Ejemplo n.º 1
0
inline
void
op_mean::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_mean>& in)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const uword dim = in.aux_uword_a;
  arma_debug_check( (dim > 2), "mean(): parameter 'dim' must be 0 or 1 or 2" );
  
  const ProxyCube<T1> P(in.m);
  
  if(P.is_alias(out) == false)
    {
    op_mean::apply_noalias(out, P, dim);
    }
  else
    {
    Cube<eT> tmp;
    
    op_mean::apply_noalias(tmp, P, dim);
    
    out.steal_mem(tmp);
    }
  }
inline
void
op_cx_scalar_div_post::apply
  (
           Cube< typename std::complex<typename T1::pod_type> >& out,
  const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_div_post>& X
  )
  {
  arma_extra_debug_sigprint();
  
  typedef typename std::complex<typename T1::pod_type> eT;
  
  const ProxyCube<T1> A(X.m);
  
  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  
  const eT    k       = X.aux_out_eT;
  const uword n_elem  = out.n_elem;
        eT*   out_mem = out.memptr();
  
  for(uword i=0; i<n_elem; ++i)
    {
    out_mem[i] = A[i] / k;
    }
  }
inline
void
op_cx_scalar_times::apply
  (
           Cube< typename std::complex<typename T1::pod_type> >& out,
  const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>& X
  )
  {
  arma_extra_debug_sigprint();
  
  typedef typename std::complex<typename T1::pod_type> eT;
  
  const ProxyCube<T1> A(X.m);
  
  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  
  const eT    k       = X.aux_out_eT;
  const uword n_elem  = out.n_elem;
        eT*   out_mem = out.memptr();
  
  // TODO: implement handling for ProxyCube<T1>::prefer_at_accessor == true
  for(uword i=0; i<n_elem; ++i)
    {
    out_mem[i] = A[i] * k;
    }
  }
Ejemplo n.º 4
0
inline
void
glue_mixed_schur::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT1;
  typedef typename T2::elem_type eT2;
  
  typedef typename promote_type<eT1,eT2>::result out_eT;
  
  promote_type<eT1,eT2>::check();
  
  const ProxyCube<T1> A(X.A);
  const ProxyCube<T2> B(X.B);
  
  arma_debug_assert_same_size(A, B, "element-wise cube multiplication");
  
  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  
        out_eT* out_mem = out.memptr();
  const u32     n_elem  = out.n_elem;
  
  for(u32 i=0; i<n_elem; ++i)
    {
    out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::apply(B[i]);
    }
  }
Ejemplo n.º 5
0
inline
void
glue_mixed_div::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_div>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT1;
  typedef typename T2::elem_type eT2;
  
  typedef typename promote_type<eT1,eT2>::result out_eT;
  
  promote_type<eT1,eT2>::check();
  
  const ProxyCube<T1> A(X.A);
  const ProxyCube<T2> B(X.B);
  
  arma_debug_assert_same_size(A, B, "element-wise division");
  
  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  
        out_eT* out_mem = out.memptr();
  const uword     n_elem  = out.n_elem;
  
  // TODO: add faster handling of subviews
  
  for(uword i=0; i<n_elem; ++i)
    {
    out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::apply(B[i]);
    }
  }
Ejemplo n.º 6
0
arma_hot
arma_warn_unused
inline
typename T1::elem_type
accu(const BaseCube<typename T1::elem_type,T1>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type          eT;
  typedef typename ProxyCube<T1>::ea_type ea_type;
  
  const ProxyCube<T1> A(X.get_ref());
  
        ea_type P      = A.get_ea();
  const u32     n_elem = A.get_n_elem();
  
  eT val1 = eT(0);
  eT val2 = eT(0);
  
  u32 i,j;
  
  for(i=0, j=1; j<n_elem; i+=2, j+=2)
    {
    val1 += P[i];
    val2 += P[j];
    }
  
  if(i < n_elem)
    {
    val1 += P[i];
    }
  
  return val1 + val2;
  }
