Functions

Fn_misc

//! More...

Functions

template<typename vec_type >
vec_type linspace (const typename vec_type::pod_type start, const typename vec_type::pod_type end, const u32 num)
 //! Generate a vector with 'num' elements. //! The values of the elements linearly increase from 'start' upto (and including) 'end'.
mat linspace (const double start, const double end, const u32 num)
template<typename eT , typename T1 >
const mtOp< u32, T1, op_findfind (const Base< eT, T1 > &X, const u32 k=0, const char *direction="first")
template<typename T1 >
arma_inline const T1 & real (const Base< typename T1::pod_type, T1 > &X)
template<typename T1 >
arma_inline const T1 & real (const BaseCube< typename T1::pod_type, T1 > &X)
template<typename T1 >
const mtOp< typename
T1::pod_type, T1, op_real
real (const Base< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
Cube< typename T1::pod_type > real (const BaseCube< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
const eOp< Mat< typename
T1::pod_type >, eop_zeros
imag (const Base< typename T1::pod_type, T1 > &X)
template<typename T1 >
const eOpCube< Cube< typename
T1::pod_type >, eop_cube_zeros
imag (const BaseCube< typename T1::pod_type, T1 > &X)
template<typename T1 >
const mtOp< typename
T1::pod_type, T1, op_imag
imag (const Base< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
Cube< typename T1::pod_type > imag (const BaseCube< std::complex< typename T1::pod_type >, T1 > &X)
template<typename eT >
arma_float_only< eT >::result log_add (eT log_a, eT log_b)
template<typename T1 >
arma_inline const eOp< T1,
eop_log
log (const Base< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_log
log (const BaseCube< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_log10
log10 (const Base< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_log10
log10 (const BaseCube< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_exp
exp (const Base< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_exp
exp (const BaseCube< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_abs
abs (const Base< typename T1::elem_type, T1 > &X)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_abs
abs (const BaseCube< typename T1::elem_type, T1 > &X)
template<typename T1 >
const mtOp< typename
T1::pod_type, T1, op_abs
abs (const Base< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
Mat< typename T1::pod_type > abs (const BaseCube< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
arma_inline const eOp< T1,
eop_abs
fabs (const Base< typename T1::pod_type, T1 > &X)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_abs
fabs (const BaseCube< typename T1::pod_type, T1 > &X)
template<typename T1 >
const mtOp< typename
T1::pod_type, T1, op_abs
fabs (const Base< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
arma_inline Mat< typename
T1::pod_type > 
fabs (const BaseCube< std::complex< typename T1::pod_type >, T1 > &X)
template<typename T1 >
arma_inline const eOp< T1,
eop_square
square (const Base< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_square
square (const BaseCube< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_sqrt
sqrt (const Base< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_sqrt
sqrt (const BaseCube< typename T1::elem_type, T1 > &A)
template<typename T1 >
arma_inline const T1 & conj (const Base< typename T1::pod_type, T1 > &A)
template<typename T1 >
arma_inline const T1 & conj (const BaseCube< typename T1::pod_type, T1 > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_conj
conj (const Base< std::complex< typename T1::pod_type >, T1 > &A)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_conj
conj (const BaseCube< std::complex< typename T1::pod_type >, T1 > &A)
template<typename T1 >
arma_inline const T1 & conj (const eOp< T1, eop_conj > &A)
template<typename T1 >
arma_inline const T1 & conj (const eOpCube< T1, eop_cube_conj > &A)
template<typename T1 >
arma_inline const eOp< T1,
eop_pow
pow (const Base< typename T1::elem_type, T1 > &A, const typename T1::elem_type exponent)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_pow
pow (const BaseCube< typename T1::elem_type, T1 > &A, const typename T1::elem_type exponent)
template<typename T1 >
arma_inline const eOp< T1,
eop_pow
pow (const Base< typename T1::elem_type, T1 > &A, const typename T1::elem_type::value_type exponent)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_pow
pow (const BaseCube< typename T1::elem_type, T1 > &A, const typename T1::elem_type::value_type exponent)
template<typename T1 >
arma_inline const eOp< T1,
eop_pow_int
pow (const Base< typename T1::elem_type, T1 > &A, const int exponent)
template<typename T1 >
arma_inline const eOpCube< T1,
eop_cube_pow_int
pow (const BaseCube< typename T1::elem_type, T1 > &A, const int exponent)

Detailed Description

//!


Function Documentation

template<typename vec_type >
vec_type linspace ( const typename vec_type::pod_type  start,
const typename vec_type::pod_type  end,
const u32  num 
) [inline]

//! Generate a vector with 'num' elements. //! The values of the elements linearly increase from 'start' upto (and including) 'end'.

Definition at line 30 of file fn_misc.hpp.

References Mat< eT >::memptr().

  {
  arma_extra_debug_sigprint();
  
  arma_type_check< (is_Mat<vec_type>::value == false) >::apply();
  
  arma_debug_check( (num < 2), "linspace(): num must be >= 2");
  
  typedef typename vec_type::elem_type eT;
  typedef typename vec_type::pod_type   T;
  
  const u32 n_rows = (is_Row<vec_type>::value == true) ? 1   : num;
  const u32 n_cols = (is_Row<vec_type>::value == true) ? num : 1;
  
  Mat<eT> x(n_rows, n_cols);
  eT* x_mem = x.memptr();
  
  const u32 num_m1 = num - 1;
  
  if(is_non_integral<T>::value == true)
    {
    const T delta = (end-start)/T(num_m1);
    
    for(u32 i=0; i<num_m1; ++i)
      {
      x_mem[i] = eT(start + i*delta);
      }
    
    x_mem[num_m1] = eT(end);
    }
  else
    {
    const double delta = (end >= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1);
    
    for(u32 i=0; i<num_m1; ++i)
      {
      x_mem[i] = eT(double(start) + i*delta);
      }
    
    x_mem[num_m1] = eT(end);
    }
  
  return x;
  }

mat linspace ( const double  start,
const double  end,
const u32  num 
) [inline]

Definition at line 83 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  return linspace<mat>(start, end, num);
  }

template<typename eT , typename T1 >
const mtOp<u32, T1, op_find> find ( const Base< eT, T1 > &  X,
const u32  k = 0,
const char *  direction = "first" 
) [inline]

Definition at line 94 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  const char sig = direction[0];
  
  arma_debug_check( (sig != 'f' && sig != 'F' && sig != 'l' && sig != 'L'), "find(): 3rd input argument must be \"first\" or \"last\"" );
  
  const u32 type = (sig == 'f' || sig == 'F') ? 0 : 1;
  
  return mtOp<u32, T1, op_find>(X.get_ref(), k, type);
  }

template<typename T1 >
arma_inline const T1& real ( const Base< typename T1::pod_type, T1 > &  X  ) 

Definition at line 115 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by op_real::apply(), real(), and auxlib::svd().

  {
  arma_extra_debug_sigprint();
  
  return X.get_ref();
  }

template<typename T1 >
arma_inline const T1& real ( const BaseCube< typename T1::pod_type, T1 > &  X  ) 

Definition at line 127 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return X.get_ref();
  }

template<typename T1 >
const mtOp<typename T1::pod_type, T1, op_real> real ( const Base< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 139 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return mtOp<typename T1::pod_type, T1, op_real>( X.get_ref() );
  }

template<typename T1 >
Cube<typename T1::pod_type> real ( const BaseCube< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 151 of file fn_misc.hpp.

References real().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::pod_type T;
  
  const ProxyCube<T1> A(X.get_ref());
  
  Cube<T> out(A.n_rows, A.n_cols, A.n_slices);
  
  T* out_mem = out.memptr();
  
  for(u32 i=0; i<out.n_elem; ++i)
    {
    out_mem[i] = std::real(A[i]);
    }
  
  return out;
  }

template<typename T1 >
const eOp<Mat<typename T1::pod_type>, eop_zeros> imag ( const Base< typename T1::pod_type, T1 > &  X  )  [inline]

Definition at line 179 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by op_imag::apply(), and imag().

  {
  arma_extra_debug_sigprint();
  
  const Proxy<T1> A(X.get_ref());
  
  return eOp<Mat<typename T1::pod_type>, eop_zeros>(A.n_rows, A.n_cols);
  }

template<typename T1 >
const eOpCube<Cube<typename T1::pod_type>, eop_cube_zeros> imag ( const BaseCube< typename T1::pod_type, T1 > &  X  )  [inline]

Definition at line 193 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  const ProxyCube<T1> A(X.get_ref());
  
  return eOpCube<Cube<typename T1::pod_type>, eop_cube_zeros>(A.n_rows, A.n_cols, A.n_slices);
  }

template<typename T1 >
const mtOp<typename T1::pod_type, T1, op_imag> imag ( const Base< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 207 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return mtOp<typename T1::pod_type, T1, op_imag>( X.get_ref() );
  }

template<typename T1 >
Cube<typename T1::pod_type> imag ( const BaseCube< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 219 of file fn_misc.hpp.

References imag().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::pod_type T;
  
  const ProxyCube<T1> A(X.get_ref());
  
  Cube<T> out(A.n_rows, A.n_cols, A.n_slices);
  
  T* out_mem = out.memptr();
  
  for(u32 i=0; i<out.n_elem; ++i)
    {
    out_mem[i] = std::imag(A[i]);
    }
  
  return out;
  }

template<typename eT >
arma_float_only<eT>::result log_add ( eT  log_a,
eT  log_b 
) [inline]

Definition at line 247 of file fn_misc.hpp.

References arma_isfinite(), exp(), and log().

  {
  if(log_a < log_b)
    {
    std::swap(log_a, log_b);
    }
  
  const eT negdelta = log_b - log_a;
  
  if( (negdelta < Math<eT>::log_min()) || (arma_isfinite(negdelta) == false) )
    {
    return log_a;
    }
  else
    {
    #if defined(ARMA_HAVE_LOG1P)
      return (log_a + log1p(std::exp(negdelta)));
    #else
      return (log_a + std::log(1.0 + std::exp(negdelta)));
    #endif
    }
  }

template<typename T1 >
arma_inline const eOp<T1, eop_log> log ( const Base< typename T1::elem_type, T1 > &  A  ) 
template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_log> log ( const BaseCube< typename T1::elem_type, T1 > &  A  ) 

Definition at line 290 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_log>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOp<T1, eop_log10> log10 ( const Base< typename T1::elem_type, T1 > &  A  ) 

Definition at line 305 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by eop_aux::direct_eps(), eop_cube_core< eop_cube_type >::process(), and eop_core< eop_type >::process().

  {
  arma_extra_debug_sigprint();
  
  return eOp<T1, eop_log10>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_log10> log10 ( const BaseCube< typename T1::elem_type, T1 > &  A  ) 

Definition at line 317 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_log10>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOp<T1, eop_exp> exp ( const Base< typename T1::elem_type, T1 > &  A  ) 

Definition at line 332 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

Referenced by log_add(), eop_cube_core< eop_cube_type >::process(), eop_core< eop_type >::process(), and trunc_exp().

  {
  arma_extra_debug_sigprint();
  
  return eOp<T1, eop_exp>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_exp> exp ( const BaseCube< typename T1::elem_type, T1 > &  A  ) 

Definition at line 344 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_exp>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOp<T1, eop_abs> abs ( const Base< typename T1::elem_type, T1 > &  X  ) 
template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_abs> abs ( const BaseCube< typename T1::elem_type, T1 > &  X  ) 

Definition at line 372 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_abs>(X.get_ref());
  }

template<typename T1 >
const mtOp<typename T1::pod_type, T1, op_abs> abs ( const Base< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 384 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return mtOp<typename T1::pod_type, T1, op_abs>( X.get_ref() );
  }

template<typename T1 >
Mat<typename T1::pod_type> abs ( const BaseCube< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 396 of file fn_misc.hpp.

References abs(), Cube< eT >::memptr(), and Cube< eT >::n_elem.

  {
  arma_extra_debug_sigprint();
  
  const ProxyCube<T1> A(X.get_ref());

  // if T1 is a complex matrix,
  // pod_type is the underlying type used by std::complex;
  // otherwise pod_type is the same as elem_type
  
  typedef typename T1::elem_type  in_eT;
  typedef typename T1::pod_type  out_eT;

  Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
  
  out_eT* out_mem = out.memptr();
  
  for(u32 i=0; i<out.n_elem; ++i)
    {
    out_mem[i] = std::abs(A[i]);
    }
  
  return out;
  }

template<typename T1 >
arma_inline const eOp<T1, eop_abs> fabs ( const Base< typename T1::pod_type, T1 > &  X  ) 

Definition at line 429 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOp<T1, eop_abs>(X.get_ref());
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_abs> fabs ( const BaseCube< typename T1::pod_type, T1 > &  X  ) 

Definition at line 441 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_abs>(X.get_ref());
  }

template<typename T1 >
const mtOp<typename T1::pod_type, T1, op_abs> fabs ( const Base< std::complex< typename T1::pod_type >, T1 > &  X  )  [inline]

Definition at line 453 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return mtOp<typename T1::pod_type, T1, op_abs>( X.get_ref() );
  }

template<typename T1 >
arma_inline Mat<typename T1::pod_type> fabs ( const BaseCube< std::complex< typename T1::pod_type >, T1 > &  X  ) 

Definition at line 465 of file fn_misc.hpp.

References abs().

  {
  arma_extra_debug_sigprint();
  
  return abs(X);
  }

template<typename T1 >
arma_inline const eOp<T1, eop_square> square ( const Base< typename T1::elem_type, T1 > &  A  ) 

Definition at line 480 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOp<T1, eop_square>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_square> square ( const BaseCube< typename T1::elem_type, T1 > &  A  ) 

Definition at line 492 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_square>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOp<T1, eop_sqrt> sqrt ( const Base< typename T1::elem_type, T1 > &  A  ) 
template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_sqrt> sqrt ( const BaseCube< typename T1::elem_type, T1 > &  A  ) 

Definition at line 519 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_sqrt>(A.get_ref());
  }

template<typename T1 >
arma_inline const T1& conj ( const Base< typename T1::pod_type, T1 > &  A  ) 
template<typename T1 >
arma_inline const T1& conj ( const BaseCube< typename T1::pod_type, T1 > &  A  ) 

Definition at line 546 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();

  return A.get_ref();
  }

template<typename T1 >
arma_inline const eOp<T1, eop_conj> conj ( const Base< std::complex< typename T1::pod_type >, T1 > &  A  ) 

Definition at line 558 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();

  return eOp<T1, eop_conj>(A.get_ref());
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_conj> conj ( const BaseCube< std::complex< typename T1::pod_type >, T1 > &  A  ) 

Definition at line 570 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();

  return eOpCube<T1, eop_cube_conj>(A.get_ref());
  }

template<typename T1 >
arma_inline const T1& conj ( const eOp< T1, eop_conj > &  A  ) 

Definition at line 582 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return A.m;
  }

template<typename T1 >
arma_inline const T1& conj ( const eOpCube< T1, eop_cube_conj > &  A  ) 

Definition at line 594 of file fn_misc.hpp.

  {
  arma_extra_debug_sigprint();
  
  return A.m;
  }

template<typename T1 >
arma_inline const eOp<T1, eop_pow> pow ( const Base< typename T1::elem_type, T1 > &  A,
const typename T1::elem_type  exponent 
)
template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_pow> pow ( const BaseCube< typename T1::elem_type, T1 > &  A,
const typename T1::elem_type  exponent 
)

Definition at line 636 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  return eOpCube<T1, eop_cube_pow>(A.get_ref(), exponent);
  }

template<typename T1 >
arma_inline const eOp<T1, eop_pow> pow ( const Base< typename T1::elem_type, T1 > &  A,
const typename T1::elem_type::value_type  exponent 
)

Definition at line 650 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  return eOp<T1, eop_pow>(A.get_ref(), eT(exponent));
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_pow> pow ( const BaseCube< typename T1::elem_type, T1 > &  A,
const typename T1::elem_type::value_type  exponent 
)

Definition at line 664 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  return eOpCube<T1, eop_cube_pow>(A.get_ref(), eT(exponent));
  }

template<typename T1 >
arma_inline const eOp<T1, eop_pow_int> pow ( const Base< typename T1::elem_type, T1 > &  A,
const int  exponent 
)

Definition at line 683 of file fn_misc.hpp.

References Base< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  if(exponent >= 0)
    {
    return eOp<T1, eop_pow_int>(A.get_ref(), exponent, 0);
    }
  else
    {
    return eOp<T1, eop_pow_int>(A.get_ref(), -exponent, 1);
    }
  }

template<typename T1 >
arma_inline const eOpCube<T1, eop_cube_pow_int> pow ( const BaseCube< typename T1::elem_type, T1 > &  A,
const int  exponent 
)

Definition at line 702 of file fn_misc.hpp.

References BaseCube< elem_type, derived >::get_ref().

  {
  arma_extra_debug_sigprint();
  
  if(exponent >= 0)
    {
    return eOpCube<T1, eop_cube_pow_int>(A.get_ref(),  exponent, 0);
    }
  else
    {
    return eOpCube<T1, eop_cube_pow_int>(A.get_ref(), -exponent, 1);
    }
  }