Merge branch 'master' into multilabel_softmargin_loss
This commit is contained in:
-219
@@ -1,219 +0,0 @@
|
||||
clone_depth: 10
|
||||
|
||||
environment:
|
||||
BOOST_MATH : "C:/projects/mlpack/\
|
||||
boost_math_c99-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
|
||||
BOOST_RANDOM : "C:/projects/mlpack/\
|
||||
boost_random-vc140.1.60.0.0/lib/native/address-model-64/lib/*.*"
|
||||
ARMADILLO_DOWNLOAD : "https://data.kurg.org/armadillo-8.400.0.tar.xz"
|
||||
ARMADILLO_LIBRARY : "C:/projects/mlpack/armadillo-8.400.0/\
|
||||
build/Debug/armadillo.lib"
|
||||
BLAS_LIBRARY : "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/\
|
||||
libopenblas.dll.a"
|
||||
BOOST_INCLUDE : "C:/projects/mlpack/boost.1.60.0.0/lib/native/include"
|
||||
JENKINS_DOC_DOWNLOAD : "http://ci.mlpack.org/job/mlpack%20-%20doxygen%20\
|
||||
build/lastSuccessfulBuild/artifact/build/doc/html/*zip*/html.zip"
|
||||
JENKINS_DOC : "C:/projects/mlpack/dist/win-installer/jenkinsdoc.zip"
|
||||
GIT_VERSION_FILE : "C:/projects/mlpack/src/mlpack/core/util/gitversion.hpp"
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
VSVER: Visual Studio 16 2019
|
||||
MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
|
||||
|
||||
# We have removed the VS studio 15 2017 build since it is not possible to complete
|
||||
# or finish the build due to the `compiler out of heap space issues`.
|
||||
# Therefore, in the meanwhile, we are only doing the installation for VS 16 2019.
|
||||
|
||||
configuration: Release
|
||||
|
||||
os: Visual Studio 2019
|
||||
|
||||
install:
|
||||
- ps: nuget install boost -o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
|
||||
- ps: >
|
||||
nuget install boost_random-vc140
|
||||
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
|
||||
- ps: >
|
||||
nuget install boost_math_c99-vc140
|
||||
-o "${env:APPVEYOR_BUILD_FOLDER}" -Version 1.60.0
|
||||
- ps: >
|
||||
nuget install unofficial-flayan-cereal
|
||||
-o "${env:APPVEYOR_BUILD_FOLDER}"
|
||||
- ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}"
|
||||
- set path=C:\Program Files (x86)\WiX Toolset v3.11\bin;%path%
|
||||
|
||||
build_script:
|
||||
- mkdir boost_libs
|
||||
- ps: cp ${env:BOOST_MATH} C:\projects\mlpack\boost_libs\
|
||||
- ps: cp ${env:BOOST_RANDOM} C:\projects\mlpack\boost_libs\
|
||||
- echo TEST_ARMA is %ARMADILLO_DOWNLOAD%
|
||||
- >
|
||||
appveyor DownloadFile %ARMADILLO_DOWNLOAD%
|
||||
-FileName armadillo.tar.xz
|
||||
- 7z x armadillo.tar.xz -so -txz | 7z x -si -ttar > nul
|
||||
- cd armadillo-8.400.0 && mkdir build && cd build
|
||||
- >
|
||||
cmake -G "%VSVER%"
|
||||
-DBLAS_LIBRARY:FILEPATH=%BLAS_LIBRARY%
|
||||
-DLAPACK_LIBRARY:FILEPATH=%BLAS_LIBRARY%
|
||||
-DCMAKE_PREFIX:FILEPATH="%APPVEYOR_BUILD_FOLDER%/armadillo"
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DCMAKE_BUILD_TYPE=Release ..
|
||||
- >
|
||||
"%MSBUILD%" "C:\projects\mlpack\armadillo-8.400.0\build\armadillo.sln"
|
||||
/m /verbosity:quiet /p:Configuration=Release;Platform=x64
|
||||
- cd C:\projects\mlpack && mkdir build && cd build
|
||||
- >
|
||||
cmake -G "%VSVER%"
|
||||
-DBLAS_LIBRARIES:FILEPATH=%BLAS_LIBRARY%
|
||||
-DLAPACK_LIBRARIES:FILEPATH=%BLAS_LIBRARY%
|
||||
-DARMADILLO_INCLUDE_DIR="C:/projects/mlpack/armadillo-8.400.0/include"
|
||||
-DARMADILLO_LIBRARY:FILEPATH=%ARMADILLO_LIBRARY%
|
||||
-DCEREAL_INCLUDE_DIR="C:/projects/mlpack/unofficial-flayan-cereal.1.2.2/build/native/include"
|
||||
-DBOOST_INCLUDEDIR:PATH=%BOOST_INCLUDE%
|
||||
-DDEBUG=OFF
|
||||
-DPROFILE=OFF
|
||||
-DBUILD_PYTHON_BINDINGS=OFF
|
||||
-DBUILD_GO_BINDINGS=OFF
|
||||
-DBUILD_R_BINDINGS=OFF
|
||||
-DBUILD_TESTS=OFF
|
||||
-DCMAKE_BUILD_TYPE=Release ..
|
||||
- >
|
||||
"%MSBUILD%" "C:\projects\mlpack\build\mlpack.sln"
|
||||
/m /verbosity:minimal /nologo /p:BuildInParallel=true
|
||||
/p:Configuration=Release;Platform=x64
|
||||
|
||||
# Zip Artifacts.
|
||||
- >
|
||||
7z a mlpack-windows-no-libs.zip
|
||||
"%APPVEYOR_BUILD_FOLDER%\build\Release\*.exe"
|
||||
- >
|
||||
7z a mlpack-windows.zip
|
||||
"%APPVEYOR_BUILD_FOLDER%\build\Release\*.*"
|
||||
"%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/*.*"
|
||||
|
||||
# Pulling documentation for the installer.
|
||||
- ps: >
|
||||
try{(new-object net.webclient).DownloadFile(${env:JENKINS_DOC_DOWNLOAD},
|
||||
'C:\projects\mlpack\dist\win-installer\jenkinsdoc.zip')}
|
||||
catch{Write-Output "Unable to pull jenkins doc, skipping!"}
|
||||
- ps: >
|
||||
try{(Add-Type -AssemblyName System.IO.Compression.FileSystem);
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory(${env:JENKINS_DOC},
|
||||
'C:\projects\mlpack\dist\win-installer\staging\doc')}
|
||||
catch{Write-Output "Unable to add doc to installer, skipping!"}
|
||||
|
||||
# Preparing installer staging.
|
||||
- cd C:\projects\mlpack\dist\win-installer\staging && mkdir lib
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\build\Release\*.lib
|
||||
C:\projects\mlpack\dist\win-installer\staging\lib\
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\build\Release\*.exp
|
||||
C:\projects\mlpack\dist\win-installer\staging\lib\
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\build\Release\*.dll
|
||||
C:\projects\mlpack\dist\win-installer\staging\
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\build\Release\*.exe
|
||||
C:\projects\mlpack\dist\win-installer\staging\
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll
|
||||
C:\projects\mlpack\dist\win-installer\staging\
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\build\include\mlpack
|
||||
C:\projects\mlpack\dist\win-installer\staging -recurse
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\doc\examples
|
||||
C:\projects\mlpack\dist\win-installer\staging -recurse
|
||||
- ps: >
|
||||
cp C:\projects\mlpack\src\mlpack\tests\data\german.csv
|
||||
C:\projects\mlpack\dist\win-installer\staging\examples\sample-ml-app\sample-ml-app\data\
|
||||
|
||||
# Checking current gitversion or mlpack version.
|
||||
- ps: >
|
||||
$ver = (Get-Content
|
||||
"${env:APPVEYOR_BUILD_FOLDER}\src\mlpack\core\util\version.hpp" |
|
||||
where {$_ -like "*MLPACK_VERSION*"});
|
||||
$env:MLPACK_VERSION += $ver[0].substring($ver[0].length - 1, 1) + '.';
|
||||
$env:MLPACK_VERSION += $ver[1].substring($ver[1].length - 1, 1) + '.';
|
||||
$env:MLPACK_VERSION += $ver[2].substring($ver[2].length - 1, 1);
|
||||
|
||||
if (Test-Path ${env:GIT_VERSION_FILE})
|
||||
{
|
||||
$ver = (Get-Content ${env:GIT_VERSION_FILE});
|
||||
$env:INSTALL_VERSION = $ver.Split('"')[1].Split(' ')[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$env:INSTALL_VERSION = $env:MLPACK_VERSION;
|
||||
}
|
||||
- echo INSTALL_VERSION is %INSTALL_VERSION%
|
||||
|
||||
# Building MSI installer.
|
||||
- cd C:\projects\mlpack\dist\win-installer\mlpack-win-installer
|
||||
- >
|
||||
heat dir ..\staging
|
||||
-cg HeatGenerated
|
||||
-dr INSTALLFOLDER
|
||||
-sreg
|
||||
-srd
|
||||
-var var.HarvestPath
|
||||
-ag
|
||||
-sfrag
|
||||
-out HeatGeneratedFileList.wxs
|
||||
- >
|
||||
candle -dHarvestPath=..\staging
|
||||
-dConfiguration=Release
|
||||
-dOutDir=bin\x64\Release\
|
||||
-dPlatform=x64
|
||||
-dProjectDir=.
|
||||
-dProjectExt=.wixproj
|
||||
-dProjectFileName=mlpack-win-installer.wixproj
|
||||
-dProjectName=mlpack-win-installer
|
||||
-dProjectPath=mlpack-win-installer.wixproj
|
||||
-dTargetDir=.\bin\x64\Release\
|
||||
-dTargetExt=.msi
|
||||
-dTargetFileName=mlpack-windows.msi
|
||||
-dTargetName=mlpack-windows
|
||||
-dTargetPath=.\bin\x64\Release\mlpack-windows.msi
|
||||
-out obj\x64\Release\
|
||||
-arch x64
|
||||
-ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\\WixUIExtension.dll"
|
||||
Product.wxs HeatGeneratedFileList.wxs
|
||||
- >
|
||||
light -out .\bin\x64\Release\mlpack-%INSTALL_VERSION%.msi
|
||||
-pdbout .\bin\x64\Release\mlpack-windows.wixpdb
|
||||
-cultures:null
|
||||
-loc mlpack-localization.wxl
|
||||
-ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\\WixUIExtension.dll"
|
||||
-contentsfile
|
||||
obj\x64\Release\mlpack-win-installer.wixproj.BindContentsFileListnull.txt
|
||||
-outputsfile
|
||||
obj\x64\Release\mlpack-win-installer.wixproj.BindOutputsFileListnull.txt
|
||||
-builtoutputsfile
|
||||
obj\x64\Release\mlpack-win-installer.wixproj.BindBuiltOutputsFileListnull.txt
|
||||
-wixprojectfile
|
||||
mlpack-win-installer.wixproj
|
||||
obj\x64\Release\Product.wixobj
|
||||
obj\x64\Release\HeatGeneratedFileList.wixobj
|
||||
|
||||
artifacts:
|
||||
- path: 'build\*.zip'
|
||||
name: mlpack-windows-zip
|
||||
|
||||
- path: 'dist\win-installer\mlpack-win-installer\bin\x64\Release\*.msi'
|
||||
name: mlpack-windows-installer
|
||||
|
||||
notifications:
|
||||
- provider: Email
|
||||
to:
|
||||
- mlpack-git@lists.mlpack.org
|
||||
on_build_success: true
|
||||
on_build_failure: true
|
||||
on_build_status_changed: true
|
||||
|
||||
cache:
|
||||
- packages -> **\packages.config
|
||||
- armadillo.tar.xz -> appveyor.yaml
|
||||
|
||||
+10
-6
@@ -21,7 +21,7 @@ steps:
|
||||
unset BOOST_ROOT
|
||||
echo "##vso[task.setvariable variable=BOOST_ROOT]"$BOOST_ROOT
|
||||
|
||||
sudo apt-get install -y --allow-unauthenticated libopenblas-dev g++ libboost1.70-dev xz-utils
|
||||
sudo apt-get install -y --allow-unauthenticated libopenblas-dev g++ libboost-all-dev xz-utils
|
||||
|
||||
if [ "$(binding)" == "python" ]; then
|
||||
export PYBIN=$(which python)
|
||||
@@ -35,13 +35,17 @@ steps:
|
||||
fi
|
||||
|
||||
# Install armadillo.
|
||||
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo*
|
||||
cmake . && make && sudo make install && cd ..
|
||||
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && \
|
||||
cd armadillo* && \
|
||||
cmake . && \
|
||||
make && \
|
||||
sudo make install && \
|
||||
cd ..
|
||||
|
||||
# Install cereal.
|
||||
wget https://github.com/USCiLab/cereal/archive/v1.3.0.tar.gz
|
||||
tar -xvzpf v1.3.0.tar.gz # Unpack into cereal-1.3.0/.
|
||||
cd cereal-1.3.0/
|
||||
|
||||
displayName: 'Install Build Dependencies'
|
||||
|
||||
# Configure mlpack (CMake)
|
||||
@@ -56,12 +60,12 @@ steps:
|
||||
displayName: 'CMake'
|
||||
|
||||
# Build mlpack
|
||||
- script: cd build && make
|
||||
- script: cd build && make && make mlpack_test
|
||||
condition: eq(variables['CMakeArgs'], '-DDEBUG=ON -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF')
|
||||
displayName: 'Build'
|
||||
|
||||
# Build mlpack
|
||||
- script: cd build && make -j2
|
||||
- script: cd build && make -j2 && make -j2 mlpack_test
|
||||
condition: ne(variables['CMakeArgs'], '-DDEBUG=ON -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF')
|
||||
displayName: 'Build'
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ steps:
|
||||
set -e
|
||||
sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer
|
||||
unset BOOST_ROOT
|
||||
brew install openblas armadillo boost cereal
|
||||
brew install libomp openblas armadillo boost cereal
|
||||
|
||||
if [ "$(binding)" == "python" ]; then
|
||||
pip install --upgrade pip
|
||||
@@ -45,7 +45,7 @@ steps:
|
||||
displayName: 'CMake'
|
||||
|
||||
# Build mlpack
|
||||
- script: cd build && make -j2
|
||||
- script: cd build && make -j2 && make -j2 mlpack_test
|
||||
displayName: 'Build'
|
||||
|
||||
# Run tests via ctest.
|
||||
|
||||
@@ -88,6 +88,7 @@ steps:
|
||||
# Run tests via ctest.
|
||||
- bash: |
|
||||
cd build
|
||||
cmake --build . --target mlpack_test -C Release
|
||||
CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test -C Release . -j1
|
||||
displayName: 'Run tests via ctest'
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')"
|
||||
|
||||
- name: Cache R packages
|
||||
if: runner.os != 'Windows'
|
||||
if: runner.os != 'Windows' && runner.os != 'macOS'
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ env.R_LIBS_USER }}
|
||||
@@ -68,7 +68,7 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd build && make -j2
|
||||
cd build && make -j2 && make -j2 mlpack_test
|
||||
|
||||
- name: Run tests via ctest
|
||||
run: |
|
||||
@@ -120,7 +120,7 @@ jobs:
|
||||
run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')"
|
||||
|
||||
- name: Cache R packages
|
||||
if: runner.os != 'Windows'
|
||||
if: runner.os != 'Windows' && runner.os != 'macOS'
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ env.R_LIBS_USER }}
|
||||
@@ -129,6 +129,7 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
install.packages('remotes')
|
||||
remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE)
|
||||
remotes::install_cran("rcmdcheck")
|
||||
shell: Rscript {0}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
## This function auto-downloads mlpack dependencies.
|
||||
## You need to pass the LINK to download from, the name of
|
||||
## the dependency, and the name of the compressed package such as
|
||||
## armadillo.tar.gz
|
||||
## At each download, this module sets a GENERIC_INCLUDE_DIR path,
|
||||
## which means that you need to set the main path for the include
|
||||
## directories for each package.
|
||||
## Note that, the package should be compressed only as .tar.gz
|
||||
|
||||
macro(get_deps LINK DEPS_NAME PACKAGE)
|
||||
if (NOT EXISTS "${CMAKE_BINARY_DIR}/deps/${PACKAGE}")
|
||||
file(DOWNLOAD ${LINK}
|
||||
"${CMAKE_BINARY_DIR}/deps/${PACKAGE}"
|
||||
STATUS DOWNLOAD_STATUS_LIST LOG DOWNLOAD_LOG
|
||||
SHOW_PROGRESS)
|
||||
list(GET DOWNLOAD_STATUS_LIST 0 DOWNLOAD_STATUS)
|
||||
if (DOWNLOAD_STATUS EQUAL 0)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E
|
||||
tar xf "${CMAKE_BINARY_DIR}/deps/${PACKAGE}"
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/")
|
||||
else ()
|
||||
list(GET DOWNLOAD_STATUS_LIST 1 DOWNLOAD_ERROR)
|
||||
message(FATAL_ERROR
|
||||
"Could not download ${DEPS_NAME}! Error code ${DOWNLOAD_STATUS}: ${DOWNLOAD_ERROR}! Error log: ${DOWNLOAD_LOG}")
|
||||
endif()
|
||||
endif()
|
||||
# Get the name of the directory.
|
||||
file (GLOB DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
|
||||
"${CMAKE_BINARY_DIR}/deps/${DEPS_NAME}*.*")
|
||||
# Clean this line when boost is removed.
|
||||
if (${DEPS_NAME} MATCHES "boost")
|
||||
file (GLOB DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
|
||||
"${CMAKE_BINARY_DIR}/deps/${DEPS_NAME}*_*")
|
||||
elseif(${DEPS_NAME} MATCHES "stb")
|
||||
file (GLOB DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
|
||||
"${CMAKE_BINARY_DIR}/deps/${DEPS_NAME}")
|
||||
endif()
|
||||
# list(FILTER) is not available on 3.5 or older, but try to keep
|
||||
# configuring without filtering the list anyway
|
||||
# (it works only if the file is present as .tar.gz).
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.6.0")
|
||||
list(FILTER DIRECTORIES EXCLUDE REGEX ".*\.tar\.gz")
|
||||
endif ()
|
||||
list(LENGTH DIRECTORIES DIRECTORIES_LEN)
|
||||
if (DIRECTORIES_LEN GREATER 0)
|
||||
list(GET DIRECTORIES 0 DEPENDENCY_DIR)
|
||||
# Clean these lines when boost is removed.
|
||||
if (${DEPS_NAME} MATCHES "boost")
|
||||
set(Boost_INCLUDE_DIR "${CMAKE_BINARY_DIR}/deps/${DEPENDENCY_DIR}/")
|
||||
install(DIRECTORY "${Boost_INCLUDE_DIR}/boost" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
else()
|
||||
set(GENERIC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/deps/${DEPENDENCY_DIR}/include")
|
||||
install(DIRECTORY "${GENERIC_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
endif()
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"Problem unpacking ${DEPS_NAME}! Expected only one directory ${DEPS_NAME};. Try to remove the directory ${CMAKE_BINARY_DIR}/deps and reconfigure.")
|
||||
endif ()
|
||||
endmacro()
|
||||
@@ -0,0 +1,44 @@
|
||||
# This file adds the necessary configurations to cross compile
|
||||
# mlpack for embedded systems. You need to set the following variables
|
||||
# from the command line: CMAKE_SYSROOT and TOOLCHAIN_PREFIX.
|
||||
# This file will compile OpenBLAS if it is downloaded and it is not
|
||||
# available on your system in order to find the BLAS library. If OpenBLAS will
|
||||
# be compiled, the OPENBLAS_TARGET variable must be set. This can be done
|
||||
# by, e.g., setting BOARD_NAME (which will set OPENBLAS_TARGET in
|
||||
# `board/flags-config.cmake`).
|
||||
|
||||
if (CMAKE_CROSSCOMPILING)
|
||||
include(board/flags-config.cmake)
|
||||
if (NOT CMAKE_SYSROOT AND (NOT TOOLCHAIN_PREFIX))
|
||||
message(FATAL_ERROR "Neither CMAKE_SYSROOT nor TOOLCHAIN_PREFIX are set; please set both of them and try again.")
|
||||
elseif(NOT CMAKE_SYSROOT)
|
||||
message(FATAL_ERROR "Cannot configure: CMAKE_SYSROOT must be set when performing cross-compiling!")
|
||||
elseif(NOT TOOLCHAIN_PREFIX)
|
||||
message(FATAL_ERROR "Cannot configure: TOOLCHAIN_PREFIX must be set when performing cross-compiling!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
macro(search_openblas version)
|
||||
set(BLA_STATIC ON)
|
||||
find_package(BLAS)
|
||||
if (NOT BLAS_FOUND OR (NOT BLAS_LIBRARIES))
|
||||
if(NOT OPENBLAS_TARGET)
|
||||
message(FATAL_ERROR "Cannot compile OpenBLAS: OPENBLAS_TARGET is not set. Either set that variable, or set BOARD_NAME correctly!")
|
||||
endif()
|
||||
get_deps(https://github.com/xianyi/OpenBLAS/releases/download/v${version}/OpenBLAS-${version}.tar.gz OpenBLAS OpenBLAS-${version}.tar.gz)
|
||||
if (NOT MSVC)
|
||||
if (NOT EXISTS "${CMAKE_BINARY_DIR}/deps/OpenBLAS-${version}/libopenblas.a")
|
||||
execute_process(COMMAND make TARGET=${OPENBLAS_TARGET} BINARY=${OPENBLAS_BINARY} HOSTCC=gcc CC=${CMAKE_C_COMPILER} FC=${CMAKE_FORTRAN_COMPILER} NO_SHARED=1
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/deps/OpenBLAS-${version})
|
||||
endif()
|
||||
file(GLOB OPENBLAS_LIBRARIES "${CMAKE_BINARY_DIR}/deps/OpenBLAS-${version}/libopenblas.a")
|
||||
set(BLAS_openblas_LIBRARY ${OPENBLAS_LIBRARIES})
|
||||
set(LAPACK_openblas_LIBRARY ${OPENBLAS_LIBRARIES})
|
||||
set(BLA_VENDOR OpenBLAS)
|
||||
set(BLAS_FOUND ON)
|
||||
endif()
|
||||
endif()
|
||||
find_library(GFORTRAN NAMES libgfortran.a)
|
||||
find_library(PTHREAD NAMES libpthread.a)
|
||||
set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES} ${GFORTRAN} ${PTHREAD})
|
||||
endmacro()
|
||||
@@ -77,13 +77,14 @@ else()
|
||||
# don't link to armadillo in this case
|
||||
set(ARMADILLO_LIBRARY "")
|
||||
endif()
|
||||
|
||||
# Link to support libraries in either case on MSVC.
|
||||
if(NOT _ARMA_USE_WRAPPER OR MSVC)
|
||||
if(_ARMA_USE_LAPACK)
|
||||
if(ARMADILLO_FIND_QUIETLY OR NOT ARMADILLO_FIND_REQUIRED)
|
||||
find_package(LAPACK QUIET)
|
||||
else()
|
||||
find_package(LAPCK REQUIRED)
|
||||
find_package(LAPACK REQUIRED)
|
||||
endif()
|
||||
if(LAPACK_FOUND)
|
||||
set(_ARMA_SUPPORT_LIBRARIES "${_ARMA_SUPPORT_LIBRARIES}" "${LAPACK_LIBRARIES}")
|
||||
@@ -154,5 +155,6 @@ unset(__ARMA_SUPPORT_INCLUDE_DIRS)
|
||||
|
||||
# Hide internal variables
|
||||
mark_as_advanced(
|
||||
ARMADILLO_INCLUDE_DIR
|
||||
ARMADILLO_LIBRARY)
|
||||
ARMADILLO_INCLUDE_DIR
|
||||
ARMADILLO_LIBRARY
|
||||
ARMADILLO_LIBRARIES)
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
# This module looks for mex, the MATLAB compiler.
|
||||
# The following variables are defined when the script completes:
|
||||
# MATLAB_MEX: location of mex compiler
|
||||
# MATLAB_ROOT: root of MATLAB installation
|
||||
# MATLABMEX_FOUND: 0 if not found, 1 if found
|
||||
|
||||
set(MATLABMEX_FOUND 0)
|
||||
|
||||
if(WIN32)
|
||||
# This is untested but taken from the older FindMatlab.cmake script as well as
|
||||
# the modifications by Ramon Casero and Tom Doel for Gerardus.
|
||||
|
||||
# Search for a version of Matlab available, starting from the most modern one
|
||||
# to older versions.
|
||||
foreach(MATVER "7.20" "7.19" "7.18" "7.17" "7.16" "7.15" "7.14" "7.13" "7.12"
|
||||
"7.11" "7.10" "7.9" "7.8" "7.7" "7.6" "7.5" "7.4")
|
||||
if((NOT DEFINED MATLAB_ROOT)
|
||||
OR ("${MATLAB_ROOT}" STREQUAL "")
|
||||
OR ("${MATLAB_ROOT}" STREQUAL "/registry"))
|
||||
get_filename_component(MATLAB_ROOT
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\${MATVER};MATLABROOT]"
|
||||
ABSOLUTE)
|
||||
set(MATLAB_VERSION ${MATVER})
|
||||
endif()
|
||||
OR ("${MATLAB_ROOT}" STREQUAL "")
|
||||
OR ("${MATLAB_ROOT}" STREQUAL "/registry"))
|
||||
endforeach()
|
||||
|
||||
find_program(MATLAB_MEX
|
||||
mex
|
||||
${MATLAB_ROOT}/bin
|
||||
)
|
||||
else()
|
||||
# Check if this is a Mac.
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
# This code is untested but taken from the older FindMatlab.cmake script as
|
||||
# well as the modifications by Ramon Casero and Tom Doel for Gerardus.
|
||||
|
||||
set(LIBRARY_EXTENSION .dylib)
|
||||
|
||||
# If this is a Mac and the attempts to find MATLAB_ROOT have so far failed,~
|
||||
# we look in the applications folder
|
||||
if((NOT DEFINED MATLAB_ROOT) OR ("${MATLAB_ROOT}" STREQUAL ""))
|
||||
|
||||
# Search for a version of Matlab available, starting from the most modern
|
||||
# one to older versions
|
||||
foreach(MATVER "R2013b" "R2013a" "R2012b" "R2012a" "R2011b" "R2011a"
|
||||
"R2010b" "R2010a" "R2009b" "R2009a" "R2008b")
|
||||
if((NOT DEFINED MATLAB_ROOT) OR ("${MATLAB_ROOT}" STREQUAL ""))
|
||||
if(EXISTS /Applications/MATLAB_${MATVER}.app)
|
||||
set(MATLAB_ROOT /Applications/MATLAB_${MATVER}.app)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
||||
find_program(MATLAB_MEX
|
||||
mex
|
||||
PATHS
|
||||
${MATLAB_ROOT}/bin
|
||||
)
|
||||
|
||||
else()
|
||||
# On a Linux system. The goal is to find MATLAB_ROOT.
|
||||
set(LIBRARY_EXTENSION .so)
|
||||
|
||||
find_program(MATLAB_MEX_POSSIBLE_LINK
|
||||
mex
|
||||
PATHS
|
||||
${MATLAB_ROOT}/bin
|
||||
/opt/matlab/bin
|
||||
/usr/local/matlab/bin
|
||||
$ENV{HOME}/matlab/bin
|
||||
# Now all the versions
|
||||
/opt/matlab/[rR]20[0-9][0-9][abAB]/bin
|
||||
/usr/local/matlab/[rR]20[0-9][0-9][abAB]/bin
|
||||
/opt/matlab-[rR]20[0-9][0-9][abAB]/bin
|
||||
/opt/matlab_[rR]20[0-9][0-9][abAB]/bin
|
||||
/usr/local/matlab-[rR]20[0-9][0-9][abAB]/bin
|
||||
/usr/local/matlab_[rR]20[0-9][0-9][abAB]/bin
|
||||
$ENV{HOME}/matlab/[rR]20[0-9][0-9][abAB]/bin
|
||||
$ENV{HOME}/matlab-[rR]20[0-9][0-9][abAB]/bin
|
||||
$ENV{HOME}/matlab_[rR]20[0-9][0-9][abAB]/bin
|
||||
)
|
||||
|
||||
get_filename_component(MATLAB_MEX "${MATLAB_MEX_POSSIBLE_LINK}" REALPATH)
|
||||
get_filename_component(MATLAB_BIN_ROOT "${MATLAB_MEX}" PATH)
|
||||
# Strip ./bin/.
|
||||
get_filename_component(MATLAB_ROOT "${MATLAB_BIN_ROOT}" PATH)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${MATLAB_MEX}" AND "${MatlabMex_FIND_REQUIRED}")
|
||||
message(FATAL_ERROR "Could not find MATLAB mex compiler; try specifying MATLAB_ROOT.")
|
||||
else()
|
||||
if(EXISTS "${MATLAB_MEX}")
|
||||
message(STATUS "Found MATLAB mex compiler: ${MATLAB_MEX}")
|
||||
message(STATUS "MATLAB root: ${MATLAB_ROOT}")
|
||||
set(MATLABMEX_FOUND 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
MATLAB_MEX
|
||||
MATLABMEX_FOUND
|
||||
MATLAB_ROOT
|
||||
)
|
||||
|
||||
@@ -35,17 +35,19 @@ if (NOT (MODEL_FILE_TYPE MATCHES "\"${MODEL_SAFE_TYPES}\""))
|
||||
set(MODEL_PTR_IMPLS "${MODEL_PTR_IMPLS}
|
||||
// Get the pointer to a ${MODEL_TYPE} parameter.
|
||||
// [[Rcpp::export]]
|
||||
SEXP IO_GetParam${MODEL_SAFE_TYPE}Ptr(const std::string& paramName)
|
||||
SEXP GetParam${MODEL_SAFE_TYPE}Ptr(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return std::move((${MODEL_PTR_TYPEDEF}) IO::GetParam<${MODEL_TYPE}*>(paramName));
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return std::move((${MODEL_PTR_TYPEDEF}) p.Get<${MODEL_TYPE}*>(paramName));
|
||||
}
|
||||
|
||||
// Set the pointer to a ${MODEL_TYPE} parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParam${MODEL_SAFE_TYPE}Ptr(const std::string& paramName, SEXP ptr)
|
||||
void SetParam${MODEL_SAFE_TYPE}Ptr(SEXP params, const std::string& paramName, SEXP ptr)
|
||||
{
|
||||
IO::GetParam<${MODEL_TYPE}*>(paramName) = Rcpp::as<${MODEL_PTR_TYPEDEF}>(ptr);
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<${MODEL_TYPE}*>(paramName) = Rcpp::as<${MODEL_PTR_TYPEDEF}>(ptr);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Serialize a ${MODEL_TYPE} pointer.
|
||||
|
||||
+13
-11
@@ -44,8 +44,8 @@ function(append_model SERIALIZATION_FILE PROGRAM_MAIN_FILE)
|
||||
else ()
|
||||
string(APPEND GOMODEL_SAFE_TYPE ${MODEL_CHAR})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# See if the model type already exists.
|
||||
file(READ "${SERIALIZATION_FILE}" SERIALIZATION_FILE_CONTENTS)
|
||||
@@ -64,20 +64,22 @@ function(append_model SERIALIZATION_FILE PROGRAM_MAIN_FILE)
|
||||
" mem unsafe.Pointer \n"
|
||||
"}\n\n"
|
||||
"func (m *${GOMODEL_SAFE_TYPE}) alloc"
|
||||
"${MODEL_SAFE_TYPE}(identifier string) {\n"
|
||||
" m.mem = C.mlpackGet${MODEL_SAFE_TYPE}Ptr(C.CString(identifier))\n"
|
||||
"${MODEL_SAFE_TYPE}(params *params, identifier string) {\n"
|
||||
" m.mem = C.mlpackGet${MODEL_SAFE_TYPE}Ptr(params.mem,\n"
|
||||
" C.CString(identifier))\n"
|
||||
" runtime.KeepAlive(m)\n"
|
||||
"}\n\n"
|
||||
"func (m *${GOMODEL_SAFE_TYPE}) get"
|
||||
"${MODEL_SAFE_TYPE}(identifier string) {\n"
|
||||
" m.alloc${MODEL_SAFE_TYPE}(identifier)\n"
|
||||
"${MODEL_SAFE_TYPE}(params *params, identifier string) {\n"
|
||||
" m.alloc${MODEL_SAFE_TYPE}(params, identifier)\n"
|
||||
"}\n\n"
|
||||
"func set${MODEL_SAFE_TYPE}(identifier string, ptr *"
|
||||
"${GOMODEL_SAFE_TYPE}) {\n"
|
||||
" C.mlpackSet${MODEL_SAFE_TYPE}"
|
||||
"Ptr(C.CString(identifier), (unsafe.Pointer)(ptr.mem))\n"
|
||||
"func set${MODEL_SAFE_TYPE}(params* params,\n"
|
||||
" identifier string,\n"
|
||||
" ptr *${GOMODEL_SAFE_TYPE}) {\n"
|
||||
" C.mlpackSet${MODEL_SAFE_TYPE}Ptr(params.mem,\n"
|
||||
" C.CString(identifier), ptr.mem)\n"
|
||||
"}\n\n")
|
||||
endif ()
|
||||
endif()
|
||||
endforeach ()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@@ -24,10 +24,13 @@ if (${NUM_MODEL_TYPES} GREATER 0)
|
||||
# Generate the definition.
|
||||
set(MODEL_PTR_DEFNS "${MODEL_PTR_DEFNS}
|
||||
// Set the pointer to a ${MODEL_TYPE} parameter.
|
||||
extern void mlpackSet${MODEL_SAFE_TYPE}Ptr(const char* identifier, void* value);
|
||||
extern void mlpackSet${MODEL_SAFE_TYPE}Ptr(void* params,
|
||||
const char* identifier,
|
||||
void* value);
|
||||
|
||||
// Get the pointer to a ${MODEL_TYPE} parameter.
|
||||
extern void* mlpackGet${MODEL_SAFE_TYPE}Ptr(const char* identifier);
|
||||
extern void* mlpackGet${MODEL_SAFE_TYPE}Ptr(void* params,
|
||||
const char* identifier);
|
||||
"
|
||||
)
|
||||
|
||||
@@ -35,17 +38,22 @@ extern void* mlpackGet${MODEL_SAFE_TYPE}Ptr(const char* identifier);
|
||||
set(MODEL_PTR_IMPLS "${MODEL_PTR_IMPLS}
|
||||
// Set the pointer to a ${MODEL_TYPE} parameter.
|
||||
extern \"C\" void mlpackSet${MODEL_SAFE_TYPE}Ptr(
|
||||
void* params,
|
||||
const char* identifier,
|
||||
void* value)
|
||||
{
|
||||
mlpack::util::SetParamPtr<${MODEL_TYPE}>(identifier,
|
||||
static_cast<${MODEL_TYPE}*>(value));
|
||||
util::Params& p = *((util::Params*) params);
|
||||
mlpack::util::SetParamPtr<${MODEL_TYPE}>(p, identifier,
|
||||
static_cast<${MODEL_TYPE}*>(value));
|
||||
}
|
||||
|
||||
// Get the pointer to a ${MODEL_TYPE} parameter.
|
||||
extern \"C\" void *mlpackGet${MODEL_SAFE_TYPE}Ptr(const char* identifier)
|
||||
extern \"C\" void *mlpackGet${MODEL_SAFE_TYPE}Ptr(
|
||||
void* params,
|
||||
const char* identifier)
|
||||
{
|
||||
${MODEL_TYPE} *modelptr = IO::GetParam<${MODEL_TYPE}*>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
${MODEL_TYPE} *modelptr = p.Get<${MODEL_TYPE}*>(identifier);
|
||||
return modelptr;
|
||||
}
|
||||
")
|
||||
|
||||
@@ -26,9 +26,11 @@ if (${NUM_MODEL_TYPES} GREATER 0)
|
||||
# Generate the definition.
|
||||
set(MODEL_PTR_DEFNS "${MODEL_PTR_DEFNS}
|
||||
// Get the pointer to a ${MODEL_TYPE} parameter.
|
||||
void* IO_GetParam${MODEL_SAFE_TYPE}Ptr(const char* paramName);
|
||||
void* GetParam${MODEL_SAFE_TYPE}Ptr(void* params, const char* paramName);
|
||||
// Set the pointer to a ${MODEL_TYPE} parameter.
|
||||
void IO_SetParam${MODEL_SAFE_TYPE}Ptr(const char* paramName, void* ptr);
|
||||
void SetParam${MODEL_SAFE_TYPE}Ptr(void* params,
|
||||
const char* paramName,
|
||||
void* ptr);
|
||||
// Delete a ${MODEL_TYPE} pointer.
|
||||
void Delete${MODEL_SAFE_TYPE}Ptr(void* ptr);
|
||||
// Serialize a ${MODEL_TYPE} pointer.
|
||||
@@ -40,16 +42,20 @@ void* Deserialize${MODEL_SAFE_TYPE}Ptr(const char* buffer, const size_t length);
|
||||
# Generate the implementation.
|
||||
set(MODEL_PTR_IMPLS "${MODEL_PTR_IMPLS}
|
||||
// Get the pointer to a ${MODEL_TYPE} parameter.
|
||||
void* IO_GetParam${MODEL_SAFE_TYPE}Ptr(const char* paramName)
|
||||
void* GetParam${MODEL_SAFE_TYPE}Ptr(void* params, const char* paramName)
|
||||
{
|
||||
return (void*) IO::GetParam<${MODEL_TYPE}*>(paramName);
|
||||
util::Params* p = (util::Params*) params;
|
||||
return (void*) p->Get<${MODEL_TYPE}*>(paramName);
|
||||
}
|
||||
|
||||
// Set the pointer to a ${MODEL_TYPE} parameter.
|
||||
void IO_SetParam${MODEL_SAFE_TYPE}Ptr(const char* paramName, void* ptr)
|
||||
void SetParam${MODEL_SAFE_TYPE}Ptr(void* params,
|
||||
const char* paramName,
|
||||
void* ptr)
|
||||
{
|
||||
IO::GetParam<${MODEL_TYPE}*>(paramName) = (${MODEL_TYPE}*) ptr;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params* p = (util::Params*) params;
|
||||
p->Get<${MODEL_TYPE}*>(paramName) = (${MODEL_TYPE}*) ptr;
|
||||
p->SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Delete a ${MODEL_TYPE} pointer.
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This script gets the test coverage for mlpack_test.
|
||||
test_case="ALL"
|
||||
gcov_loc=""
|
||||
token=""
|
||||
clean=true
|
||||
current_log_file=`date +'%Y.%h.%d:%H:%M:%S-coverage.log'`
|
||||
current_coverage_file=`date +'%Y.%h.%d:%H:%M:%S-coverage.info'`
|
||||
max_cov_count=50000
|
||||
|
||||
# default directories
|
||||
root_dir="../"
|
||||
|
||||
# Extract arguments.
|
||||
for i in "$@"
|
||||
do
|
||||
case $i in
|
||||
-h|--help)
|
||||
echo "Usage: mlpack_coverage --help|-h"
|
||||
echo " mlpack_coverage [-r=test_suite] [-g=gcov_tool_location]"
|
||||
echo " [--token=coveralls_token]"
|
||||
echo "Optional parameters:"
|
||||
echo " -n|--no_test Do not run test before coverage computation"
|
||||
echo " -r|--run_test Run tests with specific test suite"
|
||||
echo " --no_clean Do not remove existing gcda file"
|
||||
echo " -g|--gcov_tool_location Gcov location if not default"
|
||||
echo " -t|--token Upload to coveralls with given token"
|
||||
echo " --max_cov_count Max line coverage count (default 50000)"
|
||||
echo " --root_dir Set the root directory from which gcov will be called. (default ../)"
|
||||
exit 0
|
||||
shift
|
||||
;;
|
||||
-n|--no_test)
|
||||
test_case=""
|
||||
shift
|
||||
;;
|
||||
-r=*|--run_test=*)
|
||||
test_case="${i#*=}"
|
||||
shift # past argument=value
|
||||
;;
|
||||
--no_clean)
|
||||
clean=false
|
||||
shift
|
||||
;;
|
||||
-g=*|--gcov_tool_location=*)
|
||||
gcov_loc="${i#*=}"
|
||||
shift # past argument=value
|
||||
;;
|
||||
-t=*|--token=*)
|
||||
token="${i#*=}"
|
||||
shift # past argument=value
|
||||
;;
|
||||
--max_cov_count)
|
||||
max_cov_count="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
--root_dir=*)
|
||||
root_dir="${i#*=}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$clean" = true ]; then
|
||||
echo "Deleting existing coverage data..."
|
||||
find ./ -name "*.gcda" -type f -delete
|
||||
fi
|
||||
|
||||
# Initial pass.
|
||||
echo "Generating primary coverage report."
|
||||
[[ -d ./coveragehistory/ ]] || mkdir coveragehistory
|
||||
lcov -b . -c -i -d ./ -o .coverage.wtest.base > ./coveragehistory/$current_log_file
|
||||
|
||||
# Run the tests.
|
||||
if [ "$test_case" = "ALL" ]; then
|
||||
echo "Running all the tests..."
|
||||
"@CMAKE_BINARY_DIR@"/bin/mlpack_test
|
||||
elif ! [ "$test_case" = "" ]; then
|
||||
echo "Running test suite: $test_case"
|
||||
"@CMAKE_BINARY_DIR@"/bin/mlpack_test --run_test=$test_case
|
||||
fi
|
||||
|
||||
# Generate coverage based on executed tests.
|
||||
echo "Computing coverage..."
|
||||
if [ "$gcov_loc" = "" ];
|
||||
then lcov -b . -c -d ./ -o .coverage.wtest.run >> ./coveragehistory/$current_log_file
|
||||
else
|
||||
lcov -b . -c -d ./ -o .coverage.wtest.run --gcov-tool=$gcov_loc >> ./coveragehistory/$current_log_file
|
||||
fi
|
||||
|
||||
echo "Filtering coverage files..."
|
||||
# Clear negative entries in coverage file
|
||||
sed -E 's/-([0-9]+)/$max_cov_count/g' -i .coverage.wtest.run
|
||||
# Merge coverage tracefiles.
|
||||
lcov -a .coverage.wtest.base -a .coverage.wtest.run -o .coverage.total >> ./coveragehistory/$current_log_file
|
||||
|
||||
# Filtering, extracting project files.
|
||||
lcov -e .coverage.total "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/*" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
|
||||
|
||||
# Filtering, removing test-files and main.cpp.
|
||||
lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/*/*_main.cpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
|
||||
lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/tests/*" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
|
||||
|
||||
# Remove untestable files.
|
||||
lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/core/util/gitversion.hpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
|
||||
lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/core/util/arma_config.hpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
|
||||
|
||||
# Extra: Replace /build/ with /src/ to unify directories.
|
||||
cat .coverage.total.filtered > .coverage.total
|
||||
|
||||
# Extra: Clear up previous data, create html folder.
|
||||
if [[ -d ./coverage/ ]] ; then
|
||||
rm -rf ./coverage/*
|
||||
else
|
||||
mkdir coverage
|
||||
fi
|
||||
|
||||
# Step 9: Generate webpage.
|
||||
genhtml -o ./coverage/ .coverage.total
|
||||
|
||||
# Extra: Preserve coverage file in coveragehistory folder.
|
||||
coverage_file=$current_coverage_file
|
||||
cp .coverage.total ./coveragehistory/$current_coverage_file
|
||||
|
||||
# Clean temporary coverage files.
|
||||
#rm .coverage.*
|
||||
|
||||
# Upload the result to coveralls if token is provided.
|
||||
if ! [ "$token" = "" ]; then
|
||||
cpp-coveralls -n -r $root_dir -b $root_dir -l ./coveragehistory/$current_coverage_file -t "$token" --max-cov-count $max_cov_count
|
||||
fi
|
||||
|
||||
+115
-172
@@ -1,21 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.3.2)
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(mlpack C CXX)
|
||||
|
||||
include(CMake/cotire.cmake)
|
||||
include(CMake/CheckHash.cmake)
|
||||
include(CMake/Autodownload.cmake)
|
||||
include(CMake/ConfigureCrossCompile.cmake)
|
||||
|
||||
# First, define all the compilation options.
|
||||
# We default to debugging mode for developers.
|
||||
option(DEBUG "Compile with debugging information." OFF)
|
||||
option(PROFILE "Compile with profiling information." OFF)
|
||||
option(ARMA_EXTRA_DEBUG "Compile with extra Armadillo debugging symbols." OFF)
|
||||
option(MATLAB_BINDINGS "Compile MATLAB bindings if MATLAB is found." OFF)
|
||||
option(TEST_VERBOSE "Run test cases with verbose output." OFF)
|
||||
option(BUILD_TESTS "Build tests." ON)
|
||||
option(BUILD_CLI_EXECUTABLES "Build command-line executables." ON)
|
||||
option(DISABLE_DOWNLOADS "Disable downloads of dependencies during build." OFF)
|
||||
option(DOWNLOAD_ENSMALLEN "If ensmallen is not found, download it." ON)
|
||||
option(DOWNLOAD_STB_IMAGE "Download stb_image for image loading." ON)
|
||||
option(BUILD_GO_SHLIB "Build Go shared library." OFF)
|
||||
option(BUILD_DOCS "Build doxygen documentation (if doxygen is available)." ON)
|
||||
|
||||
@@ -25,15 +24,29 @@ set(ENSMALLEN_VERSION "2.10.0")
|
||||
set(BOOST_VERSION "1.58")
|
||||
set(CEREAL_VERSION "1.1.2")
|
||||
|
||||
# If BUILD_SHARED_LIBS is OFF then the mlpack library will be built statically.
|
||||
# In addition, all mlpack CLI bindings will be linked statically as well.
|
||||
if (WIN32)
|
||||
option(BUILD_SHARED_LIBS
|
||||
"Compile shared libraries (if OFF, static libraries are compiled)." OFF)
|
||||
"Compile shared libraries (if OFF, static libraries and binaries are compiled)." OFF)
|
||||
|
||||
set(DLL_COPY_DIRS "" CACHE STRING "List of directories (separated by ';') containing DLLs to copy for runtime.")
|
||||
set(DLL_COPY_LIBS "" CACHE STRING "List of DLLs (separated by ';') that should be copied for runtime.")
|
||||
else ()
|
||||
elseif(CMAKE_CROSSCOMPILING)
|
||||
option(BUILD_SHARED_LIBS
|
||||
"Compile shared libraries (if OFF, static libraries are compiled)." ON)
|
||||
"Compile shared libraries (if OFF, static libraries and binaries are compiled)." OFF)
|
||||
else()
|
||||
option(BUILD_SHARED_LIBS
|
||||
"Compile shared libraries (if OFF, static libraries and binaries are compiled)." ON)
|
||||
endif()
|
||||
|
||||
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES.
|
||||
if (NOT BUILD_SHARED_LIBS)
|
||||
if(WIN32)
|
||||
list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a)
|
||||
else()
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Detect whether the user passed BUILD_PYTHON_BINDINGS in order to determine if
|
||||
@@ -80,8 +93,6 @@ option(BUILD_R_BINDINGS "Build R bindings." OFF)
|
||||
# generation.
|
||||
option(BUILD_MARKDOWN_BINDINGS "Build Markdown bindings for website documentation." OFF)
|
||||
|
||||
option(BUILD_WITH_COVERAGE
|
||||
"Build with support for code coverage tools (gcc only)." OFF)
|
||||
option(MATHJAX
|
||||
"Use MathJax for HTML Doxygen output (disabled by default)." OFF)
|
||||
option(FORCE_CXX11
|
||||
@@ -93,15 +104,14 @@ enable_testing()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Ensure that GCC is new enough, if the compiler is GCC.
|
||||
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
|
||||
message(FATAL_ERROR "GCC version (${CMAKE_CXX_COMPILER_VERSION}) is too old! 5.x or newer is required.")
|
||||
endif ()
|
||||
|
||||
# Include modules in the CMake directory.
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
|
||||
|
||||
# Disable any downloads if needed.
|
||||
if (DISABLE_DOWNLOADS)
|
||||
set(DOWNLOAD_ENSMALLEN OFF)
|
||||
set(DOWNLOAD_STB_IMAGE OFF)
|
||||
endif ()
|
||||
|
||||
# If we are on a Unix-like system, use the GNU install directories module.
|
||||
# Otherwise set the values manually.
|
||||
if (UNIX)
|
||||
@@ -115,12 +125,12 @@ else ()
|
||||
endif ()
|
||||
|
||||
# This is as of yet unused.
|
||||
#option(PGO "Use profile-guided optimization if not a debug build" ON)
|
||||
# option(PGO "Use profile-guided optimization if not a debug build" ON)
|
||||
|
||||
# Set the CFLAGS and CXXFLAGS depending on the options the user specified.
|
||||
# Only GCC-like compilers support -Wextra, and other compilers give tons of
|
||||
# output for -Wall, so only -Wall and -Wextra on GCC.
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if (CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# Ensure that we can't compile with clang 3.4, since this causes strange
|
||||
# issues.
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
|
||||
@@ -147,7 +157,7 @@ endif ()
|
||||
|
||||
# If we are using MINGW, we need sections and big-obj, otherwise we create too
|
||||
# many sections.
|
||||
if(CMAKE_COMPILER_IS_GNUCC AND WIN32)
|
||||
if (CMAKE_COMPILER_IS_GNUCC AND WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -Wa,-mbig-obj")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wa,-mbig-obj")
|
||||
endif()
|
||||
@@ -156,7 +166,7 @@ endif()
|
||||
# OS (at least on some systems). Further, gcc sometimes optimizes calls to
|
||||
# math.h functions, making -lm unnecessary with gcc, but it may still be
|
||||
# necessary with clang.
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if (APPLE)
|
||||
# Detect OS X version. Use '/usr/bin/sw_vers -productVersion' to
|
||||
# extract V from '10.V.x'.
|
||||
@@ -169,7 +179,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
|
||||
# OSX Lion (10.7) and OS X Mountain Lion (10.8) doesn't automatically
|
||||
# select the right stdlib.
|
||||
if(${MACOSX_VERSION} LESS 9)
|
||||
if (${MACOSX_VERSION} LESS 9)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS
|
||||
"${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
|
||||
@@ -190,46 +200,14 @@ endif()
|
||||
|
||||
# If we're using gcc, then we need to link against pthreads to use std::thread,
|
||||
# which we do in the tests.
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
if (CMAKE_COMPILER_IS_GNUCC)
|
||||
find_package(Threads)
|
||||
set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
# Setup build for test coverage
|
||||
if(BUILD_WITH_COVERAGE)
|
||||
# Currently coverage only works with GNU g++.
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
# Find gcov and lcov
|
||||
find_program(GCOV gcov)
|
||||
find_program(LCOV lcov)
|
||||
|
||||
if(NOT GCOV)
|
||||
message(FATAL_ERROR
|
||||
"gcov not found! gcov is required when BUILD_WITH_COVERAGE=ON.")
|
||||
endif()
|
||||
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "supc++")
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "quadmath")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -fkeep-inline-functions")
|
||||
message(STATUS "Adding debug compile options for code coverage.")
|
||||
# Remove optimizations for better line coverage
|
||||
set(DEBUG ON)
|
||||
|
||||
if(LCOV)
|
||||
configure_file(CMake/mlpack_coverage.in mlpack_coverage @ONLY)
|
||||
add_custom_target(mlpack_coverage DEPENDS mlpack_test COMMAND ${PROJECT_BINARY_DIR}/mlpack_coverage)
|
||||
else()
|
||||
message(WARNING "'lcov' not found; local coverage report is disabled. "
|
||||
"Install 'lcov' and rerun cmake to generate local coverage report.")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "BUILD_WITH_COVERAGE can only work with GNU environment.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Debugging CFLAGS. Turn optimizations off; turn debugging symbols on.
|
||||
if(DEBUG)
|
||||
if (DEBUG)
|
||||
if (NOT MSVC)
|
||||
add_definitions(-DDEBUG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -ftemplate-backtrace-limit=0")
|
||||
@@ -238,10 +216,10 @@ if(DEBUG)
|
||||
|
||||
# mlpack uses it's own mlpack::backtrace class based on Binary File Descriptor
|
||||
# <bfd.h> and linux Dynamic Loader <libdl.h> and more portable version in future
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
find_package(Bfd)
|
||||
find_package(LibDL)
|
||||
if(LIBBFD_FOUND AND LIBDL_FOUND)
|
||||
if (LIBBFD_FOUND AND LIBDL_FOUND)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${LIBBFD_INCLUDE_DIRS}
|
||||
${LIBDL_INCLUDE_DIRS})
|
||||
@@ -265,19 +243,19 @@ else()
|
||||
endif()
|
||||
|
||||
# Profiling CFLAGS. Turn profiling information on.
|
||||
if(CMAKE_COMPILER_IS_GNUCC AND PROFILE)
|
||||
if (CMAKE_COMPILER_IS_GNUCC AND PROFILE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
|
||||
endif()
|
||||
|
||||
# If the user asked for running test cases with verbose output, turn that on.
|
||||
if(TEST_VERBOSE)
|
||||
if (TEST_VERBOSE)
|
||||
add_definitions(-DTEST_VERBOSE)
|
||||
endif()
|
||||
|
||||
# If the user asked for extra Armadillo debugging output, turn that on.
|
||||
if(ARMA_EXTRA_DEBUG)
|
||||
if (ARMA_EXTRA_DEBUG)
|
||||
add_definitions(-DARMA_EXTRA_DEBUG)
|
||||
endif()
|
||||
|
||||
@@ -289,136 +267,87 @@ endif()
|
||||
# ARMADILLO_INCLUDE_DIRS - directories necessary for Armadillo includes
|
||||
# BOOST_ROOT - root of Boost installation
|
||||
# BOOST_INCLUDEDIR - include directory for Boost
|
||||
# CEREAL_INCLUDE_DIR - include directory for cereal
|
||||
# ENSMALLEN_INCLUDE_DIR - include directory for ensmallen
|
||||
# STB_IMAGE_INCLUDE_DIR - include directory for STB image library
|
||||
# MATHJAX_ROOT - root of MathJax installation
|
||||
find_package(Armadillo "${ARMADILLO_VERSION}" REQUIRED)
|
||||
|
||||
# Download and compile OpenBLAS if we are cross compiling mlpack for a specific
|
||||
# architecture. The function takes the version of OpenBLAS as variable.
|
||||
if (CMAKE_CROSSCOMPILING)
|
||||
search_openblas(0.3.13)
|
||||
endif()
|
||||
|
||||
if (DISABLE_DOWNLOADS)
|
||||
find_package(Armadillo "${ARMADILLO_VERSION}" REQUIRED)
|
||||
else()
|
||||
find_package(Armadillo "${ARMADILLO_VERSION}")
|
||||
if (NOT ARMADILLO_FOUND)
|
||||
if (NOT CMAKE_CROSSCOMPILING)
|
||||
find_package(BLAS QUIET)
|
||||
find_package(LAPACK QUIET)
|
||||
if (NOT BLAS_FOUND AND NOT LAPACK_FOUND)
|
||||
message(FATAL_ERROR "Can not find BLAS or LAPACK! These are required for Armadillo. Please install one of them---or install Armadillo---before installing mlpack.")
|
||||
endif()
|
||||
endif()
|
||||
get_deps(http://files.mlpack.org/armadillo-10.3.0.tar.gz armadillo armadillo-10.3.0.tar.gz)
|
||||
set(ARMADILLO_INCLUDE_DIR ${GENERIC_INCLUDE_DIR})
|
||||
find_package(Armadillo REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
# Include directories for the previous dependencies.
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS})
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${ARMADILLO_LIBRARIES})
|
||||
|
||||
# Find stb_image.h and stb_image_write.h.
|
||||
find_package(StbImage)
|
||||
# Download stb_image for image loading.
|
||||
if (NOT STB_IMAGE_FOUND)
|
||||
if (DOWNLOAD_STB_IMAGE)
|
||||
set(STB_DIR "stb")
|
||||
install(DIRECTORY DESTINATION "${CMAKE_BINARY_DIR}/deps/${STB_DIR}")
|
||||
file(DOWNLOAD http://mlpack.org/files/stb-2.22/stb_image.h
|
||||
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image.h"
|
||||
STATUS STB_IMAGE_DOWNLOAD_STATUS_LIST LOG STB_IMAGE_DOWNLOAD_LOG
|
||||
SHOW_PROGRESS)
|
||||
list(GET STB_IMAGE_DOWNLOAD_STATUS_LIST 0 STB_IMAGE_DOWNLOAD_STATUS)
|
||||
file(DOWNLOAD http://mlpack.org/files/stb-1.13/stb_image_write.h
|
||||
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image_write.h"
|
||||
STATUS STB_IMAGE_WRITE_DOWNLOAD_STATUS_LIST
|
||||
LOG STB_IMAGE_WRITE_DOWNLOAD_LOG
|
||||
SHOW_PROGRESS)
|
||||
list(GET STB_IMAGE_WRITE_DOWNLOAD_STATUS_LIST 0
|
||||
STB_IMAGE_WRITE_DOWNLOAD_STATUS)
|
||||
if (STB_IMAGE_DOWNLOAD_STATUS EQUAL 0 AND
|
||||
STB_IMAGE_WRITE_DOWNLOAD_STATUS EQUAL 0)
|
||||
check_hash (http://mlpack.org/files/stb/hash.md5 "${CMAKE_BINARY_DIR}/deps/${STB_DIR}"
|
||||
HASH_CHECK_FAIL)
|
||||
if (HASH_CHECK_FAIL EQUAL 0)
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS}
|
||||
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
|
||||
message(STATUS
|
||||
"Successfully downloaded stb into ${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
|
||||
# Now we have to also ensure these header files get installed.
|
||||
install(FILES "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
install(FILES "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image_write.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
add_definitions(-DHAS_STB)
|
||||
set(STB_AVAILABLE "1")
|
||||
else ()
|
||||
message(WARNING
|
||||
"stb/stb_image.h is not installed. Image utilities will not be available!")
|
||||
endif ()
|
||||
else ()
|
||||
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
|
||||
list(GET STB_IMAGE_DOWNLOAD_STATUS_LIST 1 STB_DOWNLOAD_ERROR)
|
||||
message(WARNING
|
||||
"Could not download stb! Error code ${STB_DOWNLOAD_STATUS}: ${STB_DOWNLOAD_ERROR}! Error log: ${STB_DOWNLOAD_LOG}")
|
||||
message(WARNING
|
||||
"stb/stb_image.h is not installed. Image utilities will not be available!")
|
||||
endif ()
|
||||
else ()
|
||||
message(WARNING
|
||||
"stb/stb_image.h is not installed. Image utilities will not be available!")
|
||||
endif ()
|
||||
else ()
|
||||
# Already has STB installed.
|
||||
if (DISABLE_DOWNLOADS)
|
||||
find_package(StbImage)
|
||||
else()
|
||||
find_package(StbImage)
|
||||
if (NOT STB_IMAGE_FOUND)
|
||||
get_deps(http://mlpack.org/files/stb.tar.gz stb stb.tar.gz)
|
||||
set(STB_IMAGE_INCLUDE_DIR ${GENERIC_INCLUDE_DIR})
|
||||
find_package(StbImage REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (STB_IMAGE_FOUND)
|
||||
add_definitions(-DHAS_STB)
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${STB_IMAGE_INCLUDE_DIR})
|
||||
set(STB_AVAILABLE "1")
|
||||
endif ()
|
||||
endif()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${STB_IMAGE_INCLUDE_DIR}")
|
||||
|
||||
# Find ensmallen.
|
||||
# Once ensmallen is readily available in package repos, the automatic downloader
|
||||
# here can be removed.
|
||||
find_package(Ensmallen "${ENSMALLEN_VERSION}")
|
||||
if (NOT ENSMALLEN_FOUND)
|
||||
if (DOWNLOAD_ENSMALLEN)
|
||||
file(DOWNLOAD http://www.ensmallen.org/files/ensmallen-latest.tar.gz
|
||||
"${CMAKE_BINARY_DIR}/deps/ensmallen-latest.tar.gz"
|
||||
STATUS ENS_DOWNLOAD_STATUS_LIST LOG ENS_DOWNLOAD_LOG
|
||||
SHOW_PROGRESS)
|
||||
list(GET ENS_DOWNLOAD_STATUS_LIST 0 ENS_DOWNLOAD_STATUS)
|
||||
if (ENS_DOWNLOAD_STATUS EQUAL 0)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E
|
||||
tar xzf "${CMAKE_BINARY_DIR}/deps/ensmallen-latest.tar.gz"
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/")
|
||||
if (DISABLE_DOWNLOADS)
|
||||
find_package(Ensmallen "${ENSMALLEN_VERSION}" REQUIRED)
|
||||
else()
|
||||
find_package(Ensmallen "${ENSMALLEN_VERSION}")
|
||||
if (NOT ENSMALLEN_FOUND)
|
||||
get_deps(http://www.ensmallen.org/files/ensmallen-latest.tar.gz ensmallen ensmallen-latest.tar.gz)
|
||||
set(ENSMALLEN_INCLUDE_DIR ${GENERIC_INCLUDE_DIR})
|
||||
find_package(Ensmallen REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${ENSMALLEN_INCLUDE_DIR}")
|
||||
|
||||
# Get the name of the directory.
|
||||
file (GLOB ENS_DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
|
||||
"${CMAKE_BINARY_DIR}/deps/ensmallen-[0-9]*.[0-9]*.[0-9]*")
|
||||
# list(FILTER) is not available on 3.5 or older, but try to keep
|
||||
# configuring without filtering the list anyway (it might work if only
|
||||
# the file ensmallen-latest.tar.gz is present.
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.6.0")
|
||||
list(FILTER ENS_DIRECTORIES EXCLUDE REGEX "ensmallen-.*\.tar\.gz")
|
||||
endif ()
|
||||
list(LENGTH ENS_DIRECTORIES ENS_DIRECTORIES_LEN)
|
||||
if (ENS_DIRECTORIES_LEN EQUAL 1)
|
||||
list(GET ENS_DIRECTORIES 0 ENSMALLEN_INCLUDE_DIR)
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS}
|
||||
"${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include")
|
||||
message(STATUS
|
||||
"Successfully downloaded ensmallen into ${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/")
|
||||
|
||||
# Now we have to also ensure these header files get installed.
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include/ensmallen_bits/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ensmallen_bits")
|
||||
install(FILES "${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include/ensmallen.hpp" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
else ()
|
||||
message(FATAL_ERROR "Problem unpacking ensmallen! Expected only one directory ensmallen-x.y.z/; found ${ENS_DIRECTORIES}. Try removing the directory ${CMAKE_BINARY_DIR}/deps and reconfiguring.")
|
||||
endif ()
|
||||
else ()
|
||||
list(GET ENS_DOWNLOAD_STATUS_LIST 1 ENS_DOWNLOAD_ERROR)
|
||||
message(FATAL_ERROR
|
||||
"Could not download ensmallen! Error code ${ENS_DOWNLOAD_STATUS}: ${ENS_DOWNLOAD_ERROR}! Error log: ${ENS_DOWNLOAD_LOG}")
|
||||
endif ()
|
||||
else ()
|
||||
# Release versions will have ensmallen packaged with the release so we can
|
||||
# just reference that.
|
||||
if (EXISTS "${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen/ensmallen.hpp")
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS}
|
||||
"${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen")
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"Cannot find ensmallen headers! Try setting ENSMALLEN_INCLUDE_DIR!")
|
||||
endif ()
|
||||
endif ()
|
||||
else ()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${ENSMALLEN_INCLUDE_DIR}")
|
||||
endif ()
|
||||
|
||||
find_package(cereal "${CEREAL_VERSION}" REQUIRED)
|
||||
# Find cereal.
|
||||
if (DISABLE_DOWNLOADS)
|
||||
find_package(cereal "${CEREAL_VERSION}" REQUIRED)
|
||||
else()
|
||||
find_package(cereal "${CEREAL_VERSION}")
|
||||
if (NOT CEREAL_FOUND)
|
||||
get_deps(https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.0.tar.gz cereal cereal-1.3.0.tar.gz)
|
||||
set(CEREAL_INCLUDE_DIR ${GENERIC_INCLUDE_DIR})
|
||||
find_package(cereal REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${CEREAL_INCLUDE_DIR})
|
||||
|
||||
# Unfortunately this configuration variable is necessary and will need to be
|
||||
# updated as time goes on and new versions are released.
|
||||
set(Boost_ADDITIONAL_VERSIONS
|
||||
"1.77.0" "1.77"
|
||||
"1.76.0" "1.76"
|
||||
"1.75.0" "1.75"
|
||||
"1.74.0" "1.74"
|
||||
"1.73.0" "1.73"
|
||||
@@ -443,8 +372,19 @@ set(Boost_ADDITIONAL_VERSIONS
|
||||
# TODO for the brave: transition all mlpack's CMake to 'target-based modern
|
||||
# CMake'. Good luck! You'll need it.
|
||||
set(Boost_NO_BOOST_CMAKE 1)
|
||||
find_package(Boost "${BOOST_VERSION}")
|
||||
|
||||
if (DISABLE_DOWNLOADS)
|
||||
find_package(Boost "${BOOST_VERSION}" REQUIRED)
|
||||
else()
|
||||
find_package(Boost "${BOOST_VERSION}")
|
||||
if (NOT Boost_FOUND)
|
||||
if (CMAKE_COMPILER_IS_GNUCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
|
||||
get_deps(http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.gz boost boost_1_58_0.tar.gz)
|
||||
else()
|
||||
get_deps(https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz boost boost_1_76_0.tar.gz)
|
||||
endif()
|
||||
find_package(Boost REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES})
|
||||
set(MLPACK_LIBRARY_DIRS ${MLPACK_LIBRARY_DIRS})
|
||||
@@ -467,6 +407,9 @@ if (OPENMP_FOUND)
|
||||
add_definitions(-DHAS_OPENMP)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
if (OpenMP_CXX_FOUND)
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${OpenMP_CXX_LIBRARIES})
|
||||
endif ()
|
||||
else ()
|
||||
# Disable warnings for all the unknown OpenMP pragmas.
|
||||
if (NOT MSVC)
|
||||
|
||||
@@ -141,6 +141,10 @@ Copyright:
|
||||
Copyright 2020, Alex Nguyen <alexvn.edu@gmail.com>
|
||||
Copyright 2020, Gaurav Ghati <gauravghatii@gmail.com>
|
||||
Copyright 2020, Anmolpreet Singh <anmol323c@gmail.com>
|
||||
Copyright 2021, Tru Hoang <trugiahoang@gmail.com>
|
||||
Copyright 2021, Mark Fischinger <markfischinger@gmail.com>
|
||||
Copyright 2021, Muhammad Fawwaz Mayda <maydafawwaz@gmail.com>
|
||||
Copyright 2021, Roshan Nrusing Swain <swainroshan001@gmail.com>
|
||||
|
||||
License: BSD-3-clause
|
||||
All rights reserved.
|
||||
|
||||
+36
-1
@@ -2,7 +2,20 @@
|
||||
###### ????-??-??
|
||||
* Added `Multi Label Soft Margin Loss` loss function for neural networks
|
||||
(#2345).
|
||||
|
||||
|
||||
* Added Decision Tree Regressor (#2905). It can be used using the class
|
||||
`mlpack::tree::DecisionTreeRegressor`. It is accessible only though C++.
|
||||
|
||||
* Added dict-style inspection of mlpack models in python bindings (#2868).
|
||||
|
||||
* Added Extra Trees Algorithm (#2883). Currently, it can be used using the
|
||||
class `mlpack::tree::ExtraTrees`, but only through C++.
|
||||
|
||||
* Add Flatten T Swish activation function (`flatten-t-swish.hpp`)
|
||||
|
||||
* Added warm start feature to Random Forest (#2881); this feature is
|
||||
accessible from mlpack's bindings to different languages.
|
||||
|
||||
* Added Pixel Shuffle layer (#2563).
|
||||
|
||||
* Add "check_input_matrices" option to python bindings that checks
|
||||
@@ -37,6 +50,28 @@
|
||||
* `NegativeLogLikelihood<>` now expects classes in the range `0` to
|
||||
`numClasses - 1` (#2534).
|
||||
|
||||
* Add `Lambda1()`, `Lambda2()`, `UseCholesky()`, and `Tolerance()` members to
|
||||
`LARS` so parameters for training can be modified (#2861).
|
||||
|
||||
* Remove unused `ElemType` template parameter from `DecisionTree` and
|
||||
`RandomForest` (#2874).
|
||||
|
||||
* Fix Python binding build when the CMake variable `USE_OPENMP` is set to
|
||||
`OFF` (#2884).
|
||||
|
||||
* The `mlpack_test` target is no longer built as part of `make all`. Use
|
||||
`make mlpack_test` to build the tests.
|
||||
|
||||
* Fixes to `HoeffdingTree`: ensure that training still works when empty
|
||||
constructor is used (#2964).
|
||||
|
||||
* Fix Julia model serialization bug (#2970).
|
||||
|
||||
* Fix `LoadCSV()` to use pre-populated `DatasetInfo` objects (#2980).
|
||||
|
||||
* Add `probabilities` option to softmax regression binding, to get class
|
||||
probabilities for test points (#3001).
|
||||
|
||||
### mlpack 3.4.2
|
||||
###### 2020-10-26
|
||||
* Added Mean Absolute Percentage Error.
|
||||
|
||||
@@ -14,8 +14,7 @@ src="https://cdn.rawgit.com/mlpack/mlpack.org/e7d36ed8/mlpack-black.svg" style="
|
||||
</h5>
|
||||
|
||||
<p align="center">
|
||||
<a href="http://ci.mlpack.org/job/mlpack%20-%20git%20commit%20test/"><img src="https://img.shields.io/jenkins/build.svg?jobUrl=http%3A%2F%2Fci.mlpack.org%2Fjob%2Fmlpack%2520-%2520git%2520commit%2520test%2F&label=Linux%20build&style=flat-square" alt="Jenkins"></a>
|
||||
<a href="https://coveralls.io/github/mlpack/mlpack?branch=master"><img src="https://img.shields.io/coveralls/mlpack/mlpack/master.svg?style=flat-square" alt="Coveralls"></a>
|
||||
<a href="https://dev.azure.com/mlpack/mlpack/_build?definitionId=1"><img alt="Azure DevOps builds (job)" src="https://img.shields.io/azure-devops/build/mlpack/84320e87-76e3-4b6e-8b6e-3adaf6b36eed/1/master?job=Linux&label=Linux%20Build&style=flat-square"></a>
|
||||
<a href="https://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/License-BSD%203--Clause-blue.svg?style=flat-square" alt="License"></a>
|
||||
<a href="http://numfocus.org/donate-to-mlpack"><img src="https://img.shields.io/badge/sponsored%20by-NumFOCUS-orange.svg?style=flat-square&colorA=E1523D&colorB=007D8A" alt="NumFOCUS"></a>
|
||||
</p>
|
||||
@@ -102,7 +101,7 @@ mlpack has the following dependencies:
|
||||
|
||||
Armadillo >= 8.400.0
|
||||
Boost (math_c99, spirit) >= 1.58.0
|
||||
CMake >= 3.2.2
|
||||
CMake >= 3.6
|
||||
ensmallen >= 2.10.0
|
||||
cereal >= 1.1.2
|
||||
|
||||
@@ -142,10 +141,10 @@ If you are compiling Armadillo by hand, ensure that LAPACK and BLAS are enabled.
|
||||
|
||||
### 4. Building mlpack from source
|
||||
|
||||
This document discusses how to build mlpack from source. These build directions
|
||||
This document discusses how to build mlpack from source. These build directions
|
||||
will work for any Linux-like shell environment (for example Ubuntu, macOS,
|
||||
FreeBSD etc). However, mlpack is in the repositories of many Linux distributions
|
||||
and so it may be easier to use the package manager for your system. For example,
|
||||
FreeBSD etc). However, mlpack is in the repositories of many Linux distributions
|
||||
and so it may be easier to use the package manager for your system. For example,
|
||||
on Ubuntu, you can install the mlpack library and command-line executables (e.g.
|
||||
mlpack_pca, mlpack_kmeans etc.) with the following command:
|
||||
|
||||
@@ -154,11 +153,16 @@ mlpack_pca, mlpack_kmeans etc.) with the following command:
|
||||
On Fedora or Red Hat (EPEL):
|
||||
$ sudo dnf install mlpack-devel mlpack-bin
|
||||
|
||||
Note: Older Ubuntu versions may not have the most recent version of mlpack
|
||||
*Note*: Older Ubuntu versions may not have the most recent version of mlpack
|
||||
available---for instance, at the time of this writing, Ubuntu 16.04 only has
|
||||
mlpack 3.4.2 available. Options include upgrading your Ubuntu version, finding
|
||||
a PPA or other non-official sources, or installing with a manual build.
|
||||
|
||||
*Note*: If you are using RHEL7/CentOS 7, gcc 4.8 is too old to compile mlpack.
|
||||
One option is to use `devtoolset-8`; see
|
||||
[here](https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/) for more
|
||||
information.
|
||||
|
||||
There are some useful pages to consult in addition to this section:
|
||||
|
||||
- [Building mlpack From Source](https://www.mlpack.org/doc/mlpack-git/doxygen/build.html)
|
||||
@@ -183,7 +187,7 @@ sufficient.
|
||||
|
||||
The next step is to run CMake to configure the project. Running CMake is the
|
||||
equivalent to running `./configure` with autotools. If you run CMake with no
|
||||
options, it will configure the project to build with no debugging symbols and
|
||||
options, it will configure the project to build with no debugging symbols and
|
||||
no profiling information:
|
||||
|
||||
$ cmake ../
|
||||
@@ -212,19 +216,22 @@ Options are specified with the -D flag. The allowed options include:
|
||||
BUILD_R_BINDINGS=(ON/OFF): whether or not to build R bindings
|
||||
R_EXECUTABLE=(/path/to/R): Path to specific R executable
|
||||
BUILD_TESTS=(ON/OFF): whether or not to build tests
|
||||
BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries as opposed to
|
||||
static libraries
|
||||
BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries and executables as
|
||||
opposed to static libraries
|
||||
DISABLE_DOWNLOADS=(ON/OFF): whether to disable all downloads during build
|
||||
DOWNLOAD_ENSMALLEN=(ON/OFF): If ensmallen is not found, download it
|
||||
ENSMALLEN_INCLUDE_DIR=(/path/to/ensmallen/include): path to include directory
|
||||
for ensmallen
|
||||
DOWNLOAD_STB_IMAGE=(ON/OFF): If STB is not found, download it
|
||||
STB_IMAGE_INCLUDE_DIR=(/path/to/stb/include): path to include directory for
|
||||
STB image library
|
||||
USE_OPENMP=(ON/OFF): whether or not to use OpenMP if available
|
||||
BUILD_DOCS=(ON/OFF): build Doxygen documentation, if Doxygen is available
|
||||
(default ON)
|
||||
|
||||
For example, to build mlpack library and CLI bindings statically the following
|
||||
command can be used:
|
||||
|
||||
$ cmake -D BUILD_SHARED_LIBS=OFF ../
|
||||
|
||||
Other tools can also be used to configure CMake, but those are not documented
|
||||
here. See [this section of the build guide](https://www.mlpack.org/doc/mlpack-git/doxygen/build.html#build_config)
|
||||
for more details, including a full list of options, and their default values.
|
||||
@@ -235,15 +242,21 @@ also be built. OpenMP will be used for parallelization when possible by
|
||||
default.
|
||||
|
||||
Once CMake is configured, building the library is as simple as typing 'make'.
|
||||
This will build all library components as well as 'mlpack_test'.
|
||||
This will build all library components and bindings.
|
||||
|
||||
$ make
|
||||
|
||||
If you do not want to build everything in the library, individual components
|
||||
If you do not want to build everything in the library, individual components
|
||||
of the build can be specified:
|
||||
|
||||
$ make mlpack_pca mlpack_knn mlpack_kfn
|
||||
|
||||
If you want to build the tests, just make the `mlpack_test` target, and use
|
||||
`ctest` to run the tests:
|
||||
|
||||
$ make mlpack_test
|
||||
$ ctest .
|
||||
|
||||
If the build fails and you cannot figure out why, register an account on Github
|
||||
and submit an issue. The mlpack developers will quickly help you figure it out:
|
||||
|
||||
@@ -252,7 +265,7 @@ and submit an issue. The mlpack developers will quickly help you figure it out:
|
||||
Alternately, mlpack help can be found in IRC at `#mlpack` on chat.freenode.net.
|
||||
|
||||
If you wish to install mlpack to `/usr/local/include/mlpack/`, `/usr/local/lib/`,
|
||||
and `/usr/local/bin/`, make sure you have root privileges (or write permissions
|
||||
and `/usr/local/bin/`, make sure you have root privileges (or write permissions
|
||||
to those three directories), and simply type
|
||||
|
||||
$ make install
|
||||
@@ -356,6 +369,9 @@ older versions of mlpack:
|
||||
- [Development Site (Github)](https://www.github.com/mlpack/mlpack/)
|
||||
- [API documentation (Doxygen)](https://www.mlpack.org/doc/mlpack-git/doxygen/index.html)
|
||||
|
||||
To learn about the development goals of mlpack in the short- and medium-term
|
||||
future, see the [vision document](https://www.mlpack.org/papers/vision.pdf).
|
||||
|
||||
### 8. Bug reporting
|
||||
|
||||
(see also [mlpack help](https://www.mlpack.org/questions.html))
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
## This file handles cross-compilation configurations for aarch64,
|
||||
## known as arm64. The objective of this file is to find and assign
|
||||
## cross-compiler and the entire toolchain.
|
||||
##
|
||||
## This configuration works best with the buildroot toolchain. When using this
|
||||
## file, be sure to set the TOOLCHAIN_PREFIX and CMAKE_SYSROOT variables,
|
||||
## preferably via the CMake configuration command (e.g. `-DCMAKE_SYSROOT=<...>`).
|
||||
##
|
||||
## Currently, we recommend using buildroot toolchain for
|
||||
## cross-compilation. Here is the link to download the toolchains:
|
||||
## https://toolchains.bootlin.com/
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSROOT)
|
||||
set(TOOLCHAIN_PREFIX "" CACHE STRING "Path for toolchain for cross compiler and other compilation tools.")
|
||||
|
||||
# Ensure that CMake tries to build static libraries when testing the compiler.
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
set(CMAKE_AR "${TOOLCHAIN_PREFIX}gcc-ar" CACHE FILEPATH "" FORCE)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_C_ARCHIVE_FINISH true)
|
||||
set(CMAKE_FORTRAN_COMPILER ${TOOLCHAIN_PREFIX}gfortran)
|
||||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
|
||||
set(CMAKE_SIZE_UTIL ${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool")
|
||||
|
||||
## Here are the standard ROOT_PATH if you are using the standard toolchain
|
||||
## if you are using a different toolchain you have to specify that too.
|
||||
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_SYSROOT}" CACHE INTERNAL "" FORCE)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
@@ -0,0 +1,69 @@
|
||||
# This function provides a set of specific flags for each supported board
|
||||
# depending on the processor type. The objective is to optimize for size.
|
||||
# Thus, all of the following flags are chosen carefully to reduce binary
|
||||
# footprints.
|
||||
|
||||
# Set generic minimization flags for all platforms.
|
||||
# These flags are the same for all cross-compilation cases.
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fno-unwind-tables")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-asynchronous-unwind-tables -fvisibility=hidden")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fshort-enums -finline-small-functions")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -findirect-inlining -fno-common")
|
||||
#-flto -fuse-ld=gold # There is an issue with gold link when compiling on
|
||||
# Ubuntu 16. At that point gcc linker did not integrate the flto support
|
||||
# inside and it was a separate plugin that need to be added. Therefore,
|
||||
# this can be added when mlpack Azure CI moves toward Ubuntu 20.
|
||||
|
||||
set(BOARD_NAME "" CACHE STRING "Specify Board name to optimize for.")
|
||||
string(TOUPPER ${BOARD_NAME} BOARD)
|
||||
|
||||
# Set specific platforms CMAKE CXX flags.
|
||||
if(BOARD MATCHES "RPI0" OR BOARD MATCHES "RPI1")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=arm1176jzf-s")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "ARMV6")
|
||||
set(OPENBLAS_BINARY "32")
|
||||
elseif(BOARD MATCHES "RPI2")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=cortex-a7")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "ARMV7")
|
||||
set(OPENBLAS_BINARY "32")
|
||||
elseif(BOARD MATCHES "RPI3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=cortex-a53")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "CORTEXA53")
|
||||
set(OPENBLAS_BINARY "64")
|
||||
elseif(BOARD MATCHES "RPI4")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=cortex-a72")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "CORTEXA72")
|
||||
set(OPENBLAS_BINARY "64")
|
||||
elseif(BOARD MATCHES "BV")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "RISCV64_GENERIC")
|
||||
set(OPENBLAS_BINARY "64")
|
||||
elseif(BOARD MATCHES "JETSONAGX")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -matune=cortex-a76")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "ARM8")
|
||||
set(OPENBLAS_BINARY "64")
|
||||
elseif(BOARD MATCHES "KATAMI")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium3")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "KATAMI")
|
||||
set(OPENBLAS_BINARY "32")
|
||||
elseif(BOARD MATCHES "COPPERMINE")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium3")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "COPPERMINE")
|
||||
set(OPENBLAS_BINARY "32")
|
||||
elseif(BOARD MATCHES "NORTHWOOD")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium4")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(OPENBLAS_TARGET "NORTHWOOD")
|
||||
set(OPENBLAS_BINARY "32")
|
||||
elseif(BOARD)
|
||||
## TODO: update documentation with a list of the supported boards.
|
||||
message(FATAL_ERROR "Given BOARD_NAME is not known; please choose a supported board from the list")
|
||||
endif()
|
||||
+36
-19
@@ -63,6 +63,10 @@ $ sudo make install
|
||||
If the \c cmake \c .. command fails, you are probably missing a dependency, so
|
||||
check the output and install any necessary libraries. (See \ref build_dep.)
|
||||
|
||||
@note If you are using RHEL7/CentOS 7, the default version of gcc is too old.
|
||||
One solution is to use \c devtoolset-8; more information is available at
|
||||
https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/ .
|
||||
|
||||
On many Linux systems, mlpack will install by default to @c /usr/local/lib and
|
||||
you may need to set the @c LD_LIBRARY_PATH environment variable:
|
||||
|
||||
@@ -170,25 +174,25 @@ The full list of options mlpack allows:
|
||||
- PROFILE=(ON/OFF): compile with profiling symbols (default OFF)
|
||||
- ARMA_EXTRA_DEBUG=(ON/OFF): compile with extra Armadillo debugging symbols
|
||||
(default OFF)
|
||||
- BUILD_TESTS=(ON/OFF): compile the \c mlpack_test program (default ON)
|
||||
- BUILD_TESTS=(ON/OFF): compile the \c mlpack_test program when `make` is run
|
||||
(default ON)
|
||||
- BUILD_CLI_EXECUTABLES=(ON/OFF): compile the mlpack command-line executables
|
||||
(i.e. \c mlpack_knn, \c mlpack_kfn, \c mlpack_logistic_regression, etc.)
|
||||
(default ON)
|
||||
- BUILD_PYTHON_BINDINGS=(ON/OFF): compile the bindings for Python, if the
|
||||
necessary Python libraries are available (default ON except on Windows)
|
||||
necessary Python libraries are available (default OFF)
|
||||
- BUILD_R_BINDINGS=(ON/OFF): compile the bindings for R, if R is found
|
||||
(default OFF)
|
||||
- BUILD_GO_BINDINGS=(ON/OFF): compile Go bindings, if Go and the necessary Go
|
||||
and Gonum exist. (default OFF)
|
||||
- BUILD_JULIA_BINDINGS=(ON/OFF): compile Julia bindings, if Julia is found
|
||||
(default ON)
|
||||
- BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries as opposed to
|
||||
(default OFF)
|
||||
- BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries and executables as opposed to
|
||||
static libraries (default ON)
|
||||
- TEST_VERBOSE=(ON/OFF): run test cases in \c mlpack_test with verbose output
|
||||
(default OFF)
|
||||
- DISABLE_DOWNLOADS=(ON/OFF): Disable downloads of dependencies during build
|
||||
(default OFF)
|
||||
- DOWNLOAD_ENSMALLEN=(ON/OFF): If ensmallen is not found, download it
|
||||
(default ON)
|
||||
- DOWNLOAD_STB_IMAGE=(ON/OFF): If STB is not found, download it (default ON)
|
||||
- BUILD_WITH_COVERAGE=(ON/OFF): Build with support for code coverage tools
|
||||
(gcc only) (default OFF)
|
||||
- PYTHON_EXECUTABLE=(/path/to/python_version): Path to specific Python executable
|
||||
- PYTHON_INSTALL_PREFIX=(/path/to/python/): Path to root of Python installation
|
||||
- JULIA_EXECUTABLE=(/path/to/julia): Path to specific Julia executable
|
||||
@@ -207,6 +211,14 @@ The full list of options mlpack allows:
|
||||
Each option can be specified to CMake with the '-D' flag. Other tools can also
|
||||
be used to configure CMake, but those are not documented here.
|
||||
|
||||
For example, if you would like to build mlpack and its CLI bindings statically, then
|
||||
you need to execute the following commands:
|
||||
|
||||
@code
|
||||
$ cd build
|
||||
$ cmake -D BUILD_SHARED_LIBS=OFF ../
|
||||
@endcode
|
||||
|
||||
In addition, the following directories may be specified, to find include files
|
||||
and libraries. These also use the '-D' flag.
|
||||
|
||||
@@ -214,23 +226,21 @@ and libraries. These also use the '-D' flag.
|
||||
- ARMADILLO_LIBRARY=(/path/to/armadillo/libarmadillo.so): location of Armadillo
|
||||
library
|
||||
- BOOST_ROOT=(/path/to/boost/): path to root of boost installation
|
||||
- CEREAL_INCLUDE_DIR=(/path/to/cereal/include): path to include directory for
|
||||
cereal
|
||||
- ENSMALLEN_INCLUDE_DIR=(/path/to/ensmallen/include): path to include directory
|
||||
for ensmallen
|
||||
- STB_IMAGE_INCLUDE_DIR=(/path/to/stb/include): path to include directory for
|
||||
STB image library
|
||||
STB image library
|
||||
- MATHJAX_ROOT=(/path/to/mathjax): path to root of MathJax installation
|
||||
|
||||
@section build_build Building mlpack
|
||||
|
||||
Once CMake is configured, building the library is as simple as typing 'make'.
|
||||
This will build all library components as well as 'mlpack_test'.
|
||||
This will build all library components.
|
||||
|
||||
@code
|
||||
$ make
|
||||
Scanning dependencies of target mlpack
|
||||
[ 1%] Building CXX object
|
||||
src/mlpack/CMakeFiles/mlpack.dir/core/optimizers/aug_lagrangian/aug_lagrangian_test_functions.cpp.o
|
||||
<...>
|
||||
@endcode
|
||||
|
||||
It's often useful to specify \c -jN to the \c make command, which will build on
|
||||
@@ -245,17 +255,24 @@ $ make mlpack_pca mlpack_knn mlpack_kfn
|
||||
@endcode
|
||||
|
||||
One particular component of interest is mlpack_test, which runs the mlpack test
|
||||
suite. You can build this component with
|
||||
suite. This is not built when @c make is run. You can build this component
|
||||
with
|
||||
|
||||
@code
|
||||
$ make mlpack_test
|
||||
@endcode
|
||||
|
||||
We use <a href="https://github.com/catchorg/Catch2">Catch2</a> to write our tests.
|
||||
To run all tests, you can simply run:
|
||||
To run all tests, you can simply use CTest:
|
||||
|
||||
@code
|
||||
$ ./bin/mlpack_test
|
||||
$ ctest .
|
||||
@endcode
|
||||
|
||||
Or, you can run the test suite manually:
|
||||
|
||||
@code
|
||||
$ bin/mlpack_test
|
||||
@endcode
|
||||
|
||||
To run all tests in a particular file you can run:
|
||||
@@ -264,7 +281,7 @@ To run all tests in a particular file you can run:
|
||||
$ ./bin/mlpack_test "[testname]"
|
||||
@endcode
|
||||
|
||||
where testname is the name of the test suite.
|
||||
where testname is the name of the test suite.
|
||||
For example to run all collaborative filtering tests implemented in cf_test.cpp you can run:
|
||||
|
||||
@code
|
||||
|
||||
@@ -46,6 +46,7 @@ A list of all the sections this tutorial contains.
|
||||
- \ref cli_ex2_lrtut
|
||||
- \ref cli_ex3_lrtut
|
||||
- \ref cli_ex4_lrtut
|
||||
- \ref cli_ex5_lrtut
|
||||
- \ref linreg_lrtut
|
||||
- \ref linreg_ex1_lrtut
|
||||
- \ref linreg_ex2_lrtut
|
||||
@@ -113,22 +114,23 @@ $ cat dataset.csv
|
||||
4,4
|
||||
|
||||
$ cat lr.xml
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<!DOCTYPE boost_serialization>
|
||||
<boost_serialization signature="serialization::archive" version="12">
|
||||
<linearRegressionModel class_id="0" tracking_level="0" version="0">
|
||||
<parameters class_id="1" tracking_level="0" version="0">
|
||||
<n_rows>2</n_rows>
|
||||
<n_cols>1</n_cols>
|
||||
<n_elem>2</n_elem>
|
||||
<vec_state>1</vec_state>
|
||||
<item>-3.97205464519563669e-16</item>
|
||||
<item>1.00000000000000022e+00</item>
|
||||
</parameters>
|
||||
<lambda>0.00000000000000000e+00</lambda>
|
||||
<intercept>1</intercept>
|
||||
</linearRegressionModel>
|
||||
</boost_serialization>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<cereal>
|
||||
<model>
|
||||
<cereal_class_version>0</cereal_class_version>
|
||||
<parameters>
|
||||
<n_rows>2</n_rows>
|
||||
<n_cols>1</n_cols>
|
||||
<vec_state>1</vec_state>
|
||||
<elem>0</elem>
|
||||
<elem>1</elem>
|
||||
</parameters>
|
||||
<lambda>0</lambda>
|
||||
<intercept>true</intercept>
|
||||
</model>
|
||||
</cereal>
|
||||
|
||||
|
||||
@endcode
|
||||
|
||||
As you can see, the function for this input is \f$f(y)=0+1x_1\f$. We can see
|
||||
@@ -141,36 +143,102 @@ dataset is one dimensional, and the last column has the \f$y\f$ values, or
|
||||
responses, for each row. You can specify these responses in a separate file if
|
||||
you want, using the \c --input_responses, or \c -r, option.
|
||||
|
||||
@subsection cli_ex2_lrtut Compute model and predict at the same time
|
||||
@subsection cli_ex2_lrtut Train a multivariate linear regression model
|
||||
|
||||
Multivariate linear regression means that the response variable is predicted by
|
||||
more than just one input variable. In this example we will try to fit a
|
||||
multivariate linear regression model to data that contains four variables, stored in
|
||||
\c dataset_2.csv.
|
||||
|
||||
@code
|
||||
$ mlpack_linear_regression --training_file dataset.csv --test_file predict.csv \
|
||||
$ cat dataset_2.csv
|
||||
0,0,0,0,14
|
||||
1,1,1,1,24
|
||||
2,1,0,2,27
|
||||
1,2,2,2,32
|
||||
-1,-3,0,2,17
|
||||
@endcode
|
||||
|
||||
Now let's run \c mlpack_linear_regression as usual:
|
||||
|
||||
@code
|
||||
$ mlpack_linear_regression --training_file dataset_2.csv -v -M lr.xml
|
||||
[INFO ] Loading 'dataset_2.csv' as CSV data. Size is 5 x 5.
|
||||
[INFO ]
|
||||
[INFO ] Execution parameters:
|
||||
[INFO ] help: 0
|
||||
[INFO ] info:
|
||||
[INFO ] input_model_file:
|
||||
[INFO ] lambda: 0
|
||||
[INFO ] output_model_file: lr.xml
|
||||
[INFO ] output_predictions_file:
|
||||
[INFO ] test_file:
|
||||
[INFO ] training_file: dataset_2.csv
|
||||
[INFO ] training_responses_file:
|
||||
[INFO ] verbose: 1
|
||||
[INFO ] version: 0
|
||||
[INFO ] Program timers:
|
||||
[INFO ] load_regressors: 0.000060s
|
||||
[INFO ] loading_data: 0.000050s
|
||||
[INFO ] regression: 0.000049s
|
||||
[INFO ] total_time: 0.000118s
|
||||
|
||||
$ cat lr.xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<cereal>
|
||||
<model>
|
||||
<cereal_class_version>0</cereal_class_version>
|
||||
<parameters>
|
||||
<n_rows>5</n_rows>
|
||||
<n_cols>1</n_cols>
|
||||
<vec_state>1</vec_state>
|
||||
<elem>14.00000000000002</elem>
|
||||
<elem>1.9999999999999447</elem>
|
||||
<elem>1.0000000000000431</elem>
|
||||
<elem>2.9999999999999516</elem>
|
||||
<elem>4.0000000000000249</elem>
|
||||
</parameters>
|
||||
<lambda>0</lambda>
|
||||
<intercept>true</intercept>
|
||||
</model>
|
||||
</cereal>
|
||||
@endcode
|
||||
|
||||
If we take a look at the \c lr.xml output we can see the \c \<parameters\> part has five elements which
|
||||
the first corresponds to \f$\beta_0\f$ , the second corresponds to \f$\beta_1\f$ , and so on. This is equivalent
|
||||
to \f$f(y) = \beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_3 + \beta_4x_4\f$ or \f$f(y)=14+2x_1+1x_2+3x_3+4x_4\f$.
|
||||
|
||||
@subsection cli_ex3_lrtut Compute model and predict at the same time
|
||||
|
||||
@code
|
||||
$ mlpack_linear_regression --training_file dataset.csv --test_file predict.csv --output_predictions_file predictions.csv \
|
||||
> -v
|
||||
[WARN ] '--output_predictions_file (-o)' ignored because '--test_file (-T)' is specified!
|
||||
[INFO ] Loading 'dataset.csv' as CSV data. Size is 2 x 5.
|
||||
[INFO ] Loading 'predict.csv' as raw ASCII formatted data. Size is 1 x 3.
|
||||
[INFO ] Saving CSV data to 'predictions.csv'.
|
||||
[INFO ]
|
||||
[INFO ]
|
||||
[INFO ] Execution parameters:
|
||||
[INFO ] help: false
|
||||
[INFO ] info: ""
|
||||
[INFO ] input_model_file: ""
|
||||
[INFO ] help: 0
|
||||
[INFO ] info:
|
||||
[INFO ] input_model_file:
|
||||
[INFO ] lambda: 0
|
||||
[INFO ] output_model_file: ""
|
||||
[INFO ] output_predictions: predictions.csv
|
||||
[INFO ] test_file: predict.csv
|
||||
[INFO ] training_file: dataset.csv
|
||||
[INFO ] training_responses: ""
|
||||
[INFO ] verbose: true
|
||||
[INFO ] version: false
|
||||
[INFO ]
|
||||
[INFO ] output_model_file:
|
||||
[INFO ] output_predictions_file: 'predictions.csv' (1x3 matrix)
|
||||
[INFO ] test_file: 'predict.csv' (0x0 matrix)
|
||||
[INFO ] training_file: 'dataset.csv' (0x0 matrix)
|
||||
[INFO ] training_responses_file: ''
|
||||
[INFO ] verbose: 1
|
||||
[INFO ] version: 0
|
||||
[INFO ] Program timers:
|
||||
[INFO ] load_regressors: 0.000371s
|
||||
[INFO ] load_test_points: 0.000229s
|
||||
[INFO ] loading_data: 0.000491s
|
||||
[INFO ] prediction: 0.000075s
|
||||
[INFO ] regression: 0.000449s
|
||||
[INFO ] saving_data: 0.000186s
|
||||
[INFO ] total_time: 0.002731s
|
||||
[INFO ] load_regressors: 0.000069s
|
||||
[INFO ] load_test_points: 0.000031s
|
||||
[INFO ] loading_data: 0.000079s
|
||||
[INFO ] prediction: 0.000001s
|
||||
[INFO ] regression: 0.000054s
|
||||
[INFO ] saving_data: 0.000055s
|
||||
[INFO ] total_time: 0.000203s
|
||||
|
||||
|
||||
$ cat dataset.csv
|
||||
0,0
|
||||
@@ -195,51 +263,52 @@ about the \c predict.csv dataset is that it has the same dimensionality as the
|
||||
dataset used to create the model, one. If the model generating dataset has
|
||||
\f$d\f$ dimensions, so must the dataset we want to predict for.
|
||||
|
||||
@subsection cli_ex3_lrtut Prediction using a precomputed model
|
||||
@subsection cli_ex4_lrtut Prediction using a precomputed model
|
||||
|
||||
@code
|
||||
$ mlpack_linear_regression --input_model_file lr.xml --test_file predict.csv -v
|
||||
$ mlpack_linear_regression --input_model_file lr.xml --test_file predict.csv --output_predictions_file predictions.csv -v
|
||||
[WARN ] '--output_predictions_file (-o)' ignored because '--test_file (-T)' is specified!
|
||||
[INFO ] Loading 'predict.csv' as raw ASCII formatted data. Size is 1 x 3.
|
||||
[INFO ] Saving CSV data to 'predictions.csv'.
|
||||
[INFO ]
|
||||
[INFO ]
|
||||
[INFO ] Execution parameters:
|
||||
[INFO ] help: false
|
||||
[INFO ] info: ""
|
||||
[INFO ] help: 0
|
||||
[INFO ] info:
|
||||
[INFO ] input_model_file: lr.xml
|
||||
[INFO ] lambda: 0
|
||||
[INFO ] output_model_file: ""
|
||||
[INFO ] output_predictions: predictions.csv
|
||||
[INFO ] test_file: predict.csv
|
||||
[INFO ] training_file: ""
|
||||
[INFO ] training_responses: ""
|
||||
[INFO ] verbose: true
|
||||
[INFO ] version: false
|
||||
[INFO ]
|
||||
[INFO ] output_model_file:
|
||||
[INFO ] output_predictions_file: 'predictions.csv' (1x3 matrix)
|
||||
[INFO ] test_file: 'predict.csv' (0x0 matrix)
|
||||
[INFO ] training_file: ''
|
||||
[INFO ] training_responses_file: ''
|
||||
[INFO ] verbose: 1
|
||||
[INFO ] version: 0
|
||||
[INFO ] Program timers:
|
||||
[INFO ] load_model: 0.000264s
|
||||
[INFO ] load_test_points: 0.000186s
|
||||
[INFO ] loading_data: 0.000157s
|
||||
[INFO ] prediction: 0.000098s
|
||||
[INFO ] saving_data: 0.000157s
|
||||
[INFO ] total_time: 0.001688s
|
||||
[INFO ] load_model: 0.000051s
|
||||
[INFO ] load_test_points: 0.000052s
|
||||
[INFO ] loading_data: 0.000044s
|
||||
[INFO ] prediction: 0.000010s
|
||||
[INFO ] saving_data: 0.000079s
|
||||
[INFO ] total_time: 0.000160s
|
||||
|
||||
|
||||
$ cat lr.xml
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<!DOCTYPE boost_serialization>
|
||||
<boost_serialization signature="serialization::archive" version="12">
|
||||
<linearRegressionModel class_id="0" tracking_level="0" version="0">
|
||||
<parameters class_id="1" tracking_level="0" version="0">
|
||||
<n_rows>2</n_rows>
|
||||
<n_cols>1</n_cols>
|
||||
<n_elem>2</n_elem>
|
||||
<vec_state>1</vec_state>
|
||||
<item>-3.97205464519563669e-16</item>
|
||||
<item>1.00000000000000022e+00</item>
|
||||
</parameters>
|
||||
<lambda>0.00000000000000000e+00</lambda>
|
||||
<intercept>1</intercept>
|
||||
</linearRegressionModel>
|
||||
</boost_serialization>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<cereal>
|
||||
<model>
|
||||
<cereal_class_version>0</cereal_class_version>
|
||||
<parameters>
|
||||
<n_rows>2</n_rows>
|
||||
<n_cols>1</n_cols>
|
||||
<vec_state>1</vec_state>
|
||||
<elem>0</elem>
|
||||
<elem>1</elem>
|
||||
</parameters>
|
||||
<lambda>0</lambda>
|
||||
<intercept>true</intercept>
|
||||
</model>
|
||||
</cereal>
|
||||
|
||||
|
||||
$ cat predict.csv
|
||||
2
|
||||
@@ -252,7 +321,7 @@ $ cat predictions.csv
|
||||
4.0000000000e+00
|
||||
@endcode
|
||||
|
||||
@subsection cli_ex4_lrtut Using ridge regression
|
||||
@subsection cli_ex5_lrtut Using ridge regression
|
||||
|
||||
Sometimes, the input matrix of predictors has a covariance matrix that is not
|
||||
invertible, or the system is overdetermined. In this case, ridge regression is
|
||||
|
||||
@@ -153,19 +153,22 @@ the output shape is represented by the number of possible actions, which in this
|
||||
(`foward` and `backward`).
|
||||
|
||||
We can also use mlpack's ann module to setup a custom FFN network. For example, here we use a single
|
||||
hidden layer.
|
||||
hidden layer. However, the Q-Learning agent expects the object to have a `ResetNoise` method which `SimpleDQN` has.
|
||||
We can't pass mlpack's FFN network directly. Instead, we have to wrap it into `SimpleDQN` object.
|
||||
|
||||
@code
|
||||
int main()
|
||||
{
|
||||
// Set up the network.
|
||||
FFN<MeanSquaredError<>, GaussianInitialization> model(MeanSquaredError<>(),
|
||||
FFN<MeanSquaredError<>, GaussianInitialization> network(MeanSquaredError<>(),
|
||||
GaussianInitialization(0, 0.001));
|
||||
model.Add<Linear<>>(4, 128);
|
||||
model.Add<ReLULayer<>>();
|
||||
model.Add<Linear<>>(128, 128);
|
||||
model.Add<ReLULayer<>>();
|
||||
model.Add<Linear<>>(128, 2);
|
||||
network.Add<Linear<>>(4, 128);
|
||||
network.Add<ReLULayer<>>();
|
||||
network.Add<Linear<>>(128, 128);
|
||||
network.Add<ReLULayer<>>();
|
||||
network.Add<Linear<>>(128, 2);
|
||||
|
||||
SimpleDQN<> model(network);
|
||||
|
||||
@endcode
|
||||
|
||||
@@ -323,7 +326,7 @@ auto measure = [&returns, &position, &episode](double episodeReturn)
|
||||
|
||||
std::cout << "Episode No.: " << episode
|
||||
<< "; Episode Return: " << episodeReturn
|
||||
<< "; Average Return: " << arma::mean(returns) << endl;
|
||||
<< "; Average Return: " << arma::mean(returns) << std::endl;
|
||||
};
|
||||
@endcode
|
||||
|
||||
@@ -389,7 +392,7 @@ int main()
|
||||
|
||||
std::cout << "Episode No.: " << episode
|
||||
<< "; Episode Return: " << episodeReturn
|
||||
<< "; Average Return: " << arma::mean(returns) << endl;
|
||||
<< "; Average Return: " << arma::mean(returns) << std::endl;
|
||||
};
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
|
||||
@@ -208,6 +208,7 @@ if (BUILD_R_BINDINGS)
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/print_input_processing.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/print_output_processing.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/print_serialize_util.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack_main.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/R_option.hpp"
|
||||
)
|
||||
|
||||
@@ -284,6 +285,11 @@ if (BUILD_R_BINDINGS)
|
||||
DESTINATION
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mlpack/")
|
||||
|
||||
file(COPY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mlpack/configure"
|
||||
DESTINATION
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mlpack/")
|
||||
|
||||
# Do the actual build.
|
||||
add_custom_target(r_build ALL)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class ROption
|
||||
* @param input Whether or not the option is an input option.
|
||||
* @param noTranspose If the parameter is a matrix and this is true, then the
|
||||
* matrix will not be transposed on loading.
|
||||
* @param * (testName) Is not used and added for compatibility reasons.
|
||||
* @param bindingName Name of the binding that this parameter is for.
|
||||
*/
|
||||
ROption(const T defaultValue,
|
||||
const std::string& identifier,
|
||||
@@ -57,7 +57,7 @@ class ROption
|
||||
const bool required = false,
|
||||
const bool input = true,
|
||||
const bool noTranspose = false,
|
||||
const std::string& /* testName */ = "")
|
||||
const std::string& bindingName = "")
|
||||
{
|
||||
// Create the ParamData object to give to IO.
|
||||
util::ParamData data;
|
||||
@@ -70,47 +70,29 @@ class ROption
|
||||
data.required = required;
|
||||
data.input = input;
|
||||
data.loaded = false;
|
||||
|
||||
// Only "verbose" will be persistent.
|
||||
if (identifier == "verbose")
|
||||
data.persistent = true;
|
||||
else
|
||||
data.persistent = false;
|
||||
data.cppType = cppName;
|
||||
|
||||
// Every parameter we'll get from R will have the correct type.
|
||||
data.value = boost::any(defaultValue);
|
||||
|
||||
// Restore the parameters for this program.
|
||||
if (identifier != "verbose")
|
||||
IO::RestoreSettings(IO::ProgramName(), false);
|
||||
|
||||
// Set the function pointers that we'll need. All of these function
|
||||
// pointers will be used by both the program that generates the R, and
|
||||
// also the binding itself. (The binding itself will only use GetParam,
|
||||
// GetPrintableParam, and GetRawParam.)
|
||||
IO::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
|
||||
&GetPrintableParam<T>;
|
||||
IO::AddFunction(data.tname, "GetParam", &GetParam<T>);
|
||||
IO::AddFunction(data.tname, "GetPrintableParam", &GetPrintableParam<T>);
|
||||
|
||||
// These are used by the R generator.
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintInputParam"] =
|
||||
&PrintInputParam<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
|
||||
&PrintOutputProcessing<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
|
||||
&PrintInputProcessing<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintSerializeUtil"] =
|
||||
&PrintSerializeUtil<T>;
|
||||
IO::AddFunction(data.tname, "PrintDoc", &PrintDoc<T>);
|
||||
IO::AddFunction(data.tname, "PrintInputParam", &PrintInputParam<T>);
|
||||
IO::AddFunction(data.tname, "PrintOutputProcessing",
|
||||
&PrintOutputProcessing<T>);
|
||||
IO::AddFunction(data.tname, "PrintInputProcessing",
|
||||
&PrintInputProcessing<T>);
|
||||
IO::AddFunction(data.tname, "PrintSerializeUtil", &PrintSerializeUtil<T>);
|
||||
|
||||
// Add the ParamData object, then store. This is necessary because we may
|
||||
// import more than one .so or .o that uses IO, so we have to keep the
|
||||
// options separate. programName is a global variable from mlpack_main.hpp.
|
||||
IO::Add(std::move(data));
|
||||
if (identifier != "verbose")
|
||||
IO::StoreSettings(IO::ProgramName());
|
||||
IO::ClearSettings();
|
||||
// Add the ParamData object.
|
||||
IO::AddParameter(bindingName, std::move(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@ namespace r {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a vector option.
|
||||
@@ -39,7 +40,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a string option.
|
||||
@@ -47,7 +48,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a matrix option, a tuple option, a
|
||||
@@ -57,7 +58,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */ = 0);
|
||||
@@ -69,8 +70,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of an option. This is the function that will be
|
||||
|
||||
@@ -24,12 +24,13 @@ namespace r {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if (std::is_same<T, bool>::value)
|
||||
@@ -46,7 +47,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* /* junk */)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
@@ -89,7 +90,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type*)
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *boost::any_cast<std::string>(&data.value);
|
||||
return "\"" + s + "\"";
|
||||
@@ -102,7 +103,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */)
|
||||
@@ -132,8 +133,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
return "NA";
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
#endif
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
#include <mlpack/bindings/R/print_R.hpp>
|
||||
|
||||
// This will include the ParamData options that are part of the program.
|
||||
#include <${PROGRAM_MAIN_FILE}>
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
#include <mlpack/bindings/R/print_R.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::bindings;
|
||||
@@ -31,9 +31,8 @@ using namespace mlpack::util;
|
||||
|
||||
int main(int /* argc */, char** /* argv */)
|
||||
{
|
||||
// All the parameters are registered, but stored, so restore them.
|
||||
// programName is defined in mlpack_main.hpp.
|
||||
IO::RestoreSettings(IO::ProgramName());
|
||||
// All the parameters are registered; get a copy of them.
|
||||
util::Params params = IO::Parameters(STRINGIFY(BINDING_NAME));
|
||||
|
||||
PrintR(IO::GetSingleton().doc, "${NAME}");
|
||||
PrintR(params, "${NAME}", STRINGIFY(BINDING_NAME));
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace r {
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << boost::any_cast<T>(data.value);
|
||||
@@ -42,7 +42,7 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = boost::any_cast<T>(data.value);
|
||||
|
||||
@@ -58,7 +58,7 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = boost::any_cast<T>(data.value);
|
||||
@@ -74,8 +74,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << boost::any_cast<T*>(data.value);
|
||||
@@ -88,8 +88,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = boost::any_cast<T>(data.value);
|
||||
|
||||
@@ -23,84 +23,88 @@ namespace r {
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<size_t>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<size_t>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<size_t>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<size_t>>::type*,
|
||||
const typename boost::disable_if<std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
void GetPrintableType(util::ParamData& d,
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace r {
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -34,11 +34,11 @@ inline std::string GetPrintableType(
|
||||
template<>
|
||||
inline std::string GetPrintableType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "integer";
|
||||
}
|
||||
@@ -46,11 +46,11 @@ inline std::string GetPrintableType<int>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "numeric";
|
||||
}
|
||||
@@ -58,11 +58,15 @@ inline std::string GetPrintableType<double>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo,arma::mat>>::value>::type*)
|
||||
{
|
||||
return "character";
|
||||
}
|
||||
@@ -70,11 +74,11 @@ inline std::string GetPrintableType<std::string>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<size_t>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<size_t>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<size_t>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<size_t>>::type*,
|
||||
const typename boost::disable_if<std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "integer";
|
||||
}
|
||||
@@ -82,11 +86,11 @@ inline std::string GetPrintableType<size_t>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "logical";
|
||||
}
|
||||
@@ -94,9 +98,9 @@ inline std::string GetPrintableType<bool>(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "vector of " + GetPrintableType<typename T::value_type>(d) + "s";
|
||||
}
|
||||
@@ -104,9 +108,9 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
std::string type = "numeric matrix";
|
||||
if (std::is_same<typename T::elem_type, double>::value)
|
||||
@@ -127,8 +131,8 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "categorical matrix/data.frame";
|
||||
}
|
||||
@@ -136,10 +140,10 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
std::string type = util::StripType(d.cppType);
|
||||
if (type == "mlpackModel")
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace r {
|
||||
template<typename T>
|
||||
inline std::string GetRType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -35,11 +35,11 @@ inline std::string GetRType(
|
||||
template<>
|
||||
inline std::string GetRType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "logical";
|
||||
}
|
||||
@@ -47,11 +47,11 @@ inline std::string GetRType<bool>(
|
||||
template<>
|
||||
inline std::string GetRType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "integer";
|
||||
}
|
||||
@@ -59,11 +59,11 @@ inline std::string GetRType<int>(
|
||||
template<>
|
||||
inline std::string GetRType<size_t>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<size_t>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<size_t>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<size_t>>::type*,
|
||||
const typename boost::disable_if<std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<size_t,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "integer";
|
||||
}
|
||||
@@ -71,11 +71,11 @@ inline std::string GetRType<size_t>(
|
||||
template<>
|
||||
inline std::string GetRType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "numeric";
|
||||
}
|
||||
@@ -83,11 +83,15 @@ inline std::string GetRType<double>(
|
||||
template<>
|
||||
inline std::string GetRType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "character";
|
||||
}
|
||||
@@ -95,7 +99,7 @@ inline std::string GetRType<std::string>(
|
||||
template<typename T>
|
||||
inline std::string GetRType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
return GetRType<typename T::value_type>(d) + " vector";
|
||||
}
|
||||
@@ -103,9 +107,9 @@ inline std::string GetRType(
|
||||
template<typename T>
|
||||
inline std::string GetRType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
std::string elemType = GetRType<typename T::elem_type>(d);
|
||||
std::string type = "matrix";
|
||||
@@ -120,8 +124,8 @@ inline std::string GetRType(
|
||||
template<typename T>
|
||||
inline std::string GetRType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "numeric matrix/data.frame with info";
|
||||
}
|
||||
@@ -129,8 +133,8 @@ inline std::string GetRType(
|
||||
template<typename T>
|
||||
inline std::string GetRType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
return util::StripType(d.cppType);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace r {
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -36,11 +36,11 @@ inline std::string GetType(
|
||||
template<>
|
||||
inline std::string GetType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "Int";
|
||||
}
|
||||
@@ -48,11 +48,11 @@ inline std::string GetType<int>(
|
||||
template<>
|
||||
inline std::string GetType<float>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<float>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<float>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<float>>::type*,
|
||||
const typename boost::disable_if<std::is_same<float,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<float>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<float>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<float>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<float,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "Float";
|
||||
}
|
||||
@@ -60,11 +60,11 @@ inline std::string GetType<float>(
|
||||
template<>
|
||||
inline std::string GetType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "Double";
|
||||
}
|
||||
@@ -72,11 +72,14 @@ inline std::string GetType<double>(
|
||||
template<>
|
||||
inline std::string GetType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
@@ -84,11 +87,11 @@ inline std::string GetType<std::string>(
|
||||
template<>
|
||||
inline std::string GetType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "Bool";
|
||||
}
|
||||
@@ -96,9 +99,9 @@ inline std::string GetType<bool>(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "Vec" + GetType<typename T::value_type>(d);
|
||||
}
|
||||
@@ -106,9 +109,9 @@ inline std::string GetType(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::string type = "";
|
||||
if (std::is_same<typename T::elem_type, double>::value)
|
||||
@@ -136,8 +139,8 @@ inline std::string GetType(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "MatWithInfo";
|
||||
}
|
||||
@@ -145,8 +148,8 @@ inline std::string GetType(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
return d.cppType;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,5 @@ Suggests: testthat (>= 2.1.0)
|
||||
URL: https://www.mlpack.org/doc/mlpack-@PACKAGE_VERSION@/r_documentation.html,
|
||||
https://github.com/mlpack/mlpack
|
||||
BugReports: https://github.com/mlpack/mlpack/issues
|
||||
LazyData: true
|
||||
RoxygenNote: 7.1.0
|
||||
Encoding: UTF-8
|
||||
|
||||
@@ -38,13 +38,13 @@ mark_categorical_variable = function(x) {
|
||||
# Given some matrix-like x (which should be either a matrix or
|
||||
# data.frame), convert it into a matrix.
|
||||
to_matrix_with_info <- function(x) {
|
||||
|
||||
|
||||
# Handle transformation
|
||||
transformed_x <- to_matrix(x)
|
||||
|
||||
# Figure out categoricals
|
||||
info <- mark_categorical_variable(x)
|
||||
|
||||
# Return needed data.
|
||||
|
||||
# Return needed data.
|
||||
return(list("info" = info, "data" = transformed_x))
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test `uname` = "SunOS" ;
|
||||
then
|
||||
sed '1 s/$/ -ftrack-macro-expansion=0 -pipe --param ggc-min-expand=10 --param ggc-min-heapsize=8192/' ./src/Makevars > ./src/Makevars.tmp && cat ./src/Makevars.tmp > ./src/Makevars && rm ./src/Makevars.tmp
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,3 +1,3 @@
|
||||
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS)
|
||||
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS) -ftrack-macro-expansion=0 -pipe --param ggc-min-expand=10 --param ggc-min-heapsize=8192
|
||||
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
|
||||
CXX_STD = CXX11
|
||||
|
||||
@@ -30,271 +30,321 @@ bool inline inplace_transpose(arma::Mat<eT>& X)
|
||||
}
|
||||
}
|
||||
|
||||
// Call IO::RestoreSettings() for a given program name.
|
||||
// Create a new util::Params object.
|
||||
// [[Rcpp::export]]
|
||||
void IO_RestoreSettings(const std::string& programName)
|
||||
SEXP CreateParams(const std::string& bindingName)
|
||||
{
|
||||
IO::RestoreSettings(programName);
|
||||
util::Params* p = new util::Params(IO::Parameters(bindingName));
|
||||
std::cout << "create params " << p << "\n";
|
||||
return std::move(Rcpp::XPtr<util::Params>(p));
|
||||
}
|
||||
|
||||
// Call IO::SetParam<int>().
|
||||
// Create a new util::Timers object.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamInt(const std::string& paramName, int paramValue)
|
||||
SEXP CreateTimers()
|
||||
{
|
||||
IO::GetParam<int>(paramName) = paramValue;
|
||||
IO::SetPassed(paramName);
|
||||
util::Timers* t = new util::Timers();
|
||||
std::cout << "create timers " << t << "\n";
|
||||
return std::move(Rcpp::XPtr<util::Timers>(t));
|
||||
}
|
||||
|
||||
// Call IO::SetParam<double>().
|
||||
// Call params.Get<int>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamDouble(const std::string& paramName, double paramValue)
|
||||
void SetParamInt(SEXP params, const std::string& paramName, int paramValue)
|
||||
{
|
||||
IO::GetParam<double>(paramName) = paramValue;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<int>(paramName) = paramValue;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<std::string>().
|
||||
// Call params.Get<double>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamString(const std::string& paramName, std::string& paramValue)
|
||||
void SetParamDouble(SEXP params,
|
||||
const std::string& paramName,
|
||||
double paramValue)
|
||||
{
|
||||
IO::GetParam<std::string>(paramName) = paramValue;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<double>(paramName) = paramValue;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<bool>().
|
||||
// Call params.Get<std::string>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamBool(const std::string& paramName, bool paramValue)
|
||||
void SetParamString(SEXP params,
|
||||
const std::string& paramName,
|
||||
std::string& paramValue)
|
||||
{
|
||||
IO::GetParam<bool>(paramName) = paramValue;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<std::string>(paramName) = paramValue;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<std::vector<std::string>>().
|
||||
// Call params.Get<bool>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamVecString(const std::string& paramName,
|
||||
void SetParamBool(SEXP params, const std::string& paramName, bool paramValue)
|
||||
{
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<bool>(paramName) = paramValue;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call params.Get<std::vector<std::string>>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void SetParamVecString(SEXP params,
|
||||
const std::string& paramName,
|
||||
const std::vector<std::string>& str)
|
||||
{
|
||||
IO::GetParam<std::vector<std::string>>(paramName) = std::move(str);
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<std::vector<std::string>>(paramName) = std::move(str);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<std::vector<int>>().
|
||||
// Call params.Get<std::vector<int>>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamVecInt(const std::string& paramName,
|
||||
void SetParamVecInt(SEXP params,
|
||||
const std::string& paramName,
|
||||
const std::vector<int>& ints)
|
||||
{
|
||||
IO::GetParam<std::vector<int>>(paramName) = std::move(ints);
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<std::vector<int>>(paramName) = std::move(ints);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::mat>().
|
||||
// Call params.Get<arma::mat>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamMat(const std::string& paramName,
|
||||
void SetParamMat(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::mat& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::mat>(paramName) = paramValue.t();
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::mat>(paramName) = paramValue.t();
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::Mat<size_t>>().
|
||||
// Call params.Get<arma::Mat<size_t>>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamUMat(const std::string& paramName,
|
||||
void SetParamUMat(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::Mat<size_t>& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::Mat<size_t>>(paramName) = paramValue.t();
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::Mat<size_t>>(paramName) = paramValue.t();
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::rowvec>().
|
||||
// Call params.Get<arma::rowvec>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamRow(const std::string& paramName,
|
||||
void SetParamRow(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::rowvec& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::rowvec>(paramName) = std::move(paramValue);
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::rowvec>(paramName) = std::move(paramValue);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::Row<size_t>>().
|
||||
// Call params.Get<arma::Row<size_t>>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamURow(const std::string& paramName,
|
||||
void SetParamURow(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::Row<size_t>& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::Row<size_t>>(paramName) = paramValue - 1;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::Row<size_t>>(paramName) = paramValue - 1;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::vec>().
|
||||
// Call params.Get<arma::vec>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamCol(const std::string& paramName,
|
||||
void SetParamCol(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::vec& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::vec>(paramName) = std::move(paramValue);
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::vec>(paramName) = std::move(paramValue);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<arma::Col<size_t>>().
|
||||
// Call params.Get<arma::Col<size_t>>() to set the value of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamUCol(const std::string& paramName,
|
||||
void SetParamUCol(SEXP params,
|
||||
const std::string& paramName,
|
||||
const arma::Col<size_t>& paramValue)
|
||||
{
|
||||
IO::GetParam<arma::Col<size_t>>(paramName) = paramValue - 1;
|
||||
IO::SetPassed(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.Get<arma::Col<size_t>>(paramName) = paramValue - 1;
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::SetParam<std::tuple<data::DatasetInfo, arma::mat>>().
|
||||
// Call params.Get<std::tuple<data::DatasetInfo, arma::mat>>() to set the value
|
||||
// of a parameter.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetParamMatWithInfo(const std::string& paramName,
|
||||
void SetParamMatWithInfo(SEXP params,
|
||||
const std::string& paramName,
|
||||
const LogicalVector& dimensions,
|
||||
const arma::mat& paramValue)
|
||||
{
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
data::DatasetInfo d(paramValue.n_cols);
|
||||
for (size_t i = 0; i < d.Dimensionality(); ++i)
|
||||
{
|
||||
d.Type(i) = (dimensions[i]) ? data::Datatype::categorical :
|
||||
data::Datatype::numeric;
|
||||
}
|
||||
std::get<0>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
std::get<0>(p.Get<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
paramName)) = std::move(d);
|
||||
std::get<1>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
std::get<1>(p.Get<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
paramName)) = paramValue.t();
|
||||
IO::SetPassed(paramName);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Call IO::GetParam<int>().
|
||||
// Call p.Get<int>().
|
||||
// [[Rcpp::export]]
|
||||
int IO_GetParamInt(const std::string& paramName)
|
||||
int GetParamInt(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<int>(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<int>(paramName);
|
||||
}
|
||||
|
||||
// Call IO::GetParam<double>().
|
||||
// Call p.Get<double>().
|
||||
// [[Rcpp::export]]
|
||||
double IO_GetParamDouble(const std::string& paramName)
|
||||
double GetParamDouble(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<double>(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<double>(paramName);
|
||||
}
|
||||
|
||||
// Call IO::GetParam<std::string>().
|
||||
// Call p.Get<std::string>().
|
||||
// [[Rcpp::export]]
|
||||
std::string& IO_GetParamString(const std::string& paramName)
|
||||
std::string& GetParamString(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<std::string>(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<std::string>(paramName);
|
||||
}
|
||||
|
||||
// Call IO::GetParam<bool>().
|
||||
// Call p.Get<bool>().
|
||||
// [[Rcpp::export]]
|
||||
bool IO_GetParamBool(const std::string& paramName)
|
||||
bool GetParamBool(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<bool>(paramName);
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<bool>(paramName);
|
||||
}
|
||||
|
||||
// Call IO::GetParam<std::vector<std::string>>().
|
||||
// Call p.Get<std::vector<std::string>>().
|
||||
// [[Rcpp::export]]
|
||||
const std::vector<std::string>& IO_GetParamVecString(const
|
||||
std::string& paramName)
|
||||
const std::vector<std::string>& GetParamVecString(
|
||||
SEXP params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
return std::move(IO::GetParam<std::vector<std::string>>(paramName));
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return std::move(p.Get<std::vector<std::string>>(paramName));
|
||||
}
|
||||
|
||||
// Call IO::GetParam<std::vector<int>>().
|
||||
// Call p.Get<std::vector<int>>().
|
||||
// [[Rcpp::export]]
|
||||
const std::vector<int>& IO_GetParamVecInt(const std::string& paramName)
|
||||
const std::vector<int>& GetParamVecInt(SEXP params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
return std::move(IO::GetParam<std::vector<int>>(paramName));
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return std::move(p.Get<std::vector<int>>(paramName));
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::mat>().
|
||||
// Call p.Get<arma::mat>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::mat& IO_GetParamMat(const std::string& paramName)
|
||||
const arma::mat& GetParamMat(SEXP params, const std::string& paramName)
|
||||
{
|
||||
inplace_transpose(IO::GetParam<arma::mat>(paramName));
|
||||
return std::move(IO::GetParam<arma::mat>(paramName));
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
inplace_transpose(p.Get<arma::mat>(paramName));
|
||||
return std::move(p.Get<arma::mat>(paramName));
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::Mat<size_t>>().
|
||||
// Call p.Get<arma::Mat<size_t>>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::Mat<size_t>& IO_GetParamUMat(const std::string& paramName)
|
||||
const arma::Mat<size_t>& GetParamUMat(SEXP params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
inplace_transpose(IO::GetParam<arma::Mat<size_t>>(paramName));
|
||||
return std::move(IO::GetParam<arma::Mat<size_t>>(paramName));
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
inplace_transpose(p.Get<arma::Mat<size_t>>(paramName));
|
||||
return std::move(p.Get<arma::Mat<size_t>>(paramName));
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::rowvec>().
|
||||
// Call p.Get<arma::rowvec>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::vec IO_GetParamRow(const std::string& paramName)
|
||||
const arma::vec GetParamRow(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<arma::rowvec>(paramName).t();
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<arma::rowvec>(paramName).t();
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::Row<size_t>>().
|
||||
// Call p.Get<arma::Row<size_t>>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::Col<size_t> IO_GetParamURow(const std::string& paramName)
|
||||
const arma::Col<size_t> GetParamURow(SEXP params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<arma::Row<size_t>>(paramName).t() + 1;
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<arma::Row<size_t>>(paramName).t() + 1;
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::vec>().
|
||||
// Call p.Get<arma::vec>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::rowvec IO_GetParamCol(const std::string& paramName)
|
||||
const arma::rowvec GetParamCol(SEXP params, const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<arma::vec>(paramName).t();
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<arma::vec>(paramName).t();
|
||||
}
|
||||
|
||||
// Call IO::GetParam<arma::Col<size_t>>().
|
||||
// Call p.Get<arma::Col<size_t>>().
|
||||
// [[Rcpp::export]]
|
||||
const arma::Row<size_t> IO_GetParamUCol(const std::string& paramName)
|
||||
const arma::Row<size_t> GetParamUCol(SEXP params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
return IO::GetParam<arma::Col<size_t>>(paramName).t() + 1;
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
return p.Get<arma::Col<size_t>>(paramName).t() + 1;
|
||||
}
|
||||
|
||||
// Call IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>().
|
||||
// Call p.Get<std::tuple<data::DatasetInfo, arma::mat>>().
|
||||
// [[Rcpp::export]]
|
||||
List IO_GetParamMatWithInfo(const std::string& paramName)
|
||||
List IO_GetParamMatWithInfo(SEXP params, const std::string& paramName)
|
||||
{
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
const data::DatasetInfo& d = std::get<0>(
|
||||
IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(paramName));
|
||||
p.Get<std::tuple<data::DatasetInfo, arma::mat>>(paramName));
|
||||
const arma::mat& m = std::get<1>(
|
||||
IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(paramName)).t();
|
||||
p.Get<std::tuple<data::DatasetInfo, arma::mat>>(paramName)).t();
|
||||
|
||||
LogicalVector dims(d.Dimensionality());
|
||||
for (size_t i = 0; i < d.Dimensionality(); ++i)
|
||||
dims[i] = (d.Type(i) == data::Datatype::numeric) ? false : true;
|
||||
|
||||
return List::create (Rcpp::Named("Info") = std::move(dims),
|
||||
Rcpp::Named("Data") = std::move(m));
|
||||
return List::create(Rcpp::Named("Info") = std::move(dims),
|
||||
Rcpp::Named("Data") = std::move(m));
|
||||
}
|
||||
|
||||
// Enable verbose output.
|
||||
// [[Rcpp::export]]
|
||||
void IO_EnableVerbose()
|
||||
void EnableVerbose()
|
||||
{
|
||||
Log::Info.ignoreInput = false;
|
||||
}
|
||||
|
||||
// Disable verbose output.
|
||||
// [[Rcpp::export]]
|
||||
void IO_DisableVerbose()
|
||||
void DisableVerbose()
|
||||
{
|
||||
Log::Info.ignoreInput = true;
|
||||
}
|
||||
|
||||
// Reset the state of all timers.
|
||||
// [[Rcpp::export]]
|
||||
void IO_ResetTimers()
|
||||
void ResetTimers()
|
||||
{
|
||||
IO::GetSingleton().timer.Reset();
|
||||
Timer::ResetAll();
|
||||
}
|
||||
|
||||
// Set an argument as passed to the IO object.
|
||||
// [[Rcpp::export]]
|
||||
void IO_SetPassed(const std::string& paramName)
|
||||
void SetPassed(SEXP params, const std::string& paramName)
|
||||
{
|
||||
IO::SetPassed(paramName);
|
||||
}
|
||||
|
||||
// Clear settings.
|
||||
// [[Rcpp::export]]
|
||||
void IO_ClearSettings()
|
||||
{
|
||||
IO::ClearSettings();
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
p.SetPassed(paramName);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <Rcpp.h>
|
||||
|
||||
// To suppress Found ‘__assert_fail’, possibly from ‘assert’ (C).
|
||||
// To suppress Found '__assert_fail', possibly from 'assert' (C).
|
||||
#define BOOST_DISABLE_ASSERTS
|
||||
|
||||
// Rcpp has its own stream object which cooperates more nicely with R's i/o
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file mlpack_main.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Define the macros used when compiling a Go binding. This file should not
|
||||
* be included directly; instead, mlpack/core/util/mlpack_main.hpp should be
|
||||
* included with the right setting of BINDING_TYPE.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_R_MLPACK_MAIN_HPP
|
||||
#define MLPACK_BINDINGS_R_MLPACK_MAIN_HPP
|
||||
|
||||
#ifndef BINDING_TYPE
|
||||
#error "BINDING_TYPE not defined! Don't include this file directly!"
|
||||
#endif
|
||||
#if BINDING_TYPE != BINDING_TYPE_R
|
||||
#error "BINDING_TYPE is not set to BINDING_TYPE_R!"
|
||||
#endif
|
||||
|
||||
// This doesn't actually matter for this binding type.
|
||||
#define BINDING_MATRIX_TRANSPOSED true
|
||||
|
||||
#include <mlpack/bindings/R/R_option.hpp>
|
||||
#include <mlpack/bindings/R/print_doc_functions.hpp>
|
||||
|
||||
/**
|
||||
* PRINT_PARAM_STRING() returns a string that contains the correct
|
||||
* language-specific representation of a parameter's name.
|
||||
*/
|
||||
#define PRINT_PARAM_STRING mlpack::bindings::r::ParamString
|
||||
|
||||
/**
|
||||
* PRINT_PARAM_VALUE() returns a string that contains a correct
|
||||
* language-specific representation of a parameter's value.
|
||||
*/
|
||||
#define PRINT_PARAM_VALUE mlpack::bindings::r::PrintValue
|
||||
|
||||
/**
|
||||
* PRINT_DATASET() returns a string that contains a correct language-specific
|
||||
* representation of a dataset name.
|
||||
*/
|
||||
#define PRINT_DATASET mlpack::bindings::r::PrintDataset
|
||||
|
||||
/**
|
||||
* PRINT_MODEL() returns a string that contains a correct language-specific
|
||||
* representation of an mlpack model name.
|
||||
*/
|
||||
#define PRINT_MODEL mlpack::bindings::r::PrintModel
|
||||
|
||||
/**
|
||||
* PRINT_CALL() returns a string that contains the full language-specific
|
||||
* representation of a call to an mlpack binding. The first argument should be
|
||||
* the name of the binding, and all other arguments should be names of
|
||||
* parameters followed by values (in the case where the preceding parameter is
|
||||
* not a flag).
|
||||
*/
|
||||
#define PRINT_CALL(...) mlpack::bindings::r::ProgramCall(false, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* BINDING_IGNORE_CHECK() is an internally-used macro to determine whether or
|
||||
* not a specific parameter check should be ignored.
|
||||
*/
|
||||
#define BINDING_IGNORE_CHECK(...) mlpack::bindings::r::IgnoreCheck( \
|
||||
STRINGIFY(BINDING_NAME), __VA_ARGS__)
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
template<typename T>
|
||||
using Option = mlpack::bindings::r::ROption<T>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include <mlpack/core/util/param.hpp>
|
||||
|
||||
// In R, we want to call the binding function mlpack_<BINDING_NAME>() instead of
|
||||
// just <BINDING_NAME>(), so we change the definition of BINDING_FUNCTION().
|
||||
#undef BINDING_FUNCTION
|
||||
#define BINDING_FUNCTION(...) JOIN(mlpack_, BINDING_NAME)(__VA_ARGS__)
|
||||
|
||||
// Add default parameters that are included in every program.
|
||||
PARAM_FLAG("verbose", "Display informational messages and the full list of "
|
||||
"parameters and timers at the end of execution.", "v");
|
||||
|
||||
#endif
|
||||
@@ -21,20 +21,20 @@ namespace mlpack {
|
||||
namespace bindings {
|
||||
namespace r {
|
||||
|
||||
|
||||
/**
|
||||
* Print the code for a .R binding for an mlpack program to stdout.
|
||||
*
|
||||
* @param doc Documentation for the binding.
|
||||
* @param params Instantiated Params object for this binding.
|
||||
* @param functionName Name of the function (i.e. "pca").
|
||||
* @param bindingName Name of the binding (as specified by BINDING_NAME).
|
||||
*/
|
||||
void PrintR(const util::BindingDetails& doc,
|
||||
const string& functionName)
|
||||
void PrintR(util::Params& params,
|
||||
const string& functionName,
|
||||
const string& bindingName)
|
||||
{
|
||||
// Restore parameters.
|
||||
IO::RestoreSettings(doc.programName);
|
||||
const util::BindingDetails& doc = params.Doc();
|
||||
|
||||
map<string, util::ParamData>& parameters = IO::Parameters();
|
||||
map<string, util::ParamData>& parameters = params.Parameters();
|
||||
typedef map<string, util::ParamData>::iterator ParamIter;
|
||||
|
||||
// First, let's get a list of input and output options. We'll take two passes
|
||||
@@ -68,7 +68,7 @@ void PrintR(const util::BindingDetails& doc,
|
||||
// Print the documentation.
|
||||
// Print programName as @title.
|
||||
cout << "#' @title ";
|
||||
cout << util::HyphenateString(doc.programName, "#' ") << endl;
|
||||
cout << util::HyphenateString(doc.name, "#' ") << endl;
|
||||
cout << "#'" << endl;
|
||||
|
||||
// Next print the short description as @description.
|
||||
@@ -85,7 +85,7 @@ void PrintR(const util::BindingDetails& doc,
|
||||
util::ParamData& d = parameters.at(opt);
|
||||
|
||||
bool out = false;
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintDoc"](d, NULL, (void*) &out);
|
||||
params.functionMap[d.tname]["PrintDoc"](d, NULL, (void*) &out);
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ void PrintR(const util::BindingDetails& doc,
|
||||
util::ParamData& d = parameters.at(opt);
|
||||
|
||||
bool out = true;
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintDoc"](d, NULL, (void*) &out);
|
||||
params.functionMap[d.tname]["PrintDoc"](d, NULL, (void*) &out);
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
@@ -162,36 +162,35 @@ void PrintR(const util::BindingDetails& doc,
|
||||
if (i != 0)
|
||||
cout << "," << endl << std::string(indent, ' ');
|
||||
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintInputParam"](d, NULL, NULL);
|
||||
params.functionMap[d.tname]["PrintInputParam"](d, NULL, NULL);
|
||||
}
|
||||
|
||||
// Print closing brace for function definition.
|
||||
cout << ") {" << endl;
|
||||
|
||||
// Restore IO settings.
|
||||
cout << " # Restore IO settings." << endl;
|
||||
cout << " IO_RestoreSettings(\"" << IO::ProgramName()
|
||||
<< "\")" << endl;
|
||||
// Create timers and parameters objects.
|
||||
cout << " # Create parameters and timers objects." << endl;
|
||||
cout << " p <- CreateParams(\"" << bindingName << "\")" << endl;
|
||||
cout << " t <- CreateTimers()" << endl;
|
||||
cout << endl;
|
||||
|
||||
// Handle each input argument's processing before calling mlpackMain().
|
||||
cout << " # Process each input argument before calling mlpackMain()."
|
||||
// Handle each input argument's processing before calling the binding.
|
||||
cout << " # Process each input argument before calling the binding."
|
||||
<< endl;
|
||||
for (const string& opt : inputOptions)
|
||||
{
|
||||
if (opt != "verbose")
|
||||
{
|
||||
util::ParamData& d = parameters.at(opt);
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintInputProcessing"](d,
|
||||
NULL, NULL);
|
||||
params.functionMap[d.tname]["PrintInputProcessing"](d, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling for verbose output.
|
||||
cout << " if (verbose) {" << endl;
|
||||
cout << " IO_EnableVerbose()" << endl;
|
||||
cout << " EnableVerbose()" << endl;
|
||||
cout << " } else {" << endl;
|
||||
cout << " IO_DisableVerbose()" << endl;
|
||||
cout << " DisableVerbose()" << endl;
|
||||
cout << " }" << endl;
|
||||
cout << endl;
|
||||
|
||||
@@ -200,13 +199,13 @@ void PrintR(const util::BindingDetails& doc,
|
||||
for (const string& opt : outputOptions)
|
||||
{
|
||||
util::ParamData& d = parameters.at(opt);
|
||||
cout << " IO_SetPassed(\"" << d.name << "\")" << endl;
|
||||
cout << " SetPassed(p, \"" << d.name << "\")" << endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
// Call the program.
|
||||
cout << " # Call the program." << endl;
|
||||
cout << " " << functionName << "_mlpackMain()" << endl << endl;
|
||||
cout << " " << functionName << "_call(p, t)" << endl << endl;
|
||||
|
||||
// Add ModelType as attr to the model pointer.
|
||||
cout << " # Add ModelType as attribute to the model pointer, if needed."
|
||||
@@ -214,8 +213,7 @@ void PrintR(const util::BindingDetails& doc,
|
||||
for (size_t i = 0; i < outputOptions.size(); ++i)
|
||||
{
|
||||
util::ParamData& d = parameters.at(outputOptions[i]);
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintSerializeUtil"](d,
|
||||
NULL, NULL);
|
||||
params.functionMap[d.tname]["PrintSerializeUtil"](d, NULL, NULL);
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
@@ -228,17 +226,13 @@ void PrintR(const util::BindingDetails& doc,
|
||||
if (i == 0)
|
||||
cout << indentStr;
|
||||
util::ParamData& d = parameters.at(outputOptions[i]);
|
||||
IO::GetSingleton().functionMap[d.tname]["PrintOutputProcessing"](d,
|
||||
NULL, NULL);
|
||||
params.functionMap[d.tname]["PrintOutputProcessing"](d, NULL, NULL);
|
||||
// Print newlines if we are returning multiple output options.
|
||||
if (i + 1 < outputOptions.size())
|
||||
cout << "," << endl << indentStr;
|
||||
}
|
||||
cout << endl << " )" << endl << endl;
|
||||
|
||||
// Clear the parameters.
|
||||
cout << " # Clear the parameters." << endl;
|
||||
cout << " IO_ClearSettings()" << endl;
|
||||
cout << endl;
|
||||
cout << " return(out)" << endl << "}" << endl;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ namespace r {
|
||||
/**
|
||||
* Print the code for a .R binding for an mlpack program to stdout.
|
||||
*
|
||||
* @param doc Documentation for the binding.
|
||||
* @param params Instantiated Params object for this binding.
|
||||
* @param functionName Name of the function (i.e. "pca").
|
||||
* @param bindingName Name of the binding (as specified by BINDING_NAME).
|
||||
*/
|
||||
void PrintR(const util::BindingDetails& doc,
|
||||
const std::string& functionName);
|
||||
void PrintR(util::Params& params,
|
||||
const std::string& functionName,
|
||||
const std::string& bindingName);
|
||||
|
||||
} // namespace r
|
||||
} // namespace bindings
|
||||
|
||||
@@ -54,29 +54,33 @@ inline std::string PrintValue(const bool& value, bool quotes);
|
||||
/**
|
||||
* Given a parameter name, print its corresponding default value.
|
||||
*/
|
||||
inline std::string PrintDefault(const std::string& paramName);
|
||||
inline std::string PrintDefault(const std::string& bindingName,
|
||||
const std::string& paramName);
|
||||
|
||||
/**
|
||||
* Recursion base case.
|
||||
*/
|
||||
inline std::string PrintInputOptions();
|
||||
inline std::string PrintInputOptions(util::Params& /* p */);
|
||||
|
||||
/**
|
||||
* Print an input option. This will throw an exception if the parameter does
|
||||
* not exist in IO.
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
std::string PrintInputOptions(const std::string& paramName,
|
||||
std::string PrintInputOptions(util::Params& p,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args);
|
||||
|
||||
/**
|
||||
* Recursion base case.
|
||||
*/
|
||||
inline std::string PrintOutputOptions(const bool /* markdown */);
|
||||
inline std::string PrintOutputOptions(util::Params& /* p */,
|
||||
const bool /* markdown */);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
std::string PrintOutputOptions(const bool markdown,
|
||||
std::string PrintOutputOptions(util::Params& p,
|
||||
const bool markdown,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args);
|
||||
@@ -94,7 +98,7 @@ std::string ProgramCall(const bool markdown,
|
||||
* Given the name of a binding, print a program call assuming that all options
|
||||
* are specified.
|
||||
*/
|
||||
inline std::string ProgramCall(const std::string& programName);
|
||||
inline std::string ProgramCall(util::Params& p, const std::string& programName);
|
||||
|
||||
/**
|
||||
* Given the name of a model, print it. Here we do not need to modify anything.
|
||||
|
||||
@@ -93,16 +93,17 @@ inline std::string PrintValue(const std::vector<T>& value, bool quotes)
|
||||
/**
|
||||
* Given a parameter name, print its corresponding default value.
|
||||
*/
|
||||
inline std::string PrintDefault(const std::string& paramName)
|
||||
inline std::string PrintDefault(const std::string& bindingName,
|
||||
const std::string& paramName)
|
||||
{
|
||||
if (IO::Parameters().count(paramName) == 0)
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
if (p.Parameters().count(paramName) == 0)
|
||||
throw std::invalid_argument("unknown parameter " + paramName + "!");
|
||||
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = p.Parameters()[paramName];
|
||||
|
||||
std::string defaultValue;
|
||||
IO::GetSingleton().functionMap[d.tname]["DefaultParam"](d, NULL,
|
||||
(void*) &defaultValue);
|
||||
p.functionMap[d.tname]["DefaultParam"](d, NULL, (void*) &defaultValue);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -126,22 +127,23 @@ inline std::string PrintValue(const bool& value, bool quotes)
|
||||
/**
|
||||
* Recursion base case.
|
||||
*/
|
||||
std::string PrintInputOptions() { return ""; }
|
||||
std::string PrintInputOptions(util::Params& /* p */) { return ""; }
|
||||
|
||||
/**
|
||||
* Print an input option. This will throw an exception if the parameter does
|
||||
* not exist in IO.
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
std::string PrintInputOptions(const std::string& paramName,
|
||||
std::string PrintInputOptions(util::Params& p,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args)
|
||||
{
|
||||
// See if this is part of the program.
|
||||
std::string result = "";
|
||||
if (IO::Parameters().count(paramName) > 0)
|
||||
if (p.Parameters().count(paramName) > 0)
|
||||
{
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = p.Parameters()[paramName];
|
||||
if (d.input)
|
||||
{
|
||||
// Print the input option.
|
||||
@@ -160,7 +162,7 @@ std::string PrintInputOptions(const std::string& paramName,
|
||||
}
|
||||
|
||||
// Continue recursion.
|
||||
std::string rest = PrintInputOptions(args...);
|
||||
std::string rest = PrintInputOptions(p, args...);
|
||||
if (rest != "" && result != "")
|
||||
result += ", " + rest;
|
||||
else if (result == "")
|
||||
@@ -172,10 +174,15 @@ std::string PrintInputOptions(const std::string& paramName,
|
||||
/**
|
||||
* Recursion base case.
|
||||
*/
|
||||
inline std::string PrintOutputOptions(const bool /* markdown */) { return ""; }
|
||||
inline std::string PrintOutputOptions(util::Params& /* p */,
|
||||
const bool /* markdown */)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
std::string PrintOutputOptions(const bool markdown,
|
||||
std::string PrintOutputOptions(util::Params& p,
|
||||
const bool markdown,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args)
|
||||
@@ -183,9 +190,9 @@ std::string PrintOutputOptions(const bool markdown,
|
||||
// See if this is part of the program.
|
||||
std::string result = "";
|
||||
std::string command_prefix = "R> ";
|
||||
if (IO::Parameters().count(paramName) > 0)
|
||||
if (p.Parameters().count(paramName) > 0)
|
||||
{
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = p.Parameters()[paramName];
|
||||
if (!d.input)
|
||||
{
|
||||
// Print a new line for the output option.
|
||||
@@ -205,7 +212,7 @@ std::string PrintOutputOptions(const bool markdown,
|
||||
}
|
||||
|
||||
// Continue recursion.
|
||||
std::string rest = PrintOutputOptions(markdown, args...);
|
||||
std::string rest = PrintOutputOptions(p, markdown, args...);
|
||||
if (rest != "" && result != "")
|
||||
result += "\n";
|
||||
result += rest;
|
||||
@@ -223,26 +230,27 @@ std::string ProgramCall(const bool markdown,
|
||||
const std::string& programName,
|
||||
Args... args)
|
||||
{
|
||||
util::Params p = IO::Parameters(programName);
|
||||
std::ostringstream oss;
|
||||
if (markdown)
|
||||
oss << "R> ";
|
||||
|
||||
// Find out if we have any output options first.
|
||||
std::ostringstream ossOutput;
|
||||
ossOutput << PrintOutputOptions(markdown, args...);
|
||||
ossOutput << PrintOutputOptions(p, markdown, args...);
|
||||
if (ossOutput.str() != "")
|
||||
oss << "output <- ";
|
||||
oss << programName << "(";
|
||||
|
||||
// Now process each input option.
|
||||
oss << PrintInputOptions(args...);
|
||||
oss << PrintInputOptions(p, args...);
|
||||
oss << ")";
|
||||
|
||||
std::string call = oss.str();
|
||||
oss.str(""); // Reset it.
|
||||
|
||||
// Now process each output option.
|
||||
oss << PrintOutputOptions(markdown, args...);
|
||||
oss << PrintOutputOptions(p, markdown, args...);
|
||||
if (markdown)
|
||||
{
|
||||
if (oss.str() == "")
|
||||
@@ -262,14 +270,14 @@ std::string ProgramCall(const bool markdown,
|
||||
* Given the name of a binding, print a program call assuming that all options
|
||||
* are specified. The programName should not be the output of GetBindingName().
|
||||
*/
|
||||
inline std::string ProgramCall(const std::string& programName)
|
||||
inline std::string ProgramCall(util::Params& p, const std::string& programName)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
std::string command_prefix = "R> ";
|
||||
oss << command_prefix;
|
||||
|
||||
// Determine if we have any output options.
|
||||
std::map<std::string, util::ParamData>& parameters = IO::Parameters();
|
||||
std::map<std::string, util::ParamData>& parameters = p.Parameters();
|
||||
bool hasOutput = false;
|
||||
for (auto it = parameters.begin(); it != parameters.end(); ++it)
|
||||
{
|
||||
@@ -289,8 +297,7 @@ inline std::string ProgramCall(const std::string& programName)
|
||||
bool first = true;
|
||||
for (auto it = parameters.begin(); it != parameters.end(); ++it)
|
||||
{
|
||||
if (!it->second.input || (it->second.persistent &&
|
||||
it->second.name != "verbose"))
|
||||
if (!it->second.input)
|
||||
continue;
|
||||
|
||||
if (!first)
|
||||
@@ -302,8 +309,8 @@ inline std::string ProgramCall(const std::string& programName)
|
||||
oss << it->second.name << "=";
|
||||
|
||||
std::string value;
|
||||
IO::GetSingleton().functionMap[it->second.tname]["DefaultParam"](
|
||||
it->second, NULL, (void*) &value);
|
||||
p.functionMap[it->second.tname]["DefaultParam"]( it->second, NULL,
|
||||
(void*) &value);
|
||||
oss << value;
|
||||
}
|
||||
oss << ")";
|
||||
@@ -374,16 +381,20 @@ inline std::string ParamString(const std::string& paramName, const T& value)
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline bool IgnoreCheck(const std::string& paramName)
|
||||
inline bool IgnoreCheck(const std::string& bindingName,
|
||||
const std::string& paramName)
|
||||
{
|
||||
return !IO::Parameters()[paramName].input;
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
return !p.Parameters()[paramName].input;
|
||||
}
|
||||
|
||||
inline bool IgnoreCheck(const std::vector<std::string>& constraints)
|
||||
inline bool IgnoreCheck(const std::string& bindingName,
|
||||
const std::vector<std::string>& constraints)
|
||||
{
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
for (size_t i = 0; i < constraints.size(); ++i)
|
||||
{
|
||||
if (!IO::Parameters()[constraints[i]].input)
|
||||
if (!p.Parameters()[constraints[i]].input)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -391,16 +402,18 @@ inline bool IgnoreCheck(const std::vector<std::string>& constraints)
|
||||
}
|
||||
|
||||
inline bool IgnoreCheck(
|
||||
const std::string& bindingName,
|
||||
const std::vector<std::pair<std::string, bool>>& constraints,
|
||||
const std::string& paramName)
|
||||
{
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
for (size_t i = 0; i < constraints.size(); ++i)
|
||||
{
|
||||
if (!IO::Parameters()[constraints[i].first].input)
|
||||
if (!p.Parameters()[constraints[i].first].input)
|
||||
return true;
|
||||
}
|
||||
|
||||
return !IO::Parameters()[paramName].input;
|
||||
return !p.Parameters()[paramName].input;
|
||||
}
|
||||
|
||||
} // namespace r
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace r {
|
||||
template<typename T>
|
||||
void PrintInputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
if (!d.required)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ void PrintInputProcessing(
|
||||
* This gives us code like:
|
||||
*
|
||||
* if (!identical(<param_name>, NA)) {
|
||||
* IO_SetParam<type>("<param_name>", <param_name>)
|
||||
* SetParam<type>(p, "<param_name>", <param_name>)
|
||||
* }
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " if (!identical(" << d.name;
|
||||
@@ -49,7 +49,7 @@ void PrintInputProcessing(
|
||||
{
|
||||
MLPACK_COUT_STREAM << ", NA)) {" << std::endl;
|
||||
}
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", " << d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
|
||||
}
|
||||
@@ -58,9 +58,9 @@ void PrintInputProcessing(
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* IO_SetParam<type>("<param_name>", <param_name>)
|
||||
* SetParam<type>(p, "<param_name>", <param_name>)
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", " << d.name << ")" << std::endl;
|
||||
}
|
||||
MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
|
||||
@@ -72,7 +72,7 @@ void PrintInputProcessing(
|
||||
template<typename T>
|
||||
void PrintInputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
if (!d.required)
|
||||
{
|
||||
@@ -80,12 +80,12 @@ void PrintInputProcessing(
|
||||
* This gives us code like:
|
||||
*
|
||||
* if (!identical(<param_name>, NA)) {
|
||||
* IO_SetParam<type>("<param_name>", to_matrix(<param_name>))
|
||||
* SetParam<type>(p, "<param_name>", to_matrix(<param_name>))
|
||||
* }
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
|
||||
<< std::endl;
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", to_matrix(" << d.name << "))" << std::endl;
|
||||
MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
|
||||
}
|
||||
@@ -94,9 +94,9 @@ void PrintInputProcessing(
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* IO_SetParam<type>("<param_name>", to_matrix(<param_name>))
|
||||
* SetParam<type>(p, "<param_name>", to_matrix(<param_name>))
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", to_matrix(" << d.name << "))" << std::endl;
|
||||
}
|
||||
MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
|
||||
@@ -108,8 +108,8 @@ void PrintInputProcessing(
|
||||
template<typename T>
|
||||
void PrintInputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
if (!d.required)
|
||||
{
|
||||
@@ -118,15 +118,15 @@ void PrintInputProcessing(
|
||||
*
|
||||
* if (!identical(<param_name>, NA)) {
|
||||
* <param_name> = to_matrix_with_info(<param_name>)
|
||||
* IO_SetParam<type>("<param_name>", <param_name>$info,
|
||||
* <param_name>$data)
|
||||
* SetParam<type>(p, "<param_name>", <param_name>$info,
|
||||
* <param_name>$data)
|
||||
* }
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
|
||||
<< std::endl;
|
||||
MLPACK_COUT_STREAM << " " << d.name << " <- to_matrix_with_info("
|
||||
<< d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", " << d.name << "$info, " << d.name
|
||||
<< "$data)" << std::endl;
|
||||
MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
|
||||
@@ -137,12 +137,12 @@ void PrintInputProcessing(
|
||||
* This gives us code like:
|
||||
*
|
||||
* <param_name> = to_matrix_with_info(<param_name>)
|
||||
* IO_SetParam<type>("<param_name>", <param_name>$info,
|
||||
* <param_name>$data)
|
||||
* SetParam<type>(p, "<param_name>", <param_name>$info,
|
||||
* <param_name>$data)
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " " << d.name << " <- to_matrix_with_info("
|
||||
<< d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << GetType<T>(d) << "(\""
|
||||
MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
|
||||
<< d.name << "\", " << d.name << "$info, " << d.name
|
||||
<< "$data)" << std::endl;
|
||||
}
|
||||
@@ -155,8 +155,8 @@ void PrintInputProcessing(
|
||||
template<typename T>
|
||||
void PrintInputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
if (!d.required)
|
||||
{
|
||||
@@ -164,13 +164,13 @@ void PrintInputProcessing(
|
||||
* This gives us code like:
|
||||
*
|
||||
* if (!identical(<param_name>, NA)) {
|
||||
* IO_SetParam<ModelType>Ptr("<param_name>", <param_name>)
|
||||
* SetParam<ModelType>Ptr(p, "<param_name>", <param_name>)
|
||||
* }
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
|
||||
<< std::endl;
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << util::StripType(d.cppType)
|
||||
<< "Ptr(\"" << d.name << "\", " << d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
|
||||
<< "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
|
||||
}
|
||||
else
|
||||
@@ -178,10 +178,10 @@ void PrintInputProcessing(
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* IO_SetParam<ModelType>Ptr("<param_name>", <param_name>)
|
||||
* SetParam<ModelType>Ptr(p, "<param_name>", <param_name>)
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " IO_SetParam" << util::StripType(d.cppType)
|
||||
<< "Ptr(\"" << d.name << "\", " << d.name << ")" << std::endl;
|
||||
MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
|
||||
<< "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
|
||||
}
|
||||
MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
|
||||
}
|
||||
|
||||
@@ -26,20 +26,20 @@ namespace r {
|
||||
template<typename T>
|
||||
void PrintOutputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* "<param_name>" = IO_GetParam<Type>("param_name")
|
||||
* "<param_name>" = GetParam<Type>(p, "param_name")
|
||||
*
|
||||
*/
|
||||
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = IO_GetParam" << GetType<T>(d)
|
||||
<< "(\"" << d.name << "\")";
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = GetParam" << GetType<T>(d)
|
||||
<< "(p, \"" << d.name << "\")";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,19 +48,19 @@ void PrintOutputProcessing(
|
||||
template<typename T>
|
||||
void PrintOutputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* "<param_name>" = IO_GetParam<Type>("param_name")
|
||||
* "<param_name>" = GetParam<Type>(p, "param_name")
|
||||
*
|
||||
*/
|
||||
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = IO_GetParam" << GetType<T>(d)
|
||||
<< "(\"" << d.name << "\")";
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = GetParam" << GetType<T>(d)
|
||||
<< "(p, \"" << d.name << "\")";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,18 +69,18 @@ void PrintOutputProcessing(
|
||||
template<typename T>
|
||||
void PrintOutputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* "<param_name>" = IO_GetParam<Type>("param_name")
|
||||
* "<param_name>" = GetParam<Type>(p, "param_name")
|
||||
*
|
||||
*/
|
||||
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = IO_GetParam" << GetType<T>(d)
|
||||
<< "(\"" << d.name << "\")";
|
||||
MLPACK_COUT_STREAM << " \"" << d.name << "\" = GetParam" << GetType<T>(d)
|
||||
<< "(p, \"" << d.name << "\")";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +89,8 @@ void PrintOutputProcessing(
|
||||
template<typename T>
|
||||
void PrintOutputProcessing(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
/**
|
||||
* This gives us code like:
|
||||
|
||||
@@ -54,12 +54,12 @@ void PrintSerializeUtil(
|
||||
/**
|
||||
* This gives us code like:
|
||||
*
|
||||
* <param_name> <- IO_GetParam<ModelType>Ptr("<param_name>")
|
||||
* <param_name> <- GetParam<ModelType>Ptr(p, "<param_name>")
|
||||
* attr(<param_name>, "type") <- "<ModelType>"
|
||||
*
|
||||
*/
|
||||
MLPACK_COUT_STREAM << " " << d.name << " <- IO_GetParam"
|
||||
<< util::StripType(d.cppType) << "Ptr(\"" << d.name << "\")";
|
||||
MLPACK_COUT_STREAM << " " << d.name << " <- GetParam"
|
||||
<< util::StripType(d.cppType) << "Ptr(p, \"" << d.name << "\")";
|
||||
MLPACK_COUT_STREAM << std::endl;
|
||||
MLPACK_COUT_STREAM << " attr(" << d.name << ", \"type\") <- \""
|
||||
<< util::StripType(d.cppType) << "\"";
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace r {
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string representing the command-line type of a vector.
|
||||
@@ -62,8 +62,8 @@ std::string PrintTypeDoc(
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Print the command-line type of an option into a string.
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace r {
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
// A flag type.
|
||||
if (std::is_same<T, bool>::value)
|
||||
@@ -146,8 +146,8 @@ std::string PrintTypeDoc(
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*)
|
||||
{
|
||||
return "An mlpack model pointer. `<Model>` refers to the type of model that "
|
||||
"is being stored, so, e.g., for `cf()`, the type will be `CFModel`. "
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
#define Free(p) (R_chk_free( (void *)(p) ), (p) = NULL)
|
||||
|
||||
// [[Rcpp::export]]
|
||||
void ${PROGRAM_NAME}_mlpackMain()
|
||||
void ${PROGRAM_NAME}_call(SEXP params, SEXP timers)
|
||||
{
|
||||
mlpackMain();
|
||||
util::Params& p = *Rcpp::as<Rcpp::XPtr<util::Params>>(params);
|
||||
util::Timers& t = *Rcpp::as<Rcpp::XPtr<util::Timers>>(timers);
|
||||
|
||||
BINDING_FUNCTION(p, t);
|
||||
}
|
||||
|
||||
// Any implementations of methods for dealing with model pointers will be put
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
*/
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/core/util/io.hpp>
|
||||
|
||||
#ifdef BINDING_NAME
|
||||
#undef BINDING_NAME
|
||||
#endif
|
||||
#define BINDING_NAME test_R_binding
|
||||
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
#include <mlpack/core/kernels/gaussian_kernel.hpp>
|
||||
|
||||
@@ -19,7 +25,7 @@ using namespace mlpack;
|
||||
using namespace mlpack::kernel;
|
||||
|
||||
// Program Name.
|
||||
BINDING_NAME("R binding test");
|
||||
BINDING_USER_NAME("R binding test");
|
||||
|
||||
// Short description.
|
||||
BINDING_SHORT_DESC(
|
||||
@@ -65,110 +71,110 @@ PARAM_MODEL_OUT(GaussianKernel, "model_out", "Output model, with twice the "
|
||||
"bandwidth.", "");
|
||||
PARAM_DOUBLE_OUT("model_bw_out", "The bandwidth of the model.");
|
||||
|
||||
static void mlpackMain()
|
||||
void BINDING_FUNCTION(util::Params& params, util::Timers& /* timers */)
|
||||
{
|
||||
const string s = IO::GetParam<string>("string_in");
|
||||
const int i = IO::GetParam<int>("int_in");
|
||||
const double d = IO::GetParam<double>("double_in");
|
||||
const string s = params.Get<string>("string_in");
|
||||
const int i = params.Get<int>("int_in");
|
||||
const double d = params.Get<double>("double_in");
|
||||
|
||||
IO::GetParam<string>("string_out") = "wrong";
|
||||
IO::GetParam<int>("int_out") = 11;
|
||||
IO::GetParam<double>("double_out") = 3.0;
|
||||
params.Get<string>("string_out") = "wrong";
|
||||
params.Get<int>("int_out") = 11;
|
||||
params.Get<double>("double_out") = 3.0;
|
||||
|
||||
// Check that everything is right on the input, and then set output
|
||||
// accordingly.
|
||||
if (!IO::HasParam("flag2") && IO::HasParam("flag1"))
|
||||
if (!params.Has("flag2") && params.Has("flag1"))
|
||||
{
|
||||
if (s == "hello")
|
||||
IO::GetParam<string>("string_out") = "hello2";
|
||||
params.Get<string>("string_out") = "hello2";
|
||||
|
||||
if (i == 12)
|
||||
IO::GetParam<int>("int_out") = 13;
|
||||
params.Get<int>("int_out") = 13;
|
||||
|
||||
if (d == 4.0)
|
||||
IO::GetParam<double>("double_out") = 5.0;
|
||||
params.Get<double>("double_out") = 5.0;
|
||||
}
|
||||
|
||||
// Input matrices should be at least 5 rows; the 5th row will be dropped and
|
||||
// the 3rd row will be multiplied by two.
|
||||
if (IO::HasParam("matrix_in"))
|
||||
if (params.Has("matrix_in"))
|
||||
{
|
||||
arma::mat out = move(IO::GetParam<arma::mat>("matrix_in"));
|
||||
arma::mat out = move(params.Get<arma::mat>("matrix_in"));
|
||||
out.shed_row(4);
|
||||
out.row(2) *= 2.0;
|
||||
|
||||
IO::GetParam<arma::mat>("matrix_out") = move(out);
|
||||
params.Get<arma::mat>("matrix_out") = move(out);
|
||||
}
|
||||
|
||||
// Input matrices should be at least 5 rows; the 5th row will be dropped and
|
||||
// the 3rd row will be multiplied by two.
|
||||
if (IO::HasParam("umatrix_in"))
|
||||
if (params.Has("umatrix_in"))
|
||||
{
|
||||
arma::Mat<size_t> out =
|
||||
move(IO::GetParam<arma::Mat<size_t>>("umatrix_in"));
|
||||
move(params.Get<arma::Mat<size_t>>("umatrix_in"));
|
||||
out.shed_row(4);
|
||||
out.row(2) *= 2;
|
||||
|
||||
IO::GetParam<arma::Mat<size_t>>("umatrix_out") = move(out);
|
||||
params.Get<arma::Mat<size_t>>("umatrix_out") = move(out);
|
||||
}
|
||||
|
||||
// An input column or row should have all elements multiplied by two.
|
||||
if (IO::HasParam("col_in"))
|
||||
if (params.Has("col_in"))
|
||||
{
|
||||
arma::vec out = move(IO::GetParam<arma::vec>("col_in"));
|
||||
arma::vec out = move(params.Get<arma::vec>("col_in"));
|
||||
out *= 2.0;
|
||||
|
||||
IO::GetParam<arma::vec>("col_out") = move(out);
|
||||
params.Get<arma::vec>("col_out") = move(out);
|
||||
}
|
||||
|
||||
if (IO::HasParam("ucol_in"))
|
||||
if (params.Has("ucol_in"))
|
||||
{
|
||||
arma::Col<size_t> out =
|
||||
move(IO::GetParam<arma::Col<size_t>>("ucol_in"));
|
||||
move(params.Get<arma::Col<size_t>>("ucol_in"));
|
||||
out += 1;
|
||||
|
||||
IO::GetParam<arma::Col<size_t>>("ucol_out") = move(out);
|
||||
params.Get<arma::Col<size_t>>("ucol_out") = move(out);
|
||||
}
|
||||
|
||||
if (IO::HasParam("row_in"))
|
||||
if (params.Has("row_in"))
|
||||
{
|
||||
arma::rowvec out = move(IO::GetParam<arma::rowvec>("row_in"));
|
||||
arma::rowvec out = move(params.Get<arma::rowvec>("row_in"));
|
||||
out *= 2.0;
|
||||
|
||||
IO::GetParam<arma::rowvec>("row_out") = move(out);
|
||||
params.Get<arma::rowvec>("row_out") = move(out);
|
||||
}
|
||||
|
||||
if (IO::HasParam("urow_in"))
|
||||
if (params.Has("urow_in"))
|
||||
{
|
||||
arma::Row<size_t> out =
|
||||
move(IO::GetParam<arma::Row<size_t>>("urow_in"));
|
||||
move(params.Get<arma::Row<size_t>>("urow_in"));
|
||||
out += 1;
|
||||
|
||||
IO::GetParam<arma::Row<size_t>>("urow_out") = move(out);
|
||||
params.Get<arma::Row<size_t>>("urow_out") = move(out);
|
||||
}
|
||||
|
||||
// Vector arguments should have the last element removed.
|
||||
if (IO::HasParam("vector_in"))
|
||||
if (params.Has("vector_in"))
|
||||
{
|
||||
vector<int> out = move(IO::GetParam<vector<int>>("vector_in"));
|
||||
vector<int> out = move(params.Get<vector<int>>("vector_in"));
|
||||
out.pop_back();
|
||||
|
||||
IO::GetParam<vector<int>>("vector_out") = move(out);
|
||||
params.Get<vector<int>>("vector_out") = move(out);
|
||||
}
|
||||
|
||||
if (IO::HasParam("str_vector_in"))
|
||||
if (params.Has("str_vector_in"))
|
||||
{
|
||||
vector<string> out = move(IO::GetParam<vector<string>>("str_vector_in"));
|
||||
vector<string> out = move(params.Get<vector<string>>("str_vector_in"));
|
||||
out.pop_back();
|
||||
|
||||
IO::GetParam<vector<string>>("str_vector_out") = move(out);
|
||||
params.Get<vector<string>>("str_vector_out") = move(out);
|
||||
}
|
||||
|
||||
// All numeric elements should be multiplied by 3.
|
||||
if (IO::HasParam("matrix_and_info_in"))
|
||||
if (params.Has("matrix_and_info_in"))
|
||||
{
|
||||
typedef tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
TupleType tuple = move(IO::GetParam<TupleType>("matrix_and_info_in"));
|
||||
TupleType tuple = move(params.Get<TupleType>("matrix_and_info_in"));
|
||||
|
||||
const data::DatasetInfo& di = std::get<0>(tuple);
|
||||
arma::mat& m = std::get<1>(tuple);
|
||||
@@ -179,19 +185,19 @@ static void mlpackMain()
|
||||
m.row(i) *= 2.0;
|
||||
}
|
||||
|
||||
IO::GetParam<arma::mat>("matrix_and_info_out") = move(m);
|
||||
params.Get<arma::mat>("matrix_and_info_out") = move(m);
|
||||
}
|
||||
|
||||
// If we got a request to build a model, then build it.
|
||||
if (IO::HasParam("build_model"))
|
||||
if (params.Has("build_model"))
|
||||
{
|
||||
IO::GetParam<GaussianKernel*>("model_out") = new GaussianKernel(10.0);
|
||||
params.Get<GaussianKernel*>("model_out") = new GaussianKernel(10.0);
|
||||
}
|
||||
|
||||
// If we got an input model, double the bandwidth and output that.
|
||||
if (IO::HasParam("model_in"))
|
||||
if (params.Has("model_in"))
|
||||
{
|
||||
IO::GetParam<double>("model_bw_out") =
|
||||
IO::GetParam<GaussianKernel*>("model_in")->Bandwidth() * 2.0;
|
||||
params.Get<double>("model_bw_out") =
|
||||
params.Get<GaussianKernel*>("model_in")->Bandwidth() * 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ set(SOURCES
|
||||
get_printable_param_value_impl.hpp
|
||||
in_place_copy.hpp
|
||||
map_parameter_name.hpp
|
||||
mlpack_main.hpp
|
||||
output_param.hpp
|
||||
output_param_impl.hpp
|
||||
parameter_type.hpp
|
||||
@@ -50,11 +51,21 @@ if (BUILD_CLI_EXECUTABLES)
|
||||
add_executable(mlpack_${name}
|
||||
${name}_main.cpp
|
||||
)
|
||||
target_link_libraries(mlpack_${name}
|
||||
mlpack
|
||||
${ARMADILLO_LIBRARIES}
|
||||
${COMPILER_SUPPORT_LIBRARIES}
|
||||
)
|
||||
# Build mlpack CLI binding binaries statically.
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
target_link_libraries(mlpack_${name} -static
|
||||
mlpack
|
||||
${ARMADILLO_LIBRARIES}
|
||||
${COMPILER_SUPPORT_LIBRARIES}
|
||||
)
|
||||
else()
|
||||
# Build mlpack CLI binding binaries dynamically.
|
||||
target_link_libraries(mlpack_${name}
|
||||
mlpack
|
||||
${ARMADILLO_LIBRARIES}
|
||||
${COMPILER_SUPPORT_LIBRARIES}
|
||||
)
|
||||
endif()
|
||||
# Make sure that we set BINDING_TYPE to cli so the command-line program is
|
||||
# compiled with the correct int main() call.
|
||||
set_target_properties(mlpack_${name} PROPERTIES COMPILE_FLAGS
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace cli {
|
||||
|
||||
/**
|
||||
* Add a tuple option to CLI11.
|
||||
*
|
||||
*
|
||||
* @param cliName The name of the option to add to CLI11.
|
||||
* @param param an object of util::ParamData.
|
||||
* @param app A CLI11 object to add parameter to.
|
||||
@@ -33,22 +33,22 @@ template<typename T>
|
||||
void AddToCLI11(const std::string& cliName,
|
||||
util::ParamData& param,
|
||||
CLI::App& app,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
bool>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
bool>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>>::type* = 0)
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
app.add_option_function<std::string>(cliName.c_str(),
|
||||
[¶m](const std::string& value)
|
||||
{
|
||||
using TupleType = std::tuple<T, typename ParameterType<T>::type>;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(¶m.value);
|
||||
std::get<1>(tuple) = boost::any_cast<std::string>(value);
|
||||
std::get<0>(std::get<1>(tuple)) = boost::any_cast<std::string>(value);
|
||||
param.wasPassed = true;
|
||||
},
|
||||
param.desc.c_str());
|
||||
@@ -56,7 +56,7 @@ void AddToCLI11(const std::string& cliName,
|
||||
|
||||
/**
|
||||
* Add a serializable option to CLI11.
|
||||
*
|
||||
*
|
||||
* @param cliName The name of the option to add to CLI11.
|
||||
* @param param an object of util::ParamData.
|
||||
* @param app a CLI11 object to add parameter to.
|
||||
@@ -65,15 +65,15 @@ template<typename T>
|
||||
void AddToCLI11(const std::string& cliName,
|
||||
util::ParamData& param,
|
||||
CLI::App& app,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
bool>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<
|
||||
data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
bool>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<
|
||||
data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>>::type* = 0)
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
app.add_option_function<std::string>(cliName.c_str(),
|
||||
[¶m](const std::string& value)
|
||||
@@ -97,20 +97,20 @@ template<typename T>
|
||||
void AddToCLI11(const std::string& cliName,
|
||||
util::ParamData& param,
|
||||
CLI::App& app,
|
||||
const typename boost::disable_if<
|
||||
std::is_same<T, bool>>::type* = 0,
|
||||
const typename boost::enable_if<
|
||||
arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
const typename std::enable_if<!
|
||||
std::is_same<T, bool>::value>::type* = 0,
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>>::type* = 0)
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
app.add_option_function<std::string>(cliName.c_str(),
|
||||
[¶m](const std::string& value)
|
||||
{
|
||||
using TupleType = std::tuple<T, typename ParameterType<T>::type>;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(¶m.value);
|
||||
std::get<1>(tuple) = boost::any_cast<std::string>(value);
|
||||
std::get<0>(std::get<1>(tuple)) = boost::any_cast<std::string>(value);
|
||||
param.wasPassed = true;
|
||||
},
|
||||
param.desc.c_str());
|
||||
@@ -118,7 +118,7 @@ void AddToCLI11(const std::string& cliName,
|
||||
|
||||
/**
|
||||
* Add an option to CLI11.
|
||||
*
|
||||
*
|
||||
* @param cliName The name of the option to add to CLI11.
|
||||
* @param param an object of util::ParamData.
|
||||
* @param app a CLI11 object to add parameter to.
|
||||
@@ -127,15 +127,15 @@ template<typename T>
|
||||
void AddToCLI11(const std::string& cliName,
|
||||
util::ParamData& param,
|
||||
CLI::App& app,
|
||||
const typename boost::disable_if<
|
||||
std::is_same<T, bool>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
const typename std::enable_if<!
|
||||
std::is_same<T, bool>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>>::type* = 0)
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
app.add_option_function<T>(cliName.c_str(),
|
||||
[¶m](const T& value)
|
||||
@@ -157,15 +157,15 @@ template<typename T>
|
||||
void AddToCLI11(const std::string& cliName,
|
||||
util::ParamData& param,
|
||||
CLI::App& app,
|
||||
const typename boost::enable_if<
|
||||
std::is_same<T, bool>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<
|
||||
data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
const typename std::enable_if<
|
||||
std::is_same<T, bool>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!
|
||||
data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>>::type* = 0)
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
app.add_flag_function(cliName.c_str(),
|
||||
[¶m](const T& value)
|
||||
|
||||
@@ -63,7 +63,8 @@ class CLIOption
|
||||
* @param input Whether or not the option is an input option.
|
||||
* @param noTranspose If the parameter is a matrix and this is true, then the
|
||||
* matrix will not be transposed on loading.
|
||||
* @param * (testName) Is not used and added for compatibility reasons.
|
||||
* @param bindingName Name of the binding that this option is for. If empty,
|
||||
* then it will be added to every binding.
|
||||
*/
|
||||
CLIOption(const N defaultValue,
|
||||
const std::string& identifier,
|
||||
@@ -73,7 +74,7 @@ class CLIOption
|
||||
const bool required = false,
|
||||
const bool input = true,
|
||||
const bool noTranspose = false,
|
||||
const std::string& /*testName*/ = "")
|
||||
const std::string& bindingName = "")
|
||||
{
|
||||
// Create the ParamData object to give to CLI.
|
||||
util::ParamData data;
|
||||
@@ -87,7 +88,6 @@ class CLIOption
|
||||
data.required = required;
|
||||
data.input = input;
|
||||
data.loaded = false;
|
||||
data.persistent = false; // All CLI parameters are not persistent.
|
||||
data.cppType = cppName;
|
||||
|
||||
// Apply default value.
|
||||
@@ -109,58 +109,23 @@ class CLIOption
|
||||
std::string progOptId = (alias[0] != '\0') ?
|
||||
"-" + std::string(1, alias[0]) + ",--" + cliName : "--" + cliName;
|
||||
|
||||
// Do a check to ensure that the boost name isn't already in use.
|
||||
const std::map<std::string, util::ParamData>& parameters =
|
||||
IO::Parameters();
|
||||
if (parameters.count(cliName) > 0)
|
||||
{
|
||||
// Create a fake Log::Fatal since it may not yet be initialized.
|
||||
// Temporarily define color code escape sequences.
|
||||
#ifndef _WIN32
|
||||
#define BASH_RED "\033[0;31m"
|
||||
#define BASH_CLEAR "\033[0m"
|
||||
#else
|
||||
#define BASH_RED ""
|
||||
#define BASH_CLEAR ""
|
||||
#endif
|
||||
|
||||
// Temporary outstream object for detecting duplicate identifiers.
|
||||
util::PrefixedOutStream outstr(std::cerr,
|
||||
BASH_RED "[FATAL] " BASH_CLEAR, false, true /* fatal */);
|
||||
|
||||
#undef BASH_RED
|
||||
#undef BASH_CLEAR
|
||||
|
||||
outstr << "Parameter --" << cliName << " (" << data.alias << ") "
|
||||
<< "is defined multiple times with the same identifiers."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
IO::Add(std::move(data));
|
||||
|
||||
// Set some function pointers that we need.
|
||||
IO::GetSingleton().functionMap[tname]["DefaultParam"] =
|
||||
&DefaultParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["OutputParam"] =
|
||||
&OutputParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetPrintableParam"] =
|
||||
&GetPrintableParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["StringTypeParam"] =
|
||||
&StringTypeParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetParam"] = &GetParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetRawParam"] = &GetRawParam<N>;
|
||||
IO::GetSingleton().functionMap[tname]["AddToCLI11"] = &AddToCLI11<N>;
|
||||
IO::GetSingleton().functionMap[tname]["MapParameterName"] =
|
||||
&MapParameterName<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetPrintableParamName"] =
|
||||
&GetPrintableParamName<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetPrintableParamValue"] =
|
||||
&GetPrintableParamValue<N>;
|
||||
IO::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
|
||||
&GetAllocatedMemory<N>;
|
||||
IO::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
|
||||
&DeleteAllocatedMemory<N>;
|
||||
IO::GetSingleton().functionMap[tname]["InPlaceCopy"] = &InPlaceCopy<N>;
|
||||
IO::AddFunction(tname, "DefaultParam", &DefaultParam<N>);
|
||||
IO::AddFunction(tname, "OutputParam", &OutputParam<N>);
|
||||
IO::AddFunction(tname, "GetPrintableParam", &GetPrintableParam<N>);
|
||||
IO::AddFunction(tname, "StringTypeParam", &StringTypeParam<N>);
|
||||
IO::AddFunction(tname, "GetParam", &GetParam<N>);
|
||||
IO::AddFunction(tname, "GetRawParam", &GetRawParam<N>);
|
||||
IO::AddFunction(tname, "AddToCLI11", &AddToCLI11<N>);
|
||||
IO::AddFunction(tname, "MapParameterName", &MapParameterName<N>);
|
||||
IO::AddFunction(tname, "GetPrintableParamName", &GetPrintableParamName<N>);
|
||||
IO::AddFunction(tname, "GetPrintableParamValue",
|
||||
&GetPrintableParamValue<N>);
|
||||
IO::AddFunction(tname, "GetAllocatedMemory", &GetAllocatedMemory<N>);
|
||||
IO::AddFunction(tname, "DeleteAllocatedMemory", &DeleteAllocatedMemory<N>);
|
||||
IO::AddFunction(tname, "InPlaceCopy", &InPlaceCopy<N>);
|
||||
|
||||
IO::AddParameter(bindingName, std::move(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a vector option.
|
||||
@@ -39,7 +40,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a string option.
|
||||
@@ -47,7 +48,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a matrix option, a tuple option, a
|
||||
@@ -57,7 +58,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */ = 0);
|
||||
@@ -69,8 +70,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of an option. This is the function that will be
|
||||
|
||||
@@ -24,12 +24,13 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if (!std::is_same<T, bool>::value)
|
||||
@@ -44,7 +45,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* /* junk */)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
@@ -88,7 +89,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type*)
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *boost::any_cast<std::string>(&data.value);
|
||||
return "'" + s + "'";
|
||||
@@ -100,7 +101,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */)
|
||||
@@ -115,8 +116,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
return "''";
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace cli {
|
||||
template<typename T>
|
||||
void DeleteAllocatedMemoryImpl(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
@@ -30,7 +30,7 @@ void DeleteAllocatedMemoryImpl(
|
||||
template<typename T>
|
||||
void DeleteAllocatedMemoryImpl(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
@@ -38,8 +38,8 @@ void DeleteAllocatedMemoryImpl(
|
||||
template<typename T>
|
||||
void DeleteAllocatedMemoryImpl(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Delete the allocated memory (hopefully we actually own it).
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
|
||||
@@ -23,21 +23,21 @@ namespace cli {
|
||||
* Handle command-line program termination. If --help or --info was passed, we
|
||||
* won't make it here, so we don't have to write any contingencies for that.
|
||||
*/
|
||||
inline void EndProgram()
|
||||
inline void EndProgram(util::Params& params, util::Timers& timers)
|
||||
{
|
||||
// Stop the CLI timers.
|
||||
IO::GetSingleton().timer.StopAllTimers();
|
||||
// Stop the timers.
|
||||
timers.StopAllTimers();
|
||||
|
||||
// Print any output.
|
||||
std::map<std::string, util::ParamData>& parameters = IO::Parameters();
|
||||
std::map<std::string, util::ParamData>& parameters = params.Parameters();
|
||||
for (auto& it : parameters)
|
||||
{
|
||||
util::ParamData& d = it.second;
|
||||
if (!d.input)
|
||||
IO::GetSingleton().functionMap[d.tname]["OutputParam"](d, NULL, NULL);
|
||||
params.functionMap[d.tname]["OutputParam"](d, NULL, NULL);
|
||||
}
|
||||
|
||||
if (IO::HasParam("verbose"))
|
||||
if (params.Has("verbose"))
|
||||
{
|
||||
Log::Info << std::endl << "Execution parameters:" << std::endl;
|
||||
|
||||
@@ -48,21 +48,34 @@ inline void EndProgram()
|
||||
// We can handle strings, ints, bools, doubles.
|
||||
util::ParamData& data = it.second;
|
||||
std::string cliName;
|
||||
IO::GetSingleton().functionMap[data.tname]["MapParameterName"](data,
|
||||
NULL, (void*) &cliName);
|
||||
params.functionMap[data.tname]["MapParameterName"](data, NULL,
|
||||
(void*) &cliName);
|
||||
Log::Info << " " << cliName << ": ";
|
||||
|
||||
std::string printableParam;
|
||||
IO::GetSingleton().functionMap[data.tname]["GetPrintableParam"](data,
|
||||
NULL, (void*) &printableParam);
|
||||
params.functionMap[data.tname]["GetPrintableParam"](data, NULL,
|
||||
(void*) &printableParam);
|
||||
Log::Info << printableParam << std::endl;
|
||||
}
|
||||
|
||||
Log::Info << "Program timers:" << std::endl;
|
||||
for (auto& it2 : IO::GetSingleton().timer.GetAllTimers())
|
||||
|
||||
// Merge the global timers with the binding-specific ones.
|
||||
std::map<std::string, std::chrono::microseconds> timerMap =
|
||||
timers.GetAllTimers();
|
||||
std::map<std::string, std::chrono::microseconds> globalTimerMap =
|
||||
Timer::GetAllTimers();
|
||||
for (auto& it : globalTimerMap)
|
||||
{
|
||||
Log::Info << " " << it2.first << ": ";
|
||||
IO::GetSingleton().timer.PrintTimer(it2.first);
|
||||
if (timerMap.count(it.first) == 1)
|
||||
timerMap[it.first] += it.second;
|
||||
else
|
||||
timerMap[it.first] = it.second;
|
||||
}
|
||||
|
||||
for (auto& it2 : timerMap)
|
||||
{
|
||||
Log::Info << " " << it2.first << ": " << timers.Print(it2.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +88,8 @@ inline void EndProgram()
|
||||
util::ParamData& data = it.second;
|
||||
|
||||
void* result;
|
||||
IO::GetSingleton().functionMap[data.tname]["GetAllocatedMemory"](data,
|
||||
NULL, (void*) &result);
|
||||
params.functionMap[data.tname]["GetAllocatedMemory"](data, NULL,
|
||||
(void*) &result);
|
||||
if (result != NULL && memoryAddresses.count(result) == 0)
|
||||
memoryAddresses[result] = &data;
|
||||
}
|
||||
@@ -88,8 +101,7 @@ inline void EndProgram()
|
||||
{
|
||||
util::ParamData& data = *(it2->second);
|
||||
|
||||
IO::GetSingleton().functionMap[data.tname]["DeleteAllocatedMemory"](data,
|
||||
NULL, NULL);
|
||||
params.functionMap[data.tname]["DeleteAllocatedMemory"](data, NULL, NULL);
|
||||
|
||||
++it2;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace cli {
|
||||
template<typename T>
|
||||
void* GetAllocatedMemory(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ void* GetAllocatedMemory(
|
||||
template<typename T>
|
||||
void* GetAllocatedMemory(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -39,8 +39,8 @@ void* GetAllocatedMemory(
|
||||
template<typename T>
|
||||
void* GetAllocatedMemory(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Here we have a model, which is a tuple, and we need the address of the
|
||||
// memory.
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace cli {
|
||||
template<typename T>
|
||||
T& GetParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed, so just cast it directly.
|
||||
return *boost::any_cast<T>(&d.value);
|
||||
@@ -45,7 +45,7 @@ T& GetParam(
|
||||
template<typename T>
|
||||
T& GetParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// If the matrix is an input matrix, we have to load the matrix. 'value'
|
||||
// contains the filename. It's possible we could load empty matrices many
|
||||
@@ -53,8 +53,10 @@ T& GetParam(
|
||||
// happens.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
|
||||
const std::string& value = std::get<1>(tuple);
|
||||
const std::string& value = std::get<0>(std::get<1>(tuple));
|
||||
T& matrix = std::get<0>(tuple);
|
||||
size_t& n_rows = std::get<1>(std::get<1>(tuple));
|
||||
size_t& n_cols = std::get<2>(std::get<1>(tuple));
|
||||
if (d.input && !d.loaded)
|
||||
{
|
||||
// Call correct data::Load() function.
|
||||
@@ -62,6 +64,8 @@ T& GetParam(
|
||||
data::Load(value, matrix, true);
|
||||
else
|
||||
data::Load(value, matrix, true, !d.noTranspose);
|
||||
n_rows = matrix.n_rows;
|
||||
n_cols = matrix.n_cols;
|
||||
d.loaded = true;
|
||||
}
|
||||
|
||||
@@ -76,18 +80,22 @@ T& GetParam(
|
||||
template<typename T>
|
||||
T& GetParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// If this is an input parameter, we need to load both the matrix and the
|
||||
// dataset info.
|
||||
typedef std::tuple<T, std::string> TupleType;
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
TupleType* tuple = boost::any_cast<TupleType>(&d.value);
|
||||
const std::string& value = std::get<1>(*tuple);
|
||||
const std::string& value = std::get<0>(std::get<1>(*tuple));
|
||||
T& t = std::get<0>(*tuple);
|
||||
size_t& n_rows = std::get<1>(std::get<1>(*tuple));
|
||||
size_t& n_cols = std::get<2>(std::get<1>(*tuple));
|
||||
if (d.input && !d.loaded)
|
||||
{
|
||||
data::Load(value, std::get<1>(t), std::get<0>(t), true, !d.noTranspose);
|
||||
n_rows = std::get<1>(t).n_rows;
|
||||
n_cols = std::get<1>(t).n_cols;
|
||||
d.loaded = true;
|
||||
}
|
||||
|
||||
@@ -102,8 +110,8 @@ T& GetParam(
|
||||
template<typename T>
|
||||
T*& GetParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// If the model is an input model, we have to load it from file. 'value'
|
||||
// contains the filename.
|
||||
|
||||
@@ -27,11 +27,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Print a vector option, with spaces between it.
|
||||
@@ -57,8 +57,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Print an option into a std::string. This should print a short, one-line
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << boost::any_cast<T>(data.value);
|
||||
@@ -83,13 +83,15 @@ std::string GetPrintableParam(
|
||||
const TupleType* tuple = boost::any_cast<TupleType>(&data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "'" << std::get<1>(*tuple) << "'";
|
||||
oss << "'" << std::get<0>(std::get<1>(*tuple)) << "'";
|
||||
|
||||
if (std::get<1>(*tuple) != "")
|
||||
if (std::get<0>(std::get<1>(*tuple)) != "")
|
||||
{
|
||||
// Make sure the matrix is loaded so that we can print its size.
|
||||
T& mat = GetParam<T>(const_cast<util::ParamData&>(data));
|
||||
std::string matDescription = GetMatrixSize(mat);
|
||||
GetParam<T>(const_cast<util::ParamData&>(data));
|
||||
std::string matDescription =
|
||||
std::to_string(std::get<2>(std::get<1>(*tuple))) + "x" +
|
||||
std::to_string(std::get<1>(std::get<1>(*tuple))) + " matrix";
|
||||
|
||||
oss << " (" << matDescription << ")";
|
||||
}
|
||||
@@ -101,8 +103,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
// Extract the string from the tuple that's being held.
|
||||
typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a matrix type (where the user has to pass the file
|
||||
@@ -38,7 +38,7 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0);
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a serializable model type (where the user has to
|
||||
@@ -47,8 +47,8 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a mapped matrix type (where the user has to pass
|
||||
@@ -57,8 +57,8 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter's name as seen by the user.
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "--" + data.name;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type*)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type*)
|
||||
{
|
||||
return "--" + data.name + "_file";
|
||||
}
|
||||
@@ -53,8 +53,8 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*)
|
||||
{
|
||||
return "--" + data.name + "_file";
|
||||
}
|
||||
@@ -66,8 +66,8 @@ std::string GetPrintableParamName(
|
||||
template<typename T>
|
||||
std::string GetPrintableParamName(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "--" + data.name + "_file";
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& data,
|
||||
const std::string& value,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a matrix type (where the user has to pass the file
|
||||
@@ -40,7 +40,7 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& data,
|
||||
const std::string& value,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0);
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a serializable model type (where the user has to
|
||||
@@ -50,8 +50,8 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& data,
|
||||
const std::string& value,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter name for a mapped matrix type (where the user has to pass
|
||||
@@ -61,8 +61,8 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& data,
|
||||
const std::string& value,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Get the parameter's name as seen by the user.
|
||||
|
||||
@@ -28,10 +28,10 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& /* data */,
|
||||
const std::string& input,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& /* data */,
|
||||
const std::string& input,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type*)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type*)
|
||||
{
|
||||
return input + ".csv";
|
||||
}
|
||||
@@ -57,8 +57,8 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& /* data */,
|
||||
const std::string& input,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*)
|
||||
{
|
||||
return input + ".bin";
|
||||
}
|
||||
@@ -71,8 +71,8 @@ template<typename T>
|
||||
std::string GetPrintableParamValue(
|
||||
util::ParamData& /* data */,
|
||||
const std::string& input,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return input + ".arff";
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableType(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string representing the command-line type of a vector.
|
||||
@@ -60,8 +60,8 @@ std::string GetPrintableType(
|
||||
template<typename T>
|
||||
std::string GetPrintableType(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Print the command-line type of an option into a string.
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string GetPrintableType(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
if (std::is_same<T, bool>::value)
|
||||
return "flag";
|
||||
@@ -101,8 +101,8 @@ std::string GetPrintableType(
|
||||
template<typename T>
|
||||
std::string GetPrintableType(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*)
|
||||
{
|
||||
return data.cppType + " file";
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ namespace cli {
|
||||
template<typename T>
|
||||
T& GetRawParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed, so just cast it directly.
|
||||
return *boost::any_cast<T>(&d.value);
|
||||
@@ -42,13 +42,13 @@ T& GetRawParam(
|
||||
template<typename T>
|
||||
T& GetRawParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Don't load the matrix.
|
||||
typedef std::tuple<T, std::string> TupleType;
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
T& value = std::get<0>(*boost::any_cast<TupleType>(&d.value));
|
||||
return value;
|
||||
}
|
||||
@@ -59,8 +59,8 @@ T& GetRawParam(
|
||||
template<typename T>
|
||||
T*& GetRawParam(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Don't load the model.
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
|
||||
@@ -31,17 +31,17 @@ template<typename T>
|
||||
void InPlaceCopyInternal(
|
||||
util::ParamData& /* d */,
|
||||
util::ParamData& /* input */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the filename for any type that needs to be loaded from disk to match
|
||||
* the filename of the input parameter.
|
||||
* the filename of the input parameter, for a matrix/DatasetInfo parameter.
|
||||
*
|
||||
* @param d ParamData object we want to make into an in-place copy.
|
||||
* @param input ParamData object whose filename we should copy.
|
||||
@@ -53,12 +53,35 @@ void InPlaceCopyInternal(
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value ||
|
||||
data::HasSerialize<T>::value>::type* = 0)
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
// Make the output filename the same as the input filename.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
|
||||
std::string& value = std::get<0>(std::get<1>(tuple));
|
||||
|
||||
const TupleType& inputTuple = *boost::any_cast<TupleType>(&input.value);
|
||||
value = std::get<0>(std::get<1>(inputTuple));
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the filename for any type that needs to be loaded from disk to match
|
||||
* the filename of the input parameter. For serializable objects.
|
||||
*
|
||||
* @param d ParamData object we want to make into an in-place copy.
|
||||
* @param input ParamData object whose filename we should copy.
|
||||
*/
|
||||
template<typename T>
|
||||
void InPlaceCopyInternal(
|
||||
util::ParamData& d,
|
||||
util::ParamData& input,
|
||||
const typename std::enable_if<
|
||||
data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Make the output filename the same as the input filename.
|
||||
typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
|
||||
std::string& value = std::get<1>(tuple);
|
||||
|
||||
const TupleType& inputTuple = *boost::any_cast<TupleType>(&input.value);
|
||||
|
||||
@@ -27,10 +27,10 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string MapParameterName(
|
||||
const std::string& identifier,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ std::string MapParameterName(
|
||||
template<typename T>
|
||||
std::string MapParameterName(
|
||||
const std::string& identifier,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value ||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file mlpack_main.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Define the macros used when compiling a command-line binding. This file
|
||||
* should not be included directly; instead, mlpack/core/util/mlpack_main.hpp
|
||||
* should be included with the right setting of BINDING_TYPE.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_CLI_MLPACK_MAIN_HPP
|
||||
#define MLPACK_BINDINGS_CLI_MLPACK_MAIN_HPP
|
||||
|
||||
#ifndef BINDING_TYPE
|
||||
#error "BINDING_TYPE not defined! Don't include this file directly!"
|
||||
#endif
|
||||
#if BINDING_TYPE != BINDING_TYPE_CLI
|
||||
#error "BINDING_TYPE is not set to BINDING_TYPE_CLI!"
|
||||
#endif
|
||||
|
||||
// Matrices are transposed on load/save.
|
||||
#define BINDING_MATRIX_TRANSPOSED true
|
||||
|
||||
#include <mlpack/bindings/cli/cli_option.hpp>
|
||||
#include <mlpack/bindings/cli/print_doc_functions.hpp>
|
||||
|
||||
/**
|
||||
* PRINT_PARAM_STRING() returns a string that contains the correct
|
||||
* language-specific representation of a parameter's name.
|
||||
*/
|
||||
#define PRINT_PARAM_STRING(x) mlpack::bindings::cli::ParamString( \
|
||||
STRINGIFY(BINDING_NAME), x)
|
||||
|
||||
/**
|
||||
* PRINT_PARAM_VALUE() returns a string that contains a correct
|
||||
* language-specific representation of a parameter's value.
|
||||
*/
|
||||
#define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue
|
||||
|
||||
/**
|
||||
* PRINT_DATASET() returns a string that contains a correct language-specific
|
||||
* representation of a dataset name.
|
||||
*/
|
||||
#define PRINT_DATASET mlpack::bindings::cli::PrintDataset
|
||||
|
||||
/**
|
||||
* PRINT_MODEL() returns a string that contains a correct language-specific
|
||||
* representation of an mlpack model name.
|
||||
*/
|
||||
#define PRINT_MODEL mlpack::bindings::cli::PrintModel
|
||||
|
||||
/**
|
||||
* PRINT_CALL() returns a string that contains the full language-specific
|
||||
* representation of a call to an mlpack binding. The first argument should be
|
||||
* the name of the binding, and all other arguments should be names of
|
||||
* parameters followed by values (in the case where the preceding parameter is
|
||||
* not a flag).
|
||||
*/
|
||||
#define PRINT_CALL mlpack::bindings::cli::ProgramCall
|
||||
|
||||
/**
|
||||
* BINDING_IGNORE_CHECK() is an internally-used macro to determine whether or
|
||||
* not a specific parameter check should be ignored.
|
||||
*/
|
||||
#define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck
|
||||
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
template<typename T>
|
||||
using Option = mlpack::bindings::cli::CLIOption<T>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include <mlpack/core/util/param.hpp>
|
||||
#include <mlpack/core/util/timers.hpp>
|
||||
#include <mlpack/bindings/cli/parse_command_line.hpp>
|
||||
#include <mlpack/bindings/cli/end_program.hpp>
|
||||
|
||||
// Forward definition of the binding function.
|
||||
void BINDING_FUNCTION(mlpack::util::Params&, mlpack::util::Timers&);
|
||||
|
||||
// Define the main function that will be used by this binding.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Parse the command-line options; put them into CLI.
|
||||
mlpack::util::Params params =
|
||||
mlpack::bindings::cli::ParseCommandLine(argc, argv);
|
||||
// Create a new timer object for this call.
|
||||
mlpack::util::Timers timers;
|
||||
timers.Enabled() = true;
|
||||
mlpack::Timer::EnableTiming();
|
||||
|
||||
// A "total_time" timer is run by default for each mlpack program.
|
||||
timers.Start("total_time");
|
||||
BINDING_FUNCTION(params, timers);
|
||||
timers.Stop("total_time");
|
||||
|
||||
// Print output options, print verbose information, save model parameters,
|
||||
// clean up, and so forth.
|
||||
mlpack::bindings::cli::EndProgram(params, timers);
|
||||
}
|
||||
|
||||
// Add default parameters that are included in every program.
|
||||
PARAM_GLOBAL(bool, "help", "Default help info.", "h", "bool", false, true,
|
||||
false, false);
|
||||
PARAM_GLOBAL(std::string, "info", "Print help on a specific option.", "",
|
||||
"std::string", false, true, false, "");
|
||||
PARAM_GLOBAL(bool, "verbose", "Display informational messages and the full "
|
||||
"list of parameters and timers at the end of execution.", "v", "bool",
|
||||
false, true, false, false);
|
||||
PARAM_GLOBAL(bool, "version", "Display the version of mlpack.", "V", "bool",
|
||||
false, true, false, false);
|
||||
|
||||
#endif
|
||||
@@ -26,11 +26,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Output a vector option (print to stdout).
|
||||
@@ -38,7 +38,7 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Output a matrix option (this saves it to the given file).
|
||||
@@ -46,7 +46,7 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0);
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Output a serializable class option (this saves it to the given file).
|
||||
@@ -54,8 +54,8 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Output a mapped dataset.
|
||||
@@ -63,8 +63,8 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Output an option. This is the function that will be called by the IO
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::cout << data.name << ": " << *boost::any_cast<T>(&data.value)
|
||||
<< std::endl;
|
||||
@@ -38,7 +38,7 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* /* junk */)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
std::cout << data.name << ": ";
|
||||
const T& t = *boost::any_cast<T>(&data.value);
|
||||
@@ -51,12 +51,12 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* /* junk */)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* /* junk */)
|
||||
{
|
||||
typedef std::tuple<T, std::string> TupleType;
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
const T& output = std::get<0>(*boost::any_cast<TupleType>(&data.value));
|
||||
const std::string& filename =
|
||||
std::get<1>(*boost::any_cast<TupleType>(&data.value));
|
||||
std::get<0>(std::get<1>(*boost::any_cast<TupleType>(&data.value)));
|
||||
|
||||
if (output.n_elem > 0 && filename != "")
|
||||
{
|
||||
@@ -71,8 +71,8 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
// The const cast is necessary here because Serialize() can't ever be marked
|
||||
// const. In this case we can assume it though, since we will be saving and
|
||||
@@ -91,14 +91,14 @@ void OutputParamImpl(
|
||||
template<typename T>
|
||||
void OutputParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
// Output the matrix with the mappings.
|
||||
typedef std::tuple<T, std::string> TupleType;
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
const T& tuple = std::get<0>(*boost::any_cast<TupleType>(&data.value));
|
||||
const std::string& filename =
|
||||
std::get<1>(*boost::any_cast<TupleType>(&data.value));
|
||||
std::get<0>(std::get<1>(*boost::any_cast<TupleType>(&data.value)));
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
// The mapping isn't taken into account. We should write a data::Save()
|
||||
|
||||
@@ -53,7 +53,7 @@ struct ParameterType
|
||||
template<typename eT>
|
||||
struct ParameterType<arma::Col<eT>>
|
||||
{
|
||||
typedef std::string type;
|
||||
typedef std::tuple<std::string, size_t, size_t> type;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ struct ParameterType<arma::Col<eT>>
|
||||
template<typename eT>
|
||||
struct ParameterType<arma::Row<eT>>
|
||||
{
|
||||
typedef std::string type;
|
||||
typedef std::tuple<std::string, size_t, size_t> type;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ struct ParameterType<arma::Row<eT>>
|
||||
template<typename eT>
|
||||
struct ParameterType<arma::Mat<eT>>
|
||||
{
|
||||
typedef std::string type;
|
||||
typedef std::tuple<std::string, size_t, size_t> type;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ template<typename eT, typename PolicyType>
|
||||
struct ParameterType<std::tuple<mlpack::data::DatasetMapper<PolicyType,
|
||||
std::string>, arma::Mat<eT>>>
|
||||
{
|
||||
typedef std::string type;
|
||||
typedef std::tuple<std::string, size_t, size_t> type;
|
||||
};
|
||||
|
||||
} // namespace cli
|
||||
|
||||
@@ -22,38 +22,40 @@ namespace mlpack {
|
||||
namespace bindings {
|
||||
namespace cli {
|
||||
|
||||
// Add default parameters that are included in every program.
|
||||
PARAM_FLAG("help", "Default help info.", "h");
|
||||
PARAM_STRING_IN("info", "Print help on a specific option.", "", "");
|
||||
PARAM_FLAG("verbose", "Display informational messages and the full list of "
|
||||
"parameters and timers at the end of execution.", "v");
|
||||
PARAM_FLAG("version", "Display the version of mlpack.", "V");
|
||||
|
||||
/**
|
||||
* Parse the command line, setting all of the options inside of the CLI object
|
||||
* to their appropriate given values.
|
||||
*
|
||||
* If `bindingName` is specified, that is used for the name of the binding,
|
||||
* instead of whatever the setting of the macro `BINDING_NAME` is. That is
|
||||
* generally only used for testing, in `io_test.cpp`.
|
||||
*/
|
||||
void ParseCommandLine(int argc, char** argv)
|
||||
mlpack::util::Params ParseCommandLine(
|
||||
int argc,
|
||||
char** argv,
|
||||
const char* bindingName = "")
|
||||
{
|
||||
// First, we need to build the CLI11 variables for parsing.
|
||||
CLI::App app;
|
||||
app.set_help_flag();
|
||||
|
||||
// Get an empty Params object that will hold all of the parameters for this
|
||||
// call.
|
||||
mlpack::util::Params params = (std::string(bindingName) == "") ?
|
||||
IO::Parameters(STRINGIFY(BINDING_NAME)) :
|
||||
IO::Parameters(bindingName);
|
||||
|
||||
// Go through list of options in order to add them.
|
||||
std::map<std::string, util::ParamData>& parameters = IO::Parameters();
|
||||
std::map<std::string, util::ParamData>& parameters = params.Parameters();
|
||||
using ItType = std::map<std::string, util::ParamData>::iterator;
|
||||
|
||||
for (ItType it = parameters.begin(); it != parameters.end(); ++it)
|
||||
{
|
||||
// Add the parameter to desc.
|
||||
util::ParamData& d = it->second;
|
||||
IO::GetSingleton().functionMap[d.tname]["AddToCLI11"](d, NULL, (void*)
|
||||
&app);
|
||||
params.functionMap[d.tname]["AddToCLI11"](d, NULL, (void*) &app);
|
||||
}
|
||||
|
||||
// Mark that we did parsing.
|
||||
IO::GetSingleton().didParse = true;
|
||||
|
||||
// Parse the command line, then place the values in the right place.
|
||||
try
|
||||
{
|
||||
@@ -85,37 +87,37 @@ void ParseCommandLine(int argc, char** argv)
|
||||
// --info), handle those.
|
||||
|
||||
// --version is prioritized over --help.
|
||||
if (IO::HasParam("version"))
|
||||
if (params.Has("version"))
|
||||
{
|
||||
std::cout << IO::GetSingleton().ProgramName() << ": part of "
|
||||
<< util::GetVersion() << "." << std::endl;
|
||||
std::cout << params.Doc().name << ": part of " << util::GetVersion() << "."
|
||||
<< std::endl;
|
||||
exit(0); // Don't do anything else.
|
||||
}
|
||||
|
||||
// Default help message.
|
||||
if (IO::HasParam("help"))
|
||||
if (params.Has("help"))
|
||||
{
|
||||
Log::Info.ignoreInput = false;
|
||||
PrintHelp();
|
||||
PrintHelp(params);
|
||||
exit(0); // The user doesn't want to run the program, he wants help.
|
||||
}
|
||||
|
||||
// Info on a specific parameter.
|
||||
if (IO::HasParam("info"))
|
||||
if (params.Has("info"))
|
||||
{
|
||||
Log::Info.ignoreInput = false;
|
||||
std::string str = IO::GetParam<std::string>("info");
|
||||
std::string str = params.Get<std::string>("info");
|
||||
|
||||
// The info node should always be there, but the user may not have specified
|
||||
// anything.
|
||||
if (str != "")
|
||||
{
|
||||
PrintHelp(str);
|
||||
PrintHelp(params, str);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Otherwise just print the generalized help.
|
||||
PrintHelp();
|
||||
PrintHelp(params);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ void ParseCommandLine(int argc, char** argv)
|
||||
// if we have not compiled in debugging mode.
|
||||
Log::Debug << "Compiled with debugging symbols." << std::endl;
|
||||
|
||||
if (IO::HasParam("verbose"))
|
||||
if (params.Has("verbose"))
|
||||
{
|
||||
// Give [INFO ] output.
|
||||
Log::Info.ignoreInput = false;
|
||||
@@ -138,7 +140,7 @@ void ParseCommandLine(int argc, char** argv)
|
||||
{
|
||||
// CLI11 expects the parameter name to have "--" prepended.
|
||||
std::string cliName;
|
||||
IO::GetSingleton().functionMap[d.tname]["MapParameterName"](d, NULL,
|
||||
params.functionMap[d.tname]["MapParameterName"](d, NULL,
|
||||
(void*) &cliName);
|
||||
cliName = "--" + cliName;
|
||||
|
||||
@@ -149,6 +151,8 @@ void ParseCommandLine(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
|
||||
@@ -55,7 +55,8 @@ inline std::string PrintValue(const T& value, bool quotes);
|
||||
/**
|
||||
* Given a parameter name, print its corresponding default value.
|
||||
*/
|
||||
inline std::string PrintDefault(const std::string& paramName);
|
||||
inline std::string PrintDefault(const std::string& bindingName,
|
||||
const std::string& paramName);
|
||||
|
||||
/**
|
||||
* Print a dataset type parameter (add .csv and return).
|
||||
@@ -82,7 +83,8 @@ inline std::string ProcessOptions();
|
||||
* Print an option for a command-line argument.
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
std::string ProcessOptions(const std::string& paramName,
|
||||
std::string ProcessOptions(util::Params& params,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args);
|
||||
|
||||
@@ -91,13 +93,14 @@ std::string ProcessOptions(const std::string& paramName,
|
||||
* be.
|
||||
*/
|
||||
template<typename... Args>
|
||||
std::string ProgramCall(const std::string& programName, Args... args);
|
||||
std::string ProgramCall(const std::string& programName,
|
||||
Args... args);
|
||||
|
||||
/**
|
||||
* Given a program name, print a program call invocation assuming that all
|
||||
* options are specified.
|
||||
*/
|
||||
inline std::string ProgramCall(const std::string& programName);
|
||||
inline std::string ProgramCall(util::Params& p, const std::string& programName);
|
||||
|
||||
/**
|
||||
* Print what a user would type to invoke the given option name. Note that the
|
||||
@@ -106,7 +109,8 @@ inline std::string ProgramCall(const std::string& programName);
|
||||
* that all of the PARAM_*() declarataions need to come before
|
||||
* BINDING_LONG_DESC() and BINDING_EXAMPLE() declaration.)
|
||||
*/
|
||||
inline std::string ParamString(const std::string& paramName);
|
||||
inline std::string ParamString(const std::string& bindingName,
|
||||
const std::string& paramName);
|
||||
|
||||
/**
|
||||
* Return whether or not a runtime check on parameters should be ignored. We
|
||||
|
||||
@@ -90,16 +90,17 @@ inline std::string PrintValue(const std::vector<T>& value, bool quotes)
|
||||
/**
|
||||
* Given a parameter name, print its corresponding default value.
|
||||
*/
|
||||
inline std::string PrintDefault(const std::string& paramName)
|
||||
inline std::string PrintDefault(const std::string& bindingName,
|
||||
const std::string& paramName)
|
||||
{
|
||||
if (IO::Parameters().count(paramName) == 0)
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
if (p.Parameters().count(paramName) == 0)
|
||||
throw std::invalid_argument("unknown parameter " + paramName + "!");
|
||||
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = p.Parameters()[paramName];
|
||||
|
||||
std::string defaultValue;
|
||||
IO::GetSingleton().functionMap[d.tname]["DefaultParam"](d, NULL,
|
||||
(void*) &defaultValue);
|
||||
p.functionMap[d.tname]["DefaultParam"](d, NULL, (void*) &defaultValue);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -121,32 +122,33 @@ inline std::string PrintModel(const std::string& model)
|
||||
}
|
||||
|
||||
// Base case for recursion.
|
||||
inline std::string ProcessOptions() { return ""; }
|
||||
inline std::string ProcessOptions(util::Params& /* params */) { return ""; }
|
||||
|
||||
/**
|
||||
* Print an option for a command-line argument.
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
std::string ProcessOptions(const std::string& paramName,
|
||||
std::string ProcessOptions(util::Params& params,
|
||||
const std::string& paramName,
|
||||
const T& value,
|
||||
Args... args)
|
||||
{
|
||||
// See if it is part of the program.
|
||||
std::string result = "";
|
||||
if (IO::Parameters().count(paramName) > 0)
|
||||
if (params.Parameters().count(paramName) > 0)
|
||||
{
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = params.Parameters()[paramName];
|
||||
|
||||
std::string name;
|
||||
IO::GetSingleton().functionMap[d.tname]["GetPrintableParamName"](d, NULL,
|
||||
params.functionMap[d.tname]["GetPrintableParamName"](d, NULL,
|
||||
(void*) &name);
|
||||
|
||||
std::ostringstream ossValue;
|
||||
ossValue << value;
|
||||
std::string rawValue = ossValue.str();
|
||||
std::string fullValue;
|
||||
IO::GetSingleton().functionMap[d.tname]["GetPrintableParamValue"](d,
|
||||
(void*) &rawValue, (void*) &fullValue);
|
||||
params.functionMap[d.tname]["GetPrintableParamValue"](d, (void*) &rawValue,
|
||||
(void*) &fullValue);
|
||||
|
||||
std::ostringstream oss;
|
||||
if (d.tname != TYPENAME(bool))
|
||||
@@ -162,7 +164,7 @@ std::string ProcessOptions(const std::string& paramName,
|
||||
+ " and BINDING_EXAMPLE() declaration.");
|
||||
}
|
||||
|
||||
std::string rest = ProcessOptions(args...);
|
||||
std::string rest = ProcessOptions(params, args...);
|
||||
if (rest != "")
|
||||
result += " " + rest;
|
||||
|
||||
@@ -176,35 +178,36 @@ std::string ProcessOptions(const std::string& paramName,
|
||||
template<typename... Args>
|
||||
std::string ProgramCall(const std::string& programName, Args... args)
|
||||
{
|
||||
util::Params params = IO::Parameters(programName);
|
||||
return util::HyphenateString("$ " + GetBindingName(programName) + " " +
|
||||
ProcessOptions(args...), 2);
|
||||
ProcessOptions(params, args...), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a program name, print a program call invocation assuming that all
|
||||
* options are specified.
|
||||
*/
|
||||
inline std::string ProgramCall(const std::string& programName)
|
||||
inline std::string ProgramCall(util::Params& p, const std::string& programName)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "$ " << GetBindingName(programName);
|
||||
|
||||
// Handle all options---first input options, then output options.
|
||||
std::map<std::string, util::ParamData>& parameters = IO::Parameters();
|
||||
std::map<std::string, util::ParamData>& parameters = p.Parameters();
|
||||
|
||||
for (auto& it : parameters)
|
||||
{
|
||||
if (!it.second.input || it.second.persistent)
|
||||
if (!it.second.input)
|
||||
continue;
|
||||
|
||||
// Otherwise, print the name and the default value.
|
||||
std::string name;
|
||||
IO::GetSingleton().functionMap[it.second.tname]["GetPrintableParamName"](
|
||||
it.second, NULL, (void*) &name);
|
||||
p.functionMap[it.second.tname]["GetPrintableParamName"]( it.second, NULL,
|
||||
(void*) &name);
|
||||
|
||||
std::string value;
|
||||
IO::GetSingleton().functionMap[it.second.tname]["DefaultParam"](
|
||||
it.second, NULL, (void*) &value);
|
||||
p.functionMap[it.second.tname]["DefaultParam"]( it.second, NULL,
|
||||
(void*) &value);
|
||||
if (value == "''")
|
||||
value = "<string>";
|
||||
|
||||
@@ -228,12 +231,12 @@ inline std::string ProgramCall(const std::string& programName)
|
||||
|
||||
// Otherwise, print the name and the default value.
|
||||
std::string name;
|
||||
IO::GetSingleton().functionMap[it.second.tname]["GetPrintableParamName"](
|
||||
it.second, NULL, (void*) &name);
|
||||
p.functionMap[it.second.tname]["GetPrintableParamName"]( it.second, NULL,
|
||||
(void*) &name);
|
||||
|
||||
std::string value;
|
||||
IO::GetSingleton().functionMap[it.second.tname]["DefaultParam"](
|
||||
it.second, NULL, (void*) &value);
|
||||
p.functionMap[it.second.tname]["DefaultParam"]( it.second, NULL,
|
||||
(void*) &value);
|
||||
if (value == "''")
|
||||
value = "<string>";
|
||||
|
||||
@@ -253,16 +256,18 @@ inline std::string ProgramCall(const std::string& programName)
|
||||
* that all of the PARAM_*() declarataions need to come before
|
||||
* BINDING_LONG_DESC() and BINDING_EXAMPLE() declaration.)
|
||||
*/
|
||||
inline std::string ParamString(const std::string& paramName)
|
||||
inline std::string ParamString(const std::string& bindingName,
|
||||
const std::string& paramName)
|
||||
{
|
||||
util::Params p = IO::Parameters(bindingName);
|
||||
|
||||
// Return the correct parameter name.
|
||||
if (IO::Parameters().count(paramName) > 0)
|
||||
if (p.Parameters().count(paramName) > 0)
|
||||
{
|
||||
util::ParamData& d = IO::Parameters()[paramName];
|
||||
util::ParamData& d = p.Parameters()[paramName];
|
||||
|
||||
std::string output;
|
||||
IO::GetSingleton().functionMap[d.tname]["GetPrintableParamName"](d, NULL,
|
||||
(void*) &output);
|
||||
p.functionMap[d.tname]["GetPrintableParamName"](d, NULL, (void*) &output);
|
||||
// Is there an alias?
|
||||
std::string alias = "";
|
||||
if (d.alias != '\0')
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace bindings {
|
||||
namespace cli {
|
||||
|
||||
/* Prints the descriptions of the current hierarchy. */
|
||||
void PrintHelp(const std::string& param)
|
||||
void PrintHelp(util::Params& params, const std::string& param)
|
||||
{
|
||||
std::string usedParam = param;
|
||||
std::map<std::string, util::ParamData>& parameters = IO::Parameters();
|
||||
const std::map<char, std::string>& aliases = IO::Aliases();
|
||||
util::BindingDetails& bindingDetails = IO::GetSingleton().doc;
|
||||
std::map<std::string, util::ParamData>& parameters = params.Parameters();
|
||||
const std::map<char, std::string>& aliases = params.Aliases();
|
||||
const util::BindingDetails& bindingDetails = params.Doc();
|
||||
// If we pass a single param, alias it if necessary.
|
||||
if (usedParam.length() == 1 && aliases.count(usedParam[0]))
|
||||
usedParam = aliases.at(usedParam[0]);
|
||||
@@ -39,7 +39,7 @@ void PrintHelp(const std::string& param)
|
||||
|
||||
// Figure out the name of the type.
|
||||
std::string printableType;
|
||||
IO::GetSingleton().functionMap[data.tname]["StringTypeParam"](data, NULL,
|
||||
params.functionMap[data.tname]["StringTypeParam"](data, NULL,
|
||||
(void*) &printableType);
|
||||
std::string type = " [" + printableType + "]";
|
||||
|
||||
@@ -63,9 +63,9 @@ void PrintHelp(const std::string& param)
|
||||
}
|
||||
|
||||
// Print out the descriptions.
|
||||
if (bindingDetails.programName != "")
|
||||
if (bindingDetails.name != "")
|
||||
{
|
||||
std::cout << bindingDetails.programName << std::endl << std::endl;
|
||||
std::cout << bindingDetails.name << std::endl << std::endl;
|
||||
std::cout << " " << util::HyphenateString(bindingDetails.longDescription(),
|
||||
2) << std::endl << std::endl;
|
||||
for (size_t j = 0; j < bindingDetails.example.size(); ++j)
|
||||
@@ -85,8 +85,8 @@ void PrintHelp(const std::string& param)
|
||||
{
|
||||
util::ParamData& data = iter.second;
|
||||
const std::string key;
|
||||
IO::GetSingleton().functionMap[data.tname]["MapParameterName"](data,
|
||||
NULL, (void*) &key);
|
||||
params.functionMap[data.tname]["MapParameterName"](data, NULL,
|
||||
(void*) &key);
|
||||
|
||||
std::string desc = data.desc;
|
||||
std::string alias = (iter.second.alias != '\0') ?
|
||||
@@ -125,15 +125,15 @@ void PrintHelp(const std::string& param)
|
||||
data.cppType == "std::vector<std::string>"))
|
||||
{
|
||||
std::string defaultValue;
|
||||
IO::GetSingleton().functionMap[data.tname]["DefaultParam"](data,
|
||||
NULL, (void*) &defaultValue);
|
||||
params.functionMap[data.tname]["DefaultParam"](data, NULL,
|
||||
(void*) &defaultValue);
|
||||
desc += " Default value " + defaultValue + ".";
|
||||
}
|
||||
|
||||
// Now, print the descriptions.
|
||||
std::string printableType;
|
||||
IO::GetSingleton().functionMap[data.tname]["StringTypeParam"](data,
|
||||
NULL, (void*) &printableType);
|
||||
params.functionMap[data.tname]["StringTypeParam"](data, NULL,
|
||||
(void*) &printableType);
|
||||
std::string type = " [" + printableType + "]";
|
||||
std::string fullDesc = " --" + key + alias + type + " ";
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace cli {
|
||||
*
|
||||
* @param param Parameter name to print help for.
|
||||
*/
|
||||
void PrintHelp(const std::string& param = "");
|
||||
void PrintHelp(util::Params& params, const std::string& param = "");
|
||||
|
||||
} // namespace cli
|
||||
} // namespace bindings
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string representing the command-line type of a vector.
|
||||
@@ -62,8 +62,8 @@ std::string PrintTypeDoc(
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Print the command-line type of an option into a string.
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace cli {
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
// A flag type.
|
||||
if (std::is_same<T, bool>::value)
|
||||
@@ -98,8 +98,9 @@ std::string PrintTypeDoc(
|
||||
"of the data is detected by the extension of the filename. The storage"
|
||||
" should be such that one row corresponds to one point, and one column "
|
||||
"corresponds to one dimension (this is the typical storage format for "
|
||||
"on-disk data). All values of the matrix will be loaded as double-"
|
||||
"precision floating point data.";
|
||||
"on-disk data). CSV files will be checked for a header; if no header "
|
||||
"is found, the first row will be loaded as a data point. All values of"
|
||||
" the matrix will be loaded as double-precision floating point data.";
|
||||
}
|
||||
else if (std::is_same<T, arma::Mat<size_t>>::value)
|
||||
{
|
||||
@@ -111,8 +112,10 @@ std::string PrintTypeDoc(
|
||||
"compiled with HDF5 support. The type of the data is detected by the "
|
||||
"extension of the filename. The storage should be such that one row "
|
||||
"corresponds to one point, and one column corresponds to one dimension "
|
||||
"(this is the typical storage format for on-disk data). All values of "
|
||||
"the matrix will be loaded as unsigned integers.";
|
||||
"(this is the typical storage format for on-disk data). CSV files will"
|
||||
" be checked for a header; if no header is found, the first row will be"
|
||||
" loaded as a data point. All values of the matrix will be loaded as "
|
||||
"unsigned integers.";
|
||||
}
|
||||
else if (std::is_same<T, arma::rowvec>::value ||
|
||||
std::is_same<T, arma::vec>::value)
|
||||
@@ -162,8 +165,8 @@ std::string PrintTypeDoc(
|
||||
template<typename T>
|
||||
std::string PrintTypeDoc(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*)
|
||||
{
|
||||
return "A filename containing an mlpack model. These can have one of three "
|
||||
"formats: binary (.bin), text (.txt), and XML (.xml). The XML format "
|
||||
|
||||
@@ -27,11 +27,11 @@ template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const boost::any& value,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T, bool>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T, bool>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed.
|
||||
d.value = value;
|
||||
@@ -44,15 +44,15 @@ template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const boost::any& /* value */,
|
||||
const typename boost::enable_if<std::is_same<T, bool>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
|
||||
{
|
||||
// Force set to the value of whether or not this was passed.
|
||||
d.value = d.wasPassed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a matrix parameter, a matrix/dataset info parameter, or a serializable
|
||||
* object. These set the filename referring to the parameter.
|
||||
* Set a matrix parameter, a matrix/dataset info parameter.
|
||||
* These set the filename referring to the parameter.
|
||||
*/
|
||||
template<typename T>
|
||||
void SetParam(
|
||||
@@ -65,7 +65,7 @@ void SetParam(
|
||||
// We're setting the string filename.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
|
||||
std::get<1>(tuple) = boost::any_cast<std::string>(value);
|
||||
std::get<0>(std::get<1>(tuple)) = boost::any_cast<std::string>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,8 +76,8 @@ template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const boost::any& value,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// We're setting the string filename.
|
||||
typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
|
||||
|
||||
@@ -26,22 +26,22 @@ namespace cli {
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string containing the type of the parameter, for vector options.
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string containing the type of the parameter,
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return a string containing the type of a parameter. This overload is used if
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace cli {
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
// Don't know what type this is.
|
||||
return "unknown";
|
||||
@@ -35,7 +35,7 @@ std::string StringTypeParamImpl(
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* /* junk */)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
return "vector";
|
||||
}
|
||||
@@ -45,7 +45,7 @@ std::string StringTypeParamImpl(
|
||||
*/
|
||||
template<typename T>
|
||||
std::string StringTypeParamImpl(
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
+1357
-677
File diff suppressed because it is too large
Load Diff
@@ -91,6 +91,7 @@ if (BUILD_GO_SHLIB)
|
||||
mlpack/arma_util.hpp
|
||||
mlpack/io_util.h
|
||||
mlpack/io_util.hpp
|
||||
mlpack_main.hpp
|
||||
print_class_defn.hpp
|
||||
print_defn_input.hpp
|
||||
print_defn_output.hpp
|
||||
|
||||
@@ -26,12 +26,13 @@ namespace go {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a vector option.
|
||||
@@ -39,7 +40,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a string option.
|
||||
@@ -47,7 +48,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a matrix option, a tuple option, a
|
||||
@@ -57,10 +58,10 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */ = 0);
|
||||
arma::mat>>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of a model option (this returns the default
|
||||
@@ -69,8 +70,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0);
|
||||
|
||||
/**
|
||||
* Return the default value of an option. This is the function that will be
|
||||
|
||||
@@ -24,12 +24,13 @@ namespace go {
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* /* junk */,
|
||||
const typename boost::disable_if<std::is_same<T, std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if (std::is_same<T, bool>::value)
|
||||
@@ -46,7 +47,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* /* junk */)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
@@ -90,7 +91,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T, std::string>>::type*)
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *boost::any_cast<std::string>(&data.value);
|
||||
return "\"" + s + "\"";
|
||||
@@ -102,7 +103,7 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::enable_if_c<
|
||||
const typename std::enable_if<
|
||||
arma::is_arma_type<T>::value ||
|
||||
std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
|
||||
arma::mat>>::value>::type* /* junk */)
|
||||
@@ -134,8 +135,8 @@ std::string DefaultParamImpl(
|
||||
template<typename T>
|
||||
std::string DefaultParamImpl(
|
||||
util::ParamData& /* data */,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* /* junk */,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* /* junk */)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
|
||||
{
|
||||
return "nil";
|
||||
}
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
#endif
|
||||
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
#include <mlpack/bindings/go/print_go.hpp>
|
||||
|
||||
// This will include the ParamData options that are a part of the program.
|
||||
#include <${PROGRAM_MAIN_FILE}>
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
|
||||
#include <mlpack/bindings/go/print_go.hpp>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::bindings;
|
||||
@@ -41,9 +42,8 @@ using namespace mlpack::util;
|
||||
|
||||
int main(int /* argc */, char** /* argv */)
|
||||
{
|
||||
// All the parameters are registered, but stored, so restore them.
|
||||
// programName is defined in mlpack_main.hpp.
|
||||
IO::RestoreSettings(programName);
|
||||
// All the parameters are registered.
|
||||
util::Params p = IO::Parameters(STRINGIFY(BINDING_NAME));
|
||||
|
||||
PrintGo(IO::GetSingleton().doc, "${PROGRAM_NAME}");
|
||||
PrintGo(p, p.Doc(), "${PROGRAM_NAME}", STRINGIFY(BINDING_NAME));
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace go {
|
||||
template<typename T>
|
||||
inline std::string GetGoType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -37,11 +37,11 @@ inline std::string GetGoType(
|
||||
template<>
|
||||
inline std::string GetGoType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "int";
|
||||
}
|
||||
@@ -49,11 +49,11 @@ inline std::string GetGoType<int>(
|
||||
template<>
|
||||
inline std::string GetGoType<float>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<float>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<float>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<float>>::type*,
|
||||
const typename boost::disable_if<std::is_same<float,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<float>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<float>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<float>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<float,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "float32";
|
||||
}
|
||||
@@ -61,11 +61,11 @@ inline std::string GetGoType<float>(
|
||||
template<>
|
||||
inline std::string GetGoType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "float64";
|
||||
}
|
||||
@@ -73,11 +73,14 @@ inline std::string GetGoType<double>(
|
||||
template<>
|
||||
inline std::string GetGoType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
@@ -85,11 +88,11 @@ inline std::string GetGoType<std::string>(
|
||||
template<>
|
||||
inline std::string GetGoType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "bool";
|
||||
}
|
||||
@@ -97,7 +100,7 @@ inline std::string GetGoType<bool>(
|
||||
template<typename T>
|
||||
inline std::string GetGoType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
return "[]" + GetGoType<typename T::value_type>(d);
|
||||
}
|
||||
@@ -105,9 +108,9 @@ inline std::string GetGoType(
|
||||
template<typename T>
|
||||
inline std::string GetGoType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
return "mat.Dense";
|
||||
}
|
||||
@@ -115,8 +118,8 @@ inline std::string GetGoType(
|
||||
template<typename T>
|
||||
inline std::string GetGoType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
return "matrixWithInfo";
|
||||
}
|
||||
@@ -124,8 +127,8 @@ inline std::string GetGoType(
|
||||
template<typename T>
|
||||
inline std::string GetGoType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::string goStrippedType, strippedType, printedType, defaultsType;
|
||||
StripType(d.cppType, goStrippedType, strippedType, printedType, defaultsType);
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace go {
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << boost::any_cast<T>(data.value);
|
||||
@@ -42,7 +42,7 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = boost::any_cast<T>(data.value);
|
||||
|
||||
@@ -58,7 +58,7 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = boost::any_cast<T>(data.value);
|
||||
@@ -74,8 +74,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << boost::any_cast<T*>(data.value);
|
||||
@@ -88,8 +88,8 @@ std::string GetPrintableParam(
|
||||
template<typename T>
|
||||
std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = boost::any_cast<T>(data.value);
|
||||
|
||||
@@ -23,75 +23,78 @@ namespace go {
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<>
|
||||
inline std::string GetPrintableType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*);
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0);
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0);
|
||||
|
||||
template<typename T>
|
||||
void GetPrintableType(util::ParamData& d,
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace go {
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -35,11 +35,11 @@ inline std::string GetPrintableType(
|
||||
template<>
|
||||
inline std::string GetPrintableType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*,
|
||||
const typename boost::disable_if<std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<int,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "int";
|
||||
}
|
||||
@@ -47,11 +47,11 @@ inline std::string GetPrintableType<int>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*,
|
||||
const typename boost::disable_if<std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<double,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "float64";
|
||||
}
|
||||
@@ -59,11 +59,14 @@ inline std::string GetPrintableType<double>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
|
||||
const typename boost::disable_if<std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<std::string,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
@@ -71,11 +74,11 @@ inline std::string GetPrintableType<std::string>(
|
||||
template<>
|
||||
inline std::string GetPrintableType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
|
||||
const typename boost::disable_if<std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<bool,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "bool";
|
||||
}
|
||||
@@ -83,9 +86,9 @@ inline std::string GetPrintableType<bool>(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "array of " + GetPrintableType<typename T::value_type>(d) + "s";
|
||||
}
|
||||
@@ -93,9 +96,9 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
std::string type = "*mat.Dense";
|
||||
if (T::is_row || T::is_col)
|
||||
@@ -107,8 +110,8 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
return "matrixWithInfo";
|
||||
}
|
||||
@@ -116,10 +119,10 @@ inline std::string GetPrintableType(
|
||||
template<typename T>
|
||||
inline std::string GetPrintableType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type*,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type*,
|
||||
const typename boost::disable_if<std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>>::type*)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type*,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type*,
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
|
||||
{
|
||||
std::string goStrippedType, strippedType, printedType, defaultsType;
|
||||
StripType(d.cppType, goStrippedType, strippedType, printedType, defaultsType);
|
||||
|
||||
@@ -24,9 +24,9 @@ namespace go {
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
|
||||
const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
@@ -34,9 +34,9 @@ inline std::string GetType(
|
||||
template<>
|
||||
inline std::string GetType<int>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<int>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<int>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<int>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<int>::value>::type*)
|
||||
{
|
||||
return "Int";
|
||||
}
|
||||
@@ -44,9 +44,9 @@ inline std::string GetType<int>(
|
||||
template<>
|
||||
inline std::string GetType<float>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<float>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<float>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<float>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<float>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<float>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<float>::value>::type*)
|
||||
{
|
||||
return "Float";
|
||||
}
|
||||
@@ -54,9 +54,9 @@ inline std::string GetType<float>(
|
||||
template<>
|
||||
inline std::string GetType<double>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<double>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<double>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<double>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<double>::value>::type*)
|
||||
{
|
||||
return "Double";
|
||||
}
|
||||
@@ -64,9 +64,12 @@ inline std::string GetType<double>(
|
||||
template<>
|
||||
inline std::string GetType<std::string>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<std::string>>::type*)
|
||||
const typename std::enable_if<
|
||||
!util::IsStdVector<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!data::HasSerialize<std::string>::value>::type*,
|
||||
const typename std::enable_if<
|
||||
!arma::is_arma_type<std::string>::value>::type*)
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
@@ -74,9 +77,9 @@ inline std::string GetType<std::string>(
|
||||
template<>
|
||||
inline std::string GetType<bool>(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::disable_if<util::IsStdVector<bool>>::type*,
|
||||
const typename boost::disable_if<data::HasSerialize<bool>>::type*,
|
||||
const typename boost::disable_if<arma::is_arma_type<bool>>::type*)
|
||||
const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
|
||||
const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
|
||||
const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*)
|
||||
{
|
||||
return "Bool";
|
||||
}
|
||||
@@ -84,7 +87,7 @@ inline std::string GetType<bool>(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& d,
|
||||
const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
return "Vec" + GetType<typename T::value_type>(d);
|
||||
}
|
||||
@@ -92,7 +95,7 @@ inline std::string GetType(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& /* d */,
|
||||
const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
std::string type = "";
|
||||
if (std::is_same<typename T::elem_type, double>::value)
|
||||
@@ -120,8 +123,8 @@ inline std::string GetType(
|
||||
template<typename T>
|
||||
inline std::string GetType(
|
||||
util::ParamData& d,
|
||||
const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
|
||||
const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
|
||||
const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
return d.cppType + "*";
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
#include <${PROGRAM_MAIN_FILE}>
|
||||
#include <mlpack/bindings/go/mlpack/capi/io_util.hpp>
|
||||
|
||||
static void ${GOPROGRAM_NAME}MlpackMain()
|
||||
extern "C" void mlpack${GOPROGRAM_NAME}(void* params, void* timers)
|
||||
{
|
||||
mlpackMain();
|
||||
}
|
||||
util::Params& p = *((util::Params*) params);
|
||||
util::Timers& t = *((util::Timers*) timers);
|
||||
|
||||
extern "C" void mlpack${GOPROGRAM_NAME}()
|
||||
{
|
||||
${GOPROGRAM_NAME}MlpackMain();
|
||||
BINDING_FUNCTION(p, t);
|
||||
}
|
||||
|
||||
// Any implementations of methods for dealing with model pointers will be put
|
||||
|
||||
@@ -15,7 +15,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void mlpack${GOPROGRAM_NAME}();
|
||||
extern void mlpack${GOPROGRAM_NAME}(void* params, void* timers);
|
||||
|
||||
// Any definitions of methods for dealing with model pointers will be put below
|
||||
// this comment, if needed.
|
||||
|
||||
@@ -29,9 +29,6 @@ namespace mlpack {
|
||||
namespace bindings {
|
||||
namespace go {
|
||||
|
||||
// Defined in mlpack_main.hpp.
|
||||
extern std::string programName;
|
||||
|
||||
/**
|
||||
* The Go option class.
|
||||
*/
|
||||
@@ -65,7 +62,7 @@ class GoOption
|
||||
const bool required = false,
|
||||
const bool input = true,
|
||||
const bool noTranspose = false,
|
||||
const std::string& /*testName*/ = "")
|
||||
const std::string& bindingName = "")
|
||||
{
|
||||
// Create the ParamData object to give to IO.
|
||||
util::ParamData data;
|
||||
@@ -79,50 +76,29 @@ class GoOption
|
||||
data.required = required;
|
||||
data.input = input;
|
||||
data.loaded = false;
|
||||
// Only "verbose" and "copy_all_inputs" will be persistent.
|
||||
if (identifier == "verbose" /*|| identifier == "copy_all_inputs"*/)
|
||||
data.persistent = true;
|
||||
else
|
||||
data.persistent = false;
|
||||
data.cppType = cppName;
|
||||
|
||||
data.value = boost::any(defaultValue);
|
||||
|
||||
// Restore the parameters for this program.
|
||||
if (identifier != "verbose" /*&& identifier != "copy_all_inputs"*/)
|
||||
IO::RestoreSettings(programName, false);
|
||||
|
||||
// Set the function pointers that we'll need. All of these function
|
||||
// pointers will be used by both the program that generates the .cpp,
|
||||
// the .h, and the .go binding files.
|
||||
IO::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
|
||||
&GetPrintableParam<T>;
|
||||
IO::AddFunction(data.tname, "GetParam", &GetParam<T>);
|
||||
IO::AddFunction(data.tname, "GetPrintableParam", &GetPrintableParam<T>);
|
||||
IO::AddFunction(data.tname, "DefaultParam", &DefaultParam<T>);
|
||||
IO::AddFunction(data.tname, "PrintDefnInput", &PrintDefnInput<T>);
|
||||
IO::AddFunction(data.tname, "PrintDefnOutput", &PrintDefnOutput<T>);
|
||||
IO::AddFunction(data.tname, "PrintDoc", &PrintDoc<T>);
|
||||
IO::AddFunction(data.tname, "PrintOutputProcessing",
|
||||
&PrintOutputProcessing<T>);
|
||||
IO::AddFunction(data.tname, "PrintMethodConfig", &PrintMethodConfig<T>);
|
||||
IO::AddFunction(data.tname, "PrintMethodInit", &PrintMethodInit<T>);
|
||||
IO::AddFunction(data.tname, "PrintInputProcessing",
|
||||
&PrintInputProcessing<T>);
|
||||
IO::AddFunction(data.tname, "GetType", &GetType<T>);
|
||||
|
||||
IO::GetSingleton().functionMap[data.tname]["DefaultParam"] =
|
||||
&DefaultParam<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintDefnInput"] =
|
||||
&PrintDefnInput<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintDefnOutput"] =
|
||||
&PrintDefnOutput<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
|
||||
&PrintOutputProcessing<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintMethodConfig"] =
|
||||
&PrintMethodConfig<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintMethodInit"] =
|
||||
&PrintMethodInit<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
|
||||
&PrintInputProcessing<T>;
|
||||
IO::GetSingleton().functionMap[data.tname]["GetType"] = &GetType<T>;
|
||||
|
||||
// Add the ParamData object, then store. This is necessary because we may
|
||||
// import more than one .so that uses IO, so we have to keep the options
|
||||
// separate. programName is a global variable from mlpack_main.hpp.
|
||||
IO::Add(std::move(data));
|
||||
if (identifier != "verbose" /*&& identifier != "copy_all_inputs"*/)
|
||||
IO::StoreSettings(programName);
|
||||
IO::ClearSettings();
|
||||
// Add the ParamData object to the IO class for the correct binding name.
|
||||
IO::AddParameter(bindingName, std::move(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
)
|
||||
|
||||
type mlpackArma struct {
|
||||
|
||||
mem unsafe.Pointer
|
||||
}
|
||||
|
||||
@@ -26,7 +25,7 @@ type mlpackArma struct {
|
||||
// (Categoricals) indicating which dimensions are categorical (represented by
|
||||
// `true`) and which are numeric (represented by `false`). The number of
|
||||
// elements in the boolean array should be the same as the dimensionality of
|
||||
// the data matrix. It is expected that each row of the matrix corresponds to a
|
||||
// the data matrix. It is expected that each row of the matrix corresponds to a
|
||||
// single data point when calling mlpack bindings.
|
||||
type matrixWithInfo struct {
|
||||
Categoricals []bool
|
||||
@@ -43,55 +42,56 @@ func DataAndInfo() *matrixWithInfo {
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrMat(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrMat(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrMat(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrMat(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrUmat(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUmat(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrUmat(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUmat(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrRow(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrRow(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrRow(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrRow(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrUrow(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUrow(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrUrow(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUrow(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrCol(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrCol(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrCol(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrCol(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrUcol(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUcol(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrUcol(p *params, identifier string) {
|
||||
m.mem = C.mlpackArmaPtrUcol(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Allocates a C memory Pointer via cgo and registers the finalizer
|
||||
// in order to free the C memory once the input has been registered in Go.
|
||||
func (m *mlpackArma) allocArmaPtrMatWithInfo(identifier string) {
|
||||
m.mem = C.mlpackArmaPtrMatWithInfoPtr(C.CString(identifier))
|
||||
func (m *mlpackArma) allocArmaPtrMatWithInfo(p *params,
|
||||
identifier string) {
|
||||
m.mem = C.mlpackArmaPtrMatWithInfoPtr(p.mem, C.CString(identifier))
|
||||
runtime.KeepAlive(m)
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaMat(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaMat(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
r, c := m.Dims()
|
||||
blas64General := m.RawMatrix()
|
||||
@@ -99,11 +99,12 @@ func gonumToArmaMat(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaMat(C.CString(identifier), (*C.double)(ptr), C.size_t(c), C.size_t(r))
|
||||
C.mlpackToArmaMat(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(c), C.size_t(r))
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaUmat(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaUmat(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
r, c := m.Dims()
|
||||
blas64General := m.RawMatrix()
|
||||
@@ -111,11 +112,12 @@ func gonumToArmaUmat(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaUmat(C.CString(identifier), (*C.double)(ptr), C.size_t(c), C.size_t(r))
|
||||
C.mlpackToArmaUmat(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(c), C.size_t(r))
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaRow(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaRow(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
e, err := m.Dims()
|
||||
if (err != 1 && e != 1){
|
||||
@@ -133,11 +135,12 @@ func gonumToArmaRow(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaRow(C.CString(identifier), (*C.double)(ptr), C.size_t(e))
|
||||
C.mlpackToArmaRow(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(e))
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaUrow(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaUrow(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
e, err := m.Dims()
|
||||
if (err != 1 && e != 1){
|
||||
@@ -155,11 +158,12 @@ func gonumToArmaUrow(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaUrow(C.CString(identifier), (*C.double)(ptr), C.size_t(e))
|
||||
C.mlpackToArmaUrow(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(e))
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaCol(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaCol(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
err, e := m.Dims()
|
||||
if (err != 1 && e != 1){
|
||||
@@ -177,11 +181,12 @@ func gonumToArmaCol(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaCol(C.CString(identifier), (*C.double)(ptr), C.size_t(e))
|
||||
C.mlpackToArmaCol(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(e))
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func gonumToArmaUcol(identifier string, m *mat.Dense) {
|
||||
func gonumToArmaUcol(p *params, identifier string, m *mat.Dense) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
err, e := m.Dims()
|
||||
if (err != 1 && e != 1){
|
||||
@@ -199,12 +204,15 @@ func gonumToArmaUcol(identifier string, m *mat.Dense) {
|
||||
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
ptr := unsafe.Pointer(&data[0])
|
||||
C.mlpackToArmaUcol(C.CString(identifier), (*C.double)(ptr), C.size_t(e))
|
||||
C.mlpackToArmaUcol(p.mem, C.CString(identifier), (*C.double)(ptr),
|
||||
C.size_t(e))
|
||||
}
|
||||
|
||||
// GonumToArmaMatWithInfo passes a gonum matrix with info to C by
|
||||
// using it's gonums underlying blas64.
|
||||
func gonumToArmaMatWithInfo(identifier string, m *matrixWithInfo) {
|
||||
func gonumToArmaMatWithInfo(p *params,
|
||||
identifier string,
|
||||
m *matrixWithInfo) {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
r, c := m.Data.Dims()
|
||||
blas64General := m.Data.RawMatrix()
|
||||
@@ -213,20 +221,21 @@ func gonumToArmaMatWithInfo(identifier string, m *matrixWithInfo) {
|
||||
// Pass pointer of the underlying matrix to mlpack.
|
||||
boolptr := unsafe.Pointer(&boolarray[0])
|
||||
matptr := unsafe.Pointer(&dataAndInfo[0])
|
||||
C.mlpackToArmaMatWithInfo(C.CString(identifier), (*C.bool)(boolptr),
|
||||
(*C.double)(matptr), C.size_t(c), C.size_t(r))
|
||||
C.mlpackToArmaMatWithInfo(p.mem, C.CString(identifier),
|
||||
(*C.bool)(boolptr), (*C.double)(matptr), C.size_t(c), C.size_t(r))
|
||||
}
|
||||
|
||||
// ArmaToGonum returns a gonum matrix based on the memory pointer
|
||||
// of an armadillo matrix.
|
||||
func (m *mlpackArma) armaToGonumMat(identifier string) *mat.Dense {
|
||||
func (m *mlpackArma) armaToGonumMat(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo row.
|
||||
c := int(C.mlpackNumRowMat(C.CString(identifier)))
|
||||
r := int(C.mlpackNumColMat(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemMat(C.CString(identifier)))
|
||||
c := int(C.mlpackNumRowMat(p.mem, C.CString(identifier)))
|
||||
r := int(C.mlpackNumColMat(p.mem, C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemMat(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrMat(identifier)
|
||||
m.allocArmaPtrMat(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -244,14 +253,15 @@ func (m *mlpackArma) armaToGonumMat(identifier string) *mat.Dense {
|
||||
|
||||
// ArmaToGonum returns a gonum matrix based on the memory pointer
|
||||
// of an armadillo matrix.
|
||||
func (m *mlpackArma) armaToGonumArray(identifier string) (int, int, []float64){
|
||||
func (m *mlpackArma) armaToGonumArray(p *params,
|
||||
identifier string) (int, int, []float64) {
|
||||
// Get the number of elements in the Armadillo row.
|
||||
c := int(C.mlpackNumRowMat(C.CString(identifier)))
|
||||
r := int(C.mlpackNumColMat(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemMat(C.CString(identifier)))
|
||||
c := int(C.mlpackNumRowMat(p.mem, C.CString(identifier)))
|
||||
r := int(C.mlpackNumColMat(p.mem, C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemMat(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrMat(identifier)
|
||||
m.allocArmaPtrMat(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -262,14 +272,15 @@ func (m *mlpackArma) armaToGonumArray(identifier string) (int, int, []float64){
|
||||
|
||||
// ArmaToGonum returns a gonum matrix based on the memory pointer
|
||||
// of an armadillo matrix.
|
||||
func (m *mlpackArma) armaToGonumUmat(identifier string) *mat.Dense {
|
||||
func (m *mlpackArma) armaToGonumUmat(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo row.
|
||||
c := int(C.mlpackNumRowUmat(C.CString(identifier)))
|
||||
r := int(C.mlpackNumColUmat(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemUmat(C.CString(identifier)))
|
||||
c := int(C.mlpackNumRowUmat(p.mem, C.CString(identifier)))
|
||||
r := int(C.mlpackNumColUmat(p.mem, C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemUmat(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrUmat(identifier)
|
||||
m.allocArmaPtrUmat(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -287,12 +298,13 @@ func (m *mlpackArma) armaToGonumUmat(identifier string) *mat.Dense {
|
||||
|
||||
// ArmaRowToGonum returns a gonum vector based on the memory pointer
|
||||
// of the underlying armadillo object.
|
||||
func (m *mlpackArma) armaToGonumRow(identifier string) *mat.Dense{
|
||||
func (m *mlpackArma) armaToGonumRow(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo row.
|
||||
e := int(C.mlpackNumElemRow(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemRow(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrRow(identifier)
|
||||
m.allocArmaPtrRow(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -310,12 +322,13 @@ func (m *mlpackArma) armaToGonumRow(identifier string) *mat.Dense{
|
||||
|
||||
// ArmaRowToGonum returns a gonum vector based on the memory pointer
|
||||
// of the underlying armadillo object.
|
||||
func (m *mlpackArma) armaToGonumUrow(identifier string) *mat.Dense {
|
||||
func (m *mlpackArma) armaToGonumUrow(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo row.
|
||||
e := int(C.mlpackNumElemUrow(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemUrow(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrUrow(identifier)
|
||||
m.allocArmaPtrUrow(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -330,13 +343,15 @@ func (m *mlpackArma) armaToGonumUrow(identifier string) *mat.Dense {
|
||||
return mat.NewDense(1, 1, nil)
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func (m *mlpackArma) armaToGonumCol(identifier string) *mat.Dense {
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum
|
||||
// matrix.
|
||||
func (m *mlpackArma) armaToGonumCol(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
e := int(C.mlpackNumElemCol(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemCol(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrCol(identifier)
|
||||
m.allocArmaPtrCol(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -352,13 +367,15 @@ func (m *mlpackArma) armaToGonumCol(identifier string) *mat.Dense {
|
||||
return mat.NewDense(1, 1, nil)
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func (m *mlpackArma) armaToGonumUcol(identifier string) *mat.Dense {
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum
|
||||
// matrix.
|
||||
func (m *mlpackArma) armaToGonumUcol(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get the number of elements in the Armadillo column.
|
||||
e := int(C.mlpackNumElemUcol(C.CString(identifier)))
|
||||
e := int(C.mlpackNumElemUcol(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrUcol(identifier)
|
||||
m.allocArmaPtrUcol(p, identifier)
|
||||
|
||||
// Convert pointer to slice of data, to then pass it to a gonum matrix.
|
||||
array := (*[1<<30 - 1]float64)(m.mem)
|
||||
@@ -374,15 +391,17 @@ func (m *mlpackArma) armaToGonumUcol(identifier string) *mat.Dense {
|
||||
return mat.NewDense(1, 1, nil)
|
||||
}
|
||||
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum matrix.
|
||||
func (m *mlpackArma) armaToGonumMatWithInfo(identifier string) *mat.Dense {
|
||||
// Passes a Gonum matrix to C by using the underlying data from the Gonum
|
||||
// matrix.
|
||||
func (m *mlpackArma) armaToGonumMatWithInfo(p *params,
|
||||
identifier string) *mat.Dense {
|
||||
// Get number of rows, columns, and elements of the Armadillo matrix.
|
||||
c := int(C.mlpackArmaMatWithInfoRows(C.CString(identifier)))
|
||||
r := int(C.mlpackArmaMatWithInfoCols(C.CString(identifier)))
|
||||
e := int(C.mlpackArmaMatWithInfoElements(C.CString(identifier)))
|
||||
c := int(C.mlpackArmaMatWithInfoRows(p.mem, C.CString(identifier)))
|
||||
r := int(C.mlpackArmaMatWithInfoCols(p.mem, C.CString(identifier)))
|
||||
e := int(C.mlpackArmaMatWithInfoElements(p.mem, C.CString(identifier)))
|
||||
|
||||
// Allocate Go memory pointer to the armadillo matrix.
|
||||
m.allocArmaPtrMatWithInfo(identifier)
|
||||
m.allocArmaPtrMatWithInfo(p, identifier)
|
||||
matarray := (*[1<<30 - 1]float64)(m.mem)
|
||||
|
||||
if matarray != nil {
|
||||
|
||||
@@ -24,88 +24,119 @@ extern "C" {
|
||||
/**
|
||||
* Pass Gonum Dense pointer and wrap an Armadillo mat around it.
|
||||
*/
|
||||
void mlpackToArmaMat(const char* identifier, double* mat,
|
||||
const size_t row, const size_t col)
|
||||
void mlpackToArmaMat(void* params,
|
||||
const char* identifier,
|
||||
double* mat,
|
||||
const size_t row,
|
||||
const size_t col)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::mat m(mat, row, col, false, true);
|
||||
|
||||
// Set input parameter with corresponding matrix in IO.
|
||||
SetParam(identifier, m);
|
||||
SetParam(p, identifier, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Gonum Dense pointer and wrap an Armadillo mat around it.
|
||||
*/
|
||||
void mlpackToArmaUmat(const char* identifier, double* mat,
|
||||
const size_t row, const size_t col)
|
||||
void mlpackToArmaUmat(void* params,
|
||||
const char* identifier,
|
||||
double* mat,
|
||||
const size_t row,
|
||||
const size_t col)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::mat m(mat, row, col, false, true);
|
||||
|
||||
arma::Mat<size_t> matr = arma::conv_to<arma::Mat<size_t>>::from(m);
|
||||
|
||||
// Set input parameter with corresponding matrix in IO.
|
||||
SetParam(identifier, matr);
|
||||
SetParam(p, identifier, matr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Gonum VecDense pointer and wrap an Armadillo rowvec around it.
|
||||
*/
|
||||
void mlpackToArmaRow(const char* identifier, double* rowvec, const size_t elem)
|
||||
void mlpackToArmaRow(void* params,
|
||||
const char* identifier,
|
||||
double* rowvec,
|
||||
const size_t elem)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::rowvec m(rowvec, elem, false, true);
|
||||
|
||||
// Set input parameter with corresponding row in IO.
|
||||
SetParam(identifier, m);
|
||||
SetParam(p, identifier, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Gonum VecDense pointer and wrap an Armadillo rowvec around it.
|
||||
*/
|
||||
void mlpackToArmaUrow(const char* identifier, double* rowvec, const size_t elem)
|
||||
void mlpackToArmaUrow(void* params,
|
||||
const char* identifier,
|
||||
double* rowvec,
|
||||
const size_t elem)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::rowvec m(rowvec, elem, false, true);
|
||||
|
||||
arma::Row<size_t> matr = arma::conv_to<arma::Row<size_t>>::from(m);
|
||||
|
||||
// Set input parameter with corresponding row in IO.
|
||||
SetParam(identifier, matr);
|
||||
SetParam(p, identifier, matr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Gonum VecDense pointer and wrap an Armadillo colvec around it.
|
||||
*/
|
||||
void mlpackToArmaCol(const char* identifier, double* colvec, const size_t elem)
|
||||
void mlpackToArmaCol(void* params,
|
||||
const char* identifier,
|
||||
double* colvec,
|
||||
const size_t elem)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::colvec m(colvec, elem, false, true);
|
||||
|
||||
// Set input parameter with corresponding column in IO.
|
||||
SetParam(identifier, m);
|
||||
SetParam(p, identifier, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Gonum VecDense pointer and wrap an Armadillo colvec around it.
|
||||
*/
|
||||
void mlpackToArmaUcol(const char* identifier, double* colvec, const size_t elem)
|
||||
void mlpackToArmaUcol(void* params,
|
||||
const char* identifier,
|
||||
double* colvec,
|
||||
const size_t elem)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
|
||||
// Advanced constructor.
|
||||
arma::colvec m(colvec, elem, false, true);
|
||||
|
||||
arma::Col<size_t> matr = arma::conv_to<arma::Col<size_t>>::from(m);
|
||||
|
||||
// Set input parameter with corresponding column in IO.
|
||||
SetParam(identifier, matr);
|
||||
SetParam(p, identifier, matr);
|
||||
}
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo mat object.
|
||||
*/
|
||||
void* mlpackArmaPtrMat(const char* identifier)
|
||||
void* mlpackArmaPtrMat(void* params, const char* identifier)
|
||||
{
|
||||
arma::mat& output = IO::GetParam<arma::mat>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::mat& output = p.Get<arma::mat>(identifier);
|
||||
if (output.is_empty())
|
||||
{
|
||||
return NULL;
|
||||
@@ -117,9 +148,10 @@ void* mlpackArmaPtrMat(const char* identifier)
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo umat object.
|
||||
*/
|
||||
void* mlpackArmaPtrUmat(const char* identifier)
|
||||
void* mlpackArmaPtrUmat(void* params, const char* identifier)
|
||||
{
|
||||
arma::Mat<size_t>& m = IO::GetParam<arma::Mat<size_t>>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::Mat<size_t>& m = p.Get<arma::Mat<size_t>>(identifier);
|
||||
|
||||
arma::mat output = arma::conv_to<arma::mat>::from(m);
|
||||
if (output.is_empty())
|
||||
@@ -133,9 +165,10 @@ void* mlpackArmaPtrUmat(const char* identifier)
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo row object.
|
||||
*/
|
||||
void* mlpackArmaPtrRow(const char* identifier)
|
||||
void* mlpackArmaPtrRow(void* params, const char* identifier)
|
||||
{
|
||||
arma::Row<double>& output = IO::GetParam<arma::Row<double>>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::Row<double>& output = p.Get<arma::Row<double>>(identifier);
|
||||
if (output.is_empty())
|
||||
{
|
||||
return NULL;
|
||||
@@ -147,9 +180,10 @@ void* mlpackArmaPtrRow(const char* identifier)
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo urow object.
|
||||
*/
|
||||
void* mlpackArmaPtrUrow(const char* identifier)
|
||||
void* mlpackArmaPtrUrow(void* params, const char* identifier)
|
||||
{
|
||||
arma::Row<size_t>& m = IO::GetParam<arma::Row<size_t>>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::Row<size_t>& m = p.Get<arma::Row<size_t>>(identifier);
|
||||
|
||||
arma::Row<double> output = arma::conv_to<arma::Row<double>>::from(m);
|
||||
if (output.is_empty())
|
||||
@@ -163,9 +197,10 @@ void* mlpackArmaPtrUrow(const char* identifier)
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo col object.
|
||||
*/
|
||||
void* mlpackArmaPtrCol(const char* identifier)
|
||||
void* mlpackArmaPtrCol(void* params, const char* identifier)
|
||||
{
|
||||
arma::Col<double>& output = IO::GetParam<arma::Col<double>>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::Col<double>& output = p.Get<arma::Col<double>>(identifier);
|
||||
if (output.is_empty())
|
||||
{
|
||||
return NULL;
|
||||
@@ -177,9 +212,10 @@ void* mlpackArmaPtrCol(const char* identifier)
|
||||
/**
|
||||
* Return the memory pointer of an Armadillo ucol object.
|
||||
*/
|
||||
void* mlpackArmaPtrUcol(const char* identifier)
|
||||
void* mlpackArmaPtrUcol(void* params, const char* identifier)
|
||||
{
|
||||
arma::Col<size_t>& m = IO::GetParam<arma::Col<size_t>>(identifier);
|
||||
util::Params& p = *((util::Params*) params);
|
||||
arma::Col<size_t>& m = p.Get<arma::Col<size_t>>(identifier);
|
||||
|
||||
arma::Col<double> output = arma::conv_to<arma::Col<double>>::from(m);
|
||||
if (output.is_empty())
|
||||
@@ -193,92 +229,104 @@ void* mlpackArmaPtrUcol(const char* identifier)
|
||||
/**
|
||||
* Return the number of rows in a Armadillo mat.
|
||||
*/
|
||||
int mlpackNumRowMat(const char* identifier)
|
||||
int mlpackNumRowMat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::mat>(identifier).n_rows;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::mat>(identifier).n_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of columns in an Armadillo mat.
|
||||
*/
|
||||
int mlpackNumColMat(const char* identifier)
|
||||
int mlpackNumColMat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::mat>(identifier).n_cols;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::mat>(identifier).n_cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo mat.
|
||||
*/
|
||||
int mlpackNumElemMat(const char* identifier)
|
||||
int mlpackNumElemMat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::mat>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::mat>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of rows in an Armadillo umat.
|
||||
*/
|
||||
int mlpackNumRowUmat(const char* identifier)
|
||||
int mlpackNumRowUmat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Mat<size_t>>(identifier).n_rows;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Mat<size_t>>(identifier).n_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of columns in an Armadillo umat.
|
||||
*/
|
||||
int mlpackNumColUmat(const char* identifier)
|
||||
int mlpackNumColUmat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Mat<size_t>>(identifier).n_cols;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Mat<size_t>>(identifier).n_cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo umat.
|
||||
*/
|
||||
int mlpackNumElemUmat(const char* identifier)
|
||||
int mlpackNumElemUmat(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Mat<size_t>>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Mat<size_t>>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo row.
|
||||
*/
|
||||
int mlpackNumElemRow(const char* identifier)
|
||||
int mlpackNumElemRow(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Row<double>>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Row<double>>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo urow.
|
||||
*/
|
||||
int mlpackNumElemUrow(const char* identifier)
|
||||
int mlpackNumElemUrow(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Row<size_t>>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Row<size_t>>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo col.
|
||||
*/
|
||||
int mlpackNumElemCol(const char* identifier)
|
||||
int mlpackNumElemCol(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Col<double>>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Col<double>>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in an Armadillo ucol.
|
||||
*/
|
||||
int mlpackNumElemUcol(const char* identifier)
|
||||
int mlpackNumElemUcol(void* params, const char* identifier)
|
||||
{
|
||||
return IO::GetParam<arma::Col<size_t>>(identifier).n_elem;
|
||||
util::Params& p = *((util::Params*) params);
|
||||
return p.Get<arma::Col<size_t>>(identifier).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call IO::SetParam<std::tuple<data::DatasetInfo, arma::mat>>().
|
||||
*/
|
||||
void mlpackToArmaMatWithInfo(const char* identifier,
|
||||
void mlpackToArmaMatWithInfo(void* params,
|
||||
const char* identifier,
|
||||
const bool* dimensions,
|
||||
double* memptr,
|
||||
const size_t rows,
|
||||
const size_t cols)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
data::DatasetInfo d(rows);
|
||||
for (size_t i = 0; i < d.Dimensionality(); ++i)
|
||||
{
|
||||
@@ -287,48 +335,52 @@ void mlpackToArmaMatWithInfo(const char* identifier,
|
||||
}
|
||||
|
||||
arma::mat m(memptr, rows, cols, false, true);
|
||||
std::get<0>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
identifier)) = std::move(d);
|
||||
std::get<1>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
identifier)) = std::move(m);
|
||||
IO::SetPassed(identifier);
|
||||
std::get<0>(p.Get<std::tuple<data::DatasetInfo, arma::mat>>( identifier)) =
|
||||
std::move(d);
|
||||
std::get<1>(p.Get<std::tuple<data::DatasetInfo, arma::mat>>( identifier)) =
|
||||
std::move(m);
|
||||
p.SetPassed(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of elements in a matrix with DatasetInfo parameter.
|
||||
*/
|
||||
int mlpackArmaMatWithInfoElements(const char* identifier)
|
||||
int mlpackArmaMatWithInfoElements(void* params, const char* identifier)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
typedef std::tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
return std::get<1>(IO::GetParam<TupleType>(identifier)).n_elem;
|
||||
return std::get<1>(p.Get<TupleType>(identifier)).n_elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows in a matrix with DatasetInfo parameter.
|
||||
*/
|
||||
int mlpackArmaMatWithInfoRows(const char* identifier)
|
||||
int mlpackArmaMatWithInfoRows(void* params, const char* identifier)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
typedef std::tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
return std::get<1>(IO::GetParam<TupleType>(identifier)).n_rows;
|
||||
return std::get<1>(p.Get<TupleType>(identifier)).n_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of columns in a matrix with DatasetInfo parameter.
|
||||
*/
|
||||
int mlpackArmaMatWithInfoCols(const char* identifier)
|
||||
int mlpackArmaMatWithInfoCols(void* params, const char* identifier)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
typedef std::tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
return std::get<1>(IO::GetParam<TupleType>(identifier)).n_cols;
|
||||
return std::get<1>(p.Get<TupleType>(identifier)).n_cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pointer to the memory of the matrix. The calling function is expected
|
||||
* to own the memory.
|
||||
*/
|
||||
void* mlpackArmaPtrMatWithInfoPtr(const char* identifier)
|
||||
void* mlpackArmaPtrMatWithInfoPtr(void* params, const char* identifier)
|
||||
{
|
||||
util::Params& p = *((util::Params*) params);
|
||||
typedef std::tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
arma::mat& m = std::get<1>(IO::GetParam<TupleType>(identifier));
|
||||
arma::mat& m = std::get<1>(p.Get<TupleType>(identifier));
|
||||
if (m.is_empty())
|
||||
{
|
||||
return NULL;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user