diff --git a/include/armadillo_bits/op_inv_spd_meat.hpp b/include/armadillo_bits/op_inv_spd_meat.hpp index 94660341..057f5514 100644 --- a/include/armadillo_bits/op_inv_spd_meat.hpp +++ b/include/armadillo_bits/op_inv_spd_meat.hpp @@ -113,8 +113,6 @@ op_inv_spd::apply_direct(Mat& out, const Base::no) && (N <= 4)) { arma_extra_debug_print("op_inv_spd: attempting tinymatrix optimisation"); @@ -169,25 +167,41 @@ op_inv_spd::apply_direct(Mat& out, const Base::no) && (is_op_diagmat::value || out.is_diagmat())) + if(is_cx::yes) { - arma_extra_debug_print("op_inv_spd: detected diagonal matrix"); + arma_extra_debug_print("op_inv_spd: checking imaginary components of diagonal elements"); - // specialised handling of real matrices only; - // currently auxlib::inv_sympd() does not enforce that - // imaginary components of diagonal elements must be zero; - // strictly enforcing this constraint may break existing user software. + const T tol = T(100) * std::numeric_limits::epsilon(); // allow some leeway - // TODO: allow this speedup for complex matrices, since imaginary components of diagonal elements will be checked above + const eT* colmem = out.memptr(); for(uword i=0; i tol) { return false; } - out_ii = eT(T(1) / real_out_ii); + colmem += N; + } + } + + if(is_op_diagmat::value || out.is_diagmat()) + { + arma_extra_debug_print("op_inv_spd: detected diagonal matrix"); + + const eT* colmem = out.memptr(); + + for(uword i=0; i