From 946cd1e7999bf704df02412bc44043cc02179918 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Wed, 5 Oct 2022 16:23:05 -0400 Subject: [PATCH 1/2] as_scalar() is not always applicable. --- src/mlpack/methods/ann/layer/max_pooling.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mlpack/methods/ann/layer/max_pooling.hpp b/src/mlpack/methods/ann/layer/max_pooling.hpp index 232f3f0a5c..7493092e98 100644 --- a/src/mlpack/methods/ann/layer/max_pooling.hpp +++ b/src/mlpack/methods/ann/layer/max_pooling.hpp @@ -42,9 +42,8 @@ class MaxPoolingRule std::tuple PoolingWithIndex( const MatType& input) { - const typename MatType::elem_type maxVal = - arma::max(arma::vectorise(input)); - const size_t index = arma::as_scalar(arma::find(input == maxVal, 1)); + const size_t index = arma::index_max(arma::vectorise(input)); + const typename MatType::elem_type maxVal = input[index]; return std::tuple(index, maxVal); } From a4dab0e427b3cefcef77d33023802d430a70ee81 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Fri, 7 Oct 2022 17:17:22 -0400 Subject: [PATCH 2/2] Use simpler solution. --- src/mlpack/methods/ann/layer/max_pooling.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/ann/layer/max_pooling.hpp b/src/mlpack/methods/ann/layer/max_pooling.hpp index 7493092e98..14817cf875 100644 --- a/src/mlpack/methods/ann/layer/max_pooling.hpp +++ b/src/mlpack/methods/ann/layer/max_pooling.hpp @@ -42,7 +42,7 @@ class MaxPoolingRule std::tuple PoolingWithIndex( const MatType& input) { - const size_t index = arma::index_max(arma::vectorise(input)); + const size_t index = input.index_max(); const typename MatType::elem_type maxVal = input[index]; return std::tuple(index, maxVal);