From 0e1c50bb3d01a67fe517d4d63842f2e4014f33ac Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Mon, 12 Feb 2024 13:38:56 +0100 Subject: [PATCH] Adding the Accu Signed-off-by: Omar Shrit --- src/mlpack/core.hpp | 1 + src/mlpack/core/util/accu.hpp | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/mlpack/core/util/accu.hpp diff --git a/src/mlpack/core.hpp b/src/mlpack/core.hpp index 04550aa925..b79988cd1c 100644 --- a/src/mlpack/core.hpp +++ b/src/mlpack/core.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/src/mlpack/core/util/accu.hpp b/src/mlpack/core/util/accu.hpp new file mode 100644 index 0000000000..5989a97f9d --- /dev/null +++ b/src/mlpack/core/util/accu.hpp @@ -0,0 +1,51 @@ +/** + * @file core/util/accu.hpp + * @author Omar Shrit + * + * A simple `Accu` wrapper that based on the data type forwards to + * `coot::accu` or `arma::accu`. + * + * 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_ACCU_HPP +#define MLPACK_CORE_UTIL_ACCU_HPP + +namespace mlpack { + + +#ifdef MLPACK_HAS_COOT + + /** + * Compute the sum of all the elements in InputType + * + * @param input The input type to be a bandicoot vector, matrix or cube. + */ + template + typename InputType::elem_type Accu(const InputType& input, + const typename std::enable_if_t< + coot::is_coot_type::value>* = 0) + { + return coot::accu(input); + } + +#endif + + /** + * Compute the sum of all the elements in InputType + * + * @param input The input type to be an armadillo vector, matrix or cube. + */ + template + typename InputType::elem_type Accu(const InputType& input, + const typename std::enable_if_t< + arma::is_arma_type::value>* = 0) + { + return arma::accu(input); + } + +} // namespace mlpack + +#endif