Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller authored Nov 2, 2023
1 parent 2da5643 commit f55063e
Show file tree
Hide file tree
Showing 45 changed files with 1,126 additions and 947 deletions.
2 changes: 1 addition & 1 deletion .ci_support/run_docker_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ uid=$1
gid=$2
if test -n "${uid}" -a -n "${gid}"
then
sudo cp -r ~/.local/share/*/doc/html /io
sudo cp -r ~/.local/share/doc/*/html /io
sudo chown -R ${uid}:${gid} /io/html
fi
32 changes: 17 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cmake_minimum_required (VERSION 3.13)

option ( BUILD_PYTHON "Build the python module for the library" ON )
option (USE_SPHINX "Use sphinx for documentation" ON)
option ( BUILD_SHARED_LIBS "Build shared libraries" ON )
option ( USE_INTERNAL_LIBSVM "Use internal LibSVM" ON )
option (BUILD_PYTHON "Build the python module for the library" ON)
option (USE_SPHINX "Use sphinx for documentation" ON)
option (BUILD_SHARED_LIBS "Build shared libraries" ON)
option (USE_EXTERNAL_LIBSVM "Use internal LibSVM" OFF)

# By default, build in Release mode. Must appear before project() command
set( CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")

project (OTSVM)
project (otsvm)

string (TOLOWER ${CMAKE_PROJECT_NAME} PACKAGE_NAME)

Expand All @@ -34,26 +34,28 @@ if (NOT DEFINED OPENTURNS_PYTHON_MODULE_PATH)
set (OPENTURNS_PYTHON_MODULE_PATH ${OPENTURNS_PYTHON3_MODULE_PATH})
endif ()

if (USE_EXTERNAL_LIBSVM)
find_package (LibSVM 3.24 REQUIRED)
endif ()

if (NOT BUILD_SHARED_LIBS)
list ( APPEND OTSVM_DEFINITIONS "-DOTSVM_STATIC" )
list (APPEND OTSVM_DEFINITIONS "-DOTSVM_STATIC")
endif ()
add_definitions ( ${OTSVM_DEFINITIONS} )
add_definitions (${OTSVM_DEFINITIONS})

if (MSVC)
# Disable some warnings
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4197 /wd4244 /wd4251 /wd4267 /wd4996")
endif ()

if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
set (CMAKE_INSTALL_LIBDIR lib${LIB_SUFFIX})
endif ()
include (GNUInstallDirs)

set (OTSVM_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR})
set (OTSVM_INCLUDE_PATH include)
set (OTSVM_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR})
set (OTSVM_SWIG_INCLUDE_DIRS ${OTSVM_INCLUDE_PATH}/${PACKAGE_NAME}/swig)
set (OTSVM_DATA_PATH share)
set (OTSVM_CONFIG_CMAKE_PATH ${CMAKE_INSTALL_LIBDIR}/cmake/otsvm)
set (OTSVM_DOC_PATH share/${PACKAGE_NAME}/doc)
set (OTSVM_DATA_PATH ${CMAKE_INSTALL_DATAROOTDIR})
set (OTSVM_CONFIG_CMAKE_PATH ${CMAKE_INSTALL_LIBDIR}/cmake/ottemplate)
set (OTSVM_DOC_PATH ${CMAKE_INSTALL_DOCDIR})

set (CMAKE_CXX_STANDARD 11)

Expand Down
68 changes: 29 additions & 39 deletions cmake/FindLibSVM.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# - Find LibSVM
# LibSVM is a Library for Support Vector Machines
# available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
# available at https://github.com/cjlin1/libsvm
#
# The module defines the following variables:
# LIBSVM_FOUND - the system has LibSVM
Expand All @@ -10,12 +10,11 @@
# LIBSVM_LIBRARIES - aditional libraries
# LIBSVM_MAJOR_VERSION - major version
# LIBSVM_MINOR_VERSION - minor version
# LIBSVM_PATCH_VERSION - patch version
# LIBSVM_VERSION_STRING - version (ex. 2.9.0)
# LIBSVM_ROOT_DIR - root dir (ex. /usr/local)

#=============================================================================
# Copyright 2010-2013, Julien Schueller
# Copyright 2010-2023, Julien Schueller
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -44,7 +43,7 @@
#=============================================================================

