From 033c93196cefbcfccf8bfacd3ada20b4d24e8443 Mon Sep 17 00:00:00 2001 From: conrad Date: Tue, 16 Jun 2026 12:33:54 +1000 Subject: [PATCH] more robust handling of aux_mem --- include/armadillo_bits/Cube_meat.hpp | 31 +++++++++++++++++++++++++--- include/armadillo_bits/Mat_meat.hpp | 27 ++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/include/armadillo_bits/Cube_meat.hpp b/include/armadillo_bits/Cube_meat.hpp index f44d0465..508ddc6e 100644 --- a/include/armadillo_bits/Cube_meat.hpp +++ b/include/armadillo_bits/Cube_meat.hpp @@ -807,11 +807,29 @@ Cube::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, cons { init_cold(); - arrayops::copy( memptr(), aux_mem, n_elem ); + if(aux_mem == nullptr) + { + arrayops::fill_zeros(memptr(), n_elem); + } + else + { + arrayops::copy( memptr(), aux_mem, n_elem ); + } } else { - create_mat(); + if(aux_mem == nullptr) + { + access::rw(mem_state) = 0; + + init_cold(); + + arrayops::fill_zeros(memptr(), n_elem); + } + else + { + create_mat(); + } } } @@ -835,7 +853,14 @@ Cube::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols init_cold(); - arrayops::copy( memptr(), aux_mem, n_elem ); + if(aux_mem == nullptr) + { + arrayops::fill_zeros(memptr(), n_elem); + } + else + { + arrayops::copy( memptr(), aux_mem, n_elem ); + } } diff --git a/include/armadillo_bits/Mat_meat.hpp b/include/armadillo_bits/Mat_meat.hpp index fe3d5e4f..b2e3d272 100644 --- a/include/armadillo_bits/Mat_meat.hpp +++ b/include/armadillo_bits/Mat_meat.hpp @@ -1369,7 +1369,23 @@ Mat::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const { init_cold(); - arrayops::copy( memptr(), aux_mem, n_elem ); + if(aux_mem == nullptr) + { + arrayops::fill_zeros(memptr(), n_elem); + } + else + { + arrayops::copy( memptr(), aux_mem, n_elem ); + } + } + else + if(aux_mem == nullptr) + { + access::rw(mem_state) = 0; + + init_cold(); + + arrayops::fill_zeros(memptr(), n_elem); } } @@ -1392,7 +1408,14 @@ Mat::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) init_cold(); - arrayops::copy( memptr(), aux_mem, n_elem ); + if(aux_mem == nullptr) + { + arrayops::fill_zeros(memptr(), n_elem); + } + else + { + arrayops::copy( memptr(), aux_mem, n_elem ); + } }