diff --git a/CMake/FindGo.cmake b/CMake/FindGo.cmake index dfccd8a9fe..39b93f69aa 100644 --- a/CMake/FindGo.cmake +++ b/CMake/FindGo.cmake @@ -14,9 +14,9 @@ if (GO_EXECUTABLE) RESULT_VARIABLE RESULT ) if (RESULT EQUAL 0) - string(REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" + string(REGEX REPLACE ".*([0-9]+\\.[0-9]+\(\\.[0-9]+\)?).*" "\\1" GO_VERSION_STRING ${GO_VERSION_STRING}) - endif() + endif() endif() include(FindPackageHandleStandardArgs) diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index bbf274dc07..0613e4ed15 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -132,6 +132,7 @@ Copyright: Copyright 2020, Lakshya Ojha Copyright 2020, Bisakh Mondal Copyright 2020, Benson Muite + Copyright 2020, Sarthak Bhardwaj <7sarthakbhardwaj@gmail.com> License: BSD-3-clause All rights reserved. diff --git a/doc/guide/build.hpp b/doc/guide/build.hpp index 7831d69b98..e454e2a1da 100644 --- a/doc/guide/build.hpp +++ b/doc/guide/build.hpp @@ -100,8 +100,8 @@ installed through apt: @code # apt-get install libboost-math-dev libboost-test-dev libcereal-dev - libarmadillo-dev binutils-dev python-pandas python-numpy cython - python-setuptools + libarmadillo-dev binutils-dev python3-pandas python3-numpy cython3 + python3-setuptools @endcode If you are using Ubuntu 19.10 or newer, you can also install @c libensmallen-dev @@ -123,7 +123,7 @@ On Fedora, Red Hat, or CentOS, these same dependencies can be obtained via dnf: @code # dnf install boost-devel boost-test boost-math armadillo-devel binutils-devel - python2-Cython python2-setuptools python2-numpy python2-pandas ensmallen-devel + python3-Cython python3-setuptools python3-numpy python3-pandas ensmallen-devel stbi-devel cereal-devel @endcode diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt index 12ff343a34..e3efa5e836 100644 --- a/src/mlpack/CMakeLists.txt +++ b/src/mlpack/CMakeLists.txt @@ -125,68 +125,9 @@ string(REGEX REPLACE ".*#define MLPACK_VERSION_PATCH [\"]?([0-9x]+)[\"]?.*" set(PACKAGE_VERSION "${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH}") -# If we are building Python bindings, we have to configure setup.py but only -# after we've recursed into methods/. -if (BUILDING_PYTHON_BINDINGS) - - get_property(CYTHON_INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY INCLUDE_DIRECTORIES) - add_custom_target(python_configure - COMMAND ${CMAKE_COMMAND} - -D SETUP_PY_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/setup.py.in - -D SETUP_PY_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py - -D PACKAGE_VERSION="${PACKAGE_VERSION}" - -D Boost_SERIALIZATION_LIBRARY="${Boost_SERIALIZATION_LIBRARY_RELEASE}" - -D Boost_LIBRARY_DIRS="${Boost_LIBRARY_DIRS}" - -D ARMADILLO_LIBRARIES="${ARMADILLO_LIBRARIES}" - -D MLPACK_LIBRARY=$ - -D MLPACK_LIBDIR=$ - -D MLPACK_PYXS="${MLPACK_PYXS}" - -D OpenMP_CXX_FLAGS="${OpenMP_CXX_FLAGS}" - -D DISABLE_CFLAGS="${DISABLE_CFLAGS}" - -D CYTHON_INCLUDE_DIRECTORIES="${CYTHON_INCLUDE_DIRECTORIES}" - -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -D OUTPUT_DIR=${CMAKE_BINARY_DIR} - -P "${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/ConfigureSetup.cmake" - BYPRODUCTS "${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py" - COMMENT "Configuring setup.py...") - add_dependencies(python_configure python_copy) - add_dependencies(python_configured python_configure) - - # Append the package version to __init__.py after all the imports are loaded. - file(APPEND ${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/mlpack/__init__.py - "__version__='${PACKAGE_VERSION}'\n") -endif () - -# If we are building Julia bindings, we have to end the 'module' declaration in -# mlpack.jl -if (BUILD_JULIA_BINDINGS) - file(APPEND - "${CMAKE_BINARY_DIR}/src/mlpack/bindings/julia/mlpack/src/mlpack.jl" - "\nend\ninclude(\"functions.jl\")\ninclude(\"serialization.jl\")\nend\n") -endif () - -# If we are building Go bindings, we have to end the 'module' declaration in -# models.go -if (BUILD_GO_BINDINGS) - file(APPEND - "${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/src/mlpack.org/v1/mlpack/models.go" - "*/\n" - "import \"C\"\n\n" - "import (\n" - " \"runtime\"\n" - " \"unsafe\"\n" - ")\n\n") - - include("${CMAKE_SOURCE_DIR}/CMake/go/AppendModel.cmake") - # Read list content. - get_property(MODELS GLOBAL PROPERTY GO_MODELS) - foreach (models IN LISTS MODELS) - append_model( - "${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/src/mlpack.org/v1/mlpack/models.go" - ${models}) - endforeach() -endif() +post_python_bindings() +post_julia_setup() +post_go_setup() # If we are building R-bindings, we have to run some setup after we # recurse into methods/. If not, this macro is empty. diff --git a/src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp b/src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp index a65aecfa1d..6674a32c2e 100644 --- a/src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp +++ b/src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp @@ -691,7 +691,7 @@ class CallForVersion : public Success { : CallForVersion("This should be caught in your main function, see examples", ExitCodes::Success) {} }; -/// Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error code. +/// Does not output a diagnostic in CLI11_PARSE, but allows main() to return with a specific error code. class RuntimeError : public ParseError { CLI11_ERROR_DEF(ParseError, RuntimeError) explicit RuntimeError(int exit_code = 1) : RuntimeError("Runtime error", exit_code) {} diff --git a/src/mlpack/bindings/go/CMakeLists.txt b/src/mlpack/bindings/go/CMakeLists.txt index 5433acd6eb..8d83745bdf 100644 --- a/src/mlpack/bindings/go/CMakeLists.txt +++ b/src/mlpack/bindings/go/CMakeLists.txt @@ -9,6 +9,29 @@ macro (not_found_return message) endif() endmacro () +macro (post_go_setup) + if (BUILD_GO_BINDINGS) + # Once `GO_MODELS` is populated, generate `models.go`. + file(APPEND + "${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/src/mlpack.org/v1/mlpack/models.go" + "*/\n" + "import \"C\"\n\n" + "import (\n" + " \"runtime\"\n" + " \"unsafe\"\n" + ")\n\n") + + include("${CMAKE_SOURCE_DIR}/CMake/go/AppendModel.cmake") + # Read list content. + get_property(MODELS GLOBAL PROPERTY GO_MODELS) + foreach (models IN LISTS MODELS) + append_model( + "${CMAKE_BINARY_DIR}/src/mlpack/bindings/go/src/mlpack.org/v1/mlpack/models.go" + ${models}) + endforeach() + endif() +endmacro () + # If we are not supposed to make Go bindings, define the macro so it does # nothing and leave this file. if (NOT BUILD_GO_BINDINGS) @@ -176,7 +199,7 @@ set_property(GLOBAL PROPERTY GO_MODELS "") macro (add_go_binding name) if (BUILD_GO_BINDINGS) - # Include all .h that define model to models.go. + # Include all .h that define model to models.go. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${name}_main.cpp" MAIN_FILE) if (MAIN_FILE MATCHES "PARAM_MODEL") file(APPEND diff --git a/src/mlpack/bindings/julia/CMakeLists.txt b/src/mlpack/bindings/julia/CMakeLists.txt index 39172d8144..c737b9ee36 100644 --- a/src/mlpack/bindings/julia/CMakeLists.txt +++ b/src/mlpack/bindings/julia/CMakeLists.txt @@ -7,6 +7,16 @@ macro (not_found_return message) return() endmacro () +macro (post_julia_setup) + # If we are building Julia bindings, we have to end the 'module' declaration in + # mlpack.jl. + if (BUILD_JULIA_BINDINGS) + file(APPEND + "${CMAKE_BINARY_DIR}/src/mlpack/bindings/julia/mlpack/src/mlpack.jl" + "\nend\ninclude(\"functions.jl\")\ninclude(\"serialization.jl\")\nend\n") + endif () +endmacro () + # If we are not supposed to make Julia bindings, define the macro so it does # nothing and leave this file. if (NOT BUILD_JULIA_BINDINGS) diff --git a/src/mlpack/bindings/python/CMakeLists.txt b/src/mlpack/bindings/python/CMakeLists.txt index 191a5eb00d..b35bd85745 100644 --- a/src/mlpack/bindings/python/CMakeLists.txt +++ b/src/mlpack/bindings/python/CMakeLists.txt @@ -7,6 +7,40 @@ macro (not_found_return message) return() endmacro () +macro (post_python_bindings) + # If we are building Python bindings, we have to configure setup.py but only + # after we've recursed into methods/. + if (BUILDING_PYTHON_BINDINGS) + get_property(CYTHON_INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + PROPERTY INCLUDE_DIRECTORIES) + add_custom_target(python_configure + COMMAND ${CMAKE_COMMAND} + -D SETUP_PY_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/setup.py.in + -D SETUP_PY_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py + -D PACKAGE_VERSION="${PACKAGE_VERSION}" + -D Boost_SERIALIZATION_LIBRARY="${Boost_SERIALIZATION_LIBRARY_RELEASE}" + -D Boost_LIBRARY_DIRS="${Boost_LIBRARY_DIRS}" + -D ARMADILLO_LIBRARIES="${ARMADILLO_LIBRARIES}" + -D MLPACK_LIBRARY=$ + -D MLPACK_LIBDIR=$ + -D MLPACK_PYXS="${MLPACK_PYXS}" + -D OpenMP_CXX_FLAGS="${OpenMP_CXX_FLAGS}" + -D DISABLE_CFLAGS="${DISABLE_CFLAGS}" + -D CYTHON_INCLUDE_DIRECTORIES="${CYTHON_INCLUDE_DIRECTORIES}" + -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -D OUTPUT_DIR=${CMAKE_BINARY_DIR} + -P "${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/ConfigureSetup.cmake" + BYPRODUCTS "${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/setup.py" + COMMENT "Configuring setup.py...") + add_dependencies(python_configure python_copy) + add_dependencies(python_configured python_configure) + + # Append the package version to __init__.py after all the imports are loaded. + file(APPEND ${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/mlpack/__init__.py + "__version__='${PACKAGE_VERSION}'\n") + endif () +endmacro () + # If we are not supposed to make Python bindings, define the macro so it does # nothing and leave this file. if (NOT BUILD_PYTHON_BINDINGS) diff --git a/src/mlpack/core/cv/cv_base_impl.hpp b/src/mlpack/core/cv/cv_base_impl.hpp index f8b28cdef3..a7017d770a 100644 --- a/src/mlpack/core/cv/cv_base_impl.hpp +++ b/src/mlpack/core/cv/cv_base_impl.hpp @@ -23,10 +23,12 @@ CVBase::CVBase() : - isDatasetInfoPassed(false) + isDatasetInfoPassed(false), + numClasses(0) { static_assert(!MIE::TakesNumClasses, - "The given MLAlgorithm requires the numClasses parameter"); + "The given MLAlgorithm requires the numClasses parameter; " + "make sure that you pass numClasses with type size_t!"); } template