From 27f50ccc77ac2eb9db62e7c1c5550af090234c19 Mon Sep 17 00:00:00 2001 From: conrad Date: Thu, 9 Oct 2025 11:10:33 +1000 Subject: [PATCH] experiment with avoiding unnecessary alias checks --- include/armadillo_bits/Mat_bones.hpp | 4 ++ include/armadillo_bits/Mat_meat.hpp | 8 ++-- include/armadillo_bits/arma_forward.hpp | 2 + include/armadillo_bits/op_htrans_bones.hpp | 6 +++ include/armadillo_bits/op_htrans_meat.hpp | 48 ++++++++++++++++++++++ include/armadillo_bits/op_mean_bones.hpp | 3 ++ include/armadillo_bits/op_mean_meat.hpp | 18 ++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) diff --git a/include/armadillo_bits/Mat_bones.hpp b/include/armadillo_bits/Mat_bones.hpp index b8997272..d0673160 100644 --- a/include/armadillo_bits/Mat_bones.hpp +++ b/include/armadillo_bits/Mat_bones.hpp @@ -958,4 +958,8 @@ class Mat_aux +template class Mat_noalias : public Mat {}; + + + //! @} diff --git a/include/armadillo_bits/Mat_meat.hpp b/include/armadillo_bits/Mat_meat.hpp index 3bb32ade..b7719217 100644 --- a/include/armadillo_bits/Mat_meat.hpp +++ b/include/armadillo_bits/Mat_meat.hpp @@ -5066,10 +5066,12 @@ Mat::Mat(const Op& X) , mem() { arma_debug_sigprint_this(this); - + arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); - op_type::apply(*this, X); + // op_type::apply(*this, X); + + op_type::apply(static_cast< Mat_noalias& >(*this), X); } @@ -5082,7 +5084,7 @@ Mat& Mat::operator=(const Op& X) { arma_debug_sigprint(); - + arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); diff --git a/include/armadillo_bits/arma_forward.hpp b/include/armadillo_bits/arma_forward.hpp index 981776ad..83c484c3 100644 --- a/include/armadillo_bits/arma_forward.hpp +++ b/include/armadillo_bits/arma_forward.hpp @@ -31,6 +31,8 @@ template class Row; template class Cube; template class field; +template class Mat_noalias; + template struct xvec_htrans; template struct xtrans_mat; diff --git a/include/armadillo_bits/op_htrans_bones.hpp b/include/armadillo_bits/op_htrans_bones.hpp index 0d86f275..c4293d46 100644 --- a/include/armadillo_bits/op_htrans_bones.hpp +++ b/include/armadillo_bits/op_htrans_bones.hpp @@ -77,6 +77,12 @@ struct op_htrans template inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = nullptr); + + template + inline static void apply(Mat_noalias& out, const Op& in, const typename arma_not_cx::result* junk = nullptr); + + template + inline static void apply(Mat_noalias& out, const Op& in, const typename arma_cx_only::result* junk = nullptr); }; diff --git a/include/armadillo_bits/op_htrans_meat.hpp b/include/armadillo_bits/op_htrans_meat.hpp index 964c885e..5c8248b6 100644 --- a/include/armadillo_bits/op_htrans_meat.hpp +++ b/include/armadillo_bits/op_htrans_meat.hpp @@ -377,6 +377,54 @@ op_htrans::apply(Mat& out, const Op& in, c +template +inline +void +op_htrans::apply(Mat_noalias& out, const Op& in, const typename arma_not_cx::result* junk) + { + arma_debug_sigprint(); + arma_ignore(junk); + + if((is_Mat::stored_type>::value) || (arma_config::openmp && Proxy::use_mp)) + { + const quasi_unwrap U(in.m); + + op_strans::apply_mat_noalias(out, U.M); + } + else + { + const Proxy P(in.m); + + op_strans::apply_proxy(out, P); + } + } + + + +template +inline +void +op_htrans::apply(Mat_noalias& out, const Op& in, const typename arma_cx_only::result* junk) + { + arma_debug_sigprint(); + arma_ignore(junk); + + if((is_Mat::stored_type>::value) || (arma_config::openmp && Proxy::use_mp)) + { + const quasi_unwrap U(in.m); + + op_htrans::apply_mat_noalias(out, U.M); + } + else + { + const Proxy P(in.m); + + op_htrans::apply_proxy(out, P); + } + } + + + // // op_htrans2 diff --git a/include/armadillo_bits/op_mean_bones.hpp b/include/armadillo_bits/op_mean_bones.hpp index 33d50e47..e30de199 100644 --- a/include/armadillo_bits/op_mean_bones.hpp +++ b/include/armadillo_bits/op_mean_bones.hpp @@ -29,6 +29,9 @@ struct op_mean template inline static void apply(Mat& out, const Op& in); + template + inline static void apply(Mat_noalias& out, const Op& in); + template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim); diff --git a/include/armadillo_bits/op_mean_meat.hpp b/include/armadillo_bits/op_mean_meat.hpp index 39a6904f..4760e2e0 100644 --- a/include/armadillo_bits/op_mean_meat.hpp +++ b/include/armadillo_bits/op_mean_meat.hpp @@ -52,6 +52,24 @@ op_mean::apply(Mat& out, const Op& in) +template +inline +void +op_mean::apply(Mat_noalias& out, const Op& in) + { + arma_debug_sigprint(); + + const uword dim = in.aux_uword_a; + + arma_conform_check( (dim > 1), "mean(): parameter 'dim' must be 0 or 1" ); + + const quasi_unwrap U(in.m); + + op_mean::apply_noalias(out, U.M, dim); + } + + + template inline void