simplifications
This commit is contained in:
@@ -26,10 +26,13 @@ class op_sp_var
|
||||
: public traits_op_xvec
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
template<typename T1>
|
||||
inline static void apply(Mat<typename T1::pod_type>& out, const mtSpToDOp<typename T1::pod_type, T1, op_sp_var>& in);
|
||||
|
||||
|
||||
template<typename T1>
|
||||
inline static void apply_slow(Mat<typename T1::elem_type>& out, const SpProxy<T1>& p, const uword norm_type, const uword dim);
|
||||
|
||||
// Calculate variance of a sparse vector, where we can directly use the memory.
|
||||
template<typename T1>
|
||||
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<typename eT>
|
||||
inline static eT direct_var(const eT* const X, const uword length, const uword N, const uword norm_type = 0);
|
||||
|
||||
|
||||
// For complex numbers.
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline static T direct_var(const std::complex<T>* const X, const uword length, const uword N, const uword norm_type = 0);
|
||||
|
||||
|
||||
// Calculate the variance using iterators, for non-complex numbers.
|
||||
template<typename T1, typename eT>
|
||||
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<eT>::result* junk2 = nullptr);
|
||||
|
||||
|
||||
// Calculate the variance using iterators, for complex numbers.
|
||||
template<typename T1, typename eT>
|
||||
inline static typename get_pod_type<eT>::result iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only<eT>::result* junk2 = nullptr);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -28,9 +28,6 @@ op_sp_var::apply(Mat<typename T1::pod_type>& out, const mtSpToDOp<typename T1::p
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
typedef typename T1::elem_type in_eT;
|
||||
//typedef typename T1::pod_type out_eT;
|
||||
|
||||
const uword norm_type = in.aux_uword_a;
|
||||
const uword dim = in.aux_uword_b;
|
||||
|
||||
@@ -42,13 +39,43 @@ op_sp_var::apply(Mat<typename T1::pod_type>& out, const mtSpToDOp<typename T1::p
|
||||
const uword p_n_rows = p.get_n_rows();
|
||||
const uword p_n_cols = p.get_n_cols();
|
||||
|
||||
if( (p_n_rows == 0) || (p_n_cols == 0) || (p.get_n_nonzero() == 0) )
|
||||
{
|
||||
if(dim == 0) { out.zeros((p_n_rows > 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<typename T1>
|
||||
inline
|
||||
void
|
||||
op_sp_var::apply_slow
|
||||
(
|
||||
Mat<typename T1::elem_type>& out,
|
||||
const SpProxy<T1>& 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<typename T1::pod_type>& out, const mtSpToDOp<typename T1::p
|
||||
else
|
||||
if(dim == 1) // find variance in each row
|
||||
{
|
||||
arma_debug_print("op_sp_var::apply_noalias(): dim = 1");
|
||||
arma_debug_print("op_sp_var::apply_slow(): dim = 1");
|
||||
|
||||
out.zeros(p_n_rows, (p_n_cols > 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user