| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 24 | |
| | | | |
| //! \addtogroup Mat | | //! \addtogroup Mat | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::~Mat() | | Mat<eT>::~Mat() | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
|
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | if(use_aux_mem == false) | |
| { | | { | |
|
| delete [] mem; | | if(n_elem > sizeof(mem_local)/sizeof(eT) ) | |
| | | { | |
| | | delete [] mem; | |
| | | } | |
| } | | } | |
| | | | |
| if(arma_config::debug == true) | | if(arma_config::debug == true) | |
| { | | { | |
| // try to expose buggy user code that accesses deleted objects | | // try to expose buggy user code that accesses deleted objects | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| access::rw(n_elem) = 0; | | access::rw(n_elem) = 0; | |
| access::rw(mem) = 0; | | access::rw(mem) = 0; | |
| } | | } | |
| | | | |
| isnt_supported_elem_type<eT>::check(); | | isnt_supported_elem_type<eT>::check(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat() | | Mat<eT>::Mat() | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
| //! construct the matrix to have user specified dimensions | | //! construct the matrix to have user specified dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const u32 in_n_rows, const u32 in_n_cols) | | Mat<eT>::Mat(const u32 in_n_rows, const u32 in_n_cols) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(in_n_rows, in_n_cols); | | init(in_n_rows, in_n_cols); | |
| } | | } | |
| | | | |
|
| //! change the matrix to have user specified dimensions (data is not preser | | | |
| ved) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Mat<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| arma_extra_debug_sigprint(arma_boost::format("in_n_rows = %d, in_n_cols = | | | |
| %d") % in_n_rows % in_n_cols); | | | |
| | | | |
| init(in_n_rows,in_n_cols); | | | |
| } | | | |
| | | | |
| //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | | //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::init(const u32 in_n_rows, const u32 in_n_cols) | | Mat<eT>::init(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | |
| | | | |
| const u32 new_n_elem = in_n_rows * in_n_cols; | | const u32 new_n_elem = in_n_rows * in_n_cols; | |
| | | | |
| if(n_elem == new_n_elem) | | if(n_elem == new_n_elem) | |
| { | | { | |
| access::rw(n_rows) = in_n_rows; | | access::rw(n_rows) = in_n_rows; | |
| access::rw(n_cols) = in_n_cols; | | access::rw(n_cols) = in_n_cols; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | arma_debug_check | |
| | | ( | |
| | | (use_aux_mem == true), | |
| | | "Mat::init(): can't change the amount of memory as auxiliary memory i | |
| | | s in use" | |
| | | ); | |
| | | | |
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | if(n_elem > sizeof(mem_local)/sizeof(eT) ) | |
| { | | { | |
| delete [] mem; | | delete [] mem; | |
| } | | } | |
| | | | |
| if(new_n_elem <= sizeof(mem_local)/sizeof(eT) ) | | if(new_n_elem <= sizeof(mem_local)/sizeof(eT) ) | |
| { | | { | |
| access::rw(mem) = mem_local; | | access::rw(mem) = mem_local; | |
| } | | } | |
| | | | |
| skipping to change at line 126 | | skipping to change at line 125 | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| } | | } | |
| else | | else | |
| { | | { | |
| access::rw(n_rows) = in_n_rows; | | access::rw(n_rows) = in_n_rows; | |
| access::rw(n_cols) = in_n_cols; | | access::rw(n_cols) = in_n_cols; | |
| } | | } | |
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const char* text) | | Mat<eT>::Mat(const char* text) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init( std::string(text) ); | | init( std::string(text) ); | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 163 | | skipping to change at line 162 | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const std::string& text) | | Mat<eT>::Mat(const std::string& text) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(text); | | init(text); | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 237 | | skipping to change at line 237 | |
| } | | } | |
| else | | else | |
| arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent n
umber of columns in given string"); | | arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent n
umber of columns in given string"); | |
| | | | |
| ++t_n_rows; | | ++t_n_rows; | |
| } | | } | |
| line_start = line_end+1; | | line_start = line_end+1; | |
| | | | |
| } | | } | |
| | | | |
|
| Mat<eT> &x = *this; | | Mat<eT>& x = *this; | |
| x.set_size(t_n_rows, t_n_cols); | | x.set_size(t_n_rows, t_n_cols); | |
| | | | |
| line_start = 0; | | line_start = 0; | |
| line_end = 0; | | line_end = 0; | |
| | | | |
| u32 row = 0; | | u32 row = 0; | |
| | | | |
| while( line_start < text.length() ) | | while( line_start < text.length() ) | |
| { | | { | |
| | | | |
| | | | |
| skipping to change at line 358 | | skipping to change at line 358 | |
| { | | { | |
| access::rw(mem[i]) /= val; | | access::rw(mem[i]) /= val; | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a matrix from a given matrix | | //! construct a matrix from a given matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Mat<eT>::Mat(const Mat<eT> &in_mat) | | Mat<eT>::Mat(const Mat<eT>& in_mat) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") %
this % &in_mat); | | arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") %
this % &in_mat); | |
| | | | |
| init(in_mat); | | init(in_mat); | |
| } | | } | |
| | | | |
| //! construct a matrix from a given matrix | | //! construct a matrix from a given matrix | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 386 | | skipping to change at line 387 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(x); | | init(x); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a matrix from a given matrix | | //! construct a matrix from a given matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::init(const Mat<eT> &x) | | Mat<eT>::init(const Mat<eT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(this != &x) | | if(this != &x) | |
| { | | { | |
| init(x.n_rows, x.n_cols); | | init(x.n_rows, x.n_cols); | |
| syslib::copy_elem( memptr(), x.mem, n_elem ); | | syslib::copy_elem( memptr(), x.mem, n_elem ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! construct a matrix from a given auxillary array of eTs | | //! construct a matrix from a given auxiliary array of eTs. | |
| | | //! if copy_aux_mem is true, new memory is allocated and the array is copie | |
| | | d. | |
| | | //! if copy_aux_mem is false, the auxiliary array is used directly (without | |
| | | allocating memory and copying). | |
| | | //! the default is to copy the array. | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::Mat(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const | |
| | | bool copy_aux_mem) | |
| | | : n_rows (copy_aux_mem ? 0 : aux_n_rows ) | |
| | | , n_cols (copy_aux_mem ? 0 : aux_n_cols ) | |
| | | , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols) | |
| | | , use_aux_mem(copy_aux_mem ? false : true ) | |
| | | , mem (copy_aux_mem ? mem : aux_mem ) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | if(copy_aux_mem == true) | |
| | | { | |
| | | init(aux_n_rows, aux_n_cols); | |
| | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| | | } | |
| | | } | |
| | | | |
| | | //! construct a matrix from a given auxiliary read-only array of eTs. | |
| | | //! the array is copied. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | | Mat<eT>::Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(aux_n_rows, aux_n_cols); | | init(aux_n_rows, aux_n_cols); | |
| syslib::copy_elem( memptr(), aux_mem, n_elem ); | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| } | | } | |
| | | | |
|
| | | //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. | |
| | | //! This constructor is NOT intended for usage by user code. | |
| | | //! Its sole purpose is to be used by the Cube class. | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons | |
| | | t u32 aux_n_cols) | |
| | | : n_rows (aux_n_rows ) | |
| | | , n_cols (aux_n_cols ) | |
| | | , n_elem (aux_n_rows*aux_n_cols) | |
| | | , use_aux_mem(true ) | |
| | | , mem (aux_mem ) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | } | |
| | | | |
| //! in-place matrix addition | | //! in-place matrix addition | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const Mat<eT>& m) | | Mat<eT>::operator+=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| glue_plus::apply_inplace(*this, m); | | glue_plus::apply_inplace(*this, m); | |
| return *this; | | return *this; | |
| | | | |
| skipping to change at line 485 | | skipping to change at line 527 | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Mat<eT>::Mat | | Mat<eT>::Mat | |
| ( | | ( | |
| const Base<typename Mat<eT>::pod_type,T1>& A, | | const Base<typename Mat<eT>::pod_type,T1>& A, | |
| const Base<typename Mat<eT>::pod_type,T2>& B | | const Base<typename Mat<eT>::pod_type,T2>& B | |
| ) | | ) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil
e-time abort if eT isn't std::complex | | arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil
e-time abort if eT isn't std::complex | |
| | | | |
| typedef typename T1::elem_type T; | | typedef typename T1::elem_type T; | |
| arma_type_check< is_complex<T>::value == true >::apply(); //!< compile-
time abort if T is std::complex | | arma_type_check< is_complex<T>::value == true >::apply(); //!< compile-
time abort if T is std::complex | |
| | | | |
| | | | |
| skipping to change at line 523 | | skipping to change at line 566 | |
| } | | } | |
| } | | } | |
| | | | |
| //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | | //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const subview<eT>& X) | | Mat<eT>::Mat(const subview<eT>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | | //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 603 | | skipping to change at line 647 | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const subview<eT>& X) | | Mat<eT>::operator/=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::div_inplace(*this, X); | | subview<eT>::div_inplace(*this, X); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| | | //! construct a matrix from a subview_cube instance | |
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::Mat(const subview_cube<eT>& x) | |
| | | : n_rows(0) | |
| | | , n_cols(0) | |
| | | , n_elem(0) | |
| | | , use_aux_mem(false) | |
| | | //, mem(0) | |
| | | , mem(mem) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | this->operator=(x); | |
| | | } | |
| | | | |
| | | //! construct a matrix from a subview_cube instance | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | subview_cube<eT>::extract(*this, X); | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! in-place matrix addition (using a single-slice subcube on the right-han | |
| | | d-side) | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator+=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | subview_cube<eT>::plus_inplace(*this, X); | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! in-place matrix subtraction (using a single-slice subcube on the right- | |
| | | hand-side) | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator-=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | subview_cube<eT>::minus_inplace(*this, X); | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! in-place matrix mutiplication (using a single-slice subcube on the righ | |
| | | t-hand-side) | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator*=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const Mat<eT> tmp(X); | |
| | | glue_times::apply_inplace(*this, tmp); | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! in-place element-wise matrix mutiplication (using a single-slice subcub | |
| | | e on the right-hand-side) | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator%=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | subview_cube<eT>::schur_inplace(*this, X); | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! in-place element-wise matrix division (using a single-slice subcube on | |
| | | the right-hand-side) | |
| | | template<typename eT> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::operator/=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | subview_cube<eT>::div_inplace(*this, X); | |
| | | return *this; | |
| | | } | |
| | | | |
| //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | | //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const diagview<eT>& X) | | Mat<eT>::Mat(const diagview<eT>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | | //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 696 | | skipping to change at line 830 | |
| Mat<eT>::rows(const u32 in_row1, const u32 in_row2) | | Mat<eT>::rows(const u32 in_row1, const u32 in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| "Mat::rows(): indices out of bounds or incorrectly used" | | "Mat::rows(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, 0, in_row2, n_cols-1); | | return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0
) ); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified row vectors) | | //! creation of subview (submatrix comprised of specified row vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::rows(const u32 in_row1, const u32 in_row2) const | | Mat<eT>::rows(const u32 in_row1, const u32 in_row2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| "Mat::rows(): indices out of bounds or incorrectly used" | | "Mat::rows(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, in_row1, 0, in_row2, n_cols-1); | | return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0
) ); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified column vectors) | | //! creation of subview (submatrix comprised of specified column vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::cols(const u32 in_col1, const u32 in_col2) | | Mat<eT>::cols(const u32 in_col1, const u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| "Mat::cols(): indices out of bounds or incorrectly used" | | "Mat::cols(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, 0, in_col1, n_rows-1, in_col2); | | return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col
2); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix comprised of specified column vectors) | | //! creation of subview (submatrix comprised of specified column vectors) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::cols(const u32 in_col1, const u32 in_col2) const | | Mat<eT>::cols(const u32 in_col1, const u32 in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| "Mat::cols(): indices out of bounds or incorrectly used" | | "Mat::cols(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
|
| return subview<eT>(*this, 0, in_col1, n_rows-1, in_col2); | | return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col
2); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix) | | //! creation of subview (submatrix) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) | | Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, co
nst u32 in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 887 | | skipping to change at line 1021 | |
| } | | } | |
| | | | |
| //! create a matrix from Op, i.e. run the previously delayed unary operatio
ns | | //! create a matrix from Op, i.e. run the previously delayed unary operatio
ns | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const Op<T1, op_type>& X) | | Mat<eT>::Mat(const Op<T1, op_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| op_type::apply(*this, X); | | op_type::apply(*this, X); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 999 | | skipping to change at line 1134 | |
| } | | } | |
| | | | |
| //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | | //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) | | Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| | | , use_aux_mem(false) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | | //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| | | | |
| skipping to change at line 1308 | | skipping to change at line 1444 | |
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's flags are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print(const std::string extra_text) const | | Mat<eT>::print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
|
| | | const std::streamsize orig_width = cout.width(); | |
| | | | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
|
| | | | |
| | | cout.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, true); | | arma_ostream::print(cout, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the matrix to a user specified stream, | | //! print contents of the matrix to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's flags are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print(std::ostream& user_stream, const std::string extra_text) con
st | | Mat<eT>::print(std::ostream& user_stream, const std::string extra_text) con
st | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
|
| | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
|
| | | | |
| | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, true); | | arma_ostream::print(user_stream, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the matrix (to the cout stream), | | //! print contents of the matrix (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the stream's flags are used as is and are not modified | | //! the stream's flags are used as is and are not modified | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print(const std::string extra_text) const | | Mat<eT>::raw_print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
|
| | | const std::streamsize orig_width = cout.width(); | |
| | | | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
|
| | | | |
| | | cout.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, false); | | arma_ostream::print(cout, *this, false); | |
| } | | } | |
| | | | |
| //! print contents of the matrix to a user specified stream, | | //! print contents of the matrix to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the stream's flags are used as is and are not modified. | | //! the stream's flags are used as is and are not modified. | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print(std::ostream& user_stream, const std::string extra_text)
const | | Mat<eT>::raw_print(std::ostream& user_stream, const std::string extra_text)
const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
|
| | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
|
| | | | |
| | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, false); | | arma_ostream::print(user_stream, *this, false); | |
| } | | } | |
| | | | |
|
| | | //! change the matrix to have user specified dimensions (data is not preser | |
| | | ved) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | init(in_n_rows, in_n_cols); | |
| | | } | |
| | | | |
| | | //! change the matrix (without preserving data) to have the same dimensions | |
| | | as the given matrix | |
| | | template<typename eT> | |
| | | template<typename eT2> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::copy_size(const Mat<eT2>& m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | init(m.n_rows, m.n_cols); | |
| | | } | |
| | | | |
| //! fill the matrix with the specified value | | //! fill the matrix with the specified value | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::fill(const eT val) | | Mat<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 1409 | | skipping to change at line 1584 | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | |
| | | | |
| set_size(in_rows, in_cols); | | set_size(in_rows, in_cols); | |
| fill(eT(0)); | | fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| | | Mat<eT>::ones() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | fill(eT(1)); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::ones(const u32 in_rows, const u32 in_cols) | |
| | | { | |
| | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d | |
| | | ") % in_rows % in_cols ); | |
| | | | |
| | | set_size(in_rows, in_cols); | |
| | | fill(eT(1)); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| Mat<eT>::reset() | | Mat<eT>::reset() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(0,0); | | init(0,0); | |
| } | | } | |
| | | | |
| //! save the matrix to a file | | //! save the matrix to a file | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| | | | |
| skipping to change at line 1443 | | skipping to change at line 1639 | |
| | | | |
| case arma_binary: | | case arma_binary: | |
| diskio::save_arma_binary(*this, name); | | diskio::save_arma_binary(*this, name); | |
| break; | | break; | |
| | | | |
| case pgm_binary: | | case pgm_binary: | |
| diskio::save_pgm_binary(*this, name); | | diskio::save_pgm_binary(*this, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
|
| arma_stop("Mat::save(): unsupported type"); | | arma_stop("Mat::save(): unsupported file type"); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! load a matrix from a file | | //! load a matrix from a file | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::load(const std::string name, const file_type type) | | Mat<eT>::load(const std::string name, const file_type type) | |
| { | | { | |
| | | | |
| skipping to change at line 1479 | | skipping to change at line 1675 | |
| | | | |
| case arma_binary: | | case arma_binary: | |
| diskio::load_arma_binary(*this, name); | | diskio::load_arma_binary(*this, name); | |
| break; | | break; | |
| | | | |
| case pgm_binary: | | case pgm_binary: | |
| diskio::load_pgm_binary(*this, name); | | diskio::load_pgm_binary(*this, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
|
| arma_stop("Mat::load(): unsupported type"); | | arma_stop("Mat::load(): unsupported file type"); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! prefix ++ | | //! prefix ++ | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| void | | void | |
| Mat_aux::prefix_pp(Mat<eT>& x) | | Mat_aux::prefix_pp(Mat<eT>& x) | |
| { | | { | |
| | | | |
End of changes. 38 change blocks. |
| 26 lines changed or deleted | | 233 lines changed or added | |
|
| Mat_proto.hpp | | Mat_proto.hpp | |
| | | | |
| skipping to change at line 21 | | skipping to change at line 21 | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup Mat | | //! \addtogroup Mat | |
| //! @{ | | //! @{ | |
| | | | |
| //! Dense matrix class | | //! Dense matrix class | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class Mat : public Base<eT, Mat<eT> > | | class Mat : public Base< eT, Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; //!< the type of elements stored in the matrix | | typedef eT elem_type; //!< the type of elements stored in the matrix | |
| | | | |
| typedef typename get_pod_type<elem_type>::pod_type pod_type; | | typedef typename get_pod_type<elem_type>::pod_type pod_type; | |
| //!< if eT is std::complex, pod_type is the underlying type used by std::
complex. | | //!< if eT is std::complex, pod_type is the underlying type used by std::
complex. | |
| //!< otherwise pod_type is the same as elem_type | | //!< otherwise pod_type is the same as elem_type | |
| | | | |
|
| const u32 n_rows; //!< number of rows in the matrix (read-only) | | const u32 n_rows; //!< number of rows in the matrix (read-only) | |
| const u32 n_cols; //!< number of columns in the matrix (read-only) | | const u32 n_cols; //!< number of columns in the matrix (read-only) | |
| const u32 n_elem; //!< number of elements in the matrix (read-only) | | const u32 n_elem; //!< number of elements in the matrix (read-only) | |
| | | const bool use_aux_mem; //!< true if externally managed memory is being u | |
| | | sed (read-only) | |
| | | | |
|
| arma_aligned const eT* const mem; //!< pointer to memory used by the mat
rix (memory is read-only) | | arma_aligned const eT* const mem; //!< pointer to the memory used by the
matrix (memory is read-only) | |
| | | | |
| protected: | | protected: | |
| arma_aligned eT mem_local[ 16 ]; | | arma_aligned eT mem_local[ 16 ]; | |
| | | | |
| public: | | public: | |
| | | | |
| inline ~Mat(); | | inline ~Mat(); | |
| inline Mat(); | | inline Mat(); | |
| | | | |
|
| inline Mat(const u32 in_rows, const u32 in_cols); | | inline Mat(const u32 in_rows, const u32 in_cols); | |
| inline void set_size(const u32 in_rows, const u32 in_cols); | | | |
| | | | |
| inline Mat(const char* text); | | inline Mat(const char* text); | |
| inline const Mat& operator=(const char* text); | | inline const Mat& operator=(const char* text); | |
| inline Mat(const std::string& text); | | inline Mat(const std::string& text); | |
| inline const Mat& operator=(const std::string& text); | | inline const Mat& operator=(const std::string& text); | |
| | | | |
|
| | | inline Mat( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols,
const bool copy_aux_mem = true); | |
| inline Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
; | | inline Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
; | |
| | | | |
| arma_inline const Mat& operator=(const eT val); | | arma_inline const Mat& operator=(const eT val); | |
| arma_inline const Mat& operator+=(const eT val); | | arma_inline const Mat& operator+=(const eT val); | |
| arma_inline const Mat& operator-=(const eT val); | | arma_inline const Mat& operator-=(const eT val); | |
| arma_inline const Mat& operator*=(const eT val); | | arma_inline const Mat& operator*=(const eT val); | |
| arma_inline const Mat& operator/=(const eT val); | | arma_inline const Mat& operator/=(const eT val); | |
| | | | |
| inline Mat(const Mat& m); | | inline Mat(const Mat& m); | |
| inline const Mat& operator=(const Mat& m); | | inline const Mat& operator=(const Mat& m); | |
| | | | |
| skipping to change at line 80 | | skipping to change at line 81 | |
| inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | | inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | |
| | | | |
| inline Mat(const subview<eT>& X); | | inline Mat(const subview<eT>& X); | |
| inline const Mat& operator=(const subview<eT>& X); | | inline const Mat& operator=(const subview<eT>& X); | |
| inline const Mat& operator+=(const subview<eT>& X); | | inline const Mat& operator+=(const subview<eT>& X); | |
| inline const Mat& operator-=(const subview<eT>& X); | | inline const Mat& operator-=(const subview<eT>& X); | |
| inline const Mat& operator*=(const subview<eT>& X); | | inline const Mat& operator*=(const subview<eT>& X); | |
| inline const Mat& operator%=(const subview<eT>& X); | | inline const Mat& operator%=(const subview<eT>& X); | |
| inline const Mat& operator/=(const subview<eT>& X); | | inline const Mat& operator/=(const subview<eT>& X); | |
| | | | |
|
| | | //inline explicit Mat(const subview_cube<eT>& X); | |
| | | inline Mat(const subview_cube<eT>& X); | |
| | | inline const Mat& operator=(const subview_cube<eT>& X); | |
| | | inline const Mat& operator+=(const subview_cube<eT>& X); | |
| | | inline const Mat& operator-=(const subview_cube<eT>& X); | |
| | | inline const Mat& operator*=(const subview_cube<eT>& X); | |
| | | inline const Mat& operator%=(const subview_cube<eT>& X); | |
| | | inline const Mat& operator/=(const subview_cube<eT>& X); | |
| | | | |
| //inline explicit Mat(const diagview<eT>& X); | | //inline explicit Mat(const diagview<eT>& X); | |
| inline Mat(const diagview<eT>& X); | | inline Mat(const diagview<eT>& X); | |
| inline const Mat& operator=(const diagview<eT>& X); | | inline const Mat& operator=(const diagview<eT>& X); | |
| | | | |
| arma_inline subview_row<eT> row(const u32 row_num); | | arma_inline subview_row<eT> row(const u32 row_num); | |
| arma_inline const subview_row<eT> row(const u32 row_num) const; | | arma_inline const subview_row<eT> row(const u32 row_num) const; | |
| | | | |
| arma_inline subview_col<eT> col(const u32 col_num); | | arma_inline subview_col<eT> col(const u32 col_num); | |
| arma_inline const subview_col<eT> col(const u32 col_num) const; | | arma_inline const subview_col<eT> col(const u32 col_num) const; | |
| | | | |
| | | | |
| skipping to change at line 153 | | skipping to change at line 163 | |
| | | | |
| arma_inline eT* memptr(); | | arma_inline eT* memptr(); | |
| arma_inline const eT* memptr() const; | | arma_inline const eT* memptr() const; | |
| | | | |
| inline void print(const std::string extra_text = "") const; | | inline void print(const std::string extra_text = "") const; | |
| inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | | inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | |
| | | | |
| inline void raw_print(const std::string extra_text = "") const; | | inline void raw_print(const std::string extra_text = "") const; | |
| inline void raw_print(std::ostream& user_stream, const std::string extra_
text = "") const; | | inline void raw_print(std::ostream& user_stream, const std::string extra_
text = "") const; | |
| | | | |
|
| | | inline void set_size(const u32 in_rows, const u32 in_cols); | |
| | | | |
| | | template<typename eT2> inline void copy_size(const Mat<eT2>& m); | |
| | | | |
| inline void fill(const eT val); | | inline void fill(const eT val); | |
|
| | | | |
| inline void zeros(); | | inline void zeros(); | |
| inline void zeros(const u32 in_rows, const u32 in_cols); | | inline void zeros(const u32 in_rows, const u32 in_cols); | |
| | | | |
|
| | | inline void ones(); | |
| | | inline void ones(const u32 in_rows, const u32 in_cols); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| | | | |
| inline void save(const std::string name, const file_type type = arma_bina
ry) const; | | inline void save(const std::string name, const file_type type = arma_bina
ry) const; | |
| inline void load(const std::string name, const file_type type = auto_dete
ct); | | inline void load(const std::string name, const file_type type = auto_dete
ct); | |
| | | | |
| protected: | | protected: | |
| | | | |
| inline void init(const u32 in_rows, const u32 in_cols); | | inline void init(const u32 in_rows, const u32 in_cols); | |
| inline void init(const std::string& text); | | inline void init(const std::string& text); | |
| inline void init(const Mat& x); | | inline void init(const Mat& x); | |
|
| | | | |
| | | inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons | |
| | | t u32 aux_n_cols); | |
| | | | |
| | | friend class Cube<eT>; | |
| }; | | }; | |
| | | | |
| class Mat_aux | | class Mat_aux | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x); | | template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x); | |
| template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | | template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | | template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | |
| | | | |
End of changes. 10 change blocks. |
| 7 lines changed or deleted | | 31 lines changed or added | |
|
| armadillo | | armadillo | |
| | | | |
| skipping to change at line 133 | | skipping to change at line 133 | |
| | | | |
| #include "armadillo_bits/syslib_proto.hpp" | | #include "armadillo_bits/syslib_proto.hpp" | |
| #include "armadillo_bits/podarray_proto.hpp" | | #include "armadillo_bits/podarray_proto.hpp" | |
| | | | |
| #include "armadillo_bits/blas_proto.hpp" | | #include "armadillo_bits/blas_proto.hpp" | |
| #include "armadillo_bits/lapack_proto.hpp" | | #include "armadillo_bits/lapack_proto.hpp" | |
| #include "armadillo_bits/atlas_proto.hpp" | | #include "armadillo_bits/atlas_proto.hpp" | |
| #include "armadillo_bits/auxlib_proto.hpp" | | #include "armadillo_bits/auxlib_proto.hpp" | |
| | | | |
| #include "armadillo_bits/Base.hpp" | | #include "armadillo_bits/Base.hpp" | |
|
| | | #include "armadillo_bits/BaseCube.hpp" | |
| | | | |
| #include "armadillo_bits/Mat_proto.hpp" | | #include "armadillo_bits/Mat_proto.hpp" | |
| #include "armadillo_bits/Col_proto.hpp" | | #include "armadillo_bits/Col_proto.hpp" | |
| #include "armadillo_bits/Row_proto.hpp" | | #include "armadillo_bits/Row_proto.hpp" | |
|
| | | #include "armadillo_bits/Cube_proto.hpp" | |
| | | | |
| #include "armadillo_bits/field_proto.hpp" | | #include "armadillo_bits/field_proto.hpp" | |
| #include "armadillo_bits/subview_proto.hpp" | | #include "armadillo_bits/subview_proto.hpp" | |
| #include "armadillo_bits/subview_field_proto.hpp" | | #include "armadillo_bits/subview_field_proto.hpp" | |
|
| | | #include "armadillo_bits/subview_cube_proto.hpp" | |
| #include "armadillo_bits/diagview_proto.hpp" | | #include "armadillo_bits/diagview_proto.hpp" | |
| | | | |
| #include "armadillo_bits/diskio_proto.hpp" | | #include "armadillo_bits/diskio_proto.hpp" | |
| #include "armadillo_bits/wall_clock_proto.hpp" | | #include "armadillo_bits/wall_clock_proto.hpp" | |
| #include "armadillo_bits/running_stat_proto.hpp" | | #include "armadillo_bits/running_stat_proto.hpp" | |
| | | | |
| #include "armadillo_bits/Op_proto.hpp" | | #include "armadillo_bits/Op_proto.hpp" | |
|
| | | #include "armadillo_bits/OpCube_proto.hpp" | |
| #include "armadillo_bits/Glue_proto.hpp" | | #include "armadillo_bits/Glue_proto.hpp" | |
|
| | | #include "armadillo_bits/GlueCube_proto.hpp" | |
| | | | |
| #include "armadillo_bits/op_diagmat_proto.hpp" | | #include "armadillo_bits/op_diagmat_proto.hpp" | |
| #include "armadillo_bits/op_dot_proto.hpp" | | #include "armadillo_bits/op_dot_proto.hpp" | |
| #include "armadillo_bits/op_inv_proto.hpp" | | #include "armadillo_bits/op_inv_proto.hpp" | |
| #include "armadillo_bits/op_htrans_proto.hpp" | | #include "armadillo_bits/op_htrans_proto.hpp" | |
| #include "armadillo_bits/op_misc_proto.hpp" | | #include "armadillo_bits/op_misc_proto.hpp" | |
| #include "armadillo_bits/op_max_proto.hpp" | | #include "armadillo_bits/op_max_proto.hpp" | |
| #include "armadillo_bits/op_min_proto.hpp" | | #include "armadillo_bits/op_min_proto.hpp" | |
| #include "armadillo_bits/op_mean_proto.hpp" | | #include "armadillo_bits/op_mean_proto.hpp" | |
| #include "armadillo_bits/op_median_proto.hpp" | | #include "armadillo_bits/op_median_proto.hpp" | |
| | | | |
| skipping to change at line 169 | | skipping to change at line 176 | |
| #include "armadillo_bits/op_rand_proto.hpp" | | #include "armadillo_bits/op_rand_proto.hpp" | |
| #include "armadillo_bits/op_randn_proto.hpp" | | #include "armadillo_bits/op_randn_proto.hpp" | |
| #include "armadillo_bits/op_scalar_misc_proto.hpp" | | #include "armadillo_bits/op_scalar_misc_proto.hpp" | |
| #include "armadillo_bits/op_sort_proto.hpp" | | #include "armadillo_bits/op_sort_proto.hpp" | |
| #include "armadillo_bits/op_sum_proto.hpp" | | #include "armadillo_bits/op_sum_proto.hpp" | |
| #include "armadillo_bits/op_stddev_proto.hpp" | | #include "armadillo_bits/op_stddev_proto.hpp" | |
| #include "armadillo_bits/op_trig_proto.hpp" | | #include "armadillo_bits/op_trig_proto.hpp" | |
| #include "armadillo_bits/op_trans_proto.hpp" | | #include "armadillo_bits/op_trans_proto.hpp" | |
| #include "armadillo_bits/op_var_proto.hpp" | | #include "armadillo_bits/op_var_proto.hpp" | |
| #include "armadillo_bits/op_zeros_proto.hpp" | | #include "armadillo_bits/op_zeros_proto.hpp" | |
|
| | | #include "armadillo_bits/op_repmat_proto.hpp" | |
| | | | |
| #include "armadillo_bits/glue_plus_proto.hpp" | | #include "armadillo_bits/glue_plus_proto.hpp" | |
| #include "armadillo_bits/glue_minus_proto.hpp" | | #include "armadillo_bits/glue_minus_proto.hpp" | |
| #include "armadillo_bits/glue_times_proto.hpp" | | #include "armadillo_bits/glue_times_proto.hpp" | |
| #include "armadillo_bits/glue_schur_proto.hpp" | | #include "armadillo_bits/glue_schur_proto.hpp" | |
| #include "armadillo_bits/glue_div_proto.hpp" | | #include "armadillo_bits/glue_div_proto.hpp" | |
| | | | |
|
| | | #include "armadillo_bits/glue_cube_plus_proto.hpp" | |
| | | #include "armadillo_bits/glue_cube_minus_proto.hpp" | |
| | | #include "armadillo_bits/glue_cube_schur_proto.hpp" | |
| | | #include "armadillo_bits/glue_cube_div_proto.hpp" | |
| | | | |
| // | | // | |
| // debugging functions | | // debugging functions | |
| | | | |
| #include "armadillo_bits/debug.hpp" | | #include "armadillo_bits/debug.hpp" | |
| | | | |
|
| | | // | |
| | | // classes that underlay metaprogramming | |
| | | | |
| #include "armadillo_bits/unwrap.hpp" | | #include "armadillo_bits/unwrap.hpp" | |
|
| | | #include "armadillo_bits/unwrap_cube.hpp" | |
| | | | |
| #include "armadillo_bits/Op_meat.hpp" | | #include "armadillo_bits/Op_meat.hpp" | |
|
| | | #include "armadillo_bits/OpCube_meat.hpp" | |
| #include "armadillo_bits/Glue_meat.hpp" | | #include "armadillo_bits/Glue_meat.hpp" | |
|
| | | #include "armadillo_bits/GlueCube_meat.hpp" | |
| | | | |
| #include "armadillo_bits/glue_metaprog.hpp" | | #include "armadillo_bits/glue_metaprog.hpp" | |
|
| | | #include "armadillo_bits/glue_cube_metaprog.hpp" | |
| | | | |
| | | // | |
| | | // ostream | |
| | | | |
| | | #include "armadillo_bits/arma_ostream_proto.hpp" | |
| | | #include "armadillo_bits/arma_ostream_meat.hpp" | |
| | | | |
| // | | // | |
| // operators | | // operators | |
| | | | |
| #include "armadillo_bits/operator_plus.hpp" | | #include "armadillo_bits/operator_plus.hpp" | |
| #include "armadillo_bits/operator_minus.hpp" | | #include "armadillo_bits/operator_minus.hpp" | |
| #include "armadillo_bits/operator_times.hpp" | | #include "armadillo_bits/operator_times.hpp" | |
| #include "armadillo_bits/operator_times_dot.hpp" | | #include "armadillo_bits/operator_times_dot.hpp" | |
| #include "armadillo_bits/operator_schur.hpp" | | #include "armadillo_bits/operator_schur.hpp" | |
| #include "armadillo_bits/operator_div.hpp" | | #include "armadillo_bits/operator_div.hpp" | |
| #include "armadillo_bits/operator_relational.hpp" | | #include "armadillo_bits/operator_relational.hpp" | |
| | | | |
|
| // | | #include "armadillo_bits/operator_cube_plus.hpp" | |
| // ostream | | #include "armadillo_bits/operator_cube_minus.hpp" | |
| | | #include "armadillo_bits/operator_cube_times.hpp" | |
| | | #include "armadillo_bits/operator_cube_schur.hpp" | |
| | | #include "armadillo_bits/operator_cube_div.hpp" | |
| | | #include "armadillo_bits/operator_cube_relational.hpp" | |
| | | | |
|
| #include "armadillo_bits/ostream_mat.hpp" | | #include "armadillo_bits/operator_ostream.hpp" | |
| #include "armadillo_bits/ostream_diagmat.hpp" | | | |
| #include "armadillo_bits/ostream_field.hpp" | | | |
| #include "armadillo_bits/ostream_misc.hpp" | | | |
| | | | |
| // | | // | |
| // user accessible functions | | // user accessible functions | |
| | | | |
| #include "armadillo_bits/fn_conv_to.hpp" | | #include "armadillo_bits/fn_conv_to.hpp" | |
| #include "armadillo_bits/fn_min.hpp" | | #include "armadillo_bits/fn_min.hpp" | |
| #include "armadillo_bits/fn_max.hpp" | | #include "armadillo_bits/fn_max.hpp" | |
| #include "armadillo_bits/fn_accu.hpp" | | #include "armadillo_bits/fn_accu.hpp" | |
| #include "armadillo_bits/fn_sum.hpp" | | #include "armadillo_bits/fn_sum.hpp" | |
| #include "armadillo_bits/fn_diagmat.hpp" | | #include "armadillo_bits/fn_diagmat.hpp" | |
| | | | |
| skipping to change at line 239 | | skipping to change at line 268 | |
| #include "armadillo_bits/fn_median.hpp" | | #include "armadillo_bits/fn_median.hpp" | |
| #include "armadillo_bits/fn_stddev.hpp" | | #include "armadillo_bits/fn_stddev.hpp" | |
| #include "armadillo_bits/fn_var.hpp" | | #include "armadillo_bits/fn_var.hpp" | |
| #include "armadillo_bits/fn_sort.hpp" | | #include "armadillo_bits/fn_sort.hpp" | |
| #include "armadillo_bits/fn_sort_index.hpp" | | #include "armadillo_bits/fn_sort_index.hpp" | |
| #include "armadillo_bits/fn_htrans.hpp" | | #include "armadillo_bits/fn_htrans.hpp" | |
| #include "armadillo_bits/fn_chol.hpp" | | #include "armadillo_bits/fn_chol.hpp" | |
| #include "armadillo_bits/fn_qr.hpp" | | #include "armadillo_bits/fn_qr.hpp" | |
| #include "armadillo_bits/fn_svd.hpp" | | #include "armadillo_bits/fn_svd.hpp" | |
| #include "armadillo_bits/fn_solve.hpp" | | #include "armadillo_bits/fn_solve.hpp" | |
|
| | | #include "armadillo_bits/fn_repmat.hpp" | |
| | | | |
| // | | // | |
| // class meat | | // class meat | |
| | | | |
| #include "armadillo_bits/gemm.hpp" | | #include "armadillo_bits/gemm.hpp" | |
| #include "armadillo_bits/gemv.hpp" | | #include "armadillo_bits/gemv.hpp" | |
| #include "armadillo_bits/gemm_mixed.hpp" | | #include "armadillo_bits/gemm_mixed.hpp" | |
| | | | |
| #include "armadillo_bits/podarray_meat.hpp" | | #include "armadillo_bits/podarray_meat.hpp" | |
| #include "armadillo_bits/auxlib_meat.hpp" | | #include "armadillo_bits/auxlib_meat.hpp" | |
| | | | |
| #include "armadillo_bits/Mat_meat.hpp" | | #include "armadillo_bits/Mat_meat.hpp" | |
| #include "armadillo_bits/Col_meat.hpp" | | #include "armadillo_bits/Col_meat.hpp" | |
| #include "armadillo_bits/Row_meat.hpp" | | #include "armadillo_bits/Row_meat.hpp" | |
|
| | | #include "armadillo_bits/Cube_meat.hpp" | |
| #include "armadillo_bits/field_meat.hpp" | | #include "armadillo_bits/field_meat.hpp" | |
| #include "armadillo_bits/subview_meat.hpp" | | #include "armadillo_bits/subview_meat.hpp" | |
| #include "armadillo_bits/subview_field_meat.hpp" | | #include "armadillo_bits/subview_field_meat.hpp" | |
|
| | | #include "armadillo_bits/subview_cube_meat.hpp" | |
| #include "armadillo_bits/diagview_meat.hpp" | | #include "armadillo_bits/diagview_meat.hpp" | |
| | | | |
| #include "armadillo_bits/diskio_meat.hpp" | | #include "armadillo_bits/diskio_meat.hpp" | |
| #include "armadillo_bits/wall_clock_meat.hpp" | | #include "armadillo_bits/wall_clock_meat.hpp" | |
| #include "armadillo_bits/running_stat_meat.hpp" | | #include "armadillo_bits/running_stat_meat.hpp" | |
| | | | |
| #include "armadillo_bits/op_diagmat_meat.hpp" | | #include "armadillo_bits/op_diagmat_meat.hpp" | |
| #include "armadillo_bits/op_dot_meat.hpp" | | #include "armadillo_bits/op_dot_meat.hpp" | |
| #include "armadillo_bits/op_inv_meat.hpp" | | #include "armadillo_bits/op_inv_meat.hpp" | |
| #include "armadillo_bits/op_htrans_meat.hpp" | | #include "armadillo_bits/op_htrans_meat.hpp" | |
| | | | |
| skipping to change at line 283 | | skipping to change at line 315 | |
| #include "armadillo_bits/op_rand_meat.hpp" | | #include "armadillo_bits/op_rand_meat.hpp" | |
| #include "armadillo_bits/op_randn_meat.hpp" | | #include "armadillo_bits/op_randn_meat.hpp" | |
| #include "armadillo_bits/op_scalar_misc_meat.hpp" | | #include "armadillo_bits/op_scalar_misc_meat.hpp" | |
| #include "armadillo_bits/op_sort_meat.hpp" | | #include "armadillo_bits/op_sort_meat.hpp" | |
| #include "armadillo_bits/op_sum_meat.hpp" | | #include "armadillo_bits/op_sum_meat.hpp" | |
| #include "armadillo_bits/op_stddev_meat.hpp" | | #include "armadillo_bits/op_stddev_meat.hpp" | |
| #include "armadillo_bits/op_trans_meat.hpp" | | #include "armadillo_bits/op_trans_meat.hpp" | |
| #include "armadillo_bits/op_trig_meat.hpp" | | #include "armadillo_bits/op_trig_meat.hpp" | |
| #include "armadillo_bits/op_var_meat.hpp" | | #include "armadillo_bits/op_var_meat.hpp" | |
| #include "armadillo_bits/op_zeros_meat.hpp" | | #include "armadillo_bits/op_zeros_meat.hpp" | |
|
| | | #include "armadillo_bits/op_repmat_meat.hpp" | |
| | | | |
| #include "armadillo_bits/glue_plus_meat.hpp" | | #include "armadillo_bits/glue_plus_meat.hpp" | |
| #include "armadillo_bits/glue_minus_meat.hpp" | | #include "armadillo_bits/glue_minus_meat.hpp" | |
| #include "armadillo_bits/glue_times_meat.hpp" | | #include "armadillo_bits/glue_times_meat.hpp" | |
| #include "armadillo_bits/glue_schur_meat.hpp" | | #include "armadillo_bits/glue_schur_meat.hpp" | |
| #include "armadillo_bits/glue_div_meat.hpp" | | #include "armadillo_bits/glue_div_meat.hpp" | |
| | | | |
|
| #include "armadillo_bits/deprecated.hpp" | | #include "armadillo_bits/glue_cube_plus_meat.hpp" | |
| | | #include "armadillo_bits/glue_cube_minus_meat.hpp" | |
| | | #include "armadillo_bits/glue_cube_schur_meat.hpp" | |
| | | #include "armadillo_bits/glue_cube_div_meat.hpp" | |
| } | | } | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 19 change blocks. |
| 8 lines changed or deleted | | 43 lines changed or added | |
|
| debug.hpp | | debug.hpp | |
| | | | |
| skipping to change at line 90 | | skipping to change at line 90 | |
| arma_bktprint() | | arma_bktprint() | |
| { | | { | |
| std::cout << std::endl; | | std::cout << std::endl; | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| arma_bktprint(const T1& x) | | arma_bktprint(const T1& x) | |
| { | | { | |
|
| std::cout << " [" << x << "]" << std::endl; | | std::cout << " [" << x << ']' << std::endl; | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| arma_bktprint(const T1& x, const T2& y) | | arma_bktprint(const T1& x, const T2& y) | |
| { | | { | |
|
| std::cout << " [" << x << y << "]" << std::endl; | | std::cout << " [" << x << y << ']' << std::endl; | |
| } | | } | |
| | | | |
| #ifdef ARMA_USE_BOOST | | #ifdef ARMA_USE_BOOST | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| arma_bktprint(const arma_boost::basic_format<T1>& x) | | arma_bktprint(const arma_boost::basic_format<T1>& x) | |
| { | | { | |
|
| std::cout << " [" << x << "]" << std::endl; | | std::cout << " [" << x << ']' << std::endl; | |
| } | | } | |
| #else | | #else | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| arma_bktprint(const arma_boost::basic_format<T1,T2>& x) | | arma_bktprint(const arma_boost::basic_format<T1,T2>& x) | |
| { | | { | |
|
| std::cout << " [" << x << "]" << std::endl; | | std::cout << " [" << x << ']' << std::endl; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| // | | // | |
| // arma_thisprint | | // arma_thisprint | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_thisprint(void* this_ptr) | | arma_thisprint(void* this_ptr) | |
| { | | { | |
|
| std::cout << " [this = " << this_ptr << "]" << std::endl; | | std::cout << " [this = " << this_ptr << ']' << std::endl; | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_warn | | // arma_warn | |
| | | | |
| //! if state is true, print a message on cout | | //! if state is true, print a message on cout | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| arma_hot | | arma_hot | |
| | | | |
| skipping to change at line 233 | | skipping to change at line 233 | |
| arma_hot | | arma_hot | |
| arma_check(const bool state, const arma_boost::basic_format<T1,T2>& x) | | arma_check(const bool state, const arma_boost::basic_format<T1,T2>& x) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| throw std::runtime_error(str(x)); | | throw std::runtime_error(str(x)); | |
| } | | } | |
| } | | } | |
| #endif | | #endif | |
| | | | |
|
| | | // | |
| | | // functions for checking whether two matrices have the same dimensions | |
| | | | |
| inline | | inline | |
| std::string | | std::string | |
| arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32
B_n_rows, const u32 B_n_cols, const char* x) | | arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32
B_n_rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| std::stringstream tmp; | | std::stringstream tmp; | |
| | | | |
|
| tmp << x << ": incompatible matrix dimensions: (" << A_n_rows << "," << A
_n_cols << ") and (" << B_n_rows << "," << B_n_cols << ")"; | | tmp << x << ": incompatible matrix dimensions: (" << A_n_rows << ',' << A
_n_cols << ") and (" << B_n_rows << ',' << B_n_cols << ')'; | |
| | | | |
| return tmp.str(); | | return tmp.str(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n
_rows, const u32 B_n_cols, const char* x) | | arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n
_rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| | | | |
| skipping to change at line 319 | | skipping to change at line 322 | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ) | |
| { | | { | |
| throw std::runtime_error | | throw std::runtime_error | |
| ( | | ( | |
| arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) | | arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) | |
| ); | | ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | // | |
| | | // functions for checking whether two cubes have the same dimensions | |
| | | | |
| | | inline | |
| | | std::string | |
| | | arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 | |
| | | A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, | |
| | | const char* x) | |
| | | { | |
| | | std::stringstream tmp; | |
| | | | |
| | | tmp << x << ": incompatible cube dimensions: (" << A_n_rows << ',' << A_n | |
| | | _cols << ',' << A_n_slices << ") and (" << B_n_rows << ',' << B_n_cols << ' | |
| | | ,' << B_n_slices << ')'; | |
| | | | |
| | | return tmp.str(); | |
| | | } | |
| | | | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n | |
| | | _slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, cons | |
| | | t char* x) | |
| | | { | |
| | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_ | |
| | | n_slices) ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B | |
| | | _n_cols, B_n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | //! if given cubes have different sizes, throw a run-time error exception | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x | |
| | | ) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. | |
| | | n_slices) ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const | |
| | | char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. | |
| | | n_slices) ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const | |
| | | char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. | |
| | | n_slices) ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& | |
| | | B, const char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. | |
| | | n_slices)) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | // | |
| | | // functions for checking whether a cube or subcube can be interpreted as a | |
| | | matrix (i.e. single slice) | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) | |
| | | ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, 1, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) | |
| | | ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, | |
| | | B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const | |
| | | char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) | |
| | | ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B | |
| | | .n_cols, 1, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | arma_hot | |
| | | arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const | |
| | | char* x) | |
| | | { | |
| | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) | |
| | | ) | |
| | | { | |
| | | throw std::runtime_error | |
| | | ( | |
| | | arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, | |
| | | B.n_slices, x) | |
| | | ); | |
| | | } | |
| | | } | |
| | | | |
| | | // | |
| | | // functions for checking whether two matrices have dimensions that are com | |
| | | patible with the matrix multiply operation | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_hot | | arma_hot | |
| arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_
rows, const u32 B_n_cols, const char* x) | | arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_
rows, const u32 B_n_cols, const char* x) | |
| { | | { | |
| if(A_n_cols != B_n_rows) | | if(A_n_cols != B_n_rows) | |
| { | | { | |
| throw std::runtime_error | | throw std::runtime_error | |
| ( | | ( | |
| arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) | | arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) | |
| | | | |
End of changes. 8 change blocks. |
| 6 lines changed or deleted | | 196 lines changed or added | |
|
| diskio_meat.hpp | | diskio_meat.hpp | |
| | | | |
| skipping to change at line 154 | | skipping to change at line 154 | |
| { | | { | |
| return std::string("ARMA_MAT_BIN_FC016"); | | return std::string("ARMA_MAT_BIN_FC016"); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return std::string(); | | return std::string(); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | //! Generate the first line of the header used for saving cubes in text for | |
| | | mat. | |
| | | //! Format: "ARMA_CUB_TXT_ABXYZ". | |
| | | //! A is one of: I (for integral types) or F (for floating point types). | |
| | | //! B is one of: U (for unsigned types), S (for signed types), N (for not a | |
| | | ppliable) or C (for complex types). | |
| | | //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i | |
| | | ndicates eight bytes. | |
| | | template<typename eT> | |
| | | inline | |
| | | std::string | |
| | | diskio::gen_txt_header(const Cube<eT>& x) | |
| | | { | |
| | | arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); | |
| | | | |
| | | if(is_u8<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IU001"); | |
| | | } | |
| | | else | |
| | | if(is_s8<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IS001"); | |
| | | } | |
| | | else | |
| | | if(is_u16<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IU002"); | |
| | | } | |
| | | else | |
| | | if(is_s16<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IS002"); | |
| | | } | |
| | | else | |
| | | if(is_u32<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IU004"); | |
| | | } | |
| | | else | |
| | | if(is_s32<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_IS004"); | |
| | | } | |
| | | else | |
| | | if(is_float<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_FN004"); | |
| | | } | |
| | | else | |
| | | if(is_double<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_FN008"); | |
| | | } | |
| | | else | |
| | | if(is_complex_float<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_FC008"); | |
| | | } | |
| | | else | |
| | | if(is_complex_double<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_TXT_FC016"); | |
| | | } | |
| | | else | |
| | | { | |
| | | return std::string(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Generate the first line of the header used for saving cubes in binary f | |
| | | ormat. | |
| | | //! Format: "ARMA_CUB_BIN_ABXYZ". | |
| | | //! A is one of: I (for integral types) or F (for floating point types). | |
| | | //! B is one of: U (for unsigned types), S (for signed types), N (for not a | |
| | | ppliable) or C (for complex types). | |
| | | //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i | |
| | | ndicates eight bytes. | |
| | | template<typename eT> | |
| | | inline | |
| | | std::string | |
| | | diskio::gen_bin_header(const Cube<eT>& x) | |
| | | { | |
| | | arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); | |
| | | | |
| | | if(is_u8<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IU001"); | |
| | | } | |
| | | else | |
| | | if(is_s8<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IS001"); | |
| | | } | |
| | | else | |
| | | if(is_u16<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IU002"); | |
| | | } | |
| | | else | |
| | | if(is_s16<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IS002"); | |
| | | } | |
| | | else | |
| | | if(is_u32<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IU004"); | |
| | | } | |
| | | else | |
| | | if(is_s32<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_IS004"); | |
| | | } | |
| | | else | |
| | | if(is_float<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_FN004"); | |
| | | } | |
| | | else | |
| | | if(is_double<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_FN008"); | |
| | | } | |
| | | else | |
| | | if(is_complex_float<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_FC008"); | |
| | | } | |
| | | else | |
| | | if(is_complex_double<eT>::value == true) | |
| | | { | |
| | | return std::string("ARMA_CUB_BIN_FC016"); | |
| | | } | |
| | | else | |
| | | { | |
| | | return std::string(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| inline | | inline | |
| char | | char | |
| diskio::conv_to_hex_char(const u8 x) | | diskio::conv_to_hex_char(const u8 x) | |
| { | | { | |
| char out; | | char out; | |
|
| | | | |
| switch(x) | | switch(x) | |
| { | | { | |
| case 0: out = '0'; break; | | case 0: out = '0'; break; | |
| case 1: out = '1'; break; | | case 1: out = '1'; break; | |
| case 2: out = '2'; break; | | case 2: out = '2'; break; | |
| case 3: out = '3'; break; | | case 3: out = '3'; break; | |
| case 4: out = '4'; break; | | case 4: out = '4'; break; | |
| case 5: out = '5'; break; | | case 5: out = '5'; break; | |
| case 6: out = '6'; break; | | case 6: out = '6'; break; | |
| case 7: out = '7'; break; | | case 7: out = '7'; break; | |
| | | | |
| skipping to change at line 981 | | skipping to change at line 1118 | |
| else | | else | |
| { | | { | |
| load_raw_ascii(x, name); | | load_raw_ascii(x, name); | |
| } | | } | |
| | | | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1> | | // cubes | |
| | | | |
| | | //! Save a cube as raw text (no header, human readable). | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| diskio::save_field_arma_binary(const field<T1>& x, const std::string& final
_name) | | diskio::save_raw_ascii(const Cube<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
|
| std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | | | |
| | | std::fstream f(tmp_name.c_str(), std::fstream::out); | |
| | | | |
| if(f.is_open() == false) | | if(f.is_open() == false) | |
| { | | { | |
|
| arma_print("couldn't write ", tmp_name); | | arma_print("unable to write ", tmp_name); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| f << "ARMA_FLD_BIN" << '\n'; | | u32 cell_width; | |
| f << x.n_rows << '\n'; | | | |
| f << x.n_cols << '\n'; | | | |
| | | | |
|
| for(u32 i=0; i<x.n_elem; ++i) | | // TODO: need sane values for complex numbers | |
| | | | |
| | | if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | |
| { | | { | |
|
| diskio::save_arma_binary(x[i], tmp_name, f); | | f.setf(ios::scientific); | |
| | | f.precision(8); | |
| | | cell_width = 16; | |
| | | } | |
| | | | |
| | | for(u32 slice=0; slice < x.n_slices; ++slice) | |
| | | { | |
| | | for(u32 row=0; row < x.n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col < x.n_cols; ++col) | |
| | | { | |
| | | f.put(' '); | |
| | | | |
| | | if( (is_float<eT>::value == true) || (is_double<eT>::value == tru | |
| | | e) ) | |
| | | { | |
| | | f.width(cell_width); | |
| | | } | |
| | | | |
| | | f << x.at(row,col,slice); | |
| | | } | |
| | | | |
| | | f.put('\n'); | |
| | | } | |
| } | | } | |
| | | | |
| const bool writing_problem = (f.good() == false); | | const bool writing_problem = (f.good() == false); | |
| | | | |
| arma_warn(writing_problem, "trouble writing ", tmp_name ); | | arma_warn(writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| f.flush(); | | f.flush(); | |
| f.close(); | | f.close(); | |
| | | | |
| if(writing_problem == false) | | if(writing_problem == false) | |
| { | | { | |
| diskio::safe_rename(tmp_name, final_name); | | diskio::safe_rename(tmp_name, final_name); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1> | | //! Save a cube in text format (human readable), | |
| | | //! with a header that indicates the cube type as well as its dimensions | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| diskio::load_field_arma_binary(field<T1>& x, const std::string& name) | | diskio::save_arma_ascii(const Cube<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | | |
| bool load_okay = true; | | | |
| | | | |
| std::ifstream f( name.c_str() ); | | | |
| | | | |
| if(f.fail()) | | | |
| { | | | |
| load_okay = false; | | | |
| arma_extra_debug_print("unable to read ", name); | | | |
| } | | | |
| else | | | |
| { | | | |
| std::string f_type; | | | |
| f >> f_type; | | | |
| | | | |
| if(f_type != "ARMA_FLD_BIN") | | | |
| { | | | |
| arma_print("unsupported field type in ", name); | | | |
| load_okay = false; | | | |
| } | | | |
| else | | | |
| { | | | |
| u32 f_n_rows; | | | |
| u32 f_n_cols; | | | |
| | | | |
| f >> f_n_rows; | | | |
| f >> f_n_cols; | | | |
| | | | |
| x.set_size(f_n_rows, f_n_cols); | | | |
| | | | |
|
| f.get(); | | std::ofstream f(tmp_name.c_str()); | |
| | | | |
|
| for(u32 i=0; i<x.n_elem; ++i) | | diskio::save_arma_ascii(x, tmp_name, f); | |
| { | | | |
| diskio::load_arma_binary(x[i], name, f); | | | |
| | | | |
|
| if(f.good() == false) | | const bool writing_problem = (f.good() == false); | |
| { | | | |
| arma_print("trouble reading ", name); | | | |
| load_okay = false; | | | |
| break; | | | |
| } | | | |
| } | | | |
| } | | | |
| } | | | |
| | | | |
|
| | | f.flush(); | |
| f.close(); | | f.close(); | |
| | | | |
|
| if(load_okay == false) | | arma_warn( writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| | | if(writing_problem == false) | |
| { | | { | |
|
| x.reset(); | | diskio::safe_rename(tmp_name, final_name); | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename T1> | | //! Save a cube in text format (human readable), | |
| | | //! with a header that indicates the cube type as well as its dimensions | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| diskio::save_field_ppm_binary(const field<T1>& x, const std::string& final_
name) | | diskio::save_arma_ascii(const Cube<eT>& x, const std::string& name, std::of
stream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| arma_debug_check( (x.n_elem != 3), "diskio::save_field_ppm_binary(): give | | | |
| n field must have exactly 3 matrices of equal size" ); | | | |
| | | | |
| bool same_size = true; | | | |
| for(u32 i=1; i<3; ++i) | | | |
| { | | | |
| if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) | | | |
| { | | | |
| same_size = false; | | | |
| break; | | | |
| } | | | |
| } | | | |
| | | | |
| arma_debug_check( (same_size != true), "diskio::save_field_ppm_binary(): | | | |
| given field must have exactly 3 matrices of equal size" ); | | | |
| | | | |
| const Mat<eT>& R = x(0); | | | |
| const Mat<eT>& G = x(1); | | | |
| const Mat<eT>& B = x(2); | | | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | | |
| std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | | | |
| | | | |
| if(f.is_open() == false) | | if(f.is_open() == false) | |
| { | | { | |
|
| arma_print("couldn't write ", tmp_name); | | arma_debug_print("unable to write ", name); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| f << "P6" << '\n'; | | const ios::fmtflags orig_flags = f.flags(); | |
| f << R.n_cols << '\n'; | | | |
| f << R.n_rows << '\n'; | | | |
| f << 255 << '\n'; | | | |
| | | | |
|
| const u32 n_elem = 3 * R.n_rows * R.n_cols; | | f << diskio::gen_txt_header(x) << '\n'; | |
| podarray<u8> tmp(n_elem); | | f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; | |
| | | | |
|
| u32 i = 0; | | u32 cell_width; | |
| for(u32 row=0; row < R.n_rows; ++row) | | | |
| { | | | |
| for(u32 col=0; col < R.n_cols; ++col) | | | |
| { | | | |
| tmp[i+0] = u8( R.at(row,col) ); | | | |
| tmp[i+1] = u8( G.at(row,col) ); | | | |
| tmp[i+2] = u8( B.at(row,col) ); | | | |
| | | | |
|
| i+=3; | | // TODO: need sane values for complex numbers | |
| } | | | |
| } | | | |
| | | | |
|
| f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); | | if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | |
| | | { | |
| | | f.setf(ios::scientific); | |
| | | f.precision(8); | |
| | | cell_width = 16; | |
| | | } | |
| | | | |
|
| const bool writing_problem = (f.good() == false); | | for(u32 slice=0; slice < x.n_slices; ++slice) | |
| | | { | |
| | | for(u32 row=0; row < x.n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col < x.n_cols; ++col) | |
| | | { | |
| | | f.put(' '); | |
| | | | |
|
| arma_warn(writing_problem, "trouble writing ", tmp_name ); | | if( (is_float<eT>::value == true) || (is_double<eT>::value == tru | |
| | | e) ) | |
| | | { | |
| | | f.width(cell_width); | |
| | | } | |
| | | | |
|
| f.flush(); | | f << x.at(row,col,slice); | |
| f.close(); | | } | |
| | | | |
|
| if(writing_problem == false) | | f.put('\n'); | |
| { | | } | |
| diskio::safe_rename(tmp_name, final_name); | | | |
| } | | } | |
| | | | |
|
| | | f.flags(orig_flags); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1> | | //! Save a cube in binary format, | |
| | | //! with a header that stores the cube type as well as its dimensions | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| diskio::load_field_ppm_binary(field<T1>& x, const std::string& name) | | diskio::save_arma_binary(const Cube<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
|
| std::fstream f; | | std::ofstream f(tmp_name.c_str(), std::fstream::binary); | |
| f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | | |
| | | diskio::save_arma_binary(x, tmp_name, f); | |
| | | | |
| | | const bool writing_problem = (f.good() == false); | |
| | | | |
| | | f.flush(); | |
| | | f.close(); | |
| | | | |
| | | arma_warn( writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| | | if(writing_problem == false) | |
| | | { | |
| | | diskio::safe_rename(tmp_name, final_name); | |
| | | } | |
| | | } | |
| | | | |
| | | //! Save a cube in binary format, | |
| | | //! with a header that stores the cube type as well as its dimensions | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::save_arma_binary(const Cube<eT>& x, const std::string& name, std::o | |
| | | fstream& f) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | arma_print("unable to write ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | f << diskio::gen_bin_header(x) << '\n'; | |
| | | f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; | |
| | | | |
| | | f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT)); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Load a cube as raw text (no header, human readable). | |
| | | //! NOTE: this is much slower than reading a file with a header. | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_raw_ascii(Cube<eT>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT> tmp; | |
| | | tmp.load(name); | |
| | | | |
| | | x.set_size(tmp.n_rows, tmp.n_cols, 1); | |
| | | | |
| | | if(x.n_slices > 0) | |
| | | { | |
| | | x.slice(0) = tmp; | |
| | | } | |
| | | } | |
| | | | |
| | | //! Load a cube in text format (human readable), | |
| | | //! with a header that indicates the cube type as well as its dimensions | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_arma_ascii(Cube<eT>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | std::ifstream f(name.c_str()); | |
| | | diskio::load_arma_ascii(x, name, f); | |
| | | f.close(); | |
| | | } | |
| | | | |
| | | //! Load a cube in text format (human readable), | |
| | | //! with a header that indicates the cube type as well as its dimensions | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_arma_ascii(Cube<eT>& x, const std::string& name, std::ifstream | |
| | | & f) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool load_okay = true; | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | std::string f_header; | |
| | | u32 f_n_rows; | |
| | | u32 f_n_cols; | |
| | | u32 f_n_slices; | |
| | | | |
| | | f >> f_header; | |
| | | f >> f_n_rows; | |
| | | f >> f_n_cols; | |
| | | f >> f_n_slices; | |
| | | | |
| | | if(f_header == diskio::gen_txt_header(x)) | |
| | | { | |
| | | x.set_size(f_n_rows, f_n_cols, f_n_slices); | |
| | | | |
| | | for(u32 slice=0; slice < x.n_slices; ++slice) | |
| | | { | |
| | | for(u32 row=0; row < x.n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col < x.n_cols; ++col) | |
| | | { | |
| | | f >> x.at(row,col,slice); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(f.good() == false) | |
| | | { | |
| | | arma_print("trouble reading ", name); | |
| | | load_okay = false; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_print("incorrect header in ", name ); | |
| | | load_okay = false; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | x.reset(); | |
| | | } | |
| | | } | |
| | | | |
| | | //! Load a cube in binary format, | |
| | | //! with a header that indicates the cube type as well as its dimensions | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_arma_binary(Cube<eT>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | std::ifstream f; | |
| | | f.open(name.c_str(), std::fstream::binary); | |
| | | diskio::load_arma_binary(x, name, f); | |
| | | f.close(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_arma_binary(Cube<eT>& x, const std::string& name, std::ifstrea | |
| | | m& f) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool load_okay = true; | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | std::string f_header; | |
| | | u32 f_n_rows; | |
| | | u32 f_n_cols; | |
| | | u32 f_n_slices; | |
| | | | |
| | | f >> f_header; | |
| | | f >> f_n_rows; | |
| | | f >> f_n_cols; | |
| | | f >> f_n_slices; | |
| | | | |
| | | if(f_header == diskio::gen_bin_header(x)) | |
| | | { | |
| | | //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a W | |
| | | indows machine a newline could be two characters | |
| | | f.get(); | |
| | | | |
| | | x.set_size(f_n_rows, f_n_cols, f_n_slices); | |
| | | f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT)); | |
| | | | |
| | | if(f.good() == false) | |
| | | { | |
| | | arma_print("trouble reading ", name); | |
| | | load_okay = false; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_print("incorrect header in ", name); | |
| | | load_okay = false; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | x.reset(); | |
| | | } | |
| | | } | |
| | | | |
| | | //! Try to load a cube by automatically determining its type | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_auto_detect(Cube<eT>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; | |
| | | static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; | |
| | | static const std::string P6 = "P6"; | |
| | | | |
| | | std::fstream f; | |
| | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | x.reset(); | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); | |
| | | | |
| | | f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); | |
| | | raw_header[ARMA_CUB_TXT.length()] = '\0'; | |
| | | | |
| | | const std::string header = raw_header.mem; | |
| | | | |
| | | if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) | |
| | | { | |
| | | load_arma_ascii(x, name); | |
| | | } | |
| | | else | |
| | | if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) | |
| | | { | |
| | | load_arma_binary(x, name); | |
| | | } | |
| | | else | |
| | | if(P6 == header.substr(0,P6.length())) | |
| | | { | |
| | | load_ppm_binary(x, name); | |
| | | } | |
| | | else | |
| | | { | |
| | | load_raw_ascii(x, name); | |
| | | } | |
| | | | |
| | | f.close(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | // fields | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | diskio::save_arma_binary(const field<T1>& x, const std::string& final_name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f | |
| | | alse) >::apply(); | |
| | | | |
| | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | arma_print("couldn't write ", tmp_name); | |
| | | } | |
| | | else | |
| | | { | |
| | | f << "ARMA_FLD_BIN" << '\n'; | |
| | | f << x.n_rows << '\n'; | |
| | | f << x.n_cols << '\n'; | |
| | | | |
| | | for(u32 i=0; i<x.n_elem; ++i) | |
| | | { | |
| | | diskio::save_arma_binary(x[i], tmp_name, f); | |
| | | } | |
| | | | |
| | | const bool writing_problem = (f.good() == false); | |
| | | | |
| | | arma_warn(writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| | | f.flush(); | |
| | | f.close(); | |
| | | | |
| | | if(writing_problem == false) | |
| | | { | |
| | | diskio::safe_rename(tmp_name, final_name); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | diskio::load_arma_binary(field<T1>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f | |
| | | alse) >::apply(); | |
| | | | |
| | | bool load_okay = true; | |
| | | | |
| | | std::ifstream f( name.c_str() ); | |
| | | | |
| | | if(f.fail()) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | std::string f_type; | |
| | | f >> f_type; | |
| | | | |
| | | if(f_type != "ARMA_FLD_BIN") | |
| | | { | |
| | | arma_print("unsupported field type in ", name); | |
| | | load_okay = false; | |
| | | } | |
| | | else | |
| | | { | |
| | | u32 f_n_rows; | |
| | | u32 f_n_cols; | |
| | | | |
| | | f >> f_n_rows; | |
| | | f >> f_n_cols; | |
| | | | |
| | | x.set_size(f_n_rows, f_n_cols); | |
| | | | |
| | | f.get(); | |
| | | | |
| | | for(u32 i=0; i<x.n_elem; ++i) | |
| | | { | |
| | | diskio::load_arma_binary(x[i], name, f); | |
| | | | |
| | | if(f.good() == false) | |
| | | { | |
| | | arma_print("trouble reading ", name); | |
| | | load_okay = false; | |
| | | break; | |
| | | } | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | f.close(); | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | x.reset(); | |
| | | } | |
| | | } | |
| | | | |
| | | inline | |
| | | void | |
| | | diskio::save_std_string(const field<std::string>& x, const std::string& fin | |
| | | al_name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | arma_print("couldn't write ", tmp_name); | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 row=0; row<x.n_rows; ++row) | |
| | | for(u32 col=0; col<x.n_cols; ++col) | |
| | | { | |
| | | f << x.at(row,col); | |
| | | | |
| | | if(col < x.n_cols-1) | |
| | | { | |
| | | f << ' '; | |
| | | } | |
| | | else | |
| | | { | |
| | | f << '\n'; | |
| | | } | |
| | | } | |
| | | | |
| | | const bool writing_problem = (f.good() == false); | |
| | | | |
| | | arma_warn(writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| | | f.flush(); | |
| | | f.close(); | |
| | | | |
| | | if(writing_problem == false) | |
| | | { | |
| | | diskio::safe_rename(tmp_name, final_name); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | inline | |
| | | void | |
| | | diskio::load_std_string(field<std::string>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool load_okay = true; | |
| | | | |
| | | std::ifstream f( name.c_str() ); | |
| | | | |
| | | if(f.fail()) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | // | |
| | | // work out the size | |
| | | | |
| | | u32 f_n_rows = 0; | |
| | | u32 f_n_cols = 0; | |
| | | | |
| | | bool f_n_cols_found = false; | |
| | | | |
| | | std::string line_string; | |
| | | std::string token; | |
| | | | |
| | | while( (f.good() == true) && (load_okay == true) ) | |
| | | { | |
| | | std::getline(f, line_string); | |
| | | if(line_string.size() == 0) | |
| | | break; | |
| | | | |
| | | std::stringstream line_stream(line_string); | |
| | | | |
| | | u32 line_n_cols = 0; | |
| | | while (line_stream >> token) | |
| | | line_n_cols++; | |
| | | | |
| | | if(f_n_cols_found == false) | |
| | | { | |
| | | f_n_cols = line_n_cols; | |
| | | f_n_cols_found = true; | |
| | | } | |
| | | else | |
| | | { | |
| | | if(line_n_cols != f_n_cols) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_print("inconsistent number of columns in ", name ); | |
| | | } | |
| | | } | |
| | | | |
| | | ++f_n_rows; | |
| | | } | |
| | | | |
| | | if(load_okay == true) | |
| | | { | |
| | | f.clear(); | |
| | | f.seekg(0, ios::beg); | |
| | | //f.seekg(start); | |
| | | | |
| | | x.set_size(f_n_rows, f_n_cols); | |
| | | | |
| | | for(u32 row=0; row < x.n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col < x.n_cols; ++col) | |
| | | { | |
| | | f >> x.at(row,col); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(f.good() == false) | |
| | | { | |
| | | load_okay = false; | |
| | | arma_print("trouble reading ", name ); | |
| | | } | |
| | | | |
| | | f.close(); | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | x.reset(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Try to load a field by automatically determining its type | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | diskio::load_auto_detect(field<T1>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check<is_Mat<T1>::value == false>::apply(); | |
| | | | |
| | | static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | |
| | | static const std::string P6 = "P6"; | |
| | | | |
| | | std::fstream f; | |
| | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
| | | if(f.is_open() == false) | |
| | | { | |
| | | x.reset(); | |
| | | arma_extra_debug_print("unable to read ", name); | |
| | | } | |
| | | else | |
| | | { | |
| | | podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | |
| | | | |
| | | f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); | |
| | | raw_header[ARMA_FLD_BIN.length()] = '\0'; | |
| | | | |
| | | const std::string header = raw_header.mem; | |
| | | | |
| | | if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length())) | |
| | | { | |
| | | load_arma_binary(x, name); | |
| | | } | |
| | | else | |
| | | if(P6 == header.substr(0,P6.length())) | |
| | | { | |
| | | load_ppm_binary(x, name); | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_print("unsupported header in ", name); | |
| | | x.reset(); | |
| | | } | |
| | | | |
| | | f.close(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | // | |
| | | // handling of PPM images | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | diskio::load_ppm_binary(Cube<eT>& x, const std::string& name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | std::fstream f; | |
| | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
| bool load_okay = true; | | bool load_okay = true; | |
| | | | |
| if(f.is_open() == false) | | if(f.is_open() == false) | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| arma_extra_debug_print("unable to read ", name); | | arma_extra_debug_print("unable to read ", name); | |
| } | | } | |
| else | | else | |
| { | | { | |
| | | | |
| skipping to change at line 1206 | | skipping to change at line 1874 | |
| diskio::pnm_skip_comments(f); | | diskio::pnm_skip_comments(f); | |
| | | | |
| f >> f_n_rows; | | f >> f_n_rows; | |
| diskio::pnm_skip_comments(f); | | diskio::pnm_skip_comments(f); | |
| | | | |
| f >> f_maxval; | | f >> f_maxval; | |
| f.get(); | | f.get(); | |
| | | | |
| if( (f_maxval > 0) || (f_maxval <= 65535) ) | | if( (f_maxval > 0) || (f_maxval <= 65535) ) | |
| { | | { | |
|
| x.set_size(3); | | x.set_size(f_n_rows, f_n_cols, 3); | |
| Mat<eT>& R = x(0); | | | |
| Mat<eT>& G = x(1); | | | |
| Mat<eT>& B = x(2); | | | |
| | | | |
| R.set_size(f_n_rows,f_n_cols); | | | |
| G.set_size(f_n_rows,f_n_cols); | | | |
| B.set_size(f_n_rows,f_n_cols); | | | |
| | | | |
| if(f_maxval <= 255) | | if(f_maxval <= 255) | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u8> tmp(n_elem); | | podarray<u8> tmp(n_elem); | |
| | | | |
| f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | | f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | |
| | | | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| //cout << "f_n_cols = " << f_n_cols << endl; | | //cout << "f_n_cols = " << f_n_cols << endl; | |
| //cout << "f_n_rows = " << f_n_rows << endl; | | //cout << "f_n_rows = " << f_n_rows << endl; | |
| | | | |
| for(u32 row=0; row < f_n_rows; ++row) | | for(u32 row=0; row < f_n_rows; ++row) | |
| { | | { | |
| for(u32 col=0; col < f_n_cols; ++col) | | for(u32 col=0; col < f_n_cols; ++col) | |
| { | | { | |
|
| R.at(row,col) = eT(tmp[i+0]); | | x.at(row,col,0) = eT(tmp[i+0]); | |
| G.at(row,col) = eT(tmp[i+1]); | | x.at(row,col,1) = eT(tmp[i+1]); | |
| B.at(row,col) = eT(tmp[i+2]); | | x.at(row,col,2) = eT(tmp[i+2]); | |
| i+=3; | | i+=3; | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u16> tmp(n_elem); | | podarray<u16> tmp(n_elem); | |
| | | | |
| f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); | | f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); | |
| | | | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| for(u32 row=0; row < f_n_rows; ++row) | | for(u32 row=0; row < f_n_rows; ++row) | |
| { | | { | |
| for(u32 col=0; col < f_n_cols; ++col) | | for(u32 col=0; col < f_n_cols; ++col) | |
| { | | { | |
|
| R.at(row,col) = eT(tmp[i+0]); | | x.at(row,col,0) = eT(tmp[i+0]); | |
| G.at(row,col) = eT(tmp[i+1]); | | x.at(row,col,1) = eT(tmp[i+1]); | |
| B.at(row,col) = eT(tmp[i+2]); | | x.at(row,col,2) = eT(tmp[i+2]); | |
| i+=3; | | i+=3; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| if(f.good() == false) | | if(f.good() == false) | |
| | | | |
| skipping to change at line 1287 | | skipping to change at line 1948 | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
| if(load_okay == false) | | if(load_okay == false) | |
| { | | { | |
| x.reset(); | | x.reset(); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| diskio::save_field_std_string(const field<std::string>& x, const std::strin
g& final_name) | | diskio::save_ppm_binary(const Cube<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cu | |
| | | be must have exactly 3 slices" ); | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | | std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | |
| | | | |
| if(f.is_open() == false) | | if(f.is_open() == false) | |
| { | | { | |
| arma_print("couldn't write ", tmp_name); | | arma_print("couldn't write ", tmp_name); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(u32 row=0; row<x.n_rows; ++row) | | const u32 n_elem = 3 * x.n_rows * x.n_cols; | |
| for(u32 col=0; col<x.n_cols; ++col) | | podarray<u8> tmp(n_elem); | |
| { | | | |
| f << x.at(row,col); | | | |
| | | | |
|
| if(col < x.n_cols-1) | | u32 i = 0; | |
| { | | for(u32 row=0; row < x.n_rows; ++row) | |
| f << ' '; | | { | |
| } | | for(u32 col=0; col < x.n_cols; ++col) | |
| else | | | |
| { | | { | |
|
| f << '\n'; | | tmp[i+0] = u8( x.at(row,col,0) ); | |
| | | tmp[i+1] = u8( x.at(row,col,1) ); | |
| | | tmp[i+2] = u8( x.at(row,col,2) ); | |
| | | | |
| | | i+=3; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | f << "P6" << '\n'; | |
| | | f << x.n_cols << '\n'; | |
| | | f << x.n_rows << '\n'; | |
| | | f << 255 << '\n'; | |
| | | | |
| | | f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); | |
| | | | |
| const bool writing_problem = (f.good() == false); | | const bool writing_problem = (f.good() == false); | |
| | | | |
| arma_warn(writing_problem, "trouble writing ", tmp_name ); | | arma_warn(writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| f.flush(); | | f.flush(); | |
| f.close(); | | f.close(); | |
| | | | |
| if(writing_problem == false) | | if(writing_problem == false) | |
| { | | { | |
| diskio::safe_rename(tmp_name, final_name); | | diskio::safe_rename(tmp_name, final_name); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| diskio::load_field_std_string(field<std::string>& x, const std::string& nam
e) | | diskio::load_ppm_binary(field<T1>& x, const std::string& name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| bool load_okay = true; | | arma_type_check<is_Mat<T1>::value == false>::apply(); | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
|
| std::ifstream f( name.c_str() ); | | std::fstream f; | |
| | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
|
| if(f.fail()) | | bool load_okay = true; | |
| | | | |
| | | if(f.is_open() == false) | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| arma_extra_debug_print("unable to read ", name); | | arma_extra_debug_print("unable to read ", name); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| // | | std::string f_header; | |
| // work out the size | | f >> f_header; | |
| | | | |
| u32 f_n_rows = 0; | | | |
| u32 f_n_cols = 0; | | | |
| | | | |
|
| bool f_n_cols_found = false; | | if(f_header == "P6") | |
| | | { | |
| | | u32 f_n_rows = 0; | |
| | | u32 f_n_cols = 0; | |
| | | int f_maxval = 0; | |
| | | | |
|
| std::string line_string; | | diskio::pnm_skip_comments(f); | |
| std::string token; | | | |
| | | | |
|
| while( (f.good() == true) && (load_okay == true) ) | | f >> f_n_cols; | |
| { | | diskio::pnm_skip_comments(f); | |
| std::getline(f, line_string); | | | |
| if(line_string.size() == 0) | | | |
| break; | | | |
| | | | |
|
| std::stringstream line_stream(line_string); | | f >> f_n_rows; | |
| | | diskio::pnm_skip_comments(f); | |
| | | | |
|
| u32 line_n_cols = 0; | | f >> f_maxval; | |
| while (line_stream >> token) | | f.get(); | |
| line_n_cols++; | | | |
| | | | |
|
| if(f_n_cols_found == false) | | if( (f_maxval > 0) || (f_maxval <= 65535) ) | |
| { | | | |
| f_n_cols = line_n_cols; | | | |
| f_n_cols_found = true; | | | |
| } | | | |
| else | | | |
| { | | { | |
|
| if(line_n_cols != f_n_cols) | | x.set_size(3); | |
| | | Mat<eT>& R = x(0); | |
| | | Mat<eT>& G = x(1); | |
| | | Mat<eT>& B = x(2); | |
| | | | |
| | | R.set_size(f_n_rows,f_n_cols); | |
| | | G.set_size(f_n_rows,f_n_cols); | |
| | | B.set_size(f_n_rows,f_n_cols); | |
| | | | |
| | | if(f_maxval <= 255) | |
| { | | { | |
|
| load_okay = false; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| arma_print("inconsistent number of columns in ", name ); | | podarray<u8> tmp(n_elem); | |
| } | | | |
| } | | | |
| | | | |
|
| ++f_n_rows; | | f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | |
| } | | | |
| | | | |
|
| if(load_okay == true) | | u32 i = 0; | |
| { | | | |
| f.clear(); | | | |
| f.seekg(0, ios::beg); | | | |
| //f.seekg(start); | | | |
| | | | |
|
| x.set_size(f_n_rows, f_n_cols); | | //cout << "f_n_cols = " << f_n_cols << endl; | |
| | | //cout << "f_n_rows = " << f_n_rows << endl; | |
| | | | |
|
| for(u32 row=0; row < x.n_rows; ++row) | | for(u32 row=0; row < f_n_rows; ++row) | |
| { | | { | |
| for(u32 col=0; col < x.n_cols; ++col) | | for(u32 col=0; col < f_n_cols; ++col) | |
| | | { | |
| | | R.at(row,col) = eT(tmp[i+0]); | |
| | | G.at(row,col) = eT(tmp[i+1]); | |
| | | B.at(row,col) = eT(tmp[i+2]); | |
| | | i+=3; | |
| | | } | |
| | | | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| f >> x.at(row,col); | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| | | podarray<u16> tmp(n_elem); | |
| | | | |
| | | f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); | |
| | | | |
| | | u32 i = 0; | |
| | | | |
| | | for(u32 row=0; row < f_n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col < f_n_cols; ++col) | |
| | | { | |
| | | R.at(row,col) = eT(tmp[i+0]); | |
| | | G.at(row,col) = eT(tmp[i+1]); | |
| | | B.at(row,col) = eT(tmp[i+2]); | |
| | | i+=3; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| } | | | |
| | | | |
|
| if(f.good() == false) | | if(f.good() == false) | |
| | | { | |
| | | arma_print("trouble reading ", name); | |
| | | load_okay = false; | |
| | | } | |
| | | | |
| | | } | |
| | | else | |
| { | | { | |
|
| | | arma_print("unsupported header in ", name); | |
| load_okay = false; | | load_okay = false; | |
|
| arma_print("trouble reading ", name ); | | | |
| } | | } | |
| | | | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
| if(load_okay == false) | | if(load_okay == false) | |
| { | | { | |
| x.reset(); | | x.reset(); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! Try to load a field by automatically determining its type | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| diskio::load_field_auto_detect(field<T1>& x, const std::string& name) | | diskio::save_ppm_binary(const field<T1>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | arma_type_check<is_Mat<T1>::value == false>::apply(); | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
|
| static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | | arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given fiel | |
| static const std::string P6 = "P6"; | | d must have exactly 3 matrices of equal size" ); | |
| | | | |
|
| std::fstream f; | | bool same_size = true; | |
| f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | for(u32 i=1; i<3; ++i) | |
| | | { | |
| | | if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) | |
| | | { | |
| | | same_size = false; | |
| | | break; | |
| | | } | |
| | | } | |
| | | | |
| | | arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given | |
| | | field must have exactly 3 matrices of equal size" ); | |
| | | | |
| | | const Mat<eT>& R = x(0); | |
| | | const Mat<eT>& G = x(1); | |
| | | const Mat<eT>& B = x(2); | |
| | | | |
| | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | std::ofstream f( tmp_name.c_str(), std::fstream::binary ); | |
| | | | |
| if(f.is_open() == false) | | if(f.is_open() == false) | |
| { | | { | |
|
| x.reset(); | | arma_print("couldn't write ", tmp_name); | |
| arma_extra_debug_print("unable to read ", name); | | | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | | f << "P6" << '\n'; | |
| | | f << R.n_cols << '\n'; | |
| f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); | | f << R.n_rows << '\n'; | |
| raw_header[ARMA_FLD_BIN.length()] = '\0'; | | f << 255 << '\n'; | |
| | | | |
|
| const std::string header = raw_header.mem; | | const u32 n_elem = 3 * R.n_rows * R.n_cols; | |
| | | podarray<u8> tmp(n_elem); | |
| | | | |
|
| if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length())) | | u32 i = 0; | |
| { | | for(u32 row=0; row < R.n_rows; ++row) | |
| load_field_arma_binary(x, name); | | | |
| } | | | |
| else | | | |
| if(P6 == header.substr(0,P6.length())) | | | |
| { | | { | |
|
| load_field_ppm_binary(x, name); | | for(u32 col=0; col < R.n_cols; ++col) | |
| | | { | |
| | | tmp[i+0] = u8( R.at(row,col) ); | |
| | | tmp[i+1] = u8( G.at(row,col) ); | |
| | | tmp[i+2] = u8( B.at(row,col) ); | |
| | | | |
| | | i+=3; | |
| | | } | |
| } | | } | |
|
| else | | | |
| | | f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); | |
| | | | |
| | | const bool writing_problem = (f.good() == false); | |
| | | | |
| | | arma_warn(writing_problem, "trouble writing ", tmp_name ); | |
| | | | |
| | | f.flush(); | |
| | | f.close(); | |
| | | | |
| | | if(writing_problem == false) | |
| { | | { | |
|
| arma_print("unsupported header in ", name); | | diskio::safe_rename(tmp_name, final_name); | |
| x.reset(); | | | |
| } | | } | |
| | | | |
|
| f.close(); | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 86 change blocks. |
| 216 lines changed or deleted | | 965 lines changed or added | |
|
| field_meat.hpp | | field_meat.hpp | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 156 | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| void | | void | |
| field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in) | | field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in) | |
| { | | { | |
| arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in =
%d") % n_rows_in % n_cols_in); | | arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in =
%d") % n_rows_in % n_cols_in); | |
| | | | |
| init(n_rows_in, n_cols_in); | | init(n_rows_in, n_cols_in); | |
| } | | } | |
| | | | |
|
| | | //! change the field to have the specified dimensions (data is not preserve | |
| | | d) | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::copy_size(const field<oT>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(this != &x) | |
| | | { | |
| | | init(x.n_rows, x.n_cols); | |
| | | } | |
| | | } | |
| | | | |
| //! linear element accessor (treats the field as a vector); no bounds check | | //! linear element accessor (treats the field as a vector); no bounds check | |
| template<typename oT> | | template<typename oT> | |
| arma_inline | | arma_inline | |
| oT& | | oT& | |
| field<oT>::operator[] (const u32 i) | | field<oT>::operator[] (const u32 i) | |
| { | | { | |
| return (*mem[i]); | | return (*mem[i]); | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the field as a vector); no bounds check | | //! linear element accessor (treats the field as a vector); no bounds check | |
| | | | |
| skipping to change at line 382 | | skipping to change at line 396 | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols), | |
| "field::subfield(): indices out of bounds or incorrectly used" | | "field::subfield(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2); | | return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2); | |
| } | | } | |
| | | | |
|
| //! print contents of the field, optionally preceding with a user specified | | //! print contents of the field (to the cout stream), | |
| line of text | | //! optionally preceding with a user specified line of text. | |
| | | //! the field class preserves the stream's flags | |
| | | //! but the associated operator<< function for type oT | |
| | | //! may still modify the stream's parameters. | |
| | | //! NOTE: this function assumes that type oT can be printed, | |
| | | //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | |
| | | //! has been defined. | |
| | | | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| void | | void | |
| field<oT>::print(const std::string extra_text) const | | field<oT>::print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
|
| | | const std::streamsize orig_width = cout.width(); | |
| | | | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
|
| | | | |
| | | cout.width(orig_width); | |
| | | } | |
| | | | |
| | | arma_ostream::print(cout, *this); | |
| | | } | |
| | | | |
| | | //! print contents of the field to a user specified stream, | |
| | | //! optionally preceding with a user specified line of text. | |
| | | //! the field class preserves the stream's flags | |
| | | //! but the associated operator<< function for type oT | |
| | | //! may still modify the stream's parameters. | |
| | | //! NOTE: this function assumes that type oT can be printed, | |
| | | //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | |
| | | //! has been defined. | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::print(std::ostream& user_stream, const std::string extra_text) c | |
| | | onst | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(extra_text.length() != 0) | |
| | | { | |
| | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| | | user_stream << extra_text << '\n'; | |
| | | | |
| | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
|
| cout << *this << '\n'; | | arma_ostream::print(user_stream, *this); | |
| } | | } | |
| | | | |
| //! fill the field with an object | | //! fill the field with an object | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| void | | void | |
| field<oT>::fill(const oT& x) | | field<oT>::fill(const oT& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 618 | | skipping to change at line 672 | |
| field_aux::reset_objects(field< Row<eT> >& x) | | field_aux::reset_objects(field< Row<eT> >& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| for(u32 i=0; i<x.n_elem; ++i) | | for(u32 i=0; i<x.n_elem; ++i) | |
| { | | { | |
| (*(x.mem[i])).reset(); | | (*(x.mem[i])).reset(); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | field_aux::reset_objects(field< Cube<eT> >& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | for(u32 i=0; i<x.n_elem; ++i) | |
| | | { | |
| | | (*(x.mem[i])).reset(); | |
| | | } | |
| | | } | |
| | | | |
| inline | | inline | |
| void | | void | |
| field_aux::reset_objects(field< std::string >& x) | | field_aux::reset_objects(field< std::string >& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| for(u32 i=0; i<x.n_elem; ++i) | | for(u32 i=0; i<x.n_elem; ++i) | |
| { | | { | |
| (*(x.mem[i])).clear(); | | (*(x.mem[i])).clear(); | |
| } | | } | |
| | | | |
| skipping to change at line 665 | | skipping to change at line 732 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::save(const field< Mat<eT> >& x, const std::string& name, const f
ile_type type) | | field_aux::save(const field< Mat<eT> >& x, const std::string& name, const f
ile_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::save_field_arma_binary(x, name); | | diskio::save_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::save_field_ppm_binary(x, name); | | diskio::save_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::save(): unsupported type"); | | arma_stop("field_aux::save(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_ty
pe type) | | field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_ty
pe type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case auto_detect: | | case auto_detect: | |
|
| diskio::load_field_auto_detect(x, name); | | diskio::load_auto_detect(x, name); | |
| break; | | break; | |
| | | | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::load_field_arma_binary(x, name); | | diskio::load_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::load_field_ppm_binary(x, name); | | diskio::load_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::load(): unsupported type"); | | arma_stop("field_aux::load(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::save(const field< Col<eT> >& x, const std::string& name, const f
ile_type type) | | field_aux::save(const field< Col<eT> >& x, const std::string& name, const f
ile_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::save_field_arma_binary(x, name); | | diskio::save_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::save_field_ppm_binary(x, name); | | diskio::save_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::save(): unsupported type"); | | arma_stop("field_aux::save(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::load(field< Col<eT> >& x, const std::string& name, const file_ty
pe type) | | field_aux::load(field< Col<eT> >& x, const std::string& name, const file_ty
pe type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case auto_detect: | | case auto_detect: | |
|
| diskio::load_field_auto_detect(x, name); | | diskio::load_auto_detect(x, name); | |
| break; | | break; | |
| | | | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::load_field_arma_binary(x, name); | | diskio::load_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::load_field_ppm_binary(x, name); | | diskio::load_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::load(): unsupported type"); | | arma_stop("field_aux::load(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::save(const field< Row<eT> >& x, const std::string& name, const f
ile_type type) | | field_aux::save(const field< Row<eT> >& x, const std::string& name, const f
ile_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::save_field_arma_binary(x, name); | | diskio::save_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::save_field_ppm_binary(x, name); | | diskio::save_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::save(): unsupported type"); | | arma_stop("field_aux::save(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| field_aux::load(field< Row<eT> >& x, const std::string& name, const file_ty
pe type) | | field_aux::load(field< Row<eT> >& x, const std::string& name, const file_ty
pe type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(type) | | switch(type) | |
| { | | { | |
| case auto_detect: | | case auto_detect: | |
|
| diskio::load_field_auto_detect(x, name); | | diskio::load_auto_detect(x, name); | |
| | | break; | |
| | | | |
| | | case arma_binary: | |
| | | diskio::load_arma_binary(x, name); | |
| | | break; | |
| | | | |
| | | case ppm_binary: | |
| | | diskio::load_ppm_binary(x, name); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_stop("field_aux::load(): unsupported type"); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | field_aux::save(const field< Cube<eT> >& x, const std::string& name, const | |
| | | file_type type) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | case arma_binary: | |
| | | diskio::save_arma_binary(x, name); | |
| | | break; | |
| | | | |
| | | case ppm_binary: | |
| | | diskio::save_ppm_binary(x, name); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_stop("field_aux::save(): unsupported type"); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_t | |
| | | ype type) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | case auto_detect: | |
| | | diskio::load_auto_detect(x, name); | |
| break; | | break; | |
| | | | |
| case arma_binary: | | case arma_binary: | |
|
| diskio::load_field_arma_binary(x, name); | | diskio::load_arma_binary(x, name); | |
| break; | | break; | |
| | | | |
| case ppm_binary: | | case ppm_binary: | |
|
| diskio::load_field_ppm_binary(x, name); | | diskio::load_ppm_binary(x, name); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("field_aux::load(): unsupported type"); | | arma_stop("field_aux::load(): unsupported type"); | |
| } | | } | |
| } | | } | |
| | | | |
| inline | | inline | |
| void | | void | |
| field_aux::save(const field< std::string >& x, const std::string& name, con
st file_type type) | | field_aux::save(const field< std::string >& x, const std::string& name, con
st file_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| diskio::save_field_std_string(x, name); | | diskio::save_std_string(x, name); | |
| } | | } | |
| | | | |
| inline | | inline | |
| void | | void | |
| field_aux::load(field< std::string >& x, const std::string& name, const fil
e_type type) | | field_aux::load(field< std::string >& x, const std::string& name, const fil
e_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| diskio::load_field_std_string(x, name); | | diskio::load_std_string(x, name); | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 23 change blocks. |
| 20 lines changed or deleted | | 138 lines changed or added | |
|
| fn_misc.hpp | | fn_misc.hpp | |
| | | | |
| skipping to change at line 74 | | skipping to change at line 74 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| Mat<typename T1::elem_type> | | Mat<typename T1::elem_type> | |
| reshape(const Base<typename T1::elem_type,T1>& X, const u32 in_n_rows, cons
t u32 in_n_cols, const u32 dim = 0) | | reshape(const Base<typename T1::elem_type,T1>& X, const u32 in_n_rows, cons
t u32 in_n_cols, const u32 dim = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| Mat<eT> out; | | | |
| | | | |
| const unwrap<T1> A_tmp(X.get_ref()); | | const unwrap<T1> A_tmp(X.get_ref()); | |
| const Mat<eT>& A = A_tmp.M; | | const Mat<eT>& A = A_tmp.M; | |
| | | | |
| const u32 in_n_elem = in_n_rows * in_n_cols; | | const u32 in_n_elem = in_n_rows * in_n_cols; | |
| | | | |
| arma_debug_check( (A.n_elem != in_n_elem), "reshape(): incompatible dimen
sions"); | | arma_debug_check( (A.n_elem != in_n_elem), "reshape(): incompatible dimen
sions"); | |
| arma_debug_check( (dim > 1), "reshape(): dim must be 0 or 1"); | | arma_debug_check( (dim > 1), "reshape(): dim must be 0 or 1"); | |
| | | | |
| if(dim == 0) | | if(dim == 0) | |
| { | | { | |
|
| out = A; | | return Mat<eT>(A.mem, in_n_rows, in_n_cols); | |
| | | | |
| access::rw(out.n_rows) = in_n_rows; | | | |
| access::rw(out.n_cols) = in_n_cols; | | | |
| | | | |
| return out; | | | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| out.set_size(in_n_rows, in_n_cols); | | Mat<eT> out(in_n_rows, in_n_cols); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| for(u32 row=0; row<A.n_rows; ++row) | | for(u32 row=0; row<A.n_rows; ++row) | |
| { | | { | |
| for(u32 col=0; col<A.n_cols; ++col) | | for(u32 col=0; col<A.n_cols; ++col) | |
| { | | { | |
| out_mem[i] = A.at(row,col); | | out_mem[i] = A.at(row,col); | |
| ++i; | | ++i; | |
| } | | } | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | Cube<typename T1::elem_type> | |
| | | reshape(const BaseCube<typename T1::elem_type,T1>& X, const u32 in_n_rows, | |
| | | const u32 in_n_cols, const u32 in_n_slices, const u32 dim = 0) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> A_tmp(X.get_ref()); | |
| | | const Cube<eT>& A = A_tmp.M; | |
| | | | |
| | | 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 dimen | |
| | | sions"); | |
| | | arma_debug_check( (dim > 1), "reshape(): dim must be 0 or 1"); | |
| | | | |
| | | if(dim == 0) | |
| | | { | |
| | | return Cube<eT>(A.mem, in_n_rows, in_n_cols, in_n_slices); | |
| | | } | |
| | | else | |
| | | { | |
| | | Cube<eT> out(in_n_rows, in_n_cols, in_n_slices); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | u32 i = 0; | |
| | | | |
| | | for(u32 slice=0; slice<A.n_slices; ++slice) | |
| | | { | |
| | | for(u32 row=0; row<A.n_rows; ++row) | |
| | | { | |
| | | for(u32 col=0; col<A.n_cols; ++col) | |
| | | { | |
| | | out_mem[i] = A.at(row,col,slice); | |
| | | ++i; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | } | |
| | | | |
| // | | // | |
| // real | | // real | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| Mat<T> | | Mat<T> | |
| real(const Base<std::complex<T>, T1>& X) | | real(const Base<std::complex<T>, T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 141 | | skipping to change at line 178 | |
| T* out_mem = out.memptr(); | | T* out_mem = out.memptr(); | |
| | | | |
| for(u32 i=0; i<out.n_elem; ++i) | | for(u32 i=0; i<out.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = std::real(A_mem[i]); | | out_mem[i] = std::real(A_mem[i]); | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
|
| | | template<typename T, typename T1> | |
| | | inline | |
| | | Cube<T> | |
| | | real(const BaseCube<std::complex<T>, T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef std::complex<T> eT; | |
| | | | |
| | | const unwrap_cube<T1> A_tmp(X.get_ref()); | |
| | | const Cube<eT>& A = A_tmp.M; | |
| | | | |
| | | Cube<T> out(A.n_rows, A.n_cols, A.n_slices); | |
| | | | |
| | | const eT* A_mem = A.mem; | |
| | | T* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<out.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = std::real(A_mem[i]); | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | | |
| // | | // | |
| // imag | | // imag | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| Mat<T> | | Mat<T> | |
| imag(const Base<std::complex<T>,T1>& X) | | imag(const Base<std::complex<T>,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 169 | | skipping to change at line 231 | |
| T* out_mem = out.memptr(); | | T* out_mem = out.memptr(); | |
| | | | |
| for(u32 i=0; i<out.n_elem; ++i) | | for(u32 i=0; i<out.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = std::imag(A_mem[i]); | | out_mem[i] = std::imag(A_mem[i]); | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
|
| | | template<typename T, typename T1> | |
| | | inline | |
| | | Cube<T> | |
| | | imag(const BaseCube<std::complex<T>,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef std::complex<T> eT; | |
| | | | |
| | | const unwrap_cube<T1> A_tmp(X.get_ref()); | |
| | | const Cube<eT>& A = A_tmp.M; | |
| | | | |
| | | Cube<T> out(A.n_rows, A.n_cols, A.n_slices); | |
| | | | |
| | | const eT* A_mem = A.mem; | |
| | | T* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<out.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = std::imag(A_mem[i]); | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | | |
| // | | // | |
| // log_add | | // log_add | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| log_add(eT log_a, eT log_b) | | log_add(eT log_a, eT log_b) | |
| { | | { | |
| if(log_a < log_b) | | if(log_a < log_b) | |
| { | | { | |
| | | | |
| skipping to change at line 248 | | skipping to change at line 335 | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_log> | | const Op<T1, op_log> | |
| log(const Base<typename T1::elem_type,T1>& A) | | log(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_log>(A.get_ref()); | | return Op<T1, op_log>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_log> | |
| | | log(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_log>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // trunc_log | | // trunc_log | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_trunc_log> | | const Op<T1, op_trunc_log> | |
| trunc_log(const Base<typename T1::elem_type,T1>& A) | | trunc_log(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_trunc_log>(A.get_ref()); | | return Op<T1, op_trunc_log>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_trunc_log> | |
| | | trunc_log(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_trunc_log>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // log10 | | // log10 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_log10> | | const Op<T1, op_log10> | |
| log10(const Base<typename T1::elem_type,T1>& A) | | log10(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_log10>(A.get_ref()); | | return Op<T1, op_log10>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_log10> | |
| | | log10(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_log10>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // exp | | // exp | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_exp> | | const Op<T1, op_exp> | |
| exp(const Base<typename T1::elem_type,T1>& A) | | exp(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_exp>(A.get_ref()); | | return Op<T1, op_exp>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_exp> | |
| | | exp(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_exp>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // trunc_exp | | // trunc_exp | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_trunc_exp> | | const Op<T1, op_trunc_exp> | |
| trunc_exp(const Base<typename T1::elem_type,T1>& A) | | trunc_exp(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_trunc_exp>(A.get_ref()); | | return Op<T1, op_trunc_exp>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_trunc_exp> | |
| | | trunc_exp(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_trunc_exp>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // abs | | // abs | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| Mat<typename T1::pod_type> | | Mat<typename T1::pod_type> | |
| abs(const Base<typename T1::elem_type,T1>& X) | | abs(const Base<typename T1::elem_type,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 334 | | skipping to change at line 471 | |
| out_eT* out_mem = out.memptr(); | | out_eT* out_mem = out.memptr(); | |
| | | | |
| for(u32 i=0; i<out.n_elem; ++i) | | for(u32 i=0; i<out.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = std::abs(A_mem[i]); | | out_mem[i] = std::abs(A_mem[i]); | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | Cube<typename T1::pod_type> | |
| | | abs(const BaseCube<typename T1::elem_type,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap_cube<T1> A_tmp(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; | |
| | | | |
| | | const Cube<in_eT>& A = A_tmp.M; | |
| | | | |
| | | Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices); | |
| | | | |
| | | const in_eT* A_mem = A.mem; | |
| | | out_eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<out.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = std::abs(A_mem[i]); | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | | |
| // | | // | |
| // fabs | | // fabs | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| Mat<typename T1::pod_type> | | Mat<typename T1::pod_type> | |
| fabs(const Base<typename T1::elem_type,T1>& A) | | fabs(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return abs(A); | | return abs(A); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | Cube<typename T1::pod_type> | |
| | | fabs(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return abs(A); | |
| | | } | |
| | | | |
| // | | // | |
| // square | | // square | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_square> | | const Op<T1, op_square> | |
| square(const Base<typename T1::elem_type,T1>& A) | | square(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_square>(A.get_ref()); | | return Op<T1, op_square>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_square> | |
| | | square(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_square>(A.get_ref()); | |
| | | } | |
| | | | |
| // | | // | |
| // sqrt | | // sqrt | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_sqrt> | | const Op<T1, op_sqrt> | |
| sqrt(const Base<typename T1::elem_type,T1>& A) | | sqrt(const Base<typename T1::elem_type,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_sqrt>(A.get_ref()); | | return Op<T1, op_sqrt>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_sqrt> | |
| | | sqrt(const BaseCube<typename T1::elem_type,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_sqrt>(A.get_ref()); | |
| | | } | |
| | | | |
| // pow | | // pow | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_pow> | | const Op<T1, op_pow> | |
| pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type
exponent) | | pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type
exponent) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_pow>(A.get_ref(), exponent); | | return Op<T1, op_pow>(A.get_ref(), exponent); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_pow> | |
| | | pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t | |
| | | ype exponent) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_pow>(A.get_ref(), exponent); | |
| | | } | |
| | | | |
| // pow, specialised handling (non-complex exponent for complex matrices) | | // pow, specialised handling (non-complex exponent for complex matrices) | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_pow> | | const Op<T1, op_pow> | |
| pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type:
:value_type exponent) | | pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type:
:value_type exponent) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_pow>(A.get_ref(), eT(exponent)); | | return Op<T1, op_pow>(A.get_ref(), eT(exponent)); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_pow> | |
| | | pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t | |
| | | ype::value_type exponent) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_pow>(A.get_ref(), eT(exponent)); | |
| | | } | |
| | | | |
| // pow_s32 (integer exponent) | | // pow_s32 (integer exponent) | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_pow_s32> | | const Op<T1, op_pow_s32> | |
| pow(const Base<typename T1::elem_type,T1>& A, const s32 exponent) | | pow(const Base<typename T1::elem_type,T1>& A, const s32 exponent) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(exponent >= 0) | | if(exponent >= 0) | |
| { | | { | |
| return Op<T1, op_pow_s32>(A.get_ref(), exponent, 0); | | return Op<T1, op_pow_s32>(A.get_ref(), exponent, 0); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return Op<T1, op_pow_s32>(A.get_ref(), -exponent, 1); | | return Op<T1, op_pow_s32>(A.get_ref(), -exponent, 1); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_pow_s32> | |
| | | pow(const BaseCube<typename T1::elem_type,T1>& A, const s32 exponent) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(exponent >= 0) | |
| | | { | |
| | | return OpCube<T1, op_pow_s32>(A.get_ref(), exponent, 0); | |
| | | } | |
| | | else | |
| | | { | |
| | | return OpCube<T1, op_pow_s32>(A.get_ref(), -exponent, 1); | |
| | | } | |
| | | } | |
| | | | |
| // conj | | // conj | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| const Op<T1, op_conj> | | const Op<T1, op_conj> | |
| conj(const Base<std::complex<T>,T1>& A) | | conj(const Base<std::complex<T>,T1>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return Op<T1, op_conj>(A.get_ref()); | | return Op<T1, op_conj>(A.get_ref()); | |
| } | | } | |
| | | | |
|
| | | template<typename T, typename T1> | |
| | | inline | |
| | | const OpCube<T1, op_conj> | |
| | | conj(const BaseCube<std::complex<T>,T1>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return OpCube<T1, op_conj>(A.get_ref()); | |
| | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const T1& | | const T1& | |
| conj(const Op<T1, op_conj>& A) | | conj(const Op<T1, op_conj>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return A.m; | | return A.m; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | const T1& | |
| | | conj(const OpCube<T1, op_conj>& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return A.m; | |
| | | } | |
| | | | |
| //! the conjugate of the transpose of a complex matrix is the same as the h
ermitian transpose | | //! the conjugate of the transpose of a complex matrix is the same as the h
ermitian transpose | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| const Op<T1, op_htrans> | | const Op<T1, op_htrans> | |
| conj(const Op<T1, op_trans>& A) | | conj(const Op<T1, op_trans>& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_type_check< is_complex<typename T1::elem_type>::value == false >::ap
ply(); | | arma_type_check< is_complex<typename T1::elem_type>::value == false >::ap
ply(); | |
| | | | |
| | | | |
End of changes. 20 change blocks. |
| 9 lines changed or deleted | | 268 lines changed or added | |
|
| glue_plus_meat.hpp | | glue_plus_meat.hpp | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| // no aliasing problem | | // no aliasing problem | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] = A_mem[i] + B_mem[i]; | | out_mem[i] = A_mem[i] + B_mem[i]; | |
| | | | |
| skipping to change at line 54 | | skipping to change at line 55 | |
| inline | | inline | |
| void | | void | |
| glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Ma
t<eT>& C) | | glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Ma
t<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| arma_debug_assert_same_size(A, C, "matrix addition"); | | arma_debug_assert_same_size(A, C, "matrix addition"); | |
| | | | |
| // no aliasing problem | | // no aliasing problem | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| const eT* C_mem = C.mem; | | const eT* C_mem = C.mem; | |
| | | | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 195 | | skipping to change at line 197 | |
| const Mat<eT>& orig_A = X.A; | | const Mat<eT>& orig_A = X.A; | |
| const Mat<eT>& orig_B = X.B.m; | | const Mat<eT>& orig_B = X.B.m; | |
| | | | |
| if( &out != &orig_B ) | | if( &out != &orig_B ) | |
| { | | { | |
| //const u32 sub_B_n_rows = X.B.n_rows; | | //const u32 sub_B_n_rows = X.B.n_rows; | |
| //const u32 sub_B_n_cols = X.B.n_cols; | | //const u32 sub_B_n_cols = X.B.n_cols; | |
| | | | |
| arma_debug_assert_same_size(X.A, X.B, "matrix addition"); | | arma_debug_assert_same_size(X.A, X.B, "matrix addition"); | |
| | | | |
|
| out.set_size(orig_A.n_rows, orig_A.n_cols); | | //out.set_size(orig_A.n_rows, orig_A.n_cols); | |
| | | out.copy_size(orig_A); | |
| | | | |
| for(u32 col = 0; col<orig_A.n_cols; ++col) | | for(u32 col = 0; col<orig_A.n_cols; ++col) | |
| { | | { | |
| const u32 B_col_mod = X.B.aux_col1 + col; | | const u32 B_col_mod = X.B.aux_col1 + col; | |
| | | | |
| for(u32 row = 0; row<orig_A.n_rows; ++row) | | for(u32 row = 0; row<orig_A.n_rows; ++row) | |
| { | | { | |
| const u32 B_row_mod = X.B.aux_row1 + row; | | const u32 B_row_mod = X.B.aux_row1 + row; | |
| | | | |
| out.at(row,col) = orig_A.at(row, col) + orig_B.at(B_row_mod, B_col
_mod); | | out.at(row,col) = orig_A.at(row, col) + orig_B.at(B_row_mod, B_col
_mod); | |
| | | | |
| skipping to change at line 515 | | skipping to change at line 518 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp1(in.A.m); | | const unwrap<T1> tmp1(in.A.m); | |
| const unwrap<T2> tmp2(in.B.m); | | const unwrap<T2> tmp2(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.aux; | | const eT k1 = in.A.aux; | |
| const eT k2 = in.B.aux; | | const eT k2 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const u32 local_n_elem = A.n_elem; | | const u32 local_n_elem = A.n_elem; | |
| | | | |
| | | | |
| skipping to change at line 557 | | skipping to change at line 561 | |
| const unwrap<T2> tmp2(in.A.B.m); | | const unwrap<T2> tmp2(in.A.B.m); | |
| const unwrap<T3> tmp3(in.B.m); | | const unwrap<T3> tmp3(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| const Mat<eT>& C = tmp3.M; | | const Mat<eT>& C = tmp3.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| arma_debug_assert_same_size(B, C, "matrix addition"); | | arma_debug_assert_same_size(B, C, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.A.aux; | | const eT k1 = in.A.A.aux; | |
| const eT k2 = in.A.B.aux; | | const eT k2 = in.A.B.aux; | |
| const eT k3 = in.B.aux; | | const eT k3 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| const eT* C_mem = C.mem; | | const eT* C_mem = C.mem; | |
| | | | |
| | | | |
| skipping to change at line 598 | | skipping to change at line 603 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp1(in.A.m); | | const unwrap<T1> tmp1(in.A.m); | |
| const unwrap<T2> tmp2(in.B.m); | | const unwrap<T2> tmp2(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.aux; | | const eT k1 = in.A.aux; | |
| const eT k2 = in.B.aux; | | const eT k2 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const u32 local_n_elem = A.n_elem; | | const u32 local_n_elem = A.n_elem; | |
| | | | |
| | | | |
| skipping to change at line 640 | | skipping to change at line 646 | |
| const unwrap<T2> tmp2(in.A.B.m); | | const unwrap<T2> tmp2(in.A.B.m); | |
| const unwrap<T3> tmp3(in.B.m); | | const unwrap<T3> tmp3(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| const Mat<eT>& C = tmp3.M; | | const Mat<eT>& C = tmp3.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| arma_debug_assert_same_size(B, C, "matrix addition"); | | arma_debug_assert_same_size(B, C, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.A.aux; | | const eT k1 = in.A.A.aux; | |
| const eT k2 = in.A.B.aux; | | const eT k2 = in.A.B.aux; | |
| const eT k3 = in.B.aux; | | const eT k3 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| const eT* C_mem = C.mem; | | const eT* C_mem = C.mem; | |
| | | | |
| | | | |
| skipping to change at line 681 | | skipping to change at line 688 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp1(in.A.m); | | const unwrap<T1> tmp1(in.A.m); | |
| const unwrap<T2> tmp2(in.B.m); | | const unwrap<T2> tmp2(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.aux; | | const eT k1 = in.A.aux; | |
| const eT k2 = in.B.aux; | | const eT k2 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const u32 local_n_elem = A.n_elem; | | const u32 local_n_elem = A.n_elem; | |
| | | | |
| | | | |
| skipping to change at line 723 | | skipping to change at line 731 | |
| const unwrap<T2> tmp2(in.A.B.m); | | const unwrap<T2> tmp2(in.A.B.m); | |
| const unwrap<T3> tmp3(in.B.m); | | const unwrap<T3> tmp3(in.B.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| const Mat<eT>& C = tmp3.M; | | const Mat<eT>& C = tmp3.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| arma_debug_assert_same_size(B, C, "matrix addition"); | | arma_debug_assert_same_size(B, C, "matrix addition"); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| const eT k1 = in.A.A.aux; | | const eT k1 = in.A.A.aux; | |
| const eT k2 = in.A.B.aux; | | const eT k2 = in.A.B.aux; | |
| const eT k3 = in.B.aux; | | const eT k3 = in.B.aux; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| const eT* C_mem = C.mem; | | const eT* C_mem = C.mem; | |
| | | | |
| | | | |
| skipping to change at line 757 | | skipping to change at line 766 | |
| inline | | inline | |
| void | | void | |
| glue_plus::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, co
nst Mat<eT1>& X, const Mat<eT2>& Y) | | glue_plus::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, co
nst Mat<eT1>& X, const Mat<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename promote_type<eT1,eT2>::result out_eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| arma_debug_assert_same_size(X,Y, "matrix addition"); | | arma_debug_assert_same_size(X,Y, "matrix addition"); | |
| | | | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| out_eT* out_mem = out.memptr(); | | out_eT* out_mem = out.memptr(); | |
| const eT1* X_mem = X.mem; | | const eT1* X_mem = X.mem; | |
| const eT2* Y_mem = Y.mem; | | const eT2* Y_mem = Y.mem; | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] = upgrade_val<eT1,eT2>::apply(X_mem[i]) + upgrade_val<eT1,eT
2>::apply(Y_mem[i]); | | out_mem[i] = upgrade_val<eT1,eT2>::apply(X_mem[i]) + upgrade_val<eT1,eT
2>::apply(Y_mem[i]); | |
| | | | |
| skipping to change at line 795 | | skipping to change at line 805 | |
| const unwrap<T1> tmp1(A_orig); | | const unwrap<T1> tmp1(A_orig); | |
| const unwrap<T2> tmp2(B_orig.m); | | const unwrap<T2> tmp2(B_orig.m); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_check( !B.is_square(), "glue_plus_diag::apply(): matrices must
be square" ); | | arma_debug_check( !B.is_square(), "glue_plus_diag::apply(): matrices must
be square" ); | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| // no aliasing problem | | // no aliasing problem | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| for(u32 col=0; col<A.n_cols; ++col) | | for(u32 col=0; col<A.n_cols; ++col) | |
| { | | { | |
| for(u32 row=0; row<A.n_rows; ++row) | | for(u32 row=0; row<A.n_rows; ++row) | |
| { | | { | |
| if(col != row) | | if(col != row) | |
| { | | { | |
| out.at(row,col) = A.at(row,col); | | out.at(row,col) = A.at(row,col); | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 845 | | skipping to change at line 856 | |
| { | | { | |
| out.zeros(A.n_rows, A.n_cols); | | out.zeros(A.n_rows, A.n_cols); | |
| | | | |
| for(u32 i=0; i<A.n_rows; ++i) | | for(u32 i=0; i<A.n_rows; ++i) | |
| { | | { | |
| out.at(i,i) = A.at(i,i) + B.at(i,i); | | out.at(i,i) = A.at(i,i) + B.at(i,i); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| for(u32 col=0; col<A.n_cols; ++col) | | for(u32 col=0; col<A.n_cols; ++col) | |
| { | | { | |
| for(u32 row=0; row<A.n_rows; ++row) | | for(u32 row=0; row<A.n_rows; ++row) | |
| { | | { | |
| if(col != row) | | if(col != row) | |
| { | | { | |
| out.at(row,col) = 0.0; | | out.at(row,col) = 0.0; | |
| } | | } | |
| else | | else | |
| | | | |
End of changes. 12 change blocks. |
| 12 lines changed or deleted | | 24 lines changed or added | |
|
| op_misc_meat.hpp | | op_misc_meat.hpp | |
| | | | |
| skipping to change at line 30 | | skipping to change at line 30 | |
| void | | void | |
| op_log::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_log>& in) | | op_log::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_log>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::log(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_log>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::log(A.mem[i]); | | out_ptr[i] = std::log(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 54 | | skipping to change at line 82 | |
| void | | void | |
| op_trunc_log::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_trunc_
log>& in) | | op_trunc_log::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_trunc_
log>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = trunc_log(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_trunc_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t | |
| | | runc_log>& in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = trunc_log(A.mem[i]); | | out_ptr[i] = trunc_log(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 78 | | skipping to change at line 134 | |
| void | | void | |
| op_log10::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_log10>& in
) | | op_log10::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_log10>& in
) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::log10(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_log10::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_log10 | |
| | | >& in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::log10(A.mem[i]); | | out_ptr[i] = std::log10(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 104 | | skipping to change at line 188 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::exp(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_exp>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::exp(A.mem[i]); | | out_ptr[i] = std::exp(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 126 | | skipping to change at line 238 | |
| void | | void | |
| op_trunc_exp::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_trunc_
exp>& in) | | op_trunc_exp::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_trunc_
exp>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = trunc_exp(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_trunc_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t | |
| | | runc_exp>& in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = trunc_exp(A.mem[i]); | | out_ptr[i] = trunc_exp(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 150 | | skipping to change at line 290 | |
| void | | void | |
| op_sqrt::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sqrt>& in) | | op_sqrt::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sqrt>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::sqrt(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_sqrt::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_sqrt>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::sqrt(A.mem[i]); | | out_ptr[i] = std::sqrt(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 176 | | skipping to change at line 344 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | const eT tmp_val = A.mem[i]; | |
| | | out_ptr[i] = tmp_val*tmp_val; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_square::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_squa | |
| | | re>& in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| const eT tmp_val = A.mem[i]; | | const eT tmp_val = A.mem[i]; | |
| out_ptr[i] = tmp_val*tmp_val; | | out_ptr[i] = tmp_val*tmp_val; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 199 | | skipping to change at line 396 | |
| void | | void | |
| op_pow::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pow>& in) | | op_pow::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pow>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::pow(A.mem[i], in.aux); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_pow::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_pow>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::pow(A.mem[i], in.aux); | | out_ptr[i] = std::pow(A.mem[i], in.aux); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| | | | |
| skipping to change at line 227 | | skipping to change at line 452 | |
| | | | |
| typedef std::complex<T> eT; | | typedef std::complex<T> eT; | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | if(in.aux.imag() == T(0)) | |
| | | { | |
| | | const T in_aux_real = in.aux.real(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::pow(A.mem[i], in_aux_real); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::pow(A.mem[i], in.aux); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | op_pow::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_pow>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef std::complex<T> eT; | |
| | | | |
| | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| if(in.aux.imag() == T(0)) | | if(in.aux.imag() == T(0)) | |
| { | | { | |
| const T in_aux_real = in.aux.real(); | | const T in_aux_real = in.aux.real(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::pow(A.mem[i], in_aux_real); | | out_ptr[i] = std::pow(A.mem[i], in_aux_real); | |
| } | | } | |
| | | | |
| skipping to change at line 300 | | skipping to change at line 566 | |
| void | | void | |
| op_pow_s32::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pow_s32>
& in) | | op_pow_s32::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pow_s32>
& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | const int exponent = (in.aux_u32_b == 0) ? in.aux_u32_a : -in.aux_u32_a; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_ptr[i] = std::pow(A.mem[i], exponent); // causes problems with g | |
| | | cc 4.1/4.2 for base that has an integer type | |
| | | out_ptr[i] = op_pow_s32::internal_pow(A.mem[i], exponent); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_pow_s32::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_pow | |
| | | _s32>& in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| const int exponent = (in.aux_u32_b == 0) ? in.aux_u32_a : -in.aux_u32_a; | | const int exponent = (in.aux_u32_b == 0) ? in.aux_u32_a : -in.aux_u32_a; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| //out_ptr[i] = std::pow(A.mem[i], exponent); // causes problems with g
cc 4.1/4.2 for base that has an integer type | | //out_ptr[i] = std::pow(A.mem[i], exponent); // causes problems with g
cc 4.1/4.2 for base that has an integer type | |
| out_ptr[i] = op_pow_s32::internal_pow(A.mem[i], exponent); | | out_ptr[i] = op_pow_s32::internal_pow(A.mem[i], exponent); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 329 | | skipping to change at line 626 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| arma_type_check< is_complex<T1>::value == true >::apply(); | | arma_type_check< is_complex<T1>::value == true >::apply(); | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
|
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::conj(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_conj::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_conj>& | |
| | | in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | arma_type_check< is_complex<T1>::value == true >::apply(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::conj(A.mem[i]); | | out_ptr[i] = std::conj(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 19 change blocks. |
| 19 lines changed or deleted | | 357 lines changed or added | |
|
| op_scalar_misc_meat.hpp | | op_scalar_misc_meat.hpp | |
| | | | |
| skipping to change at line 18 | | skipping to change at line 18 | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup op_scalar_misc | | //! \addtogroup op_scalar_misc | |
| //! @{ | | //! @{ | |
| | | | |
|
| //! Add a scalar to all elements of a matrix and store the result in a dens
e matrix | | //! Add a scalar to all elements of a matrix | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_plus::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scal
ar_plus>& in) | | op_scalar_plus::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_scal
ar_plus>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = X_mem[i] + k; | | out_mem[i] = X_mem[i] + k; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! For each element of a matrix, subtract it from a scalar and store the r | | //! Add a scalar to all elements of a cube | |
| esult in a dense matrix | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_plus::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op | |
| | | _scalar_plus>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i<X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = X_mem[i] + k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! For each element of a matrix, subtract it from a scalar | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_minus_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_scalar_minus_pre>& in) | | op_scalar_minus_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_scalar_minus_pre>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i<X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k - X_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! For each element of a cube, subtract it from a scalar | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_minus_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< | |
| | | T1,op_scalar_minus_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = k - X_mem[i]; | | out_mem[i] = k - X_mem[i]; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 86 | | skipping to change at line 144 | |
| op_scalar_minus_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,o
p_scalar_minus_post>& in) | | op_scalar_minus_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,o
p_scalar_minus_post>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i<X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = X_mem[i] - k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! subtract a scalar from each element of a cube | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_minus_post::apply(Cube<typename T1::elem_type>& out, const OpCube | |
| | | <T1,op_scalar_minus_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = X_mem[i] - k; | | out_mem[i] = X_mem[i] - k; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! Multiply all elements of a matrix by a scalar and store the result in a
dense matrix | | //! Multiply all elements of a matrix by a scalar | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sca
lar_times>& in) | | op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sca
lar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = X_mem[i] * k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Multiply all elements of a cube by a scalar | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,o | |
| | | p_scalar_times>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i < X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = X_mem[i] * k; | | out_mem[i] = X_mem[i] * k; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! \brief | | | |
| //! Evaluate Glue<T1,T2,glue_type>, and then multiply each element of the r
esult by a scalar. | | //! Evaluate Glue<T1,T2,glue_type>, and then multiply each element of the r
esult by a scalar. | |
|
| //! Store the final result in a dense matrix. | | | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op<Glue<T1,T
2,glue_type>, op_scalar_times>& in) | | op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op<Glue<T1,T
2,glue_type>, op_scalar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| out = in.m; // implicit conversion to 'Mat<eT>' | | out = in.m; // implicit conversion to 'Mat<eT>' | |
| | | | |
| skipping to change at line 150 | | skipping to change at line 264 | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] *= k; | | out_mem[i] *= k; | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! \brief | | //! Evaluate GlueCube<T1,T2,glue_type>, and then multiply each element of t | |
| | | he result by a scalar. | |
| | | template<typename T1, typename T2, typename glue_type> | |
| | | inline | |
| | | void | |
| | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube<Glue | |
| | | Cube<T1,T2,glue_type>, op_scalar_times>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | out = in.m; // implicit conversion to 'Cube<eT>' | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] *= k; | |
| | | } | |
| | | } | |
| | | | |
| //! Evaluate A + B, and then multiply each element of the result by a scala
r. | | //! Evaluate A + B, and then multiply each element of the result by a scala
r. | |
|
| //! Store the final result in a dense matrix. | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_plus>, op_scalar_times>& in) | | op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_plus>, op_scalar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp1(in.m.A); | | const unwrap<T1> tmp1(in.m.A); | |
| const unwrap<T2> tmp2(in.m.B); | | const unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] + B_mem[i]) * k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Evaluate A + B, and then multiply each element of the result by a scala | |
| | | r. | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< Glu | |
| | | eCube<T1,T2,glue_cube_plus>, op_scalar_times>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap_cube<T1> tmp1(in.m.A); | |
| | | const unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube addition"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] = (A_mem[i] + B_mem[i]) * k; | | out_mem[i] = (A_mem[i] + B_mem[i]) * k; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! \brief | | | |
| //! Evaluate A - B, and then multiply each element of the result by a scala
r. | | //! Evaluate A - B, and then multiply each element of the result by a scala
r. | |
|
| //! Store the final result in a dense matrix. | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_minus>, op_scalar_times>& in) | | op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_minus>, op_scalar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp1(in.m.A); | | const unwrap<T1> tmp1(in.m.A); | |
| const unwrap<T2> tmp2(in.m.B); | | const unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix subtraction"); | | arma_debug_assert_same_size(A, B, "matrix subtraction"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] - B_mem[i]) * k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Evaluate A - B, and then multiply each element of the result by a scala | |
| | | r. | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< Glu | |
| | | eCube<T1,T2,glue_cube_minus>, op_scalar_times>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap_cube<T1> tmp1(in.m.A); | |
| | | const unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube subtraction"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] = (A_mem[i] - B_mem[i]) * k; | | out_mem[i] = (A_mem[i] - B_mem[i]) * k; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! \brief | | | |
| //! Evaluate A % B (where % is the element-wise multiply operation) and the
n multiply each element of the result by a scalar. | | //! Evaluate A % B (where % is the element-wise multiply operation) and the
n multiply each element of the result by a scalar. | |
|
| //! Store the final result in a dense matrix. | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_schur>, op_scalar_times>& in) | | op_scalar_times::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,
T2,glue_schur>, op_scalar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp1(in.m.A); | | const unwrap<T1> tmp1(in.m.A); | |
| const unwrap<T2> tmp2(in.m.B); | | const unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "schur product"); | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] * B_mem[i]) * k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Evaluate A % B (where % is the element-wise multiply operation) and the | |
| | | n multiply each element of the result by a scalar. | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube< Glu | |
| | | eCube<T1,T2,glue_cube_schur>, op_scalar_times>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap_cube<T1> tmp1(in.m.A); | |
| | | const unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 278 | | skipping to change at line 519 | |
| op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_s
calar_div_pre>& in) | | op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_s
calar_div_pre>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // TODO: analyse effects of aliasing | | // TODO: analyse effects of aliasing | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / X_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<T1 | |
| | | ,op_scalar_div_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // TODO: analyse effects of aliasing | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i < X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = k / X_mem[i]; | | out_mem[i] = k / X_mem[i]; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 302 | | skipping to change at line 571 | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_pre::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_pre>&
in) | | op_scalar_div_pre::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_pre>&
in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Mat<eT>& X = in.m; | | const Mat<eT>& X = in.m; | |
| | | | |
| if(&out != &X) | | if(&out != &X) | |
| { | | { | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / X_mem[i]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < out.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / out_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<eT>& out, const OpCube<Cube<eT>,op_scalar_div | |
| | | _pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const Cube<eT>& X = in.m; | |
| | | | |
| | | if(&out != &X) | |
| | | { | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i < X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = k / X_mem[i]; | | out_mem[i] = k / X_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 348 | | skipping to change at line 655 | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] = k / out_mem[i]; | | out_mem[i] = k / out_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1, typename T2, typename glue_type> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<Gl | |
| | | ueCube<T1,T2,glue_type>, op_scalar_div_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | out = in.m; // implicit conversion to 'Cube<eT>' | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / out_mem[i]; | |
| | | } | |
| | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T
1,T2,glue_plus>, op_scalar_div_pre>& in) | | op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T
1,T2,glue_plus>, op_scalar_div_pre>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| unwrap<T1> tmp1(in.m.A); | | unwrap<T1> tmp1(in.m.A); | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / (A_mem[i] + B_mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< G | |
| | | lueCube<T1,T2,glue_cube_plus>, op_scalar_div_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube addition"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 400 | | skipping to change at line 764 | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix subtraction"); | | arma_debug_assert_same_size(A, B, "matrix subtraction"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / (A_mem[i] - B_mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< G | |
| | | lueCube<T1,T2,glue_cube_minus>, op_scalar_div_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube subtraction"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 434 | | skipping to change at line 834 | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "schur product"); | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / (A_mem[i] * B_mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube< G | |
| | | lueCube<T1,T2,glue_cube_schur>, op_scalar_div_pre>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 467 | | skipping to change at line 903 | |
| op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_
scalar_div_post>& in) | | op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_
scalar_div_post>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| // TODO: analyse effects of aliasing | | // TODO: analyse effects of aliasing | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = X_mem[i] / k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube<T | |
| | | 1,op_scalar_div_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | const Cube<eT>& X = tmp.M; | |
| | | | |
| | | // TODO: analyse effects of aliasing | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i < X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = X_mem[i] / k; | | out_mem[i] = X_mem[i] / k; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 491 | | skipping to change at line 955 | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_post::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_post
>& in) | | op_scalar_div_post::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_post
>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Mat<eT>& X = in.m; | | const Mat<eT>& X = in.m; | |
| | | | |
| if(&out != &X) | | if(&out != &X) | |
| { | | { | |
|
| out.set_size(X.n_rows, X.n_cols); | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* X_mem = X.mem; | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < X.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = X_mem[i] / k; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT k = in.aux; | |
| | | | |
| | | for(u32 i=0; i < out.n_elem; ++i) | |
| | | { | |
| | | out_mem[i] /= k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<eT>& out, const OpCube<Cube<eT>,op_scalar_di | |
| | | v_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const Cube<eT>& X = in.m; | |
| | | | |
| | | if(&out != &X) | |
| | | { | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* X_mem = X.mem; | | const eT* X_mem = X.mem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i < X.n_elem; ++i) | |
| { | | { | |
| out_mem[i] = X_mem[i] / k; | | out_mem[i] = X_mem[i] / k; | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 537 | | skipping to change at line 1039 | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] /= k; | | out_mem[i] /= k; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1, typename T2, typename glue_type> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube<G | |
| | | lueCube<T1,T2,glue_type>, op_scalar_div_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | out = in.m; // implicit conversion to 'Cube<eT>' | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] /= k; | |
| | | } | |
| | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op< Glue<
T1,T2,glue_plus>, op_scalar_div_post>& in) | | op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op< Glue<
T1,T2,glue_plus>, op_scalar_div_post>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| unwrap<T1> tmp1(in.m.A); | | unwrap<T1> tmp1(in.m.A); | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] + B_mem[i]) / k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< | |
| | | GlueCube<T1,T2,glue_cube_plus>, op_scalar_div_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube addition"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 589 | | skipping to change at line 1148 | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix subtraction"); | | arma_debug_assert_same_size(A, B, "matrix subtraction"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] - B_mem[i]) / k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< | |
| | | GlueCube<T1,T2,glue_cube_minus>, op_scalar_div_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube subtraction"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 623 | | skipping to change at line 1218 | |
| unwrap<T2> tmp2(in.m.B); | | unwrap<T2> tmp2(in.m.B); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Mat<eT>& B = tmp2.M; | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_same_size(A, B, "schur product"); | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| // no alias problems | | // no alias problems | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k = in.aux; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = (A_mem[i] * B_mem[i]) / k; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube< | |
| | | GlueCube<T1,T2,glue_cube_schur>, op_scalar_div_post>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | unwrap_cube<T1> tmp1(in.m.A); | |
| | | unwrap_cube<T2> tmp2(in.m.B); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "schur product"); | |
| | | | |
| | | // no alias problems | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| | | | |
End of changes. 30 change blocks. |
| 29 lines changed or deleted | | 683 lines changed or added | |
|
| op_scalar_misc_proto.hpp | | op_scalar_misc_proto.hpp | |
| | | | |
| skipping to change at line 18 | | skipping to change at line 18 | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup op_scalar_misc | | //! \addtogroup op_scalar_misc | |
| //! @{ | | //! @{ | |
| | | | |
|
| //! 'add scalar to matrix' operation | | //! 'add scalar to a matrix/cube' operation | |
| class op_scalar_plus | | class op_scalar_plus | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_plus>& in); | |
| _scalar_plus>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_plus>& in); | |
| }; | | }; | |
| | | | |
|
| //! 'subtract matrix from a scalar' operation | | //! 'subtract matrix/cube from a scalar' operation | |
| class op_scalar_minus_pre | | class op_scalar_minus_pre | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_minus_pre>& in); | |
| _scalar_minus_pre>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_minus_pre>& in); | |
| }; | | }; | |
| | | | |
|
| //! 'subtract scalar from matrix' operation | | //! 'subtract scalar from a matrix/cube' operation | |
| class op_scalar_minus_post | | class op_scalar_minus_post | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_minus_post>& in); | |
| _scalar_minus_post>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_minus_post>& in); | |
| }; | | }; | |
| | | | |
|
| //! 'multiply matrix by a scalar' operation | | //! 'multiply matrix/cube by a scalar' operation | |
| class op_scalar_times | | class op_scalar_times | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_times>& in); | |
| _scalar_times>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_times>& in); | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> inline static void | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | |
| T1,T2,glue_type>, op_scalar_times>& in); | | type>, op_scalar_times>& in); | |
| | | template<typename T1, typename T2, typename glue_type> inline static void | |
| | | apply(Cube<typename T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_ | |
| | | type>, op_scalar_times>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, op_scal | |
| T1,T2,glue_plus>, op_scalar_times>& in); | | ar_times>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_plus>, op_scal | |
| | | ar_times>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_minus>, op_scal | |
| T1,T2,glue_minus>, op_scalar_times>& in); | | ar_times>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| template<typename T1, typename T2> | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_minus>, op_scal | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | ar_times>& in); | |
| T1,T2,glue_schur>, op_scalar_times>& in); | | | |
| | | | |
|
| | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_schur>, op_scal | |
| | | ar_times>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_schur>, op_scal | |
| | | ar_times>& in); | |
| }; | | }; | |
| | | | |
|
| //! 'divide scalar by a matrix' operation | | //! 'divide scalar by a matrix/cube' operation | |
| class op_scalar_div_pre | | class op_scalar_div_pre | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_div_pre>& in); | |
| _scalar_div_pre>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_div_pre>& in); | |
| template<typename eT> | | | |
| inline static void apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_pre | | | |
| >& in); | | | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> inline static void apply( Mat<eT>& out, const O | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | p< Mat<eT>,op_scalar_div_pre>& in); | |
| T1,T2,glue_type>, op_scalar_div_pre>& in); | | template<typename eT> inline static void apply(Cube<eT>& out, const OpCub | |
| | | e<Cube<eT>,op_scalar_div_pre>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2, typename glue_type> inline static void | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | |
| T1,T2,glue_plus>, op_scalar_div_pre>& in); | | type>, op_scalar_div_pre>& in); | |
| | | template<typename T1, typename T2, typename glue_type> inline static void | |
| | | apply(Cube<typename T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_ | |
| | | type>, op_scalar_div_pre>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, op_scal | |
| T1,T2,glue_minus>, op_scalar_div_pre>& in); | | ar_div_pre>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_plus>, op_scal | |
| | | ar_div_pre>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_minus>, op_scal | |
| T1,T2,glue_schur>, op_scalar_div_pre>& in); | | ar_div_pre>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_minus>, op_scal | |
| | | ar_div_pre>& in); | |
| | | | |
|
| | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_schur>, op_scal | |
| | | ar_div_pre>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_schur>, op_scal | |
| | | ar_div_pre>& in); | |
| }; | | }; | |
| | | | |
|
| //! 'divide matrix by a scalar' operation | | //! 'divide matrix/cube by a scalar' operation | |
| class op_scalar_div_post | | class op_scalar_div_post | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename T1> | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op | | e>& out, const Op<T1,op_scalar_div_post>& in); | |
| _scalar_div_post>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_scalar_div_post>& in); | |
| template<typename eT> | | | |
| inline static void apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_pos | | | |
| t>& in); | | | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> inline static void apply( Mat<eT>& out, const O | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | p< Mat<eT>,op_scalar_div_post>& in); | |
| T1,T2,glue_type>, op_scalar_div_post>& in); | | template<typename eT> inline static void apply(Cube<eT>& out, const OpCub | |
| | | e<Cube<eT>,op_scalar_div_post>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2, typename glue_type> inline static void | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | |
| T1,T2,glue_plus>, op_scalar_div_post>& in); | | type>, op_scalar_div_post>& in); | |
| | | template<typename T1, typename T2, typename glue_type> inline static void | |
| | | apply(Cube<typename T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_ | |
| | | type>, op_scalar_div_post>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, op_scal | |
| T1,T2,glue_minus>, op_scalar_div_post>& in); | | ar_div_post>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_plus>, op_scal | |
| | | ar_div_post>& in); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue< | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_minus>, op_scal | |
| T1,T2,glue_schur>, op_scalar_div_post>& in); | | ar_div_post>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_minus>, op_scal | |
| | | ar_div_post>& in); | |
| | | | |
|
| | | template<typename T1, typename T2> inline static void apply( Mat<typename | |
| | | T1::elem_type>& out, const Op< Glue<T1,T2, glue_schur>, op_scal | |
| | | ar_div_post>& in); | |
| | | template<typename T1, typename T2> inline static void apply(Cube<typename | |
| | | T1::elem_type>& out, const OpCube<GlueCube<T1,T2,glue_cube_schur>, op_scal | |
| | | ar_div_post>& in); | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 26 change blocks. |
| 69 lines changed or deleted | | 110 lines changed or added | |
|
| op_trig_meat.hpp | | op_trig_meat.hpp | |
| | | | |
| skipping to change at line 40 | | skipping to change at line 40 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::cos(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_cos::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_cos>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::cos(A.mem[i]); | | out_ptr[i] = std::cos(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 64 | | skipping to change at line 92 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::acos(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_acos::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_acos>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::acos(A.mem[i]); | | out_ptr[i] = std::acos(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| | | | |
| skipping to change at line 91 | | skipping to change at line 147 | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::acos(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_acos::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | op_acos::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_acos>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename std::complex<T> eT; | |
| | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::acos(A.mem[i]); | | out_ptr[i] = boost::math::acos(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_acos::apply(): need Boost libraries"); | | arma_stop("op_acos::apply(): need Boost libraries"); | |
| | | | |
| skipping to change at line 120 | | skipping to change at line 212 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::cosh(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_cosh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_cosh>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::cosh(A.mem[i]); | | out_ptr[i] = std::cosh(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 146 | | skipping to change at line 266 | |
| | | | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::acosh(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_acosh::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_acosh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_acosh | |
| | | >& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::acosh(A.mem[i]); | | out_ptr[i] = boost::math::acosh(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_acosh::apply(): need Boost libraries"); | | arma_stop("op_acosh::apply(): need Boost libraries"); | |
| | | | |
| skipping to change at line 178 | | skipping to change at line 334 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::sin(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_sin::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_sin>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::sin(A.mem[i]); | | out_ptr[i] = std::sin(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 202 | | skipping to change at line 386 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::acos(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_asin::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asin>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::acos(A.mem[i]); | | out_ptr[i] = std::acos(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| | | | |
| skipping to change at line 229 | | skipping to change at line 441 | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::asin(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_asin::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | op_asin::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_asin>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename std::complex<T> eT; | |
| | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::asin(A.mem[i]); | | out_ptr[i] = boost::math::asin(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_asin::apply(): need Boost libraries"); | | arma_stop("op_asin::apply(): need Boost libraries"); | |
| | | | |
| skipping to change at line 258 | | skipping to change at line 506 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::sinh(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_sinh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_sinh>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::sinh(A.mem[i]); | | out_ptr[i] = std::sinh(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 284 | | skipping to change at line 560 | |
| | | | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::asinh(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_asinh::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_asinh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asinh | |
| | | >& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::asinh(A.mem[i]); | | out_ptr[i] = boost::math::asinh(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_asinh::apply(): need Boost libraries"); | | arma_stop("op_asinh::apply(): need Boost libraries"); | |
| | | | |
| skipping to change at line 315 | | skipping to change at line 626 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::tan(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_tan::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_tan>& i | |
| | | n) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::tan(A.mem[i]); | | out_ptr[i] = std::tan(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 339 | | skipping to change at line 678 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::atan(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_atan::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_atan>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::atan(A.mem[i]); | | out_ptr[i] = std::atan(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| | | | |
| skipping to change at line 366 | | skipping to change at line 733 | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::atan(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_asin::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | op_atan::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_atan>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename std::complex<T> eT; | |
| | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::atan(A.mem[i]); | | out_ptr[i] = boost::math::atan(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_asin::apply(): need Boost libraries"); | | arma_stop("op_asin::apply(): need Boost libraries"); | |
| | | | |
| skipping to change at line 395 | | skipping to change at line 798 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = std::tanh(A.mem[i]); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_tanh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_tanh>& | |
| | | in) | |
| | | { | |
| | | 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 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = std::tanh(A.mem[i]); | | out_ptr[i] = std::tanh(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 421 | | skipping to change at line 852 | |
| | | | |
| #if defined(ARMA_USE_BOOST) | | #if defined(ARMA_USE_BOOST) | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(in.m); | | const unwrap<T1> tmp(in.m); | |
| | | | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| out.set_size(A.n_rows, A.n_cols); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_ptr = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_ptr[i] = boost::math::atanh(A.mem[i]); | |
| | | } | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("op_atanh::apply(): need Boost libraries"); | |
| | | } | |
| | | #endif | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | op_atanh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_atanh | |
| | | >& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_BOOST) | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| | | const Cube<eT>& A = tmp.M; | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| eT* out_ptr = out.memptr(); | | eT* out_ptr = out.memptr(); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_ptr[i] = boost::math::atanh(A.mem[i]); | | out_ptr[i] = boost::math::atanh(A.mem[i]); | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("op_atanh::apply(): need Boost libraries"); | | arma_stop("op_atanh::apply(): need Boost libraries"); | |
| | | | |
End of changes. 15 change blocks. |
| 15 lines changed or deleted | | 494 lines changed or added | |
|
| op_trig_proto.hpp | | op_trig_proto.hpp | |
| | | | |
| skipping to change at line 29 | | skipping to change at line 29 | |
| // trigonometric functions: | | // trigonometric functions: | |
| // cos family: cos, acos, cosh, acosh | | // cos family: cos, acos, cosh, acosh | |
| // sin family: sin, asin, sinh, asinh | | // sin family: sin, asin, sinh, asinh | |
| // tan family: tan, atan, tanh, atanh | | // tan family: tan, atan, tanh, atanh | |
| | | | |
| // cos family | | // cos family | |
| | | | |
| class op_cos | | class op_cos | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_cos>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_cos>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_cos>& in); | |
| }; | | }; | |
| | | | |
| class op_acos | | class op_acos | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_acos>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| template<typename T, typename T1> inline static void apply(Mat< std::comp | | e>& out, const Op<T1,op_acos>& in); | |
| lex<T> >& out, const Op<T1,op_acos>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_acos>& in); | |
| | | | |
| | | template<typename T, typename T1> inline static void apply( Mat< std::com | |
| | | plex<T> >& out, const Op<T1,op_acos>& in); | |
| | | template<typename T, typename T1> inline static void apply(Cube< std::com | |
| | | plex<T> >& out, const OpCube<T1,op_acos>& in); | |
| }; | | }; | |
| | | | |
| class op_cosh | | class op_cosh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_cosh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_cosh>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_cosh>& in); | |
| }; | | }; | |
| | | | |
| class op_acosh | | class op_acosh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_acosh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| template<typename T, typename T1> inline static void apply(Mat< std::comp | | e>& out, const Op<T1,op_acosh>& in); | |
| lex<T> >& out, const Op<T1,op_acosh>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_acosh>& in); | |
| | | | |
| | | template<typename T, typename T1> inline static void apply( Mat< std::com | |
| | | plex<T> >& out, const Op<T1,op_acosh>& in); | |
| | | template<typename T, typename T1> inline static void apply(Cube< std::com | |
| | | plex<T> >& out, const OpCube<T1,op_acosh>& in); | |
| }; | | }; | |
| | | | |
| // sin family | | // sin family | |
| | | | |
| class op_sin | | class op_sin | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_sin>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_sin>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_sin>& in); | |
| }; | | }; | |
| | | | |
| class op_asin | | class op_asin | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_asin>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| template<typename T, typename T1> inline static void apply(Mat< std::comp | | e>& out, const Op<T1,op_asin>& in); | |
| lex<T> >& out, const Op<T1,op_asin>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_asin>& in); | |
| | | | |
| | | template<typename T, typename T1> inline static void apply( Mat< std::com | |
| | | plex<T> >& out, const Op<T1,op_asin>& in); | |
| | | template<typename T, typename T1> inline static void apply(Cube< std::com | |
| | | plex<T> >& out, const OpCube<T1,op_asin>& in); | |
| }; | | }; | |
| | | | |
| class op_sinh | | class op_sinh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_sinh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_sinh>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_sinh>& in); | |
| }; | | }; | |
| | | | |
| class op_asinh | | class op_asinh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_asinh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_asinh>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_asinh>& in); | |
| }; | | }; | |
| | | | |
| // tan family | | // tan family | |
| | | | |
| class op_tan | | class op_tan | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_tan>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_tan>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_tan>& in); | |
| }; | | }; | |
| | | | |
| class op_atan | | class op_atan | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_atan>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| template<typename T, typename T1> inline static void apply(Mat< std::comp | | e>& out, const Op<T1,op_atan>& in); | |
| lex<T> >& out, const Op<T1,op_atan>& in); | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_atan>& in); | |
| | | | |
| | | template<typename T, typename T1> inline static void apply( Mat< std::com | |
| | | plex<T> >& out, const Op<T1,op_atan>& in); | |
| | | template<typename T, typename T1> inline static void apply(Cube< std::com | |
| | | plex<T> >& out, const OpCube<T1,op_atan>& in); | |
| }; | | }; | |
| | | | |
| class op_tanh | | class op_tanh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_tanh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_tanh>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_tanh>& in); | |
| }; | | }; | |
| | | | |
| class op_atanh | | class op_atanh | |
| { | | { | |
| public: | | public: | |
|
| template<typename T1> inline static void apply(Mat<typename T1::elem_type | | | |
| >& out, const Op<T1,op_atanh>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ | |
| | | e>& out, const Op<T1,op_atanh>& in); | |
| | | template<typename T1> inline static void apply(Cube<typename T1::elem_typ | |
| | | e>& out, const OpCube<T1,op_atanh>& in); | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 12 change blocks. |
| 32 lines changed or deleted | | 80 lines changed or added | |
|