# set LIBSVM_INCLUDE_DIR
find_path ( LIBSVM_INCLUDE_DIR
find_path (LIBSVM_INCLUDE_DIR
NAMES
svm.h
PATH_SUFFIXES
Expand All @@ -54,43 +53,39 @@ find_path ( LIBSVM_INCLUDE_DIR


# set LIBSVM_INCLUDE_DIRS
if ( LIBSVM_INCLUDE_DIR )
set ( LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR} )
endif ()

set (LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR})

# version
set ( _VERSION_FILE ${LIBSVM_INCLUDE_DIR}/svm.h )
if ( EXISTS ${_VERSION_FILE} )
set (_VERSION_FILE ${LIBSVM_INCLUDE_DIR}/svm.h)
if (EXISTS ${_VERSION_FILE})
# LIBSVM_VERSION_STRING macro defined in svm.h since version 2.8.9
file ( STRINGS ${_VERSION_FILE} _VERSION_STRING REGEX ".*define[ ]+LIBSVM_VERSION[ ]+[0-9]+.*" )
if ( _VERSION_STRING )
string ( REGEX REPLACE ".*LIBSVM_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}" )
math ( EXPR LIBSVM_MAJOR_VERSION "${_VERSION_NUMBER} / 100" )
math ( EXPR LIBSVM_MINOR_VERSION "(${_VERSION_NUMBER} % 100 ) / 10" )
math ( EXPR LIBSVM_PATCH_VERSION "${_VERSION_NUMBER} % 10" )
set ( LIBSVM_VERSION_STRING "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_PATCH_VERSION}" )
file (STRINGS ${_VERSION_FILE} _VERSION_STRING REGEX ".*define[ ]+LIBSVM_VERSION[ ]+[0-9]+.*")
if (_VERSION_STRING)
string (REGEX REPLACE ".*LIBSVM_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}")
math (EXPR LIBSVM_MAJOR_VERSION "${_VERSION_NUMBER} / 100")
math (EXPR LIBSVM_MINOR_VERSION "(${_VERSION_NUMBER} % 100 )")
set (LIBSVM_VERSION_STRING "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}")
endif ()
endif ()


# check version
set ( _LIBSVM_VERSION_MATCH TRUE )
if ( LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING )
if ( LibSVM_FIND_VERSION_EXACT )
if ( NOT LibSVM_FIND_VERSION VERSION_EQUAL LIBSVM_VERSION_STRING )
set ( _LIBSVM_VERSION_MATCH FALSE )
set (_LIBSVM_VERSION_MATCH TRUE)
if (LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING)
if (LibSVM_FIND_VERSION_EXACT)
if (NOT LibSVM_FIND_VERSION VERSION_EQUAL LIBSVM_VERSION_STRING)
set (_LIBSVM_VERSION_MATCH FALSE)
endif ()
else ()
if ( LIBSVM_VERSION_STRING VERSION_LESS LibSVM_FIND_VERSION )
set ( _LIBSVM_VERSION_MATCH FALSE )
if (LIBSVM_VERSION_STRING VERSION_LESS LibSVM_FIND_VERSION)
set (_LIBSVM_VERSION_MATCH FALSE)
endif ()
endif ()
endif ()


# set LIBSVM_LIBRARY
find_library ( LIBSVM_LIBRARY
find_library (LIBSVM_LIBRARY
NAMES
svm
DOC
Expand All @@ -99,30 +94,26 @@ find_library ( LIBSVM_LIBRARY


# set LIBSVM_LIBRARIES
set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )
set (LIBSVM_LIBRARIES ${LIBSVM_LIBRARY})

# link with math library on unix
if ( UNIX )
list ( APPEND LIBSVM_LIBRARIES "-lm" )
if (UNIX)
list (APPEND LIBSVM_LIBRARIES "m")
endif ()


# try to guess root dir from include dir
if ( LIBSVM_INCLUDE_DIR )
string ( REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR} )
if (LIBSVM_INCLUDE_DIR)
string (REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR})
# try to guess root dir from library dir
elseif ( LIBSVM_LIBRARY )
string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY} )
elseif (LIBSVM_LIBRARY)
string (REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY})
endif ()


