From ee9f42faffc336200f1c065a95ebcb09af229b92 Mon Sep 17 00:00:00 2001 From: conrad Date: Sun, 19 Jan 2025 23:41:41 +1000 Subject: [PATCH] simplifications --- include/armadillo_bits/op_sum_bones.hpp | 26 ++--- include/armadillo_bits/op_sum_meat.hpp | 140 +++++++++++------------- 2 files changed, 74 insertions(+), 92 deletions(-) diff --git a/include/armadillo_bits/op_sum_bones.hpp b/include/armadillo_bits/op_sum_bones.hpp index a72c7869..fb390172 100644 --- a/include/armadillo_bits/op_sum_bones.hpp +++ b/include/armadillo_bits/op_sum_bones.hpp @@ -28,31 +28,25 @@ class op_sum // dense matrices template - arma_hot inline static void apply(Mat& out, const Op& in); + inline static void apply(Mat& out, const Op& in); + + template + inline static void apply_mat_noalias(Mat& out, const Mat& X, const uword dim); template - arma_hot inline static void apply_noalias(Mat& out, const Proxy& P, const uword dim); - - template - arma_hot inline static void apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim); - - template - arma_hot inline static void apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim); + inline static void apply_proxy_noalias(Mat& out, const Proxy& P, const uword dim); // cubes template - arma_hot inline static void apply(Cube& out, const OpCube& in); + inline static void apply(Cube& out, const OpCube& in); + + template + inline static void apply_cube_noalias(Cube& out, const Cube& X, const uword dim); template - arma_hot inline static void apply_noalias(Cube& out, const ProxyCube& P, const uword dim); - - template - arma_hot inline static void apply_noalias_unwrap(Cube& out, const ProxyCube& P, const uword dim); - - template - arma_hot inline static void apply_noalias_proxy(Cube& out, const ProxyCube& P, const uword dim); + inline static void apply_proxy_noalias(Cube& out, const ProxyCube& P, const uword dim); }; diff --git a/include/armadillo_bits/op_sum_meat.hpp b/include/armadillo_bits/op_sum_meat.hpp index 16becb36..bf1c985c 100644 --- a/include/armadillo_bits/op_sum_meat.hpp +++ b/include/armadillo_bits/op_sum_meat.hpp @@ -31,60 +31,54 @@ op_sum::apply(Mat& out, const Op& in) typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; + arma_conform_check( (dim > 1), "sum(): parameter 'dim' must be 0 or 1" ); - const Proxy P(in.m); - - if(P.is_alias(out) == false) + if((is_Mat::value) || (is_Mat::stored_type>::value) || (arma_config::openmp && Proxy::use_mp)) { - op_sum::apply_noalias(out, P, dim); + const quasi_unwrap U(in.m); + + if(U.is_alias(out)) + { + Mat tmp; + + op_sum::apply_mat_noalias(tmp, U.M, dim); + + out.steal_mem(tmp); + } + else + { + op_sum::apply_mat_noalias(out, U.M, dim); + } } else { - Mat tmp; + const Proxy P(in.m); - op_sum::apply_noalias(tmp, P, dim); - - out.steal_mem(tmp); + if(P.is_alias(out)) + { + Mat tmp; + + op_sum::apply_proxy_noalias(tmp, P, dim); + + out.steal_mem(tmp); + } + else + { + op_sum::apply_proxy_noalias(out, P, dim); + } } } -template +template inline void -op_sum::apply_noalias(Mat& out, const Proxy& P, const uword dim) +op_sum::apply_mat_noalias(Mat& out, const Mat& X, const uword dim) { arma_debug_sigprint(); - if(is_Mat::stored_type>::value || (arma_config::openmp && Proxy::use_mp)) - { - op_sum::apply_noalias_unwrap(out, P, dim); - } - else - { - op_sum::apply_noalias_proxy(out, P, dim); - } - } - - - -template -inline -void -op_sum::apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim) - { - arma_debug_sigprint(); - - typedef typename T1::elem_type eT; - - typedef typename Proxy::stored_type P_stored_type; - - const unwrap tmp(P.Q); - - const typename unwrap::stored_type& X = tmp.M; - const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; @@ -127,7 +121,7 @@ op_sum::apply_noalias_unwrap(Mat& out, const Proxy& template inline void -op_sum::apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim) +op_sum::apply_proxy_noalias(Mat& out, const Proxy& P, const uword dim) { arma_debug_sigprint(); @@ -244,60 +238,54 @@ op_sum::apply(Cube& out, const OpCube& in) typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; + arma_conform_check( (dim > 2), "sum(): parameter 'dim' must be 0 or 1 or 2" ); - const ProxyCube P(in.m); - - if(P.is_alias(out) == false) + if((is_Cube::value) || (is_Cube::stored_type>::value) || (arma_config::openmp && ProxyCube::use_mp)) { - op_sum::apply_noalias(out, P, dim); + const unwrap_cube U(in.m); + + if(U.is_alias(out)) + { + Cube tmp; + + op_sum::apply_cube_noalias(tmp, U.M, dim); + + out.steal_mem(tmp); + } + else + { + op_sum::apply_cube_noalias(out, U.M, dim); + } } else { - Cube tmp; + const ProxyCube P(in.m); - op_sum::apply_noalias(tmp, P, dim); - - out.steal_mem(tmp); + if(P.is_alias(out)) + { + Cube tmp; + + op_sum::apply_proxy_noalias(tmp, P, dim); + + out.steal_mem(tmp); + } + else + { + op_sum::apply_proxy_noalias(out, P, dim); + } } } -template +template inline void -op_sum::apply_noalias(Cube& out, const ProxyCube& P, const uword dim) +op_sum::apply_cube_noalias(Cube& out, const Cube& X, const uword dim) { arma_debug_sigprint(); - if(is_Cube::stored_type>::value || (arma_config::openmp && ProxyCube::use_mp)) - { - op_sum::apply_noalias_unwrap(out, P, dim); - } - else - { - op_sum::apply_noalias_proxy(out, P, dim); - } - } - - - -template -inline -void -op_sum::apply_noalias_unwrap(Cube& out, const ProxyCube& P, const uword dim) - { - arma_debug_sigprint(); - - typedef typename T1::elem_type eT; - - typedef typename ProxyCube::stored_type P_stored_type; - - const unwrap_cube tmp(P.Q); - - const Cube& X = tmp.M; - const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword X_n_slices = X.n_slices; @@ -350,7 +338,7 @@ op_sum::apply_noalias_unwrap(Cube& out, const ProxyCube< template inline void -op_sum::apply_noalias_proxy(Cube& out, const ProxyCube& P, const uword dim) +op_sum::apply_proxy_noalias(Cube& out, const ProxyCube& P, const uword dim) { arma_debug_sigprint();