From ada1e18e45b35bca2c2edbaf0a55d49c159203e2 Mon Sep 17 00:00:00 2001 From: conrad Date: Sat, 28 Jun 2025 19:16:24 +1000 Subject: [PATCH] split out handling of spop_square into separate function --- include/armadillo_bits/fn_accu.hpp | 88 +++++++++++++++++------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/include/armadillo_bits/fn_accu.hpp b/include/armadillo_bits/fn_accu.hpp index 09228756..7d57c026 100644 --- a/include/armadillo_bits/fn_accu.hpp +++ b/include/armadillo_bits/fn_accu.hpp @@ -1387,45 +1387,6 @@ accu(const SpOp& expr) if(is_vectorise) { return accu(expr.m); } - if(is_same_type::yes) - { - if(is_SpSubview_col::value) - { - const SpSubview_col& svcol = reinterpret_cast&>(expr.m); - - if(svcol.n_rows == svcol.m.n_rows) - { - const SpMat& m = svcol.m; - const uword col = svcol.aux_col1; - - const eT* ptr = &(m.values[ m.col_ptrs[col] ]); - - return op_dot::direct_dot(svcol.n_nonzero, ptr, ptr); - } - } - - const SpProxy P(expr.m); - - const uword N = P.get_n_nonzero(); - - if(N == 0) { return eT(0); } - - if(SpProxy::use_iterator == false) - { - return op_dot::direct_dot(N, P.get_values(), P.get_values()); - } - else - { - typename SpProxy::const_iterator_type it = P.begin(); - - eT val = eT(0); - - for(uword i=0; i < N; ++i) { const eT tmp = (*it); val += (tmp*tmp); ++it; } - - return val; - } - } - const SpMat tmp = expr; return accu(tmp); @@ -1433,6 +1394,55 @@ accu(const SpOp& expr) +template +arma_warn_unused +inline +typename T1::elem_type +accu(const SpOp& expr) + { + arma_debug_sigprint(); + + typedef typename T1::elem_type eT; + + if(is_SpSubview_col::value) + { + const SpSubview_col& svcol = reinterpret_cast&>(expr.m); + + if(svcol.n_rows == svcol.m.n_rows) + { + const SpMat& m = svcol.m; + const uword col = svcol.aux_col1; + + const eT* ptr = &(m.values[ m.col_ptrs[col] ]); + + return op_dot::direct_dot(svcol.n_nonzero, ptr, ptr); + } + } + + const SpProxy P(expr.m); + + const uword N = P.get_n_nonzero(); + + if(N == 0) { return eT(0); } + + if(SpProxy::use_iterator == false) + { + return op_dot::direct_dot(N, P.get_values(), P.get_values()); + } + else + { + typename SpProxy::const_iterator_type it = P.begin(); + + eT val = eT(0); + + for(uword i=0; i < N; ++i) { const eT tmp = (*it); val += (tmp*tmp); ++it; } + + return val; + } + } + + + template arma_warn_unused inline