Ejemplo n.º 7
0
inline
const GenCube<typename T1::pod_type, gen_zeros>
imag(const BaseCube<typename T1::pod_type,T1>& X)
  {
  arma_extra_debug_sigprint();
  
  const ProxyCube<T1> A(X.get_ref());
  
  return GenCube<typename T1::pod_type, gen_zeros>(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  }
Ejemplo n.º 8
0
arma_warn_unused
inline
uword
size(const BaseCube<typename T1::elem_type, T1>& X, const uword dim)
  {
  arma_extra_debug_sigprint();
  
  const ProxyCube<T1> P(X.get_ref());
  
  return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() )( dim );
  }
Ejemplo n.º 9
0
inline
void
glue_max::apply(Cube< std::complex<T> >& out, const ProxyCube<T1>& PA, const ProxyCube<T2>& PB)
  {
  arma_extra_debug_sigprint();
  
  typedef typename std::complex<T> eT;
  
  const uword n_rows   = PA.get_n_rows();
  const uword n_cols   = PA.get_n_cols();
  const uword n_slices = PA.get_n_slices();
  
  arma_debug_assert_same_size(n_rows, n_cols, n_slices, PB.get_n_rows(), PB.get_n_cols(), PB.get_n_slices(), "max(): given cubes must have the same size");
  
  out.set_size(n_rows, n_cols, n_slices);
  
  eT* out_mem = out.memptr();
  
  if( (ProxyCube<T1>::use_at == false) && (ProxyCube<T2>::use_at == false) )
    {
    typename ProxyCube<T1>::ea_type A = PA.get_ea();
    typename ProxyCube<T2>::ea_type B = PB.get_ea();
    
    const uword N = PA.get_n_elem();
    
    for(uword i=0; i<N; ++i)
      {
      const eT A_val = A[i];
      const eT B_val = B[i];
      
      out_mem[i] = ( std::abs(A_val) > std::abs(B_val) ) ? A_val : B_val;
      }
    }
  else
    {
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword   col=0;   col < n_cols;   ++col  )
    for(uword   row=0;   row < n_rows;   ++row  )
      {
      const eT A_val = PA.at(row,col,slice);
      const eT B_val = PB.at(row,col,slice);
      
      *out_mem = ( std::abs(A_val) > std::abs(B_val) ) ? A_val : B_val;
      
      ++out_mem;
      }
    }
  }
Ejemplo n.º 10
0
arma_hot
arma_warn_unused
inline
typename T1::elem_type
accu(const BaseCube<typename T1::elem_type,T1>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type          eT;
  typedef typename ProxyCube<T1>::ea_type ea_type;
  
  const ProxyCube<T1> A(X.get_ref());
  
  if(ProxyCube<T1>::prefer_at_accessor == false)
    {
    
          ea_type P      = A.get_ea();
    const uword   n_elem = A.get_n_elem();
    
    eT val1 = eT(0);
    eT val2 = eT(0);
    
    uword i,j;
    
    for(i=0, j=1; j<n_elem; i+=2, j+=2)
      {
      val1 += P[i];
      val2 += P[j];
      }
    
    if(i < n_elem)
      {
      val1 += P[i];
      }
    
    return val1 + val2;
    }
  else
    {
    const uword n_rows   = A.get_n_rows();
    const uword n_cols   = A.get_n_cols();
    const uword n_slices = A.get_n_slices();
    
    eT val = eT(0);
    
    for(uword slice=0; slice<n_slices; ++slice)
      {
      for(uword col=0; col<n_cols; ++col)
        {
        for(uword row=0; row<n_rows; ++row)
          {
          val += A.at(row,col,slice);
          }
        }
      }
    
    return val;
    }
  }
