From 5d312b07c1680baea0190bcc146ce48df2a5844f Mon Sep 17 00:00:00 2001 From: conrad Date: Sat, 18 Oct 2025 14:10:01 +1000 Subject: [PATCH] add subview_row overload --- include/armadillo_bits/op_accu_bones.hpp | 3 + include/armadillo_bits/op_accu_meat.hpp | 71 +++++++++++++++--------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/include/armadillo_bits/op_accu_bones.hpp b/include/armadillo_bits/op_accu_bones.hpp index ad99826b..6cbd860f 100644 --- a/include/armadillo_bits/op_accu_bones.hpp +++ b/include/armadillo_bits/op_accu_bones.hpp @@ -65,6 +65,9 @@ struct op_accu_mat template static inline eT apply(const subview_col& X); + + template + static inline eT apply(const subview_row& X); }; diff --git a/include/armadillo_bits/op_accu_meat.hpp b/include/armadillo_bits/op_accu_meat.hpp index e3559170..707cec4c 100644 --- a/include/armadillo_bits/op_accu_meat.hpp +++ b/include/armadillo_bits/op_accu_meat.hpp @@ -121,20 +121,6 @@ op_accu_mat::apply(const T1& X) return arrayops::accumulate(U.M.memptr(), U.M.n_elem); } - if(is_subview_row::value) - { - typedef typename T1::elem_type eT; - - const subview_row& sv = reinterpret_cast< const subview_row& >(X); - - if(sv.m.n_rows == 1) - { - const eT* sv_mem = &(sv.m.at(sv.aux_col1)); - - return arrayops::accumulate(sv_mem, sv.n_elem); - } - } - const Proxy P(X); return (Proxy::use_at) ? op_accu_mat::apply_proxy_at(P) : op_accu_mat::apply_proxy_linear(P); @@ -616,19 +602,7 @@ op_accu_mat::apply(const subview& X) const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; - if(X_n_rows == 1) - { - const Mat& m = X.m; - - const uword col_offset = X.aux_col1; - const uword row_offset = X.aux_row1; - - eT val = eT(0); - - for(uword i=0; i < X_n_cols; ++i) { val += m.at(row_offset, col_offset + i); } - - return val; - } + if(X_n_rows == 1) { return op_accu_mat::apply( static_cast< const subview_row& >(X) ); } if(X_n_cols == 1) { return arrayops::accumulate( X.colptr(0), X_n_rows ); } @@ -656,6 +630,49 @@ op_accu_mat::apply(const subview_col& X) +template +inline +eT +op_accu_mat::apply(const subview_row& X) + { + arma_debug_sigprint(); + + if(X.n_elem == 0} { return eT(0); } + + if(X.m.n_rows == 1) + { + const eT* sv_mem = &(X.m.at(X.aux_col1)); + + return arrayops::accumulate(sv_mem, X.n_elem); + } + + const Mat& m = X.m; + + const uword X_n_cols = X.n_cols; + + const uword row_offset = X.aux_row1; + const uword col_offset = X.aux_col1; + + eT val1 = eT(0); + eT val2 = eT(0); + + uword i,j; + for(i=0, j=1; j < X_n_cols; i+=2, j+=2) + { + val1 += m.at(row_offset, col_offset + i); + val2 += m.at(row_offset, col_offset + j); + } + + if(i < X_n_cols) + { + val1 += m.at(row_offset, col_offset + i); + } + + return val1 + val2; + } + + + //