示例#1
0
文件: fn_norm.hpp 项目: iirob/wire
inline
arma_warn_unused
typename T1::pod_type
norm
  (
  const Base<typename T1::elem_type,T1>& X,
  const char* method,
  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 char sig    = method[0];
  const bool is_vec = (A.get_n_rows() == 1) || (A.get_n_cols() == 1);
  
  if(is_vec == true)
    {
    if( (sig == 'i') || (sig == 'I') || (sig == '+') )   // max norm
      {
      return arma_vec_norm_max(A);
      }
    else
    if(sig == '-')   // min norm
      {
      return arma_vec_norm_min(A);
      }
    else
    if( (sig == 'f') || (sig == 'F') )
      {
      return arma_vec_norm_2(A);
      }
    else
      {
      arma_stop("norm(): unsupported vector norm type");
      return T(0);
      }
    }
  else
    {
    if( (sig == 'i') || (sig == 'I') || (sig == '+') )   // inf norm
      {
      return arma_mat_norm_inf(A);
      }
    else
    if( (sig == 'f') || (sig == 'F') )
      {
      return arma_vec_norm_2(A);
      }
    else
      {
      arma_stop("norm(): unsupported matrix norm type");
      return T(0);
      }
    }
  }
示例#2
0
文件: fn_norm.hpp 项目: k8wells/452p1
inline
arma_warn_unused
typename enable_if2< is_arma_sparse_type<T1>::value, typename T1::pod_type >::result
norm
(
    const T1& X,
    const char* method,
    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 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);


    const char sig    = method[0];
    const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);

    if(is_vec == true)
    {
        if( (sig == 'i') || (sig == 'I') || (sig == '+') )   // max norm
        {
            return arma_vec_norm_max(P_fake_vector);
        }
        else if(sig == '-')  // min norm
        {
            const T val = arma_vec_norm_min(P_fake_vector);

            if( P.get_n_nonzero() < P.get_n_elem() )
            {
                return (std::min)(T(0), val);
            }
            else
            {
                return val;
            }
        }
        else if( (sig == 'f') || (sig == 'F') )
        {
            return arma_vec_norm_2(P_fake_vector);
        }
        else
        {
            arma_stop("norm(): unsupported vector norm type");
            return T(0);
        }
    }
    else
    {
        if( (sig == 'i') || (sig == 'I') || (sig == '+') )   // inf norm
        {
            return arma_mat_norm_inf(P);
        }
        else if( (sig == 'f') || (sig == 'F') )
        {
            return arma_vec_norm_2(P_fake_vector);
        }
        else
        {
            arma_stop("norm(): unsupported matrix norm type");
            return T(0);
        }
    }
}