From 252708e38992852b6d3be690eef0dbfb6eb0452c Mon Sep 17 00:00:00 2001 From: conrad Date: Fri, 20 Feb 2026 13:17:43 +1000 Subject: [PATCH] get pointer to first element via dedicated function --- include/armadillo_bits/subview_bones.hpp | 3 +++ include/armadillo_bits/subview_meat.hpp | 28 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/armadillo_bits/subview_bones.hpp b/include/armadillo_bits/subview_bones.hpp index f3837606..4f727737 100644 --- a/include/armadillo_bits/subview_bones.hpp +++ b/include/armadillo_bits/subview_bones.hpp @@ -142,6 +142,9 @@ class subview : public Base< eT, subview > arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; + arma_inline eT* startptr(); + arma_inline const eT* startptr() const; + template inline bool check_overlap(const subview& x) const; diff --git a/include/armadillo_bits/subview_meat.hpp b/include/armadillo_bits/subview_meat.hpp index 487924aa..4135dff8 100644 --- a/include/armadillo_bits/subview_meat.hpp +++ b/include/armadillo_bits/subview_meat.hpp @@ -1425,6 +1425,26 @@ subview::colptr(const uword in_col) const +template +arma_inline +eT* +subview::startptr() + { + return (m.mem == nullptr) ? nullptr : ( & access::rw((const_cast< Mat& >(m)).mem[ aux_col1*m.n_rows + aux_row1 ]) ); + } + + + +template +arma_inline +const eT* +subview::startptr() const + { + return (m.mem == nullptr) ? nullptr : ( & m.mem[ aux_col1*m.n_rows + aux_row1 ] ); + } + + + template template inline @@ -3266,7 +3286,7 @@ template inline subview_col::subview_col(const Mat& in_m, const uword in_col) : subview(in_m, 0, in_col, in_m.n_rows, 1) - , colmem(subview::colptr(0)) + , colmem(subview::startptr()) { arma_debug_sigprint(); } @@ -3277,7 +3297,7 @@ template inline subview_col::subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) : subview(in_m, in_row1, in_col, in_n_rows, 1) - , colmem(subview::colptr(0)) + , colmem(subview::startptr()) { arma_debug_sigprint(); } @@ -4270,7 +4290,7 @@ template inline subview_row::subview_row(const Mat& in_m, const uword in_row) : subview(in_m, in_row, 0, 1, in_m.n_cols) - , rowmem(subview::colptr(0)) + , rowmem(subview::startptr()) { arma_debug_sigprint(); } @@ -4281,7 +4301,7 @@ template inline subview_row::subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) : subview(in_m, in_row, in_col1, 1, in_n_cols) - , rowmem(subview::colptr(0)) + , rowmem(subview::startptr()) { arma_debug_sigprint(); }