add .clamp()

This commit is contained in:
conrad
2021-05-04 01:08:08 +10:00
parent 857671fe95
commit fa22fc0cb9
2 changed files with 33 additions and 0 deletions
+2
View File
@@ -338,6 +338,8 @@ class SpMat : public SpBase< eT, SpMat<eT> >
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);
+31
View File
@@ -4115,6 +4115,37 @@ SpMat<eT>::clean(const typename get_pod_type<eT>::result threshold)
template<typename eT>
inline
const SpMat<eT>&
SpMat<eT>::clamp(const eT min_val, const eT max_val)
{
arma_extra_debug_sigprint();
if(is_cx<eT>::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<typename eT>
inline
const SpMat<eT>&