Ejemplo n.º 11
0
inline
void
glue_mixed_schur::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT1;
  typedef typename T2::elem_type eT2;
  
  typedef typename promote_type<eT1,eT2>::result out_eT;
  
  promote_type<eT1,eT2>::check();
  
  const ProxyCube<T1> A(X.A);
  const ProxyCube<T2> B(X.B);
  
  arma_debug_assert_same_size(A, B, "element-wise multiplication");
  
  const uword n_rows   = A.get_n_rows();
  const uword n_cols   = A.get_n_cols();
  const uword n_slices = A.get_n_slices();

  out.set_size(n_rows, n_cols, n_slices);
  
        out_eT* out_mem = out.memptr();
  const uword    n_elem = out.n_elem;
  
  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
  
  if(prefer_at_accessor == false)
    {
    typename ProxyCube<T1>::ea_type AA = A.get_ea();
    typename ProxyCube<T2>::ea_type BB = B.get_ea();
    
    for(uword i=0; i<n_elem; ++i)
      {
      out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) * upgrade_val<eT1,eT2>::apply(BB[i]);
      }
    }
  else
    {
    uword i = 0;
    
    for(uword slice = 0; slice < n_slices; ++slice)
    for(uword col   = 0; col   < n_cols;   ++col  )
    for(uword row   = 0; row   < n_rows;   ++row  )
      {
      out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col,slice)) * upgrade_val<eT1,eT2>::apply(B.at(row,col,slice));
      ++i;
      }
    }
  }
Ejemplo n.º 12
0
inline
arma_warn_unused
uword
BaseCube<elem_type,derived>::index_min() const
  {
  const ProxyCube<derived> P( (*this).get_ref() );
  
  uword index = 0;
  
  if(P.get_n_elem() == 0)
    {
    arma_debug_check(true, "index_min(): object has no elements");
    }
  else
    {
    op_min::min_with_index(P, index);
    }
  
  return index;
  }
Ejemplo n.º 13
0
inline
void
op_imag::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1::pod_type, T1, op_imag>& X )
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::pod_type T;
  
  const ProxyCube<T1> A(X.m);
  
  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
  
  const u32 n_elem  = out.n_elem;
        T*  out_mem = out.memptr();
  
  for(u32 i=0; i<n_elem; ++i)
    {
    out_mem[i] = std::imag(A[i]);
    }
  }
Ejemplo n.º 14
0
inline
void
glue_min::apply(Cube<eT>& out, const ProxyCube<T1>& PA, const ProxyCube<T2>& PB)
  {
  arma_extra_debug_sigprint();
  
  const uword n_rows   = PA.get_n_rows();
  const uword n_cols   = PA.get_n_cols();
  const uword n_slices = PA.get_n_slices();
  
  arma_debug_assert_same_size(n_rows, n_cols, n_slices, PB.get_n_rows(), PB.get_n_cols(), PB.get_n_slices(), "min(): given cubes must have the same size");
  
  out.set_size(n_rows, n_cols, n_slices);
  
  eT* out_mem = out.memptr();
  
  if( (ProxyCube<T1>::use_at == false) && (ProxyCube<T2>::use_at == false) )
    {
    typename ProxyCube<T1>::ea_type A = PA.get_ea();
    typename ProxyCube<T2>::ea_type B = PB.get_ea();
    
    const uword N = PA.get_n_elem();
    
    for(uword i=0; i<N; ++i)
      {
      out_mem[i] = (std::min)(A[i], B[i]);
      }
    }
  else
    {
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword   col=0;   col < n_cols;   ++col  )
    for(uword   row=0;   row < n_rows;   ++row  )
      {
      *out_mem = (std::min)( PA.at(row,col,slice), PB.at(row,col,slice) );
      
      ++out_mem;
      }
    }
  }
