From 475b97464dae806d547e8bf9fb3adf78bcf8d86f Mon Sep 17 00:00:00 2001 From: conrad Date: Mon, 20 Oct 2025 12:21:33 +1000 Subject: [PATCH] faster handling of row subvectors --- include/armadillo_bits/Row_bones.hpp | 3 +++ include/armadillo_bits/Row_meat.hpp | 18 ++++++++++++++++++ include/armadillo_bits/unwrap.hpp | 24 ++++++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/armadillo_bits/Row_bones.hpp b/include/armadillo_bits/Row_bones.hpp index dfcb1b29..fdb9612f 100644 --- a/include/armadillo_bits/Row_bones.hpp +++ b/include/armadillo_bits/Row_bones.hpp @@ -169,6 +169,9 @@ class Row : public Mat inline const_row_iterator end_row (const uword row_num) const; + inline explicit Row(const subview& X, const bool reuse_mem); // only to be used by the partial_unwrap class + + template class fixed; diff --git a/include/armadillo_bits/Row_meat.hpp b/include/armadillo_bits/Row_meat.hpp index 4851e987..987a0f48 100644 --- a/include/armadillo_bits/Row_meat.hpp +++ b/include/armadillo_bits/Row_meat.hpp @@ -1264,6 +1264,20 @@ Row::end_row(const uword row_num) const +template +inline +Row::Row(const subview& X, const bool reuse_mem) + : Mat(X, reuse_mem) + { + arma_debug_sigprint_this(this); + } + + + +// + + + template template arma_inline @@ -1859,6 +1873,10 @@ Row::fixed::ones() +// + + + template inline Row::Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) diff --git a/include/armadillo_bits/unwrap.hpp b/include/armadillo_bits/unwrap.hpp index 07d581c0..4d64744a 100644 --- a/include/armadillo_bits/unwrap.hpp +++ b/include/armadillo_bits/unwrap.hpp @@ -382,19 +382,21 @@ struct quasi_unwrap< subview_row > { inline quasi_unwrap(const subview_row& A) - : M(A) + : sv( A ) + , M ( A, (A.m.n_rows == 1) ) { arma_debug_sigprint(); } - Row M; + const subview_row& sv; + const Row M; - static constexpr bool is_const = false; - static constexpr bool has_subview = false; - static constexpr bool has_orig_mem = false; + static constexpr bool is_const = true; + static constexpr bool has_subview = true; + static constexpr bool has_orig_mem = false; // NOTE: set to false as this is the general case; original memory is only used when the subview is a contiguous chunk template - constexpr bool is_alias(const Mat&) const { return false; } + arma_inline bool is_alias(const Mat& X) const { return (is_same_type::yes) && ( (sv.m.n_rows == 1) ? (void_ptr(&X) == void_ptr(&(sv.m))) : false ); } }; @@ -1430,7 +1432,8 @@ struct partial_unwrap< subview_row > inline partial_unwrap(const subview_row& A) - : M(A) + : sv( A ) + , M ( A, (A.m.n_rows == 1) ) { arma_debug_sigprint(); } @@ -1438,13 +1441,14 @@ struct partial_unwrap< subview_row > constexpr eT get_val() const { return eT(1); } template - constexpr bool is_alias(const Mat&) const { return false; } + arma_inline bool is_alias(const Mat& X) const { return (sv.m.n_rows == 1) ? (void_ptr(&X) == void_ptr(&(sv.m))) : false; } static constexpr bool do_trans = false; static constexpr bool do_times = false; - static constexpr bool is_fast = false; + static constexpr bool is_fast = false; // can't determine at compile time that memory is reused - const Row M; + const subview_row& sv; + const Row M; };