| Col_meat.hpp | | Col_meat.hpp | |
| | | | |
| skipping to change at line 55 | | skipping to change at line 55 | |
| | | | |
| //! construct a column vector from specified text | | //! construct a column vector from specified text | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const char* text) | | Col<eT>::Col(const char* text) | |
| : Mat<eT>(text) | | : Mat<eT>(text) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | | std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| //! construct a column vector from specified text | | //! construct a column vector from specified text | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const char* text) | | Col<eT>::operator=(const char* text) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(text); | | Mat<eT>::operator=(text); | |
|
| | | | |
| | | std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! construct a column vector from specified text | |
| | | template<typename eT> | |
| | | inline | |
| | | Col<eT>::Col(const std::string& text) | |
| | | : Mat<eT>(text) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | |
| | | ); | |
| | | } | |
| | | | |
| | | //! construct a column vector from specified text | |
| | | template<typename eT> | |
| | | inline | |
| | | const Col<eT>& | |
| | | Col<eT>::operator=(const std::string& text) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator=(text); | |
| | | | |
| std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | | std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a column vector from a given column vector | | //! construct a column vector from a given column vector | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const Col<eT>& X) | | Col<eT>::Col(const Col<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| | | | |
| skipping to change at line 91 | | skipping to change at line 124 | |
| | | | |
| //! construct a column vector from a given column vector | | //! construct a column vector from a given column vector | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const Col<eT>& X) | | Col<eT>::operator=(const Col<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a column vector from a given matrix; the matrix must have exa
ctly one column | | //! construct a column vector from a given matrix; the matrix must have exa
ctly one column | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const Mat<eT>& X) | | Col<eT>::Col(const Mat<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 114 | | skipping to change at line 148 | |
| | | | |
| //! construct a column vector from a given matrix; the matrix must have exa
ctly one column | | //! construct a column vector from a given matrix; the matrix must have exa
ctly one column | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const Mat<eT>& X) | | Col<eT>::operator=(const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator*=(const Mat<eT>& X) | | Col<eT>::operator*=(const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a column vector from a given auxiliary array of eTs | | //! construct a column vector from a given auxiliary array of eTs | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const
bool copy_aux_mem) | | Col<eT>::Col(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const
bool copy_aux_mem) | |
| : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols, copy_aux_mem) | | : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols, copy_aux_mem) | |
| | | | |
| skipping to change at line 219 | | skipping to change at line 255 | |
| | | | |
| //! construct a column vector from given a submatrix; the submatrix must ha
ve exactly one column | | //! construct a column vector from given a submatrix; the submatrix must ha
ve exactly one column | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const subview<eT>& X) | | Col<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator*=(const subview<eT>& X) | | Col<eT>::operator*=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | //! construct a column vector from given a subcube; the subcube must have e | |
| | | xactly one column | |
| | | template<typename eT> | |
| | | inline | |
| | | Col<eT>::Col(const subview_cube<eT>& X) | |
| | | : Mat<eT>(X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | |
| | | ); | |
| | | } | |
| | | | |
| | | //! construct a column vector from given a subcube; the subcube must have e | |
| | | xactly one column | |
| | | template<typename eT> | |
| | | inline | |
| | | const Col<eT>& | |
| | | Col<eT>::operator=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator=(X); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const Col<eT>& | |
| | | Col<eT>::operator*=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator*=(X); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a column vector from given a diagview | | //! construct a column vector from given a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const diagview<eT>& X) | | Col<eT>::Col(const diagview<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| | | | |
| skipping to change at line 257 | | skipping to change at line 335 | |
| | | | |
| //! construct a column vector from given a diagview | | //! construct a column vector from given a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const diagview<eT>& X) | | Col<eT>::operator=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator*=(const diagview<eT>& X) | | Col<eT>::operator*=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | arma_inline | |
| | | eT& | |
| | | Col<eT>::row(const u32 row_num) | |
| | | { | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "Col::row(): out of bound | |
| | | s" ); | |
| | | | |
| | | return access::rw(Mat<eT>::mem[row_num]); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | eT | |
| | | Col<eT>::row(const u32 row_num) | |
| | | const | |
| | | { | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "Col::row(): out of bound | |
| | | s" ); | |
| | | | |
| | | return Mat<eT>::mem[row_num]; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview_col<eT> | |
| | | Col<eT>::rows(const u32 in_row1, const u32 in_row2) | |
| | | { | |
| | | arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ) | |
| | | , "Col::rows(): indices out of bounds or incorrectly used"); | |
| | | | |
| | | return subview_col<eT>(*this, 0, in_row1, in_row2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview_col<eT> | |
| | | Col<eT>::rows(const u32 in_row1, const u32 in_row2) | |
| | | const | |
| | | { | |
| | | arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ) | |
| | | , "Col::rows(): indices out of bounds or incorrectly used"); | |
| | | | |
| | | return subview_col<eT>(*this, 0, in_row1, in_row2); | |
| | | } | |
| | | | |
| //! construct a column vector from Op, i.e. run the previously delayed oper
ations; the result of the operations must have exactly one column | | //! construct a column vector from Op, i.e. run the previously delayed oper
ations; the result of the operations must have exactly one column | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Col<eT>::Col(const Op<T1, op_type>& X) | | Col<eT>::Col(const Op<T1, op_type>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| skipping to change at line 308 | | skipping to change at line 432 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator*=(const Op<T1, op_type>& X) | | Col<eT>::operator*=(const Op<T1, op_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible
dimensions" ); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible
dimensions" ); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a column vector from Glue, i.e. run the previously delayed op
erations; the result of the operations must have exactly one column | | //! construct a column vector from Glue, i.e. run the previously delayed op
erations; the result of the operations must have exactly one column | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Col<eT>::Col(const Glue<T1, T2, glue_type>& X) | | Col<eT>::Col(const Glue<T1, T2, glue_type>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| | | | |
| skipping to change at line 334 | | skipping to change at line 460 | |
| //! construct a column vector from Glue, i.e. run the previously delayed op
erations; the result of the operations must have exactly one column | | //! construct a column vector from Glue, i.e. run the previously delayed op
erations; the result of the operations must have exactly one column | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator=(const Glue<T1, T2, glue_type>& X) | | Col<eT>::operator=(const Glue<T1, T2, glue_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
| Col<eT>::operator*=(const Glue<T1, T2, glue_type>& X) | | Col<eT>::operator*=(const Glue<T1, T2, glue_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| //! change the number of n_rows | | //! change the number of rows | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::set_size(const u32 in_n_elem) | | Col<eT>::set_size(const u32 in_n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::set_size(in_n_elem,1); | | Mat<eT>::set_size(in_n_elem,1); | |
| } | | } | |
| | | | |
|
| //! change the number of n_rows (this function re-implements mat::set_size
() in order to check the number of columns) | | //! change the number of rows (this function re-implements mat::set_size()
in order to check the number of columns) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | | Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min() is used in case in_n_cols is zero | |
| Mat<eT>::set_size( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | | Mat<eT>::set_size( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | |
|
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensi
ons" ); | | arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensi
ons" ); | |
| } | | } | |
| | | | |
|
| //! change the number of n_rows (this function re-implements mat::copy_siz
e() in order to check the number of columns) | | //! change the number of rows (this function re-implements mat::copy_size(
) in order to check the number of columns) | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| Col<eT>::copy_size(const Mat<eT>& x) | | Col<eT>::copy_size(const Mat<eT2>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min() is used in case x.n_cols is zero | |
| Mat<eT>::set_size( x.n_rows, (std::min)( u32(1), x.n_cols ) ); | | Mat<eT>::set_size( x.n_rows, (std::min)( u32(1), x.n_cols ) ); | |
|
| | | | |
| arma_debug_check( (x.n_cols > 1), "Col::copy_size(): incompatible dimensi
ons" ); | | arma_debug_check( (x.n_cols > 1), "Col::copy_size(): incompatible dimensi
ons" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::zeros() | | Col<eT>::zeros() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 415 | | skipping to change at line 548 | |
| Mat<eT>::zeros(in_n_elem, 1); | | Mat<eT>::zeros(in_n_elem, 1); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | | Col<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min() is used in case in_n_cols is zero | |
| Mat<eT>::zeros( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | | Mat<eT>::zeros( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | |
|
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::zeros(): incompatible dimensions
" ); | | arma_debug_check( (in_n_cols > 1), "Col::zeros(): incompatible dimensions
" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::ones() | | Col<eT>::ones() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 446 | | skipping to change at line 581 | |
| Mat<eT>::ones(in_n_elem, 1); | | Mat<eT>::ones(in_n_elem, 1); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | | Col<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min() is used in case in_n_cols is zero | |
| Mat<eT>::ones( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | | Mat<eT>::ones( in_n_rows, (std::min)( u32(1), in_n_cols ) ); | |
|
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::ones(): incompatible dimensions"
); | | arma_debug_check( (in_n_cols > 1), "Col::ones(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Col<eT>::load(const std::string name, const file_type type) | | Col<eT>::load(const std::string name, const file_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::load(name,type); | | Mat<eT>::load(name,type); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 31 change blocks. |
| 4 lines changed or deleted | | 153 lines changed or added | |
|
| Col_proto.hpp | | Col_proto.hpp | |
| | | | |
| skipping to change at line 32 | | skipping to change at line 32 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::pod_type pod_type; | | typedef typename get_pod_type<elem_type>::pod_type pod_type; | |
| | | | |
| inline Col(); | | inline Col(); | |
| inline explicit Col(const u32 n_elem); | | inline explicit Col(const u32 n_elem); | |
| inline Col(const u32 in_rows, const u32 in_cols); | | inline Col(const u32 in_rows, const u32 in_cols); | |
| | | | |
|
| inline Col(const char* text); | | inline Col(const char* text); | |
| inline const Col& operator=(const char* text); // TODO: std::string i | | inline const Col& operator=(const char* text); | |
| nput | | inline Col(const std::string& text); | |
| | | inline const Col& operator=(const std::string& text); | |
| | | | |
| inline Col(const Col& X); | | inline Col(const Col& X); | |
| inline const Col& operator=(const Col& X); | | inline const Col& operator=(const Col& X); | |
| | | | |
| //inline explicit Col(const Mat<eT>& X); | | //inline explicit Col(const Mat<eT>& X); | |
| inline Col(const Mat<eT>& X); | | inline Col(const Mat<eT>& X); | |
| inline const Col& operator=(const Mat<eT>& X); | | inline const Col& operator=(const Mat<eT>& X); | |
| inline const Col& operator*=(const Mat<eT>& X); | | inline const Col& operator*=(const Mat<eT>& X); | |
| | | | |
| inline Col( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols,
const bool copy_aux_mem = true); | | inline Col( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols,
const bool copy_aux_mem = true); | |
| | | | |
| skipping to change at line 56 | | skipping to change at line 58 | |
| inline Col( eT* aux_mem, const u32 aux_length, const bool copy_aux_m
em = true); | | inline Col( eT* aux_mem, const u32 aux_length, const bool copy_aux_m
em = true); | |
| inline Col(const eT* aux_mem, const u32 aux_length); | | inline Col(const eT* aux_mem, const u32 aux_length); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline explicit Col(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | | inline explicit Col(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | |
| | | | |
| inline Col(const subview<eT>& X); | | inline Col(const subview<eT>& X); | |
| inline const Col& operator=(const subview<eT>& X); | | inline const Col& operator=(const subview<eT>& X); | |
| inline const Col& operator*=(const subview<eT>& X); | | inline const Col& operator*=(const subview<eT>& X); | |
| | | | |
|
| // TODO: handling of subview_cube | | inline Col(const subview_cube<eT>& X); | |
| | | inline const Col& operator=(const subview_cube<eT>& X); | |
| | | inline const Col& operator*=(const subview_cube<eT>& X); | |
| | | | |
| inline Col(const diagview<eT>& X); | | inline Col(const diagview<eT>& X); | |
| inline const Col& operator=(const diagview<eT>& X); | | inline const Col& operator=(const diagview<eT>& X); | |
| inline const Col& operator*=(const diagview<eT>& X); | | inline const Col& operator*=(const diagview<eT>& X); | |
| | | | |
|
| | | arma_inline eT& row(const u32 row_num); | |
| | | arma_inline eT row(const u32 row_num) const; | |
| | | | |
| | | arma_inline subview_col<eT> rows(const u32 in_row1, const u32 in_ro | |
| | | w2); | |
| | | arma_inline const subview_col<eT> rows(const u32 in_row1, const u32 in_ro | |
| | | w2) const; | |
| | | | |
| template<typename T1, typename op_type> inline Col(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline Col(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Col& operator=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Col& operator=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Col& operator*=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Col& operator*=(cons
t Op<T1, op_type>& X); | |
| | | | |
| template<typename T1, typename T2, typename glue_type> inline
Col(const Glue<T1, T2, glue_type>& X); | | template<typename T1, typename T2, typename glue_type> inline
Col(const Glue<T1, T2, glue_type>& X); | |
| template<typename T1, typename T2, typename glue_type> inline const Col&
operator=(const Glue<T1, T2, glue_type>& X); | | template<typename T1, typename T2, typename glue_type> inline const Col&
operator=(const Glue<T1, T2, glue_type>& X); | |
| template<typename T1, typename T2, typename glue_type> inline const Col&
operator*=(const Glue<T1, T2, glue_type>& X); | | template<typename T1, typename T2, typename glue_type> inline const Col&
operator*=(const Glue<T1, T2, glue_type>& X); | |
| | | | |
| inline void set_size(const u32 n_elem); | | inline void set_size(const u32 n_elem); | |
| inline void set_size(const u32 n_rows, const u32 n_cols); | | inline void set_size(const u32 n_rows, const u32 n_cols); | |
|
| inline void copy_size(const Mat<eT>& x); | | | |
| | | template<typename eT2> | |
| | | inline void copy_size(const Mat<eT2>& m); | |
| | | | |
| inline void zeros(); | | inline void zeros(); | |
| inline void zeros(const u32 n_elem); | | inline void zeros(const u32 n_elem); | |
| inline void zeros(const u32 n_rows, const u32 n_cols); | | inline void zeros(const u32 n_rows, const u32 n_cols); | |
| | | | |
| inline void ones(); | | inline void ones(); | |
| inline void ones(const u32 n_elem); | | inline void ones(const u32 n_elem); | |
| inline void ones(const u32 n_rows, const u32 n_cols); | | inline void ones(const u32 n_rows, const u32 n_cols); | |
| | | | |
| 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); | |
| | | | |
End of changes. 4 change blocks. |
| 5 lines changed or deleted | | 18 lines changed or added | |
|
| Row_meat.hpp | | Row_meat.hpp | |
| | | | |
| skipping to change at line 62 | | skipping to change at line 62 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const char* text) | | Row<eT>::operator=(const char* text) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(text); | | Mat<eT>::operator=(text); | |
|
| | | | |
| | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Row<eT>::Row(const std::string& text) | |
| | | : Mat<eT>(text) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | |
| | | ); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const Row<eT>& | |
| | | Row<eT>::operator=(const std::string& text) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator=(text); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const Row<eT>& X) | | Row<eT>::Row(const Row<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| skipping to change at line 86 | | skipping to change at line 112 | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const Row<eT>& X) | | Row<eT>::operator=(const Row<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| inline Row<eT>::Row(const Mat<eT>& X) | | inline | |
| | | Row<eT>::Row(const Mat<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| | | | |
| skipping to change at line 201 | | skipping to change at line 228 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const subview<eT>& X) | | Row<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator*=(const subview<eT>& X) | | Row<eT>::operator*=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Row<eT>::Row(const subview_cube<eT>& X) | |
| | | : Mat<eT>(X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | |
| | | ); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const Row<eT>& | |
| | | Row<eT>::operator=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator=(X); | |
| | | | |
| | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | |
| | | ); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const Row<eT>& | |
| | | Row<eT>::operator*=(const subview_cube<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat<eT>::operator*=(X); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a row vector from given a diagview | | //! construct a row vector from given a diagview | |
| template<typename eT> | | template<typename eT> | |
|
| inline Row<eT>::Row(const diagview<eT>& X) | | inline | |
| | | Row<eT>::Row(const diagview<eT>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | | std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) ); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| //! construct a row vector from given a diagview | | //! construct a row vector from given a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const diagview<eT>& X) | | Row<eT>::operator=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 259 | | skipping to change at line 330 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | eT& | |
| | | Row<eT>::col(const u32 col_num) | |
| | | { | |
| | | arma_debug_check( (col_num >= Mat<eT>::n_cols), "Row::col(): out of bound | |
| | | s" ); | |
| | | | |
| | | return access::rw(Mat<eT>::mem[col_num]); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | eT | |
| | | Row<eT>::col(const u32 col_num) | |
| | | const | |
| | | { | |
| | | arma_debug_check( (col_num >= Mat<eT>::n_cols), "Row::col(): out of bound | |
| | | s" ); | |
| | | | |
| | | return Mat<eT>::mem[col_num]; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview_row<eT> | |
| | | Row<eT>::cols(const u32 in_col1, const u32 in_col2) | |
| | | { | |
| | | arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ) | |
| | | , "Row::cols(): indices out of bounds or incorrectly used"); | |
| | | | |
| | | return subview_row<eT>(*this, 0, in_col1, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview_row<eT> | |
| | | Row<eT>::cols(const u32 in_col1, const u32 in_col2) | |
| | | const | |
| | | { | |
| | | arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ) | |
| | | , "Row::cols(): indices out of bounds or incorrectly used"); | |
| | | | |
| | | return subview_row<eT>(*this, 0, in_col1, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Row<eT>::Row(const Op<T1, op_type>& X) | | Row<eT>::Row(const Op<T1, op_type>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const Op<T1, op_type>& X) | | Row<eT>::operator=(const Op<T1, op_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator*=(const Op<T1, op_type>& X) | | Row<eT>::operator*=(const Op<T1, op_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Row<eT>::Row(const Glue<T1, T2, glue_type>& X) | | Row<eT>::Row(const Glue<T1, T2, glue_type>& X) | |
| : Mat<eT>(X) | | : Mat<eT>(X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 315 | | skipping to change at line 432 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const Glue<T1, T2, glue_type>& X) | | Row<eT>::operator=(const Glue<T1, T2, glue_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator*=(const Glue<T1, T2, glue_type>& X) | | Row<eT>::operator*=(const Glue<T1, T2, glue_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator*=(X); | | Mat<eT>::operator*=(X); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::set_size(const u32 in_n_elem) | | Row<eT>::set_size(const u32 in_n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::set_size(1,in_n_elem); | | Mat<eT>::set_size(1,in_n_elem); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | | Row<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min is used in case in_n_rows is zero | |
| Mat<eT>::set_size( (std::min)( u32(1), in_n_rows), in_n_cols ); | | Mat<eT>::set_size( (std::min)( u32(1), in_n_rows), in_n_cols ); | |
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row::set_size(): incompatible dimensi
ons" ); | | arma_debug_check( (in_n_rows > 1), "Row::set_size(): incompatible dimensi
ons" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| Row<eT>::copy_size(const Mat<eT>& x) | | Row<eT>::copy_size(const Mat<eT2>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min is used in case x.n_rows is zero | |
| Mat<eT>::set_size( (std::min)( u32(1), x.n_rows), x.n_cols ); | | Mat<eT>::set_size( (std::min)( u32(1), x.n_rows), x.n_cols ); | |
| | | | |
| arma_debug_check( (x.n_rows > 1), "Row::copy_size(): incompatible dimensi
ons" ); | | arma_debug_check( (x.n_rows > 1), "Row::copy_size(): incompatible dimensi
ons" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::zeros() | | Row<eT>::zeros() | |
| { | | { | |
| | | | |
| skipping to change at line 393 | | skipping to change at line 517 | |
| Mat<eT>::zeros(1, in_n_elem); | | Mat<eT>::zeros(1, in_n_elem); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | | Row<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min is used in case in_n_rows is zero | |
| Mat<eT>::zeros( (std::min)( u32(1), in_n_rows), in_n_cols ); | | Mat<eT>::zeros( (std::min)( u32(1), in_n_rows), in_n_cols ); | |
|
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row<eT>::zeros(): incompatible dimens
ions" ); | | arma_debug_check( (in_n_rows > 1), "Row<eT>::zeros(): incompatible dimens
ions" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::ones() | | Row<eT>::ones() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 424 | | skipping to change at line 550 | |
| Mat<eT>::ones(1, in_n_elem); | | Mat<eT>::ones(1, in_n_elem); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | | Row<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | // min is used in case in_n_rows is zero | |
| Mat<eT>::ones( (std::min)( u32(1), in_n_rows), in_n_cols ); | | Mat<eT>::ones( (std::min)( u32(1), in_n_rows), in_n_cols ); | |
|
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row<eT>::ones(): incompatible dimensi
ons" ); | | arma_debug_check( (in_n_rows > 1), "Row<eT>::ones(): incompatible dimensi
ons" ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Row<eT>::load(const std::string name, const file_type type) | | Row<eT>::load(const std::string name, const file_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::load(name,type); | | Mat<eT>::load(name,type); | |
|
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 27 change blocks. |
| 3 lines changed or deleted | | 141 lines changed or added | |
|
| Row_proto.hpp | | Row_proto.hpp | |
| | | | |
| skipping to change at line 32 | | skipping to change at line 32 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::pod_type pod_type; | | typedef typename get_pod_type<elem_type>::pod_type pod_type; | |
| | | | |
| inline Row(); | | inline Row(); | |
| inline explicit Row(const u32 N); | | inline explicit Row(const u32 N); | |
| inline Row(const u32 in_rows, const u32 in_cols); | | inline Row(const u32 in_rows, const u32 in_cols); | |
| | | | |
|
| inline Row(const char* text); | | inline Row(const char* text); | |
| inline const Row& operator=(const char* text); // TODO: std::string i | | inline const Row& operator=(const char* text); | |
| nput | | inline Row(const std::string& text); | |
| | | inline const Row& operator=(const std::string& text); | |
| | | | |
| inline Row(const Row& X); | | inline Row(const Row& X); | |
| inline const Row& operator=(const Row& X); | | inline const Row& operator=(const Row& X); | |
| inline const Row& operator*=(const Row& X); | | inline const Row& operator*=(const Row& X); | |
| | | | |
| //inline explicit Row(const Mat<eT>& X); | | //inline explicit Row(const Mat<eT>& X); | |
| inline Row(const Mat<eT>& X); | | inline Row(const Mat<eT>& X); | |
| inline const Row& operator=(const Mat<eT>& X); | | inline const Row& operator=(const Mat<eT>& X); | |
| inline const Row& operator*=(const Mat<eT>& X); | | inline const Row& operator*=(const Mat<eT>& X); | |
| | | | |
| | | | |
| skipping to change at line 57 | | skipping to change at line 59 | |
| inline Row( eT* aux_mem, const u32 aux_length, const bool copy_aux_m
em = true); | | inline Row( eT* aux_mem, const u32 aux_length, const bool copy_aux_m
em = true); | |
| inline Row(const eT* aux_mem, const u32 aux_length); | | inline Row(const eT* aux_mem, const u32 aux_length); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | | inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>&
B); | |
| | | | |
| inline Row(const subview<eT>& X); | | inline Row(const subview<eT>& X); | |
| inline const Row& operator=(const subview<eT>& X); | | inline const Row& operator=(const subview<eT>& X); | |
| inline const Row& operator*=(const subview<eT>& X); | | inline const Row& operator*=(const subview<eT>& X); | |
| | | | |
|
| // TODO: handling of subview_cube | | inline Row(const subview_cube<eT>& X); | |
| | | inline const Row& operator=(const subview_cube<eT>& X); | |
| | | inline const Row& operator*=(const subview_cube<eT>& X); | |
| | | | |
| inline explicit Row(const diagview<eT>& X); | | inline explicit Row(const diagview<eT>& X); | |
| inline const Row& operator=(const diagview<eT>& X); | | inline const Row& operator=(const diagview<eT>& X); | |
| inline const Row& operator*=(const diagview<eT>& X); | | inline const Row& operator*=(const diagview<eT>& X); | |
| | | | |
|
| | | arma_inline eT& col(const u32 col_num); | |
| | | arma_inline eT col(const u32 col_num) const; | |
| | | | |
| | | arma_inline subview_row<eT> cols(const u32 in_col1, const u32 in_co | |
| | | l2); | |
| | | arma_inline const subview_row<eT> cols(const u32 in_col1, const u32 in_co | |
| | | l2) const; | |
| | | | |
| template<typename T1, typename op_type> inline Row(cons
t Op<T1, op_type> &X); | | template<typename T1, typename op_type> inline Row(cons
t Op<T1, op_type> &X); | |
| template<typename T1, typename op_type> inline const Row& operator=(cons
t Op<T1, op_type> &X); | | template<typename T1, typename op_type> inline const Row& operator=(cons
t Op<T1, op_type> &X); | |
| template<typename T1, typename op_type> inline const Row& operator*=(cons
t Op<T1, op_type> &X); | | template<typename T1, typename op_type> inline const Row& operator*=(cons
t Op<T1, op_type> &X); | |
| | | | |
| template<typename T1, typename T2, typename glue_type> inline
Row(const Glue<T1, T2, glue_type> &X); | | template<typename T1, typename T2, typename glue_type> inline
Row(const Glue<T1, T2, glue_type> &X); | |
| template<typename T1, typename T2, typename glue_type> inline const Row&
operator=(const Glue<T1, T2, glue_type> &X); | | template<typename T1, typename T2, typename glue_type> inline const Row&
operator=(const Glue<T1, T2, glue_type> &X); | |
| template<typename T1, typename T2, typename glue_type> inline const Row&
operator*=(const Glue<T1, T2, glue_type> &X); | | template<typename T1, typename T2, typename glue_type> inline const Row&
operator*=(const Glue<T1, T2, glue_type> &X); | |
| | | | |
| inline void set_size(const u32 N); | | inline void set_size(const u32 N); | |
| inline void set_size(const u32 n_rows, const u32 n_cols); | | inline void set_size(const u32 n_rows, const u32 n_cols); | |
|
| inline void copy_size(const Mat<eT>& x); | | | |
| | | template<typename eT2> | |
| | | inline void copy_size(const Mat<eT2>& m); | |
| | | | |
| inline void zeros(); | | inline void zeros(); | |
| inline void zeros(const u32 N); | | inline void zeros(const u32 N); | |
| inline void zeros(const u32 n_rows, const u32 n_cols); | | inline void zeros(const u32 n_rows, const u32 n_cols); | |
| | | | |
| inline void ones(); | | inline void ones(); | |
| inline void ones(const u32 N); | | inline void ones(const u32 N); | |
| inline void ones(const u32 n_rows, const u32 n_cols); | | inline void ones(const u32 n_rows, const u32 n_cols); | |
| | | | |
| 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); | |
| | | | |
End of changes. 4 change blocks. |
| 5 lines changed or deleted | | 18 lines changed or added | |
|
| armadillo | | armadillo | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| #ifndef ARMA_INCLUDES | | #ifndef ARMA_INCLUDES | |
| #define ARMA_INCLUDES | | #define ARMA_INCLUDES | |
| | | | |
| #define arma_hot | | #define arma_hot | |
| #define arma_pure | | #define arma_pure | |
| #define arma_const | | #define arma_const | |
| #define arma_inline inline | | #define arma_inline inline | |
| #define arma_aligned | | #define arma_aligned | |
| | | | |
| #if defined(__GNUG__) | | #if defined(__GNUG__) | |
|
| #if(__GNUC__ < 4) | | | |
| | | #if (__GNUC__ < 4) | |
| #error "*** Need a newer compiler ***" | | #error "*** Need a newer compiler ***" | |
| #endif | | #endif | |
|
| #if(__GNUC_MINOR__ >= 3) | | | |
| | | #if (__GNUC_MINOR__ >= 3) | |
| #undef arma_hot | | #undef arma_hot | |
| #define arma_hot __attribute__((hot)) | | #define arma_hot __attribute__((hot)) | |
| #endif | | #endif | |
| | | | |
| #undef arma_pure | | #undef arma_pure | |
| #undef arma_const | | #undef arma_const | |
| #undef arma_inline | | #undef arma_inline | |
| #undef arma_aligned | | #undef arma_aligned | |
| | | | |
| #define arma_pure __attribute__((pure)) | | #define arma_pure __attribute__((pure)) | |
| #define arma_const __attribute__((const)) | | #define arma_const __attribute__((const)) | |
| #define arma_inline inline __attribute__((always_inline)) | | #define arma_inline inline __attribute__((always_inline)) | |
| #define arma_aligned __attribute__((aligned)) | | #define arma_aligned __attribute__((aligned)) | |
|
| | | | |
| | | #define ARMA_GOOD_COMPILER | |
| | | | |
| #elif defined(__INTEL_COMPILER) | | #elif defined(__INTEL_COMPILER) | |
|
| #if(__INTEL_COMPILER < 1000) | | | |
| | | #if (__INTEL_COMPILER < 1000) | |
| #error "*** Need a newer compiler ***" | | #error "*** Need a newer compiler ***" | |
| #endif | | #endif | |
|
| | | | |
| | | #define ARMA_GOOD_COMPILER | |
| | | | |
| #elif defined(_MSC_VER) | | #elif defined(_MSC_VER) | |
|
| #if(_MSC_VER <= 1500) | | | |
| #error "*** This compiler is not supported due to its incomplete implem | | #pragma message ("*** WARNING: This compiler may have an incomplete imple | |
| entation of the C++ standard -- please try the gcc, mingw-gcc or intel comp | | mentation of the C++ standard ***") | |
| ilers instead ***" | | #undef ARMA_GOOD_COMPILER | |
| #else | | | |
| #pragma message ("*** WARNING: This compiler may have an incomplete imp | | | |
| lementation of the C++ standard ***") | | | |
| #endif | | | |
| #endif | | #endif | |
| | | | |
| #include "armadillo_bits/config.hpp" | | #include "armadillo_bits/config.hpp" | |
| | | | |
| #include <cstdlib> | | #include <cstdlib> | |
| #include <cstring> | | #include <cstring> | |
| #include <climits> | | #include <climits> | |
| #include <cmath> | | #include <cmath> | |
| | | | |
| #include <iostream> | | #include <iostream> | |
| | | | |
| skipping to change at line 149 | | skipping to change at line 157 | |
| | | | |
| #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/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/running_stat_vec_proto.hpp" | |
| | | | |
| #include "armadillo_bits/Op_proto.hpp" | | #include "armadillo_bits/Op_proto.hpp" | |
| #include "armadillo_bits/OpCube_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/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" | |
| | | | |
| skipping to change at line 180 | | skipping to change at line 189 | |
| #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/op_repmat_proto.hpp" | |
| #include "armadillo_bits/op_reshape_proto.hpp" | | #include "armadillo_bits/op_reshape_proto.hpp" | |
| #include "armadillo_bits/op_cov_proto.hpp" | | #include "armadillo_bits/op_cov_proto.hpp" | |
| #include "armadillo_bits/op_cor_proto.hpp" | | #include "armadillo_bits/op_cor_proto.hpp" | |
|
| | | #include "armadillo_bits/op_shuffle_proto.hpp" | |
| | | #include "armadillo_bits/op_prod_proto.hpp" | |
| | | #include "armadillo_bits/op_eps_proto.hpp" | |
| | | #include "armadillo_bits/op_pinv_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_cov_proto.hpp" | | #include "armadillo_bits/glue_cov_proto.hpp" | |
| #include "armadillo_bits/glue_cor_proto.hpp" | | #include "armadillo_bits/glue_cor_proto.hpp" | |
|
| | | #include "armadillo_bits/glue_kron_proto.hpp" | |
| | | | |
| #include "armadillo_bits/glue_cube_plus_proto.hpp" | | #include "armadillo_bits/glue_cube_plus_proto.hpp" | |
| #include "armadillo_bits/glue_cube_minus_proto.hpp" | | #include "armadillo_bits/glue_cube_minus_proto.hpp" | |
| #include "armadillo_bits/glue_cube_schur_proto.hpp" | | #include "armadillo_bits/glue_cube_schur_proto.hpp" | |
| #include "armadillo_bits/glue_cube_div_proto.hpp" | | #include "armadillo_bits/glue_cube_div_proto.hpp" | |
| | | | |
| // | | // | |
| // debugging functions | | // debugging functions | |
| | | | |
| #include "armadillo_bits/debug.hpp" | | #include "armadillo_bits/debug.hpp" | |
| | | | |
| skipping to change at line 243 | | skipping to change at line 257 | |
| #include "armadillo_bits/operator_cube_times.hpp" | | #include "armadillo_bits/operator_cube_times.hpp" | |
| #include "armadillo_bits/operator_cube_schur.hpp" | | #include "armadillo_bits/operator_cube_schur.hpp" | |
| #include "armadillo_bits/operator_cube_div.hpp" | | #include "armadillo_bits/operator_cube_div.hpp" | |
| #include "armadillo_bits/operator_cube_relational.hpp" | | #include "armadillo_bits/operator_cube_relational.hpp" | |
| | | | |
| #include "armadillo_bits/operator_ostream.hpp" | | #include "armadillo_bits/operator_ostream.hpp" | |
| | | | |
| // | | // | |
| // user accessible functions | | // user accessible functions | |
| | | | |
|
| | | // the order of the fn_*.hpp include files matters, | |
| | | // as some files require functionality given in preceding files | |
| | | | |
| #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" | |
| #include "armadillo_bits/fn_inv.hpp" | | #include "armadillo_bits/fn_inv.hpp" | |
| #include "armadillo_bits/fn_trace.hpp" | | #include "armadillo_bits/fn_trace.hpp" | |
| #include "armadillo_bits/fn_trans.hpp" | | #include "armadillo_bits/fn_trans.hpp" | |
| #include "armadillo_bits/fn_det.hpp" | | #include "armadillo_bits/fn_det.hpp" | |
| | | | |
| skipping to change at line 278 | | skipping to change at line 295 | |
| #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" | | #include "armadillo_bits/fn_repmat.hpp" | |
| #include "armadillo_bits/fn_reshape.hpp" | | #include "armadillo_bits/fn_reshape.hpp" | |
| #include "armadillo_bits/fn_cov.hpp" | | #include "armadillo_bits/fn_cov.hpp" | |
| #include "armadillo_bits/fn_cor.hpp" | | #include "armadillo_bits/fn_cor.hpp" | |
|
| | | #include "armadillo_bits/fn_shuffle.hpp" | |
| | | #include "armadillo_bits/fn_prod.hpp" | |
| | | #include "armadillo_bits/fn_eps.hpp" | |
| | | #include "armadillo_bits/fn_pinv.hpp" | |
| | | #include "armadillo_bits/fn_rank.hpp" | |
| | | #include "armadillo_bits/fn_kron.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" | |
| | | | |
| skipping to change at line 302 | | skipping to change at line 325 | |
| #include "armadillo_bits/Cube_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/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/running_stat_vec_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" | |
| #include "armadillo_bits/op_misc_meat.hpp" | | #include "armadillo_bits/op_misc_meat.hpp" | |
| #include "armadillo_bits/op_max_meat.hpp" | | #include "armadillo_bits/op_max_meat.hpp" | |
| #include "armadillo_bits/op_min_meat.hpp" | | #include "armadillo_bits/op_min_meat.hpp" | |
| #include "armadillo_bits/op_mean_meat.hpp" | | #include "armadillo_bits/op_mean_meat.hpp" | |
| #include "armadillo_bits/op_median_meat.hpp" | | #include "armadillo_bits/op_median_meat.hpp" | |
| | | | |
| skipping to change at line 328 | | skipping to change at line 352 | |
| #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/op_repmat_meat.hpp" | |
| #include "armadillo_bits/op_reshape_meat.hpp" | | #include "armadillo_bits/op_reshape_meat.hpp" | |
| #include "armadillo_bits/op_cov_meat.hpp" | | #include "armadillo_bits/op_cov_meat.hpp" | |
| #include "armadillo_bits/op_cor_meat.hpp" | | #include "armadillo_bits/op_cor_meat.hpp" | |
|
| | | #include "armadillo_bits/op_shuffle_meat.hpp" | |
| | | #include "armadillo_bits/op_prod_meat.hpp" | |
| | | #include "armadillo_bits/op_eps_meat.hpp" | |
| | | #include "armadillo_bits/op_pinv_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/glue_cov_meat.hpp" | | #include "armadillo_bits/glue_cov_meat.hpp" | |
| #include "armadillo_bits/glue_cor_meat.hpp" | | #include "armadillo_bits/glue_cor_meat.hpp" | |
|
| | | #include "armadillo_bits/glue_kron_meat.hpp" | |
| | | | |
| #include "armadillo_bits/glue_cube_plus_meat.hpp" | | #include "armadillo_bits/glue_cube_plus_meat.hpp" | |
| #include "armadillo_bits/glue_cube_minus_meat.hpp" | | #include "armadillo_bits/glue_cube_minus_meat.hpp" | |
| #include "armadillo_bits/glue_cube_schur_meat.hpp" | | #include "armadillo_bits/glue_cube_schur_meat.hpp" | |
| #include "armadillo_bits/glue_cube_div_meat.hpp" | | #include "armadillo_bits/glue_cube_div_meat.hpp" | |
| } | | } | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 14 change blocks. |
| 11 lines changed or deleted | | 38 lines changed or added | |
|
| auxlib_meat.hpp | | auxlib_meat.hpp | |
| | | | |
| skipping to change at line 511 | | skipping to change at line 511 | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! immediate LU decomposition of a matrix using ATLAS or LAPACK | | //! immediate LU decomposition of a matrix using ATLAS or LAPACK | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| auxlib::lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X_or
ig) | | auxlib::lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (&L == &U), "auxlib::lu(): L and U are the same object" | | | |
| ); | | | |
| | | | |
| unwrap_check< Mat<eT> > tmp1(X_orig, U); | | | |
| const Mat<eT>& X_tmp = tmp1.M; | | | |
| | | | |
| unwrap_check< Mat<eT> > tmp2(X_tmp, L); | | | |
| const Mat<eT>& X = tmp2.M; | | | |
| | | | |
| U = X; | | U = X; | |
| | | | |
| #if defined(ARMA_USE_ATLAS) || defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_ATLAS) || defined(ARMA_USE_LAPACK) | |
| { | | { | |
| | | | |
| #if defined(ARMA_USE_ATLAS) | | #if defined(ARMA_USE_ATLAS) | |
| { | | { | |
| ipiv.set_size(U.n_rows); | | ipiv.set_size(U.n_rows); | |
| | | | |
| //int info = | | //int info = | |
| | | | |
| skipping to change at line 589 | | skipping to change at line 581 | |
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| auxlib::lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X) | | auxlib::lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( ( (&P == &L) || (&P == &U) ), "auxlib::lu(): P is the s | | | |
| ame object as L or U" ); | | | |
| | | | |
| podarray<int> ipiv; | | podarray<int> ipiv; | |
| auxlib::lu(L, U, ipiv, X); | | auxlib::lu(L, U, ipiv, X); | |
| | | | |
| const u32 n = ipiv.n_elem; | | const u32 n = ipiv.n_elem; | |
| | | | |
| Mat<u32> P_tmp(n,n); | | Mat<u32> P_tmp(n,n); | |
| Mat<u32> ident = eye< Mat<u32> >(n,n); | | Mat<u32> ident = eye< Mat<u32> >(n,n); | |
| | | | |
| for(u32 i=n; i>0; --i) | | for(u32 i=n; i>0; --i) | |
| { | | { | |
| | | | |
| skipping to change at line 973 | | skipping to change at line 963 | |
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::chol(Mat<eT>& out, const Mat<eT>& X) | | auxlib::chol(Mat<eT>& out, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| int n = X.n_rows; | | int n = X.n_rows; | |
| int lda = X.n_rows; | | int lda = X.n_rows; | |
| int info; | | int info; | |
| | | | |
| out = X; | | out = X; | |
| lapack::potrf_(&uplo, &n, out.memptr(), &lda, &info); | | lapack::potrf_(&uplo, &n, out.memptr(), &lda, &info); | |
| | | | |
| | | | |
| skipping to change at line 1011 | | skipping to change at line 999 | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::qr(Mat<eT>& Q, Mat<eT>& R, const Mat<eT>& X) | | auxlib::qr(Mat<eT>& Q, Mat<eT>& R, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| int m = static_cast<int>(X.n_rows); | | int m = static_cast<int>(X.n_rows); | |
| int n = static_cast<int>(X.n_cols); | | int n = static_cast<int>(X.n_cols); | |
| int work_len = (std::max)(1,n); | | int work_len = (std::max)(1,n); | |
| int work_len_tmp; | | int work_len_tmp; | |
| int k = (std::min)(m,n); | | int k = (std::min)(m,n); | |
| int info; | | int info; | |
| | | | |
| podarray<eT> tau(k); | | podarray<eT> tau(k); | |
| | | | |
| skipping to change at line 1039 | | skipping to change at line 1025 | |
| lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo
rk_len_tmp, &info); | | lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo
rk_len_tmp, &info); | |
| | | | |
| if(info == 0) | | if(info == 0) | |
| { | | { | |
| work_len = static_cast<int>(auxlib::tmp_real(work[0])); | | work_len = static_cast<int>(auxlib::tmp_real(work[0])); | |
| work.set_size(work_len); | | work.set_size(work_len); | |
| } | | } | |
| | | | |
| lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo
rk_len, &info); | | lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo
rk_len, &info); | |
| | | | |
|
| Q.set_size(X.n_rows,X.n_rows); | | Q.set_size(X.n_rows, X.n_rows); | |
| | | | |
| eT* Q_mem = Q.memptr(); | | eT* Q_mem = Q.memptr(); | |
| const eT* R_mem = R.mem; | | const eT* R_mem = R.mem; | |
| | | | |
| const u32 n_elem_copy = (std::min)(Q.n_elem, R.n_elem); | | const u32 n_elem_copy = (std::min)(Q.n_elem, R.n_elem); | |
| for(u32 i=0; i < n_elem_copy; ++i) | | for(u32 i=0; i < n_elem_copy; ++i) | |
| { | | { | |
| Q_mem[i] = R_mem[i]; | | Q_mem[i] = R_mem[i]; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1107 | | skipping to change at line 1093 | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::svd(Col<eT>& S, const Mat<eT>& X) | | auxlib::svd(Col<eT>& S, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A = X; | | Mat<eT> A = X; | |
| | | | |
| char jobu = 'N'; | | char jobu = 'N'; | |
| char jobvt = 'N'; | | char jobvt = 'N'; | |
| | | | |
| int m = A.n_rows; | | int m = A.n_rows; | |
| int n = A.n_cols; | | int n = A.n_cols; | |
| int lda = A.n_rows; | | int lda = A.n_rows; | |
| | | | |
| skipping to change at line 1187 | | skipping to change at line 1171 | |
| | | | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::svd(Col<T>& S, const Mat< std::complex<T> >& X) | | auxlib::svd(Col<T>& S, const Mat< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef std::complex<T> eT; | | typedef std::complex<T> eT; | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A = X; | | Mat<eT> A = X; | |
| | | | |
| char jobu = 'N'; | | char jobu = 'N'; | |
| char jobvt = 'N'; | | char jobvt = 'N'; | |
| | | | |
| int m = A.n_rows; | | int m = A.n_rows; | |
| int n = A.n_cols; | | int n = A.n_cols; | |
| int lda = A.n_rows; | | int lda = A.n_rows; | |
| | | | |
| skipping to change at line 1272 | | skipping to change at line 1254 | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::svd(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Mat<eT>& X) | | auxlib::svd(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Mat<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A = X; | | Mat<eT> A = X; | |
| | | | |
| char jobu = 'A'; | | char jobu = 'A'; | |
| char jobvt = 'A'; | | char jobvt = 'A'; | |
| | | | |
| int m = A.n_rows; | | int m = A.n_rows; | |
| int n = A.n_cols; | | int n = A.n_cols; | |
| int lda = A.n_rows; | | int lda = A.n_rows; | |
| | | | |
| skipping to change at line 1353 | | skipping to change at line 1333 | |
| | | | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::svd(Mat< std::complex<T> >& U, Col<T> &S, Mat< std::complex<T> >& V
, const Mat< std::complex<T> >& X) | | auxlib::svd(Mat< std::complex<T> >& U, Col<T> &S, Mat< std::complex<T> >& V
, const Mat< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef std::complex<T> eT; | | typedef std::complex<T> eT; | |
| | | | |
|
| // TODO: check for aliasing | | | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A = X; | | Mat<eT> A = X; | |
| | | | |
| char jobu = 'A'; | | char jobu = 'A'; | |
| char jobvt = 'A'; | | char jobvt = 'A'; | |
| | | | |
| int m = A.n_rows; | | int m = A.n_rows; | |
| int n = A.n_cols; | | int n = A.n_cols; | |
| int lda = A.n_rows; | | int lda = A.n_rows; | |
| | | | |
| skipping to change at line 1413 | | skipping to change at line 1391 | |
| S.memptr(), | | S.memptr(), | |
| U.memptr(), &ldu, | | U.memptr(), &ldu, | |
| V.memptr(), &ldvt, | | V.memptr(), &ldvt, | |
| work.memptr(), &lwork, | | work.memptr(), &lwork, | |
| rwork.memptr(), | | rwork.memptr(), | |
| &info | | &info | |
| ); | | ); | |
| | | | |
| op_htrans::apply(V,V); // op_htrans will work out that an in-place t
ranspose can be done | | op_htrans::apply(V,V); // op_htrans will work out that an in-place t
ranspose can be done | |
| | | | |
|
| | | for(u32 i=0; i<A.n_cols; ++i) | |
| | | { | |
| | | V.at(i,i) = std::conj( V.at(i,i) ); | |
| | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("auxlib::svd(): need LAPACK library"); | | arma_stop("auxlib::svd(): need LAPACK library"); | |
| | | | |
End of changes. 11 change blocks. |
| 26 lines changed or deleted | | 7 lines changed or added | |
|
| fn_accu.hpp | | fn_accu.hpp | |
| | | | |
| skipping to change at line 44 | | skipping to change at line 44 | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| for(u32 i=0; i<A_n_elem; ++i) | | for(u32 i=0; i<A_n_elem; ++i) | |
| { | | { | |
| val += A_mem[i]; | | val += A_mem[i]; | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| //! sum of values along the main diagonal | | //! accumulate the elements of a cube | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| typename T1::elem_type | | typename T1::elem_type | |
|
| accu(const Op<T1, op_diagmat>& X) | | accu(const BaseCube<typename T1::elem_type,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap<T1> tmp(X.m); | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| const Mat<eT>& A = tmp.M; | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| arma_debug_check( !A.is_square(), "accu(): sum of diagonal values of a no | | const u32 A_n_elem = A.n_elem; | |
| n-square matrix requested" ); | | const eT* A_mem = A.mem; | |
| | | | |
|
| eT acc = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 i=0; i<A.n_rows; ++i) | | for(u32 i=0; i<A_n_elem; ++i) | |
| { | | { | |
|
| acc += A.at(i,i); | | val += A_mem[i]; | |
| } | | } | |
| | | | |
|
| return acc; | | return val; | |
| } | | } | |
| | | | |
|
| template<typename eT> | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | //! sum of squares | |
| | | template<typename T1> | |
| inline | | inline | |
|
| eT | | typename T1::elem_type | |
| accu(const Op<Mat<eT>, op_diagmat_vec>& X) | | accu(const Op<T1, op_square>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const Mat<eT>& A = X.m; | | typedef typename T1::elem_type eT; | |
| arma_debug_check( !A.is_vec(), "accu(): internal error: expected a vector | | | |
| " ); | | | |
| | | | |
|
| return accu(A); | | const unwrap<T1> tmp(in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | const u32 A_n_elem = A.n_elem; | |
| | | const eT* A_mem = A.mem; | |
| | | | |
| | | eT acc = eT(0); | |
| | | | |
| | | for(u32 i=0; i<A_n_elem; ++i) | |
| | | { | |
| | | const eT val = A_mem[i]; | |
| | | acc += val*val; | |
| | | } | |
| | | | |
| | | return acc; | |
| } | | } | |
| | | | |
| //! sum of squares | | //! sum of squares | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| typename T1::elem_type | | typename T1::elem_type | |
|
| accu(const Op<T1, op_square>& in) | | accu(const OpCube<T1, op_square>& 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_cube<T1> tmp(in.m); | |
| const Mat<eT>& A = tmp.M; | | const Cube<eT>& A = tmp.M; | |
| | | | |
| const u32 A_n_elem = A.n_elem; | | const u32 A_n_elem = A.n_elem; | |
| const eT* A_mem = A.mem; | | const eT* A_mem = A.mem; | |
| | | | |
| eT acc = eT(0); | | eT acc = eT(0); | |
| | | | |
| for(u32 i=0; i<A_n_elem; ++i) | | for(u32 i=0; i<A_n_elem; ++i) | |
| { | | { | |
| const eT val = A_mem[i]; | | const eT val = A_mem[i]; | |
| acc += val*val; | | acc += val*val; | |
| | | | |
| skipping to change at line 134 | | skipping to change at line 151 | |
| | | | |
| eT acc = eT(0); | | eT acc = eT(0); | |
| for(u32 i=0; i<A_n_elem; ++i) | | for(u32 i=0; i<A_n_elem; ++i) | |
| { | | { | |
| acc += std::sqrt(A_mem[i]); | | acc += std::sqrt(A_mem[i]); | |
| } | | } | |
| | | | |
| return acc; | | return acc; | |
| } | | } | |
| | | | |
|
| | | //! sum of square roots | |
| | | template<typename T1> | |
| | | inline | |
| | | typename T1::elem_type | |
| | | accu(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 A_n_elem = A.n_elem; | |
| | | const eT* A_mem = A.mem; | |
| | | | |
| | | eT acc = eT(0); | |
| | | for(u32 i=0; i<A_n_elem; ++i) | |
| | | { | |
| | | acc += std::sqrt(A_mem[i]); | |
| | | } | |
| | | | |
| | | return acc; | |
| | | } | |
| | | | |
| //! sum of squares of differences | | //! sum of squares of differences | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| typename T1::elem_type | | typename T1::elem_type | |
| accu(const Op< Glue<T1,T2, glue_minus>, op_square>& in) | | accu(const Op< Glue<T1,T2, glue_minus>, op_square>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| | | | |
| skipping to change at line 164 | | skipping to change at line 206 | |
| eT acc = eT(0); | | eT acc = eT(0); | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| const eT val = A.mem[i] - B.mem[i]; | | const eT val = A.mem[i] - B.mem[i]; | |
| acc += val*val; | | acc += val*val; | |
| } | | } | |
| | | | |
| return acc; | | return acc; | |
| } | | } | |
| | | | |
|
| //! accumulate the elements of a subview (submatrix) | | //! sum of squares of differences | |
| template<typename eT> | | template<typename T1, typename T2> | |
| inline | | inline | |
|
| eT | | typename T1::elem_type | |
| accu(const subview<eT>& X) | | accu(const OpCube< GlueCube<T1,T2, glue_cube_minus>, op_square>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT val = eT(0); | | typedef typename T1::elem_type eT; | |
| for(u32 col=0; col<X.n_cols; ++col) | | | |
| { | | | |
| const eT* coldata = X.colptr(col); | | | |
| | | | |
|
| for(u32 row=0; row<X.n_rows; ++row) | | const unwrap_cube<T1> tmp1(in.m.A); | |
| { | | const unwrap_cube<T2> tmp2(in.m.B); | |
| val += coldata[row]; | | | |
| } | | | |
| | | | |
|
| | | const Cube<eT>& A = tmp1.M; | |
| | | const Cube<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(A,B, "accu()"); | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | eT acc = eT(0); | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | const eT val = A.mem[i] - B.mem[i]; | |
| | | acc += val*val; | |
| } | | } | |
| | | | |
|
| return val; | | return acc; | |
| } | | } | |
| | | | |
|
| //! accumulate the elements of a diagview | | //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu(const diagview<eT>& X) | | accu_schur(const Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 n_elem = X.n_elem; | | arma_debug_assert_same_size(A,B, "accu()"); | |
| | | | |
| | | const eT* const A_mem = A.mem; | |
| | | const eT* const B_mem = B.mem; | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| val += X[i]; | | val += A_mem[i] * B_mem[i]; | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
| //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | | //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu_schur(const Mat<eT>& A, const Mat<eT>& B) | | accu_schur(const Cube<eT>& A, const Cube<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(A,B, "accu()"); | | arma_debug_assert_same_size(A,B, "accu()"); | |
| | | | |
| const eT* const A_mem = A.mem; | | const eT* const A_mem = A.mem; | |
| const eT* const B_mem = B.mem; | | const eT* const B_mem = B.mem; | |
| | | | |
| const u32 n_elem = A.n_elem; | | const u32 n_elem = A.n_elem; | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| skipping to change at line 239 | | skipping to change at line 293 | |
| | | | |
| //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | | //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| accu(const Glue<Mat<eT>,Mat<eT>,glue_schur>& X) | | accu(const Glue<Mat<eT>,Mat<eT>,glue_schur>& X) | |
| { | | { | |
| return accu_schur(X.A, X.B); | | return accu_schur(X.A, X.B); | |
| } | | } | |
| | | | |
|
| | | //! accumulate the result of A % B, where % is the Schur product (element-w | |
| | | ise multiplication) | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | accu(const GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >& X) | |
| | | { | |
| | | return accu_schur(X.A, X.B); | |
| | | } | |
| | | | |
| //! accumulate the result of A % B % C, where % is the Schur product (eleme
nt-wise multiplication) | | //! accumulate the result of A % B % C, where % is the Schur product (eleme
nt-wise multiplication) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| accu(const Glue<Glue<Mat<eT>,Mat<eT>,glue_schur>,Mat<eT>,glue_schur>& X) | | accu(const Glue<Glue<Mat<eT>,Mat<eT>,glue_schur>,Mat<eT>,glue_schur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Mat<eT>& A = X.A.A; | | const Mat<eT>& A = X.A.A; | |
| const Mat<eT>& B = X.A.B; | | const Mat<eT>& B = X.A.B; | |
| | | | |
| skipping to change at line 269 | | skipping to change at line 332 | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| val += A_mem[i] * B_mem[i] * C_mem[i]; | | val += A_mem[i] * B_mem[i] * C_mem[i]; | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| | | //! accumulate the result of A % B % C, where % is the Schur product (eleme | |
| | | nt-wise multiplication) | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | accu(const GlueCube< GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >, Cube< | |
| | | eT>, glue_cube_schur >& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const Cube<eT>& A = X.A.A; | |
| | | const Cube<eT>& B = X.A.B; | |
| | | const Cube<eT>& C = X.B; | |
| | | | |
| | | arma_debug_assert_same_size(A,B, "accu()"); | |
| | | arma_debug_assert_same_size(B,C, "accu()"); | |
| | | | |
| | | const eT* const A_mem = A.mem; | |
| | | const eT* const B_mem = B.mem; | |
| | | const eT* const C_mem = C.mem; | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | eT val = eT(0); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | val += A_mem[i] * B_mem[i] * C_mem[i]; | |
| | | } | |
| | | | |
| | | return val; | |
| | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! accumulate the result of T1 % T2 | | //! accumulate the result of T1 % T2 | |
| //! where % is the Schur product (element-wise multiplication), | | //! where % is the Schur product (element-wise multiplication), | |
| //! while T1 and T2 can be 'mat', 'rowvec', 'colvec', 'Op', 'Glue' | | //! while T1 and T2 can be 'mat', 'rowvec', 'colvec', 'Op', 'Glue' | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| typename T1::elem_type | | typename T1::elem_type | |
| accu(const Glue<T1,T2,glue_schur>& X) | | accu(const Glue<T1,T2,glue_schur>& X) | |
| { | | { | |
| | | | |
| skipping to change at line 290 | | skipping to change at line 383 | |
| | | | |
| isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check(); | | isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::nu
m; | | const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::nu
m; | |
| arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | | arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | |
| | | | |
| if(N_mat == 2) | | if(N_mat == 2) | |
| { | | { | |
|
| return accu_schur(Mat<eT>(X.A), Mat<eT>(X.B)); | | const unwrap<T1> tmp1(X.A); | |
| | | const unwrap<T2> tmp2(X.B); | |
| | | | |
| | | return accu_schur(tmp1.M, tmp2.M); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT>* ptrs[N_mat]; | | const Mat<eT>* ptrs[N_mat]; | |
| bool del[N_mat]; | | bool del[N_mat]; | |
| | | | |
| mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X); | | mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X); | |
| | | | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
" del[%d] = %d") % i % del[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
" del[%d] = %d") % i % del[i] ); | |
| | | | |
| skipping to change at line 341 | | skipping to change at line 437 | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete mat_ptr[%d]") %
i ); | | arma_extra_debug_print( arma_boost::format("delete mat_ptr[%d]") %
i ); | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! accumulate the result of submatrix % matrix, where % is the Schur produ | | //! sum of values along the main diagonal | |
| ct (element-wise multiplication) | | template<typename T1> | |
| template<typename eT> | | | |
| inline | | inline | |
|
| eT | | typename T1::elem_type | |
| accu(const Glue<subview<eT>,Mat<eT>,glue_schur>& X) | | accu(const Op<T1, op_diagmat>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(X.A, X.B, "accu()"); | | typedef typename T1::elem_type eT; | |
| | | | |
| const Mat<eT>& A = X.A.m; | | | |
| const Mat<eT>& B = X.B; | | | |
| | | | |
|
| const u32 A_sub_n_rows = X.A.n_rows; | | const unwrap<T1> tmp(X.m); | |
| const u32 A_sub_n_cols = X.A.n_cols; | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| const u32 A_aux_row1 = X.A.aux_row1; | | arma_debug_check( !A.is_square(), "accu(): sum of diagonal values of a no | |
| const u32 A_aux_col1 = X.A.aux_col1; | | n-square matrix requested" ); | |
| | | | |
|
| eT val = eT(0); | | eT acc = eT(0); | |
| | | | |
|
| for(u32 col = 0; col<A_sub_n_cols; ++col) | | for(u32 i=0; i<A.n_rows; ++i) | |
| { | | { | |
|
| const u32 col_mod = A_aux_col1 + col; | | acc += A.at(i,i); | |
| | | | |
| for(u32 row = 0; row<A_sub_n_rows; ++row) | | | |
| { | | | |
| const u32 row_mod = A_aux_row1 + row; | | | |
| | | | |
| val += A.at(row_mod, col_mod) * B.at(row,col); | | | |
| } | | | |
| | | | |
| } | | } | |
| | | | |
|
| return val; | | return acc; | |
| } | | } | |
| | | | |
|
| //! accumulate the result of matrix % submatrix, where % is the Schur produ
ct (element-wise multiplication) | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu(const Glue<Mat<eT>,subview<eT>,glue_schur>& X) | | accu(const Op<Mat<eT>, op_diagmat_vec>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(X.A, X.B, "accu()"); | | const Mat<eT>& A = X.m; | |
| | | arma_debug_check( !A.is_vec(), "accu(): internal error: expected a vector | |
| const Mat<eT>& A = X.A; | | " ); | |
| const Mat<eT>& B = X.B.m; | | | |
| | | | |
|
| // const u32 B_sub_n_rows = X.B.n_rows; | | return accu(A); | |
| // const u32 B_sub_n_cols = X.B.n_cols; | | } | |
| | | | |
|
| const u32 B_aux_row1 = X.B.aux_row1; | | //! accumulate the elements of a diagview | |
| const u32 B_aux_col1 = X.B.aux_col1; | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | accu(const diagview<eT>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | const u32 n_elem = X.n_elem; | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 col = 0; col<A.n_cols; ++col) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| const u32 col_mod = B_aux_col1 + col; | | val += X[i]; | |
| | | | |
| for(u32 row = 0; row<A.n_rows; ++row) | | | |
| { | | | |
| const u32 row_mod = B_aux_row1 + row; | | | |
| | | | |
| val += A.at(row, col) * B.at(row_mod, col_mod); | | | |
| } | | | |
| | | | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| //! accumulate the result of submatrix % submatrix, where % is the Schur pr
oduct (element-wise multiplication) | | //! accumulate the elements of a subview (submatrix) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu(const Glue<subview<eT>,subview<eT>,glue_schur>& X) | | accu(const subview<eT>& S) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(X.A, X.B, "accu()"); | | | |
| | | | |
| const Mat<eT>& A = X.A.m; | | | |
| const Mat<eT>& B = X.B.m; | | | |
| | | | |
| const u32 A_sub_n_rows = X.A.n_rows; | | | |
| const u32 A_sub_n_cols = X.A.n_cols; | | | |
| | | | |
| // const u32 B_sub_n_rows = X.B.n_rows; | | | |
| // const u32 B_sub_n_cols = X.B.n_cols; | | | |
| | | | |
| const u32 A_aux_row1 = X.A.aux_row1; | | | |
| const u32 A_aux_col1 = X.A.aux_col1; | | | |
| | | | |
| const u32 B_aux_row1 = X.B.aux_row1; | | | |
| const u32 B_aux_col1 = X.B.aux_col1; | | | |
| | | | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 col = 0; col<A_sub_n_cols; ++col) | | for(u32 col=0; col<S.n_cols; ++col) | |
| { | | { | |
|
| const u32 A_col_mod = A_aux_col1 + col; | | const eT* coldata = S.colptr(col); | |
| const u32 B_col_mod = B_aux_col1 + col; | | | |
| | | | |
|
| for(u32 row = 0; row<A_sub_n_rows; ++row) | | for(u32 row=0; row<S.n_rows; ++row) | |
| { | | { | |
|
| const u32 A_row_mod = A_aux_row1 + row; | | val += coldata[row]; | |
| const u32 B_row_mod = B_aux_row1 + row; | | | |
| | | | |
| val += A.at(A_row_mod, A_col_mod) * B.at(B_row_mod, B_col_mod); | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| // | | //! accumulate the elements of a subview_row | |
| // | | template<typename eT> | |
| // Cube handling | | | |
| | | | |
| //! accumulate the elements of a cube | | | |
| template<typename T1> | | | |
| inline | | inline | |
|
| typename T1::elem_type | | eT | |
| accu(const BaseCube<typename T1::elem_type,T1>& X) | | accu(const subview_row<eT>& S) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | const Mat<eT>& X = S.m; | |
| | | | |
|
| const unwrap_cube<T1> tmp(X.get_ref()); | | const u32 row = S.aux_row1; | |
| const Cube<eT>& A = tmp.M; | | const u32 start_col = S.aux_col1; | |
| | | const u32 end_col = S.aux_col2; | |
| const u32 A_n_elem = A.n_elem; | | | |
| const eT* A_mem = A.mem; | | | |
| | | | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 i=0; i<A_n_elem; ++i) | | for(u32 col=start_col; col<=end_col; ++col) | |
| { | | { | |
|
| val += A_mem[i]; | | val += X.at(row,col); | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| //! sum of squares | | //! accumulate the elements of a subview_col | |
| template<typename T1> | | template<typename eT> | |
| inline | | inline | |
|
| typename T1::elem_type | | eT | |
| accu(const OpCube<T1, op_square>& in) | | accu(const subview_col<eT>& S) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | const eT* S_colptr = S.colptr(0); | |
| | | const u32 n_rows = S.n_rows; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | eT val = eT(0); | |
| const Cube<eT>& A = tmp.M; | | | |
| | | | |
| const u32 A_n_elem = A.n_elem; | | | |
| const eT* A_mem = A.mem; | | | |
| | | | |
| eT acc = eT(0); | | | |
| | | | |
|
| for(u32 i=0; i<A_n_elem; ++i) | | for(u32 row=0; row<n_rows; ++row) | |
| { | | { | |
|
| const eT val = A_mem[i]; | | val += S_colptr[row]; | |
| acc += val*val; | | | |
| } | | } | |
| | | | |
|
| return acc; | | return val; | |
| } | | } | |
| | | | |
|
| //! sum of square roots | | //! accumulate the result of submatrix % matrix, where % is the Schur produ | |
| template<typename T1> | | ct (element-wise multiplication) | |
| | | template<typename eT> | |
| inline | | inline | |
|
| typename T1::elem_type | | eT | |
| accu(const OpCube<T1, op_sqrt>& in) | | accu(const Glue<subview<eT>,Mat<eT>,glue_schur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | arma_debug_assert_same_size(X.A, X.B, "accu()"); | |
| | | | |
| const unwrap_cube<T1> tmp(in.m); | | | |
| const Cube<eT>& A = tmp.M; | | | |
| | | | |
| const u32 A_n_elem = A.n_elem; | | | |
| const eT* A_mem = A.mem; | | | |
| | | | |
| eT acc = eT(0); | | | |
| for(u32 i=0; i<A_n_elem; ++i) | | | |
| { | | | |
| acc += std::sqrt(A_mem[i]); | | | |
| } | | | |
| | | | |
|
| return acc; | | const Mat<eT>& A = X.A.m; | |
| } | | const Mat<eT>& B = X.B; | |
| | | | |
|
| //! sum of squares of differences | | const u32 A_sub_n_rows = X.A.n_rows; | |
| template<typename T1, typename T2> | | const u32 A_sub_n_cols = X.A.n_cols; | |
| inline | | | |
| typename T1::elem_type | | | |
| accu(const OpCube< GlueCube<T1,T2, glue_cube_minus>, op_square>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| typedef typename T1::elem_type eT; | | const u32 A_aux_row1 = X.A.aux_row1; | |
| | | const u32 A_aux_col1 = X.A.aux_col1; | |
| | | | |
|
| const unwrap_cube<T1> tmp1(in.m.A); | | eT val = eT(0); | |
| const unwrap_cube<T2> tmp2(in.m.B); | | | |
| | | | |
|
| const Cube<eT>& A = tmp1.M; | | for(u32 col = 0; col<A_sub_n_cols; ++col) | |
| const Cube<eT>& B = tmp2.M; | | { | |
| | | const u32 col_mod = A_aux_col1 + col; | |
| | | | |
|
| arma_debug_assert_same_size(A,B, "accu()"); | | for(u32 row = 0; row<A_sub_n_rows; ++row) | |
| | | { | |
| | | const u32 row_mod = A_aux_row1 + row; | |
| | | | |
|
| const u32 n_elem = A.n_elem; | | val += A.at(row_mod, col_mod) * B.at(row,col); | |
| | | } | |
| | | | |
|
| eT acc = eT(0); | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| const eT val = A.mem[i] - B.mem[i]; | | | |
| acc += val*val; | | | |
| } | | } | |
| | | | |
|
| return acc; | | return val; | |
| } | | } | |
| | | | |
|
| //! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication) | | //! accumulate the result of matrix % submatrix, where % is the Schur produ
ct (element-wise multiplication) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu_schur(const Cube<eT>& A, const Cube<eT>& B) | | accu(const Glue<Mat<eT>,subview<eT>,glue_schur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_assert_same_size(A,B, "accu()"); | | arma_debug_assert_same_size(X.A, X.B, "accu()"); | |
| | | | |
|
| const eT* const A_mem = A.mem; | | const Mat<eT>& A = X.A; | |
| const eT* const B_mem = B.mem; | | const Mat<eT>& B = X.B.m; | |
| | | | |
| | | // const u32 B_sub_n_rows = X.B.n_rows; | |
| | | // const u32 B_sub_n_cols = X.B.n_cols; | |
| | | | |
| | | const u32 B_aux_row1 = X.B.aux_row1; | |
| | | const u32 B_aux_col1 = X.B.aux_col1; | |
| | | | |
|
| const u32 n_elem = A.n_elem; | | | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 i=0; i<n_elem; ++i) | | for(u32 col = 0; col<A.n_cols; ++col) | |
| { | | { | |
|
| val += A_mem[i] * B_mem[i]; | | const u32 col_mod = B_aux_col1 + col; | |
| | | | |
| | | for(u32 row = 0; row<A.n_rows; ++row) | |
| | | { | |
| | | const u32 row_mod = B_aux_row1 + row; | |
| | | | |
| | | val += A.at(row, col) * B.at(row_mod, col_mod); | |
| | | } | |
| | | | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| //! accumulate the result of A % B, where % is the Schur product (element-w | | //! accumulate the result of submatrix % submatrix, where % is the Schur pr | |
| ise multiplication) | | oduct (element-wise multiplication) | |
| template<typename eT> | | | |
| inline | | | |
| eT | | | |
| accu(const GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >& X) | | | |
| { | | | |
| return accu_schur(X.A, X.B); | | | |
| } | | | |
| | | | |
| //! accumulate the result of A % B % C, where % is the Schur product (eleme | | | |
| nt-wise multiplication) | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| accu(const GlueCube< GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >, Cube<
eT>, glue_cube_schur >& X) | | accu(const Glue<subview<eT>,subview<eT>,glue_schur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const Cube<eT>& A = X.A.A; | | arma_debug_assert_same_size(X.A, X.B, "accu()"); | |
| const Cube<eT>& B = X.A.B; | | | |
| const Cube<eT>& C = X.B; | | | |
| | | | |
|
| arma_debug_assert_same_size(A,B, "accu()"); | | const Mat<eT>& A = X.A.m; | |
| arma_debug_assert_same_size(B,C, "accu()"); | | const Mat<eT>& B = X.B.m; | |
| | | | |
|
| const eT* const A_mem = A.mem; | | const u32 A_sub_n_rows = X.A.n_rows; | |
| const eT* const B_mem = B.mem; | | const u32 A_sub_n_cols = X.A.n_cols; | |
| const eT* const C_mem = C.mem; | | | |
| | | // const u32 B_sub_n_rows = X.B.n_rows; | |
| | | // const u32 B_sub_n_cols = X.B.n_cols; | |
| | | | |
| | | const u32 A_aux_row1 = X.A.aux_row1; | |
| | | const u32 A_aux_col1 = X.A.aux_col1; | |
| | | | |
| | | const u32 B_aux_row1 = X.B.aux_row1; | |
| | | const u32 B_aux_col1 = X.B.aux_col1; | |
| | | | |
|
| const u32 n_elem = A.n_elem; | | | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
|
| for(u32 i=0; i<n_elem; ++i) | | for(u32 col = 0; col<A_sub_n_cols; ++col) | |
| { | | { | |
|
| val += A_mem[i] * B_mem[i] * C_mem[i]; | | const u32 A_col_mod = A_aux_col1 + col; | |
| | | const u32 B_col_mod = B_aux_col1 + col; | |
| | | | |
| | | for(u32 row = 0; row<A_sub_n_rows; ++row) | |
| | | { | |
| | | const u32 A_row_mod = A_aux_row1 + row; | |
| | | const u32 B_row_mod = B_aux_row1 + row; | |
| | | | |
| | | val += A.at(A_row_mod, A_col_mod) * B.at(B_row_mod, B_col_mod); | |
| | | } | |
| | | | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 94 change blocks. |
| 214 lines changed or deleted | | 265 lines changed or added | |
|
| fn_stddev.hpp | | fn_stddev.hpp | |
| | | | |
| skipping to change at line 51 | | skipping to change at line 51 | |
| } | | } | |
| | | | |
| //! Immediate 'find the standard deviation of a row vector' operation | | //! Immediate 'find the standard deviation of a row vector' operation | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| stddev(const Row<eT>& A, const u32 norm_type = 0) | | stddev(const Row<eT>& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | | return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | |
| } | | } | |
| | | | |
| //! Immediate 'find the standard deviation of a row vector' operation (vers
ion for complex numbers) | | //! Immediate 'find the standard deviation of a row vector' operation (vers
ion for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| T | | T | |
| stddev(const Row< std::complex<T> >& A, const u32 norm_type = 0) | | stddev(const Row< std::complex<T> >& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | | return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | |
| } | | } | |
| | | | |
| //! Immediate 'find the standard deviation of a column vector' operation | | //! Immediate 'find the standard deviation of a column vector' operation | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| stddev(const Col<eT>& A, const u32 norm_type = 0) | | stddev(const Col<eT>& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | | return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | |
| } | | } | |
| | | | |
| //! Immediate 'find the standard deviation of a column vector' operation (v
ersion for complex numbers) | | //! Immediate 'find the standard deviation of a column vector' operation (v
ersion for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| T | | T | |
| stddev(const Col< std::complex<T> >& A, const u32 norm_type = 0) | | stddev(const Col< std::complex<T> >& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | | return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a subview_row | | //! find the standard deviation of a subview_row | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| stddev(const subview_row<eT>& A, const u32 norm_type = 0) | | stddev(const subview_row<eT>& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a subview_row (version for complex numbe
rs) | | //! find the standard deviation of a subview_row (version for complex numbe
rs) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| T | | T | |
| stddev(const subview_row< std::complex<T> >& A, const u32 norm_type = 0) | | stddev(const subview_row< std::complex<T> >& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a subview_col | | //! find the standard deviation of a subview_col | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| stddev(const subview_col<eT>& A, const u32 norm_type = 0) | | stddev(const subview_col<eT>& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a subview_col (version for complex numbe
rs) | | //! find the standard deviation of a subview_col (version for complex numbe
rs) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| T | | T | |
| stddev(const subview_col< std::complex<T> >& A, const u32 norm_type = 0) | | stddev(const subview_col< std::complex<T> >& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a diagview | | //! find the standard deviation of a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| stddev(const diagview<eT>& A, const u32 norm_type = 0) | | stddev(const diagview<eT>& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! find the standard deviation of a diagview (version for complex numbers) | | //! find the standard deviation of a diagview (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| T | | T | |
| stddev(const diagview< std::complex<T> >& A, const u32 norm_type = 0) | | stddev(const diagview< std::complex<T> >& A, const u32 norm_type = 0) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
); | | arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" ); | |
| | | | |
| return std::sqrt( op_var::direct_var(A, norm_type) ); | | return std::sqrt( op_var::direct_var(A, norm_type) ); | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 10 change blocks. |
| 10 lines changed or deleted | | 10 lines changed or added | |
|
| glue_cube_div_meat.hpp | | glue_cube_div_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 glue_cube_div | | //! \addtogroup glue_cube_div | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_div::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "element-wise cube division"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] / B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_div::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, c | | | |
| onst Cube<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "element-wise cube division"); | | | |
| arma_debug_assert_same_size(B, C, "element-wise cube division"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| const eT* C_mem = C.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] / B_mem[i] / C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_div::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue_c | | | |
| ube_div>& X) | | | |
| { | | | |
| glue_cube_div::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_div::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cube< | | | |
| eT>,glue_cube_div>, Cube<eT>,glue_cube_div>& X) | | | |
| { | | | |
| glue_cube_div::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| | | inline | |
| void | | void | |
| glue_cube_div::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1,T
2,glue_cube_div>& X) | | glue_cube_div::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1,T
2,glue_cube_div>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_cube = 1 + depth_lhs_cube< glue_cube_div, GlueCube<T1,T2,glue
_cube_div> >::num; | | const u32 N_cube = 1 + depth_lhs_cube< glue_cube_div, GlueCube<T1,T2,glue
_cube_div> >::num; | |
| arma_extra_debug_print( arma_boost::format("N_cube = %d") % N_cube ); | | arma_extra_debug_print( arma_boost::format("N_cube = %d") % N_cube ); | |
| | | | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 87 | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_div::apply_inplace(Cube<eT>& out, const Cube<eT>& B) | | glue_cube_div::apply_inplace(Cube<typename T1::elem_type>& out, const T1& X
) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X); | |
| | | const Cube<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "element-wise cube division"); | | arma_debug_assert_same_size(out, B, "element-wise cube division"); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] /= B_mem[i]; | | out_mem[i] /= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_cube_type> | | //! element-wise division with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_div::apply_inplace(Cube<typename T1::elem_type>& out, const OpCub
e<T1, op_cube_type>& X) | | glue_cube_div::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>& ou
t, const Cube<eT1>& X, const Cube<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
|
| const Cube<eT> tmp(X); | | arma_debug_assert_same_size(X,Y, "element-wise cube division"); | |
| glue_cube_div::apply_inplace(out, tmp); | | | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_cube_type> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_div::apply_inplace(Cube<typename T1::elem_type>& out, const GlueC
ube<T1, T2, glue_cube_type>& X) | | glue_cube_div::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | arma_debug_assert_same_size(A, B, "element-wise cube division"); | |
| | | | |
|
| const Cube<eT> tmp(X); | | // no aliasing problem | |
| glue_cube_div::apply_inplace(out, tmp); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| } | | out.copy_size(A); | |
| | | | |
|
| // | | const u32 n_elem = A.n_elem; | |
| // element-wise division with different element types | | | |
| | | | |
|
| template<typename eT1, typename eT2> | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] / B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_div::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>& ou
t, const Cube<eT1>& X, const Cube<eT2>& Y) | | glue_cube_div::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, c
onst Cube<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | arma_debug_assert_same_size(A, B, "element-wise cube division"); | |
| | | arma_debug_assert_same_size(B, C, "element-wise cube division"); | |
| arma_debug_assert_same_size(X,Y, "element-wise cube division"); | | | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols, X.n_slices); | | // no aliasing problem | |
| out.copy_size(X); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | const u32 n_elem = A.n_elem; | |
| const eT1* X_mem = X.mem; | | | |
| const eT2* Y_mem = Y.mem; | | | |
| | | | |
|
| const u32 n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
| 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] = A_mem[i] / B_mem[i] / C_mem[i]; | |
| } | | } | |
|
| | | | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_div::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue_c | |
| | | ube_div>& X) | |
| | | { | |
| | | glue_cube_div::apply(out, X.A, X.B); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_div::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cube< | |
| | | eT>,glue_cube_div>, Cube<eT>,glue_cube_div>& X) | |
| | | { | |
| | | glue_cube_div::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 23 change blocks. |
| 100 lines changed or deleted | | 82 lines changed or added | |
|
| glue_cube_minus_meat.hpp | | glue_cube_minus_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 glue_cube_minus | | //! \addtogroup glue_cube_minus | |
| //! @{ | | //! @{ | |
| | | | |
|
| //! Immediate out = A-B | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_minus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube subtraction"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] - B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-C | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_minus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, | | | |
| const Cube<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube subtraction"); | | | |
| arma_debug_assert_same_size(B, C, "cube subtraction"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| const eT* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] - B_mem[i] - C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B (operands obtained from Glue) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_minus::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue | | | |
| _cube_minus>& X) | | | |
| { | | | |
| glue_cube_minus::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-C (operands obtained from Glue) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_minus::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cub | | | |
| e<eT>,glue_cube_minus>, Cube<eT>, glue_cube_minus> &X) | | | |
| { | | | |
| glue_cube_minus::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-...-Z (operands obtained from Glue) | | //! Immediate out = A-B-...-Z (operands obtained from Glue) | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_cube_minus::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1
,T2,glue_cube_minus>& X) | | glue_cube_minus::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1
,T2,glue_cube_minus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| | | | |
| skipping to change at line 163 | | skipping to change at line 89 | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
| //! Immediate out -= B | | //! Immediate out -= B | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_minus::apply_inplace(Cube<eT>& out, const Cube<eT>& B) | | glue_cube_minus::apply_inplace(Cube<typename T1::elem_type>& out, const T1&
X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X); | |
| | | const Cube<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "cube subtraction"); | | arma_debug_assert_same_size(out, B, "cube subtraction"); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| 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] -= B_mem[i]; | | out_mem[i] -= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_cube_type> | | //! cube subtraction with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_minus::apply_inplace(Cube<typename T1::elem_type>& out, const OpC
ube<T1, op_cube_type>& X) | | glue_cube_minus::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>&
out, const Cube<eT1>& X, const Cube<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
|
| const Cube<eT> tmp(X); | | arma_debug_assert_same_size(X,Y, "cube subtraction"); | |
| glue_cube_minus::apply_inplace(out, tmp); | | | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_cube_type> | | //! Immediate out = A-B | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_minus::apply_inplace(Cube<typename T1::elem_type>& out, const Glu
eCube<T1, T2, glue_cube_type>& X) | | glue_cube_minus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | arma_debug_assert_same_size(A, B, "cube subtraction"); | |
| | | | |
|
| out = out - X; | | // no aliasing problem | |
| } | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
|
| // | | const u32 n_elem = A.n_elem; | |
| // cube subtraction with different element types | | | |
| | | | |
|
| template<typename eT1, typename eT2> | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] - B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Immediate out = A-B-C | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_minus::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>&
out, const Cube<eT1>& X, const Cube<eT2>& Y) | | glue_cube_minus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B,
const Cube<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | arma_debug_assert_same_size(A, B, "cube subtraction"); | |
| | | arma_debug_assert_same_size(B, C, "cube subtraction"); | |
| arma_debug_assert_same_size(X,Y, "cube subtraction"); | | | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols, X.n_slices); | | // no aliasing problem | |
| out.copy_size(X); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT1* X_mem = X.mem; | | const eT* A_mem = A.mem; | |
| const eT2* Y_mem = Y.mem; | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
|
| const u32 n_elem = out.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] = upgrade_val<eT1,eT2>::apply(X_mem[i]) - upgrade_val<eT1,eT
2>::apply(Y_mem[i]); | | out_mem[i] = A_mem[i] - B_mem[i] - C_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | //! Immediate out = A-B (operands obtained from Glue) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_minus::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue | |
| | | _cube_minus>& X) | |
| | | { | |
| | | glue_cube_minus::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | //! Immediate out = A-B-C (operands obtained from Glue) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_minus::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cub | |
| | | e<eT>,glue_cube_minus>, Cube<eT>, glue_cube_minus> &X) | |
| | | { | |
| | | glue_cube_minus::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | glue_cube_minus::apply_inplace(Cube<typename T1::elem_type>& out, const Glu | |
| | | eCube<T1, T2, glue_cube_minus>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | out = out - X; | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 22 change blocks. |
| 103 lines changed or deleted | | 96 lines changed or added | |
|
| glue_cube_plus_meat.hpp | | glue_cube_plus_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 glue_cube_plus | | //! \addtogroup glue_cube_plus | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube addition"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] + B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, | | | |
| const Cube<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube addition"); | | | |
| arma_debug_assert_same_size(B, C, "cube addition"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| const eT* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] + B_mem[i] + C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue_ | | | |
| cube_plus>& X) | | | |
| { | | | |
| glue_cube_plus::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cube | | | |
| <eT>,glue_cube_plus>, Cube<eT>, glue_cube_plus>& X) | | | |
| { | | | |
| glue_cube_plus::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_cube_plus::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1,
T2,glue_cube_plus>& X) | | glue_cube_plus::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1,
T2,glue_cube_plus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_cube = 1 + depth_lhs_cube< glue_cube_plus, GlueCube<T1,T2,glu
e_cube_plus> >::num; | | const u32 N_cube = 1 + depth_lhs_cube< glue_cube_plus, GlueCube<T1,T2,glu
e_cube_plus> >::num; | |
| | | | |
| skipping to change at line 159 | | skipping to change at line 89 | |
| { | | { | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const T1& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X); | |
| | | const Cube<eT>& B = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, B, "cube addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const u32 n_elem = B.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! cube addition with different element types | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>& o | |
| | | ut, const Cube<eT1>& X, const Cube<eT2>& Y) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "cube addition"); | |
| | | | |
| | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube addition"); | |
| | | | |
| | | // no aliasing problem | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] + B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, | |
| | | const Cube<eT>& C) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "cube addition"); | |
| | | arma_debug_assert_same_size(B, C, "cube addition"); | |
| | | | |
| | | // no aliasing problem | |
| | | //out.set_size(A); | |
| | | out.copy_size(A); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] + B_mem[i] + C_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue_ | |
| | | cube_plus>& X) | |
| | | { | |
| | | glue_cube_plus::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_plus::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cube | |
| | | <eT>,glue_cube_plus>, Cube<eT>, glue_cube_plus>& X) | |
| | | { | |
| | | glue_cube_plus::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| glue_cube_plus::apply(Cube<eT>& out, const GlueCube<Cube<eT>, subview_cube<
eT>, glue_cube_plus>& X) | | glue_cube_plus::apply(Cube<eT>& out, const GlueCube<Cube<eT>, subview_cube<
eT>, glue_cube_plus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Cube<eT>& orig_A = X.A; | | const Cube<eT>& orig_A = X.A; | |
| const Cube<eT>& orig_B = X.B.m; | | const Cube<eT>& orig_B = X.B.m; | |
| | | | |
| | | | |
| skipping to change at line 301 | | skipping to change at line 356 | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Cube<eT> processed_A(X.A); | | const Cube<eT> processed_A(X.A); | |
| const Cube<eT> processed_B(X.B); | | const Cube<eT> processed_B(X.B); | |
| | | | |
| glue_cube_plus::apply(out, processed_A, processed_B); | | glue_cube_plus::apply(out, processed_A, processed_B); | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply_inplace(Cube<eT>& out, const Cube<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(out, B, "cube addition"); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| const u32 n_elem = B.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] += B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename T1, typename op_cube_type> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const OpCu | | | |
| be<T1, op_cube_type>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| const Cube<eT> tmp(X); | | | |
| glue_cube_plus::apply_inplace(out, tmp); | | | |
| } | | | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const OpCu
be<T1, op_square>& X) | | glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const OpCu
be<T1, op_square>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap_cube<T1> tmp(X.m); | | const unwrap_cube<T1> tmp(X.m); | |
| | | | |
| skipping to change at line 361 | | skipping to change at line 382 | |
| | | | |
| 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) | |
| { | | { | |
| const eT tmp_val = B_mem[i]; | | const eT tmp_val = B_mem[i]; | |
| out_mem[i] += tmp_val*tmp_val; | | out_mem[i] += tmp_val*tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_cube_type> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const Glue
Cube<T1, T2, glue_cube_type>& X) | | glue_cube_plus::apply_inplace(Cube<typename T1::elem_type>& out, const Glue
Cube<T1, T2, glue_cube_plus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| out = X + out; | | out = X + out; | |
| } | | } | |
| | | | |
|
| // | | #endif | |
| // cube addition with different element types | | | |
| | | | |
| template<typename eT1, typename eT2> | | | |
| inline | | | |
| void | | | |
| glue_cube_plus::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>& o | | | |
| ut, const Cube<eT1>& X, const Cube<eT2>& Y) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename promote_type<eT1,eT2>::result out_eT; | | | |
| | | | |
| arma_debug_assert_same_size(X,Y, "cube addition"); | | | |
| | | | |
| //out.set_size(X.n_rows, X.n_cols, X.n_slices); | | | |
| out.copy_size(X); | | | |
| | | | |
| out_eT* out_mem = out.memptr(); | | | |
| const eT1* X_mem = X.mem; | | | |
| const eT2* Y_mem = Y.mem; | | | |
| | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| 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]); | | | |
| } | | | |
| } | | | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 6 change blocks. |
| 140 lines changed or deleted | | 134 lines changed or added | |
|
| glue_cube_schur_meat.hpp | | glue_cube_schur_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 glue_cube_schur | | //! \addtogroup glue_cube_schur | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_schur::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube schur product"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] * B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_schur::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B, | | | |
| const Cube<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "cube schur product"); | | | |
| arma_debug_assert_same_size(A, C, "cube schur product"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| const eT* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] * B_mem[i] * C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_schur::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue | | | |
| _cube_schur>& X) | | | |
| { | | | |
| glue_cube_schur::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_cube_schur::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cub | | | |
| e<eT>,glue_cube_schur>, Cube<eT>,glue_cube_schur>& X) | | | |
| { | | | |
| glue_cube_schur::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| | | inline | |
| void | | void | |
| glue_cube_schur::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1
,T2,glue_cube_schur>& X) | | glue_cube_schur::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1
,T2,glue_cube_schur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_cube = 1 + depth_lhs_cube< glue_cube_schur, GlueCube<T1,T2,gl
ue_cube_schur> >::num; | | const u32 N_cube = 1 + depth_lhs_cube< glue_cube_schur, GlueCube<T1,T2,gl
ue_cube_schur> >::num; | |
| arma_extra_debug_print( arma_boost::format("N_cube = %d") % N_cube ); | | arma_extra_debug_print( arma_boost::format("N_cube = %d") % N_cube ); | |
| | | | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 87 | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_schur::apply_inplace(Cube<eT>& out, const Cube<eT>& B) | | glue_cube_schur::apply_inplace(Cube<typename T1::elem_type>& out, const T1&
X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X); | |
| | | const Cube<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "cube schur product"); | | arma_debug_assert_same_size(out, B, "cube schur product"); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] *= B_mem[i]; | | out_mem[i] *= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_cube_type> | | //! cube schur product with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_schur::apply_inplace(Cube<typename T1::elem_type>& out, const OpC
ube<T1, op_cube_type>& X) | | glue_cube_schur::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>&
out, const Cube<eT1>& X, const Cube<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "cube schur product"); | |
| | | | |
|
| const Cube<eT> tmp(X); | | //out.set_size(X.n_rows, X.n_cols, X.n_slices); | |
| glue_cube_schur::apply_inplace(out, tmp); | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_cube_type> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_schur::apply_inplace(Cube<typename T1::elem_type>& out, const Glu
eCube<T1, T2, glue_cube_type>& X) | | glue_cube_schur::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // out = X % out; | | arma_debug_assert_same_size(A, B, "cube schur product"); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | // no aliasing problem | |
| | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| const Cube<eT> tmp(X); | | eT* out_mem = out.memptr(); | |
| glue_cube_schur::apply_inplace(out, tmp); | | const eT* A_mem = A.mem; | |
| } | | const eT* B_mem = B.mem; | |
| | | | |
|
| // | | const u32 n_elem = A.n_elem; | |
| // cube schur product with different element types | | | |
| | | | |
|
| template<typename eT1, typename eT2> | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] * B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_cube_schur::apply_mixed(Cube<typename promote_type<eT1,eT2>::result>&
out, const Cube<eT1>& X, const Cube<eT2>& Y) | | glue_cube_schur::apply(Cube<eT>& out, const Cube<eT>& A, const Cube<eT>& B,
const Cube<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | arma_debug_assert_same_size(A, B, "cube schur product"); | |
| | | arma_debug_assert_same_size(A, C, "cube schur product"); | |
| arma_debug_assert_same_size(X,Y, "cube schur product"); | | | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols, X.n_slices); | | // no aliasing problem | |
| out.copy_size(X); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| | | out.copy_size(A); | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT1* X_mem = X.mem; | | const eT* A_mem = A.mem; | |
| const eT2* Y_mem = Y.mem; | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
|
| const u32 n_elem = out.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] = upgrade_val<eT1,eT2>::apply(X_mem[i]) * upgrade_val<eT1,eT
2>::apply(Y_mem[i]); | | out_mem[i] = A_mem[i] * B_mem[i] * C_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_schur::apply(Cube<eT>& out, const GlueCube<Cube<eT>,Cube<eT>,glue | |
| | | _cube_schur>& X) | |
| | | { | |
| | | glue_cube_schur::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_cube_schur::apply(Cube<eT>& out, const GlueCube< GlueCube<Cube<eT>,Cub | |
| | | e<eT>,glue_cube_schur>, Cube<eT>,glue_cube_schur>& X) | |
| | | { | |
| | | glue_cube_schur::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | glue_cube_schur::apply_inplace(Cube<typename T1::elem_type>& out, const Glu | |
| | | eCube<T1, T2, glue_cube_schur>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | out = X % out; | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 24 change blocks. |
| 101 lines changed or deleted | | 92 lines changed or added | |
|
| glue_div_meat.hpp | | glue_div_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 glue_div | | //! \addtogroup glue_div | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_div::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "element-wise matrix division"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols); | | | |
| out.copy_size(A); | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] / B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_div::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Mat | | | |
| <eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "element-wise matrix division"); | | | |
| arma_debug_assert_same_size(B, C, "element-wise matrix division"); | | | |
| | | | |
| // no aliasing problem | | | |
| //out.set_size(A.n_rows, A.n_cols); | | | |
| out.copy_size(A); | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT* A_mem = A.mem; | | | |
| const eT* B_mem = B.mem; | | | |
| const eT* C_mem = C.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] / B_mem[i] / C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_div::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_div>& X) | | | |
| { | | | |
| glue_div::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_div::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_div>, M | | | |
| at<eT>,glue_div>& X) | | | |
| { | | | |
| glue_div::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| | | inline | |
| void | | void | |
| glue_div::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_div
>& X) | | glue_div::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_div
>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_mat = 1 + depth_lhs< glue_div, Glue<T1,T2,glue_div> >::num; | | const u32 N_mat = 1 + depth_lhs< glue_div, Glue<T1,T2,glue_div> >::num; | |
| arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | | arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | |
| | | | |
| if(N_mat == 2) | | if(N_mat == 2) | |
| { | | { | |
|
| const unwrap<T1> tmp1(X.A); | | if(is_Mat<T1>::value == false) | |
| const unwrap<T2> tmp2(X.B); | | { | |
| | | out = X.A; | |
| | | glue_div::apply_inplace(out, X.B); | |
| | | } | |
| | | else | |
| | | { | |
| | | const unwrap<T1> tmp1(X.A); | |
| | | const unwrap<T2> tmp2(X.B); | |
| | | | |
|
| glue_div::apply(out, tmp1.M, tmp2.M); | | glue_div::apply(out, tmp1.M, tmp2.M); | |
| | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT>* ptrs[N_mat]; | | const Mat<eT>* ptrs[N_mat]; | |
| bool del[N_mat]; | | bool del[N_mat]; | |
| | | | |
| mat_ptrs<glue_div, Glue<T1,T2,glue_div> >::get_ptrs(ptrs, del, X); | | mat_ptrs<glue_div, Glue<T1,T2,glue_div> >::get_ptrs(ptrs, del, X); | |
| //mat_ptrs_outcheck<glue_div, Glue<T1,T2,glue_div> >::get_ptrs(ptrs, de
l, X, &out); | | //mat_ptrs_outcheck<glue_div, Glue<T1,T2,glue_div> >::get_ptrs(ptrs, de
l, X, &out); | |
| | | | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 95 | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_div::apply_inplace(Mat<eT>& out, const Mat<eT>& B) | | glue_div::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "element-wise matrix division"); | | arma_debug_assert_same_size(out, B, "element-wise matrix division"); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] /= B_mem[i]; | | out_mem[i] /= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_type> | | //! element-wise division with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_div::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_t
ype>& X) | | glue_div::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, con
st Mat<eT1>& X, const Mat<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "element-wise matrix division"); | |
| | | | |
| | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
|
| const Mat<eT> tmp(X); | | const u32 n_elem = out.n_elem; | |
| glue_div::apply_inplace(out, tmp); | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_div::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, T2
, glue_type>& X) | | glue_div::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | arma_debug_assert_same_size(A, B, "element-wise matrix division"); | |
| | | | |
|
| const Mat<eT> tmp(X); | | // no aliasing problem | |
| glue_div::apply_inplace(out, tmp); | | //out.set_size(A.n_rows, A.n_cols); | |
| } | | out.copy_size(A); | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
|
| // | | eT* out_mem = out.memptr(); | |
| // element-wise division with different element types | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
|
| template<typename eT1, typename eT2> | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] / B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_div::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, con
st Mat<eT1>& X, const Mat<eT2>& Y) | | glue_div::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Mat
<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | arma_debug_assert_same_size(A, B, "element-wise matrix division"); | |
| | | arma_debug_assert_same_size(B, C, "element-wise matrix division"); | |
| arma_debug_assert_same_size(X,Y, "element-wise matrix division"); | | | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols); | | // no aliasing problem | |
| out.copy_size(X); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | const u32 n_elem = A.n_elem; | |
| const eT1* X_mem = X.mem; | | | |
| const eT2* Y_mem = Y.mem; | | | |
| | | | |
|
| const u32 n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
| 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] = A_mem[i] / B_mem[i] / C_mem[i]; | |
| } | | } | |
|
| | | | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_div::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_div>& X) | |
| | | { | |
| | | glue_div::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_div::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_div>, M | |
| | | at<eT>,glue_div>& X) | |
| | | { | |
| | | glue_div::apply(out, X.A.A, X.A.B, X.B); | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 25 change blocks. |
| 102 lines changed or deleted | | 92 lines changed or added | |
|
| glue_minus_meat.hpp | | glue_minus_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 glue_minus | | //! \addtogroup glue_minus | |
| //! @{ | | //! @{ | |
| | | | |
|
| //! Immediate out = A-B | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_minus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix subtraction"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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 u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] - B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-C | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_minus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M | | | |
| at<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix subtraction"); | | | |
| arma_debug_assert_same_size(A, C, "matrix subtraction"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] - B_mem[i] - C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B (operands obtained from Glue) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_minus::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_minus>& X) | | | |
| { | | | |
| glue_minus::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-C (operands obtained from Glue) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_minus::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_minus | | | |
| >, Mat<eT>, glue_minus> &X) | | | |
| { | | | |
| glue_minus::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| //! Immediate out = A-B-...-Z (operands obtained from Glue) | | //! Immediate out = A-B-...-Z (operands obtained from Glue) | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_minus::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_m
inus>& X) | | glue_minus::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_m
inus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_mat = 1 + depth_lhs< glue_minus, Glue<T1,T2,glue_minus> >::nu
m; | | const u32 N_mat = 1 + depth_lhs< glue_minus, Glue<T1,T2,glue_minus> >::nu
m; | |
| arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | | arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | |
| | | | |
| if(N_mat == 2) | | if(N_mat == 2) | |
| { | | { | |
|
| const unwrap<T1> tmp1(X.A); | | if(is_Mat<T1>::value == false) | |
| const unwrap<T2> tmp2(X.B); | | { | |
| | | out = X.A; | |
| | | glue_minus::apply_inplace(out, X.B); | |
| | | } | |
| | | else | |
| | | { | |
| | | const unwrap<T1> tmp1(X.A); | |
| | | const unwrap<T2> tmp2(X.B); | |
| | | | |
|
| glue_minus::apply(out, tmp1.M, tmp2.M); | | glue_minus::apply(out, tmp1.M, tmp2.M); | |
| | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT>* ptrs[N_mat]; | | const Mat<eT>* ptrs[N_mat]; | |
| bool del[N_mat]; | | bool del[N_mat]; | |
| | | | |
| mat_ptrs<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs, del, X); | | mat_ptrs<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs, del, X); | |
| //mat_ptrs_outcheck<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs
, del, X, &out); | | //mat_ptrs_outcheck<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs
, del, X, &out); | |
| | | | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | |
| | | | |
| skipping to change at line 163 | | skipping to change at line 97 | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
| //! Immediate out -= B | | //! Immediate out -= B | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_minus::apply_inplace(Mat<eT>& out, const Mat<eT>& B) | | glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "matrix subtraction"); | | arma_debug_assert_same_size(out, B, "matrix subtraction"); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| 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] -= B_mem[i]; | | out_mem[i] -= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_type> | | //! matrix subtraction with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op
_type>& X) | | glue_minus::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "matrix subtraction"); | |
| | | | |
|
| const Mat<eT> tmp(X); | | //out.set_size(X.n_rows, X.n_cols); | |
| glue_minus::apply_inplace(out, tmp); | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | //! Immediate out = A-B | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, | | glue_minus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| T2, glue_type>& X) | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "matrix subtraction"); | |
| | | | |
| | | // no aliasing problem | |
| | | //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 u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] - B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! Immediate out = A-B-C | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_minus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M | |
| | | at<eT>& C) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "matrix subtraction"); | |
| | | arma_debug_assert_same_size(A, C, "matrix subtraction"); | |
| | | | |
| | | // no aliasing problem | |
| | | //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* C_mem = C.mem; | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] - B_mem[i] - C_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op | |
| | | _scalar_times>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| out = out - X; | | const unwrap<T1> tmp(X.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, A, "matrix subtraction"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | | |
| | | const eT k = X.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] -= k * A_mem[i]; | |
| | | } | |
| } | | } | |
| | | | |
|
| // | | template<typename T1> | |
| // matrix subtraction with different element types | | inline | |
| | | void | |
| | | glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op | |
| | | _scalar_div_pre>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
|
| template<typename eT1, typename eT2> | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, A, "matrix subtraction"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | | |
| | | const eT k = X.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] -= k / A_mem[i]; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_minus::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | | glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op
_scalar_div_post>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| arma_debug_assert_same_size(X,Y, "matrix subtraction"); | | const unwrap<T1> tmp(X.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols); | | arma_debug_assert_same_size(out, A, "matrix subtraction"); | |
| out.copy_size(X); | | | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT1* X_mem = X.mem; | | const eT* A_mem = A.mem; | |
| const eT2* Y_mem = Y.mem; | | | |
| | | | |
|
| const u32 n_elem = out.n_elem; | | const eT k = X.aux; | |
| | | 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] -= A_mem[i] / k; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | //! Immediate out = A-B (operands obtained from Glue) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_minus::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_minus>& X) | |
| | | { | |
| | | glue_minus::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | //! Immediate out = A-B-C (operands obtained from Glue) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_minus::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_minus | |
| | | >, Mat<eT>, glue_minus> &X) | |
| | | { | |
| | | glue_minus::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | glue_minus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, | |
| | | T2, glue_minus>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | out = out - X; | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| // | | // | |
| // glue_minus_diag | | // glue_minus_diag | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_minus_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | | glue_minus_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
End of changes. 23 change blocks. |
| 103 lines changed or deleted | | 186 lines changed or added | |
|
| glue_plus_meat.hpp | | glue_plus_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 glue_plus | | //! \addtogroup glue_plus | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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 u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] + B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Ma | | | |
| t<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix addition"); | | | |
| arma_debug_assert_same_size(A, C, "matrix addition"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] + B_mem[i] + C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_plus::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_plus>& X) | | | |
| { | | | |
| glue_plus::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_plus::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_plus>, | | | |
| Mat<eT>, glue_plus>& X) | | | |
| { | | | |
| glue_plus::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_plus::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_pl
us>& X) | | glue_plus::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_pl
us>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_mat = 1 + depth_lhs< glue_plus, Glue<T1,T2,glue_plus> >::num; | | const u32 N_mat = 1 + depth_lhs< glue_plus, Glue<T1,T2,glue_plus> >::num; | |
| | | | |
| skipping to change at line 115 | | skipping to change at line 45 | |
| glue_plus::apply_inplace(out, X.A); | | glue_plus::apply_inplace(out, X.A); | |
| } | | } | |
| else | | else | |
| if(is_glue_times<T2>::value == true) | | if(is_glue_times<T2>::value == true) | |
| { | | { | |
| out = X.A; | | out = X.A; | |
| glue_plus::apply_inplace(out, X.B); | | glue_plus::apply_inplace(out, X.B); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const unwrap<T1> tmp1(X.A); | | if(is_Mat<T1>::value == false) | |
| const unwrap<T2> tmp2(X.B); | | { | |
| | | out = X.A; | |
| | | glue_plus::apply_inplace(out, X.B); | |
| | | } | |
| | | else | |
| | | if(is_Mat<T2>::value == false) | |
| | | { | |
| | | out = X.B; | |
| | | glue_plus::apply_inplace(out, X.A); | |
| | | } | |
| | | else | |
| | | { | |
| | | // even though the calls to unwrap in this block are logically unne | |
| | | cessary, | |
| | | // the compiler ignores the above if statements and overzealously c | |
| | | hecks | |
| | | // whether the code in this block can be used during all instances | |
| | | of | |
| | | // template expansion | |
| | | | |
| | | const unwrap<T1> tmp1(X.A); | |
| | | const unwrap<T2> tmp2(X.B); | |
| | | | |
|
| glue_plus::apply(out, tmp1.M, tmp2.M); | | glue_plus::apply(out, tmp1.M, tmp2.M); | |
| | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT>* ptrs[N_mat]; | | const Mat<eT>* ptrs[N_mat]; | |
| bool del[N_mat]; | | bool del[N_mat]; | |
| | | | |
| mat_ptrs<glue_plus, Glue<T1,T2,glue_plus> >::get_ptrs(ptrs, del, X); | | mat_ptrs<glue_plus, Glue<T1,T2,glue_plus> >::get_ptrs(ptrs, del, X); | |
| | | | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | |
| | | | |
| skipping to change at line 169 | | skipping to change at line 118 | |
| { | | { | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete mat_ptr[%d]") %
i ); | | arma_extra_debug_print( arma_boost::format("delete mat_ptr[%d]") %
i ); | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, B, "matrix addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const u32 n_elem = B.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! matrix addition with different element types | |
| | | template<typename eT1, typename eT2> | |
| | | inline | |
| | | void | |
| | | 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(); | |
| | | | |
| | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "matrix addition"); | |
| | | | |
| | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
| | | out_eT* out_mem = out.memptr(); | |
| | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | | |
| | | // no aliasing problem | |
| | | //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 u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] + B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const Ma | |
| | | t<eT>& C) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_same_size(A, B, "matrix addition"); | |
| | | arma_debug_assert_same_size(A, C, "matrix addition"); | |
| | | | |
| | | // no aliasing problem | |
| | | //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* C_mem = C.mem; | |
| | | | |
| | | const u32 n_elem = A.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] + B_mem[i] + C_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_plus>& X) | |
| | | { | |
| | | glue_plus::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_plus>, | |
| | | Mat<eT>, glue_plus>& X) | |
| | | { | |
| | | glue_plus::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| // possible aliasing cases: | | // possible aliasing cases: | |
| // Q = Q + Q.row(0) -> no problem (aliasing has no effect or incompatible
matrix dimensions). | | // Q = Q + Q.row(0) -> no problem (aliasing has no effect or incompatible
matrix dimensions). | |
| // however, the only time the above will work is when
Q has the same dimensions as Q.row(0), | | // however, the only time the above will work is when
Q has the same dimensions as Q.row(0), | |
| // meaning that doing this addition operation is prett
y silly | | // meaning that doing this addition operation is prett
y silly | |
| // Q = Q + R.row(0) -> no problem | | // Q = Q + R.row(0) -> no problem | |
| // Q = R + Q.row(0) -> output Q is set to size of R, which may destroy inp
ut Q | | // Q = R + Q.row(0) -> output Q is set to size of R, which may destroy inp
ut Q | |
| // | | // | |
| // strategy: | | // strategy: | |
| // if the matrix from the second argument is an alias of the output matrix, | | // if the matrix from the second argument is an alias of the output matrix, | |
| // make a proper matrix out of the second argument | | // make a proper matrix out of the second argument | |
| | | | |
| skipping to change at line 320 | | skipping to change at line 394 | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT> processed_A(X.A); | | const Mat<eT> processed_A(X.A); | |
| const Mat<eT> processed_B(X.B); | | const Mat<eT> processed_B(X.B); | |
| | | | |
| glue_plus::apply(out, processed_A, processed_B); | | glue_plus::apply(out, processed_A, processed_B); | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline void glue_plus::apply_inplace(Mat<eT>& out, const Mat<eT>& B) | | inline | |
| | | void | |
| | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_ | |
| | | square>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X.m); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "matrix addition"); | | arma_debug_assert_same_size(out, B, "matrix addition"); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
|
| const u32 n_elem = B.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] += B_mem[i]; | | const eT tmp_val = B_mem[i]; | |
| | | out_mem[i] += tmp_val*tmp_val; | |
| } | | } | |
|
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_ | |
| | | scalar_times>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X.m); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, B, "matrix addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* B_mem = B.mem; | |
| | | | |
|
| | | const eT k = X.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += k * B_mem[i]; | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_type> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_
type>& X) | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_
scalar_div_pre>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const Mat<eT> tmp(X); | | const unwrap<T1> tmp(X.m); | |
| glue_plus::apply_inplace(out, tmp); | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, A, "matrix addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | | |
| | | const eT k = X.aux; | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += k / A_mem[i]; | |
| | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_
square>& X) | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op_
scalar_div_post>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap<T1> tmp(X.m); | | const unwrap<T1> tmp(X.m); | |
| const Mat<eT>& B = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| arma_debug_assert_same_size(out, B, "matrix addition"); | | arma_debug_assert_same_size(out, A, "matrix addition"); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
|
| const eT* B_mem = B.mem; | | const eT* A_mem = A.mem; | |
| | | | |
|
| | | const eT k = X.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) | |
| { | | { | |
|
| const eT tmp_val = B_mem[i]; | | out_mem[i] += A_mem[i] / k; | |
| out_mem[i] += tmp_val*tmp_val; | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
|
| glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, T
2, glue_type>& X) | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, T
2, glue_plus>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| out = X + out; | | out = X + out; | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
|
| | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<Op<T1 | |
| | | , op_scalar_times>, Op<T2, op_scalar_times>, glue_plus>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp1(X.A.m); | |
| | | const unwrap<T2> tmp2(X.B.m); | |
| | | | |
| | | const Mat<eT>& A = tmp1.M; | |
| | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, A, "matrix addition"); | |
| | | arma_debug_assert_same_size( A, B, "matrix addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | const eT k1 = X.A.aux; | |
| | | const eT k2 = X.B.aux; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += k1*A_mem[i] + k2*B_mem[i]; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2, typename T3> | |
| | | inline | |
| | | void | |
| | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue< Glue | |
| | | < Op<T1, op_scalar_times>, Op<T2, op_scalar_times>, glue_plus>, Op<T3, op_s | |
| | | calar_times>, glue_plus>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp1(X.A.A.m); | |
| | | const unwrap<T2> tmp2(X.A.B.m); | |
| | | const unwrap<T3> tmp3(X.B.m); | |
| | | | |
| | | const Mat<eT>& A = tmp1.M; | |
| | | const Mat<eT>& B = tmp2.M; | |
| | | const Mat<eT>& C = tmp3.M; | |
| | | | |
| | | arma_debug_assert_same_size(out, A, "matrix addition"); | |
| | | arma_debug_assert_same_size( A, B, "matrix addition"); | |
| | | arma_debug_assert_same_size( B, C, "matrix addition"); | |
| | | | |
| | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.mem; | |
| | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
| | | const eT k1 = X.A.A.aux; | |
| | | const eT k2 = X.A.B.aux; | |
| | | const eT k3 = X.B.aux; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] += k1*A_mem[i] + k2*B_mem[i] + k3*C_mem[i]; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, T
2, glue_times>& X) | | glue_plus::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, T
2, glue_times>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap_check<T1> tmp1(X.A, out); | | const unwrap_check<T1> tmp1(X.A, out); | |
| const unwrap_check<T2> tmp2(X.B, out); | | const unwrap_check<T2> tmp2(X.B, out); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| | | | |
| skipping to change at line 908 | | skipping to change at line 1099 | |
| | | | |
| const u32 local_n_elem = A.n_elem; | | const u32 local_n_elem = A.n_elem; | |
| | | | |
| for(u32 i=0; i<local_n_elem; ++i) | | for(u32 i=0; i<local_n_elem; ++i) | |
| { | | { | |
| out_mem[i] = A_mem[i]/k1 + B_mem[i]/k2 + C_mem[i]/k3; | | out_mem[i] = A_mem[i]/k1 + B_mem[i]/k2 + C_mem[i]/k3; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| // | | #endif | |
| // matrix addition with different element types | | | |
| | | | |
| template<typename eT1, typename eT2> | | | |
| inline | | | |
| void | | | |
| 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(); | | | |
| | | | |
| typedef typename promote_type<eT1,eT2>::result out_eT; | | | |
| | | | |
| arma_debug_assert_same_size(X,Y, "matrix addition"); | | | |
| | | | |
| //out.set_size(X.n_rows, X.n_cols); | | | |
| out.copy_size(X); | | | |
| | | | |
| out_eT* out_mem = out.memptr(); | | | |
| const eT1* X_mem = X.mem; | | | |
| const eT2* Y_mem = Y.mem; | | | |
| | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| 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]); | | | |
| } | | | |
| } | | | |
| | | | |
| // | | // | |
| // glue_plus_diag | | // glue_plus_diag | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_plus_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig, c
onst Op<T2,op_diagmat>& B_orig) | | glue_plus_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig, c
onst Op<T2,op_diagmat>& B_orig) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
End of changes. 23 change blocks. |
| 122 lines changed or deleted | | 294 lines changed or added | |
|
| glue_plus_proto.hpp | | glue_plus_proto.hpp | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup glue_plus | | //! \addtogroup glue_plus | |
| //! @{ | | //! @{ | |
| | | | |
| //! Class which implements the immediate addition of matrices, with the res
ult stored in 'Mat' (dense matrix) | | //! Class which implements the immediate addition of matrices, with the res
ult stored in 'Mat' (dense matrix) | |
| class glue_plus | | class glue_plus | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| // mat | | template<typename T1, typename T2> | |
| | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | |
| | | T2, glue_plus>& X); | |
| | | | |
| | | template<typename T1> | |
| | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | T1& X); | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result | |
| | | >& out, const Mat<eT1>& X, const Mat<eT2>& Y); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
); | | inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
, const Mat<eT>& C); | | inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
, const Mat<eT>& C); | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | // mat | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue<Mat<eT>, Mat<eT>, glue_
plus>& X); | | inline static void apply(Mat<eT>& out, const Glue<Mat<eT>, Mat<eT>, glue_
plus>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,g
lue_plus>, Mat<eT>, glue_plus>& X); | | inline static void apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,g
lue_plus>, Mat<eT>, glue_plus>& X); | |
| | | | |
|
| template<typename T1, typename T2> | | | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | | | |
| T2, glue_plus>& X); | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue<Mat<eT>, subview<eT>, g
lue_plus>& X); | | inline static void apply(Mat<eT>& out, const Glue<Mat<eT>, subview<eT>, g
lue_plus>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue<subview<eT>, Mat<eT>, g
lue_plus>& X); | | inline static void apply(Mat<eT>& out, const Glue<subview<eT>, Mat<eT>, g
lue_plus>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue<subview<eT>, subview<eT
>, glue_plus>& X); | | inline static void apply(Mat<eT>& out, const Glue<subview<eT>, subview<eT
>, glue_plus>& X); | |
| | | | |
| // mat, inplace | | // mat, inplace | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline static void apply_inplace(Mat<eT>& out, const Mat<eT>& B); | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | Op<T1, op_square>& X); | |
| | | | |
|
| template<typename T1, typename op_type> | | template<typename T1> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| Op<T1, op_type>& X); | | Op<T1, op_scalar_times>& X); | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| Op<T1, op_square>& X); | | Op<T1, op_scalar_div_pre>& X); | |
| | | | |
| | | template<typename T1> | |
| | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | Op<T1, op_scalar_div_post>& X); | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | Glue<T1, T2, glue_plus>& X); | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | Glue<Op<T1, op_scalar_times>, Op<T2, op_scalar_times>, glue_plus>& X); | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename T3> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| Glue<T1, T2, glue_type>& X); | | Glue< Glue< Op<T1, op_scalar_times>, Op<T2, op_scalar_times>, glue_plus>, O | |
| | | p<T3, op_scalar_times>, glue_plus>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<T1, T2, glue_times>& X); | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<T1, T2, glue_times>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<Op<T1, op_trans>, T2, glue_times>& X); | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<Op<T1, op_trans>, T2, glue_times>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<T1, Op<T2, op_trans>, glue_times>& X); | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<T1, Op<T2, op_trans>, glue_times>& X); | |
| | | | |
| | | | |
| skipping to change at line 111 | | skipping to change at line 128 | |
| | | | |
| template<typename T1, typename T2, typename T3> | | template<typename T1, typename T2, typename T3> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue<Op<T1, op_scalar_div_pre>, Op<T2, op_scalar_div_pre>, glue_plus>, Op<T3,
op_scalar_div_pre>, glue_plus>& in); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue<Op<T1, op_scalar_div_pre>, Op<T2, op_scalar_div_pre>, glue_plus>, Op<T3,
op_scalar_div_pre>, glue_plus>& in); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1, op_scalar_div_post>, Op<T2, op_scalar_div_post>, glue_plus>& in); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1, op_scalar_div_post>, Op<T2, op_scalar_div_post>, glue_plus>& in); | |
| | | | |
| template<typename T1, typename T2, typename T3> | | template<typename T1, typename T2, typename T3> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue<Op<T1, op_scalar_div_post>, Op<T2, op_scalar_div_post>, glue_plus>, Op<T
3, op_scalar_div_post>, glue_plus>& in); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue<Op<T1, op_scalar_div_post>, Op<T2, op_scalar_div_post>, glue_plus>, Op<T
3, op_scalar_div_post>, glue_plus>& in); | |
| | | | |
|
| // matrix addition with different element types | | #endif | |
| | | | |
| template<typename eT1, typename eT2> | | | |
| inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result | | | |
| >& out, const Mat<eT1>& X, const Mat<eT2>& Y); | | | |
| | | | |
| }; | | }; | |
| | | | |
| class glue_plus_diag | | class glue_plus_diag | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const T1& A, c
onst Op<T2,op_diagmat>& B); | | inline static void apply(Mat<typename T1::elem_type>& out, const T1& A, c
onst Op<T2,op_diagmat>& B); | |
| | | | |
| | | | |
End of changes. 8 change blocks. |
| 20 lines changed or deleted | | 40 lines changed or added | |
|
| glue_schur_meat.hpp | | glue_schur_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 glue_schur | | //! \addtogroup glue_schur | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_schur::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix schur product"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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 u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] * B_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_schur::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M | | | |
| at<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_same_size(A, B, "matrix schur product"); | | | |
| arma_debug_assert_same_size(A, C, "matrix schur product"); | | | |
| | | | |
| // no aliasing problem | | | |
| //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* C_mem = C.mem; | | | |
| | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = A_mem[i] * B_mem[i] * C_mem[i]; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_schur::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_schur>& X) | | | |
| { | | | |
| glue_schur::apply(out, X.A, X.B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_schur::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_schur | | | |
| >, Mat<eT>,glue_schur>& X) | | | |
| { | | | |
| glue_schur::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| | | inline | |
| void | | void | |
| glue_schur::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_s
chur>& X) | | glue_schur::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_s
chur>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::nu
m; | | const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::nu
m; | |
| arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | | arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat ); | |
| | | | |
| if(N_mat == 2) | | if(N_mat == 2) | |
| { | | { | |
|
| const unwrap<T1> tmp1(X.A); | | if(is_Mat<T1>::value == false) | |
| const unwrap<T2> tmp2(X.B); | | { | |
| | | out = X.A; | |
| | | glue_schur::apply_inplace(out, X.B); | |
| | | } | |
| | | else | |
| | | if(is_Mat<T2>::value == false) | |
| | | { | |
| | | out = X.B; | |
| | | glue_schur::apply_inplace(out, X.A); | |
| | | } | |
| | | else | |
| | | { | |
| | | const unwrap<T1> tmp1(X.A); | |
| | | const unwrap<T2> tmp2(X.B); | |
| | | | |
|
| glue_schur::apply(out, tmp1.M, tmp2.M); | | glue_schur::apply(out, tmp1.M, tmp2.M); | |
| | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT>* ptrs[N_mat]; | | const Mat<eT>* ptrs[N_mat]; | |
| bool del[N_mat]; | | bool del[N_mat]; | |
| | | | |
| mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X); | | mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X); | |
| //mat_ptrs_outcheck<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs
, del, X, &out); | | //mat_ptrs_outcheck<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs
, del, X, &out); | |
| | | | |
| for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | | for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] ); | |
| | | | |
| skipping to change at line 156 | | skipping to change at line 101 | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | | arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i )
; | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_schur::apply_inplace(Mat<eT>& out, const Mat<eT>& B) | | glue_schur::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& B = tmp.M; | |
| | | | |
| arma_debug_assert_same_size(out, B, "matrix schur product"); | | arma_debug_assert_same_size(out, B, "matrix schur product"); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT* B_mem = B.mem; | | const eT* B_mem = B.mem; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] *= B_mem[i]; | | out_mem[i] *= B_mem[i]; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_type> | | //! matrix schur product with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_schur::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op
_type>& X) | | glue_schur::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_same_size(X,Y, "matrix schur product"); | |
| | | | |
| | | //out.set_size(X.n_rows, X.n_cols); | |
| | | out.copy_size(X); | |
| | | | |
|
| const Mat<eT> tmp(X); | | out_eT* out_mem = out.memptr(); | |
| glue_schur::apply_inplace(out, tmp); | | const eT1* X_mem = X.mem; | |
| | | const eT2* Y_mem = Y.mem; | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | 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]); | |
| | | } | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_schur::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1,
T2, glue_type>& X) | | glue_schur::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // out = X % out; | | arma_debug_assert_same_size(A, B, "matrix schur product"); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | // no aliasing problem | |
| | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
|
| const Mat<eT> tmp(X); | | eT* out_mem = out.memptr(); | |
| glue_schur::apply_inplace(out, tmp); | | const eT* A_mem = A.mem; | |
| } | | const eT* B_mem = B.mem; | |
| | | | |
|
| // | | const u32 n_elem = A.n_elem; | |
| // matrix schur product with different element types | | | |
| | | | |
|
| template<typename eT1, typename eT2> | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A_mem[i] * B_mem[i]; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_schur::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | | glue_schur::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M
at<eT>& C) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | arma_debug_assert_same_size(A, B, "matrix schur product"); | |
| | | arma_debug_assert_same_size(A, C, "matrix schur product"); | |
| arma_debug_assert_same_size(X,Y, "matrix schur product"); | | | |
| | | | |
|
| //out.set_size(X.n_rows, X.n_cols); | | // no aliasing problem | |
| out.copy_size(X); | | //out.set_size(A.n_rows, A.n_cols); | |
| | | out.copy_size(A); | |
| | | | |
|
| out_eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const eT1* X_mem = X.mem; | | const eT* A_mem = A.mem; | |
| const eT2* Y_mem = Y.mem; | | const eT* B_mem = B.mem; | |
| | | const eT* C_mem = C.mem; | |
| | | | |
|
| const u32 n_elem = out.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] = upgrade_val<eT1,eT2>::apply(X_mem[i]) * upgrade_val<eT1,eT
2>::apply(Y_mem[i]); | | out_mem[i] = A_mem[i] * B_mem[i] * C_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_schur::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_schur>& X) | |
| | | { | |
| | | glue_schur::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_schur::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,glue_schur | |
| | | >, Mat<eT>,glue_schur>& X) | |
| | | { | |
| | | glue_schur::apply(out, X.A.A, X.A.B, X.B); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | glue_schur::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1, | |
| | | T2, glue_schur>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | out = X % out; | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| // | | // | |
| // glue_schur_diag | | // glue_schur_diag | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_schur_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | | glue_schur_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
End of changes. 26 change blocks. |
| 103 lines changed or deleted | | 108 lines changed or added | |
|
| glue_times_meat.hpp | | glue_times_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 glue_times | | //! \addtogroup glue_times | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | | |
| arma_inline | | | |
| u32 glue_times::mul_storage_cost(const Mat<eT>& X, const Mat<eT>& Y) | | | |
| { | | | |
| return X.n_rows * Y.n_cols; | | | |
| } | | | |
| | | | |
| //! multiply matrices A and B, storing the result in 'out' | | | |
| //! assumes that A and B are not aliases of 'out' | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_times::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "matrix multiply"); | | | |
| | | | |
| out.set_size(A.n_rows,B.n_cols); | | | |
| gemm<>::apply(out,A,B); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_times::apply(Mat<eT>& out, const Mat<eT>& A_in, const Mat<eT>& B_in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| if( (&out != &A_in) && (&out != &B_in) ) | | | |
| { | | | |
| glue_times::apply_noalias(out,A_in,B_in); | | | |
| } | | | |
| else | | | |
| { | | | |
| | | | |
| if( (&out == &A_in) && (&out != &B_in) ) | | | |
| { | | | |
| Mat<eT> A_copy(A_in); | | | |
| glue_times::apply_noalias(out,A_copy,B_in); | | | |
| } | | | |
| else | | | |
| if( (&out != &A_in) && (&out == &B_in) ) | | | |
| { | | | |
| Mat<eT> B_copy(B_in); | | | |
| glue_times::apply_noalias(out,A_in,B_copy); | | | |
| } | | | |
| else | | | |
| if( (&out == &A_in) && (&out == &B_in) ) | | | |
| { | | | |
| Mat<eT> tmp(A_in); | | | |
| glue_times::apply_noalias(out,tmp,tmp); | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| glue_times::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M | | | |
| at<eT>& C) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "matrix multiply"); | | | |
| arma_debug_assert_mul_size(B, C, "matrix multiply"); | | | |
| | | | |
| if( mul_storage_cost(A,B) <= mul_storage_cost(B,C) ) | | | |
| { | | | |
| Mat<eT> tmp; | | | |
| glue_times::apply_noalias(tmp, A, B); | | | |
| | | | |
| if(&out != &C) | | | |
| { | | | |
| glue_times::apply_noalias(out, tmp, C); | | | |
| } | | | |
| else | | | |
| { | | | |
| Mat<eT> C_copy = C; | | | |
| glue_times::apply_noalias(out, tmp, C_copy); | | | |
| } | | | |
| | | | |
| } | | | |
| else | | | |
| { | | | |
| Mat<eT> tmp; | | | |
| glue_times::apply_noalias(tmp, B, C); | | | |
| | | | |
| if(&out != &A) | | | |
| { | | | |
| glue_times::apply_noalias(out, A, tmp); | | | |
| } | | | |
| else | | | |
| { | | | |
| Mat<eT> A_copy = A; | | | |
| glue_times::apply_noalias(out, A_copy, tmp); | | | |
| } | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| void | | void | |
| glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_t
imes>& X) | | glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_t
imes>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const s32 N_mat = 1 + depth_lhs< glue_times, Glue<T1,T2,glue_times> >::nu
m; | | const s32 N_mat = 1 + depth_lhs< glue_times, Glue<T1,T2,glue_times> >::nu
m; | |
| | | | |
| | | | |
| skipping to change at line 350 | | skipping to change at line 248 | |
| { | | { | |
| if(del[i] == true) | | if(del[i] == true) | |
| { | | { | |
| arma_extra_debug_print(arma_boost::format("delete mat_ptr[%d]") % i
); | | arma_extra_debug_print(arma_boost::format("delete mat_ptr[%d]") % i
); | |
| delete ptrs[i]; | | delete ptrs[i]; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| glue_times::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_times>& X) | | glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
|
| glue_times::apply(out, X.A, X.B); | | arma_extra_debug_sigprint(); | |
| } | | | |
| | | | |
|
| template<typename eT> | | typedef typename T1::elem_type eT; | |
| inline | | | |
| void | | | |
| glue_times::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>, glue_time | | | |
| s>, Mat<eT>, glue_times>& X) | | | |
| { | | | |
| glue_times::apply(out, X.A.A, X.A.B, X.B); | | | |
| } | | | |
| | | | |
|
| template<typename eT> | | const unwrap<T1> tmp(X); | |
| inline | | const Mat<eT>& B = tmp.M; | |
| void | | | |
| glue_times::apply_inplace(Mat<eT>& out, const Mat<eT>& B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_assert_mul_size(out, B, "matrix multiply"); | | arma_debug_assert_mul_size(out, B, "matrix multiply"); | |
| | | | |
| if(out.n_cols == B.n_cols) | | if(out.n_cols == B.n_cols) | |
| { | | { | |
| podarray<eT> tmp(out.n_cols); | | podarray<eT> tmp(out.n_cols); | |
| eT* tmp_rowdata = tmp.memptr(); | | eT* tmp_rowdata = tmp.memptr(); | |
| | | | |
| for(u32 out_row=0; out_row < out.n_rows; ++out_row) | | for(u32 out_row=0; out_row < out.n_rows; ++out_row) | |
| { | | { | |
| | | | |
| skipping to change at line 404 | | skipping to change at line 291 | |
| val += tmp_rowdata[i] * B_coldata[i]; | | val += tmp_rowdata[i] * B_coldata[i]; | |
| } | | } | |
| | | | |
| out.at(out_row,B_col) = val; | | out.at(out_row,B_col) = val; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| Mat<eT> tmp = out; | | const Mat<eT> tmp(out); | |
| glue_times::apply(out, tmp, B); | | glue_times::apply(out, tmp, B); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1, typename op_type> | | //! matrix multiplication with different element types | |
| | | template<typename eT1, typename eT2> | |
| inline | | inline | |
| void | | void | |
|
| glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const Op<T1, op
_type>& X) | | glue_times::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename promote_type<eT1,eT2>::result out_eT; | |
| | | | |
| | | arma_debug_assert_mul_size(X,Y, "matrix multiply"); | |
| | | | |
|
| const Mat<eT> tmp(X); | | out.set_size(X.n_rows,Y.n_cols); | |
| glue_times::apply(out, out, tmp); | | gemm_mixed<>::apply(out, X, Y); | |
| } | | } | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> | |
| | | arma_inline | |
| | | u32 glue_times::mul_storage_cost(const Mat<eT>& X, const Mat<eT>& Y) | |
| | | { | |
| | | return X.n_rows * Y.n_cols; | |
| | | } | |
| | | | |
| | | //! multiply matrices A and B, storing the result in 'out' | |
| | | //! assumes that A and B are not aliases of 'out' | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_times::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_mul_size(A, B, "matrix multiply"); | |
| | | | |
| | | out.set_size(A.n_rows,B.n_cols); | |
| | | gemm<>::apply(out,A,B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_times::apply(Mat<eT>& out, const Mat<eT>& A_in, const Mat<eT>& B_in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if( (&out != &A_in) && (&out != &B_in) ) | |
| | | { | |
| | | glue_times::apply_noalias(out,A_in,B_in); | |
| | | } | |
| | | else | |
| | | { | |
| | | | |
| | | if( (&out == &A_in) && (&out != &B_in) ) | |
| | | { | |
| | | Mat<eT> A_copy(A_in); | |
| | | glue_times::apply_noalias(out,A_copy,B_in); | |
| | | } | |
| | | else | |
| | | if( (&out != &A_in) && (&out == &B_in) ) | |
| | | { | |
| | | Mat<eT> B_copy(B_in); | |
| | | glue_times::apply_noalias(out,A_in,B_copy); | |
| | | } | |
| | | else | |
| | | if( (&out == &A_in) && (&out == &B_in) ) | |
| | | { | |
| | | Mat<eT> tmp(A_in); | |
| | | glue_times::apply_noalias(out,tmp,tmp); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_times::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M | |
| | | at<eT>& C) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_assert_mul_size(A, B, "matrix multiply"); | |
| | | arma_debug_assert_mul_size(B, C, "matrix multiply"); | |
| | | | |
| | | if( mul_storage_cost(A,B) <= mul_storage_cost(B,C) ) | |
| | | { | |
| | | Mat<eT> tmp; | |
| | | glue_times::apply_noalias(tmp, A, B); | |
| | | | |
| | | if(&out != &C) | |
| | | { | |
| | | glue_times::apply_noalias(out, tmp, C); | |
| | | } | |
| | | else | |
| | | { | |
| | | Mat<eT> C_copy = C; | |
| | | glue_times::apply_noalias(out, tmp, C_copy); | |
| | | } | |
| | | | |
| | | } | |
| | | else | |
| | | { | |
| | | Mat<eT> tmp; | |
| | | glue_times::apply_noalias(tmp, B, C); | |
| | | | |
| | | if(&out != &A) | |
| | | { | |
| | | glue_times::apply_noalias(out, A, tmp); | |
| | | } | |
| | | else | |
| | | { | |
| | | Mat<eT> A_copy = A; | |
| | | glue_times::apply_noalias(out, A_copy, tmp); | |
| | | } | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | glue_times::direct_rowvec_mat_colvec | |
| | | ( | |
| | | const eT* A_mem, | |
| | | const Mat<eT>& B, | |
| | | const eT* C_mem | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 cost_AB = B.n_cols; | |
| | | const u32 cost_BC = B.n_rows; | |
| | | | |
| | | if(cost_AB <= cost_BC) | |
| | | { | |
| | | podarray<eT> tmp(B.n_cols); | |
| | | | |
| | | for(u32 col=0; col<B.n_cols; ++col) | |
| | | { | |
| | | const eT* B_coldata = B.colptr(col); | |
| | | | |
| | | eT val = eT(0); | |
| | | for(u32 i=0; i<B.n_rows; ++i) | |
| | | { | |
| | | val += A_mem[i] * B_coldata[i]; | |
| | | } | |
| | | | |
| | | tmp[col] = val; | |
| | | } | |
| | | | |
| | | return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem); | |
| | | } | |
| | | else | |
| | | { | |
| | | podarray<eT> tmp(B.n_rows); | |
| | | | |
| | | for(u32 row=0; row<B.n_rows; ++row) | |
| | | { | |
| | | eT val = eT(0); | |
| | | for(u32 col=0; col<B.n_cols; ++col) | |
| | | { | |
| | | val += B.at(row,col) * C_mem[col]; | |
| | | } | |
| | | | |
| | | tmp[row] = val; | |
| | | } | |
| | | | |
| | | return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | glue_times::direct_rowvec_diagmat_colvec | |
| | | ( | |
| | | const eT* A_mem, | |
| | | const Mat<eT>& B, | |
| | | const eT* C_mem | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | eT val = eT(0); | |
| | | | |
| | | for(u32 i=0; i<B.n_rows; ++i) | |
| | | { | |
| | | val += A_mem[i] * B.at(i,i) * C_mem[i]; | |
| | | } | |
| | | | |
| | | return val; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | glue_times::direct_rowvec_invdiagmat_colvec | |
| | | ( | |
| | | const eT* A_mem, | |
| | | const Mat<eT>& B, | |
| | | const eT* C_mem | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | eT val = eT(0); | |
| | | | |
| | | for(u32 i=0; i<B.n_rows; ++i) | |
| | | { | |
| | | val += (A_mem[i] * C_mem[i]) / B.at(i,i); | |
| | | } | |
| | | | |
| | | return val; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | glue_times::direct_rowvec_invdiagvec_colvec | |
| | | ( | |
| | | const eT* A_mem, | |
| | | const Mat<eT>& B, | |
| | | const eT* C_mem | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const eT* B_mem = B.mem; | |
| | | | |
| | | eT val = eT(0); | |
| | | | |
| | | for(u32 i=0; i<B.n_elem; ++i) | |
| | | { | |
| | | val += (A_mem[i] * C_mem[i]) / B_mem[i]; | |
| | | } | |
| | | | |
| | | return val; | |
| | | } | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | glue_times::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_times>& X) | |
| | | { | |
| | | glue_times::apply(out, X.A, X.B); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1,
T2, glue_type>& X) | | glue_times::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>, glue_time
s>, Mat<eT>, glue_times>& X) | |
| { | | { | |
|
| arma_extra_debug_sigprint(); | | glue_times::apply(out, X.A.A, X.A.B, X.B); | |
| | | | |
| out = out * X; | | | |
| } | | } | |
| | | | |
| //! out = T1 * trans(T2) | | //! out = T1 * trans(T2) | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Op<T2,op
_trans>, glue_times>& X) | | glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Op<T2,op
_trans>, glue_times>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 581 | | skipping to change at line 703 | |
| | | | |
| glue_times::apply(out, A, B); | | glue_times::apply(out, A, B); | |
| | | | |
| 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[i] = -out[i]; | | out[i] = -out[i]; | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename T1, typename T2> | |
| inline | | | |
| eT | | | |
| glue_times::direct_rowvec_mat_colvec | | | |
| ( | | | |
| const eT* A_mem, | | | |
| const Mat<eT>& B, | | | |
| const eT* C_mem | | | |
| ) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const u32 cost_AB = B.n_cols; | | | |
| const u32 cost_BC = B.n_rows; | | | |
| | | | |
| if(cost_AB <= cost_BC) | | | |
| { | | | |
| podarray<eT> tmp(B.n_cols); | | | |
| | | | |
| for(u32 col=0; col<B.n_cols; ++col) | | | |
| { | | | |
| const eT* B_coldata = B.colptr(col); | | | |
| | | | |
| eT val = eT(0); | | | |
| for(u32 i=0; i<B.n_rows; ++i) | | | |
| { | | | |
| val += A_mem[i] * B_coldata[i]; | | | |
| } | | | |
| | | | |
| tmp[col] = val; | | | |
| } | | | |
| | | | |
| return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem); | | | |
| } | | | |
| else | | | |
| { | | | |
| podarray<eT> tmp(B.n_rows); | | | |
| | | | |
| for(u32 row=0; row<B.n_rows; ++row) | | | |
| { | | | |
| eT val = eT(0); | | | |
| for(u32 col=0; col<B.n_cols; ++col) | | | |
| { | | | |
| val += B.at(row,col) * C_mem[col]; | | | |
| } | | | |
| | | | |
| tmp[row] = val; | | | |
| } | | | |
| | | | |
| return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem); | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| eT | | | |
| glue_times::direct_rowvec_diagmat_colvec | | | |
| ( | | | |
| const eT* A_mem, | | | |
| const Mat<eT>& B, | | | |
| const eT* C_mem | | | |
| ) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| eT val = eT(0); | | | |
| | | | |
| for(u32 i=0; i<B.n_rows; ++i) | | | |
| { | | | |
| val += A_mem[i] * B.at(i,i) * C_mem[i]; | | | |
| } | | | |
| | | | |
| return val; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| eT | | | |
| glue_times::direct_rowvec_invdiagmat_colvec | | | |
| ( | | | |
| const eT* A_mem, | | | |
| const Mat<eT>& B, | | | |
| const eT* C_mem | | | |
| ) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| eT val = eT(0); | | | |
| | | | |
| for(u32 i=0; i<B.n_rows; ++i) | | | |
| { | | | |
| val += (A_mem[i] * C_mem[i]) / B.at(i,i); | | | |
| } | | | |
| | | | |
| return val; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| eT | | | |
| glue_times::direct_rowvec_invdiagvec_colvec | | | |
| ( | | | |
| const eT* A_mem, | | | |
| const Mat<eT>& B, | | | |
| const eT* C_mem | | | |
| ) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const eT* B_mem = B.mem; | | | |
| | | | |
| eT val = eT(0); | | | |
| | | | |
| for(u32 i=0; i<B.n_elem; ++i) | | | |
| { | | | |
| val += (A_mem[i] * C_mem[i]) / B_mem[i]; | | | |
| } | | | |
| | | | |
| return val; | | | |
| } | | | |
| | | | |
| // | | | |
| // matrix multiplication with different element types | | | |
| | | | |
| template<typename eT1, typename eT2> | | | |
| inline | | inline | |
| void | | void | |
|
| glue_times::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
onst Mat<eT1>& X, const Mat<eT2>& Y) | | glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1,
T2, glue_times>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename promote_type<eT1,eT2>::result out_eT; | | out = out * X; | |
| | | | |
| arma_debug_assert_mul_size(X,Y, "matrix multiply"); | | | |
| | | | |
| out.set_size(X.n_rows,Y.n_cols); | | | |
| gemm_mixed<>::apply(out, X, Y); | | | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| // | | // | |
| // glue_times_diag | | // glue_times_diag | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| void | | void | |
| glue_times_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | | glue_times_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 853 | | skipping to change at line 847 | |
| inline | | inline | |
| void | | void | |
| glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1,o
p_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X) | | glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1,o
p_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X) | |
| { | | { | |
| glue_times_diag::apply(out, X.A, X.B); | | glue_times_diag::apply(out, X.A, X.B); | |
| } | | } | |
| | | | |
| // | | // | |
| // glue_times_vec | | // glue_times_vec | |
| | | | |
|
| | | //! at least one of T1 and T2 is a vector (both could be vectors) | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, | |
| | | glue_times_vec>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | unwrap_check<T1> tmp1(X.A, out); | |
| | | unwrap_check<T2> tmp2(X.B, out); | |
| | | | |
| | | const Mat<eT>& A = tmp1.M; | |
| | | const Mat<eT>& B = tmp2.M; | |
| | | | |
| | | arma_debug_assert_mul_size(A, B, "vector multiply"); | |
| | | | |
| | | // col * row --> outer product | |
| | | // mat * row --> only makes sense if mat is a col vector, hence equiv to | |
| | | col * row | |
| | | // col * mat --> only makes sense if mat is a row vector, hence equiv to | |
| | | col * row | |
| | | | |
| | | // row * col --> dot product | |
| | | // row * mat --> ok | |
| | | | |
| | | // mat * col --> ok | |
| | | | |
| | | out.set_size(A.n_rows, B.n_cols); | |
| | | | |
| | | if(A.n_cols == 1) // A is a column vector | |
| | | { | |
| | | glue_times_vec::mul_col_row(out, A.mem, B.mem); | |
| | | } | |
| | | else | |
| | | { | |
| | | if(A.n_rows == 1) // A is a row vector | |
| | | { | |
| | | if(B.n_cols == 1) | |
| | | { | |
| | | out[0] = op_dot::direct_dot(A.n_elem, A.mem, B.mem); | |
| | | } | |
| | | else | |
| | | { | |
| | | gemv<true>::apply(out.memptr(), B, A.mem); | |
| | | } | |
| | | } | |
| | | else // A is a matrix | |
| | | { | |
| | | gemv<>::apply(out.memptr(), A, B.mem); | |
| | | } | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| glue_times_vec::mul_col_row(Mat<eT>& out, const eT* A, const eT* B) | | glue_times_vec::mul_col_row(Mat<eT>& out, const eT* A, const eT* B) | |
| { | | { | |
| const u32 n_rows = out.n_rows; | | const u32 n_rows = out.n_rows; | |
| const u32 n_cols = out.n_cols; | | const u32 n_cols = out.n_cols; | |
| | | | |
| for(u32 col=0; col < n_cols; ++col) | | for(u32 col=0; col < n_cols; ++col) | |
| { | | { | |
| | | | |
| skipping to change at line 897 | | skipping to change at line 945 | |
| eT* out_coldata = out.colptr(col); | | eT* out_coldata = out.colptr(col); | |
| | | | |
| for(u32 row=0; row < n_rows; ++row) | | for(u32 row=0; row < n_rows; ++row) | |
| { | | { | |
| out_coldata[row] += A[row] * val; | | out_coldata[row] += A[row] * val; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T1> | | #if defined(ARMA_GOOD_COMPILER) | |
| inline | | | |
| void | | | |
| glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Col< | | | |
| typename T1::elem_type>,glue_times_vec>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| unwrap_check< T1 > tmp1(X.A, out); | | | |
| unwrap_check< Col<eT> > tmp2(X.B, out); | | | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | | |
| const Col<eT>& B = tmp2.M; | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "vector multiply"); | | | |
| | | | |
| out.set_size(A.n_rows, 1); | | | |
| | | | |
| //gemm<>::apply(out,A,B); // NOTE: B is interpreted as a Mat | | | |
| gemv<>::apply(out.memptr(), A, B.mem); | | | |
| } | | | |
| | | | |
| template<typename T1> | | | |
| inline | | | |
| void | | | |
| glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Row< | | | |
| typename T1::elem_type>,glue_times_vec>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| // T1 * rowvec makes sense only if T1 ends up being a matrix with one col | | | |
| umn (i.e. a column vector) | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| unwrap_check< T1 > tmp1(X.A, out); | | | |
| unwrap_check< Row<eT> > tmp2(X.B, out); | | | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | | |
| const Mat<eT>& B = tmp2.M; // NOTE: interpretation of a Row as a Mat | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "vector multiply"); | | | |
| | | | |
| out.set_size(A.n_rows, B.n_cols); | | | |
| | | | |
| glue_times_vec::mul_col_row(out, A.mem, B.mem); | | | |
| } | | | |
| | | | |
| template<typename T1> | | | |
| inline | | | |
| void | | | |
| glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<Col<type | | | |
| name T1::elem_type>,T1,glue_times_vec>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| // colvec * T1 makes sense only if T1 ends up being a matrix with one row | | | |
| (i.e. a row vector) | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| unwrap_check< Col<eT> > tmp1(X.A, out); | | | |
| unwrap_check< T1 > tmp2(X.B, out); | | | |
| | | | |
| const Mat<eT>& A = tmp1.M; // NOTE: interpretation of a Col as a Mat | | | |
| const Mat<eT>& B = tmp2.M; | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "vector multiply"); | | | |
| | | | |
| out.set_size(A.n_rows, B.n_cols); | | | |
| | | | |
| glue_times_vec::mul_col_row(out, A.mem, B.mem); | | | |
| } | | | |
| | | | |
| template<typename T1> | | | |
| inline | | | |
| void | | | |
| glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<Row<type | | | |
| name T1::elem_type>,T1,glue_times_vec>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| unwrap_check< Row<eT> > tmp1(X.A, out); | | | |
| unwrap_check< T1 > tmp2(X.B, out); | | | |
| | | | |
| const Row<eT>& A = tmp1.M; | | | |
| const Mat<eT>& B = tmp2.M; | | | |
| | | | |
| arma_debug_assert_mul_size(A, B, "vector multiply"); | | | |
| | | | |
| out.set_size(A.n_rows, B.n_cols); | | | |
| | | | |
| // eT* out_mem = out.memptr(); | | | |
| // const eT* A_mem = A.mem; | | | |
| // | | | |
| // const u32 A_n_cols = A.n_cols; | | | |
| // const u32 B_n_cols = B.n_cols; | | | |
| // | | | |
| // for(u32 col=0; col<B_n_cols; ++col) | | | |
| // { | | | |
| // const eT* B_coldata = B.colptr(col); | | | |
| // | | | |
| // eT val = eT(0); | | | |
| // for(u32 i=0; i<A_n_cols; ++i) | | | |
| // { | | | |
| // val += A_mem[i] * B_coldata[i]; | | | |
| // } | | | |
| // | | | |
| // out_mem[col] = val; | | | |
| // } | | | |
| | | | |
| gemv<true>::apply(out.memptr(), B, A.mem); | | | |
| } | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| glue_times_vec::apply(Mat<eT>& out, const Glue<Col<eT>,Row<eT>,glue_times_v
ec>& X) | | glue_times_vec::apply(Mat<eT>& out, const Glue<Col<eT>,Row<eT>,glue_times_v
ec>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| unwrap_check< Col<eT> > tmp1(X.A, out); | | unwrap_check< Col<eT> > tmp1(X.A, out); | |
| unwrap_check< Row<eT> > tmp2(X.B, out); | | unwrap_check< Row<eT> > tmp2(X.B, out); | |
| | | | |
| skipping to change at line 1078 | | skipping to change at line 1016 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1, o
p_trans>, Col<typename T1::elem_type>,glue_times_vec>& X) | | glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1, o
p_trans>, Col<typename T1::elem_type>,glue_times_vec>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| unwrap_check< T1 > tmp1(X.A.m, out); | | unwrap_check< T1 > tmp1(X.A.m, out); | |
| unwrap_check< Col<eT> > tmp2(X.B, out); | | unwrap_check< Col<eT> > tmp2(X.B, out); | |
| | | | |
| const Mat<eT>& A = tmp1.M; | | const Mat<eT>& A = tmp1.M; | |
| const Col<eT>& B = tmp2.M; | | const Col<eT>& B = tmp2.M; | |
| | | | |
| arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_rows, B.n_cols, "vecto
r multiply"); | | arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_rows, B.n_cols, "vecto
r multiply"); | |
| | | | |
| out.set_size(A.n_cols, B.n_cols); | | out.set_size(A.n_cols, B.n_cols); | |
| | | | |
| // eT* out_mem = out.memptr(); | | // eT* out_mem = out.memptr(); | |
| | | | |
| skipping to change at line 1110 | | skipping to change at line 1048 | |
| // { | | // { | |
| // val += A_col[row] * B_mem[row]; | | // val += A_col[row] * B_mem[row]; | |
| // } | | // } | |
| // | | // | |
| // out_mem[col] = val; | | // out_mem[col] = val; | |
| // } | | // } | |
| | | | |
| gemv<true>::apply(out.memptr(), A, B.mem); | | gemv<true>::apply(out.memptr(), A, B.mem); | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 22 change blocks. |
| 383 lines changed or deleted | | 319 lines changed or added | |
|
| glue_times_proto.hpp | | glue_times_proto.hpp | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup glue_times | | //! \addtogroup glue_times | |
| //! @{ | | //! @{ | |
| | | | |
| //! Class which implements the immediate multiplication of two or more matr
ices | | //! Class which implements the immediate multiplication of two or more matr
ices | |
| class glue_times | | class glue_times | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | |
| | | T2,glue_times>& X); | |
| | | | |
| | | template<typename T1> | |
| | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| | | T1& X); | |
| | | | |
| | | template<typename eT1, typename eT2> | |
| | | inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result | |
| | | >& out, const Mat<eT1>& X, const Mat<eT2>& Y); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline static u32 mul_storage_cost(const Mat<eT>& X, const Mat<eT>&
Y); | | arma_inline static u32 mul_storage_cost(const Mat<eT>& X, const Mat<eT>&
Y); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Ma
t<eT>& B); | | inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Ma
t<eT>& B); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
); | | inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
, const Mat<eT>& C); | | inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
, const Mat<eT>& C); | |
| | | | |
|
| template<typename T1, typename T2> | | template<typename eT> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | | inline static eT direct_rowvec_mat_colvec(const eT* A_mem, const Mat<eT>& | |
| T2,glue_times>& X); | | B, const eT* C_mem); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| inline static void apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_ti
mes>& X); | | inline static eT direct_rowvec_diagmat_colvec(const eT* A_mem, const Mat<
eT>& B, const eT* C_mem); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| inline static void apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,
glue_times>, Mat<eT>, glue_times>& X); | | inline static eT direct_rowvec_invdiagmat_colvec(const eT* A_mem, const M
at<eT>& B, const eT* C_mem); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| inline static void apply_inplace(Mat<eT>& out, const Mat<eT>& B); | | inline static eT direct_rowvec_invdiagvec_colvec(const eT* A_mem, const M | |
| | | at<eT>& B, const eT* C_mem); | |
| | | | |
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
|
| template<typename T1, typename op_type> | | template<typename eT> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | | inline static void apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_ti | |
| Op<T1, op_type>& X); | | mes>& X); | |
| | | | |
|
| template<typename T1, typename T2, typename glue_type> | | template<typename eT> | |
| inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | | inline static void apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>, | |
| Glue<T1, T2, glue_type>& X); | | glue_times>, Mat<eT>, glue_times>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
Op<T2,op_trans>,glue_times >& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
Op<T2,op_trans>,glue_times >& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,T2,glue_times>& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,T2,glue_times>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,Op<T2,op_trans>,glue_times>& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,Op<T2,op_trans>,glue_times>& X); | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Op
<T1, op_neg>, T2, glue_times>& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Op
<T1, op_neg>, T2, glue_times>& X); | |
| | | | |
|
| template<typename eT> | | template<typename T1, typename T2> | |
| inline static eT direct_rowvec_mat_colvec(const eT* A_mem, const Mat<eT>& | | inline static void apply_inplace(Mat<typename T1::elem_type>& out, const | |
| B, const eT* C_mem); | | Glue<T1, T2, glue_times>& X); | |
| | | | |
| template<typename eT> | | | |
| inline static eT direct_rowvec_diagmat_colvec(const eT* A_mem, const Mat< | | | |
| eT>& B, const eT* C_mem); | | | |
| | | | |
| template<typename eT> | | | |
| inline static eT direct_rowvec_invdiagmat_colvec(const eT* A_mem, const M | | | |
| at<eT>& B, const eT* C_mem); | | | |
| | | | |
| template<typename eT> | | | |
| inline static eT direct_rowvec_invdiagvec_colvec(const eT* A_mem, const M | | | |
| at<eT>& B, const eT* C_mem); | | | |
| | | | |
|
| // matrix multiplication with different element types | | #endif | |
| | | | |
| template<typename eT1, typename eT2> | | | |
| inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result | | | |
| >& out, const Mat<eT1>& X, const Mat<eT2>& Y); | | | |
| | | | |
| }; | | }; | |
| | | | |
| class glue_times_diag | | class glue_times_diag | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const T1& A, c
onst Op<T2,op_diagmat>& B); | | inline static void apply(Mat<typename T1::elem_type>& out, const T1& A, c
onst Op<T2,op_diagmat>& B); | |
| | | | |
| | | | |
| skipping to change at line 112 | | skipping to change at line 111 | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X); | |
| | | | |
| }; | | }; | |
| | | | |
| class glue_times_vec | | class glue_times_vec | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | |
| | | T2, glue_times_vec>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void mul_col_row(Mat<eT>& out, const eT* A_mem, const eT* B
_mem); | | inline static void mul_col_row(Mat<eT>& out, const eT* A_mem, const eT* B
_mem); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void mul_col_row_inplace_add(Mat<eT>& out, const eT* A_mem,
const eT* B_mem); | | inline static void mul_col_row_inplace_add(Mat<eT>& out, const eT* A_mem,
const eT* B_mem); | |
| | | | |
|
| template<typename T1> | | #if defined(ARMA_GOOD_COMPILER) | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | | | |
| Col<typename T1::elem_type>, glue_times_vec>& X); | | | |
| | | | |
| template<typename T1> | | | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, | | | |
| Row<typename T1::elem_type>, glue_times_vec>& X); | | | |
| | | | |
| template<typename T1> | | | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Col | | | |
| <typename T1::elem_type>, T1, glue_times_vec>& X); | | | |
| | | | |
| template<typename T1> | | | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Row | | | |
| <typename T1::elem_type>, T1, glue_times_vec>& X); | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue<Col<eT>, Row<eT>, glue_
times_vec>& X); | | inline static void apply(Mat<eT>& out, const Glue<Col<eT>, Row<eT>, glue_
times_vec>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue< Op<Row<eT>, op_trans>,
Row<eT>, glue_times_vec>& X); | | inline static void apply(Mat<eT>& out, const Glue< Op<Row<eT>, op_trans>,
Row<eT>, glue_times_vec>& X); | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline static void apply(Mat<eT>& out, const Glue< Col<eT>, Op<Col<eT>, o
p_trans>, glue_times_vec>& X); | | inline static void apply(Mat<eT>& out, const Glue< Col<eT>, Op<Col<eT>, o
p_trans>, glue_times_vec>& X); | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1, op_trans>, Col<typename T1::elem_type>, glue_times_vec>& X); | | inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1, op_trans>, Col<typename T1::elem_type>, glue_times_vec>& X); | |
| | | | |
|
| | | #endif | |
| | | | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 12 change blocks. |
| 47 lines changed or deleted | | 38 lines changed or added | |
|
| op_misc_meat.hpp | | op_misc_meat.hpp | |
| | | | |
| skipping to change at line 27 | | skipping to change at line 27 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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_mem[i] = std::log(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_log>& i
n) | | op_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_log>& i
n) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = std::log(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| const Mat<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.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) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_ptr[i] = trunc_log(A.mem[i]); | | out_mem[i] = trunc_log(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_trunc_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t
runc_log>& in) | | op_trunc_log::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t
runc_log>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = trunc_log(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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_mem[i] = std::log10(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_log10::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_log10
>& in) | | op_log10::apply(Cube<typename T1::elem_type>& out, const OpCube<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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = std::log10(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_exp::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_exp>& in) | | op_exp::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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_mem[i] = std::exp(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_exp>& i
n) | | op_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_exp>& i
n) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = std::exp(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| const Mat<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.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) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_ptr[i] = trunc_exp(A.mem[i]); | | out_mem[i] = trunc_exp(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_trunc_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t
runc_exp>& in) | | op_trunc_exp::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_t
runc_exp>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = trunc_exp(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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_mem[i] = std::sqrt(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_sqrt::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_sqrt>&
in) | | op_sqrt::apply(Cube<typename T1::elem_type>& out, const OpCube<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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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_mem[i] = std::sqrt(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_square::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_square>&
in) | | op_square::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_square>&
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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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 val = A_mem[i]; | |
| out_ptr[i] = tmp_val*tmp_val; | | out_mem[i] = val*val; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_square::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_squa
re>& in) | | op_square::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_squa
re>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| out.copy_size(A); | | | |
| | | | |
| 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 val = A_mem[i]; | |
| out_ptr[i] = tmp_val*tmp_val; | | out_mem[i] = val*val; | |
| } | | } | |
|
| | | } | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | T1 | |
| | | op_pow::internal_pow(const T1 base, const T2 exponent) | |
| | | { | |
| | | return std::pow(base, exponent); | |
| | | } | |
| | | | |
| | | template<typename T2> | |
| | | inline | |
| | | char | |
| | | op_pow::internal_pow(const char base, const T2 exponent) | |
| | | { | |
| | | typedef char out_type; | |
| | | return out_type( std::pow(double(base), exponent) ); | |
| | | } | |
| | | | |
| | | template<typename T2> | |
| | | inline | |
| | | unsigned char | |
| | | op_pow::internal_pow(const unsigned char base, const T2 exponent) | |
| | | { | |
| | | typedef unsigned char out_type; | |
| | | return out_type( std::pow(double(base), exponent) ); | |
| | | } | |
| | | | |
| | | template<typename T2> | |
| | | inline | |
| | | int | |
| | | op_pow::internal_pow(const int base, const T2 exponent) | |
| | | { | |
| | | typedef int out_type; | |
| | | return out_type( std::pow(double(base), exponent) ); | |
| | | } | |
| | | | |
| | | template<typename T2> | |
| | | inline | |
| | | unsigned int | |
| | | op_pow::internal_pow(const unsigned int base, const T2 exponent) | |
| | | { | |
| | | typedef unsigned int out_type; | |
| | | return out_type( std::pow(double(base), exponent) ); | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| op_pow::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pow>& in) | | op_pow::apply(Mat<typename T1::pod_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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const Mat<eT>& A = tmp.M; | | | |
| const u32 n_elem = A.n_elem; | | | |
| | | | |
|
| //out.set_size(A.n_rows, A.n_cols); | | eT* out_mem = out.memptr(); | |
| out.copy_size(A); | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| 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_mem[i] = std::pow(A_mem[i], in.aux); | |
| | | out_mem[i] = op_pow::internal_pow(A_mem[i], in.aux); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| op_pow::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_pow>& i
n) | | op_pow::apply(Cube<typename T1::pod_type>& out, const OpCube<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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(in.m); | |
| | | const Cube<eT>& A = tmp.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); | | eT* out_mem = out.memptr(); | |
| out.copy_size(A); | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| 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_mem[i] = std::pow(A_mem[i], in.aux); | |
| | | out_mem[i] = op_pow::internal_pow(A_mem[i], in.aux); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| template<typename T, typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| op_pow::apply(Mat< std::complex<T> >& out, const Op<T1,op_pow>& in) | | op_pow::apply(Mat< std::complex<typename T1::pod_type> >& out, const Op<T1,
op_pow>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef std::complex<T> eT; | | typedef typename T1::pod_type T; | |
| | | 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); | | 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(); | |
| | | | |
| | | | |
| skipping to change at line 475 | | skipping to change at line 460 | |
| } | | } | |
| else | | else | |
| { | | { | |
| 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 T1> | |
| inline | | inline | |
| void | | void | |
|
| op_pow::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_pow>& in) | | op_pow::apply(Cube< std::complex<typename T1::pod_type> >& out, const OpCub
e<T1,op_pow>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef std::complex<T> eT; | | typedef typename T1::pod_type T; | |
| | | 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_cube<T1> tmp(in.m); | | const unwrap_cube<T1> tmp(in.m); | |
| | | | |
| const Cube<eT>& A = tmp.M; | | const Cube<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, A.n_slices); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| out.copy_size(A); | | out.copy_size(A); | |
| | | | |
| skipping to change at line 563 | | skipping to change at line 549 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| 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_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
|
| const Mat<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.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; | | 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 | | //out_mem[i] = std::pow(A_mem[i], exponent); // causes problems with g | |
| cc 4.1/4.2 for base that has an integer type | | 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_mem[i] = op_pow_s32::internal_pow(A_mem[i], exponent); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_pow_s32::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_pow
_s32>& in) | | op_pow_s32::apply(Cube<typename T1::elem_type>& out, const OpCube<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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const Cube<eT>& A = tmp.M; | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = A.n_elem; | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| //out.set_size(A.n_rows, A.n_cols, A.n_slices); | | | |
| 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; | | 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 | | //out_mem[i] = std::pow(A_mem[i], exponent); // causes problems with g | |
| cc 4.1/4.2 for base that has an integer type | | 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_mem[i] = op_pow_s32::internal_pow(A_mem[i], exponent); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_conj::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_conj>& in) | | op_conj::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_conj>& in) | |
| { | | { | |
| 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(); | | const unwrap_write<T1> tmp(out, in.m); | |
| | | const Mat<eT>& A = tmp.M; | |
| const unwrap<T1> tmp(in.m); | | | |
| | | | |
| const Mat<eT>& A = tmp.M; | | | |
| 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(); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| 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_mem[i] = std::conj(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_conj::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_conj>&
in) | | op_conj::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_conj>&
in) | |
| { | | { | |
| 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(); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | eT* out_mem = out.memptr(); | |
| | | const eT* A_mem = A.memptr(); | |
| const Cube<eT>& A = tmp.M; | | const u32 n_elem = out.n_elem; | |
| 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(); | | | |
| | | | |
| 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_mem[i] = std::conj(A_mem[i]); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 86 change blocks. |
| 214 lines changed or deleted | | 182 lines changed or added | |
|
| op_scalar_misc_meat.hpp | | op_scalar_misc_meat.hpp | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| //! Add a scalar to all elements of a 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // no alias problems | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] + k; | | out_mem[i] = A_mem[i] + k; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! Add a scalar to all elements of a cube | | //! Add a scalar to all elements of a cube | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_plus::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op
_scalar_plus>& in) | | op_scalar_plus::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op
_scalar_plus>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] + k; | | out_mem[i] = A_mem[i] + k; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! For each element of a matrix, subtract it from a scalar | | //! 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // no alias problems | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = k - X_mem[i]; | | out_mem[i] = k - A_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! For each element of a cube, subtract it from a scalar | | //! For each element of a cube, subtract it from a scalar | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_minus_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<
T1,op_scalar_minus_pre>& in) | | op_scalar_minus_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<
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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = k - X_mem[i]; | | out_mem[i] = k - A_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! subtract a scalar from each element of a matrix | | //! subtract a scalar from each element of a matrix | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // no alias problems | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] - k; | | out_mem[i] = A_mem[i] - k; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! subtract a scalar from each element of a cube | | //! subtract a scalar from each element of a cube | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_minus_post::apply(Cube<typename T1::elem_type>& out, const OpCube
<T1,op_scalar_minus_post>& in) | | op_scalar_minus_post::apply(Cube<typename T1::elem_type>& out, const OpCube
<T1,op_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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i<X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] - k; | | out_mem[i] = A_mem[i] - k ; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! Multiply all elements of a matrix by a scalar | | //! 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // no alias problems | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] * k; | | out_mem[i] = A_mem[i] * k; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! Multiply all elements of a cube by a scalar | | //! Multiply all elements of a cube by a scalar | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,o
p_scalar_times>& in) | | op_scalar_times::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,o
p_scalar_times>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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* A_mem = A.memptr(); | |
| const eT k = in.aux; | | | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = X_mem[i] * k; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| //! Evaluate Glue<T1,T2,glue_type>, and then multiply each element of the r | | | |
| esult by a scalar. | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| void | | | |
| 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(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| out = in.m; // implicit conversion to 'Mat<eT>' | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| const eT k = in.aux; | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
|
| | | const eT k = in.aux; | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] *= k; | | out_mem[i] = A_mem[i] * k; | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! Evaluate GlueCube<T1,T2,glue_type>, and then multiply each element of t | | #if defined(ARMA_GOOD_COMPILER) | |
| 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. | |
| 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); | |
| | | | |
| skipping to change at line 502 | | skipping to change at line 428 | |
| 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; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // TODO: analyse effects of aliasing | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = k / X_mem[i]; | | out_mem[i] = k / A_mem[i]; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<T1
,op_scalar_div_pre>& in) | | op_scalar_div_pre::apply(Cube<typename T1::elem_type>& out, const OpCube<T1
,op_scalar_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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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(); | | | |
| 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 eT> | | | |
| inline | | | |
| void | | | |
| op_scalar_div_pre::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_pre>& | | | |
| in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const Mat<eT>& X = in.m; | | | |
| | | | |
| if(&out != &X) | | | |
| { | | | |
| //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(); | | | |
| 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 T1, typename T2, typename glue_type> | | | |
| inline | | | |
| void | | | |
| op_scalar_div_pre::apply(Mat<typename T1::elem_type>& out, const Op<Glue<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 'Mat<eT>' | | | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
|
| const eT k = in.aux; | | const eT* A_mem = A.memptr(); | |
| const u32 n_elem = out.n_elem; | | 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, 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 eT k = in.aux; | |
|
| 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 / A_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| 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); | |
| | | | |
| | | | |
| skipping to change at line 886 | | skipping to change at line 692 | |
| 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] = k / (A_mem[i] * B_mem[i]); | | out_mem[i] = k / (A_mem[i] * B_mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| 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_write<T1> tmp(out, in.m); | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| // TODO: analyse effects of aliasing | | | |
| //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* A_mem = A.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| const eT k = in.aux; | | const eT k = in.aux; | |
| | | | |
|
| for(u32 i=0; i < X.n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
|
| out_mem[i] = X_mem[i] / k; | | out_mem[i] = A_mem[i] / k; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube<T
1,op_scalar_div_post>& in) | | op_scalar_div_post::apply(Cube<typename T1::elem_type>& out, const OpCube<T
1,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_cube<T1> tmp(in.m); | | const unwrap_cube_write<T1> tmp(out, in.m); | |
| const Cube<eT>& X = tmp.M; | | const Cube<eT>& A = 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* A_mem = A.memptr(); | |
| const eT k = in.aux; | | | |
| | | | |
| for(u32 i=0; i < X.n_elem; ++i) | | | |
| { | | | |
| out_mem[i] = X_mem[i] / k; | | | |
| } | | | |
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| op_scalar_div_post::apply(Mat<eT>& out, const Op<Mat<eT>,op_scalar_div_post | | | |
| >& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const Mat<eT>& X = in.m; | | | |
| | | | |
| if(&out != &X) | | | |
| { | | | |
| //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(); | | | |
| 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 T1, typename T2, typename glue_type> | | | |
| inline | | | |
| void | | | |
| op_scalar_div_post::apply(Mat<typename T1::elem_type>& out, const Op<Glue<T | | | |
| 1,T2,glue_type>, op_scalar_div_post>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| out = in.m; // implicit conversion to 'Mat<eT>' | | | |
| | | | |
| eT* out_mem = out.memptr(); | | | |
| 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) | | | |
| { | | | |
| 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 eT k = in.aux; | |
|
| 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] = A_mem[i] / k; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_GOOD_COMPILER) | |
| | | | |
| 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); | |
| | | | |
| | | | |
| skipping to change at line 1270 | | skipping to change at line 956 | |
| 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; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 65 change blocks. |
| 402 lines changed or deleted | | 78 lines changed or added | |
|
| op_scalar_misc_proto.hpp | | op_scalar_misc_proto.hpp | |
| | | | |
| skipping to change at line 53 | | skipping to change at line 53 | |
| }; | | }; | |
| | | | |
| //! 'multiply matrix/cube by a scalar' operation | | //! 'multiply matrix/cube by a scalar' operation | |
| class op_scalar_times | | class op_scalar_times | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename T1> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_scalar_times>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_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> 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> inline static void | | #if defined(ARMA_GOOD_COMPILER) | |
| apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | | | |
| 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> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, op_scal
ar_times>& in); | | template<typename T1, typename T2> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, 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_plus>, 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_plus>, op_scal
ar_times>& in); | |
| | | | |
| template<typename T1, typename T2> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_minus>, op_scal
ar_times>& in); | | template<typename T1, typename T2> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_minus>, 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_minus>, 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_minus>, op_scal
ar_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( 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); | | 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); | |
|
| | | | |
| | | #endif | |
| }; | | }; | |
| | | | |
| //! 'divide scalar by a matrix/cube' operation | | //! 'divide scalar by a matrix/cube' operation | |
| class op_scalar_div_pre | | class op_scalar_div_pre | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename T1> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_scalar_div_pre>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_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 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 O | | #if defined(ARMA_GOOD_COMPILER) | |
| p< Mat<eT>,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, typename glue_type> inline static void | | | |
| apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | | | |
| 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> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, 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_plus>, 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_plus>, 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_plus>, 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_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_minus>, 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_minus>, 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_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( 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); | | 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); | |
|
| | | | |
| | | #endif | |
| }; | | }; | |
| | | | |
| //! 'divide matrix/cube 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> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_scalar_div_post>& in); | | template<typename T1> inline static void apply( Mat<typename T1::elem_typ
e>& out, const Op<T1,op_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 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 O | | #if defined(ARMA_GOOD_COMPILER) | |
| p< Mat<eT>,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, typename glue_type> inline static void | | | |
| apply( Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue_ | | | |
| 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> inline static void apply( Mat<typename
T1::elem_type>& out, const Op< Glue<T1,T2, glue_plus>, 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_plus>, 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_plus>, 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_plus>, 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_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_minus>, 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_minus>, 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_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( 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); | | 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); | |
|
| | | | |
| | | #endif | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 6 change blocks. |
| 28 lines changed or deleted | | 9 lines changed or added | |
|
| op_trig_meat.hpp | | op_trig_meat.hpp | |
| | | | |
| skipping to change at line 159 | | skipping to change at line 159 | |
| | | | |
| 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("acos(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| void | | void | |
| op_acos::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_acos>& in) | | op_acos::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_acos>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 193 | | skipping to change at line 193 | |
| | | | |
| 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("acos(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cosh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cosh>& in) | | op_cosh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cosh>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 278 | | skipping to change at line 278 | |
| | | | |
| 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("acosh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_acosh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_acosh
>& in) | | op_acosh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_acosh
>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 312 | | skipping to change at line 312 | |
| | | | |
| 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("acosh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| } | | } | |
| | | | |
| // sin family | | // sin family | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| | | | |
| skipping to change at line 393 | | skipping to change at line 393 | |
| 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); | | 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::asin(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_asin::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asin>&
in) | | op_asin::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asin>&
in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 419 | | skipping to change at line 419 | |
| const Cube<eT>& A = tmp.M; | | const Cube<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, A.n_slices); | | //out.set_size(A.n_rows, A.n_cols, A.n_slices); | |
| out.copy_size(A); | | 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::asin(A.mem[i]); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| void | | void | |
| op_asin::apply(Mat< std::complex<T> >& out, const Op<T1,op_asin>& in) | | op_asin::apply(Mat< std::complex<T> >& out, const Op<T1,op_asin>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 453 | | skipping to change at line 453 | |
| | | | |
| 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("asin(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| void | | void | |
| op_asin::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_asin>& in) | | op_asin::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_asin>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 487 | | skipping to change at line 487 | |
| | | | |
| 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("asin(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_sinh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sinh>& in) | | op_sinh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sinh>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 572 | | skipping to change at line 572 | |
| | | | |
| 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("asinh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_asinh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asinh
>& in) | | op_asinh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_asinh
>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 605 | | skipping to change at line 605 | |
| | | | |
| 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("asinh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| // tan family | | // tan family | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_tan::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_tan>& in) | | op_tan::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_tan>& in) | |
| | | | |
| skipping to change at line 745 | | skipping to change at line 745 | |
| | | | |
| 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("atan(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| void | | void | |
| op_atan::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_atan>& in) | | op_atan::apply(Cube< std::complex<T> >& out, const OpCube<T1,op_atan>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 779 | | skipping to change at line 779 | |
| | | | |
| 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("atan(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_tanh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_tanh>& in) | | op_tanh::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_tanh>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 864 | | skipping to change at line 864 | |
| | | | |
| 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("atanh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_atanh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_atanh
>& in) | | op_atanh::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_atanh
>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 898 | | skipping to change at line 898 | |
| | | | |
| 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("atanh(): need Boost libraries"); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 14 change blocks. |
| 14 lines changed or deleted | | 14 lines changed or added | |
|
| running_stat_meat.hpp | | running_stat_meat.hpp | |
| | | | |
| skipping to change at line 19 | | skipping to change at line 19 | |
| // 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 running_stat | | //! \addtogroup running_stat | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | inline | |
| | | arma_counter<eT>::~arma_counter() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_counter<eT>::arma_counter() | |
| | | : d_count( eT(0)) | |
| | | , i_count(u32(0)) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const arma_counter<eT>& | |
| | | arma_counter<eT>::operator++() | |
| | | { | |
| | | const u32 max_val = 0xffffffff; | |
| | | | |
| | | if(i_count < max_val) | |
| | | { | |
| | | i_count++; | |
| | | } | |
| | | else | |
| | | { | |
| | | d_count += eT(max_val); | |
| | | i_count = 1; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | arma_counter<eT>::operator++(int) | |
| | | { | |
| | | operator++(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | arma_counter<eT>::reset() | |
| | | { | |
| | | d_count = eT(0); | |
| | | i_count = u32(0); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | arma_counter<eT>::value() | |
| | | const | |
| | | { | |
| | | return d_count + eT(i_count); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | arma_counter<eT>::value_plus_1() | |
| | | const | |
| | | { | |
| | | const u32 max_val = 0xffffffff; | |
| | | | |
| | | if(i_count < max_val) | |
| | | { | |
| | | return d_count + eT(i_count + 1); | |
| | | } | |
| | | else | |
| | | { | |
| | | return d_count + eT(max_val) + eT(1); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | arma_counter<eT>::value_minus_1() | |
| | | const | |
| | | { | |
| | | if(i_count > 0) | |
| | | { | |
| | | return d_count + eT(i_count - 1); | |
| | | } | |
| | | else | |
| | | { | |
| | | return d_count - eT(1); | |
| | | } | |
| | | } | |
| | | | |
| | | // | |
| | | | |
| | | template<typename eT> | |
| | | running_stat<eT>::~running_stat() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| running_stat<eT>::running_stat() | | running_stat<eT>::running_stat() | |
|
| : N (typename running_stat<eT>::T(0)) | | : r_mean ( eT(0)) | |
| , acc1 ( eT(0)) | | , r_var (typename running_stat<eT>::T(0)) | |
| , acc2 (typename running_stat<eT>::T(0)) | | | |
| , min_val ( eT(0)) | | , min_val ( eT(0)) | |
| , max_val ( eT(0)) | | , max_val ( eT(0)) | |
| , min_val_norm(typename running_stat<eT>::T(0)) | | , min_val_norm(typename running_stat<eT>::T(0)) | |
| , max_val_norm(typename running_stat<eT>::T(0)) | | , max_val_norm(typename running_stat<eT>::T(0)) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
| //! update statistics to reflect new sample | | //! update statistics to reflect new sample | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| running_stat<eT>::operator() (const typename running_stat<eT>::T sample) | | running_stat<eT>::operator() (const typename running_stat<eT>::T sample) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | arma_check( (arma_isfinite(sample) == false), "running_stat: non-finite s | |
| | | ample given" ); | |
| | | | |
| running_stat_aux::update_stats(*this, sample); | | running_stat_aux::update_stats(*this, sample); | |
| } | | } | |
| | | | |
| //! update statistics to reflect new sample (version for complex numbers) | | //! update statistics to reflect new sample (version for complex numbers) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| running_stat<eT>::operator() (const std::complex< typename running_stat<eT>
::T >& sample) | | running_stat<eT>::operator() (const std::complex< typename running_stat<eT>
::T >& sample) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| isnt_same_type<eT, std::complex< typename running_stat<eT>::T > >::check(
); | | isnt_same_type<eT, std::complex< typename running_stat<eT>::T > >::check(
); | |
| | | | |
|
| | | arma_check( (arma_isfinite(sample) == false), "running_stat: non-finite s | |
| | | ample given" ); | |
| | | | |
| running_stat_aux::update_stats(*this, sample); | | running_stat_aux::update_stats(*this, sample); | |
| } | | } | |
| | | | |
| //! set all statistics to zero | | //! set all statistics to zero | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| running_stat<eT>::reset() | | running_stat<eT>::reset() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename running_stat<eT>::T T; | | typedef typename running_stat<eT>::T T; | |
| | | | |
|
| N = T(0); | | counter.reset(); | |
| | | | |
|
| acc1 = eT(0); | | r_mean = eT(0); | |
| acc2 = T(0); | | r_var = T(0); | |
| | | | |
| min_val = eT(0); | | min_val = eT(0); | |
| max_val = eT(0); | | max_val = eT(0); | |
| | | | |
| min_val_norm = T(0); | | min_val_norm = T(0); | |
| max_val_norm = T(0); | | max_val_norm = T(0); | |
| } | | } | |
| | | | |
| //! mean or average value | | //! mean or average value | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| running_stat<eT>::mean() const | | running_stat<eT>::mean() | |
| | | const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename running_stat<eT>::T T; | | return r_mean; | |
| | | | |
| if(N > T(0)) | | | |
| { | | | |
| return acc1 / N; | | | |
| } | | | |
| else | | | |
| { | | | |
| return eT(0); | | | |
| } | | | |
| } | | } | |
| | | | |
| //! variance | | //! variance | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename running_stat<eT>::T | | typename running_stat<eT>::T | |
|
| running_stat<eT>::var(const u32 norm_type) const | | running_stat<eT>::var(const u32 norm_type) | |
| | | const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return running_stat_aux::var(*this, norm_type); | | const T N = counter.value(); | |
| | | | |
| | | if(N > T(1)) | |
| | | { | |
| | | if(norm_type == 0) | |
| | | { | |
| | | return r_var; | |
| | | } | |
| | | else | |
| | | { | |
| | | const T N_minus_1 = counter.value_minus_1(); | |
| | | return (N_minus_1/N) * r_var; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | return T(0); | |
| | | } | |
| } | | } | |
| | | | |
| //! standard deviation | | //! standard deviation | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename running_stat<eT>::T | | typename running_stat<eT>::T | |
|
| running_stat<eT>::stddev(const u32 norm_type) const | | running_stat<eT>::stddev(const u32 norm_type) | |
| | | const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return std::sqrt( running_stat_aux::var(*this, norm_type) ); | | return std::sqrt( (*this).var(norm_type) ); | |
| } | | } | |
| | | | |
| //! minimum value | | //! minimum value | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| running_stat<eT>::min() const | | running_stat<eT>::min() | |
| | | const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return min_val; | | return min_val; | |
| } | | } | |
| | | | |
| //! maximum value | | //! maximum value | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| running_stat<eT>::max() const | | running_stat<eT>::max() | |
| | | const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return max_val; | | return max_val; | |
| } | | } | |
| | | | |
| //! update statistics to reflect new sample | | //! update statistics to reflect new sample | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| running_stat_aux::update_stats(running_stat<eT>& x, const eT sample) | | running_stat_aux::update_stats(running_stat<eT>& x, const eT sample) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| if(x.N > eT(0)) | | typedef typename running_stat<eT>::T T; | |
| | | | |
| | | const T N = x.counter.value(); | |
| | | | |
| | | if(N > T(0)) | |
| { | | { | |
| if(sample < x.min_val) | | if(sample < x.min_val) | |
| { | | { | |
| x.min_val = sample; | | x.min_val = sample; | |
| } | | } | |
| | | | |
| if(sample > x.max_val) | | if(sample > x.max_val) | |
| { | | { | |
| x.max_val = sample; | | x.max_val = sample; | |
| } | | } | |
|
| | | | |
| | | const T N_plus_1 = x.counter.value_plus_1(); | |
| | | const T N_minus_1 = x.counter.value_minus_1(); | |
| | | | |
| | | // note: variance has to be updated before the mean | |
| | | | |
| | | const eT tmp = sample - x.r_mean; | |
| | | | |
| | | x.r_var = N_minus_1/N * x.r_var + (tmp*tmp)/N_plus_1; | |
| | | | |
| | | x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; | |
| | | //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; | |
| | | //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | x.r_mean = sample; | |
| x.min_val = sample; | | x.min_val = sample; | |
| x.max_val = sample; | | x.max_val = sample; | |
|
| } | | | |
| | | | |
|
| x.N++; | | // r_var is initialised to zero | |
| | | // in the constructor and reset() | |
| | | } | |
| | | | |
|
| x.acc1 += sample; | | x.counter++; | |
| x.acc2 += sample*sample; | | | |
| } | | } | |
| | | | |
| //! update statistics to reflect new sample (version for complex numbers) | | //! update statistics to reflect new sample (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| void | | void | |
| running_stat_aux::update_stats(running_stat< std::complex<T> >& x, const T
sample) | | running_stat_aux::update_stats(running_stat< std::complex<T> >& x, const T
sample) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 192 | | skipping to change at line 330 | |
| } | | } | |
| | | | |
| //! alter statistics to reflect new sample (version for complex numbers) | | //! alter statistics to reflect new sample (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| void | | void | |
| running_stat_aux::update_stats(running_stat< std::complex<T> >& x, const st
d::complex<T>& sample) | | running_stat_aux::update_stats(running_stat< std::complex<T> >& x, const st
d::complex<T>& sample) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename std::complex<T> eT; | |
| | | | |
| const T sample_norm = std::norm(sample); | | const T sample_norm = std::norm(sample); | |
|
| | | const T N = x.counter.value(); | |
| | | | |
|
| if(x.N > T(0)) | | if(N > T(0)) | |
| { | | { | |
| if(sample_norm < x.min_val_norm) | | if(sample_norm < x.min_val_norm) | |
| { | | { | |
| x.min_val_norm = sample_norm; | | x.min_val_norm = sample_norm; | |
| x.min_val = sample; | | x.min_val = sample; | |
| } | | } | |
| | | | |
| if(sample_norm > x.max_val_norm) | | if(sample_norm > x.max_val_norm) | |
| { | | { | |
| x.max_val_norm = sample_norm; | | x.max_val_norm = sample_norm; | |
| x.max_val = sample; | | x.max_val = sample; | |
| } | | } | |
|
| | | | |
| | | const T N_plus_1 = x.counter.value_plus_1(); | |
| | | const T N_minus_1 = x.counter.value_minus_1(); | |
| | | | |
| | | x.r_var = N_minus_1/N * x.r_var + std::norm(sample - x.r_mean)/N_plus_1 | |
| | | ; | |
| | | | |
| | | x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; | |
| | | //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; | |
| | | //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | x.r_mean = sample; | |
| x.min_val = sample; | | x.min_val = sample; | |
| x.max_val = sample; | | x.max_val = sample; | |
| x.min_val_norm = sample_norm; | | x.min_val_norm = sample_norm; | |
| x.max_val_norm = sample_norm; | | x.max_val_norm = sample_norm; | |
|
| } | | | |
| | | | |
| x.N++; | | | |
| | | | |
| x.acc1 += sample; | | | |
| x.acc2 += sample_norm; | | | |
| } | | | |
| | | | |
| //! variance | | | |
| template<typename eT> | | | |
| inline | | | |
| eT | | | |
| running_stat_aux::var(const running_stat<eT>& x, const u32 norm_type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| if(x.N > eT(1)) | | // r_var is initialised to zero | |
| { | | // in the constructor and reset() | |
| const eT norm_val = (norm_type == 0) ? (x.N-eT(1)) : x.N; | | | |
| const eT var_val = (x.acc2 - x.acc1*x.acc1/x.N) / norm_val; | | | |
| return var_val; | | | |
| } | | | |
| else | | | |
| { | | | |
| return eT(0); | | | |
| } | | } | |
|
| } | | | |
| | | | |
| //! variance (version for complex numbers) | | | |
| template<typename T> | | | |
| inline | | | |
| T | | | |
| running_stat_aux::var(const running_stat< std::complex<T> >& x, const u32 n | | | |
| orm_type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| if(x.N > T(1)) | | x.counter++; | |
| { | | | |
| const T norm_val = (norm_type == 0) ? (x.N-T(1)) : x.N; | | | |
| const T var_val = (x.acc2 - std::norm(x.acc1)/x.N) / norm_val; | | | |
| return var_val; | | | |
| } | | | |
| else | | | |
| { | | | |
| return T(0); | | | |
| } | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 29 change blocks. |
| 73 lines changed or deleted | | 186 lines changed or added | |
|
| subview_meat.hpp | | subview_meat.hpp | |
| | | | |
| skipping to change at line 68 | | skipping to change at line 68 | |
| inline | | inline | |
| void | | void | |
| subview<eT>::fill(const eT val) | | subview<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
| eT* coldata = colptr(col); | | eT* coldata = colptr(col); | |
| | | | |
|
| for(u32 row = 0; row != n_rows; ++row) | | for(u32 row = 0; row<n_rows; ++row) | |
| { | | { | |
| coldata[row] = val; | | coldata[row] = val; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| | | | |
| skipping to change at line 166 | | skipping to change at line 166 | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const Base<eT,T1>& in) | | subview<eT>::operator= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
|
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "insert into submatrix"); | | arma_debug_assert_same_size(t, x, "insert into submatrix"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| const eT* x_coldata = x.colptr(col); | | const eT* x_coldata = x.colptr(col); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 row = 0; row<t.n_rows; ++row) | |
| { | | { | |
| | | | |
| skipping to change at line 194 | | skipping to change at line 194 | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator+= (const Base<eT,T1>& in) | | subview<eT>::operator+= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
|
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "matrix addition"); | | arma_debug_assert_same_size(t, x, "matrix addition"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| const eT* x_coldata = x.colptr(col); | | const eT* x_coldata = x.colptr(col); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 row = 0; row<t.n_rows; ++row) | |
| { | | { | |
| | | | |
| skipping to change at line 222 | | skipping to change at line 222 | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator-= (const Base<eT,T1>& in) | | subview<eT>::operator-= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
|
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "matrix subtraction"); | | arma_debug_assert_same_size(t, x, "matrix subtraction"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| const eT* x_coldata = x.colptr(col); | | const eT* x_coldata = x.colptr(col); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 row = 0; row<t.n_rows; ++row) | |
| { | | { | |
| | | | |
| skipping to change at line 250 | | skipping to change at line 250 | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator%= (const Base<eT,T1>& in) | | subview<eT>::operator%= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
|
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "matrix schur product"); | | arma_debug_assert_same_size(t, x, "matrix schur product"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| const eT* x_coldata = x.colptr(col); | | const eT* x_coldata = x.colptr(col); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 row = 0; row<t.n_rows; ++row) | |
| { | | { | |
| | | | |
| skipping to change at line 278 | | skipping to change at line 278 | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator/= (const Base<eT,T1>& in) | | subview<eT>::operator/= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap<T1> tmp(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | | |
|
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise matrix division"); | | arma_debug_assert_same_size(t, x, "element-wise matrix division"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| const eT* x_coldata = x.colptr(col); | | const eT* x_coldata = x.colptr(col); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 row = 0; row<t.n_rows; ++row) | |
| { | | { | |
| | | | |
| skipping to change at line 306 | | skipping to change at line 306 | |
| //! x.submat(...) = y.submat(...) | | //! x.submat(...) = y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const subview<eT>& x_in) | | subview<eT>::operator= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
|
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "insert into submatrix"); | | arma_debug_assert_same_size(t, x, "insert into submatrix"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| | | | |
| skipping to change at line 343 | | skipping to change at line 343 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator+= (const subview<eT>& x_in) | | subview<eT>::operator+= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
|
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
| subview<eT>& t = *this; | | subview<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "matrix addition"); | | arma_debug_assert_same_size(t, x, "matrix addition"); | |
| | | | |
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col<t.n_cols; ++col) | |
| { | | { | |
| eT* t_coldata = t.colptr(col); | | eT* t_coldata = t.colptr(col); | |
| | | | |
| skipping to change at line 642 | | skipping to change at line 642 | |
| ( | | ( | |
| ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) ) | | ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) ) | |
| || | | || | |
| ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | | ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | |
| ); | | ); | |
| | | | |
| return (row_overlap & col_overlap); | | return (row_overlap & col_overlap); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | subview<eT>::is_vec() const | |
| | | { | |
| | | return ( (n_rows == 1) || (n_cols == 1) ); | |
| | | } | |
| | | | |
| //! X = Y.submat(...) | | //! X = Y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::extract(Mat<eT>& actual_out, const subview<eT>& in) | | subview<eT>::extract(Mat<eT>& actual_out, const subview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| // | | // | |
| const bool alias = (&actual_out == &in.m); | | const bool alias = (&actual_out == &in.m); | |
| | | | |
| Mat<eT>* tmp = (alias) ? new Mat<eT> : 0; | | Mat<eT>* tmp = (alias) ? new Mat<eT> : 0; | |
| Mat<eT>& out = (alias) ? (*tmp) : actual_out; | | Mat<eT>& out = (alias) ? (*tmp) : actual_out; | |
| | | | |
| // | | // | |
| | | | |
|
| const u32 n_rows = in.n_rows; | | const u32 n_rows = in.n_rows; // number of rows in the subview | |
| const u32 n_cols = in.n_cols; | | const u32 n_cols = in.n_cols; // number of columns in the subview | |
| | | | |
| out.set_size(n_rows, n_cols); | | out.set_size(n_rows, n_cols); | |
| | | | |
| arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols =
%d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.
m.n_rows % in.m.n_cols ); | | arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols =
%d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.
m.n_rows % in.m.n_cols ); | |
| | | | |
|
| if((n_rows == 1) && (n_cols != 1)) | | if(in.is_vec() == true) | |
| { | | { | |
|
| arma_extra_debug_print("subview::apply(): copying row (going across col | | if(n_cols == 1) // a column vector | |
| umns)"); | | | |
| | | | |
| for(u32 col = 0; col<n_cols; ++col) | | | |
| { | | { | |
|
| out[col] = in.m.at(in.aux_row1, col); | | arma_extra_debug_print("subview::extract(): copying col (going across | |
| } | | rows)"); | |
| } | | | |
| else | | | |
| if((n_rows != 1) && (n_cols == 1)) | | | |
| { | | | |
| arma_extra_debug_print("subview::apply(): copying col (going across n_r | | | |
| ows)"); | | | |
| | | | |
|
| const eT* in_coldata = in.colptr(0); | | eT* out_mem = out.memptr(); | |
| | | const eT* in_coldata = in.colptr(0); // the first column of the subv | |
| | | iew, taking into account any row offset | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | for(u32 row=0; row<n_rows; ++row) | |
| { | | { | |
| out[row] = in_coldata[row]; | | out_mem[row] = in_coldata[row]; | |
| | | } | |
| } | | } | |
|
| | | else // a row vector | |
| | | { | |
| | | arma_extra_debug_print("subview::extract(): copying row (going across | |
| | | columns)"); | |
| | | | |
| | | const Mat<eT>& X = in.m; | |
| | | | |
|
| | | eT* out_mem = out.memptr(); | |
| | | const u32 row = in.aux_row1; | |
| | | const u32 start_col = in.aux_col1; | |
| | | | |
| | | for(u32 i=0; i<n_cols; ++i) | |
| | | { | |
| | | out_mem[i] = X.at(row, i+start_col); | |
| | | } | |
| | | } | |
| } | | } | |
|
| else | | else // general submatrix | |
| for(u32 col = 0; col<n_cols; ++col) | | | |
| { | | { | |
|
| eT* out_coldata = out.colptr(col); | | arma_extra_debug_print("subview::extract(): general submatrix"); | |
| const eT* in_coldata = in.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
|
| out_coldata[row] = in_coldata[row]; | | eT* out_coldata = out.colptr(col); | |
| } | | const eT* in_coldata = in.colptr(col); | |
| | | | |
|
| | | for(u32 row = 0; row<n_rows; ++row) | |
| | | { | |
| | | out_coldata[row] = in_coldata[row]; | |
| | | } | |
| | | } | |
| } | | } | |
| | | | |
| if(alias) | | if(alias) | |
| { | | { | |
| actual_out = out; | | actual_out = out; | |
| delete tmp; | | delete tmp; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 902 | | skipping to change at line 921 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col) | | subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col) | |
| : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col) | | : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col, const u | |
| | | 32 in_row1, const u32 in_row2) | |
| | | : subview<eT>(in_m, in_row1, in_col, in_row2, in_col) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col, const u32 in_ | |
| | | row1, const u32 in_row2) | |
| | | : subview<eT>(in_m, in_row1, in_col, in_row2, in_col) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_col<eT>::operator=(const subview<eT>& X) | | subview_col<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::operator=(X); | | subview<eT>::operator=(X); | |
| arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible
dimensions" ); | | arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible
dimensions" ); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 956 | | skipping to change at line 991 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row) | | subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row) | |
| : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1) | | : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row, const u | |
| | | 32 in_col1, const u32 in_col2) | |
| | | : subview<eT>(in_m, in_row, in_col1, in_row, in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row, const u32 in_ | |
| | | col1, const u32 in_col2) | |
| | | : subview<eT>(in_m, in_row, in_col1, in_row, in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_row<eT>::operator=(const subview<eT>& X) | | subview_row<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::operator=(X); | | subview<eT>::operator=(X); | |
| arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible
dimensions" ); | | arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible
dimensions" ); | |
| } | | } | |
| | | | |
| | | | |
End of changes. 24 change blocks. |
| 39 lines changed or deleted | | 95 lines changed or added | |
|