From 451d5d2cecc08bc9e308d4d4a06a43d124664320 Mon Sep 17 00:00:00 2001 From: conrad Date: Thu, 5 Mar 2026 15:50:01 +1000 Subject: [PATCH] speedups for empty submatrices --- include/armadillo_bits/op_accu_meat.hpp | 8 ++++++++ include/armadillo_bits/op_vectorise_meat.hpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/armadillo_bits/op_accu_meat.hpp b/include/armadillo_bits/op_accu_meat.hpp index 3cd71064..c770dd84 100644 --- a/include/armadillo_bits/op_accu_meat.hpp +++ b/include/armadillo_bits/op_accu_meat.hpp @@ -80,6 +80,8 @@ op_accu_mat::apply_proxy_at(const Proxy& P) const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); + if( (n_rows == 0) || (n_cols == 0) ) { return eT(0); } + eT val = eT(0); if(n_rows != 1) @@ -146,6 +148,8 @@ op_accu_mat::apply_omit_helper(const Proxy& P, functor is_omitted) const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); + if( (n_rows == 0) || (n_cols == 0) ) { return eT_zero; } + for(uword c=0; c < n_cols; ++c) for(uword r=0; r < n_rows; ++r) { @@ -602,6 +606,8 @@ op_accu_mat::apply(const subview& X) const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; + if( (X_n_rows == 0) || (X_n_cols == 0) ) { return eT(0); } + if(X_n_rows == 1) { const uword X_m_n_rows = X.m.n_rows; @@ -750,6 +756,8 @@ op_accu_cube::apply_proxy_at(const ProxyCube& P) const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); + if( (n_rows == 0) || (n_cols == 0) || (n_slices == 0) ) { return eT(0); } + eT val1 = eT(0); eT val2 = eT(0); diff --git a/include/armadillo_bits/op_vectorise_meat.hpp b/include/armadillo_bits/op_vectorise_meat.hpp index 724ce50c..f185ac4c 100644 --- a/include/armadillo_bits/op_vectorise_meat.hpp +++ b/include/armadillo_bits/op_vectorise_meat.hpp @@ -176,6 +176,8 @@ op_vectorise_col::apply_subview(Mat& out, const subview& sv) out.set_size(sv.n_elem, 1); + if(sv.n_elem == 0) { return; } + eT* out_mem = out.memptr(); for(uword col=0; col < sv_n_cols; ++col) @@ -201,6 +203,8 @@ op_vectorise_col::apply_proxy(Mat& out, const Proxy& out.set_size(N, 1); + if(N == 0) { return; } + eT* outmem = out.memptr(); if(Proxy::use_at == false) @@ -305,6 +309,8 @@ op_vectorise_row::apply_proxy(Mat& out, const Proxy& out.set_size(1, n_elem); + if(n_elem == 0) { return; } + eT* outmem = out.memptr(); if(n_cols == 1) @@ -471,6 +477,8 @@ op_vectorise_cube_col::apply_proxy(Mat& out, const T1& e out.set_size(N, 1); + if(N == 0) { return; } + eT* outmem = out.memptr(); if(ProxyCube::use_at == false)