diff --git a/include/armadillo_bits/op_sp_var_bones.hpp b/include/armadillo_bits/op_sp_var_bones.hpp index 36b0e512..81c653d4 100644 --- a/include/armadillo_bits/op_sp_var_bones.hpp +++ b/include/armadillo_bits/op_sp_var_bones.hpp @@ -26,10 +26,13 @@ class op_sp_var : public traits_op_xvec { public: - + template inline static void apply(Mat& out, const mtSpToDOp& in); - + + template + inline static void apply_slow(Mat& out, const SpProxy& p, const uword norm_type, const uword dim); + // Calculate variance of a sparse vector, where we can directly use the memory. template inline static typename T1::pod_type var_vec(const T1& X, const uword norm_type = 0); @@ -39,23 +42,21 @@ class op_sp_var // as well as the actual number of elements when zeros are included. template inline static eT direct_var(const eT* const X, const uword length, const uword N, const uword norm_type = 0); - + // For complex numbers. - + template inline static T direct_var(const std::complex* const X, const uword length, const uword N, const uword norm_type = 0); - + // Calculate the variance using iterators, for non-complex numbers. template inline static eT iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_not_cx::result* junk2 = nullptr); - + // Calculate the variance using iterators, for complex numbers. template inline static typename get_pod_type::result iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only::result* junk2 = nullptr); - }; //! @} - diff --git a/include/armadillo_bits/op_sp_var_meat.hpp b/include/armadillo_bits/op_sp_var_meat.hpp index 3faee38b..d3ae2b75 100644 --- a/include/armadillo_bits/op_sp_var_meat.hpp +++ b/include/armadillo_bits/op_sp_var_meat.hpp @@ -28,9 +28,6 @@ op_sp_var::apply(Mat& out, const mtSpToDOp& out, const mtSpToDOp 0) ? 1 : 0, p_n_cols); } + if(dim == 1) { out.zeros(p_n_rows, (p_n_cols > 0) ? 1 : 0); } + + return; + } + + op_sp_var::apply_slow(out, p, norm_type, dim); + } + + + +template +inline +void +op_sp_var::apply_slow + ( + Mat& out, + const SpProxy& p, + const uword norm_type, + const uword dim + ) + { + arma_debug_sigprint(); + + typedef typename T1::elem_type in_eT; + //typedef typename T1::pod_type out_eT; + + const uword p_n_rows = p.get_n_rows(); + const uword p_n_cols = p.get_n_cols(); + if(dim == 0) // find variance in each column { - arma_debug_print("op_sp_var::apply_noalias(): dim = 0"); + arma_debug_print("op_sp_var::apply_slow(): dim = 0"); - out.zeros((p_n_rows > 0) ? 1 : 0, p_n_cols); - - if( (p_n_rows == 0) || (p.get_n_nonzero() == 0) ) { return; } + out.zeros(1, p_n_cols); for(uword col = 0; col < p_n_cols; ++col) { @@ -79,11 +106,9 @@ op_sp_var::apply(Mat& out, const mtSpToDOp 0) ? 1 : 0); - - if( (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { return; } + out.zeros(p_n_rows, 1); for(uword row = 0; row < p_n_rows; ++row) {