inline
void
op_vectorise_cube_col::apply_proxy(Mat<typename T1::elem_type>& out, const ProxyCube<T1>& P)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const uword N = P.get_n_elem();
  
  out.set_size(N, 1);
  
  if(is_Cube<typename ProxyCube<T1>::stored_type>::value == true)
    {
    const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);
    
    arrayops::copy(out.memptr(), tmp.M.memptr(), N);
    }
  else
    {
    eT* outmem = out.memptr();
    
    if(ProxyCube<T1>::use_at == false)
      {
      typename ProxyCube<T1>::ea_type A = P.get_ea();
      
      uword i,j;
      
      for(i=0, j=1; j < N; i+=2, j+=2)
        {
        const eT tmp_i = A[i];
        const eT tmp_j = A[j];
        
        outmem[i] = tmp_i;
        outmem[j] = tmp_j;
        }
      
      if(i < N)
        {
        outmem[i] = A[i];
        }
      }
    else
      {
      const uword n_rows   = P.get_n_rows();
      const uword n_cols   = P.get_n_cols();
      const uword n_slices = P.get_n_slices();
      
      for(uword slice=0; slice < n_slices; ++slice)
      for(uword   col=0;   col < n_cols;   ++col  )
      for(uword   row=0;   row < n_rows;   ++row  )
        {
        *outmem = P.at(row,col,slice);
        outmem++;
        }
      }
    }
  }
Ejemplo n.º 16
0
inline
typename arma_not_cx<typename T1::elem_type>::result
op_min::min_with_index(const ProxyCube<T1>& P, uword& index_of_min_val)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const uword n_elem = P.get_n_elem();
  
  if(n_elem == 0)
    {
    arma_debug_check(true, "min(): object has no elements");
    
    return Datum<eT>::nan;
    }
  
  eT    best_val   = priv::most_pos<eT>();
  uword best_index = 0;
  
  if(ProxyCube<T1>::use_at == false)
    {
    typedef typename ProxyCube<T1>::ea_type ea_type;
    
    ea_type A = P.get_ea();
    
    for(uword i=0; i < n_elem; ++i)
      {
      const eT tmp = A[i];
      
      if(tmp < best_val)  { best_val = tmp;  best_index = i; }
      }
    }
  else
    {
    const uword n_rows   = P.get_n_rows();
    const uword n_cols   = P.get_n_cols();
    const uword n_slices = P.get_n_slices();
    
    uword count = 0;
    
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword   col=0;   col < n_cols;   ++col  )
    for(uword   row=0;   row < n_rows;   ++row  )
      {
      const eT tmp = P.at(row,col,slice);
      
      if(tmp < best_val)  { best_val = tmp;  best_index = count; }
      
      ++count;
      }
    }
  
  index_of_min_val = best_index;
  
  return best_val;
  }
Ejemplo n.º 17
0
inline
void
glue_max::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1, T2, glue_max>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const ProxyCube<T1> PA(X.A);
  const ProxyCube<T2> PB(X.B);
  
  if(PA.is_alias(out) || PB.is_alias(out))
    {
    Cube<eT> tmp;
    
    glue_max::apply(tmp, PA, PB);
    
    out.steal_mem(tmp);
    }
  else
    {
    glue_max::apply(out, PA, PB);
    }
  }
Ejemplo n.º 18
0
inline
void
op_real::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1::pod_type, T1, op_real>& X )
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::pod_type T;
  
  const ProxyCube<T1> P(X.m);
  
  const uword n_rows   = P.get_n_rows();
  const uword n_cols   = P.get_n_cols();
  const uword n_slices = P.get_n_slices();
    
  out.set_size(n_rows, n_cols, n_slices);
  
  T* out_mem = out.memptr();

  if(ProxyCube<T1>::prefer_at_accessor == false)
    {
    typedef typename ProxyCube<T1>::ea_type ea_type;
    
    const uword   n_elem  = P.get_n_elem();
          ea_type A       = P.get_ea();
    
    for(uword i=0; i < n_elem; ++i)
      {
      out_mem[i] = std::real( A[i] );
      }
    }
  else
    {
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword col=0;   col   < n_cols;   ++col  )
    for(uword row=0;   row   < n_rows;   ++row  )
      {
      *out_mem = std::real( P.at(row,col,slice) );
      out_mem++;
      }
    }
  }
