Ejemplo n.º 1
0
inline
arma_warn_unused
typename T1::pod_type
norm
  (
  const Base<typename T1::elem_type,T1>& X,
  const uword k,
  const typename arma_float_or_cx_only<typename T1::elem_type>::result* junk = 0
  )
  {
  arma_extra_debug_sigprint();
  arma_ignore(junk);
  
  typedef typename T1::elem_type eT;
  typedef typename T1::pod_type   T;
  
  const Proxy<T1> A(X.get_ref());
  
  if(A.get_n_elem() == 0)
    {
    return T(0);
    }
  
  const bool is_vec = (A.get_n_rows() == 1) || (A.get_n_cols() == 1);
  
  if(is_vec == true)
    {
    switch(k)
      {
      case 1:
        return arma_vec_norm_1(A);
        break;
      
      case 2:
        return arma_vec_norm_2(A);
        break;
      
      default:
        {
        arma_debug_check( (k == 0), "norm(): k must be greater than zero"   );
        return arma_vec_norm_k(A, int(k));
        }
      }
    }
  else
    {
    switch(k)
      {
      case 1:
        return arma_mat_norm_1(A);
        break;
      
      case 2:
        return arma_mat_norm_2(A);
        break;
      
      default:
        arma_stop("norm(): unsupported matrix norm type");
        return T(0);
      }
    }
  }
Ejemplo n.º 2
0
inline
arma_warn_unused
typename enable_if2< is_arma_sparse_type<T1>::value, typename T1::pod_type >::result
norm
(
    const T1& X,
    const uword k,
    const typename arma_float_or_cx_only<typename T1::elem_type>::result* junk = 0
)
{
    arma_extra_debug_sigprint();
    arma_ignore(junk);

    typedef typename T1::elem_type eT;
    typedef typename T1::pod_type   T;

    const SpProxy<T1> P(X);

    if(P.get_n_nonzero() == 0)
    {
        return T(0);
    }

    const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);

    if(is_vec == true)
    {
        const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q);
        const SpMat<eT>& A = tmp.M;

        // create a fake dense vector to allow reuse of code for dense vectors
        Col<eT> fake_vector( access::rwp(A.values), A.n_nonzero, false );

        const Proxy< Col<eT> > P_fake_vector(fake_vector);

        switch(k)
        {
        case 1:
            return arma_vec_norm_1(P_fake_vector);
            break;

        case 2:
            return arma_vec_norm_2(P_fake_vector);
            break;

        default:
        {
            arma_debug_check( (k == 0), "norm(): k must be greater than zero"   );
            return arma_vec_norm_k(P_fake_vector, int(k));
        }
        }
    }
    else
    {
        switch(k)
        {
        case 1:
            return arma_mat_norm_1(P);
            break;

        // case 2:
        //   return arma_mat_norm_2(P);
        //   break;

        default:
            arma_stop("norm(): unsupported or unimplemented norm type for sparse matrices");
            return T(0);
        }
    }
}