# handle REQUIRED and QUIET options
include ( FindPackageHandleStandardArgs )
if ( CMAKE_VERSION VERSION_LESS 2.8.3 )
find_package_handle_standard_args ( LibSVM DEFAULT_MSG LIBSVM_LIBRARY LIBSVM_INCLUDE_DIR _LIBSVM_VERSION_MATCH )
else ()
find_package_handle_standard_args ( LibSVM REQUIRED_VARS LIBSVM_LIBRARY LIBSVM_INCLUDE_DIR _LIBSVM_VERSION_MATCH VERSION_VAR LIBSVM_VERSION_STRING )
endif ()
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (LibSVM REQUIRED_VARS LIBSVM_LIBRARY LIBSVM_INCLUDE_DIR _LIBSVM_VERSION_MATCH VERSION_VAR LIBSVM_VERSION_STRING)

mark_as_advanced (
LIBSVM_LIBRARY
Expand All @@ -133,5 +124,4 @@ mark_as_advanced (
LIBSVM_VERSION_STRING
LIBSVM_MAJOR_VERSION
LIBSVM_MINOR_VERSION
LIBSVM_PATCH_VERSION
)
18 changes: 12 additions & 6 deletions lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

if ( NOT LIBSVM_FOUND )
add_subdirectory ( LibSVM )
if (NOT LIBSVM_FOUND)
add_subdirectory (LibSVM)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/LibSVM/otsvm)
endif ()

ot_add_current_dir_to_include_dirs ()
Expand Down Expand Up @@ -54,9 +54,14 @@ endif ()
if ( NOT DEFINED LIB_SOVERSION )
set ( LIB_SOVERSION 0 )
endif ()
set_target_properties ( otsvm PROPERTIES VERSION ${LIB_VERSION} )
set_target_properties ( otsvm PROPERTIES SOVERSION ${LIB_SOVERSION} )
target_link_libraries (otsvm ${OPENTURNS_LIBRARY})
set_target_properties (otsvm PROPERTIES VERSION ${LIB_VERSION})
set_target_properties (otsvm PROPERTIES SOVERSION ${LIB_SOVERSION})
target_link_libraries (otsvm PUBLIC ${OPENTURNS_LIBRARY})

if (LIBSVM_FOUND)
target_link_libraries (otsvm PRIVATE ${LIBSVM_LIBRARIES})
target_include_directories (otsvm PRIVATE ${LIBSVM_INCLUDE_DIRS})
endif ()

# Add targets to the build-tree export set
export (TARGETS otsvm FILE ${PROJECT_BINARY_DIR}/OTSVM-Targets.cmake)
Expand All @@ -73,3 +78,4 @@ install(TARGETS otsvm
ARCHIVE DESTINATION ${OTSVM_LIBRARY_PATH}
)


19 changes: 9 additions & 10 deletions lib/src/ExponentialRBF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
*
* Copyright 2014-2023 Phimeca
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "otsvm/ExponentialRBF.hxx"
Expand Down
10 changes: 5 additions & 5 deletions lib/src/KMeansClustering.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ void KMeansClustering::run()
UnsignedInteger change = 0;

Indices cluster(size);
Sample means(k_ , dimension);
Sample means(k_, dimension);

const Point min(inputSample_.getMin());
const Point max(inputSample_.getMax());

for (UnsignedInteger i = 0 ; i < dimension ; ++ i)
for (UnsignedInteger i = 0; i < dimension; ++ i)
{
Uniform uniform(min[i], max[i]);
for (UnsignedInteger j = 0 ; j < k_; ++ j)
{
means(j , i) = uniform.getRealization()[0];
means(j, i) = uniform.getRealization()[0];
}
}

while (!change)
{
for (UnsignedInteger i = 0 ; i < size; ++ i)
for (UnsignedInteger i = 0; i < size; ++ i)
{
Scalar distancemin = ( inputSample_[i] - means[0] ).norm();

for (UnsignedInteger j = 1 ; j < k_; ++j)
for (UnsignedInteger j = 1; j < k_; ++ j)
{
const Scalar distance = ( inputSample_[i] - means[j] ).norm();

Expand Down
Loading

0 comments on commit f55063e

Please sign in to comment.