add .clamp()
This commit is contained in:
@@ -93,6 +93,8 @@ class diagview : public Base< eT, diagview<eT> >
|
||||
|
||||
inline void replace(const eT old_val, const eT new_val);
|
||||
|
||||
inline void clamp(const eT min_val, const eT max_val);
|
||||
|
||||
inline void fill(const eT val);
|
||||
inline void zeros();
|
||||
inline void ones();
|
||||
|
||||
@@ -937,6 +937,40 @@ diagview<eT>::replace(const eT old_val, const eT new_val)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
void
|
||||
diagview<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)), "diagview::clamp(): min_val must be less than max_val" );
|
||||
}
|
||||
else
|
||||
{
|
||||
arma_debug_check( (access::tmp_real(min_val) > access::tmp_real(max_val)), "diagview::clamp(): real(min_val) must be less than real(max_val)" );
|
||||
arma_debug_check( (access::tmp_imag(min_val) > access::tmp_imag(max_val)), "diagview::clamp(): imag(min_val) must be less than imag(max_val)" );
|
||||
}
|
||||
|
||||
Mat<eT>& x = const_cast< Mat<eT>& >(m);
|
||||
|
||||
const uword local_n_elem = n_elem;
|
||||
|
||||
podarray<eT> tmp(local_n_elem);
|
||||
|
||||
eT* tmp_mem = tmp.memptr();
|
||||
|
||||
for(uword ii=0; ii < local_n_elem; ++ii) { tmp_mem[ii] = x.at(ii+row_offset, ii+col_offset); }
|
||||
|
||||
arrayops::clamp( tmp_mem, local_n_elem, min_val, max_val );
|
||||
|
||||
for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = tmp_mem[ii]; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
void
|
||||
|
||||
@@ -57,6 +57,8 @@ class subview_elem1 : public Base< eT, subview_elem1<eT,T1> >
|
||||
|
||||
inline void replace(const eT old_val, const eT new_val);
|
||||
|
||||
inline void clamp(const eT min_val, const eT max_val);
|
||||
|
||||
inline void fill(const eT val);
|
||||
inline void zeros();
|
||||
inline void ones();
|
||||
|
||||
@@ -395,6 +395,22 @@ subview_elem1<eT,T1>::replace(const eT old_val, const eT new_val)
|
||||
|
||||
|
||||
|
||||
template<typename eT, typename T1>
|
||||
inline
|
||||
void
|
||||
subview_elem1<eT,T1>::clamp(const eT min_val, const eT max_val)
|
||||
{
|
||||
arma_extra_debug_sigprint();
|
||||
|
||||
Mat<eT> tmp(*this);
|
||||
|
||||
tmp.clamp(min_val, max_val);
|
||||
|
||||
(*this).operator=(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT, typename T1>
|
||||
inline
|
||||
void
|
||||
|
||||
@@ -60,6 +60,8 @@ class subview_elem2 : public Base< eT, subview_elem2<eT,T1,T2> >
|
||||
|
||||
inline void clean(const pod_type threshold);
|
||||
|
||||
inline void clamp(const eT min_val, const eT max_val);
|
||||
|
||||
inline void fill(const eT val);
|
||||
inline void zeros();
|
||||
inline void ones();
|
||||
|
||||
@@ -334,6 +334,22 @@ subview_elem2<eT,T1,T2>::clean(const pod_type threshold)
|
||||
|
||||
|
||||
|
||||
template<typename eT, typename T1, typename T2>
|
||||
inline
|
||||
void
|
||||
subview_elem2<eT,T1,T2>::clamp(const eT min_val, const eT max_val)
|
||||
{
|
||||
arma_extra_debug_sigprint();
|
||||
|
||||
Mat<eT> tmp(*this);
|
||||
|
||||
tmp.clamp(min_val, max_val);
|
||||
|
||||
(*this).operator=(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT, typename T1, typename T2>
|
||||
inline
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user