From fb5ee6fa0b638196708bb4c82a199850581bf034 Mon Sep 17 00:00:00 2001 From: conrad Date: Tue, 20 May 2025 11:13:31 +1000 Subject: [PATCH] take into account possible inf and nan --- include/armadillo_bits/spglue_schur_meat.hpp | 6 +++++- include/armadillo_bits/spop_misc_meat.hpp | 22 ++------------------ 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/include/armadillo_bits/spglue_schur_meat.hpp b/include/armadillo_bits/spglue_schur_meat.hpp index 0d0a0ec0..77b64434 100644 --- a/include/armadillo_bits/spglue_schur_meat.hpp +++ b/include/armadillo_bits/spglue_schur_meat.hpp @@ -62,7 +62,11 @@ spglue_schur::apply_noalias(SpMat& out, const SpProxy& pa, const SpProxy if( (pa.get_n_nonzero() == 0) || (pb.get_n_nonzero() == 0) ) { - out.zeros(pa.get_n_rows(), pa.get_n_cols()); + if(pa.get_n_nonzero() == 0) { out = pb.Q; } + else if(pb.get_n_nonzero() == 0) { out = pa.Q; } + + out *= eT(0); // in case out has inf or nan + return; } diff --git a/include/armadillo_bits/spop_misc_meat.hpp b/include/armadillo_bits/spop_misc_meat.hpp index 14fc9330..4792c5bc 100644 --- a/include/armadillo_bits/spop_misc_meat.hpp +++ b/include/armadillo_bits/spop_misc_meat.hpp @@ -45,16 +45,7 @@ spop_scalar_times::apply(SpMat& out, const SpOp(in.aux)); - } - else - { - const SpProxy P(in.m); - - out.zeros( P.get_n_rows(), P.get_n_cols() ); - } + out.init_xform(in.m, priv::functor_scalar_times(in.aux)); } @@ -86,16 +77,7 @@ spop_cx_scalar_times::apply(SpMat< std::complex >& out, c typedef typename T1::pod_type T; typedef typename std::complex out_eT; - if(in.aux_out_eT != out_eT(0)) - { - out.init_xform_mt(in.m, priv::functor_cx_scalar_times(in.aux_out_eT)); - } - else - { - const SpProxy P(in.m); - - out.zeros( P.get_n_rows(), P.get_n_cols() ); - } + out.init_xform_mt(in.m, priv::functor_cx_scalar_times(in.aux_out_eT)); }