Merge branch 'master' into update-elu-and-celu-layers
This commit is contained in:
+6
-18
@@ -104,13 +104,11 @@ option(BUILD_MARKDOWN_BINDINGS "Build Markdown bindings for website documentatio
|
||||
|
||||
option(MATHJAX
|
||||
"Use MathJax for HTML Doxygen output (disabled by default)." OFF)
|
||||
option(FORCE_CXX11
|
||||
"Don't check that the compiler supports C++11, just assume it. Make sure to specify any necessary flag to enable C++11 as part of CXXFLAGS." OFF)
|
||||
option(USE_OPENMP "If available, use OpenMP for parallelization." ON)
|
||||
enable_testing()
|
||||
|
||||
# Set required standard to C++11.
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
# Set required standard to C++14.
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Ensure that GCC is new enough, if the compiler is GCC.
|
||||
@@ -375,26 +373,16 @@ endif()
|
||||
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${CEREAL_INCLUDE_DIR})
|
||||
|
||||
# Detect OpenMP support in a compiler. If the compiler supports OpenMP, flags
|
||||
# to compile with OpenMP are returned and added and the HAS_OPENMP definition
|
||||
# is added for compilation.
|
||||
#
|
||||
# This way we can skip calls to functions defined in omp.h with code like:
|
||||
# #ifdef HAS_OPENMP
|
||||
# {
|
||||
# ... openMP code here ...
|
||||
# }
|
||||
# #endif
|
||||
# to compile with OpenMP are returned and added. Note that MSVC does not
|
||||
# support a new-enough version of OpenMP to be useful.
|
||||
if (USE_OPENMP)
|
||||
find_package(OpenMP)
|
||||
endif ()
|
||||
|
||||
if (OPENMP_FOUND)
|
||||
add_definitions(-DHAS_OPENMP)
|
||||
if (OpenMP_FOUND AND OpenMP_CXX_VERSION VERSION_GREATER_EQUAL 3.0.0)
|
||||
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 ()
|
||||
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${OpenMP_CXX_LIBRARIES})
|
||||
else ()
|
||||
# Disable warnings for all the unknown OpenMP pragmas.
|
||||
if (NOT MSVC)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
### mlpack ?.?.?
|
||||
###### ????-??-??
|
||||
* Bump C++ standard requirement to C++14 (#3233).
|
||||
|
||||
* Fix `Perceptron` to work with cross-validation framework (#3190).
|
||||
|
||||
* Migrate from boost tests to Catch2 framework (#2523), (#2584).
|
||||
|
||||
@@ -199,9 +199,6 @@ The full list of options mlpack allows:
|
||||
(default ON)
|
||||
- MATHJAX=(ON/OFF): use MathJax for generated Doxygen documentation (default
|
||||
OFF)
|
||||
- FORCE_CXX11=(ON/OFF): assume that the compiler supports C++11 instead of
|
||||
checking; be sure to specify any necessary flag to enable C++11 as part
|
||||
of CXXFLAGS (default OFF)
|
||||
- USE_OPENMP=(ON/OFF): if ON, then use OpenMP if the compiler supports it; if
|
||||
OFF, OpenMP support is manually disabled (default ON)
|
||||
|
||||
|
||||
+14
-18
@@ -21,24 +21,20 @@ endforeach()
|
||||
# are set in the root CMakeLists.txt.
|
||||
add_library(mlpack ${MLPACK_SRCS})
|
||||
|
||||
# If we are not forcing C++11 support, check that the compiler supports C++11
|
||||
# and enable it.
|
||||
if (NOT FORCE_CXX11)
|
||||
target_compile_features(mlpack PUBLIC
|
||||
cxx_decltype
|
||||
cxx_alias_templates
|
||||
cxx_auto_type
|
||||
cxx_lambdas
|
||||
cxx_constexpr
|
||||
cxx_rvalue_references
|
||||
cxx_static_assert
|
||||
cxx_template_template_parameters
|
||||
cxx_delegating_constructors
|
||||
cxx_variadic_templates
|
||||
cxx_nullptr
|
||||
cxx_noexcept
|
||||
)
|
||||
endif ()
|
||||
target_compile_features(mlpack PUBLIC
|
||||
cxx_decltype
|
||||
cxx_alias_templates
|
||||
cxx_auto_type
|
||||
cxx_lambdas
|
||||
cxx_constexpr
|
||||
cxx_rvalue_references
|
||||
cxx_static_assert
|
||||
cxx_template_template_parameters
|
||||
cxx_delegating_constructors
|
||||
cxx_variadic_templates
|
||||
cxx_nullptr
|
||||
cxx_noexcept
|
||||
)
|
||||
|
||||
# Generate export symbols for Windows, instead of adding __declspec(dllimport)
|
||||
# and __declspec(dllexport) everywhere. However, those modifiers are still
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @file base.hpp
|
||||
*
|
||||
* The most basic core includes that mlpack expects; standard C++ includes and
|
||||
* Armadillo only
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BASE_HPP
|
||||
#define MLPACK_BASE_HPP
|
||||
|
||||
// First, check if Armadillo was included before, warning if so.
|
||||
#ifdef ARMA_INCLUDES
|
||||
#pragma message "Armadillo was included before mlpack; this can sometimes cause\
|
||||
problems. It should only be necessary to include <mlpack/core.hpp> and not \
|
||||
<armadillo>."
|
||||
#endif
|
||||
|
||||
// Defining _USE_MATH_DEFINES should set M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
|
||||
// Next, standard includes.
|
||||
#include <cctype>
|
||||
#include <cfloat>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
// But if it's not defined, we'll do it.
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653589793238462643383279
|
||||
#endif
|
||||
|
||||
// MLPACK_COUT_STREAM is used to change the default stream for printing
|
||||
// purpose.
|
||||
#if !defined(MLPACK_COUT_STREAM)
|
||||
#define MLPACK_COUT_STREAM std::cout
|
||||
#endif
|
||||
|
||||
// MLPACK_CERR_STREAM is used to change the stream for printing warnings
|
||||
// and errors.
|
||||
#if !defined(MLPACK_CERR_STREAM)
|
||||
#define MLPACK_CERR_STREAM std::cerr
|
||||
#endif
|
||||
|
||||
// Give ourselves a nice way to force functions to be inline if we need.
|
||||
#undef mlpack_force_inline
|
||||
#define mlpack_force_inline
|
||||
#if defined(__GNUG__) && !defined(DEBUG)
|
||||
#undef mlpack_force_inline
|
||||
#define mlpack_force_inline __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER) && !defined(DEBUG)
|
||||
#undef mlpack_force_inline
|
||||
#define mlpack_force_inline __forceinline
|
||||
#endif
|
||||
|
||||
// Backport std::any from C+17 to C++11 to replace boost::any.
|
||||
// Use mnmlstc backport implementation only if compiler does not
|
||||
// support C++17.
|
||||
#if __cplusplus < 201703L
|
||||
#include <mlpack/core/std_backport/any.hpp>
|
||||
#include <mlpack/core/std_backport/string_view.hpp>
|
||||
#define MLPACK_ANY core::v2::any
|
||||
#define MLPACK_ANY_CAST core::v2::any_cast
|
||||
#define MLPACK_STRING_VIEW core::v2::string_view
|
||||
#else
|
||||
#include <any>
|
||||
#include <string_view>
|
||||
#define MLPACK_ANY std::any
|
||||
#define MLPACK_ANY_CAST std::any_cast
|
||||
#define MLPACK_STRING_VIEW std::string_view
|
||||
#endif
|
||||
|
||||
// Now include Armadillo through the special mlpack extensions.
|
||||
#include <mlpack/core/arma_extend/arma_extend.hpp>
|
||||
#include <mlpack/core/util/arma_traits.hpp>
|
||||
|
||||
// On Visual Studio, disable C4519 (default arguments for function templates)
|
||||
// since it's by default an error, which doesn't even make any sense because
|
||||
// it's part of the C++11 standard.
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4519)
|
||||
#endif
|
||||
|
||||
// Ensure that the user isn't doing something stupid with their Armadillo
|
||||
// defines.
|
||||
#include <mlpack/core/util/arma_config_check.hpp>
|
||||
|
||||
// This can be removed when Visual Studio supports an OpenMP version with
|
||||
// unsigned loop variables.
|
||||
#if (defined(_OPENMP) && (_OPENMP >= 201107))
|
||||
#undef MLPACK_USE_OPENMP
|
||||
#define MLPACK_USE_OPENMP
|
||||
#endif
|
||||
|
||||
// We need to be able to mark functions deprecated.
|
||||
#include <mlpack/core/util/deprecated.hpp>
|
||||
|
||||
#endif
|
||||
@@ -15,6 +15,7 @@ endforeach()
|
||||
|
||||
set(MARKDOWN_CATEGORIES ${MARKDOWN_CATEGORIES} PARENT_SCOPE)
|
||||
set(MLPACK_SRCS ${MLPACK_SRCS} PARENT_SCOPE)
|
||||
set(MLPACK_TEST_SRCS ${MLPACK_TEST_SRCS} PARENT_SCOPE)
|
||||
set(MLPACK_PYXS ${MLPACK_PYXS} PARENT_SCOPE)
|
||||
set(DISABLE_CFLAGS ${DISABLE_CFLAGS} PARENT_SCOPE)
|
||||
set(BUILDING_PYTHON_BINDINGS ${BUILDING_PYTHON_BINDINGS} PARENT_SCOPE)
|
||||
|
||||
@@ -414,6 +414,7 @@ macro (post_r_setup)
|
||||
# Then copy each of the header and source files over to that directory.
|
||||
set(MLPACK_SOURCES
|
||||
"${CMAKE_BINARY_DIR}/src/mlpack/mlpack_export.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/base.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/prereqs.hpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/core.hpp"
|
||||
)
|
||||
|
||||
@@ -73,7 +73,7 @@ class ROption
|
||||
data.cppType = cppName;
|
||||
|
||||
// Every parameter we'll get from R will have the correct type.
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
// 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
|
||||
|
||||
@@ -36,7 +36,7 @@ std::string DefaultParamImpl(
|
||||
if (std::is_same<T, bool>::value)
|
||||
oss << "FALSE";
|
||||
else
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
const T& vector = ANY_CAST<T>(data.value);
|
||||
const T& vector = MLPACK_ANY_CAST<T>(data.value);
|
||||
oss << "c(";
|
||||
if (std::is_same<T, std::vector<std::string>>::value)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *ANY_CAST<std::string>(&data.value);
|
||||
const std::string& s = *MLPACK_ANY_CAST<std::string>(&data.value);
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void GetParam(util::ParamData& d,
|
||||
const void* /* input */,
|
||||
void* output)
|
||||
{
|
||||
*((T**) output) = const_cast<T*>(ANY_CAST<T>(&d.value));
|
||||
*((T**) output) = const_cast<T*>(MLPACK_ANY_CAST<T>(&d.value));
|
||||
}
|
||||
|
||||
} // namespace r
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -61,7 +61,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = ANY_CAST<T>(data.value);
|
||||
const T& matrix = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
|
||||
@@ -78,7 +78,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << ANY_CAST<T*>(data.value);
|
||||
oss << data.cppType << " model at " << MLPACK_ANY_CAST<T*>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = ANY_CAST<T>(data.value);
|
||||
const T& tuple = MLPACK_ANY_CAST<T>(data.value);
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -7,8 +7,7 @@ Description: A fast, flexible machine learning library, written in C++, that
|
||||
aims to provide fast, extensible implementations of cutting-edge
|
||||
machine learning algorithms. See also Curtin et al. (2018)
|
||||
<doi:10.21105/joss.00726>.
|
||||
SystemRequirements: A C++11 compiler. Versions 4.8.*, 4.9.* or later of GCC
|
||||
will be fine.
|
||||
SystemRequirements: A C++14 compiler. Version 5 or later of GCC will be fine.
|
||||
License: BSD_3_clause + file LICENSE
|
||||
Depends: R (>= 4.0.0)
|
||||
Imports: Rcpp (>= 0.12.12)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS)
|
||||
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
|
||||
CXX_STD = CXX11
|
||||
CXX_STD = CXX14
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
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
|
||||
CXX_STD = CXX14
|
||||
|
||||
@@ -55,19 +55,19 @@ void PrintDoc(util::ParamData& d,
|
||||
oss << ". Default value \"";
|
||||
if (d.cppType == "std::string")
|
||||
{
|
||||
oss << ANY_CAST<std::string>(d.value);
|
||||
oss << MLPACK_ANY_CAST<std::string>(d.value);
|
||||
}
|
||||
else if (d.cppType == "double")
|
||||
{
|
||||
oss << ANY_CAST<double>(d.value);
|
||||
oss << MLPACK_ANY_CAST<double>(d.value);
|
||||
}
|
||||
else if (d.cppType == "int")
|
||||
{
|
||||
oss << ANY_CAST<int>(d.value);
|
||||
oss << MLPACK_ANY_CAST<int>(d.value);
|
||||
}
|
||||
else if (d.cppType == "bool")
|
||||
{
|
||||
oss << (ANY_CAST<bool>(d.value) ? "TRUE" : "FALSE");
|
||||
oss << (MLPACK_ANY_CAST<bool>(d.value) ? "TRUE" : "FALSE");
|
||||
}
|
||||
oss << "\"";
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ void AddToCLI11(const std::string& cliName,
|
||||
[¶m](const std::string& value)
|
||||
{
|
||||
using TupleType = std::tuple<T, typename ParameterType<T>::type>;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<0>(std::get<1>(tuple)) = ANY_CAST<std::string>(value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<0>(std::get<1>(tuple)) = MLPACK_ANY_CAST<std::string>(value);
|
||||
param.wasPassed = true;
|
||||
},
|
||||
param.desc.c_str());
|
||||
@@ -79,8 +79,8 @@ void AddToCLI11(const std::string& cliName,
|
||||
[¶m](const std::string& value)
|
||||
{
|
||||
using TupleType = std::tuple<T*, typename ParameterType<T>::type>;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<1>(tuple) = ANY_CAST<std::string>(value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<1>(tuple) = MLPACK_ANY_CAST<std::string>(value);
|
||||
param.wasPassed = true;
|
||||
},
|
||||
param.desc.c_str());
|
||||
@@ -109,8 +109,8 @@ void AddToCLI11(const std::string& cliName,
|
||||
[¶m](const std::string& value)
|
||||
{
|
||||
using TupleType = std::tuple<T, typename ParameterType<T>::type>;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<0>(std::get<1>(tuple)) = ANY_CAST<std::string>(value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(¶m.value);
|
||||
std::get<0>(std::get<1>(tuple)) = MLPACK_ANY_CAST<std::string>(value);
|
||||
param.wasPassed = true;
|
||||
},
|
||||
param.desc.c_str());
|
||||
|
||||
@@ -95,12 +95,12 @@ class CLIOption
|
||||
typename ParameterType<typename
|
||||
std::remove_pointer<N>::type>::type>::value)
|
||||
{
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
typename ParameterType<typename std::remove_pointer<N>::type>::type tmp;
|
||||
data.value = ANY(std::tuple<N, decltype(tmp)>(defaultValue, tmp));
|
||||
data.value = std::tuple<N, decltype(tmp)>(defaultValue, tmp);
|
||||
}
|
||||
|
||||
const std::string tname = data.tname;
|
||||
|
||||
@@ -34,7 +34,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if (!std::is_same<T, bool>::value)
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
const T& vector = ANY_CAST<T>(data.value);
|
||||
const T& vector = MLPACK_ANY_CAST<T>(data.value);
|
||||
oss << "[";
|
||||
if (std::is_same<T, std::vector<std::string>>::value)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *ANY_CAST<std::string>(&data.value);
|
||||
const std::string& s = *MLPACK_ANY_CAST<std::string>(&data.value);
|
||||
return "'" + s + "'";
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ void DeleteAllocatedMemoryImpl(
|
||||
{
|
||||
// Delete the allocated memory (hopefully we actually own it).
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
delete std::get<0>(*ANY_CAST<TupleType>(&d.value));
|
||||
delete std::get<0>(*MLPACK_ANY_CAST<TupleType>(&d.value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -45,7 +45,7 @@ void* GetAllocatedMemory(
|
||||
// Here we have a model, which is a tuple, and we need the address of the
|
||||
// memory.
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
return std::get<0>(*ANY_CAST<TupleType>(&d.value));
|
||||
return std::get<0>(*MLPACK_ANY_CAST<TupleType>(&d.value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -34,7 +34,7 @@ T& GetParam(
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed, so just cast it directly.
|
||||
return *ANY_CAST<T>(&d.value);
|
||||
return *MLPACK_ANY_CAST<T>(&d.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ T& GetParam(
|
||||
// times, but I am not bothered by that---it shouldn't be something that
|
||||
// happens.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(&d.value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
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));
|
||||
@@ -86,7 +86,7 @@ T& GetParam(
|
||||
// If this is an input parameter, we need to load both the matrix and the
|
||||
// dataset info.
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
TupleType* tuple = ANY_CAST<TupleType>(&d.value);
|
||||
TupleType* tuple = MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
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));
|
||||
@@ -116,7 +116,7 @@ T*& GetParam(
|
||||
// If the model is an input model, we have to load it from file. 'value'
|
||||
// contains the filename.
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
TupleType* tuple = ANY_CAST<TupleType>(&d.value);
|
||||
TupleType* tuple = MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
const std::string& value = std::get<1>(*tuple);
|
||||
if (d.input && !d.loaded)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type*
|
||||
/* junk */)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -80,7 +80,7 @@ std::string GetPrintableParam(
|
||||
{
|
||||
// Extract the string from the tuple that's being held.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
const TupleType* tuple = ANY_CAST<TupleType>(&data.value);
|
||||
const TupleType* tuple = MLPACK_ANY_CAST<TupleType>(&data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "'" << std::get<0>(std::get<1>(*tuple)) << "'";
|
||||
@@ -108,7 +108,7 @@ std::string GetPrintableParam(
|
||||
{
|
||||
// Extract the string from the tuple that's being held.
|
||||
typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
|
||||
const TupleType* tuple = ANY_CAST<TupleType>(&data.value);
|
||||
const TupleType* tuple = MLPACK_ANY_CAST<TupleType>(&data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << std::get<1>(*tuple);
|
||||
|
||||
@@ -33,7 +33,7 @@ T& GetRawParam(
|
||||
std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed, so just cast it directly.
|
||||
return *ANY_CAST<T>(&d.value);
|
||||
return *MLPACK_ANY_CAST<T>(&d.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ T& GetRawParam(
|
||||
{
|
||||
// Don't load the matrix.
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
T& value = std::get<0>(*ANY_CAST<TupleType>(&d.value));
|
||||
T& value = std::get<0>(*MLPACK_ANY_CAST<TupleType>(&d.value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ T*& GetRawParam(
|
||||
{
|
||||
// Don't load the model.
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
T*& value = std::get<0>(*ANY_CAST<TupleType>(&d.value));
|
||||
T*& value = std::get<0>(*MLPACK_ANY_CAST<TupleType>(&d.value));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ void InPlaceCopyInternal(
|
||||
{
|
||||
// Make the output filename the same as the input filename.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(&d.value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
std::string& value = std::get<0>(std::get<1>(tuple));
|
||||
|
||||
const TupleType& inputTuple = *ANY_CAST<TupleType>(&input.value);
|
||||
const TupleType& inputTuple = *MLPACK_ANY_CAST<TupleType>(&input.value);
|
||||
value = std::get<0>(std::get<1>(inputTuple));
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ void InPlaceCopyInternal(
|
||||
{
|
||||
// Make the output filename the same as the input filename.
|
||||
typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(&d.value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
std::string& value = std::get<1>(tuple);
|
||||
|
||||
const TupleType& inputTuple = *ANY_CAST<TupleType>(&input.value);
|
||||
const TupleType& inputTuple = *MLPACK_ANY_CAST<TupleType>(&input.value);
|
||||
value = std::get<1>(inputTuple);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ using Option = mlpack::bindings::cli::CLIOption<T>;
|
||||
}
|
||||
|
||||
#include <mlpack/core/util/param.hpp>
|
||||
#include <mlpack/core/util/timers.hpp>
|
||||
#include <mlpack/core/util/io.hpp>
|
||||
#include <mlpack/bindings/cli/parse_command_line.hpp>
|
||||
#include <mlpack/bindings/cli/end_program.hpp>
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ void OutputParamImpl(
|
||||
const typename std::enable_if<!std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::cout << data.name << ": " << *ANY_CAST<T>(&data.value)
|
||||
std::cout << data.name << ": " << *MLPACK_ANY_CAST<T>(&data.value)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void OutputParamImpl(
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
std::cout << data.name << ": ";
|
||||
const T& t = *ANY_CAST<T>(&data.value);
|
||||
const T& t = *MLPACK_ANY_CAST<T>(&data.value);
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
std::cout << t[i] << " ";
|
||||
std::cout << std::endl;
|
||||
@@ -54,9 +54,9 @@ void OutputParamImpl(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* /* junk */)
|
||||
{
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
const T& output = std::get<0>(*ANY_CAST<TupleType>(&data.value));
|
||||
const T& output = std::get<0>(*MLPACK_ANY_CAST<TupleType>(&data.value));
|
||||
const std::string& filename =
|
||||
std::get<0>(std::get<1>(*ANY_CAST<TupleType>(&data.value)));
|
||||
std::get<0>(std::get<1>(*MLPACK_ANY_CAST<TupleType>(&data.value)));
|
||||
|
||||
if (output.n_elem > 0 && filename != "")
|
||||
{
|
||||
@@ -78,10 +78,10 @@ void OutputParamImpl(
|
||||
// const. In this case we can assume it though, since we will be saving and
|
||||
// not loading.
|
||||
typedef std::tuple<T*, std::string> TupleType;
|
||||
T*& output = const_cast<T*&>(std::get<0>(*ANY_CAST<TupleType>(
|
||||
T*& output = const_cast<T*&>(std::get<0>(*MLPACK_ANY_CAST<TupleType>(
|
||||
&data.value)));
|
||||
const std::string& filename =
|
||||
std::get<1>(*ANY_CAST<TupleType>(&data.value));
|
||||
std::get<1>(*MLPACK_ANY_CAST<TupleType>(&data.value));
|
||||
|
||||
if (filename != "")
|
||||
data::Save(filename, "model", *output);
|
||||
@@ -96,9 +96,9 @@ void OutputParamImpl(
|
||||
{
|
||||
// Output the matrix with the mappings.
|
||||
typedef std::tuple<T, std::tuple<std::string, size_t, size_t>> TupleType;
|
||||
const T& tuple = std::get<0>(*ANY_CAST<TupleType>(&data.value));
|
||||
const T& tuple = std::get<0>(*MLPACK_ANY_CAST<TupleType>(&data.value));
|
||||
const std::string& filename =
|
||||
std::get<0>(std::get<1>(*ANY_CAST<TupleType>(&data.value)));
|
||||
std::get<0>(std::get<1>(*MLPACK_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()
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace cli {
|
||||
template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const ANY& value,
|
||||
const MLPACK_ANY& value,
|
||||
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,
|
||||
@@ -34,7 +34,7 @@ void SetParam(
|
||||
const typename std::enable_if<!std::is_same<T, bool>::value>::type* = 0)
|
||||
{
|
||||
// No mapping is needed.
|
||||
d.value = value;
|
||||
d.value = *MLPACK_ANY_CAST<T>(&value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ void SetParam(
|
||||
template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const ANY& /* value */,
|
||||
const MLPACK_ANY& /* value */,
|
||||
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.
|
||||
@@ -57,15 +57,15 @@ void SetParam(
|
||||
template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const ANY& value,
|
||||
const MLPACK_ANY& value,
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value ||
|
||||
std::is_same<T,
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// We're setting the string filename.
|
||||
typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(&d.value);
|
||||
std::get<0>(std::get<1>(tuple)) = ANY_CAST<std::string>(value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
std::get<0>(std::get<1>(tuple)) = MLPACK_ANY_CAST<std::string>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,14 +75,14 @@ void SetParam(
|
||||
template<typename T>
|
||||
void SetParam(
|
||||
util::ParamData& d,
|
||||
const ANY& value,
|
||||
const MLPACK_ANY& value,
|
||||
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;
|
||||
TupleType& tuple = *ANY_CAST<TupleType>(&d.value);
|
||||
std::get<1>(tuple) = ANY_CAST<std::string>(value);
|
||||
TupleType& tuple = *MLPACK_ANY_CAST<TupleType>(&d.value);
|
||||
std::get<1>(tuple) = MLPACK_ANY_CAST<std::string>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ template<typename T>
|
||||
void SetParam(util::ParamData& d, const void* input, void* /* output */)
|
||||
{
|
||||
SetParam<typename std::remove_pointer<T>::type>(
|
||||
const_cast<util::ParamData&>(d), *((ANY*) input));
|
||||
const_cast<util::ParamData&>(d), *((MLPACK_ANY*) input));
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
|
||||
@@ -36,7 +36,7 @@ std::string DefaultParamImpl(
|
||||
if (std::is_same<T, bool>::value)
|
||||
oss << "false";
|
||||
else
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
const T& vector = ANY_CAST<T>(data.value);
|
||||
const T& vector = MLPACK_ANY_CAST<T>(data.value);
|
||||
if (std::is_same<T, std::vector<std::string>>::value)
|
||||
{
|
||||
oss << "[]string{";
|
||||
@@ -93,7 +93,7 @@ std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *ANY_CAST<std::string>(&data.value);
|
||||
const std::string& s = *MLPACK_ANY_CAST<std::string>(&data.value);
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void GetParam(util::ParamData& d,
|
||||
const void* /* input */,
|
||||
void* output)
|
||||
{
|
||||
*((T**) output) = const_cast<T*>(ANY_CAST<T>(&d.value));
|
||||
*((T**) output) = const_cast<T*>(MLPACK_ANY_CAST<T>(&d.value));
|
||||
}
|
||||
|
||||
} // namespace go
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -61,7 +61,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = ANY_CAST<T>(data.value);
|
||||
const T& matrix = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
|
||||
@@ -78,7 +78,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << ANY_CAST<T*>(data.value);
|
||||
oss << data.cppType << " model at " << MLPACK_ANY_CAST<T*>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = ANY_CAST<T>(data.value);
|
||||
const T& tuple = MLPACK_ANY_CAST<T>(data.value);
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -78,7 +78,7 @@ class GoOption
|
||||
data.loaded = false;
|
||||
data.cppType = cppName;
|
||||
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
// Set the function pointers that we'll need. All of these function
|
||||
// pointers will be used by both the program that generates the .cpp,
|
||||
|
||||
@@ -53,16 +53,16 @@ void PrintDoc(util::ParamData& d,
|
||||
{
|
||||
if (d.cppType == "std::string")
|
||||
{
|
||||
oss << " Default value '" << ANY_CAST<std::string>(d.value)
|
||||
oss << " Default value '" << MLPACK_ANY_CAST<std::string>(d.value)
|
||||
<< "'.";
|
||||
}
|
||||
else if (d.cppType == "double")
|
||||
{
|
||||
oss << " Default value " << ANY_CAST<double>(d.value) << ".";
|
||||
oss << " Default value " << MLPACK_ANY_CAST<double>(d.value) << ".";
|
||||
}
|
||||
else if (d.cppType == "int")
|
||||
{
|
||||
oss << " Default value " << ANY_CAST<int>(d.value) << ".";
|
||||
oss << " Default value " << MLPACK_ANY_CAST<int>(d.value) << ".";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,22 +67,22 @@ void PrintInputProcessing(
|
||||
// Print out default value.
|
||||
if (d.cppType == "std::string")
|
||||
{
|
||||
std::string value = ANY_CAST<std::string>(d.value);
|
||||
std::string value = MLPACK_ANY_CAST<std::string>(d.value);
|
||||
std::cout << "\"" << value << "\"";
|
||||
}
|
||||
else if (d.cppType == "double")
|
||||
{
|
||||
double value = ANY_CAST<double>(d.value);
|
||||
double value = MLPACK_ANY_CAST<double>(d.value);
|
||||
std::cout << value;
|
||||
}
|
||||
else if (d.cppType == "int")
|
||||
{
|
||||
int value = ANY_CAST<int>(d.value);
|
||||
int value = MLPACK_ANY_CAST<int>(d.value);
|
||||
std::cout << value;
|
||||
}
|
||||
else if (d.cppType == "bool")
|
||||
{
|
||||
bool value = ANY_CAST<bool>(d.value);
|
||||
bool value = MLPACK_ANY_CAST<bool>(d.value);
|
||||
if (value == 0)
|
||||
std::cout << "false";
|
||||
else
|
||||
|
||||
@@ -54,23 +54,23 @@ void PrintMethodInit(
|
||||
{
|
||||
if (d.cppType == "std::string")
|
||||
{
|
||||
std::string value = ANY_CAST<std::string>(d.value);
|
||||
std::string value = MLPACK_ANY_CAST<std::string>(d.value);
|
||||
std::cout << prefix << goParamName << ": \""
|
||||
<< value << "\"," << std::endl;
|
||||
}
|
||||
else if (d.cppType == "double")
|
||||
{
|
||||
double value = ANY_CAST<double>(d.value);
|
||||
double value = MLPACK_ANY_CAST<double>(d.value);
|
||||
std::cout << prefix << goParamName << ": " << value << "," << std::endl;
|
||||
}
|
||||
else if (d.cppType == "int")
|
||||
{
|
||||
int value = ANY_CAST<int>(d.value);
|
||||
int value = MLPACK_ANY_CAST<int>(d.value);
|
||||
std::cout << prefix << goParamName << ": " << value << "," << std::endl;
|
||||
}
|
||||
else if (d.cppType == "bool")
|
||||
{
|
||||
bool value = ANY_CAST<bool>(d.value);
|
||||
bool value = MLPACK_ANY_CAST<bool>(d.value);
|
||||
if (value == 0)
|
||||
std::cout << prefix << goParamName << ": false," << std::endl;
|
||||
else
|
||||
|
||||
@@ -36,7 +36,7 @@ std::string DefaultParamImpl(
|
||||
if (std::is_same<T, bool>::value)
|
||||
oss << "false";
|
||||
else
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
const T& vector = ANY_CAST<T>(data.value);
|
||||
const T& vector = MLPACK_ANY_CAST<T>(data.value);
|
||||
oss << "[";
|
||||
if (std::is_same<T, std::vector<std::string>>::value)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *ANY_CAST<std::string>(&data.value);
|
||||
const std::string& s = *MLPACK_ANY_CAST<std::string>(&data.value);
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void GetParam(util::ParamData& d,
|
||||
const void* /* input */,
|
||||
void* output)
|
||||
{
|
||||
*((T**) output) = const_cast<T*>(ANY_CAST<T>(&d.value));
|
||||
*((T**) output) = const_cast<T*>(MLPACK_ANY_CAST<T>(&d.value));
|
||||
}
|
||||
|
||||
} // namespace julia
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -61,7 +61,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = ANY_CAST<T>(data.value);
|
||||
const T& matrix = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
|
||||
@@ -78,7 +78,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << ANY_CAST<T*>(data.value);
|
||||
oss << data.cppType << " model at " << MLPACK_ANY_CAST<T*>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = ANY_CAST<T>(data.value);
|
||||
const T& tuple = MLPACK_ANY_CAST<T>(data.value);
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -64,7 +64,7 @@ class JuliaOption
|
||||
data.cppType = cppName;
|
||||
|
||||
// Every parameter we'll get from Julia will have the correct type.
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
// Set the function pointers that we'll need. All of these function
|
||||
// pointers will be used by both the program that generates the pyx, and
|
||||
|
||||
@@ -39,19 +39,19 @@ void PrintDoc(util::ParamData& d, const void* /* input */, void* output)
|
||||
oss << " Default value `";
|
||||
if (d.cppType == "std::string")
|
||||
{
|
||||
oss << ANY_CAST<std::string>(d.value);
|
||||
oss << MLPACK_ANY_CAST<std::string>(d.value);
|
||||
}
|
||||
else if (d.cppType == "double")
|
||||
{
|
||||
oss << ANY_CAST<double>(d.value);
|
||||
oss << MLPACK_ANY_CAST<double>(d.value);
|
||||
}
|
||||
else if (d.cppType == "int")
|
||||
{
|
||||
oss << ANY_CAST<int>(d.value);
|
||||
oss << MLPACK_ANY_CAST<int>(d.value);
|
||||
}
|
||||
else if (d.cppType == "bool")
|
||||
{
|
||||
oss << (ANY_CAST<bool>(d.value) ? "true" : "false");
|
||||
oss << (MLPACK_ANY_CAST<bool>(d.value) ? "true" : "false");
|
||||
}
|
||||
oss << "`." << std::endl;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void GetParam(util::ParamData& d,
|
||||
void* output)
|
||||
{
|
||||
util::ParamData& dmod = const_cast<util::ParamData&>(d);
|
||||
*((T**) output) = ANY_CAST<T>(&dmod.value);
|
||||
*((T**) output) = MLPACK_ANY_CAST<T>(&dmod.value);
|
||||
}
|
||||
|
||||
} // namespace markdown
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -61,7 +61,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = ANY_CAST<T>(data.value);
|
||||
const T& matrix = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
|
||||
@@ -78,7 +78,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << ANY_CAST<T*>(data.value);
|
||||
oss << data.cppType << " model at " << MLPACK_ANY_CAST<T*>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = ANY_CAST<T>(data.value);
|
||||
const T& tuple = MLPACK_ANY_CAST<T>(data.value);
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -63,7 +63,7 @@ class MDOption
|
||||
data.cppType = cppName;
|
||||
|
||||
// Every parameter we'll get from Markdown will have the correct type.
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
// Set the function pointers that we'll need. Most of these simply delegate
|
||||
// to the current binding type's implementation. Any new language will need
|
||||
|
||||
@@ -263,7 +263,7 @@ inline std::string PrintTypeDocs()
|
||||
data.required = false;
|
||||
data.input = true;
|
||||
data.loaded = false;
|
||||
data.value = ANY(int(0));
|
||||
data.value = MLPACK_ANY(int(0));
|
||||
|
||||
std::string type = GetPrintableType<int>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -271,7 +271,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(double).name());
|
||||
data.cppType = "double";
|
||||
data.value = ANY(double(0.0));
|
||||
data.value = MLPACK_ANY(double(0.0));
|
||||
|
||||
type = GetPrintableType<double>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -280,7 +280,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(bool).name());
|
||||
data.cppType = "double";
|
||||
data.value = ANY(bool(0.0));
|
||||
data.value = MLPACK_ANY(bool(0.0));
|
||||
|
||||
type = GetPrintableType<bool>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -288,7 +288,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(std::string).name());
|
||||
data.cppType = "std::string";
|
||||
data.value = ANY(std::string(""));
|
||||
data.value = MLPACK_ANY(std::string(""));
|
||||
|
||||
type = GetPrintableType<std::string>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -297,7 +297,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(std::vector<int>).name());
|
||||
data.cppType = "std::vector<int>";
|
||||
data.value = ANY(std::vector<int>());
|
||||
data.value = MLPACK_ANY(std::vector<int>());
|
||||
|
||||
type = GetPrintableType<std::vector<int>>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -306,7 +306,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(std::vector<std::string>).name());
|
||||
data.cppType = "std::vector<std::string>";
|
||||
data.value = ANY(std::vector<std::string>());
|
||||
data.value = MLPACK_ANY(std::vector<std::string>());
|
||||
|
||||
type = GetPrintableType<std::vector<std::string>>(data);
|
||||
oss << " - `" << type << "`{: " << "#doc_" << BindingInfo::Language() << "_"
|
||||
@@ -315,7 +315,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::mat).name());
|
||||
data.cppType = "arma::mat";
|
||||
data.value = ANY(arma::mat());
|
||||
data.value = MLPACK_ANY(arma::mat());
|
||||
|
||||
type = GetPrintableType<arma::mat>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -324,7 +324,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::Mat<size_t>).name());
|
||||
data.cppType = "arma::Mat<size_t>";
|
||||
data.value = ANY(arma::Mat<size_t>());
|
||||
data.value = MLPACK_ANY(arma::Mat<size_t>());
|
||||
|
||||
type = GetPrintableType<arma::Mat<size_t>>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -333,7 +333,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::rowvec).name());
|
||||
data.cppType = "arma::rowvec";
|
||||
data.value = ANY(arma::rowvec());
|
||||
data.value = MLPACK_ANY(arma::rowvec());
|
||||
const std::string& rowType = GetPrintableType<arma::rowvec>(data);
|
||||
|
||||
oss << " - `" << rowType << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -342,7 +342,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::Row<size_t>).name());
|
||||
data.cppType = "arma::Row<size_t>";
|
||||
data.value = ANY(arma::Row<size_t>());
|
||||
data.value = MLPACK_ANY(arma::Row<size_t>());
|
||||
const std::string& urowType = GetPrintableType<arma::Row<size_t>>(data);
|
||||
|
||||
oss << " - `" << urowType << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -352,7 +352,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::vec).name());
|
||||
data.cppType = "arma::vec";
|
||||
data.value = ANY(arma::vec());
|
||||
data.value = MLPACK_ANY(arma::vec());
|
||||
const std::string& colType = GetPrintableType<arma::vec>(data);
|
||||
|
||||
// For some languages there is no distinction between column and row vectors.
|
||||
@@ -366,7 +366,7 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(arma::Col<size_t>).name());
|
||||
data.cppType = "arma::Col<size_t>";
|
||||
data.value = ANY(arma::Col<size_t>());
|
||||
data.value = MLPACK_ANY(arma::Col<size_t>());
|
||||
const std::string& ucolType = GetPrintableType<arma::Col<size_t>>(data);
|
||||
|
||||
// For some languages there is no distinction between column and row vectors.
|
||||
@@ -381,7 +381,7 @@ inline std::string PrintTypeDocs()
|
||||
data.tname =
|
||||
std::string(typeid(std::tuple<data::DatasetInfo, arma::mat>).name());
|
||||
data.cppType = "std::tuple<data::DatasetInfo, arma::mat>";
|
||||
data.value = ANY(std::tuple<data::DatasetInfo, arma::mat>());
|
||||
data.value = MLPACK_ANY(std::tuple<data::DatasetInfo, arma::mat>());
|
||||
|
||||
type = GetPrintableType<std::tuple<data::DatasetInfo, arma::mat>>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language() << "_"
|
||||
@@ -391,14 +391,14 @@ inline std::string PrintTypeDocs()
|
||||
|
||||
data.tname = std::string(typeid(priv::mlpackModel).name());
|
||||
data.cppType = "mlpackModel";
|
||||
data.value = ANY(new priv::mlpackModel());
|
||||
data.value = MLPACK_ANY(new priv::mlpackModel());
|
||||
|
||||
type = GetPrintableType<priv::mlpackModel*>(data);
|
||||
oss << " - `" << type << "`{: #doc_" << BindingInfo::Language()
|
||||
<< "_model }: " << PrintTypeDoc<priv::mlpackModel*>(data) << std::endl;
|
||||
|
||||
// Clean up memory.
|
||||
delete ANY_CAST<priv::mlpackModel*>(data.value);
|
||||
delete MLPACK_ANY_CAST<priv::mlpackModel*>(data.value);
|
||||
|
||||
oss << std::endl << "</div>" << std::endl;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ std::string DefaultParamImpl(
|
||||
if (std::is_same<T, bool>::value)
|
||||
oss << "False";
|
||||
else
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ std::string DefaultParamImpl(
|
||||
{
|
||||
// Print each element in an array delimited by square brackets.
|
||||
std::ostringstream oss;
|
||||
const T& vector = ANY_CAST<T>(data.value);
|
||||
const T& vector = MLPACK_ANY_CAST<T>(data.value);
|
||||
oss << "[";
|
||||
if (std::is_same<T, std::vector<std::string>>::value)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ std::string DefaultParamImpl(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
|
||||
{
|
||||
const std::string& s = *ANY_CAST<std::string>(&data.value);
|
||||
const std::string& s = *MLPACK_ANY_CAST<std::string>(&data.value);
|
||||
return "'" + s + "'";
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void GetParam(util::ParamData& d,
|
||||
const void* /* input */,
|
||||
void* output)
|
||||
{
|
||||
*((T**) output) = const_cast<T*>(ANY_CAST<T>(&d.value));
|
||||
*((T**) output) = const_cast<T*>(MLPACK_ANY_CAST<T>(&d.value));
|
||||
}
|
||||
|
||||
} // namespace python
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
@@ -61,7 +61,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& matrix = ANY_CAST<T>(data.value);
|
||||
const T& matrix = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
|
||||
@@ -78,7 +78,7 @@ std::string GetPrintableParam(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << data.cppType << " model at " << ANY_CAST<T*>(data.value);
|
||||
oss << data.cppType << " model at " << MLPACK_ANY_CAST<T*>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
|
||||
{
|
||||
// Get the matrix.
|
||||
const T& tuple = ANY_CAST<T>(data.value);
|
||||
const T& tuple = MLPACK_ANY_CAST<T>(data.value);
|
||||
const arma::mat& matrix = std::get<1>(tuple);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -64,7 +64,7 @@ class PyOption
|
||||
data.cppType = cppName;
|
||||
|
||||
// Every parameter we'll get from Python will have the correct type.
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
// Set the function pointers that we'll need. All of these function
|
||||
// pointers will be used by both the program that generates the pyx, and
|
||||
|
||||
@@ -52,7 +52,7 @@ if os.getenv('NO_BUILD') == '1':
|
||||
else:
|
||||
cxx_flags = '${CMAKE_CXX_FLAGS}'.strip()
|
||||
cxx_flags = re.sub(' +', ' ', cxx_flags)
|
||||
extra_args = ['-DBINDING_TYPE=BINDING_TYPE_PYX', '-std=c++11']
|
||||
extra_args = ['-DBINDING_TYPE=BINDING_TYPE_PYX', '-std=c++14']
|
||||
if '${OpenMP_CXX_FLAGS}' != '':
|
||||
extra_args.append('${OpenMP_CXX_FLAGS}')
|
||||
if cxx_flags:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Define the files we need to compile.
|
||||
# Anything not in this list will not be compiled into mlpack.
|
||||
set(SOURCES
|
||||
# Define the files we need to compile into the test executable.
|
||||
# Anything not in this list will not be compiled into mlpack_test.
|
||||
set(BINDING_SOURCES
|
||||
clean_memory.hpp
|
||||
clean_memory.cpp
|
||||
test_option.hpp
|
||||
@@ -17,9 +17,9 @@ set(SOURCES
|
||||
|
||||
# Add directory name to sources.
|
||||
set(DIR_SRCS)
|
||||
foreach(file ${SOURCES})
|
||||
foreach(file ${BINDING_SOURCES})
|
||||
set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file})
|
||||
endforeach()
|
||||
# Append source (with directory name) to list of all mlpack sources (used at the
|
||||
# parent scope).
|
||||
set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
|
||||
set(MLPACK_TEST_SRCS ${MLPACK_TEST_SRCS} ${DIR_SRCS} PARENT_SCOPE)
|
||||
|
||||
@@ -42,7 +42,7 @@ void DeleteAllocatedMemoryImpl(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Delete the allocated memory (hopefully we actually own it).
|
||||
delete *ANY_CAST<T*>(&d.value);
|
||||
delete *MLPACK_ANY_CAST<T*>(&d.value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -43,7 +43,7 @@ void* GetAllocatedMemory(
|
||||
const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
|
||||
{
|
||||
// Here we have a model; return its memory location.
|
||||
return *ANY_CAST<T*>(&d.value);
|
||||
return *MLPACK_ANY_CAST<T*>(&d.value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -26,7 +26,7 @@ template<typename T>
|
||||
T& GetParam(util::ParamData& d)
|
||||
{
|
||||
// No mapping is needed, so just cast it directly.
|
||||
return *ANY_CAST<T>(&d.value);
|
||||
return *MLPACK_ANY_CAST<T>(&d.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ std::string GetPrintableParam(
|
||||
std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ANY_CAST<T>(data.value);
|
||||
oss << MLPACK_ANY_CAST<T>(data.value);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ std::string GetPrintableParam(
|
||||
util::ParamData& data,
|
||||
const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
|
||||
{
|
||||
const T& t = ANY_CAST<T>(data.value);
|
||||
const T& t = MLPACK_ANY_CAST<T>(data.value);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < t.size(); ++i)
|
||||
|
||||
@@ -83,7 +83,7 @@ class TestOption
|
||||
data.input = input;
|
||||
data.loaded = false;
|
||||
data.cppType = cppName;
|
||||
data.value = ANY(defaultValue);
|
||||
data.value = defaultValue;
|
||||
|
||||
const std::string tname = data.tname;
|
||||
|
||||
|
||||
+2
-2
@@ -111,8 +111,8 @@
|
||||
#include <mlpack/core/kernels/triangular_kernel.hpp>
|
||||
#include <mlpack/core/kernels/cauchy_kernel.hpp>
|
||||
|
||||
// Use OpenMP if compiled with -DHAS_OPENMP.
|
||||
#ifdef HAS_OPENMP
|
||||
// Use OpenMP if available.
|
||||
#ifdef MLPACK_USE_OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Define the files that we need to compile.
|
||||
# Anything not in this list will not be compiled into mlpack.
|
||||
set(SOURCES
|
||||
check_categorical_param.hpp
|
||||
dataset_mapper.hpp
|
||||
dataset_mapper_impl.hpp
|
||||
detect_file_type.hpp
|
||||
|
||||
@@ -48,7 +48,7 @@ void Binarize(const arma::Mat<T>& input,
|
||||
T *outPtr = output.memptr();
|
||||
|
||||
#pragma omp parallel for
|
||||
for (omp_size_t i = 0; i < (omp_size_t) input.n_elem; ++i)
|
||||
for (size_t i = 0; i < (size_t) input.n_elem; ++i)
|
||||
outPtr[i] = inPtr[i] > threshold;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void Binarize(const arma::Mat<T>& input,
|
||||
output = input;
|
||||
|
||||
#pragma omp parallel for
|
||||
for (omp_size_t i = 0; i < (omp_size_t) input.n_cols; ++i)
|
||||
for (size_t i = 0; i < (size_t) input.n_cols; ++i)
|
||||
output(dimension, i) = input(dimension, i) > threshold;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file core/data/check_categorical_param.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* This file provides an implementation of a simple function to check the values
|
||||
* of a categorical parameter. It cannot be defined in util/, since the
|
||||
* DatasetMapper class is not fully defined when that is included..
|
||||
*/
|
||||
#ifndef MLPACK_CORE_DATA_CHECK_CATEGORICAL_PARAM_HPP
|
||||
#define MLPACK_CORE_DATA_CHECK_CATEGORICAL_PARAM_HPP
|
||||
|
||||
#include <mlpack/core/util/params.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace data {
|
||||
|
||||
inline void CheckCategoricalParam(util::Params& params,
|
||||
const std::string& paramName)
|
||||
{
|
||||
typedef typename std::tuple<DatasetInfo, arma::mat> TupleType;
|
||||
arma::mat& matrix = std::get<1>(params.Get<TupleType>(paramName));
|
||||
|
||||
// This comes from Params::CheckInputMatrix().
|
||||
const std::string errMsg1 = "The input '" + paramName + "' has NaN values.";
|
||||
const std::string errMsg2 = "The input '" + paramName + "' has Inf values.";
|
||||
|
||||
if (matrix.has_nan())
|
||||
Log::Fatal << errMsg1 << std::endl;
|
||||
if (matrix.has_inf())
|
||||
Log::Fatal << errMsg2 << std::endl;
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -200,4 +200,7 @@ using DatasetInfo = DatasetMapper<data::IncrementPolicy>;
|
||||
|
||||
#include "dataset_mapper_impl.hpp"
|
||||
|
||||
// Also include utility function.
|
||||
#include "check_categorical_param.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#define MLPACK_CORE_DATA_LOAD_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/core/util/log.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "format.hpp"
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <mlpack/core/util/timers.hpp>
|
||||
|
||||
#include "extension.hpp"
|
||||
#include "detect_file_type.hpp"
|
||||
|
||||
@@ -74,7 +74,7 @@ class StringEncoding
|
||||
* @param tokenizer The tokenizer object.
|
||||
*
|
||||
* The tokenization algorithm has to be an object with two public methods:
|
||||
* 1. operator() which accepts a reference to STRING_VIEW, extracts
|
||||
* 1. operator() which accepts a reference to MLPACK_STRING_VIEW, extracts
|
||||
* the next token from the given view, removes the prefix containing
|
||||
* the extracted token and returns the token;
|
||||
* 2. IsTokenEmpty() that accepts a token and returns true if the given
|
||||
@@ -108,7 +108,7 @@ class StringEncoding
|
||||
* @param tokenizer The tokenizer object.
|
||||
*
|
||||
* The tokenization algorithm has to be an object with two public methods:
|
||||
* 1. operator() which accepts a reference to STRING_VIEW, extracts
|
||||
* 1. operator() which accepts a reference to MLPACK_STRING_VIEW, extracts
|
||||
* the next token from the given view, removes the prefix containing
|
||||
* the extracted token and returns the token;
|
||||
* 2. IsTokenEmpty() that accepts a token and returns true if the given
|
||||
@@ -158,7 +158,7 @@ class StringEncoding
|
||||
* @param policy The policy object.
|
||||
*
|
||||
* The tokenization algorithm has to be an object with two public methods:
|
||||
* 1. operator() which accepts a reference to STRING_VIEW, extracts
|
||||
* 1. operator() which accepts a reference to MLPACK_STRING_VIEW, extracts
|
||||
* the next token from the given view, removes the prefix containing
|
||||
* the extracted token and returns the token;
|
||||
* 2. IsTokenEmpty() that accepts a token and returns true if the given
|
||||
@@ -187,7 +187,7 @@ class StringEncoding
|
||||
* @param policy The policy object.
|
||||
*
|
||||
* The tokenization algorithm has to be an object with two public methods:
|
||||
* 1. operator() which accepts a reference to STRING_VIEW, extracts
|
||||
* 1. operator() which accepts a reference to MLPACK_STRING_VIEW, extracts
|
||||
* the next token from the given view, removes the prefix containing
|
||||
* the extracted token and returns the token;
|
||||
* 2. IsTokenEmpty() that accepts a token and returns true if the given
|
||||
|
||||
@@ -106,20 +106,20 @@ class StringEncodingDictionary
|
||||
};
|
||||
|
||||
/*
|
||||
* Specialization of the StringEncodingDictionary class for STRING_VIEW.
|
||||
* Specialization of the StringEncodingDictionary class for MLPACK_STRING_VIEW.
|
||||
*/
|
||||
template<>
|
||||
class StringEncodingDictionary<STRING_VIEW>
|
||||
class StringEncodingDictionary<MLPACK_STRING_VIEW>
|
||||
{
|
||||
public:
|
||||
//! A convenient alias for the internal type of the map.
|
||||
using MapType = std::unordered_map<
|
||||
STRING_VIEW,
|
||||
MLPACK_STRING_VIEW,
|
||||
size_t,
|
||||
std::hash<STRING_VIEW>>;
|
||||
std::hash<MLPACK_STRING_VIEW>>;
|
||||
|
||||
//! The type of the token that the dictionary stores.
|
||||
using TokenType = STRING_VIEW;
|
||||
using TokenType = MLPACK_STRING_VIEW;
|
||||
|
||||
//! Construct the default class.
|
||||
StringEncodingDictionary() = default;
|
||||
@@ -156,7 +156,7 @@ class StringEncodingDictionary<STRING_VIEW>
|
||||
*
|
||||
* @param token The given token.
|
||||
*/
|
||||
bool HasToken(const STRING_VIEW token) const
|
||||
bool HasToken(const MLPACK_STRING_VIEW token) const
|
||||
{
|
||||
return mapping.find(token) != mapping.end();
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class StringEncodingDictionary<STRING_VIEW>
|
||||
*
|
||||
* @param token The given token.
|
||||
*/
|
||||
size_t AddToken(const STRING_VIEW token)
|
||||
size_t AddToken(const MLPACK_STRING_VIEW token)
|
||||
{
|
||||
tokens.emplace_back(token);
|
||||
|
||||
@@ -185,7 +185,7 @@ class StringEncodingDictionary<STRING_VIEW>
|
||||
*
|
||||
* @param token The given token.
|
||||
*/
|
||||
size_t Value(const STRING_VIEW token) const
|
||||
size_t Value(const MLPACK_STRING_VIEW token) const
|
||||
{
|
||||
return mapping.at(token);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void StringEncoding<EncodingPolicyType, DictionaryType>::CreateMap(
|
||||
const std::string& input,
|
||||
const TokenizerType& tokenizer)
|
||||
{
|
||||
STRING_VIEW strView(input);
|
||||
MLPACK_STRING_VIEW strView(input);
|
||||
auto token = tokenizer(strView);
|
||||
|
||||
static_assert(
|
||||
@@ -112,7 +112,7 @@ EncodeHelper(const std::vector<std::string>& input,
|
||||
// The first pass adds the extracted tokens to the dictionary.
|
||||
for (size_t i = 0; i < input.size(); ++i)
|
||||
{
|
||||
STRING_VIEW strView(input[i]);
|
||||
MLPACK_STRING_VIEW strView(input[i]);
|
||||
auto token = tokenizer(strView);
|
||||
|
||||
static_assert(
|
||||
@@ -143,7 +143,7 @@ EncodeHelper(const std::vector<std::string>& input,
|
||||
// The second pass writes the encoded values to the output.
|
||||
for (size_t i = 0; i < input.size(); ++i)
|
||||
{
|
||||
STRING_VIEW strView(input[i]);
|
||||
MLPACK_STRING_VIEW strView(input[i]);
|
||||
auto token = tokenizer(strView);
|
||||
size_t numTokens = 0;
|
||||
|
||||
@@ -172,7 +172,7 @@ EncodeHelper(const std::vector<std::string>& input,
|
||||
// at once.
|
||||
for (size_t i = 0; i < input.size(); ++i)
|
||||
{
|
||||
STRING_VIEW strView(input[i]);
|
||||
MLPACK_STRING_VIEW strView(input[i]);
|
||||
auto token = tokenizer(strView);
|
||||
|
||||
static_assert(
|
||||
|
||||
@@ -36,7 +36,7 @@ class CharExtract
|
||||
*
|
||||
* @param str String view to retrieve the next token from.
|
||||
*/
|
||||
int operator()(STRING_VIEW& str) const
|
||||
int operator()(MLPACK_STRING_VIEW& str) const
|
||||
{
|
||||
if (str.empty())
|
||||
return EOF;
|
||||
|
||||
@@ -27,7 +27,7 @@ class SplitByAnyOf
|
||||
{
|
||||
public:
|
||||
//! The type of the token which the tokenizer extracts.
|
||||
using TokenType = STRING_VIEW;
|
||||
using TokenType = MLPACK_STRING_VIEW;
|
||||
|
||||
//! A convenient alias for the mask type.
|
||||
using MaskType = std::array<bool, 1 << CHAR_BIT>;
|
||||
@@ -37,7 +37,7 @@ class SplitByAnyOf
|
||||
*
|
||||
* @param delimiters The given delimiters.
|
||||
*/
|
||||
SplitByAnyOf(const STRING_VIEW delimiters)
|
||||
SplitByAnyOf(const MLPACK_STRING_VIEW delimiters)
|
||||
{
|
||||
mask.fill(false);
|
||||
|
||||
@@ -51,13 +51,13 @@ class SplitByAnyOf
|
||||
*
|
||||
* @param str String view to retrieve the token from.
|
||||
*/
|
||||
STRING_VIEW operator()(STRING_VIEW& str) const
|
||||
MLPACK_STRING_VIEW operator()(MLPACK_STRING_VIEW& str) const
|
||||
{
|
||||
STRING_VIEW retval;
|
||||
MLPACK_STRING_VIEW retval;
|
||||
// std::basic_string_view does not have empty function.
|
||||
// Therefore, we are assiging an empty string when reaching the last
|
||||
// delimiter.
|
||||
STRING_VIEW empty_string{""};
|
||||
MLPACK_STRING_VIEW empty_string{""};
|
||||
|
||||
while (retval.empty())
|
||||
{
|
||||
@@ -79,7 +79,7 @@ class SplitByAnyOf
|
||||
*
|
||||
* @param token The given token.
|
||||
*/
|
||||
static bool IsTokenEmpty(const STRING_VIEW token)
|
||||
static bool IsTokenEmpty(const MLPACK_STRING_VIEW token)
|
||||
{
|
||||
return token.empty();
|
||||
}
|
||||
@@ -93,11 +93,11 @@ class SplitByAnyOf
|
||||
/**
|
||||
* The function finds the first character in the given string view equal to
|
||||
* any of the delimiters and returns the position of the character or
|
||||
* STRING_VIEW::npos if no such character is found.
|
||||
* MLPACK_STRING_VIEW::npos if no such character is found.
|
||||
*
|
||||
* @param str String where to find the character.
|
||||
*/
|
||||
size_t FindFirstDelimiter(const STRING_VIEW str) const
|
||||
size_t FindFirstDelimiter(const MLPACK_STRING_VIEW str) const
|
||||
{
|
||||
for (size_t pos = 0; pos < str.size(); pos++)
|
||||
{
|
||||
|
||||
@@ -5,15 +5,16 @@ set(SOURCES
|
||||
arma_config.hpp
|
||||
arma_config_check.hpp
|
||||
backtrace.hpp
|
||||
backtrace.cpp
|
||||
backtrace_impl.hpp
|
||||
binding_details.hpp
|
||||
forward.hpp
|
||||
io.hpp
|
||||
io.cpp
|
||||
io_impl.hpp
|
||||
deprecated.hpp
|
||||
hyphenate_string.hpp
|
||||
is_std_vector.hpp
|
||||
log.hpp
|
||||
log.cpp
|
||||
log_impl.hpp
|
||||
mlpack_main.hpp
|
||||
nulloutstream.hpp
|
||||
param.hpp
|
||||
@@ -22,20 +23,17 @@ set(SOURCES
|
||||
param_data.hpp
|
||||
params.hpp
|
||||
params_impl.hpp
|
||||
params.cpp
|
||||
prefixedoutstream.hpp
|
||||
prefixedoutstream.cpp
|
||||
prefixedoutstream_impl.hpp
|
||||
program_doc.hpp
|
||||
program_doc.cpp
|
||||
program_doc_impl.hpp
|
||||
size_checks.hpp
|
||||
sfinae_utility.hpp
|
||||
singletons.cpp
|
||||
timers.hpp
|
||||
timers.cpp
|
||||
timers_impl.hpp
|
||||
to_lower.hpp
|
||||
version.hpp
|
||||
version.cpp
|
||||
version_impl.hpp
|
||||
)
|
||||
|
||||
# add directory name to sources
|
||||
|
||||
@@ -15,6 +15,37 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
// Some versions of libbfd require PACKAGE and PACKAGE_VERSION to be set in
|
||||
// order for the include to not fail. For more information:
|
||||
// https://github.com/mlpack/mlpack/issues/574
|
||||
#ifndef PACKAGE
|
||||
#define PACKAGE
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION
|
||||
#include <bfd.h>
|
||||
#undef PACKAGE_VERSION
|
||||
#else
|
||||
#include <bfd.h>
|
||||
#endif
|
||||
#undef PACKAGE
|
||||
#else
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION
|
||||
#include <bfd.h>
|
||||
#undef PACKAGE_VERSION
|
||||
#else
|
||||
#include <bfd.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
namespace mlpack {
|
||||
|
||||
/**
|
||||
@@ -71,17 +102,17 @@ class Backtrace
|
||||
*
|
||||
* @param maxDepth Maximum depth of backtrace. Default 32 steps.
|
||||
*/
|
||||
static void GetAddress(int maxDepth);
|
||||
void GetAddress(int maxDepth);
|
||||
|
||||
/**
|
||||
* Decodes file name, function & line number.
|
||||
*
|
||||
* @param address Address of traced frame.
|
||||
*/
|
||||
static void DecodeAddress(long address);
|
||||
void DecodeAddress(long address);
|
||||
|
||||
//! Demangles function name.
|
||||
static void DemangleFunction();
|
||||
void DemangleFunction();
|
||||
|
||||
//! Backtrace datastructure.
|
||||
struct Frames
|
||||
@@ -90,12 +121,22 @@ class Backtrace
|
||||
const char* function;
|
||||
const char* file;
|
||||
unsigned line;
|
||||
} static frame;
|
||||
};
|
||||
|
||||
//! A vector for all the backtrace information.
|
||||
static std::vector<Frames> stack;
|
||||
Frames frame;
|
||||
std::vector<Frames> stack;
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
// Binary File Descriptor objects.
|
||||
bfd* abfd; // Descriptor datastructure.
|
||||
asymbol **syms; // Symbols datastructure.
|
||||
asection *text; // Strings datastructure.
|
||||
#endif
|
||||
};
|
||||
|
||||
}; // namespace mlpack
|
||||
|
||||
// Include implementation.
|
||||
#include "backtrace_impl.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/backtrace.cpp
|
||||
* @file core/util/backtrace_impl.hpp
|
||||
* @author Grzegorz Krajewski
|
||||
*
|
||||
* Implementation of the Backtrace class.
|
||||
@@ -11,74 +11,36 @@
|
||||
*/
|
||||
#include <sstream>
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
// Some versions of libbfd require PACKAGE and PACKAGE_VERSION to be set in
|
||||
// order for the include to not fail. For more information:
|
||||
// https://github.com/mlpack/mlpack/issues/574
|
||||
#ifndef PACKAGE
|
||||
#define PACKAGE
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION
|
||||
#include <bfd.h>
|
||||
#undef PACKAGE_VERSION
|
||||
#else
|
||||
#include <bfd.h>
|
||||
#endif
|
||||
#undef PACKAGE
|
||||
#else
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION
|
||||
#include <bfd.h>
|
||||
#undef PACKAGE_VERSION
|
||||
#else
|
||||
#include <bfd.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#include "backtrace.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
using namespace mlpack;
|
||||
|
||||
// Initialize Backtrace static inctances.
|
||||
Backtrace::Frames Backtrace::frame;
|
||||
std::vector<Backtrace::Frames> Backtrace::stack;
|
||||
namespace mlpack {
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
// Binary File Descriptor objects.
|
||||
bfd* abfd = 0; // Descriptor datastructure.
|
||||
asymbol **syms = 0; // Symbols datastructure.
|
||||
asection *text = 0; // Strings datastructure.
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
Backtrace::Backtrace(int maxDepth)
|
||||
inline Backtrace::Backtrace(int maxDepth)
|
||||
{
|
||||
frame.address = NULL;
|
||||
frame.function = "0";
|
||||
frame.file = "0";
|
||||
frame.line = 0;
|
||||
|
||||
abfd = 0;
|
||||
syms = 0;
|
||||
text = 0;
|
||||
|
||||
stack.clear();
|
||||
|
||||
GetAddress(maxDepth);
|
||||
}
|
||||
#else
|
||||
Backtrace::Backtrace()
|
||||
inline Backtrace::Backtrace()
|
||||
{
|
||||
// Dummy constructor
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
void Backtrace::GetAddress(int maxDepth)
|
||||
inline void Backtrace::GetAddress(int maxDepth)
|
||||
{
|
||||
void* trace[maxDepth];
|
||||
int stackDepth = backtrace(trace, maxDepth);
|
||||
@@ -100,7 +62,7 @@ void Backtrace::GetAddress(int maxDepth)
|
||||
}
|
||||
}
|
||||
|
||||
void Backtrace::DecodeAddress(long addr)
|
||||
inline void Backtrace::DecodeAddress(long addr)
|
||||
{
|
||||
// Check to see if there is anything to descript. If it doesn't, we'll
|
||||
// dump running program.
|
||||
@@ -147,7 +109,7 @@ void Backtrace::DecodeAddress(long addr)
|
||||
}
|
||||
}
|
||||
|
||||
void Backtrace::DemangleFunction()
|
||||
inline void Backtrace::DemangleFunction()
|
||||
{
|
||||
int status;
|
||||
char* tmp = abi::__cxa_demangle(frame.function, 0, 0, &status);
|
||||
@@ -160,12 +122,12 @@ void Backtrace::DemangleFunction()
|
||||
}
|
||||
}
|
||||
#else
|
||||
void Backtrace::GetAddress(int /* maxDepth */) { }
|
||||
void Backtrace::DecodeAddress(long /* address */) { }
|
||||
void Backtrace::DemangleFunction() { }
|
||||
inline void Backtrace::GetAddress(int /* maxDepth */) { }
|
||||
inline void Backtrace::DecodeAddress(long /* address */) { }
|
||||
inline void Backtrace::DemangleFunction() { }
|
||||
#endif
|
||||
|
||||
std::string Backtrace::ToString()
|
||||
inline std::string Backtrace::ToString()
|
||||
{
|
||||
std::string stackStr;
|
||||
|
||||
@@ -198,8 +160,10 @@ std::string Backtrace::ToString()
|
||||
it.str("");
|
||||
}
|
||||
#else
|
||||
stackStr = "[bt]: No backtrace for this OS. Work in progress.";
|
||||
stackStr = "[bt]: No backtrace for this OS.";
|
||||
#endif
|
||||
|
||||
return stackStr;
|
||||
}
|
||||
|
||||
} // namespace mlpack
|
||||
@@ -12,8 +12,7 @@
|
||||
#ifndef MLPACK_CORE_UTIL_BINDING_DETAILS_HPP
|
||||
#define MLPACK_CORE_UTIL_BINDING_DETAILS_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include "program_doc.hpp"
|
||||
#include <mlpack/base.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file core/util/forward.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Forward declaration of components from other subdirectories necessary for
|
||||
* various util implementations.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_UTIL_FORWARD_HPP
|
||||
#define MLPACK_CORE_UTIL_FORWARD_HPP
|
||||
|
||||
#include <mlpack/base.hpp>
|
||||
|
||||
// Required forward declarations.
|
||||
namespace mlpack {
|
||||
|
||||
class IO;
|
||||
|
||||
namespace util {
|
||||
|
||||
class Timers;
|
||||
|
||||
} // namespace util
|
||||
}
|
||||
|
||||
#include "params.hpp"
|
||||
|
||||
namespace mlpack {
|
||||
namespace data {
|
||||
|
||||
class IncrementPolicy;
|
||||
|
||||
template<typename PolicyType, typename InputType>
|
||||
class DatasetMapper;
|
||||
|
||||
using DatasetInfo = DatasetMapper<IncrementPolicy, std::string>;
|
||||
|
||||
// This is a forward declaration of a function that just calls std::get(); but,
|
||||
// we cannot use std::get directly because we have only forward-declared
|
||||
// DatasetInfo.
|
||||
void CheckCategoricalParam(util::Params& p, const std::string& paramName);
|
||||
|
||||
} // namespace data
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
#include "timers.hpp"
|
||||
#include "binding_details.hpp"
|
||||
#include "program_doc.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#include "param_data.hpp"
|
||||
#include "params.hpp"
|
||||
#include "params_impl.hpp"
|
||||
|
||||
#include <mlpack/core/data/load.hpp>
|
||||
#include <mlpack/core/data/save.hpp>
|
||||
@@ -305,4 +305,13 @@ class IO
|
||||
|
||||
} // namespace mlpack
|
||||
|
||||
// This file must be included after IO is declared and fully defined.
|
||||
#include "program_doc.hpp"
|
||||
|
||||
// Include the implementation.
|
||||
#include "io_impl.hpp"
|
||||
|
||||
// Now include the implementation of the timers.
|
||||
#include "timers_impl.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/io.cpp
|
||||
* @file core/util/io_impl.hpp
|
||||
* @author Matthew Amidon
|
||||
*
|
||||
* Implementation of the IO module for parsing parameters.
|
||||
@@ -9,31 +9,33 @@
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_UTIL_IO_IMPL_HPP
|
||||
#define MLPACK_CORE_UTIL_IO_IMPL_HPP
|
||||
|
||||
#include "io.hpp"
|
||||
#include "log.hpp"
|
||||
#include "hyphenate_string.hpp"
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::util;
|
||||
namespace mlpack {
|
||||
|
||||
/* Constructors, Destructors, Copy */
|
||||
/* Make the constructor private, to preclude unauthorized instances */
|
||||
IO::IO()
|
||||
inline IO::IO()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Private copy constructor; don't want copies floating around.
|
||||
IO::IO(const IO& /* other */)
|
||||
inline IO::IO(const IO& /* other */)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Private copy operator; don't want copies floating around.
|
||||
IO& IO::operator=(const IO& /* other */) { return *this; }
|
||||
inline IO& IO::operator=(const IO& /* other */) { return *this; }
|
||||
|
||||
void IO::AddParameter(const std::string& bindingName, ParamData&& data)
|
||||
inline void IO::AddParameter(const std::string& bindingName,
|
||||
util::ParamData&& data)
|
||||
{
|
||||
// Temporarily define color code escape sequences.
|
||||
#ifndef _WIN32
|
||||
@@ -93,9 +95,9 @@ void IO::AddParameter(const std::string& bindingName, ParamData&& data)
|
||||
* @param name Name of the function.
|
||||
* @param func Function to call.
|
||||
*/
|
||||
void IO::AddFunction(const std::string& type,
|
||||
const std::string& name,
|
||||
void (*func)(util::ParamData&, const void*, void*))
|
||||
inline void IO::AddFunction(const std::string& type,
|
||||
const std::string& name,
|
||||
void (*func)(util::ParamData&, const void*, void*))
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(GetSingleton().mapMutex);
|
||||
GetSingleton().functionMap[type][name] = func;
|
||||
@@ -107,7 +109,8 @@ void IO::AddFunction(const std::string& type,
|
||||
* @param bindingName Name of the binding to add the user-friendly name for.
|
||||
* @param name User-friendly name.
|
||||
*/
|
||||
void IO::AddBindingName(const std::string& bindingName, const std::string& name)
|
||||
inline void IO::AddBindingName(const std::string& bindingName,
|
||||
const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(GetSingleton().mapMutex);
|
||||
GetSingleton().docs[bindingName].name = name;
|
||||
@@ -119,8 +122,8 @@ void IO::AddBindingName(const std::string& bindingName, const std::string& name)
|
||||
* @param bindingName Name of the binding to add the description for.
|
||||
* @param shortDescription Description to use.
|
||||
*/
|
||||
void IO::AddShortDescription(const std::string& bindingName,
|
||||
const std::string& shortDescription)
|
||||
inline void IO::AddShortDescription(const std::string& bindingName,
|
||||
const std::string& shortDescription)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(GetSingleton().docMutex);
|
||||
GetSingleton().docs[bindingName].shortDescription = shortDescription;
|
||||
@@ -132,7 +135,7 @@ void IO::AddShortDescription(const std::string& bindingName,
|
||||
* @param bindingName Name of the binding to add the description for.
|
||||
* @param longDescription Function that returns the long description.
|
||||
*/
|
||||
void IO::AddLongDescription(
|
||||
inline void IO::AddLongDescription(
|
||||
const std::string& bindingName,
|
||||
const std::function<std::string()>& longDescription)
|
||||
{
|
||||
@@ -146,8 +149,8 @@ void IO::AddLongDescription(
|
||||
* @param bindingName Name of the binding to add the example for.
|
||||
* @param example Function that returns the example.
|
||||
*/
|
||||
void IO::AddExample(const std::string& bindingName,
|
||||
const std::function<std::string()>& example)
|
||||
inline void IO::AddExample(const std::string& bindingName,
|
||||
const std::function<std::string()>& example)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(GetSingleton().docMutex);
|
||||
GetSingleton().docs[bindingName].example.push_back(std::move(example));
|
||||
@@ -160,9 +163,9 @@ void IO::AddExample(const std::string& bindingName,
|
||||
* @param description Description of the SeeAlso.
|
||||
* @param link Link of the SeeAlso.
|
||||
*/
|
||||
void IO::AddSeeAlso(const std::string& bindingName,
|
||||
const std::string& description,
|
||||
const std::string& link)
|
||||
inline void IO::AddSeeAlso(const std::string& bindingName,
|
||||
const std::string& description,
|
||||
const std::string& link)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(GetSingleton().docMutex);
|
||||
GetSingleton().docs[bindingName].seeAlso.push_back(
|
||||
@@ -170,14 +173,14 @@ void IO::AddSeeAlso(const std::string& bindingName,
|
||||
}
|
||||
|
||||
// Returns the sole instance of this class.
|
||||
IO& IO::GetSingleton()
|
||||
inline IO& IO::GetSingleton()
|
||||
{
|
||||
static IO singleton;
|
||||
return singleton;
|
||||
}
|
||||
|
||||
// Returns the sole instance of the timers.
|
||||
util::Timers& IO::GetTimers()
|
||||
inline util::Timers& IO::GetTimers()
|
||||
{
|
||||
return GetSingleton().timer;
|
||||
}
|
||||
@@ -187,7 +190,7 @@ util::Timers& IO::GetTimers()
|
||||
* binding `bindingName`. This is intended to be called at the beginning of
|
||||
* the run of a binding.
|
||||
*/
|
||||
util::Params IO::Parameters(const std::string& bindingName)
|
||||
inline util::Params IO::Parameters(const std::string& bindingName)
|
||||
{
|
||||
// We don't need a mutex here, because we are only randomly accessing elements
|
||||
// of the maps.
|
||||
@@ -205,6 +208,10 @@ util::Params IO::Parameters(const std::string& bindingName)
|
||||
GetSingleton().parameters[""];
|
||||
resultParams.insert(persistentParams.begin(), persistentParams.end());
|
||||
|
||||
return Params(resultAliases, resultParams, GetSingleton().functionMap,
|
||||
return util::Params(resultAliases, resultParams, GetSingleton().functionMap,
|
||||
bindingName, GetSingleton().docs[bindingName]);
|
||||
}
|
||||
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -53,46 +53,66 @@ namespace mlpack {
|
||||
*
|
||||
* @see PrefixedOutStream, NullOutStream, IO
|
||||
*/
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Checks if the specified condition is true.
|
||||
* If not, halts program execution and prints a custom error message.
|
||||
* Does nothing in non-debug mode.
|
||||
*/
|
||||
static void Assert(bool condition,
|
||||
const std::string& message = "Assert Failed.");
|
||||
namespace Log {
|
||||
|
||||
/**
|
||||
* MLPACK_EXPORT is required for global variables, so that they are properly
|
||||
* exported by the Windows compiler.
|
||||
*/
|
||||
/**
|
||||
* Checks if the specified condition is true.
|
||||
* If not, halts program execution and prints a custom error message.
|
||||
* Does nothing in non-debug mode.
|
||||
*/
|
||||
void Assert(bool condition,
|
||||
const std::string& message = "Assert Failed.");
|
||||
|
||||
// We only use PrefixedOutStream if the program is compiled with debug
|
||||
// symbols.
|
||||
#ifdef DEBUG
|
||||
//! Prints debug output with the appropriate tag: [DEBUG].
|
||||
static MLPACK_EXPORT util::PrefixedOutStream Debug;
|
||||
/**
|
||||
* MLPACK_EXPORT is required for global variables, so that they are properly
|
||||
* exported by the Windows compiler.
|
||||
*/
|
||||
|
||||
// Color code escape sequences -- but not on Windows.
|
||||
#ifndef _WIN32
|
||||
#define BASH_RED "\033[0;31m"
|
||||
#define BASH_GREEN "\033[0;32m"
|
||||
#define BASH_YELLOW "\033[0;33m"
|
||||
#define BASH_CYAN "\033[0;36m"
|
||||
#define BASH_CLEAR "\033[0m"
|
||||
#else
|
||||
//! Dumps debug output into the bit nether regions.
|
||||
static MLPACK_EXPORT util::NullOutStream Debug;
|
||||
#define BASH_RED ""
|
||||
#define BASH_GREEN ""
|
||||
#define BASH_YELLOW ""
|
||||
#define BASH_CYAN ""
|
||||
#define BASH_CLEAR ""
|
||||
#endif
|
||||
|
||||
//! Prints informational messages if --verbose is specified, prefixed with
|
||||
//! [INFO ].
|
||||
static MLPACK_EXPORT util::PrefixedOutStream Info;
|
||||
#ifdef DEBUG
|
||||
static util::PrefixedOutStream Debug =
|
||||
util::PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_CYAN "[DEBUG] " BASH_CLEAR);
|
||||
#else
|
||||
static util::NullOutStream Debug = util::NullOutStream();
|
||||
#endif
|
||||
|
||||
//! Prints warning messages prefixed with [WARN ].
|
||||
static MLPACK_EXPORT util::PrefixedOutStream Warn;
|
||||
static util::PrefixedOutStream Info =
|
||||
util::PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_GREEN "[INFO ] " BASH_CLEAR,
|
||||
true /* unless --verbose */,
|
||||
false);
|
||||
|
||||
//! Prints fatal messages prefixed with [FATAL], then terminates the program.
|
||||
static MLPACK_EXPORT util::PrefixedOutStream Fatal;
|
||||
static util::PrefixedOutStream Warn =
|
||||
util::PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_YELLOW "[WARN ] " BASH_CLEAR,
|
||||
false,
|
||||
false);
|
||||
|
||||
//! Reference to cout, if necessary.
|
||||
static std::ostream& cout;
|
||||
};
|
||||
static util::PrefixedOutStream Fatal =
|
||||
util::PrefixedOutStream(MLPACK_CERR_STREAM,
|
||||
BASH_RED "[FATAL] " BASH_CLEAR,
|
||||
false,
|
||||
true /* fatal */);
|
||||
|
||||
}; // namespace mlpack
|
||||
} // namespace Log
|
||||
} // namespace mlpack
|
||||
|
||||
// Include implementation.
|
||||
#include "log_impl.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/log.cpp
|
||||
* @file core/util/log_impl.hpp
|
||||
* @author Matthew Amidon
|
||||
*
|
||||
* Implementation of the Log class.
|
||||
@@ -9,18 +9,20 @@
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_UTIL_LOG_IMPL_HPP
|
||||
#define MLPACK_CORE_UTIL_LOG_IMPL_HPP
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
#ifdef HAS_BFD_DL
|
||||
#include "backtrace.hpp"
|
||||
#endif
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::util;
|
||||
namespace mlpack {
|
||||
|
||||
// Only do anything for Assert() if in debugging mode.
|
||||
#ifdef DEBUG
|
||||
void Log::Assert(bool condition, const std::string& message)
|
||||
inline void Log::Assert(bool condition, const std::string& message)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
@@ -35,6 +37,10 @@ void Log::Assert(bool condition, const std::string& message)
|
||||
}
|
||||
}
|
||||
#else
|
||||
void Log::Assert(bool /* condition */, const std::string& /* message */)
|
||||
inline void Log::Assert(bool /* condition */, const std::string& /* message */)
|
||||
{ }
|
||||
#endif
|
||||
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -15,19 +15,7 @@
|
||||
#ifndef MLPACK_CORE_UTIL_PARAM_HPP
|
||||
#define MLPACK_CORE_UTIL_PARAM_HPP
|
||||
|
||||
// Required forward declarations.
|
||||
namespace mlpack {
|
||||
namespace data {
|
||||
|
||||
class IncrementPolicy;
|
||||
|
||||
template<typename PolicyType, typename InputType>
|
||||
class DatasetMapper;
|
||||
|
||||
using DatasetInfo = DatasetMapper<IncrementPolicy, std::string>;
|
||||
|
||||
} // namespace data
|
||||
} // namespace mlpack
|
||||
#include "forward.hpp"
|
||||
|
||||
/**
|
||||
* @cond
|
||||
|
||||
@@ -13,26 +13,13 @@
|
||||
#ifndef MLPACK_CORE_UTIL_PARAM_DATA_HPP
|
||||
#define MLPACK_CORE_UTIL_PARAM_DATA_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/base.hpp>
|
||||
|
||||
/**
|
||||
* The TYPENAME macro is used internally to convert a type into a string.
|
||||
*/
|
||||
#define TYPENAME(x) (std::string(typeid(x).name()))
|
||||
|
||||
namespace mlpack {
|
||||
namespace data {
|
||||
|
||||
class IncrementPolicy;
|
||||
|
||||
template<typename PolicyType, typename InputType>
|
||||
class DatasetMapper;
|
||||
|
||||
using DatasetInfo = DatasetMapper<IncrementPolicy, std::string>;
|
||||
|
||||
} // namespace data
|
||||
} // namespace mlpack
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
@@ -75,7 +62,7 @@ struct ParamData
|
||||
bool loaded;
|
||||
//! The actual value that is held. If the user has passed a different type,
|
||||
//! this may be a tuple containing multiple values.
|
||||
ANY value;
|
||||
MLPACK_ANY value;
|
||||
//! The true name of the type, as it would be written in C++.
|
||||
std::string cppType;
|
||||
};
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
/**
|
||||
* @file params.cpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Implementation of functions in the Param class.
|
||||
*/
|
||||
#include "params.hpp"
|
||||
#include <mlpack/core/data/dataset_mapper.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
Params::Params(const std::map<char, std::string>& aliases,
|
||||
const std::map<std::string, ParamData>& parameters,
|
||||
Params::FunctionMapType& functionMap,
|
||||
const std::string& bindingName,
|
||||
const BindingDetails& doc) :
|
||||
// Copy all the given inputs.
|
||||
aliases(aliases),
|
||||
parameters(parameters),
|
||||
functionMap(functionMap),
|
||||
bindingName(bindingName),
|
||||
doc(doc)
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
Params::Params()
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return `true` if the specified parameter was given.
|
||||
*
|
||||
* @param identifier The name of the parameter in question.
|
||||
*/
|
||||
bool Params::Has(const std::string& key) const
|
||||
{
|
||||
std::string usedKey = key;
|
||||
|
||||
if (!parameters.count(key))
|
||||
{
|
||||
// Check any aliases, but only after we are sure the actual option as given
|
||||
// does not exist.
|
||||
// TODO: can we isolate alias support inside of the CLI binding code?
|
||||
if (key.length() == 1 && aliases.count(key[0]))
|
||||
usedKey = aliases.at(key[0]);
|
||||
|
||||
if (!parameters.count(usedKey))
|
||||
{
|
||||
Log::Fatal << "Parameter '" << key << "' does not exist in this "
|
||||
<< "program." << std::endl;
|
||||
}
|
||||
}
|
||||
const std::string& checkKey = usedKey;
|
||||
|
||||
return (parameters.at(checkKey).wasPassed > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two (matrix) parameters, ensure that the first is an in-place copy of
|
||||
* the second. This will generally do nothing (as the bindings already do
|
||||
* this automatically), except for command-line bindings, where we need to
|
||||
* ensure that the output filename is the same as the input filename.
|
||||
*
|
||||
* @param outputParamName Name of output (matrix) parameter.
|
||||
* @param inputParamName Name of input (matrix) parameter.
|
||||
*/
|
||||
void Params::MakeInPlaceCopy(const std::string& outputParamName,
|
||||
const std::string& inputParamName)
|
||||
{
|
||||
if (!parameters.count(outputParamName))
|
||||
Log::Fatal << "Unknown parameter '" << outputParamName << "'!" << std::endl;
|
||||
if (!parameters.count(inputParamName))
|
||||
Log::Fatal << "Unknown parameter '" << inputParamName << "'!" << std::endl;
|
||||
|
||||
ParamData& output = parameters[outputParamName];
|
||||
ParamData& input = parameters[inputParamName];
|
||||
|
||||
if (output.cppType != input.cppType)
|
||||
{
|
||||
Log::Fatal << "Cannot call MakeInPlaceCopy() with different types ("
|
||||
<< output.cppType << " and " << input.cppType << ")!" << std::endl;
|
||||
}
|
||||
|
||||
// Is there a function to do this?
|
||||
if (functionMap[output.tname].count("InPlaceCopy") != 0)
|
||||
{
|
||||
functionMap[output.tname]["InPlaceCopy"](output, (void*) &input, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the particular parameter as passed.
|
||||
*
|
||||
* @param identifier The name of the parameter to set as passed.
|
||||
*/
|
||||
void Params::SetPassed(const std::string& name)
|
||||
{
|
||||
if (parameters.count(name) == 0)
|
||||
{
|
||||
throw std::invalid_argument("Params::SetPassed(): parameter " + name +
|
||||
" not known for binding " + bindingName + "!");
|
||||
}
|
||||
|
||||
// Set passed to true.
|
||||
parameters[name].wasPassed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all input matrices for NaN and inf values, and throw an exception if
|
||||
* any are found.
|
||||
*/
|
||||
void Params::CheckInputMatrices()
|
||||
{
|
||||
typedef typename std::tuple<data::DatasetInfo, arma::mat> TupleType;
|
||||
std::map<std::string, ParamData>::iterator itr;
|
||||
|
||||
for (itr = parameters.begin(); itr != parameters.end(); ++itr)
|
||||
{
|
||||
std::string paramName = itr->first;
|
||||
std::string paramType = itr->second.cppType;
|
||||
if (paramType == "arma::mat")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::mat>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "arma::vec")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::vec>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "arma::rowvec")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::rowvec>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "std::tuple<mlpack::data::DatasetInfo, arma::mat>")
|
||||
{
|
||||
CheckInputMatrix(std::get<1>(Get<TupleType>(paramName)), paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
@@ -7,8 +7,10 @@
|
||||
#ifndef MLPACK_CORE_UTIL_PARAMS_HPP
|
||||
#define MLPACK_CORE_UTIL_PARAMS_HPP
|
||||
|
||||
//#include "forward.hpp"
|
||||
#include "param_data.hpp"
|
||||
#include "binding_details.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
@@ -144,7 +146,6 @@ class Params
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
// Include implementation.
|
||||
#include "params_impl.hpp"
|
||||
// Implementation intentionally not included.
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,11 +9,60 @@
|
||||
#define MLPACK_CORE_UTIL_PARAMS_IMPL_HPP
|
||||
|
||||
// Include definition, if needed.
|
||||
#include "forward.hpp"
|
||||
#include "params.hpp"
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
inline Params::Params(const std::map<char, std::string>& aliases,
|
||||
const std::map<std::string, ParamData>& parameters,
|
||||
Params::FunctionMapType& functionMap,
|
||||
const std::string& bindingName,
|
||||
const BindingDetails& doc) :
|
||||
// Copy all the given inputs.
|
||||
aliases(aliases),
|
||||
parameters(parameters),
|
||||
functionMap(functionMap),
|
||||
bindingName(bindingName),
|
||||
doc(doc)
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
inline Params::Params()
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return `true` if the specified parameter was given.
|
||||
*
|
||||
* @param identifier The name of the parameter in question.
|
||||
*/
|
||||
inline bool Params::Has(const std::string& key) const
|
||||
{
|
||||
std::string usedKey = key;
|
||||
|
||||
if (!parameters.count(key))
|
||||
{
|
||||
// Check any aliases, but only after we are sure the actual option as given
|
||||
// does not exist.
|
||||
// TODO: can we isolate alias support inside of the CLI binding code?
|
||||
if (key.length() == 1 && aliases.count(key[0]))
|
||||
usedKey = aliases.at(key[0]);
|
||||
|
||||
if (!parameters.count(usedKey))
|
||||
{
|
||||
Log::Fatal << "Parameter '" << key << "' does not exist in this "
|
||||
<< "program." << std::endl;
|
||||
}
|
||||
}
|
||||
const std::string& checkKey = usedKey;
|
||||
|
||||
return (parameters.at(checkKey).wasPassed > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of type T found for the parameter specified by `identifier`.
|
||||
* You can set the value using this reference safely.
|
||||
@@ -50,7 +99,7 @@ T& Params::Get(const std::string& identifier)
|
||||
}
|
||||
else
|
||||
{
|
||||
return *ANY_CAST<T>(&d.value);
|
||||
return *MLPACK_ANY_CAST<T>(&d.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +205,89 @@ void Params::CheckInputMatrix(const T& matrix, const std::string& identifier)
|
||||
Log::Fatal << errMsg2 << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two (matrix) parameters, ensure that the first is an in-place copy of
|
||||
* the second. This will generally do nothing (as the bindings already do
|
||||
* this automatically), except for command-line bindings, where we need to
|
||||
* ensure that the output filename is the same as the input filename.
|
||||
*
|
||||
* @param outputParamName Name of output (matrix) parameter.
|
||||
* @param inputParamName Name of input (matrix) parameter.
|
||||
*/
|
||||
inline void Params::MakeInPlaceCopy(const std::string& outputParamName,
|
||||
const std::string& inputParamName)
|
||||
{
|
||||
if (!parameters.count(outputParamName))
|
||||
Log::Fatal << "Unknown parameter '" << outputParamName << "'!" << std::endl;
|
||||
if (!parameters.count(inputParamName))
|
||||
Log::Fatal << "Unknown parameter '" << inputParamName << "'!" << std::endl;
|
||||
|
||||
ParamData& output = parameters[outputParamName];
|
||||
ParamData& input = parameters[inputParamName];
|
||||
|
||||
if (output.cppType != input.cppType)
|
||||
{
|
||||
Log::Fatal << "Cannot call MakeInPlaceCopy() with different types ("
|
||||
<< output.cppType << " and " << input.cppType << ")!" << std::endl;
|
||||
}
|
||||
|
||||
// Is there a function to do this?
|
||||
if (functionMap[output.tname].count("InPlaceCopy") != 0)
|
||||
{
|
||||
functionMap[output.tname]["InPlaceCopy"](output, (void*) &input, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the particular parameter as passed.
|
||||
*
|
||||
* @param identifier The name of the parameter to set as passed.
|
||||
*/
|
||||
inline void Params::SetPassed(const std::string& name)
|
||||
{
|
||||
if (parameters.count(name) == 0)
|
||||
{
|
||||
throw std::invalid_argument("Params::SetPassed(): parameter " + name +
|
||||
" not known for binding " + bindingName + "!");
|
||||
}
|
||||
|
||||
// Set passed to true.
|
||||
parameters[name].wasPassed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all input matrices for NaN and inf values, and throw an exception if
|
||||
* any are found.
|
||||
*/
|
||||
inline void Params::CheckInputMatrices()
|
||||
{
|
||||
std::map<std::string, ParamData>::iterator itr;
|
||||
|
||||
for (itr = parameters.begin(); itr != parameters.end(); ++itr)
|
||||
{
|
||||
std::string paramName = itr->first;
|
||||
std::string paramType = itr->second.cppType;
|
||||
if (paramType == "arma::mat")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::mat>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "arma::vec")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::vec>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "arma::rowvec")
|
||||
{
|
||||
CheckInputMatrix(Get<arma::rowvec>(paramName), paramName);
|
||||
}
|
||||
else if (paramType == "std::tuple<mlpack::data::DatasetInfo, arma::mat>")
|
||||
{
|
||||
// Note that CheckCategoricalParam() is a utility function that must be
|
||||
// defined after DatasetInfo is fully defined.
|
||||
data::CheckCategoricalParam(*this, paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/**
|
||||
* @file core/util/prefixedoutstream.cpp
|
||||
* @author Ryan Curtin
|
||||
* @author Matthew Amidon
|
||||
*
|
||||
* Implementation of PrefixedOutStream methods.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include <mlpack/prereqs.hpp>
|
||||
|
||||
#include "prefixedoutstream.hpp"
|
||||
|
||||
using namespace mlpack::util;
|
||||
|
||||
/**
|
||||
* These are all necessary because gcc's template mechanism does not seem smart
|
||||
* enough to figure out what I want to pass into operator<< without these. That
|
||||
* may not be the actual case, but it works when these is here.
|
||||
*/
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(bool val)
|
||||
{
|
||||
BaseLogic<bool>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(short val)
|
||||
{
|
||||
BaseLogic<short>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(unsigned short val)
|
||||
{
|
||||
BaseLogic<unsigned short>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(int val)
|
||||
{
|
||||
BaseLogic<int>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(unsigned int val)
|
||||
{
|
||||
BaseLogic<unsigned int>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(long val)
|
||||
{
|
||||
BaseLogic<long>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(unsigned long val)
|
||||
{
|
||||
BaseLogic<unsigned long>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(float val)
|
||||
{
|
||||
BaseLogic<float>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(double val)
|
||||
{
|
||||
BaseLogic<double>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(long double val)
|
||||
{
|
||||
BaseLogic<long double>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(void* val)
|
||||
{
|
||||
BaseLogic<void*>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(const char* str)
|
||||
{
|
||||
BaseLogic<const char*>(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(std::string& str)
|
||||
{
|
||||
BaseLogic<std::string>(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(std::streambuf* sb)
|
||||
{
|
||||
BaseLogic<std::streambuf*>(sb);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(
|
||||
std::ostream& (*pf)(std::ostream&))
|
||||
{
|
||||
BaseLogic<std::ostream& (*)(std::ostream&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(std::ios& (*pf)(std::ios&))
|
||||
{
|
||||
BaseLogic<std::ios& (*)(std::ios&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PrefixedOutStream& PrefixedOutStream::operator<<(
|
||||
std::ios_base& (*pf) (std::ios_base&))
|
||||
{
|
||||
BaseLogic<std::ios_base& (*)(std::ios_base&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
|
||||
#define MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/base.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
@@ -33,6 +33,116 @@ PrefixedOutStream& PrefixedOutStream::operator<<(const T& s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* These are all necessary because gcc's template mechanism does not seem smart
|
||||
* enough to figure out what I want to pass into operator<< without these. That
|
||||
* may not be the actual case, but it works when these is here.
|
||||
*/
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(bool val)
|
||||
{
|
||||
BaseLogic<bool>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(short val)
|
||||
{
|
||||
BaseLogic<short>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(unsigned short val)
|
||||
{
|
||||
BaseLogic<unsigned short>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(int val)
|
||||
{
|
||||
BaseLogic<int>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(unsigned int val)
|
||||
{
|
||||
BaseLogic<unsigned int>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(long val)
|
||||
{
|
||||
BaseLogic<long>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(unsigned long val)
|
||||
{
|
||||
BaseLogic<unsigned long>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(float val)
|
||||
{
|
||||
BaseLogic<float>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(double val)
|
||||
{
|
||||
BaseLogic<double>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(long double val)
|
||||
{
|
||||
BaseLogic<long double>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(void* val)
|
||||
{
|
||||
BaseLogic<void*>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(const char* str)
|
||||
{
|
||||
BaseLogic<const char*>(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(std::string& str)
|
||||
{
|
||||
BaseLogic<std::string>(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(std::streambuf* sb)
|
||||
{
|
||||
BaseLogic<std::streambuf*>(sb);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(
|
||||
std::ostream& (*pf)(std::ostream&))
|
||||
{
|
||||
BaseLogic<std::ostream& (*)(std::ostream&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(std::ios& (*pf)(std::ios&))
|
||||
{
|
||||
BaseLogic<std::ios& (*)(std::ios&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PrefixedOutStream& PrefixedOutStream::operator<<(
|
||||
std::ios_base& (*pf) (std::ios_base&))
|
||||
{
|
||||
BaseLogic<std::ios_base& (*)(std::ios_base&)>(pf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// For non-Armadillo types.
|
||||
template<typename T>
|
||||
typename std::enable_if<!arma::is_arma_type<T>::value>::type
|
||||
|
||||
@@ -97,4 +97,7 @@ class SeeAlso
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
// Include implementation.
|
||||
#include "program_doc_impl.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/program_doc.cpp
|
||||
* @file core/util/program_doc_impl.hpp
|
||||
* @author Yashwant Singh Parihar
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
@@ -11,14 +11,14 @@
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_CORE_UTIL_PROGRAM_DOC_IMPL_HPP
|
||||
#define MLPACK_CORE_UTIL_PROGRAM_DOC_IMPL_HPP
|
||||
|
||||
#include "io.hpp"
|
||||
#include "program_doc.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::util;
|
||||
using namespace std;
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* Construct a BindingName object. When constructed, it will register itself
|
||||
@@ -28,8 +28,8 @@ using namespace std;
|
||||
* @param bindingName Name of the binding.
|
||||
* @param name Name displayed to user of the binding.
|
||||
*/
|
||||
BindingName::BindingName(const std::string& bindingName,
|
||||
const std::string& name)
|
||||
inline BindingName::BindingName(const std::string& bindingName,
|
||||
const std::string& name)
|
||||
{
|
||||
// Register this with IO.
|
||||
IO::AddBindingName(bindingName, name);
|
||||
@@ -44,8 +44,8 @@ BindingName::BindingName(const std::string& bindingName,
|
||||
* @param shortDescription A short two-sentence description of the binding,
|
||||
* what it does, and what it is useful for.
|
||||
*/
|
||||
ShortDescription::ShortDescription(const std::string& bindingName,
|
||||
const std::string& shortDescription)
|
||||
inline ShortDescription::ShortDescription(const std::string& bindingName,
|
||||
const std::string& shortDescription)
|
||||
{
|
||||
// Register this with IO.
|
||||
IO::AddShortDescription(bindingName, shortDescription);
|
||||
@@ -61,7 +61,7 @@ ShortDescription::ShortDescription(const std::string& bindingName,
|
||||
* what it is. No newline characters are necessary; this is
|
||||
* taken care of by IO later.
|
||||
*/
|
||||
LongDescription::LongDescription(
|
||||
inline LongDescription::LongDescription(
|
||||
const std::string& bindingName,
|
||||
const std::function<std::string()>& longDescription)
|
||||
{
|
||||
@@ -76,8 +76,8 @@ LongDescription::LongDescription(
|
||||
* @param bindingName Name of the binding.
|
||||
* @param example Documentation on how to use the binding.
|
||||
*/
|
||||
Example::Example(const std::string& bindingName,
|
||||
const std::function<std::string()>& example)
|
||||
inline Example::Example(const std::string& bindingName,
|
||||
const std::function<std::string()>& example)
|
||||
{
|
||||
// Register this with IO.
|
||||
IO::AddExample(bindingName, example);
|
||||
@@ -91,10 +91,15 @@ Example::Example(const std::string& bindingName,
|
||||
* @param description Description of SeeAlso.
|
||||
* @param link Link of SeeAlso.
|
||||
*/
|
||||
SeeAlso::SeeAlso(const std::string& bindingName,
|
||||
const std::string& description,
|
||||
const std::string& link)
|
||||
inline SeeAlso::SeeAlso(const std::string& bindingName,
|
||||
const std::string& description,
|
||||
const std::string& link)
|
||||
{
|
||||
// Register this with IO.
|
||||
IO::AddSeeAlso(bindingName, description, link);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* @file core/util/singletons.cpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Declaration of singletons in libmlpack.so.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "io.hpp"
|
||||
#include "log.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::util;
|
||||
|
||||
// Color code escape sequences -- but not on Windows.
|
||||
#ifndef _WIN32
|
||||
#define BASH_RED "\033[0;31m"
|
||||
#define BASH_GREEN "\033[0;32m"
|
||||
#define BASH_YELLOW "\033[0;33m"
|
||||
#define BASH_CYAN "\033[0;36m"
|
||||
#define BASH_CLEAR "\033[0m"
|
||||
#else
|
||||
#define BASH_RED ""
|
||||
#define BASH_GREEN ""
|
||||
#define BASH_YELLOW ""
|
||||
#define BASH_CYAN ""
|
||||
#define BASH_CLEAR ""
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
PrefixedOutStream Log::Debug = PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_CYAN "[DEBUG] " BASH_CLEAR);
|
||||
#else
|
||||
NullOutStream Log::Debug = NullOutStream();
|
||||
#endif
|
||||
|
||||
PrefixedOutStream Log::Info = PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_GREEN "[INFO ] " BASH_CLEAR, true /* unless --verbose */, false);
|
||||
PrefixedOutStream Log::Warn = PrefixedOutStream(MLPACK_COUT_STREAM,
|
||||
BASH_YELLOW "[WARN ] " BASH_CLEAR, false, false);
|
||||
PrefixedOutStream Log::Fatal = PrefixedOutStream(MLPACK_CERR_STREAM,
|
||||
BASH_RED "[FATAL] " BASH_CLEAR, false, true /* fatal */);
|
||||
@@ -182,4 +182,7 @@ class Timers
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
// Note that the implementation is not included, to avoid include ordering
|
||||
// issues!
|
||||
|
||||
#endif // MLPACK_CORE_UTILITIES_TIMERS_HPP
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/timers.cpp
|
||||
* @file core/util/timers_impl.hpp
|
||||
* @author Matthew Amidon
|
||||
* @author Marcus Edel
|
||||
* @author Ryan Curtin
|
||||
@@ -12,106 +12,112 @@
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "timers.hpp"
|
||||
|
||||
#include "forward.hpp"
|
||||
#include "io.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::util;
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
namespace mlpack {
|
||||
|
||||
/**
|
||||
* Start the given timer.
|
||||
*/
|
||||
void Timer::Start(const string& name)
|
||||
inline void Timer::Start(const std::string& name)
|
||||
{
|
||||
IO::GetSingleton().timer.Start(name, this_thread::get_id());
|
||||
IO::GetSingleton().timer.Start(name, std::this_thread::get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the given timer.
|
||||
*/
|
||||
void Timer::Stop(const string& name)
|
||||
inline void Timer::Stop(const std::string& name)
|
||||
{
|
||||
IO::GetSingleton().timer.Stop(name, this_thread::get_id());
|
||||
IO::GetSingleton().timer.Stop(name, std::this_thread::get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given timer, summing over all threads.
|
||||
*/
|
||||
microseconds Timer::Get(const string& name)
|
||||
inline std::chrono::microseconds Timer::Get(const std::string& name)
|
||||
{
|
||||
return IO::GetSingleton().timer.Get(name);
|
||||
}
|
||||
|
||||
// Enable timing.
|
||||
void Timer::EnableTiming()
|
||||
inline void Timer::EnableTiming()
|
||||
{
|
||||
IO::GetSingleton().timer.Enabled() = true;
|
||||
}
|
||||
|
||||
// Disable timing.
|
||||
void Timer::DisableTiming()
|
||||
inline void Timer::DisableTiming()
|
||||
{
|
||||
IO::GetSingleton().timer.Enabled() = false;
|
||||
}
|
||||
|
||||
// Reset all timers. Save state of enabled.
|
||||
void Timer::ResetAll()
|
||||
inline void Timer::ResetAll()
|
||||
{
|
||||
IO::GetSingleton().timer.Reset();
|
||||
}
|
||||
|
||||
std::map<std::string, std::chrono::microseconds> Timer::GetAllTimers()
|
||||
inline std::map<std::string, std::chrono::microseconds> Timer::GetAllTimers()
|
||||
{
|
||||
return IO::GetSingleton().timer.GetAllTimers();
|
||||
}
|
||||
|
||||
namespace util {
|
||||
|
||||
// Reset a Timers object.
|
||||
void Timers::Reset()
|
||||
inline void Timers::Reset()
|
||||
{
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
timers.clear();
|
||||
timerStartTime.clear();
|
||||
}
|
||||
|
||||
map<string, microseconds> Timers::GetAllTimers()
|
||||
inline std::map<std::string, std::chrono::microseconds> Timers::GetAllTimers()
|
||||
{
|
||||
// Make a copy of the timer.
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
return timers;
|
||||
}
|
||||
|
||||
microseconds Timers::Get(const string& timerName)
|
||||
inline std::chrono::microseconds Timers::Get(const std::string& timerName)
|
||||
{
|
||||
if (!enabled)
|
||||
return microseconds(0);
|
||||
return std::chrono::microseconds(0);
|
||||
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
return timers[timerName];
|
||||
}
|
||||
|
||||
std::string Timers::Print(const microseconds& totalDuration)
|
||||
inline std::string Timers::Print(const std::chrono::microseconds& totalDuration)
|
||||
{
|
||||
// Convert microseconds to seconds.
|
||||
seconds totalDurationSec = duration_cast<seconds>(totalDuration);
|
||||
microseconds totalDurationMicroSec =
|
||||
duration_cast<microseconds>(totalDuration % seconds(1));
|
||||
std::chrono::seconds totalDurationSec =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(totalDuration);
|
||||
std::chrono::microseconds totalDurationMicroSec =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
totalDuration % std::chrono::seconds(1));
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << totalDurationSec.count() << "." << setw(6)
|
||||
<< setfill('0') << totalDurationMicroSec.count() << "s";
|
||||
oss << totalDurationSec.count() << "." << std::setw(6)
|
||||
<< std::setfill('0') << totalDurationMicroSec.count() << "s";
|
||||
|
||||
// Also output convenient day/hr/min/sec.
|
||||
// The following line is a custom duration for a day.
|
||||
typedef duration<int, ratio<60 * 60 * 24, 1>> days;
|
||||
days d = duration_cast<days>(totalDuration);
|
||||
hours h = duration_cast<hours>(totalDuration % days(1));
|
||||
minutes m = duration_cast<minutes>(totalDuration % hours(1));
|
||||
seconds s = duration_cast<seconds>(totalDuration % minutes(1));
|
||||
typedef std::chrono::duration<int, std::ratio<60 * 60 * 24, 1>> days;
|
||||
days d = std::chrono::duration_cast<days>(totalDuration);
|
||||
std::chrono::hours h = std::chrono::duration_cast<std::chrono::hours>(
|
||||
totalDuration % days(1));
|
||||
std::chrono::minutes m = std::chrono::duration_cast<std::chrono::minutes>(
|
||||
totalDuration % std::chrono::hours(1));
|
||||
std::chrono::seconds s = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
totalDuration % std::chrono::minutes(1));
|
||||
// No output if it didn't even take a minute.
|
||||
if (!(d.count() == 0 && h.count() == 0 && m.count() == 0))
|
||||
{
|
||||
@@ -145,87 +151,99 @@ std::string Timers::Print(const microseconds& totalDuration)
|
||||
{
|
||||
if (output)
|
||||
oss << ", ";
|
||||
oss << s.count() << "." << setw(1)
|
||||
oss << s.count() << "." << std::setw(1)
|
||||
<< (totalDurationMicroSec.count() / 100000) << " secs";
|
||||
}
|
||||
|
||||
oss << ")";
|
||||
}
|
||||
|
||||
oss << endl;
|
||||
oss << std::endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void Timers::StopAllTimers()
|
||||
inline void Timers::StopAllTimers()
|
||||
{
|
||||
// Terminate the program timers. Don't use StopTimer() since that modifies
|
||||
// the map and would invalidate our iterators.
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
|
||||
high_resolution_clock::time_point currTime = high_resolution_clock::now();
|
||||
std::chrono::high_resolution_clock::time_point currTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
for (auto it : timerStartTime)
|
||||
{
|
||||
for (auto it2 : it.second)
|
||||
timers[it2.first] += duration_cast<microseconds>(currTime - it2.second);
|
||||
{
|
||||
timers[it2.first] +=
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
currTime - it2.second);
|
||||
}
|
||||
}
|
||||
|
||||
// If all timers are stopped, we can clear the maps.
|
||||
timerStartTime.clear();
|
||||
}
|
||||
|
||||
void Timers::Start(const string& timerName,
|
||||
const thread::id& threadId)
|
||||
inline void Timers::Start(const std::string& timerName,
|
||||
const std::thread::id& threadId)
|
||||
{
|
||||
// Don't do anything if we aren't timing.
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
|
||||
if ((timerStartTime.count(threadId) > 0) &&
|
||||
(timerStartTime[threadId].count(timerName)))
|
||||
{
|
||||
ostringstream error;
|
||||
std::ostringstream error;
|
||||
error << "Timer::Start(): timer '" << timerName
|
||||
<< "' has already been started";
|
||||
throw runtime_error(error.str());
|
||||
throw std::runtime_error(error.str());
|
||||
}
|
||||
|
||||
high_resolution_clock::time_point currTime = high_resolution_clock::now();
|
||||
std::chrono::high_resolution_clock::time_point currTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
|
||||
// If the timer is added for the first time.
|
||||
if (timers.count(timerName) == 0)
|
||||
{
|
||||
timers[timerName] = (microseconds) 0;
|
||||
timers[timerName] = (std::chrono::microseconds) 0;
|
||||
}
|
||||
|
||||
timerStartTime[threadId][timerName] = currTime;
|
||||
}
|
||||
|
||||
void Timers::Stop(const string& timerName,
|
||||
const thread::id& threadId)
|
||||
inline void Timers::Stop(const std::string& timerName,
|
||||
const std::thread::id& threadId)
|
||||
{
|
||||
// Don't do anything if we aren't timing.
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
lock_guard<mutex> lock(timersMutex);
|
||||
std::lock_guard<std::mutex> lock(timersMutex);
|
||||
|
||||
if ((timerStartTime.count(threadId) == 0) ||
|
||||
(timerStartTime[threadId].count(timerName) == 0))
|
||||
{
|
||||
ostringstream error;
|
||||
std::ostringstream error;
|
||||
error << "Timer::Stop(): no timer with name '" << timerName
|
||||
<< "' currently running";
|
||||
throw runtime_error(error.str());
|
||||
throw std::runtime_error(error.str());
|
||||
}
|
||||
|
||||
high_resolution_clock::time_point currTime = high_resolution_clock::now();
|
||||
std::chrono::high_resolution_clock::time_point currTime =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Calculate the delta time.
|
||||
timers[timerName] += duration_cast<microseconds>(currTime -
|
||||
timerStartTime[threadId][timerName]);
|
||||
timers[timerName] += std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
currTime - timerStartTime[threadId][timerName]);
|
||||
|
||||
// Remove the entries.
|
||||
timerStartTime[threadId].erase(timerName);
|
||||
if (timerStartTime[threadId].empty())
|
||||
timerStartTime.erase(threadId);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
@@ -28,9 +28,12 @@ namespace util {
|
||||
* This will return either "mlpack x.y.z" or "mlpack master-XXXXXXX" depending on
|
||||
* whether or not this is a stable version of mlpack or a git repository.
|
||||
*/
|
||||
std::string GetVersion();
|
||||
inline std::string GetVersion();
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
|
||||
// Include implementation.
|
||||
#include "version_impl.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file core/util/version.cpp
|
||||
* @file core/util/version_impl.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* The implementation of GetVersion().
|
||||
@@ -13,9 +13,12 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace mlpack {
|
||||
namespace util {
|
||||
|
||||
// If we are not a git revision, just use the macros to assemble the version
|
||||
// name.
|
||||
std::string mlpack::util::GetVersion()
|
||||
inline std::string GetVersion()
|
||||
{
|
||||
#ifndef MLPACK_GIT_VERSION
|
||||
std::stringstream o;
|
||||
@@ -28,3 +31,6 @@ std::string mlpack::util::GetVersion()
|
||||
#include "gitversion.hpp"
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mlpack
|
||||
@@ -16,8 +16,6 @@
|
||||
#define MLPACK_METHODS_BAYESIAN_LINEAR_REGRESSION_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
#include <mlpack/core/util/log.hpp>
|
||||
#include <mlpack/core/util/timers.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace regression {
|
||||
|
||||
@@ -288,7 +288,7 @@ inline double ParallelSGD<ExponentialBackoff>::Optimize(
|
||||
overallObjective = 0;
|
||||
|
||||
#pragma omp parallel for reduction(+:overallObjective)
|
||||
for (omp_size_t j = 0; j < (omp_size_t) function.NumFunctions(); ++j)
|
||||
for (size_t j = 0; j < (size_t) function.NumFunctions(); ++j)
|
||||
{
|
||||
overallObjective += function.Evaluate(iterate, j);
|
||||
}
|
||||
@@ -324,7 +324,7 @@ inline double ParallelSGD<ExponentialBackoff>::Optimize(
|
||||
// Each processor gets a subset of the instances.
|
||||
// Each subset is of size threadShareSize.
|
||||
size_t threadId = 0;
|
||||
#ifdef HAS_OPENMP
|
||||
#ifdef MLPACK_USE_OPENMP
|
||||
threadId = omp_get_thread_num();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -181,12 +181,9 @@ DTree<MatType, TagType>* Trainer(MatType& dataset,
|
||||
regularizationConstants.fill(0.0);
|
||||
|
||||
timers.Start("cross_validation");
|
||||
// Go through each fold. On the Visual Studio compiler, we have to use
|
||||
// intmax_t because size_t is not yet supported by their OpenMP
|
||||
// implementation. omp_size_t is the appropriate type according to the
|
||||
// platform.
|
||||
// Go through each fold.
|
||||
#pragma omp parallel for shared(prunedSequence, regularizationConstants)
|
||||
for (omp_size_t fold = 0; fold < (omp_size_t) folds; fold++)
|
||||
for (size_t fold = 0; fold < (size_t) folds; fold++)
|
||||
{
|
||||
// Break up data into train and test sets.
|
||||
const size_t start = fold * testSize;
|
||||
|
||||
@@ -37,7 +37,7 @@ DTBRules(const arma::mat& dataSet,
|
||||
}
|
||||
|
||||
template<typename MetricType, typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double DTBRules<MetricType, TreeType>::BaseCase(const size_t queryIndex,
|
||||
const size_t referenceIndex)
|
||||
{
|
||||
|
||||
@@ -82,7 +82,7 @@ void FastMKSRules<KernelType, TreeType>::GetResults(
|
||||
}
|
||||
|
||||
template<typename KernelType, typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double FastMKSRules<KernelType, TreeType>::BaseCase(
|
||||
const size_t queryIndex,
|
||||
const size_t referenceIndex)
|
||||
|
||||
@@ -66,7 +66,7 @@ KDERules<MetricType, KernelType, TreeType>::KDERules(
|
||||
|
||||
//! The base case.
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double KDERules<MetricType, KernelType, TreeType>::BaseCase(
|
||||
const size_t queryIndex,
|
||||
const size_t referenceIndex)
|
||||
@@ -292,7 +292,7 @@ Score(const size_t queryIndex, TreeType& referenceNode)
|
||||
}
|
||||
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
inline mlpack_force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
Rescore(const size_t /* queryIndex */,
|
||||
TreeType& /* referenceNode */,
|
||||
const double oldScore) const
|
||||
@@ -515,7 +515,7 @@ Score(TreeType& queryNode, TreeType& referenceNode)
|
||||
|
||||
//! Dual-tree rescore.
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
inline mlpack_force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
Rescore(TreeType& /*queryNode*/,
|
||||
TreeType& /*referenceNode*/,
|
||||
const double oldScore) const
|
||||
@@ -525,7 +525,7 @@ Rescore(TreeType& /*queryNode*/,
|
||||
}
|
||||
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
inline mlpack_force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
EvaluateKernel(const size_t queryIndex,
|
||||
const size_t referenceIndex) const
|
||||
{
|
||||
@@ -534,14 +534,14 @@ EvaluateKernel(const size_t queryIndex,
|
||||
}
|
||||
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
inline mlpack_force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
EvaluateKernel(const arma::vec& query, const arma::vec& reference) const
|
||||
{
|
||||
return kernel.Evaluate(metric.Evaluate(query, reference));
|
||||
}
|
||||
|
||||
template<typename MetricType, typename KernelType, typename TreeType>
|
||||
inline force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
inline mlpack_force_inline double KDERules<MetricType, KernelType, TreeType>::
|
||||
CalculateAlpha(TreeType* node)
|
||||
{
|
||||
KDEStat& stat = node->Stat();
|
||||
@@ -571,7 +571,7 @@ CalculateAlpha(TreeType* node)
|
||||
|
||||
//! Clean rules base case.
|
||||
template<typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double KDECleanRules<TreeType>::BaseCase(const size_t /* queryIndex */,
|
||||
const size_t /* refIndex */)
|
||||
{
|
||||
@@ -580,7 +580,7 @@ double KDECleanRules<TreeType>::BaseCase(const size_t /* queryIndex */,
|
||||
|
||||
//! Clean rules single-tree score.
|
||||
template<typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double KDECleanRules<TreeType>::Score(const size_t /* queryIndex */,
|
||||
TreeType& referenceNode)
|
||||
{
|
||||
@@ -591,7 +591,7 @@ double KDECleanRules<TreeType>::Score(const size_t /* queryIndex */,
|
||||
|
||||
//! Clean rules double-tree score.
|
||||
template<typename TreeType>
|
||||
inline force_inline
|
||||
inline mlpack_force_inline
|
||||
double KDECleanRules<TreeType>::Score(TreeType& queryNode,
|
||||
TreeType& referenceNode)
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ class AllowEmptyClusters
|
||||
* @return Number of points changed (0).
|
||||
*/
|
||||
template<typename MetricType, typename MatType>
|
||||
static inline force_inline void EmptyCluster(
|
||||
static inline mlpack_force_inline void EmptyCluster(
|
||||
const MatType& /* data */,
|
||||
const size_t emptyCluster,
|
||||
const arma::mat& oldCentroids,
|
||||
|
||||
@@ -51,7 +51,8 @@ DualTreeKMeansRules<MetricType, TreeType>::DualTreeKMeansRules(
|
||||
}
|
||||
|
||||
template<typename MetricType, typename TreeType>
|
||||
inline force_inline double DualTreeKMeansRules<MetricType, TreeType>::BaseCase(
|
||||
inline mlpack_force_inline
|
||||
double DualTreeKMeansRules<MetricType, TreeType>::BaseCase(
|
||||
const size_t queryIndex,
|
||||
const size_t referenceIndex)
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ class KillEmptyClusters
|
||||
* @return Number of points changed (0).
|
||||
*/
|
||||
template<typename MetricType, typename MatType>
|
||||
static inline force_inline void EmptyCluster(
|
||||
static inline mlpack_force_inline void EmptyCluster(
|
||||
const MatType& /* data */,
|
||||
const size_t emptyCluster,
|
||||
const arma::mat& /* oldCentroids */,
|
||||
|
||||
@@ -306,7 +306,7 @@ Cluster(const MatType& data,
|
||||
assignments.set_size(data.n_cols);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (omp_size_t i = 0; i < (omp_size_t) data.n_cols; ++i)
|
||||
for (size_t i = 0; i < (size_t) data.n_cols; ++i)
|
||||
{
|
||||
// Find the closest centroid to this point.
|
||||
double minDistance = std::numeric_limits<double>::infinity();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user