diff --git a/src/mlpack/core.hpp b/src/mlpack/core.hpp index 80e1e9b9b7..04550aa925 100644 --- a/src/mlpack/core.hpp +++ b/src/mlpack/core.hpp @@ -37,6 +37,7 @@ // Now the core mlpack classes. #include #include +#include #include #include #include diff --git a/src/mlpack/core/util/conv_to.hpp b/src/mlpack/core/util/conv_to.hpp new file mode 100644 index 0000000000..ab560f7309 --- /dev/null +++ b/src/mlpack/core/util/conv_to.hpp @@ -0,0 +1,62 @@ +/** + * @file core/util/conv_to.hpp + * @author Marcus Edel + * + * A simple `conv_to` wrapper that based on the data type forwards to + * `coot::conv_to` or `arma::conv_to`. This file is borrowed from ensmallen. + * + * 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_CORE_UTIL_CONV_TO_HPP +#define MLPACK_CORE_UTIL_CONV_TO_HPP + +namespace mlpack { + +/** + * A utility class that based on the data type forwards to `coot::conv_to` or + * `arma::conv_to`. + * + * @tparam OutputType The data type to convert to. + */ +template +class conv_to +{ + public: + +#ifdef MLPACK_HAS_COOT + + /** + * Convert from one matrix type to another by forwarding to `coot::conv_to`. + * + * @param input The input that is converted. + */ + template + inline static typename std::enable_if< + !arma::is_arma_type::value, OutputType>::type + from(const InputType& input) + { + return coot::conv_to::from(input); + } + +#endif + + /** + * Convert from one matrix type to another by forwarding to `arma::conv_to`. + * + * @param input The input that is converted. + */ + template + inline static typename std::enable_if< + arma::is_arma_type::value, OutputType>::type + from(const InputType& input) + { + return arma::conv_to::from(input); + } +}; + +} // namespace mlpack + +#endif