Ejemplo n.º 19
0
arma_hot
inline
void
arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, const char* x)
{
    const uword A_n_rows   = A.get_n_rows();
    const uword A_n_cols   = A.get_n_cols();
    const uword A_n_slices = A.get_n_slices();

    const uword B_n_rows   = B.get_n_rows();
    const uword B_n_cols   = B.get_n_cols();
    const uword B_n_slices = B.get_n_slices();

    if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices))
    {
        arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) );
    }
}
Ejemplo n.º 20
0
inline
typename arma_cx_only<typename T1::elem_type>::result
op_min::min(const BaseCube<typename T1::elem_type,T1>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type            eT;
  typedef typename get_pod_type<eT>::result T;
  
  const ProxyCube<T1> P(X.get_ref());
  
  const uword n_elem = P.get_n_elem();
  
  if(n_elem == 0)
    {
    arma_debug_check(true, "min(): object has no elements");
    
    return Datum<eT>::nan;
    }
  
  T min_val = priv::most_pos<T>();
  
  if(ProxyCube<T1>::use_at == false)
    {
    typedef typename ProxyCube<T1>::ea_type ea_type;
    
    ea_type A = P.get_ea();
    
    uword index = 0;
    
    for(uword i=0; i<n_elem; ++i)
      {
      const T tmp = std::abs(A[i]);
      
      if(tmp < min_val)
        {
        min_val = tmp;
        index   = i;
        }
      }
    
    return( A[index] );
    }
  else
    {
    const uword n_rows   = P.get_n_rows();
    const uword n_cols   = P.get_n_cols();
    const uword n_slices = P.get_n_slices();
    
    eT min_val_orig = eT(0);
    
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword   col=0;   col < n_cols;   ++col  )
    for(uword   row=0;   row < n_rows;   ++row  )
      {
      const eT tmp_orig = P.at(row,col,slice);
      const  T tmp      = std::abs(tmp_orig);
      
      if(tmp < min_val)
        {
        min_val      = tmp;
        min_val_orig = tmp_orig;
        }
      }
    
    return min_val_orig;
    }
  }
Ejemplo n.º 21
0
inline
typename arma_not_cx<typename T1::elem_type>::result
op_min::min(const BaseCube<typename T1::elem_type,T1>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const ProxyCube<T1> P(X.get_ref());
  
  const uword n_elem = P.get_n_elem();
  
  if(n_elem == 0)
    {
    arma_debug_check(true, "min(): object has no elements");
    
    return Datum<eT>::nan;
    }
  
  eT min_val = priv::most_pos<eT>();
  
  if(ProxyCube<T1>::use_at == false)
    {
    typedef typename ProxyCube<T1>::ea_type ea_type;
    
    ea_type A = P.get_ea();
    
    uword i,j;
    
    for(i=0, j=1; j<n_elem; i+=2, j+=2)
      {
      const eT tmp_i = A[i];
      const eT tmp_j = A[j];
      
      if(tmp_i < min_val) { min_val = tmp_i; }
      if(tmp_j < min_val) { min_val = tmp_j; }
      }
    
    if(i < n_elem)
      {
      const eT tmp_i = A[i];
      
      if(tmp_i < min_val) { min_val = tmp_i; }
      }
    }
  else
    {
    const uword n_rows   = P.get_n_rows();
    const uword n_cols   = P.get_n_cols();
    const uword n_slices = P.get_n_slices();
    
    for(uword slice=0; slice < n_slices; ++slice)
    for(uword   col=0;   col < n_cols;   ++col  )
    for(uword   row=0;   row < n_rows;   ++row  )
      {
      const eT tmp = P.at(row,col,slice);

      if(tmp < min_val) { min_val = tmp; }
      }
    }
  
  return min_val;
  }