Skip to content

Commit c6b7388

Browse files
committed
Sync with Armadillo 15.2.3
1 parent c37dce2 commit c6b7388

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2025-12-16 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/current/: Sync with Armadillo 15.2.3
4+
15
2025-12-08 Dirk Eddelbuettel <[email protected]>
26

37
* .github/workflows/ci.yaml: No longer need to select 'dev' version

inst/include/current/armadillo_bits/Mat_meat.hpp

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Mat<eT>::Mat()
4949
, n_alloc(0)
5050
, vec_state(0)
5151
, mem_state(0)
52-
, mem()
52+
, mem(nullptr)
5353
{
5454
arma_debug_sigprint_this(this);
5555
}
@@ -312,15 +312,10 @@ Mat<eT>::init_cold()
312312
const char* error_message = "Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD";
313313
#endif
314314

315-
arma_conform_check
316-
(
317-
(
318-
( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) )
319-
? ( (double(n_rows) * double(n_cols)) > double(ARMA_MAX_UWORD) )
320-
: false
321-
),
322-
error_message
323-
);
315+
if( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) )
316+
{
317+
arma_conform_check( ( (double(n_rows) * double(n_cols)) > double(ARMA_MAX_UWORD) ), error_message );
318+
}
324319

325320
if(n_elem <= arma_config::mat_prealloc)
326321
{
@@ -383,17 +378,10 @@ Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols)
383378
const char* error_message_4 = "Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD";
384379
#endif
385380

386-
arma_conform_set_error
387-
(
388-
err_state,
389-
err_msg,
390-
(
391-
( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) )
392-
? ( (double(in_n_rows) * double(in_n_cols)) > double(ARMA_MAX_UWORD) )
393-
: false
394-
),
395-
error_message_4
396-
);
381+
if( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) )
382+
{
383+
arma_conform_set_error( err_state, err_msg, ( (double(in_n_rows) * double(in_n_cols)) > double(ARMA_MAX_UWORD) ), error_message_4 );
384+
}
397385

398386
arma_conform_check(err_state, err_msg);
399387

@@ -7580,10 +7568,40 @@ Mat<eT>::resize(const uword new_n_elem)
75807568
{
75817569
arma_debug_sigprint();
75827570

7583-
const uword new_n_rows = (vec_state == 2) ? uword(1 ) : uword(new_n_elem);
7584-
const uword new_n_cols = (vec_state == 2) ? uword(new_n_elem) : uword(1 );
7571+
const bool reuse_mem =
7572+
( is_vec() && (mem_state == 0) )
7573+
&&
7574+
(
7575+
( (new_n_elem <= arma_config::mat_prealloc) && (n_elem <= arma_config::mat_prealloc) && ( n_elem > 0 ) )
7576+
|| ( (new_n_elem > arma_config::mat_prealloc) && (n_elem > arma_config::mat_prealloc) && (new_n_elem <= n_alloc) )
7577+
);
7578+
7579+
if(reuse_mem)
7580+
{
7581+
arma_debug_print("Mat::resize(): reusing memory");
7582+
7583+
if(new_n_elem > n_elem)
7584+
{
7585+
arma_debug_print("Mat::resize(): zeroing memory");
7586+
7587+
eT* t_mem = (*this).memptr(); // the (n_elem > 0) check above ensures that (*this).memptr() is a valid pointer
7588+
7589+
for(uword ii = n_elem; ii < new_n_elem; ++ii) { t_mem[ii] = eT(0); }
7590+
}
7591+
7592+
access::rw(n_rows) = (vec_state == 2) ? uword(1 ) : uword(new_n_elem);
7593+
access::rw(n_cols) = (vec_state == 2) ? uword(new_n_elem) : uword(1 );
7594+
access::rw(n_elem) = new_n_elem;
7595+
}
7596+
else
7597+
{
7598+
const uword new_n_rows = (vec_state == 2) ? uword(1 ) : uword(new_n_elem);
7599+
const uword new_n_cols = (vec_state == 2) ? uword(new_n_elem) : uword(1 );
7600+
7601+
(*this).resize(new_n_rows, new_n_cols);
7602+
}
75857603

7586-
return (*this).resize(new_n_rows, new_n_cols);
7604+
return (*this);
75877605
}
75887606

75897607

inst/include/current/armadillo_bits/arma_version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#define ARMA_VERSION_MAJOR 15
2525
#define ARMA_VERSION_MINOR 2
26-
#define ARMA_VERSION_PATCH 2
26+
#define ARMA_VERSION_PATCH 3
2727
#define ARMA_VERSION_NAME "Medium Roast Deluxe"
2828

2929

inst/include/current/armadillo_bits/op_repmat_meat.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,19 @@ op_repcube::apply_noalias(Cube<eT>& out, const Cube<eT>& X, const uword copies_p
153153

154154
if(out.is_empty()) { return; }
155155

156-
// TODO: this is a rudimentary implementation
157-
158-
const SizeCube X_size = SizeCube(X.n_rows, X.n_cols, X.n_slices);
159-
160-
for(uword s = 0; s < out.n_slices; s += X.n_slices)
161-
for(uword c = 0; c < out.n_cols; c += X.n_cols )
162-
for(uword r = 0; r < out.n_rows; r += X.n_rows )
156+
for(uword s=0; s < X.n_slices; ++s)
163157
{
164-
out.subcube(r, c, s, X_size) = X;
158+
// avoid use of Cube::slice() to prevent generating Mat objects that the user may not need
159+
160+
const Mat<eT> X_slice_s(const_cast<eT*>(X.slice_memptr(s)), X.n_rows, X.n_cols, false, true);
161+
Mat<eT> out_slice_s( out.slice_memptr(s) , out.n_rows, out.n_cols, false, true);
162+
163+
op_repmat::apply_noalias(out_slice_s, X_slice_s, copies_per_row, copies_per_col);
164+
165+
for(uword t=1; t < copies_per_slice; ++t)
166+
{
167+
arrayops::copy(out.slice_memptr(s + (t * X.n_slices)), out_slice_s.memptr(), out_slice_s.n_elem);
168+
}
165169
}
166170
}
167171

inst/include/current/armadillo_bits/op_resize_meat.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ op_resize::apply_mat_inplace(Mat<eT>& A, const uword new_n_rows, const uword new
8181
arma_conform_check( (A.vec_state == 1) && (new_n_cols != 1), "resize(): requested size is not compatible with column vector layout" );
8282
arma_conform_check( (A.vec_state == 2) && (new_n_rows != 1), "resize(): requested size is not compatible with row vector layout" );
8383

84-
if(A.is_empty()) { A.zeros(new_n_rows, new_n_cols); return; }
84+
if( A.is_empty() || (new_n_rows == 0) || (new_n_cols == 0) ) { A.zeros(new_n_rows, new_n_cols); return; }
8585

8686
Mat<eT> B(new_n_rows, new_n_cols, arma_nozeros_indicator());
8787

0 commit comments

Comments
 (0)