diff --git a/include/armadillo_bits/SpMat_bones.hpp b/include/armadillo_bits/SpMat_bones.hpp index 39fbb8e7..99a7688d 100644 --- a/include/armadillo_bits/SpMat_bones.hpp +++ b/include/armadillo_bits/SpMat_bones.hpp @@ -338,6 +338,8 @@ class SpMat : public SpBase< eT, SpMat > inline const SpMat& clean(const pod_type threshold); + inline const SpMat& clamp(const eT min_val, const eT max_val); + inline const SpMat& zeros(); inline const SpMat& zeros(const uword in_elem); inline const SpMat& zeros(const uword in_rows, const uword in_cols); diff --git a/include/armadillo_bits/SpMat_meat.hpp b/include/armadillo_bits/SpMat_meat.hpp index 9e40e5a9..dac3e301 100644 --- a/include/armadillo_bits/SpMat_meat.hpp +++ b/include/armadillo_bits/SpMat_meat.hpp @@ -4115,6 +4115,37 @@ SpMat::clean(const typename get_pod_type::result threshold) +template +inline +const SpMat& +SpMat::clamp(const eT min_val, const eT max_val) + { + arma_extra_debug_sigprint(); + + if(is_cx::no) + { + arma_debug_check( (access::tmp_real(min_val) > access::tmp_real(max_val)), "SpMat::clamp(): min_val must be less than max_val" ); + } + else + { + arma_debug_check( (access::tmp_real(min_val) > access::tmp_real(max_val)), "SpMat::clamp(): real(min_val) must be less than real(max_val)" ); + arma_debug_check( (access::tmp_imag(min_val) > access::tmp_imag(max_val)), "SpMat::clamp(): imag(min_val) must be less than imag(max_val)" ); + } + + if(n_nonzero == 0) { return *this; } + + sync_csc(); + invalidate_cache(); + + arrayops::clamp(access::rwp(values), n_nonzero, min_val, max_val); + + if( (min_val == eT(0)) || (max_val == eT(0)) ) { remove_zeros(); } + + return *this; + } + + + template inline const SpMat&