Classes | Functions

Op_reshape

//! More...

Classes

class  op_reshape

Functions

template<typename T1 >
static void op_reshape::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_reshape > &in)
template<typename T1 >
static void op_reshape::apply (Cube< typename T1::elem_type > &out, const OpCube< T1, op_reshape > &in)

Detailed Description

//!


Function Documentation

template<typename T1 >
void op_reshape::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_reshape > &  in 
) [inline, static, inherited]

Definition at line 26 of file op_reshape_meat.hpp.

References Mat< eT >::at(), Op< T1, op_type >::aux, Op< T1, op_type >::aux_u32_a, Op< T1, op_type >::aux_u32_b, syslib::copy_elem(), unwrap_check< T1 >::M, unwrap< T1 >::M, Op< T1, op_type >::m, Mat< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, access::rw(), and Mat< eT >::set_size().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1>   tmp(in.m);
  const Mat<eT>& A = tmp.M;
  
  const u32 in_n_rows = in.aux_u32_a;
  const u32 in_n_cols = in.aux_u32_b;
  
  const u32 in_n_elem = in_n_rows * in_n_cols;
  
  arma_debug_check( (A.n_elem != in_n_elem), "reshape(): incompatible dimensions");
  
  if(in.aux == eT(0))
    {
    if(&out != &A)
      {
      out.set_size(in_n_rows, in_n_cols);
      syslib::copy_elem( out.memptr(), A.memptr(), out.n_elem );
      }
    else
      {
      access::rw(out.n_rows) = in_n_rows;
      access::rw(out.n_cols) = in_n_cols;
      }
    }
  else
    {
    unwrap_check< Mat<eT> > tmp(A, out);
    const Mat<eT>& B      = tmp.M;

    out.set_size(in_n_rows, in_n_cols);
    
    eT* out_mem = out.memptr();
    u32 i = 0;
    
    for(u32 row=0; row<B.n_rows; ++row)
      {
      for(u32 col=0; col<B.n_cols; ++col)
        {
        out_mem[i] = B.at(row,col);
        ++i;
        }
      }
      
    }
  
  }

template<typename T1 >
void op_reshape::apply ( Cube< typename T1::elem_type > &  out,
const OpCube< T1, op_reshape > &  in 
) [inline, static, inherited]

Definition at line 83 of file op_reshape_meat.hpp.

References Cube< eT >::at(), OpCube< T1, op_type >::aux, OpCube< T1, op_type >::aux_u32_a, OpCube< T1, op_type >::aux_u32_b, OpCube< T1, op_type >::aux_u32_c, syslib::copy_elem(), unwrap_cube_check< T1 >::M, unwrap_cube< T1 >::M, OpCube< T1, op_type >::m, Cube< eT >::memptr(), Cube< eT >::n_cols, Cube< eT >::n_elem, Cube< eT >::n_rows, Cube< eT >::n_slices, access::rw(), and Cube< eT >::set_size().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap_cube<T1> tmp(in.m);
  const Cube<eT>& A   = tmp.M;
  
  const u32 in_n_rows   = in.aux_u32_a;
  const u32 in_n_cols   = in.aux_u32_b;
  const u32 in_n_slices = in.aux_u32_c;
  
  const u32 in_n_elem = in_n_rows * in_n_cols * in_n_slices;
  
  arma_debug_check( (A.n_elem != in_n_elem), "reshape(): incompatible dimensions");
  
  if(in.aux == eT(0))
    {
    if(&out != &A)
      {
      out.set_size(in_n_rows, in_n_cols, in_n_slices);
      syslib::copy_elem( out.memptr(), A.memptr(), out.n_elem );
      }
    else
      {
      access::rw(out.n_rows)   = in_n_rows;
      access::rw(out.n_cols)   = in_n_cols;
      access::rw(out.n_slices) = in_n_slices;
      }
    }
  else
    {
    unwrap_cube_check< Cube<eT> > tmp(A, out);
    const Cube<eT>& B           = tmp.M;
    
    out.set_size(in_n_rows, in_n_cols, in_n_slices);
    
    eT* out_mem = out.memptr();
    u32 i = 0;
    
    for(u32 slice=0; slice<B.n_slices; ++slice)
      {
      for(u32 row=0; row<B.n_rows; ++row)
        {
        for(u32 col=0; col<B.n_cols; ++col)
          {
          out_mem[i] = B.at(row,col,slice);
          ++i;
          }
        }
      }
      
    }
  
  }