From df32770b2bf70d2ea397a7b3cfe1f55537ad9a83 Mon Sep 17 00:00:00 2001 From: Mikolaj Kaczmarek Date: Sun, 6 Sep 2020 19:17:05 +0200 Subject: [PATCH 1/8] Added post_x_bindings methods for Python, Go and Julia bindings --- src/mlpack/CMakeLists.txt | 65 ++--------------------- src/mlpack/bindings/go/CMakeLists.txt | 26 ++++++++- src/mlpack/bindings/julia/CMakeLists.txt | 10 ++++ src/mlpack/bindings/python/CMakeLists.txt | 34 ++++++++++++ 4 files changed, 72 insertions(+), 63 deletions(-) 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/go/CMakeLists.txt b/src/mlpack/bindings/go/CMakeLists.txt index 5433acd6eb..37d14be839 100644 --- a/src/mlpack/bindings/go/CMakeLists.txt +++ b/src/mlpack/bindings/go/CMakeLists.txt @@ -9,6 +9,30 @@ macro (not_found_return message) endif() endmacro () +macro (post_go_setup) + if (BUILD_GO_BINDINGS) + # If we are building Go bindings, we have to end the 'module' declaration in + # 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 +200,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 61e55ed9a9..d5ba58ab8b 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) From 3732112f5d43c3bec35bdd7db7cac8e46d23658d Mon Sep 17 00:00:00 2001 From: "Barak A. Pearlmutter" Date: Mon, 7 Sep 2020 11:50:48 +0100 Subject: [PATCH 2/8] grammar --- src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp | 2 +- .../bayesian_linear_regression_main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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/methods/bayesian_linear_regression/bayesian_linear_regression_main.cpp b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_main.cpp index c69bdb438c..01ce9ae4f9 100644 --- a/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_main.cpp +++ b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_main.cpp @@ -86,8 +86,8 @@ BINDING_EXAMPLE( "predictions", "test_predictions") + "\n\n" "Because the estimator computes a predictive distribution instead of " - "simple point estimate, the " + PRINT_PARAM_STRING("stds") + " parameter " - "allows to save the prediction uncertainties: " + "a simple point estimate, the " + PRINT_PARAM_STRING("stds") + " parameter " + "allows one to save the prediction uncertainties: " "\n\n" + PRINT_CALL("bayesian_linear_regression", "input_model", "blr_model", "test", "test", From 1478a716499b114e387d0773bf2436f4a4a80605 Mon Sep 17 00:00:00 2001 From: 1sarthakbhadwaj <7sarthakbhardwaj@gmail.com> Date: Thu, 10 Sep 2020 11:34:44 +0530 Subject: [PATCH 3/8] adding myself to contributors list --- COPYRIGHT.txt | 1 + 1 file changed, 1 insertion(+) 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. From cbdec63fa0afaf3769f0da4ae33861c13a8ae71e Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 10 Sep 2020 16:47:36 -0400 Subject: [PATCH 4/8] Clarify that the type should be size_t. --- src/mlpack/core/cv/cv_base_impl.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mlpack/core/cv/cv_base_impl.hpp b/src/mlpack/core/cv/cv_base_impl.hpp index f8b28cdef3..9a06ff8835 100644 --- a/src/mlpack/core/cv/cv_base_impl.hpp +++ b/src/mlpack/core/cv/cv_base_impl.hpp @@ -26,7 +26,8 @@ CVBase Date: Thu, 10 Sep 2020 19:41:40 -0400 Subject: [PATCH 5/8] Fix static code analysis issue. --- src/mlpack/core/cv/cv_base_impl.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mlpack/core/cv/cv_base_impl.hpp b/src/mlpack/core/cv/cv_base_impl.hpp index 9a06ff8835..a7017d770a 100644 --- a/src/mlpack/core/cv/cv_base_impl.hpp +++ b/src/mlpack/core/cv/cv_base_impl.hpp @@ -23,7 +23,8 @@ CVBase::CVBase() : - isDatasetInfoPassed(false) + isDatasetInfoPassed(false), + numClasses(0) { static_assert(!MIE::TakesNumClasses, "The given MLAlgorithm requires the numClasses parameter; " From b299d226da94a06e54667107c86558073e4ce7f3 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 10 Sep 2020 19:45:46 -0400 Subject: [PATCH 6/8] Fix regex for versions of Go without a patch version. --- CMake/FindGo.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From db5a82cbc2cc1e085a34c9e076339c5bbb3b06c2 Mon Sep 17 00:00:00 2001 From: Mikolaj Kaczmarek Date: Sat, 12 Sep 2020 11:31:25 +0200 Subject: [PATCH 7/8] Fixed whitespaces and one comment --- src/mlpack/bindings/go/CMakeLists.txt | 3 +-- src/mlpack/bindings/julia/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mlpack/bindings/go/CMakeLists.txt b/src/mlpack/bindings/go/CMakeLists.txt index 37d14be839..8d83745bdf 100644 --- a/src/mlpack/bindings/go/CMakeLists.txt +++ b/src/mlpack/bindings/go/CMakeLists.txt @@ -11,8 +11,7 @@ endmacro () macro (post_go_setup) if (BUILD_GO_BINDINGS) - # If we are building Go bindings, we have to end the 'module' declaration in - # models.go + # 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" diff --git a/src/mlpack/bindings/julia/CMakeLists.txt b/src/mlpack/bindings/julia/CMakeLists.txt index d5ba58ab8b..10fe0b944a 100644 --- a/src/mlpack/bindings/julia/CMakeLists.txt +++ b/src/mlpack/bindings/julia/CMakeLists.txt @@ -9,7 +9,7 @@ endmacro () macro (post_julia_setup) # If we are building Julia bindings, we have to end the 'module' declaration in - # mlpack.jl + # mlpack.jl. if (BUILD_JULIA_BINDINGS) file(APPEND "${CMAKE_BINARY_DIR}/src/mlpack/bindings/julia/mlpack/src/mlpack.jl" From b1aa4a907df3c58db4437f871c39d9fa0d647c72 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 15 Sep 2020 01:26:20 +0530 Subject: [PATCH 8/8] package name upgrade python2 to python3 --- doc/guide/build.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/guide/build.hpp b/doc/guide/build.hpp index 33f564475b..2c20941421 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 libboost-serialization-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 @endcode