| Col_meat.hpp | | Col_meat.hpp | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| // 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 Col | | //! \addtogroup Col | |
| //! @{ | | //! @{ | |
| | | | |
| //! construct an empty column vector | | //! construct an empty column vector | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col() | | Col<eT>::Col() | |
|
| : Mat<eT>() | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | | |
| | | access::rw(Mat<eT>::vec_state) = 1; | |
| } | | } | |
| | | | |
| //! construct a column vector with the specified number of n_elem | | //! construct a column vector with the specified number of n_elem | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const u32 in_n_elem) | | Col<eT>::Col(const u32 in_n_elem) | |
|
| : Mat<eT>(in_n_elem, 1) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | | |
| | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | | |
| | | Mat<eT>::init(in_n_elem, 1); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const u32 in_n_rows, const u32 in_n_cols) | | Col<eT>::Col(const u32 in_n_rows, const u32 in_n_cols) | |
|
| : Mat<eT>(in_n_rows, in_n_cols) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 1; | |
| ); | | | |
| | | Mat<eT>::init(in_n_rows, in_n_cols); | |
| } | | } | |
| | | | |
| //! 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) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| | | 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"
); | | access::rw(Mat<eT>::vec_state) = 1; | |
| } | | } | |
| | | | |
| //! 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(); | |
| | | | |
|
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| Mat<eT>::operator=(text); | | 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"
); | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! 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 std::string& text) | | Col<eT>::Col(const std::string& text) | |
|
| : Mat<eT>(text) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| | | 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"
); | | access::rw(Mat<eT>::vec_state) = 1; | |
| } | | } | |
| | | | |
| //! 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 std::string& text) | | Col<eT>::operator=(const std::string& text) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| Mat<eT>::operator=(text); | | 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"
); | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| //! construct a column vector from a given column vector | | | |
| template<typename eT> | | | |
| inline | | | |
| Col<eT>::Col(const Col<eT>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| } | | | |
| | | | |
| //! 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 eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(val); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| //! construct a column vector from a given matrix; the matrix must have exa
ctly one column | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
|
| Col<eT>::Col(const Mat<eT>& X) | | Col<eT>::Col(const Base<eT,T1>& X) | |
| : Mat<eT>(X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 1; | |
| ); | | | |
| } | | | |
| | | | |
|
| //! construct a column vector from a given matrix; the matrix must have exa | | Mat<eT>::operator=(X.get_ref()); | |
| ctly one column | | | |
| template<typename eT> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const Mat<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> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
| const Col<eT>& | | const Col<eT>& | |
|
| Col<eT>::operator*=(const Mat<eT>& X) | | Col<eT>::operator=(const Base<eT,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator*=(X); | | Mat<eT>::operator=(X.get_ref()); | |
| | | | |
| 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 | | Col<eT>::Col(eT* aux_mem, const u32 aux_length, const bool copy_aux_mem, co | |
| bool copy_aux_mem) | | nst bool strict) | |
| : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols, copy_aux_mem) | | : Mat<eT>(aux_mem, aux_length, 1, copy_aux_mem, strict) | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! construct a column vector from a given auxiliary array of eTs | | | |
| template<typename eT> | | | |
| inline | | | |
| Col<eT>::Col(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | | | |
| : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! construct a column vector from a given auxiliary array of eTs | | | |
| template<typename eT> | | | |
| inline | | | |
| Col<eT>::Col(eT* aux_mem, const u32 aux_length, const bool copy_aux_mem) | | | |
| : Mat<eT>(aux_mem, aux_length, 1, copy_aux_mem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // set_size(aux_length, 1); | | access::rw(Mat<eT>::vec_state) = 1; | |
| // | | | |
| // arma_check( (Mat<eT>::n_elem != aux_length), "Col::Col(): don't know h | | | |
| ow to handle the given array" ); | | | |
| // | | | |
| // syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem ); | | | |
| } | | } | |
| | | | |
| //! 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(const eT* aux_mem, const u32 aux_length) | | Col<eT>::Col(const eT* aux_mem, const u32 aux_length) | |
| : Mat<eT>(aux_mem, aux_length, 1) | | : Mat<eT>(aux_mem, aux_length, 1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // set_size(aux_length, 1); | | access::rw(Mat<eT>::vec_state) = 1; | |
| // | | | |
| // arma_check( (Mat<eT>::n_elem != aux_length), "Col::Col(): don't know h | | | |
| ow to handle the given array" ); | | | |
| // | | | |
| // syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem ); | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Col<eT>::Col | | Col<eT>::Col | |
| ( | | ( | |
| const Base<typename Col<eT>::pod_type, T1>& A, | | const Base<typename Col<eT>::pod_type, T1>& A, | |
| const Base<typename Col<eT>::pod_type, T2>& B | | const Base<typename Col<eT>::pod_type, T2>& B | |
| ) | | ) | |
|
| : Mat<eT>(A,B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! construct a column vector from given a submatrix; the submatrix must ha | | | |
| ve exactly one column | | | |
| template<typename eT> | | | |
| inline | | | |
| Col<eT>::Col(const subview<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 submatrix; the submatrix must ha | | | |
| ve exactly one column | | | |
| template<typename eT> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const subview<eT>& X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator=(X); | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
|
| return *this; | | Mat<eT>::init(A,B); | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const subview<eT>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| 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 | | //! construct a column vector from given a subcube; the subcube must have e
xactly one column | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Col<eT>::Col(const subview_cube<eT>& X) | | Col<eT>::Col(const subview_cube<eT>& X) | |
|
| : Mat<eT>(X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 1; | |
| ); | | | |
| } | | | |
| | | | |
| //! 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); | | 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" | | | |
| ); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| //! construct a column vector from given a diagview | | | |
| template<typename eT> | | | |
| inline | | | |
| Col<eT>::Col(const diagview<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 diagview | | //! construct a column vector from given a subcube; the subcube must have e
xactly one column | |
| 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 subview_cube<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; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const diagview<eT>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator*=(X); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| mat_injector< Col<eT> > | | mat_injector< Col<eT> > | |
| Col<eT>::operator<<(const eT val) | | Col<eT>::operator<<(const eT val) | |
| { | | { | |
| return mat_injector< Col<eT> >(*this, val); | | return mat_injector< Col<eT> >(*this, val); | |
| } | | } | |
| | | | |
| skipping to change at line 406 | | skipping to change at line 272 | |
| arma_inline | | arma_inline | |
| const subview_col<eT> | | const subview_col<eT> | |
| Col<eT>::rows(const u32 in_row1, const u32 in_row2) | | Col<eT>::rows(const u32 in_row1, const u32 in_row2) | |
| const | | const | |
| { | | { | |
| arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) )
, "Col::rows(): indices out of bounds or incorrectly used"); | | 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); | | 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 | | | |
| template<typename eT> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| Col<eT>::Col(const Op<T1, op_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! 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 T1, typename op_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const Op<T1, op_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const Op<T1, op_type>& 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> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| Col<eT>::Col(const eOp<T1, eop_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const eOp<T1, eop_type>& 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> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const eOp<T1, eop_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| Col<eT>::Col(const mtOp<eT, T1, op_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const mtOp<eT, T1, op_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const mtOp<eT, T1, op_type>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator*=(X); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
| 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 | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| Col<eT>::Col(const Glue<T1, T2, glue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! 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 T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const Glue<T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const Glue<T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| Col<eT>::Col(const eGlue<T1, T2, eglue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const eGlue<T1, T2, eglue_type>& 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> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const eGlue<T1, T2, eglue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| Col<eT>::Col(const mtGlue<eT, T1, T2, glue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Col<eT>& | | | |
| Col<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator*=(X); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| //! change the number of rows | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::set_size(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| 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) | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ) ); | | | |
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensi | | | |
| ons" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::reshape(const u32 in_rows, const u32 in_cols, const u32 dim) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::reshape(in_rows, in_cols, dim); | | | |
| | | | |
| arma_debug_check( (in_cols > 1), "Col::set_size(): incompatible dimension | | | |
| s" ); | | | |
| } | | | |
| | | | |
| //! change the number of n_rows (this function re-implements mat::copy_siz | | | |
| e() in order to check the number of columns) | | | |
| template<typename eT> | | | |
| template<typename eT2> | | | |
| inline | | | |
| void | | | |
| Col<eT>::copy_size(const Mat<eT2>& x) | | | |
| { | | | |
| 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 ) ); | | | |
| | | | |
| arma_debug_check( (x.n_cols > 1), "Col::copy_size(): incompatible dimensi | | | |
| ons" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::zeros() | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::zeros(); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::zeros(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::zeros(in_n_elem, 1); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ) ); | | | |
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::zeros(): incompatible dimensions | | | |
| " ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::ones() | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::ones(); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::ones(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::ones(in_n_elem, 1); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ) ); | | | |
| | | | |
| arma_debug_check( (in_n_cols > 1), "Col::ones(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::load(const std::string name, const file_type type, const bool prin | | | |
| t_status) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::load(name, type, print_status); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::load(std::istream& is, const file_type type, const bool print_stat | | | |
| us) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::load(is, type, print_status); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::quiet_load(const std::string name, const file_type type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::quiet_load(name, type); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Col<eT>::quiet_load(std::istream& is, const file_type type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::quiet_load(is, type); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename Col<eT>::row_iterator | | typename Col<eT>::row_iterator | |
| Col<eT>::begin_row(const u32 row_num) | | Col<eT>::begin_row(const u32 row_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o
f bounds"); | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o
f bounds"); | |
| | | | |
| return Mat<eT>::memptr() + row_num; | | return Mat<eT>::memptr() + row_num; | |
| | | | |
| skipping to change at line 864 | | skipping to change at line 320 | |
| typename Col<eT>::const_row_iterator | | typename Col<eT>::const_row_iterator | |
| Col<eT>::end_row(const u32 row_num) const | | Col<eT>::end_row(const u32 row_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of
bounds"); | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of
bounds"); | |
| | | | |
| return Mat<eT>::memptr() + row_num + 1; | | return Mat<eT>::memptr() + row_num + 1; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<u32 fixed_n_elem> | |
| | | arma_inline | |
| | | void | |
| | | Col<eT>::fixed<fixed_n_elem>::mem_setup() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | if(fixed_n_elem > 0) | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = fixed_n_elem; | |
| | | access::rw(Mat<eT>::n_cols) = 1; | |
| | | access::rw(Mat<eT>::n_elem) = fixed_n_elem; | |
| | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = (fixed_n_elem > Mat_prealloc::mem_n_el | |
| | | em) ? mem_local_extra : Mat<eT>::mem_local; | |
| | | } | |
| | | else | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = 0; | |
| | | access::rw(Mat<eT>::n_cols) = 0; | |
| | | access::rw(Mat<eT>::n_elem) = 0; | |
| | | access::rw(Mat<eT>::vec_state) = 1; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = 0; | |
| | | } | |
| | | } | |
| | | | |
| | | #ifdef ARMA_EXTRA_COL_MEAT | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_MEAT) | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 41 change blocks. |
| 645 lines changed or deleted | | 77 lines changed or added | |
|
| Cube_meat.hpp | | Cube_meat.hpp | |
| | | | |
| skipping to change at line 27 | | skipping to change at line 27 | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::~Cube() | | Cube<eT>::~Cube() | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| delete_mat(); | | delete_mat(); | |
| | | | |
|
| if(use_aux_mem == false) | | if(mem_state == 0) | |
| { | | { | |
|
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | if(n_elem > Cube_prealloc::mem_n_elem) | |
| { | | { | |
| delete [] mem; | | delete [] mem; | |
| } | | } | |
| } | | } | |
| | | | |
| if(arma_config::debug == true) | | if(arma_config::debug == true) | |
| { | | { | |
| // try to expose buggy user code that accesses deleted objects | | // try to expose buggy user code that accesses deleted objects | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| | | | |
| skipping to change at line 58 | | skipping to change at line 58 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::Cube() | | Cube<eT>::Cube() | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
| //! construct the cube to have user specified dimensions | | //! construct the cube to have user specified dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::Cube(const u32 in_n_rows, const u32 in_n_cols, const u32 in_n_sli
ces) | | Cube<eT>::Cube(const u32 in_n_rows, const u32 in_n_cols, const u32 in_n_sli
ces) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(in_n_rows, in_n_cols, in_n_slices); | | init(in_n_rows, in_n_cols, in_n_slices); | |
| } | | } | |
| | | | |
| //! internal cube construction; if the requested size is small enough, memo
ry from the stack is used. | | //! internal cube construction; if the requested size is small enough, memo
ry from the stack is used. | |
| //! otherwise memory is allocated via 'new' | | //! otherwise memory is allocated via 'new' | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::init(const u32 in_n_rows, const u32 in_n_cols, const u32 in_n_sli
ces) | | Cube<eT>::init(const u32 in_n_rows, const u32 in_n_cols, const u32 in_n_sli
ces) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices ); | | arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices ); | |
| | | | |
|
| const u32 new_n_elem = in_n_rows * in_n_cols * in_n_slices; | | const bool same_size = ( (n_rows == in_n_rows) && (n_cols == in_n_cols) &
& (n_slices == in_n_slices) ); | |
| | | | |
|
| if(n_elem == new_n_elem) | | if(same_size == false) | |
| { | | { | |
|
| if( (n_rows != in_n_rows) || (n_cols != in_n_cols) || (n_slices != in_n | | arma_debug_check( (mem_state == 3), "Cube::init(): size can't be change | |
| _slices) ) | | d as template based size specification is in use" ); | |
| { | | | |
| delete_mat(); | | | |
| | | | |
| access::rw(n_rows) = in_n_rows; | | | |
| access::rw(n_cols) = in_n_cols; | | | |
| access::rw(n_elem_slice) = in_n_rows*in_n_cols; | | | |
| access::rw(n_slices) = in_n_slices; | | | |
| | | | |
|
| create_mat(); | | const u32 old_n_elem = n_elem; | |
| } | | const u32 new_n_elem = in_n_rows * in_n_cols * in_n_slices; | |
| } | | | |
| else | | | |
| { | | | |
| arma_debug_check | | | |
| ( | | | |
| (use_aux_mem == true), | | | |
| "Cube::init(): can't change the amount of memory as auxiliary memory | | | |
| is in use" | | | |
| ); | | | |
| | | | |
| delete_mat(); | | | |
| | | | |
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | | |
| { | | | |
| delete [] mem; | | | |
| } | | | |
| | | | |
|
| if(new_n_elem <= sizeof(mem_local)/sizeof(eT) ) | | if(old_n_elem == new_n_elem) | |
| { | | { | |
|
| access::rw(mem) = mem_local; | | if(same_size == false) | |
| | | { | |
| | | delete_mat(); | |
| | | | |
| | | if(new_n_elem > 0) | |
| | | { | |
| | | access::rw(n_rows) = in_n_rows; | |
| | | access::rw(n_cols) = in_n_cols; | |
| | | access::rw(n_elem_slice) = in_n_rows*in_n_cols; | |
| | | access::rw(n_slices) = in_n_slices; | |
| | | | |
| | | create_mat(); | |
| | | } | |
| | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| access::rw(mem) = new(std::nothrow) eT[new_n_elem]; | | arma_debug_check( (mem_state == 2), "Cube::init(): requested size is | |
| arma_check( (mem == 0), "Cube::init(): out of memory" ); | | not compatible with the size of auxiliary memory" ); | |
| } | | | |
| | | delete_mat(); | |
| | | | |
| | | if(mem_state == 0) | |
| | | { | |
| | | if(n_elem > Cube_prealloc::mem_n_elem ) | |
| | | { | |
| | | arma_extra_debug_print("Cube::init(): freeing memory"); | |
| | | | |
| | | delete [] mem; | |
| | | } | |
| | | } | |
| | | | |
| | | access::rw(mem_state) = 0; | |
| | | | |
| | | if(new_n_elem <= Cube_prealloc::mem_n_elem) | |
| | | { | |
| | | access::rw(mem) = mem_local; | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_extra_debug_print("Cube::init(): allocating memory"); | |
| | | | |
| | | access::rw(mem) = new(std::nothrow) eT[new_n_elem]; | |
| | | | |
| | | arma_check( (mem == 0), "Cube::init(): out of memory" ); | |
| | | } | |
| | | | |
| | | if(new_n_elem > 0) | |
| | | { | |
| | | access::rw(n_rows) = in_n_rows; | |
| | | access::rw(n_cols) = in_n_cols; | |
| | | access::rw(n_elem_slice) = in_n_rows*in_n_cols; | |
| | | access::rw(n_slices) = in_n_slices; | |
| | | access::rw(n_elem) = new_n_elem; | |
| | | | |
|
| access::rw(n_elem) = new_n_elem; | | create_mat(); | |
| | | } | |
| | | } | |
| | | | |
| if(new_n_elem == 0) | | if(new_n_elem == 0) | |
| { | | { | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| access::rw(n_elem_slice) = 0; | | access::rw(n_elem_slice) = 0; | |
| access::rw(n_slices) = 0; | | access::rw(n_slices) = 0; | |
|
| | | access::rw(n_elem) = 0; | |
| } | | } | |
|
| else | | } | |
| { | | } | |
| access::rw(n_rows) = in_n_rows; | | | |
| access::rw(n_cols) = in_n_cols; | | | |
| access::rw(n_elem_slice) = in_n_rows*in_n_cols; | | | |
| access::rw(n_slices) = in_n_slices; | | | |
| } | | | |
| | | | |
|
| create_mat(); | | //! for constructing a complex cube out of two non-complex cubes | |
| | | template<typename eT> | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | Cube<eT>::init | |
| | | ( | |
| | | const BaseCube<typename Cube<eT>::pod_type,T1>& A, | |
| | | const BaseCube<typename Cube<eT>::pod_type,T2>& B | |
| | | ) | |
| | | { | |
| | | arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil | |
| | | e-time abort if eT isn't std::complex | |
| | | | |
| | | typedef typename T1::elem_type T; | |
| | | arma_type_check< is_complex<T>::value == true >::apply(); //!< compile- | |
| | | time abort if T is std::complex | |
| | | | |
| | | isnt_same_type<std::complex<T>, eT>::check(); //!< compile-time abort i | |
| | | f types are not compatible | |
| | | | |
| | | const unwrap_cube<T1> tmp_A(A.get_ref()); | |
| | | const unwrap_cube<T2> tmp_B(B.get_ref()); | |
| | | | |
| | | const Cube<T>& X = tmp_A.M; | |
| | | const Cube<T>& Y = tmp_B.M; | |
| | | | |
| | | arma_assert_same_size(X, Y, "Cube()"); | |
| | | | |
| | | init(X.n_rows, X.n_cols, X.n_slices); | |
| | | | |
| | | const T* X_mem = X.mem; | |
| | | const T* Y_mem = Y.mem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | access::rw(mem[i]) = std::complex<T>(X_mem[i], Y_mem[i]); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::delete_mat() | | Cube<eT>::delete_mat() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| for(u32 slice = 0; slice < n_slices; ++slice) | | for(u32 slice = 0; slice < n_slices; ++slice) | |
| { | | { | |
| delete access::rw(mat_ptrs[slice]); | | delete access::rw(mat_ptrs[slice]); | |
| } | | } | |
| | | | |
|
| if(n_slices > sizeof(mat_ptrs_local)/sizeof(Mat<eT>*) ) | | if(mem_state <= 2) | |
| { | | { | |
|
| delete [] mat_ptrs; | | if(n_slices > Cube_prealloc::mat_ptrs_size) | |
| | | { | |
| | | delete [] mat_ptrs; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::create_mat() | | Cube<eT>::create_mat() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| if( n_slices <= sizeof(mat_ptrs_local)/sizeof(Mat<eT>*) ) | | if(mem_state <= 2) | |
| { | | | |
| access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local); | | | |
| } | | | |
| else | | | |
| { | | { | |
|
| access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices]; | | if(n_slices <= Cube_prealloc::mat_ptrs_size) | |
| arma_check( (mat_ptrs == 0), "Cube::create_mat(): out of memory" ); | | { | |
| | | access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local); | |
| | | } | |
| | | else | |
| | | { | |
| | | access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices]; | |
| | | | |
| | | arma_check( (mat_ptrs == 0), "Cube::create_mat(): out of memory" ); | |
| | | } | |
| } | | } | |
| | | | |
| for(u32 slice = 0; slice < n_slices; ++slice) | | for(u32 slice = 0; slice < n_slices; ++slice) | |
| { | | { | |
| mat_ptrs[slice] = new Mat<eT>('j', slice_memptr(slice), n_rows, n_cols)
; | | mat_ptrs[slice] = new Mat<eT>('j', slice_memptr(slice), n_rows, n_cols)
; | |
| } | | } | |
| } | | } | |
| | | | |
| //! Set the cube to be equal to the specified scalar. | | //! Set the cube to be equal to the specified scalar. | |
| //! NOTE: the size of the cube will be 1x1x1 | | //! NOTE: the size of the cube will be 1x1x1 | |
| | | | |
| skipping to change at line 217 | | skipping to change at line 279 | |
| } | | } | |
| | | | |
| //! In-place addition of a scalar to all elements of the cube | | //! In-place addition of a scalar to all elements of the cube | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator+=(const eT val) | | Cube<eT>::operator+=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_plus( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] += val; | | | |
| local_ptr[j] += val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] += val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place subtraction of a scalar from all elements of the cube | | //! In-place subtraction of a scalar from all elements of the cube | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator-=(const eT val) | | Cube<eT>::operator-=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_minus( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] -= val; | | | |
| local_ptr[j] -= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] -= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place multiplication of all elements of the cube with a scalar | | //! In-place multiplication of all elements of the cube with a scalar | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator*=(const eT val) | | Cube<eT>::operator*=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_mul( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] *= val; | | | |
| local_ptr[j] *= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] *= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place division of all elements of the cube with a scalar | | //! In-place division of all elements of the cube with a scalar | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator/=(const eT val) | | Cube<eT>::operator/=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_div( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] /= val; | | | |
| local_ptr[j] /= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] /= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a cube from a given cube | | //! construct a cube from a given cube | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::Cube(const Cube<eT>& in_cube) | | Cube<eT>::Cube(const Cube<eT>& in_cube) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x")
% this % &in_cube); | | arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x")
% this % &in_cube); | |
| | | | |
| init(in_cube); | | init(in_cube); | |
| } | | } | |
| | | | |
| //! construct a cube from a given cube | | //! construct a cube from a given cube | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 370 | | skipping to change at line 376 | |
| } | | } | |
| | | | |
| //! construct a cube from a given auxiliary array of eTs. | | //! construct a cube from a given auxiliary array of eTs. | |
| //! if copy_aux_mem is true, new memory is allocated and the array is copie
d. | | //! if copy_aux_mem is true, new memory is allocated and the array is copie
d. | |
| //! if copy_aux_mem is false, the auxiliary array is used directly (without
allocating memory and copying). | | //! if copy_aux_mem is false, the auxiliary array is used directly (without
allocating memory and copying). | |
| //! note that in the latter case | | //! note that in the latter case | |
| //! the default is to copy the array. | | //! the default is to copy the array. | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Cube<eT>::Cube(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, con | | Cube<eT>::Cube(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, con | |
| st u32 aux_n_slices, const bool copy_aux_mem) | | st u32 aux_n_slices, const bool copy_aux_mem, const bool strict) | |
| : n_rows (copy_aux_mem ? 0 : aux_n_rows ) | | : n_rows (copy_aux_mem ? 0 : aux_n_rows ) | |
| , n_cols (copy_aux_mem ? 0 : aux_n_cols ) | | , n_cols (copy_aux_mem ? 0 : aux_n_cols ) | |
| , n_elem_slice(copy_aux_mem ? 0 : aux_n_rows*aux_n_cols ) | | , n_elem_slice(copy_aux_mem ? 0 : aux_n_rows*aux_n_cols ) | |
| , n_slices (copy_aux_mem ? 0 : aux_n_slices ) | | , n_slices (copy_aux_mem ? 0 : aux_n_slices ) | |
| , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols*aux_n_slices) | | , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols*aux_n_slices) | |
| , use_aux_mem (copy_aux_mem ? false : true ) | | , mem_state (copy_aux_mem ? 0 : (strict ? 2 : 1) ) | |
| , mat_ptrs (mat_ptrs ) | | , mat_ptrs (mat_ptrs ) | |
| , mem (copy_aux_mem ? mem : aux_mem ) | | , mem (copy_aux_mem ? mem : aux_mem ) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| if(copy_aux_mem == true) | | if(copy_aux_mem == true) | |
| { | | { | |
| init(aux_n_rows, aux_n_cols, aux_n_slices); | | init(aux_n_rows, aux_n_cols, aux_n_slices); | |
|
| | | | |
| syslib::copy_elem( memptr(), aux_mem, n_elem ); | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| } | | } | |
| else | | else | |
| { | | { | |
| create_mat(); | | create_mat(); | |
| } | | } | |
| } | | } | |
| | | | |
| //! construct a cube from a given auxiliary read-only array of eTs. | | //! construct a cube from a given auxiliary read-only array of eTs. | |
| //! the array is copied. | | //! the array is copied. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_col
s, const u32 aux_n_slices) | | Cube<eT>::Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_col
s, const u32 aux_n_slices) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(aux_n_rows, aux_n_cols, aux_n_slices); | | init(aux_n_rows, aux_n_cols, aux_n_slices); | |
| syslib::copy_elem( memptr(), aux_mem, n_elem ); | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| } | | } | |
| | | | |
| //! in-place cube addition | | //! in-place cube addition | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator+=(const Cube<eT>& m) | | Cube<eT>::operator+=(const Cube<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "cube addition"); | | arma_debug_assert_same_size(*this, m, "cube addition"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] += m_mem[i]; | | | |
| out_mem[j] += m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] += m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place cube subtraction | | //! in-place cube subtraction | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator-=(const Cube<eT>& m) | | Cube<eT>::operator-=(const Cube<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "cube subtraction"); | | arma_debug_assert_same_size(*this, m, "cube subtraction"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] -= m_mem[i]; | | | |
| out_mem[j] -= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] -= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise cube multiplication | | //! in-place element-wise cube multiplication | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator%=(const Cube<eT>& m) | | Cube<eT>::operator%=(const Cube<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "element-wise cube multiplication")
; | | arma_debug_assert_same_size(*this, m, "element-wise cube multiplication")
; | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] *= m_mem[i]; | | | |
| out_mem[j] *= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] *= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise cube division | | //! in-place element-wise cube division | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator/=(const Cube<eT>& m) | | Cube<eT>::operator/=(const Cube<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "element-wise cube division"); | | arma_debug_assert_same_size(*this, m, "element-wise cube division"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_div( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] /= m_mem[i]; | | | |
| out_mem[j] /= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] /= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! for constructing a complex cube out of two non-complex cubes | | //! for constructing a complex cube out of two non-complex cubes | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Cube<eT>::Cube | | Cube<eT>::Cube | |
| ( | | ( | |
| const BaseCube<typename Cube<eT>::pod_type,T1>& A, | | const BaseCube<typename Cube<eT>::pod_type,T1>& A, | |
| const BaseCube<typename Cube<eT>::pod_type,T2>& B | | const BaseCube<typename Cube<eT>::pod_type,T2>& B | |
| ) | | ) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
|
| arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil | | init(A,B); | |
| e-time abort if eT isn't std::complex | | | |
| | | | |
| typedef typename T1::elem_type T; | | | |
| arma_type_check< is_complex<T>::value == true >::apply(); //!< compile- | | | |
| time abort if T is std::complex | | | |
| | | | |
| isnt_same_type<std::complex<T>, eT>::check(); //!< compile-time abort i | | | |
| f types are not compatible | | | |
| | | | |
| const unwrap_cube<T1> tmp_A(A.get_ref()); | | | |
| const unwrap_cube<T2> tmp_B(B.get_ref()); | | | |
| | | | |
| const Cube<T>& X = tmp_A.M; | | | |
| const Cube<T>& Y = tmp_B.M; | | | |
| | | | |
| arma_assert_same_size(X, Y, "Cube()"); | | | |
| | | | |
| init(X.n_rows, X.n_cols, X.n_slices); | | | |
| | | | |
| const T* X_mem = X.mem; | | | |
| const T* Y_mem = Y.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| access::rw(mem[i]) = std::complex<T>(X_mem[i], Y_mem[i]); | | | |
| } | | | |
| } | | } | |
| | | | |
| //! construct a cube from a subview_cube instance (e.g. construct a cube fr
om a delayed subcube operation) | | //! construct a cube from a subview_cube instance (e.g. construct a cube fr
om a delayed subcube operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Cube<eT>::Cube(const subview_cube<eT>& X) | | Cube<eT>::Cube(const subview_cube<eT>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! construct a cube from a subview_cube instance (e.g. construct a cube fr
om a delayed subcube operation) | | //! construct a cube from a subview_cube instance (e.g. construct a cube fr
om a delayed subcube operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator=(const subview_cube<eT>& X) | | Cube<eT>::operator=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::extract(*this, X); | | subview_cube<eT>::extract(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place cube addition (using a subcube on the right-hand-side) | | //! in-place cube addition (using a subcube on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator+=(const subview_cube<eT>& X) | | Cube<eT>::operator+=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::plus_inplace(*this, X); | | subview_cube<eT>::plus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place cube subtraction (using a subcube on the right-hand-side) | | //! in-place cube subtraction (using a subcube on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator-=(const subview_cube<eT>& X) | | Cube<eT>::operator-=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::minus_inplace(*this, X); | | subview_cube<eT>::minus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise cube mutiplication (using a subcube on the right-
hand-side) | | //! in-place element-wise cube mutiplication (using a subcube on the right-
hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator%=(const subview_cube<eT>& X) | | Cube<eT>::operator%=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::schur_inplace(*this, X); | | subview_cube<eT>::schur_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise cube division (using a subcube on the right-hand-
side) | | //! in-place element-wise cube division (using a subcube on the right-hand-
side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::operator/=(const subview_cube<eT>& X) | | Cube<eT>::operator/=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::div_inplace(*this, X); | | subview_cube<eT>::div_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! provide the reference to the matrix representing a single slice | | //! provide the reference to the matrix representing a single slice | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| Mat<eT>& | | Mat<eT>& | |
| Cube<eT>::slice(const u32 in_slice) | | Cube<eT>::slice(const u32 in_slice) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 765 | | skipping to change at line 690 | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2
) || | |
| (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | | (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices)
, | |
| "Cube::subcube(): indices out of bounds or incorrectly used" | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c
ol2, in_slice2); | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c
ol2, in_slice2); | |
| } | | } | |
| | | | |
|
| | | //! creation of subview_cube (generic subcube) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview_cube<eT> | |
| | | Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s | |
| | | lice_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 in_row1 = row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | | |
| | | const u32 in_col1 = col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | | |
| | | const u32 in_slice1 = slice_span.a; | |
| | | const u32 in_slice2 = slice_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 | |
| | | ) || | |
| | | (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) | |
| | | , | |
| | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c | |
| | | ol2, in_slice2); | |
| | | } | |
| | | | |
| | | //! creation of subview_cube (generic subcube) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview_cube<eT> | |
| | | Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s | |
| | | lice_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 in_row1 = row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | | |
| | | const u32 in_col1 = col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | | |
| | | const u32 in_slice1 = slice_span.a; | |
| | | const u32 in_slice2 = slice_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 | |
| | | ) || | |
| | | (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) | |
| | | , | |
| | | "Cube::subcube(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c | |
| | | ol2, in_slice2); | |
| | | } | |
| | | | |
| //! create a cube from OpCube, i.e. run the previously delayed unary operat
ions | | //! create a cube from OpCube, i.e. run the previously delayed unary operat
ions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Cube<eT>::Cube(const OpCube<T1, op_type>& X) | | Cube<eT>::Cube(const OpCube<T1, op_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| op_type::apply(*this, X); | | op_type::apply(*this, X); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 876 | | skipping to change at line 855 | |
| //! create a cube from eOpCube, i.e. run the previously delayed unary opera
tions | | //! create a cube from eOpCube, i.e. run the previously delayed unary opera
tions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename eop_type> | | template<typename T1, typename eop_type> | |
| inline | | inline | |
| Cube<eT>::Cube(const eOpCube<T1, eop_type>& X) | | Cube<eT>::Cube(const eOpCube<T1, eop_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| eop_type::apply(*this, X); | | eop_type::apply(*this, X); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 977 | | skipping to change at line 956 | |
| //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | | //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Cube<eT>::Cube(const GlueCube<T1, T2, glue_type>& X) | | Cube<eT>::Cube(const GlueCube<T1, T2, glue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | | //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| | | | |
| skipping to change at line 1080 | | skipping to change at line 1059 | |
| //! create a cube from eGlue, i.e. run the previously delayed binary operat
ions | | //! create a cube from eGlue, i.e. run the previously delayed binary operat
ions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename eglue_type> | | template<typename T1, typename T2, typename eglue_type> | |
| inline | | inline | |
| Cube<eT>::Cube(const eGlueCube<T1, T2, eglue_type>& X) | | Cube<eT>::Cube(const eGlueCube<T1, T2, eglue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem_slice(0) | | , n_elem_slice(0) | |
| , n_slices(0) | | , n_slices(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , mem_state(0) | |
| , mat_ptrs(mat_ptrs) | | , mat_ptrs(mat_ptrs) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | | //! create a cube from Glue, i.e. run the previously delayed binary operati
ons | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename eglue_type> | | template<typename T1, typename T2, typename eglue_type> | |
| | | | |
| skipping to change at line 1320 | | skipping to change at line 1299 | |
| { | | { | |
| if(arma_isfinite(mem[i]) == false) | | if(arma_isfinite(mem[i]) == false) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | //! returns true if the cube has no elements | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Cube<eT>::is_empty() const | |
| | | { | |
| | | return (n_elem == 0); | |
| | | } | |
| | | | |
| | | //! returns true if the given index is currently in range | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Cube<eT>::in_range(const u32 i) const | |
| | | { | |
| | | return (i < n_elem); | |
| | | } | |
| | | | |
| | | //! returns true if the given location is currently in range | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Cube<eT>::in_range(const u32 in_row, const u32 in_col, const u32 in_slice) | |
| | | const | |
| | | { | |
| | | return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) | |
| | | ); | |
| | | } | |
| | | | |
| //! returns a pointer to array of eTs used by the cube | | //! returns a pointer to array of eTs used by the cube | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT* | | eT* | |
| Cube<eT>::memptr() | | Cube<eT>::memptr() | |
| { | | { | |
| return const_cast<eT*>(mem); | | return const_cast<eT*>(mem); | |
| } | | } | |
| | | | |
| //! returns a pointer to array of eTs used by the cube | | //! returns a pointer to array of eTs used by the cube | |
| | | | |
| skipping to change at line 1377 | | skipping to change at line 1383 | |
| arma_inline | | arma_inline | |
| const eT* | | const eT* | |
| Cube<eT>::slice_colptr(const u32 slice, const u32 col) const | | Cube<eT>::slice_colptr(const u32 slice, const u32 col) const | |
| { | | { | |
| return &mem[ slice*n_elem_slice + col*n_rows ]; | | return &mem[ slice*n_elem_slice + col*n_rows ]; | |
| } | | } | |
| | | | |
| //! print contents of the cube (to the cout stream), | | //! print contents of the cube (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::print(const std::string extra_text) const | | Cube<eT>::print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, true); | | arma_ostream::print(cout, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the cube to a user specified stream, | | //! print contents of the cube to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::print(std::ostream& user_stream, const std::string extra_text) co
nst | | Cube<eT>::print(std::ostream& user_stream, const std::string extra_text) co
nst | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, true); | | arma_ostream::print(user_stream, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the cube (to the cout stream), | | //! print contents of the cube (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified | | //! the stream's state are used as is and are not modified | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::raw_print(const std::string extra_text) const | | Cube<eT>::raw_print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, false); | | arma_ostream::print(cout, *this, false); | |
| } | | } | |
| | | | |
| //! print contents of the cube to a user specified stream, | | //! print contents of the cube to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified. | | //! the stream's state are used as is and are not modified. | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::raw_print(std::ostream& user_stream, const std::string extra_text
) const | | Cube<eT>::raw_print(std::ostream& user_stream, const std::string extra_text
) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| | | | |
| skipping to change at line 1492 | | skipping to change at line 1498 | |
| } | | } | |
| | | | |
| //! fill the cube with the specified value | | //! fill the cube with the specified value | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::fill(const eT val) | | Cube<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_set( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] = val; | | | |
| local_ptr[j] = val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] = val; | | | |
| } | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::zeros() | | Cube<eT>::zeros() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::zeros(const u32 in_rows, const u32 in_cols, const u32 in_slices) | | Cube<eT>::zeros(const u32 in_rows, const u32 in_cols, const u32 in_slices) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
, in_slices = %d") % in_rows % in_cols % in_slices ); | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
, in_slices = %d") % in_rows % in_cols % in_slices ); | |
| | | | |
| set_size(in_rows, in_cols, in_slices); | | set_size(in_rows, in_cols, in_slices); | |
|
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::ones() | | Cube<eT>::ones() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 1548 | | skipping to change at line 1541 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::ones(const u32 in_rows, const u32 in_cols, const u32 in_slices) | | Cube<eT>::ones(const u32 in_rows, const u32 in_cols, const u32 in_slices) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
, in_slices = %d") % in_rows % in_cols % in_slices ); | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
, in_slices = %d") % in_rows % in_cols % in_slices ); | |
| | | | |
| set_size(in_rows, in_cols, in_slices); | | set_size(in_rows, in_cols, in_slices); | |
|
| | | | |
| fill(eT(1)); | | fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::reset() | | Cube<eT>::reset() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(0,0,0); | | init(0,0,0); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | Cube<eT>::set_real(const BaseCube<typename Cube<eT>::pod_type,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Cube_aux::set_real(*this, X); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | Cube<eT>::set_imag(const BaseCube<typename Cube<eT>::pod_type,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Cube_aux::set_imag(*this, X); | |
| | | } | |
| | | | |
| //! save the cube to a file | | //! save the cube to a file | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| Cube<eT>::save(const std::string name, const file_type type, const bool pri
nt_status) const | | Cube<eT>::save(const std::string name, const file_type type, const bool pri
nt_status) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| bool save_okay; | | bool save_okay; | |
| | | | |
| | | | |
| skipping to change at line 1885 | | skipping to change at line 1901 | |
| typename Cube<eT>::const_slice_iterator | | typename Cube<eT>::const_slice_iterator | |
| Cube<eT>::end_slice(const u32 slice_num) const | | Cube<eT>::end_slice(const u32 slice_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bou
nds"); | | arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bou
nds"); | |
| | | | |
| return slice_memptr(slice_num) + n_elem_slice; | | return slice_memptr(slice_num) + n_elem_slice; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<u32 fixed_n_rows, u32 fixed_n_cols, u32 fixed_n_slices> | |
| | | arma_inline | |
| | | void | |
| | | Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::mem_setup() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | if(fixed_n_elem > 0) | |
| | | { | |
| | | access::rw(Cube<eT>::n_rows) = fixed_n_rows; | |
| | | access::rw(Cube<eT>::n_cols) = fixed_n_cols; | |
| | | access::rw(Cube<eT>::n_elem_slice) = fixed_n_rows * fixed_n_cols; | |
| | | access::rw(Cube<eT>::n_slices) = fixed_n_slices; | |
| | | access::rw(Cube<eT>::n_elem) = fixed_n_elem; | |
| | | access::rw(Cube<eT>::mem_state) = 3; | |
| | | access::rw(Cube<eT>::mat_ptrs) = const_cast< const Mat<eT>** >( \ | |
| | | (fixed_n_slices > Cube_prealloc::m | |
| | | at_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local ); | |
| | | access::rw(Cube<eT>::mem) = (fixed_n_elem > Cube_prealloc::m | |
| | | em_n_elem) ? mem_local_extra : mem_local; | |
| | | | |
| | | create_mat(); | |
| | | } | |
| | | else | |
| | | { | |
| | | access::rw(Cube<eT>::n_rows) = 0; | |
| | | access::rw(Cube<eT>::n_cols) = 0; | |
| | | access::rw(Cube<eT>::n_elem_slice) = 0; | |
| | | access::rw(Cube<eT>::n_slices) = 0; | |
| | | access::rw(Cube<eT>::n_elem) = 0; | |
| | | access::rw(Cube<eT>::mem_state) = 3; | |
| | | access::rw(Cube<eT>::mat_ptrs) = 0; | |
| | | access::rw(Cube<eT>::mem) = 0; | |
| | | } | |
| | | } | |
| | | | |
| //! prefix ++ | | //! prefix ++ | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| void | | void | |
| Cube_aux::prefix_pp(Cube<eT>& x) | | Cube_aux::prefix_pp(Cube<eT>& x) | |
| { | | { | |
| eT* memptr = x.memptr(); | | eT* memptr = x.memptr(); | |
| const u32 n_elem = x.n_elem; | | const u32 n_elem = x.n_elem; | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| skipping to change at line 2013 | | skipping to change at line 2064 | |
| | | | |
| //! postfix ++ for complex numbers (work around for limitations of the std:
:complex class) | | //! postfix ++ for complex numbers (work around for limitations of the std:
:complex class) | |
| template<typename T> | | template<typename T> | |
| arma_inline | | arma_inline | |
| void | | void | |
| Cube_aux::postfix_mm(Cube< std::complex<T> >& x) | | Cube_aux::postfix_mm(Cube< std::complex<T> >& x) | |
| { | | { | |
| x -= T(1); | | x -= T(1); | |
| } | | } | |
| | | | |
|
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_real(Cube<eT>& out, const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Cube::set_real()" ); | |
| | | | |
| | | out = A; | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | (is_Cube<T1>::value == true) ? Cube_aux::set_real_via_unwrap(out, X) : Cu | |
| | | be_aux::set_real_via_proxy(out, X); | |
| | | } | |
| | | | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | (is_Cube<T1>::value == true) ? Cube_aux::set_imag_via_unwrap(out, X) : Cu | |
| | | be_aux::set_imag_via_proxy(out, X); | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_real_via_unwrap(Cube< std::complex<T> >& out, const BaseCube< | |
| | | T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<T>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Cube::set_real()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | const T* A_mem = A.memptr(); | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].real() = A_mem[i]; | |
| | | out_mem[i] = std::complex<T>( A_mem[i], out_mem[i].imag() ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_imag_via_unwrap(Cube< std::complex<T> >& out, const BaseCube< | |
| | | T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const unwrap_cube<T1> tmp(X.get_ref()); | |
| | | const Cube<T>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Cube::set_imag()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | const T* A_mem = A.memptr(); | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | // out_mem[i].imag() = A_mem[i]; | |
| | | out_mem[i] = std::complex<T>(out_mem[i].real(), A_mem[i]); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_real_via_proxy(Cube< std::complex<T> >& out, const BaseCube<T | |
| | | ,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const ProxyCube<T1> P(X.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size( out.n_rows, out.n_cols, out.n_slices, P.n_ro | |
| | | ws, P.n_cols, P.n_slices, "Cube::set_real()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].real() = P[i]; | |
| | | out_mem[i] = std::complex<T>( P[i], out_mem[i].imag() ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Cube_aux::set_imag_via_proxy(Cube< std::complex<T> >& out, const BaseCube<T | |
| | | ,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const ProxyCube<T1> P(X.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size( out.n_rows, out.n_cols, out.n_slices, P.n_ro | |
| | | ws, P.n_cols, P.n_slices, "Cube::set_imag()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].imag() = P[i]; | |
| | | out_mem[i] = std::complex<T>( out_mem[i].real(), P[i] ); | |
| | | } | |
| | | } | |
| | | | |
| | | #ifdef ARMA_EXTRA_CUBE_MEAT | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT) | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 55 change blocks. |
| 248 lines changed or deleted | | 464 lines changed or added | |
|
| Cube_proto.hpp | | Cube_proto.hpp | |
| | | | |
| skipping to change at line 19 | | skipping to change at line 19 | |
| // 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 Cube | | //! \addtogroup Cube | |
| //! @{ | | //! @{ | |
| | | | |
|
| | | struct Cube_prealloc | |
| | | { | |
| | | static const u32 mat_ptrs_size = 4; | |
| | | static const u32 mem_n_elem = 64; | |
| | | }; | |
| | | | |
| //! Dense cube class | | //! Dense cube class | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class Cube : public BaseCube< eT, Cube<eT> > | | class Cube : public BaseCube< eT, Cube<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; //!< the type of ele
ments stored in the cube | | typedef eT elem_type; //!< the type of ele
ments stored in the cube | |
| typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-co
mplex, pod_type is same as eT. otherwise, pod_type is the underlying type u
sed by std::complex | | typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-co
mplex, pod_type is same as eT. otherwise, pod_type is the underlying type u
sed by std::complex | |
| | | | |
| const u32 n_rows; //!< number of rows in each slice (read-only) | | const u32 n_rows; //!< number of rows in each slice (read-only) | |
| const u32 n_cols; //!< number of columns in each slice (read-only) | | const u32 n_cols; //!< number of columns in each slice (read-only) | |
| const u32 n_elem_slice; //!< number of elements in each slice (read-only
) | | const u32 n_elem_slice; //!< number of elements in each slice (read-only
) | |
| const u32 n_slices; //!< number of slices in the cube (read-only) | | const u32 n_slices; //!< number of slices in the cube (read-only) | |
| const u32 n_elem; //!< number of elements in the cube (read-only) | | const u32 n_elem; //!< number of elements in the cube (read-only) | |
|
| const bool use_aux_mem; //!< true if externally managed memory is being | | const u32 mem_state; | |
| used (read-only) | | | |
| | | // mem_state = 0: normal cube that can be resized; | |
| | | // mem_state = 1: use auxiliary memory until change in the number of elem | |
| | | ents is requested; | |
| | | // mem_state = 2: use auxiliary memory and don't allow the number of elem | |
| | | ents to be changed; | |
| | | // mem_state = 3: fixed size via template based size specification. | |
| | | | |
| arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array con
taining pointers to Mat instances (one for each slice) | | arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array con
taining pointers to Mat instances (one for each slice) | |
| arma_aligned const eT* const mem; //!< pointer to the memory u
sed by the cube (memory is read-only) | | arma_aligned const eT* const mem; //!< pointer to the memory u
sed by the cube (memory is read-only) | |
| | | | |
| protected: | | protected: | |
|
| arma_aligned Mat<eT>* mat_ptrs_local[ 16 ]; | | arma_aligned Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; | |
| arma_aligned eT mem_local[ 64 ]; | | arma_aligned eT mem_local[ Cube_prealloc::mem_n_elem ]; | |
| | | | |
| public: | | public: | |
| | | | |
| inline ~Cube(); | | inline ~Cube(); | |
| inline Cube(); | | inline Cube(); | |
| | | | |
| inline Cube(const u32 in_rows, const u32 in_cols, const u32 in_slices); | | inline Cube(const u32 in_rows, const u32 in_cols, const u32 in_slices); | |
| | | | |
|
| inline Cube( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols
, const u32 aux_n_slices, const bool copy_aux_mem = true); | | inline Cube( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols
, const u32 aux_n_slices, const bool copy_aux_mem = true, const bool strict
= true); | |
| inline Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols
, const u32 aux_n_slices); | | inline Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols
, const u32 aux_n_slices); | |
| | | | |
| arma_inline const Cube& operator=(const eT val); | | arma_inline const Cube& operator=(const eT val); | |
| arma_inline const Cube& operator+=(const eT val); | | arma_inline const Cube& operator+=(const eT val); | |
| arma_inline const Cube& operator-=(const eT val); | | arma_inline const Cube& operator-=(const eT val); | |
| arma_inline const Cube& operator*=(const eT val); | | arma_inline const Cube& operator*=(const eT val); | |
| arma_inline const Cube& operator/=(const eT val); | | arma_inline const Cube& operator/=(const eT val); | |
| | | | |
| inline Cube(const Cube& m); | | inline Cube(const Cube& m); | |
| inline const Cube& operator=(const Cube& m); | | inline const Cube& operator=(const Cube& m); | |
| | | | |
| skipping to change at line 85 | | skipping to change at line 96 | |
| | | | |
| arma_inline Mat<eT>& slice(const u32 in_slice); | | arma_inline Mat<eT>& slice(const u32 in_slice); | |
| arma_inline const Mat<eT>& slice(const u32 in_slice) const; | | arma_inline const Mat<eT>& slice(const u32 in_slice) const; | |
| | | | |
| arma_inline subview_cube<eT> slices(const u32 in_slice1, const u32
in_slice2); | | arma_inline subview_cube<eT> slices(const u32 in_slice1, const u32
in_slice2); | |
| arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32
in_slice2) const; | | arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32
in_slice2) const; | |
| | | | |
| arma_inline subview_cube<eT> subcube(const u32 in_row1, const u32 i
n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3
2 in_slice2); | | arma_inline subview_cube<eT> subcube(const u32 in_row1, const u32 i
n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3
2 in_slice2); | |
| arma_inline const subview_cube<eT> subcube(const u32 in_row1, const u32 i
n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3
2 in_slice2) const; | | arma_inline const subview_cube<eT> subcube(const u32 in_row1, const u32 i
n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3
2 in_slice2) const; | |
| | | | |
|
| | | arma_inline subview_cube<eT> subcube(const span& row_span, const sp | |
| | | an& col_span, const span& slice_span); | |
| | | arma_inline const subview_cube<eT> subcube(const span& row_span, const sp | |
| | | an& col_span, const span& slice_span) const; | |
| | | | |
| template<typename T1, typename op_type> inline Cube(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline Cube(con
st OpCube<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Cube& operator=(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Cube& operator=(con
st OpCube<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Cube& operator+=(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Cube& operator+=(con
st OpCube<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Cube& operator-=(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Cube& operator-=(con
st OpCube<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Cube& operator%=(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Cube& operator%=(con
st OpCube<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Cube& operator/=(con
st OpCube<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Cube& operator/=(con
st OpCube<T1, op_type>& X); | |
| | | | |
| template<typename T1, typename eop_type> inline Cube(co
nst eOpCube<T1, eop_type>& X); | | template<typename T1, typename eop_type> inline Cube(co
nst eOpCube<T1, eop_type>& X); | |
| template<typename T1, typename eop_type> inline const Cube& operator=(co
nst eOpCube<T1, eop_type>& X); | | template<typename T1, typename eop_type> inline const Cube& operator=(co
nst eOpCube<T1, eop_type>& X); | |
| template<typename T1, typename eop_type> inline const Cube& operator+=(co
nst eOpCube<T1, eop_type>& X); | | template<typename T1, typename eop_type> inline const Cube& operator+=(co
nst eOpCube<T1, eop_type>& X); | |
| | | | |
| skipping to change at line 130 | | skipping to change at line 144 | |
| arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32
in_slice); | | arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32
in_slice); | |
| arma_inline eT operator() (const u32 in_row, const u32 in_col, const u32
in_slice) const; | | arma_inline eT operator() (const u32 in_row, const u32 in_col, const u32
in_slice) const; | |
| | | | |
| arma_inline const Cube& operator++(); | | arma_inline const Cube& operator++(); | |
| arma_inline void operator++(int); | | arma_inline void operator++(int); | |
| | | | |
| arma_inline const Cube& operator--(); | | arma_inline const Cube& operator--(); | |
| arma_inline void operator--(int); | | arma_inline void operator--(int); | |
| | | | |
| arma_inline bool is_finite() const; | | arma_inline bool is_finite() const; | |
|
| | | arma_inline bool is_empty() const; | |
| | | | |
| | | arma_inline bool in_range(const u32 i) const; | |
| | | arma_inline bool in_range(const u32 in_row, const u32 in_col, const u32 i | |
| | | n_slice) const; | |
| | | | |
| arma_inline eT* memptr(); | | arma_inline eT* memptr(); | |
| arma_inline const eT* memptr() const; | | arma_inline const eT* memptr() const; | |
| | | | |
| arma_inline eT* slice_memptr(const u32 slice); | | arma_inline eT* slice_memptr(const u32 slice); | |
| arma_inline const eT* slice_memptr(const u32 slice) const; | | arma_inline const eT* slice_memptr(const u32 slice) const; | |
| | | | |
| arma_inline eT* slice_colptr(const u32 in_slice, const u32 in_col); | | arma_inline eT* slice_colptr(const u32 in_slice, const u32 in_col); | |
| arma_inline const eT* slice_colptr(const u32 in_slice, const u32 in_col)
const; | | arma_inline const eT* slice_colptr(const u32 in_slice, const u32 in_col)
const; | |
| | | | |
| | | | |
| skipping to change at line 161 | | skipping to change at line 179 | |
| inline void fill(const eT val); | | inline void fill(const eT val); | |
| | | | |
| inline void zeros(); | | inline void zeros(); | |
| inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slic
es); | | inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slic
es); | |
| | | | |
| inline void ones(); | | inline void ones(); | |
| inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slice
s); | | inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slice
s); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| | | | |
|
| | | template<typename T1> inline void set_real(const BaseCube<pod_type,T1>& X | |
| | | ); | |
| | | template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X | |
| | | ); | |
| | | | |
| inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| | | | |
| inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | |
| inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | |
| | | | |
| inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | | inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | |
| inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | | inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | |
| | | | |
| inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | | inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | |
| | | | |
| skipping to change at line 193 | | skipping to change at line 214 | |
| | | | |
| inline iterator end(); | | inline iterator end(); | |
| inline const_iterator end() const; | | inline const_iterator end() const; | |
| | | | |
| inline slice_iterator begin_slice(const u32 slice_num); | | inline slice_iterator begin_slice(const u32 slice_num); | |
| inline const_slice_iterator begin_slice(const u32 slice_num) const; | | inline const_slice_iterator begin_slice(const u32 slice_num) const; | |
| | | | |
| inline slice_iterator end_slice(const u32 slice_num); | | inline slice_iterator end_slice(const u32 slice_num); | |
| inline const_slice_iterator end_slice(const u32 slice_num) const; | | inline const_slice_iterator end_slice(const u32 slice_num) const; | |
| | | | |
|
| | | template<u32 fixed_n_rows, u32 fixed_n_cols, u32 fixed_n_slices> | |
| | | class fixed : public Cube<eT> | |
| | | { | |
| | | private: | |
| | | | |
| | | static const u32 fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_s | |
| | | lices; | |
| | | | |
| | | arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prea | |
| | | lloc::mat_ptrs_size) ? fixed_n_slices : 1 ]; | |
| | | arma_aligned eT mem_local_extra [ (fixed_n_elem > Cube_prea | |
| | | lloc::mem_n_elem) ? fixed_n_elem : 1 ]; | |
| | | | |
| | | arma_inline void mem_setup(); | |
| | | | |
| | | public: | |
| | | | |
| | | inline fixed() { mem_setup(); } | |
| | | | |
| | | inline const Cube& operator=(const eT val) { mem_setup(); Cube<eT>::ope | |
| | | rator=(val); return *this; } | |
| | | | |
| | | template<typename T1> | |
| | | inline fixed(const BaseCube<eT,T1>& A) { mem_setup(); Cube<eT>::operato | |
| | | r=(A.get_ref()); } | |
| | | | |
| | | template<typename T1> | |
| | | inline const Cube& operator=(const BaseCube<eT,T1>& A) { Cube<eT>::oper | |
| | | ator=(A.get_ref()); return *this; } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline explicit fixed(const BaseCube<pod_type,T1>& A, const BaseCube<po | |
| | | d_type,T2>& B) { mem_setup(); Cube<eT>::init(A,B); } | |
| | | }; | |
| | | | |
| | | #ifdef ARMA_EXTRA_CUBE_PROTO | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO) | |
| | | #endif | |
| | | | |
| protected: | | protected: | |
| | | | |
| inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slice
s); | | inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slice
s); | |
| inline void init(const Cube& x); | | inline void init(const Cube& x); | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline void init(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type, | |
| | | T2>& B); | |
| | | | |
| inline void delete_mat(); | | inline void delete_mat(); | |
| inline void create_mat(); | | inline void create_mat(); | |
|
| | | | |
| | | friend class op_reshape; | |
| }; | | }; | |
| | | | |
| class Cube_aux | | class Cube_aux | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x); | | template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x); | |
| template<typename T> arma_inline static void prefix_pp(Cube< std::comple
x<T> >& x); | | template<typename T> arma_inline static void prefix_pp(Cube< std::comple
x<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x); | | template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x); | |
| template<typename T> arma_inline static void postfix_pp(Cube< std::compl
ex<T> >& x); | | template<typename T> arma_inline static void postfix_pp(Cube< std::compl
ex<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x); | | template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x); | |
| template<typename T> arma_inline static void prefix_mm(Cube< std::comple
x<T> >& x); | | template<typename T> arma_inline static void prefix_mm(Cube< std::comple
x<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x); | | template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x); | |
| template<typename T> arma_inline static void postfix_mm(Cube< std::compl
ex<T> >& x); | | template<typename T> arma_inline static void postfix_mm(Cube< std::compl
ex<T> >& x); | |
|
| | | | |
| | | template<typename eT, typename T1> inline static void set_real(Cube<eT>& | |
| | | out, const BaseCube<eT,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_real(Cube< std: | |
| | | :complex<T> >& out, const BaseCube< T,T1>& X); | |
| | | | |
| | | template<typename eT, typename T1> inline static void set_imag(Cube<eT>& | |
| | | out, const BaseCube<eT,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag(Cube< std: | |
| | | :complex<T> >& out, const BaseCube< T,T1>& X); | |
| | | | |
| | | template<typename T, typename T1> inline static void set_real_via_unwrap | |
| | | (Cube< std::complex<T> >& out, const BaseCube< T,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag_via_unwrap | |
| | | (Cube< std::complex<T> >& out, const BaseCube< T,T1>& X); | |
| | | | |
| | | template<typename T, typename T1> inline static void set_real_via_proxy( | |
| | | Cube< std::complex<T> >& out, const BaseCube< T,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag_via_proxy( | |
| | | Cube< std::complex<T> >& out, const BaseCube< T,T1>& X); | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 11 change blocks. |
| 5 lines changed or deleted | | 97 lines changed or added | |
|
| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| | | | |
| //! \addtogroup Mat | | //! \addtogroup Mat | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::~Mat() | | Mat<eT>::~Mat() | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
|
| if(use_aux_mem == false) | | if(mem_state == 0) | |
| { | | { | |
|
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | if(n_elem > Mat_prealloc::mem_n_elem) | |
| { | | { | |
| delete [] mem; | | delete [] mem; | |
| } | | } | |
| } | | } | |
| | | | |
| if(arma_config::debug == true) | | if(arma_config::debug == true) | |
| { | | { | |
| // try to expose buggy user code that accesses deleted objects | | // try to expose buggy user code that accesses deleted objects | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| | | | |
| skipping to change at line 51 | | skipping to change at line 51 | |
| | | | |
| isnt_supported_elem_type<eT>::check(); | | isnt_supported_elem_type<eT>::check(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat() | | Mat<eT>::Mat() | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
| //! construct the matrix to have user specified dimensions | | //! construct the matrix to have user specified dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const u32 in_n_rows, const u32 in_n_cols) | | Mat<eT>::Mat(const u32 in_n_rows, const u32 in_n_cols) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(in_n_rows, in_n_cols); | | init(in_n_rows, in_n_cols); | |
| } | | } | |
| | | | |
| //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | | //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::init(const u32 in_n_rows, const u32 in_n_cols) | | Mat<eT>::init(const u32 in_n_rows, const u32 in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | |
| | | | |
|
| const u32 new_n_elem = in_n_rows * in_n_cols; | | const bool same_size = ( (n_rows == in_n_rows) && (n_cols == in_n_cols) )
; | |
| | | | |
|
| if(n_elem == new_n_elem) | | if(same_size == false) | |
| { | | | |
| access::rw(n_rows) = in_n_rows; | | | |
| access::rw(n_cols) = in_n_cols; | | | |
| } | | | |
| else | | | |
| { | | { | |
|
| | | const u32 t_vec_state = vec_state; | |
| | | const u32 t_mem_state = mem_state; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (use_aux_mem == true), | | (t_mem_state == 3), | |
| "Mat::init(): can't change the amount of memory as auxiliary memory i | | "Mat::init(): size is fixed and hence cannot be changed" | |
| s in use" | | | |
| ); | | ); | |
| | | | |
|
| if(n_elem > sizeof(mem_local)/sizeof(eT) ) | | arma_debug_check | |
| { | | ( | |
| delete [] mem; | | ( | |
| } | | (t_vec_state > 0) && | |
| | | ( | |
| | | ((t_vec_state == 1) && (in_n_cols > 1)) || | |
| | | ((t_vec_state == 2) && (in_n_rows > 1)) | |
| | | ) | |
| | | ), | |
| | | "Mat::init(): object is a row or column vector; requested size is not | |
| | | compatible" | |
| | | ); | |
| | | | |
|
| if(new_n_elem <= sizeof(mem_local)/sizeof(eT) ) | | const u32 old_n_elem = n_elem; | |
| | | const u32 new_n_elem = in_n_rows * in_n_cols; | |
| | | | |
| | | if(old_n_elem == new_n_elem) | |
| { | | { | |
|
| access::rw(mem) = mem_local; | | arma_extra_debug_print("Mat::init(): reusing memory"); | |
| | | | |
| | | access::rw(n_rows) = in_n_rows; | |
| | | access::rw(n_cols) = in_n_cols; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| access::rw(mem) = new(std::nothrow) eT[new_n_elem]; | | arma_debug_check | |
| arma_check( (mem == 0), "Mat::init(): out of memory" ); | | ( | |
| } | | (t_mem_state == 2), | |
| | | "Mat::init(): requested size is not compatible with the size of aux | |
| | | iliary memory" | |
| | | ); | |
| | | | |
| | | if(t_mem_state == 0) | |
| | | { | |
| | | if(old_n_elem > Mat_prealloc::mem_n_elem ) | |
| | | { | |
| | | arma_extra_debug_print("Mat::init(): freeing memory"); | |
| | | | |
|
| access::rw(n_elem) = new_n_elem; | | delete [] mem; | |
| | | } | |
| | | } | |
| | | | |
| | | if(new_n_elem <= Mat_prealloc::mem_n_elem ) | |
| | | { | |
| | | access::rw(mem) = mem_local; | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_extra_debug_print("Mat::init(): allocating memory"); | |
| | | | |
| | | access::rw(mem) = new(std::nothrow) eT[new_n_elem]; | |
| | | | |
| | | arma_check( (mem == 0), "Mat::init(): out of memory" ); | |
| | | } | |
| | | | |
| | | access::rw(n_elem) = new_n_elem; | |
| | | access::rw(n_rows) = in_n_rows; | |
| | | access::rw(n_cols) = in_n_cols; | |
| | | access::rw(mem_state) = 0; | |
| | | } | |
| | | | |
| if(new_n_elem == 0) | | if(new_n_elem == 0) | |
| { | | { | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| } | | } | |
|
| else | | | |
| { | | | |
| access::rw(n_rows) = in_n_rows; | | | |
| access::rw(n_cols) = in_n_cols; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const char* text) | | Mat<eT>::Mat(const char* text) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init( std::string(text) ); | | init( std::string(text) ); | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 163 | | skipping to change at line 200 | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const std::string& text) | | Mat<eT>::Mat(const std::string& text) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(text); | | init(text); | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 300 | | skipping to change at line 338 | |
| } | | } | |
| | | | |
| //! In-place addition of a scalar to all elements of the matrix | | //! In-place addition of a scalar to all elements of the matrix | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const eT val) | | Mat<eT>::operator+=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_plus( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] += val; | | | |
| local_ptr[j] += val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] += val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place subtraction of a scalar from all elements of the matrix | | //! In-place subtraction of a scalar from all elements of the matrix | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const eT val) | | Mat<eT>::operator-=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_minus( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] -= val; | | | |
| local_ptr[j] -= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] -= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place multiplication of all elements of the matrix with a scalar | | //! In-place multiplication of all elements of the matrix with a scalar | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator*=(const eT val) | | Mat<eT>::operator*=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_mul( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] *= val; | | | |
| local_ptr[j] *= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] *= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! In-place division of all elements of the matrix with a scalar | | //! In-place division of all elements of the matrix with a scalar | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const eT val) | | Mat<eT>::operator/=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_div( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| local_ptr[i] /= val; | | | |
| local_ptr[j] /= val; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| local_ptr[i] /= val; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a matrix from a given matrix | | //! construct a matrix from a given matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const Mat<eT>& in_mat) | | Mat<eT>::Mat(const Mat<eT>& in_mat) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") %
this % &in_mat); | | arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") %
this % &in_mat); | |
| | | | |
| init(in_mat); | | init(in_mat); | |
| } | | } | |
| | | | |
| //! construct a matrix from a given matrix | | //! construct a matrix from a given matrix | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 439 | | skipping to change at line 422 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::init(const Mat<eT>& x) | | Mat<eT>::init(const Mat<eT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(this != &x) | | if(this != &x) | |
| { | | { | |
| init(x.n_rows, x.n_cols); | | init(x.n_rows, x.n_cols); | |
|
| syslib::copy_elem( memptr(), x.mem, n_elem ); | | syslib::copy_elem( memptr(), x.mem, x.n_elem ); | |
| | | } | |
| | | } | |
| | | | |
| | | //! for constructing a complex matrix out of two non-complex matrices | |
| | | template<typename eT> | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::init | |
| | | ( | |
| | | const Base<typename Mat<eT>::pod_type,T1>& A, | |
| | | const Base<typename Mat<eT>::pod_type,T2>& B | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil | |
| | | e-time abort if eT isn't std::complex | |
| | | | |
| | | typedef typename T1::elem_type T; | |
| | | arma_type_check< is_complex<T>::value == true >::apply(); //!< compile- | |
| | | time abort if T is std::complex | |
| | | | |
| | | isnt_same_type<std::complex<T>, eT>::check(); //!< compile-time abort i | |
| | | f types are not compatible | |
| | | | |
| | | const unwrap<T1> tmp_A(A.get_ref()); | |
| | | const unwrap<T2> tmp_B(B.get_ref()); | |
| | | | |
| | | const Mat<T>& X = tmp_A.M; | |
| | | const Mat<T>& Y = tmp_B.M; | |
| | | | |
| | | arma_assert_same_size(X, Y, "Mat()"); | |
| | | | |
| | | init(X.n_rows, Y.n_cols); | |
| | | | |
| | | const T* X_mem = X.mem; | |
| | | const T* Y_mem = Y.mem; | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | access::rw(mem[i]) = std::complex<T>(X_mem[i], Y_mem[i]); | |
| | | } | |
| | | } | |
| | | | |
| | | //! try to steal the memory from a given matrix; | |
| | | //! if memory can't be stolen, copy the given matrix | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::steal_mem(Mat<eT>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(this != &x) | |
| | | { | |
| | | const u32 x_n_rows = x.n_rows; | |
| | | const u32 x_n_cols = x.n_cols; | |
| | | const u32 x_n_elem = x.n_elem; | |
| | | const u32 x_vec_state = x.vec_state; | |
| | | const u32 x_mem_state = x.mem_state; | |
| | | | |
| | | const u32 t_vec_state = vec_state; | |
| | | | |
| | | bool layout_ok = false; | |
| | | | |
| | | if(t_vec_state == x_vec_state) | |
| | | { | |
| | | layout_ok = true; | |
| | | } | |
| | | else | |
| | | { | |
| | | if( (t_vec_state == 1) && ( x_n_cols <= 1) ) | |
| | | { | |
| | | layout_ok = true; | |
| | | } | |
| | | | |
| | | if( (t_vec_state == 2) && ( x_n_rows <= 1) ) | |
| | | { | |
| | | layout_ok = true; | |
| | | } | |
| | | } | |
| | | | |
| | | if( (x_mem_state == 0) && (x_n_elem > Mat_prealloc::mem_n_elem) && (lay | |
| | | out_ok == true) ) | |
| | | { | |
| | | reset(); | |
| | | | |
| | | access::rw(n_rows) = x_n_rows; | |
| | | access::rw(n_cols) = x_n_cols; | |
| | | access::rw(n_elem) = x_n_elem; | |
| | | access::rw(mem) = x.mem; | |
| | | | |
| | | access::rw(x.n_rows) = 0; | |
| | | access::rw(x.n_cols) = 0; | |
| | | access::rw(x.n_elem) = 0; | |
| | | access::rw(x.mem) = 0; | |
| | | } | |
| | | else | |
| | | { | |
| | | init(x); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! construct a matrix from a given auxiliary array of eTs. | | //! construct a matrix from a given auxiliary array of eTs. | |
| //! if copy_aux_mem is true, new memory is allocated and the array is copie
d. | | //! if copy_aux_mem is true, new memory is allocated and the array is copie
d. | |
| //! if copy_aux_mem is false, the auxiliary array is used directly (without
allocating memory and copying). | | //! if copy_aux_mem is false, the auxiliary array is used directly (without
allocating memory and copying). | |
| //! the default is to copy the array. | | //! the default is to copy the array. | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Mat<eT>::Mat(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const | | Mat<eT>::Mat(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const | |
| bool copy_aux_mem) | | bool copy_aux_mem, const bool strict) | |
| : n_rows (copy_aux_mem ? 0 : aux_n_rows ) | | : n_rows (copy_aux_mem ? 0 : aux_n_rows ) | |
| , n_cols (copy_aux_mem ? 0 : aux_n_cols ) | | , n_cols (copy_aux_mem ? 0 : aux_n_cols ) | |
| , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols) | | , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols) | |
| , use_aux_mem(copy_aux_mem ? false : true ) | | , vec_state( 0 ) | |
| , mem (copy_aux_mem ? mem : aux_mem ) | | , mem_state(copy_aux_mem ? 0 : ( strict ? 2 : 1 ) ) | |
| | | , mem (copy_aux_mem ? mem : aux_mem ) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| if(copy_aux_mem == true) | | if(copy_aux_mem == true) | |
| { | | { | |
| init(aux_n_rows, aux_n_cols); | | init(aux_n_rows, aux_n_cols); | |
|
| | | | |
| syslib::copy_elem( memptr(), aux_mem, n_elem ); | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! construct a matrix from a given auxiliary read-only array of eTs. | | //! construct a matrix from a given auxiliary read-only array of eTs. | |
| //! the array is copied. | | //! the array is copied. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | | Mat<eT>::Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(aux_n_rows, aux_n_cols); | | init(aux_n_rows, aux_n_cols); | |
|
| | | | |
| syslib::copy_elem( memptr(), aux_mem, n_elem ); | | syslib::copy_elem( memptr(), aux_mem, n_elem ); | |
| } | | } | |
| | | | |
| //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. | | //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. | |
| //! This constructor is NOT intended for usage by user code. | | //! This constructor is NOT intended for usage by user code. | |
| //! Its sole purpose is to be used by the Cube class. | | //! Its sole purpose is to be used by the Cube class. | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons
t u32 aux_n_cols) | | Mat<eT>::Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons
t u32 aux_n_cols) | |
|
| : n_rows (aux_n_rows ) | | : n_rows (aux_n_rows ) | |
| , n_cols (aux_n_cols ) | | , n_cols (aux_n_cols ) | |
| , n_elem (aux_n_rows*aux_n_cols) | | , n_elem (aux_n_rows*aux_n_cols) | |
| , use_aux_mem(true ) | | , vec_state(0 ) | |
| , mem (aux_mem ) | | , mem_state(3 ) | |
| | | , mem (aux_mem ) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
| //! in-place matrix addition | | //! in-place matrix addition | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const Mat<eT>& m) | | Mat<eT>::operator+=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "matrix addition"); | | arma_debug_assert_same_size(*this, m, "matrix addition"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] += m_mem[i]; | | | |
| out_mem[j] += m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] += m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix subtraction | | //! in-place matrix subtraction | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const Mat<eT>& m) | | Mat<eT>::operator-=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "matrix subtraction"); | | arma_debug_assert_same_size(*this, m, "matrix subtraction"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] -= m_mem[i]; | | | |
| out_mem[j] -= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] -= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix multiplication | | //! in-place matrix multiplication | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator*=(const Mat<eT>& m) | | Mat<eT>::operator*=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| glue_times::apply_inplace(*this, m); | | glue_times::apply_inplace(*this, m); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix multiplication | | //! in-place element-wise matrix multiplication | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator%=(const Mat<eT>& m) | | Mat<eT>::operator%=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "element-wise matrix multplication"
); | | arma_debug_assert_same_size(*this, m, "element-wise matrix multplication"
); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] *= m_mem[i]; | | | |
| out_mem[j] *= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] *= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix division | | //! in-place element-wise matrix division | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const Mat<eT>& m) | | Mat<eT>::operator/=(const Mat<eT>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(*this, m, "element-wise matrix division"); | | arma_debug_assert_same_size(*this, m, "element-wise matrix division"); | |
| | | | |
|
| const u32 local_n_elem = m.n_elem; | | arrayops::inplace_div( memptr(), m.memptr(), n_elem ); | |
| | | | |
| eT* out_mem = (*this).memptr(); | | | |
| const eT* m_mem = m.memptr(); | | | |
| | | | |
| u32 i,j; | | | |
| | | | |
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | | |
| { | | | |
| out_mem[i] /= m_mem[i]; | | | |
| out_mem[j] /= m_mem[j]; | | | |
| } | | | |
| | | | |
| if(i < local_n_elem) | | | |
| { | | | |
| out_mem[i] /= m_mem[i]; | | | |
| } | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! for constructing a complex matrix out of two non-complex matrices | | //! for constructing a complex matrix out of two non-complex matrices | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Mat<eT>::Mat | | Mat<eT>::Mat | |
| ( | | ( | |
| const Base<typename Mat<eT>::pod_type,T1>& A, | | const Base<typename Mat<eT>::pod_type,T1>& A, | |
| const Base<typename Mat<eT>::pod_type,T2>& B | | const Base<typename Mat<eT>::pod_type,T2>& B | |
| ) | | ) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
|
| arma_type_check< is_complex<eT>::value == false >::apply(); //!< compil | | init(A,B); | |
| e-time abort if eT isn't std::complex | | | |
| | | | |
| typedef typename T1::elem_type T; | | | |
| arma_type_check< is_complex<T>::value == true >::apply(); //!< compile- | | | |
| time abort if T is std::complex | | | |
| | | | |
| isnt_same_type<std::complex<T>, eT>::check(); //!< compile-time abort i | | | |
| f types are not compatible | | | |
| | | | |
| const unwrap<T1> tmp_A(A.get_ref()); | | | |
| const unwrap<T2> tmp_B(B.get_ref()); | | | |
| | | | |
| const Mat<T>& X = tmp_A.M; | | | |
| const Mat<T>& Y = tmp_B.M; | | | |
| | | | |
| arma_assert_same_size(X, Y, "Mat()"); | | | |
| | | | |
| init(X.n_rows, Y.n_cols); | | | |
| | | | |
| const T* X_mem = X.mem; | | | |
| const T* Y_mem = Y.mem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | | |
| { | | | |
| access::rw(mem[i]) = std::complex<T>(X_mem[i], Y_mem[i]); | | | |
| } | | | |
| } | | } | |
| | | | |
| //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | | //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const subview<eT>& X) | | Mat<eT>::Mat(const subview<eT>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | | //! construct a matrix from subview (e.g. construct a matrix from a delayed
submatrix operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator=(const subview<eT>& X) | | Mat<eT>::operator=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::extract(*this, X); | | subview<eT>::extract(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix addition (using a submatrix on the right-hand-side) | | //! in-place matrix addition (using a submatrix on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const subview<eT>& X) | | Mat<eT>::operator+=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::plus_inplace(*this, X); | | subview<eT>::plus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix subtraction (using a submatrix on the right-hand-side) | | //! in-place matrix subtraction (using a submatrix on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const subview<eT>& X) | | Mat<eT>::operator-=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::minus_inplace(*this, X); | | subview<eT>::minus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix mutiplication (using a submatrix on the right-hand-side
) | | //! in-place matrix mutiplication (using a submatrix on the right-hand-side
) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator*=(const subview<eT>& X) | | Mat<eT>::operator*=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| glue_times::apply_inplace(*this, X); | | glue_times::apply_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix mutiplication (using a submatrix on the ri
ght-hand-side) | | //! in-place element-wise matrix mutiplication (using a submatrix on the ri
ght-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator%=(const subview<eT>& X) | | Mat<eT>::operator%=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::schur_inplace(*this, X); | | subview<eT>::schur_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix division (using a submatrix on the right-h
and-side) | | //! in-place element-wise matrix division (using a submatrix on the right-h
and-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const subview<eT>& X) | | Mat<eT>::operator/=(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview<eT>::div_inplace(*this, X); | | subview<eT>::div_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a matrix from a subview_cube instance | | //! construct a matrix from a subview_cube instance | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const subview_cube<eT>& x) | | Mat<eT>::Mat(const subview_cube<eT>& x) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(x); | | this->operator=(x); | |
| } | | } | |
| | | | |
| //! construct a matrix from a subview_cube instance | | //! construct a matrix from a subview_cube instance | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator=(const subview_cube<eT>& X) | | Mat<eT>::operator=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::extract(*this, X); | | subview_cube<eT>::extract(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix addition (using a single-slice subcube on the right-han
d-side) | | //! in-place matrix addition (using a single-slice subcube on the right-han
d-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const subview_cube<eT>& X) | | Mat<eT>::operator+=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::plus_inplace(*this, X); | | subview_cube<eT>::plus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix subtraction (using a single-slice subcube on the right-
hand-side) | | //! in-place matrix subtraction (using a single-slice subcube on the right-
hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const subview_cube<eT>& X) | | Mat<eT>::operator-=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::minus_inplace(*this, X); | | subview_cube<eT>::minus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix mutiplication (using a single-slice subcube on the righ
t-hand-side) | | //! in-place matrix mutiplication (using a single-slice subcube on the righ
t-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator*=(const subview_cube<eT>& X) | | Mat<eT>::operator*=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Mat<eT> tmp(X); | | const Mat<eT> tmp(X); | |
| glue_times::apply_inplace(*this, tmp); | | glue_times::apply_inplace(*this, tmp); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix mutiplication (using a single-slice subcub
e on the right-hand-side) | | //! in-place element-wise matrix mutiplication (using a single-slice subcub
e on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator%=(const subview_cube<eT>& X) | | Mat<eT>::operator%=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::schur_inplace(*this, X); | | subview_cube<eT>::schur_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix division (using a single-slice subcube on
the right-hand-side) | | //! in-place element-wise matrix division (using a single-slice subcube on
the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const subview_cube<eT>& X) | | Mat<eT>::operator/=(const subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| subview_cube<eT>::div_inplace(*this, X); | | subview_cube<eT>::div_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | | //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const diagview<eT>& X) | | Mat<eT>::Mat(const diagview<eT>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| this->operator=(X); | | this->operator=(X); | |
| } | | } | |
| | | | |
| //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | | //! construct a matrix from diagview (e.g. construct a matrix from a delaye
d diag operation) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator=(const diagview<eT>& X) | | Mat<eT>::operator=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>::extract(*this, X); | | diagview<eT>::extract(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix addition (using a diagview on the right-hand-side) | | //! in-place matrix addition (using a diagview on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator+=(const diagview<eT>& X) | | Mat<eT>::operator+=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>::plus_inplace(*this, X); | | diagview<eT>::plus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix subtraction (using a diagview on the right-hand-side) | | //! in-place matrix subtraction (using a diagview on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator-=(const diagview<eT>& X) | | Mat<eT>::operator-=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>::minus_inplace(*this, X); | | diagview<eT>::minus_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix mutiplication (using a diagview on the right-hand-side) | | //! in-place matrix mutiplication (using a diagview on the right-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator*=(const diagview<eT>& X) | | Mat<eT>::operator*=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| glue_times::apply_inplace(*this, X); | | glue_times::apply_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix mutiplication (using a diagview on the rig
ht-hand-side) | | //! in-place element-wise matrix mutiplication (using a diagview on the rig
ht-hand-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator%=(const diagview<eT>& X) | | Mat<eT>::operator%=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>::schur_inplace(*this, X); | | diagview<eT>::schur_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place element-wise matrix division (using a diagview on the right-ha
nd-side) | | //! in-place element-wise matrix division (using a diagview on the right-ha
nd-side) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator/=(const diagview<eT>& X) | | Mat<eT>::operator/=(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>::div_inplace(*this, X); | | diagview<eT>::div_inplace(*this, X); | |
|
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| mat_injector< Mat<eT> > | | mat_injector< Mat<eT> > | |
| Mat<eT>::operator<<(const eT val) | | Mat<eT>::operator<<(const eT val) | |
| { | | { | |
| return mat_injector< Mat<eT> >(*this, val); | | return mat_injector< Mat<eT> >(*this, val); | |
| } | | } | |
| | | | |
| skipping to change at line 1115 | | skipping to change at line 1137 | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols), | |
| "Mat::submat(): indices out of bounds or incorrectly used" | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | | return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | |
| } | | } | |
| | | | |
|
| | | //! creation of subview (submatrix) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | subview<eT> | |
| | | Mat<eT>::submat(const span& row_span, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 in_row1 = row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | | |
| | | const u32 in_col1 = col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | |
| | | in_col2 >= n_cols), | |
| | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | |
| | | } | |
| | | | |
| | | //! creation of subview (generic submatrix) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview<eT> | |
| | | Mat<eT>::submat(const span& row_span, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 in_row1 = row_span.a; | |
| | | const u32 in_row2 = row_span.b; | |
| | | | |
| | | const u32 in_col1 = col_span.a; | |
| | | const u32 in_col2 = col_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | |
| | | in_col2 >= n_cols), | |
| | | "Mat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2); | |
| | | } | |
| | | | |
| //! creation of diagview (diagonal) | | //! creation of diagview (diagonal) | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| diagview<eT> | | diagview<eT> | |
| Mat<eT>::diag(const s32 in_id) | | Mat<eT>::diag(const s32 in_id) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 row_offset = (in_id < 0) ? -in_id : 0; | | const u32 row_offset = (in_id < 0) ? -in_id : 0; | |
| const u32 col_offset = (in_id > 0) ? in_id : 0; | | const u32 col_offset = (in_id > 0) ? in_id : 0; | |
| | | | |
| skipping to change at line 1137 | | skipping to change at line 1205 | |
| ( | | ( | |
| (row_offset >= n_rows) || (col_offset >= n_cols), | | (row_offset >= n_rows) || (col_offset >= n_cols), | |
| "Mat::diag(): requested diagonal out of bounds" | | "Mat::diag(): requested diagonal out of bounds" | |
| ); | | ); | |
| | | | |
| const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); | | const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); | |
| | | | |
| return diagview<eT>(*this, row_offset, col_offset, len); | | return diagview<eT>(*this, row_offset, col_offset, len); | |
| } | | } | |
| | | | |
|
| //! creation of diagview (diagonal) | | //! creation of diagview (diagonal) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const diagview<eT> | |
| | | Mat<eT>::diag(const s32 in_id) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 row_offset = (in_id < 0) ? -in_id : 0; | |
| | | const u32 col_offset = (in_id > 0) ? in_id : 0; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (row_offset >= n_rows) || (col_offset >= n_cols), | |
| | | "Mat::diag(): requested diagonal out of bounds" | |
| | | ); | |
| | | | |
| | | const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); | |
| | | | |
| | | return diagview<eT>(*this, row_offset, col_offset, len); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::swap_rows(const u32 in_row1, const u32 in_row2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 >= n_rows) || (in_row2 >= n_rows), | |
| | | "Mat::swap_rows(): out of bounds" | |
| | | ); | |
| | | | |
| | | for(u32 col=0; col<n_cols; ++col) | |
| | | { | |
| | | const u32 offset = col*n_rows; | |
| | | const u32 pos1 = in_row1 + offset; | |
| | | const u32 pos2 = in_row2 + offset; | |
| | | | |
| | | const eT tmp = mem[pos1]; | |
| | | access::rw(mem[pos1]) = mem[pos2]; | |
| | | access::rw(mem[pos2]) = tmp; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::swap_cols(const u32 in_col1, const u32 in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 >= n_cols) || (in_col2 >= n_cols), | |
| | | "Mat::swap_cols(): out of bounds" | |
| | | ); | |
| | | | |
| | | eT* ptr1 = colptr(in_col1); | |
| | | eT* ptr2 = colptr(in_col2); | |
| | | | |
| | | for(u32 row=0; row<n_rows; ++row) | |
| | | { | |
| | | const eT tmp = ptr1[row]; | |
| | | ptr1[row] = ptr2[row]; | |
| | | ptr2[row] = tmp; | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | //! remove specified row | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::shed_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( row_num >= n_rows, "Mat::shed_row(): out of bounds"); | |
| | | | |
| | | shed_rows(row_num, row_num); | |
| | | } | |
| | | | |
| | | //! remove specified column | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::shed_col(const u32 col_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( col_num >= n_cols, "Mat::shed_col(): out of bounds"); | |
| | | | |
| | | shed_cols(col_num, col_num); | |
| | | } | |
| | | | |
| | | //! remove specified rows | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::shed_rows(const u32 in_row1, const u32 in_row2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| | | "Mat::shed_rows(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const u32 n_keep_front = in_row1; | |
| | | const u32 n_keep_back = n_rows - (in_row2 + 1); | |
| | | | |
| | | Mat<eT> X(n_keep_front + n_keep_back, n_cols); | |
| | | | |
| | | if(n_keep_front > 0) | |
| | | { | |
| | | X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) ); | |
| | | } | |
| | | | |
| | | if(n_keep_back > 0) | |
| | | { | |
| | | X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+ | |
| | | 1), (n_rows-1) ); | |
| | | } | |
| | | | |
| | | steal_mem(X); | |
| | | } | |
| | | | |
| | | //! remove specified columns | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::shed_cols(const u32 in_col1, const u32 in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| | | "Mat::shed_cols(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const u32 n_keep_front = in_col1; | |
| | | const u32 n_keep_back = n_cols - (in_col2 + 1); | |
| | | | |
| | | Mat<eT> X(n_rows, n_keep_front + n_keep_back); | |
| | | | |
| | | if(n_keep_front > 0) | |
| | | { | |
| | | X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) ); | |
| | | } | |
| | | | |
| | | if(n_keep_back > 0) | |
| | | { | |
| | | X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+ | |
| | | 1), (n_cols-1) ); | |
| | | } | |
| | | | |
| | | steal_mem(X); | |
| | | } | |
| | | | |
| | | //! insert N rows at the specified row position, | |
| | | //! optionally setting the elements of the inserted rows to zero | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::insert_rows(const u32 row_num, const u32 N, const bool set_to_zero | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const u32 t_n_rows = n_rows; | |
| | | const u32 t_n_cols = n_cols; | |
| | | | |
| | | const u32 A_n_rows = row_num; | |
| | | const u32 B_n_rows = t_n_rows - row_num; | |
| | | | |
| | | // insertion at row_num == n_rows is in effect an append operation | |
| | | arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): out of bound | |
| | | s"); | |
| | | | |
| | | if(N > 0) | |
| | | { | |
| | | Mat<eT> out(t_n_rows + N, t_n_cols); | |
| | | | |
| | | if(A_n_rows > 0) | |
| | | { | |
| | | out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); | |
| | | } | |
| | | | |
| | | if(B_n_rows > 0) | |
| | | { | |
| | | out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1); | |
| | | } | |
| | | | |
| | | if(set_to_zero == true) | |
| | | { | |
| | | out.rows(row_num, row_num + N - 1).zeros(); | |
| | | } | |
| | | | |
| | | steal_mem(out); | |
| | | } | |
| | | } | |
| | | | |
| | | //! insert N columns at the specified column position, | |
| | | //! optionally setting the elements of the inserted columns to zero | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const diagview<eT> | | void | |
| Mat<eT>::diag(const s32 in_id) const | | Mat<eT>::insert_cols(const u32 col_num, const u32 N, const bool set_to_zero | |
| | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const u32 row_offset = (in_id < 0) ? -in_id : 0; | | const u32 t_n_rows = n_rows; | |
| const u32 col_offset = (in_id > 0) ? in_id : 0; | | const u32 t_n_cols = n_cols; | |
| | | | |
|
| arma_debug_check | | const u32 A_n_cols = col_num; | |
| ( | | const u32 B_n_cols = t_n_cols - col_num; | |
| (row_offset >= n_rows) || (col_offset >= n_cols), | | | |
| "Mat::diag(): requested diagonal out of bounds" | | | |
| ); | | | |
| | | | |
|
| const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); | | // insertion at col_num == n_cols is in effect an append operation | |
| | | arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): out of bound | |
| | | s"); | |
| | | | |
|
| return diagview<eT>(*this, row_offset, col_offset, len); | | if(N > 0) | |
| | | { | |
| | | Mat<eT> out(t_n_rows, t_n_cols + N); | |
| | | | |
| | | if(A_n_cols > 0) | |
| | | { | |
| | | out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); | |
| | | } | |
| | | | |
| | | if(B_n_cols > 0) | |
| | | { | |
| | | out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1); | |
| | | } | |
| | | | |
| | | if(set_to_zero == true) | |
| | | { | |
| | | out.cols(col_num, col_num + N - 1).zeros(); | |
| | | } | |
| | | | |
| | | steal_mem(out); | |
| | | } | |
| } | | } | |
| | | | |
|
| | | //! insert the given object at the specified row position; | |
| | | //! the given object must have the same number of columns as the matrix | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::swap_rows(const u32 in_row1, const u32 in_row2) | | Mat<eT>::insert_rows(const u32 row_num, const Base<eT,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check | | const unwrap<T1> tmp(X.get_ref()); | |
| ( | | const Mat<eT>& C = tmp.M; | |
| (in_row1 >= n_rows) || (in_row2 >= n_rows), | | | |
| "Mat::swap_rows(): out of bounds" | | | |
| ); | | | |
| | | | |
|
| for(u32 col=0; col<n_cols; ++col) | | const u32 N = C.n_rows; | |
| | | | |
| | | const u32 t_n_rows = n_rows; | |
| | | const u32 t_n_cols = n_cols; | |
| | | | |
| | | const u32 A_n_rows = row_num; | |
| | | const u32 B_n_rows = t_n_rows - row_num; | |
| | | | |
| | | // insertion at row_num == n_rows is in effect an append operation | |
| | | arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): out of bou | |
| | | nds"); | |
| | | arma_debug_check( (C.n_cols != t_n_cols), "Mat::insert_rows(): given obje | |
| | | ct has an incompatible number of columns"); | |
| | | | |
| | | if(N > 0) | |
| { | | { | |
|
| const u32 offset = col*n_rows; | | Mat<eT> out(t_n_rows + N, t_n_cols); | |
| const u32 pos1 = in_row1 + offset; | | | |
| const u32 pos2 = in_row2 + offset; | | | |
| | | | |
|
| const eT tmp = mem[pos1]; | | if(A_n_rows > 0) | |
| access::rw(mem[pos1]) = mem[pos2]; | | { | |
| access::rw(mem[pos2]) = tmp; | | out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); | |
| } | | } | |
| | | | |
|
| | | if(B_n_rows > 0) | |
| | | { | |
| | | out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows - 1) | |
| | | ; | |
| | | } | |
| | | | |
| | | out.rows(row_num, row_num + N - 1) = C; | |
| | | | |
| | | steal_mem(out); | |
| | | } | |
| } | | } | |
| | | | |
|
| | | //! insert the given object at the specified column position; | |
| | | //! the given object must have the same number of rows as the matrix | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::swap_cols(const u32 in_col1, const u32 in_col2) | | Mat<eT>::insert_cols(const u32 col_num, const Base<eT,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check | | const unwrap<T1> tmp(X.get_ref()); | |
| ( | | const Mat<eT>& C = tmp.M; | |
| (in_col1 >= n_cols) || (in_col2 >= n_cols), | | | |
| "Mat::swap_cols(): out of bounds" | | | |
| ); | | | |
| | | | |
|
| eT* ptr1 = colptr(in_col1); | | const u32 N = C.n_cols; | |
| eT* ptr2 = colptr(in_col2); | | | |
| | | | |
|
| for(u32 row=0; row<n_rows; ++row) | | const u32 t_n_rows = n_rows; | |
| | | const u32 t_n_cols = n_cols; | |
| | | | |
| | | const u32 A_n_cols = col_num; | |
| | | const u32 B_n_cols = t_n_cols - col_num; | |
| | | | |
| | | // insertion at col_num == n_cols is in effect an append operation | |
| | | arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): out of bou | |
| | | nds"); | |
| | | arma_debug_check( (C.n_rows != t_n_rows), "Mat::insert_cols(): given obje | |
| | | ct has an incompatible number of rows"); | |
| | | | |
| | | if(N > 0) | |
| { | | { | |
|
| const eT tmp = ptr1[row]; | | Mat<eT> out(t_n_rows, t_n_cols + N); | |
| ptr1[row] = ptr2[row]; | | | |
| ptr2[row] = tmp; | | if(A_n_cols > 0) | |
| } | | { | |
| | | out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); | |
| | | } | |
| | | | |
|
| | | if(B_n_cols > 0) | |
| | | { | |
| | | out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols - 1) | |
| | | ; | |
| | | } | |
| | | | |
| | | out.cols(col_num, col_num + N - 1) = C; | |
| | | | |
| | | steal_mem(out); | |
| | | } | |
| } | | } | |
| | | | |
| //! create a matrix from Op, i.e. run the previously delayed unary operatio
ns | | //! create a matrix from Op, i.e. run the previously delayed unary operatio
ns | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const Op<T1, op_type>& X) | | Mat<eT>::Mat(const Op<T1, op_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| op_type::apply(*this, X); | | op_type::apply(*this, X); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1333 | | skipping to change at line 1664 | |
| } | | } | |
| | | | |
| //! create a matrix from eOp, i.e. run the previously delayed unary operati
ons | | //! create a matrix from eOp, i.e. run the previously delayed unary operati
ons | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename eop_type> | | template<typename T1, typename eop_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const eOp<T1, eop_type>& X) | | Mat<eT>::Mat(const eOp<T1, eop_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| | | | |
| eop_type::apply(*this, X); | | eop_type::apply(*this, X); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1443 | | skipping to change at line 1775 | |
| } | | } | |
| | | | |
| //! EXPERIMENTAL | | //! EXPERIMENTAL | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename op_type> | | template<typename T1, typename op_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X) | | Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| op_type::apply(*this, X); | | op_type::apply(*this, X); | |
| } | | } | |
| | | | |
| //! EXPERIMENTAL | | //! EXPERIMENTAL | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 1544 | | skipping to change at line 1877 | |
| } | | } | |
| | | | |
| //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | | //! create a matrix from Glue, i.e. run the previously delayed binary opera
tions | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) | | Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| isnt_same_type<eT, typename T2::elem_type>::check(); | | isnt_same_type<eT, typename T2::elem_type>::check(); | |
| | | | |
| glue_type::apply(*this, X); | | glue_type::apply(*this, X); | |
| } | | } | |
| | | | |
| skipping to change at line 1692 | | skipping to change at line 2026 | |
| } | | } | |
| | | | |
| //! create a matrix from eGlue, i.e. run the previously delayed binary oper
ations | | //! create a matrix from eGlue, i.e. run the previously delayed binary oper
ations | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename eglue_type> | | template<typename T1, typename T2, typename eglue_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X) | | Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| isnt_same_type<eT, typename T1::elem_type>::check(); | | isnt_same_type<eT, typename T1::elem_type>::check(); | |
| isnt_same_type<eT, typename T2::elem_type>::check(); | | isnt_same_type<eT, typename T2::elem_type>::check(); | |
| | | | |
| eglue_type::apply(*this, X); | | eglue_type::apply(*this, X); | |
| } | | } | |
| | | | |
| skipping to change at line 1808 | | skipping to change at line 2143 | |
| } | | } | |
| | | | |
| //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously dela
yed binary operations | | //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously dela
yed binary operations | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| inline | | inline | |
| Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X) | | Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
|
| , use_aux_mem(false) | | , vec_state(0) | |
| | | , mem_state(0) | |
| //, mem(0) | | //, mem(0) | |
| , mem(mem) | | , mem(mem) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| glue_type::apply(*this, X); | | glue_type::apply(*this, X); | |
| } | | } | |
| | | | |
| //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delaye
d binary operations | | //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delaye
d binary operations | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 2052 | | skipping to change at line 2388 | |
| { | | { | |
| if(arma_isfinite(mem[i]) == false) | | if(arma_isfinite(mem[i]) == false) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | //! returns true if the matrix has no elements | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Mat<eT>::is_empty() const | |
| | | { | |
| | | return (n_elem == 0); | |
| | | } | |
| | | | |
| | | //! returns true if the given index is currently in range | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Mat<eT>::in_range(const u32 i) const | |
| | | { | |
| | | return (i < n_elem); | |
| | | } | |
| | | | |
| | | //! returns true if the given location is currently in range | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | bool | |
| | | Mat<eT>::in_range(const u32 in_row, const u32 in_col) const | |
| | | { | |
| | | return ( (in_row < n_rows) && (in_col < n_cols) ); | |
| | | } | |
| | | | |
| //! returns a pointer to array of eTs for a specified column; no bounds che
ck | | //! returns a pointer to array of eTs for a specified column; no bounds che
ck | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT* | | eT* | |
| Mat<eT>::colptr(const u32 in_col) | | Mat<eT>::colptr(const u32 in_col) | |
| { | | { | |
| return & access::rw(mem[in_col*n_rows]); | | return & access::rw(mem[in_col*n_rows]); | |
| } | | } | |
| | | | |
| //! returns a pointer to array of eTs for a specified column; no bounds che
ck | | //! returns a pointer to array of eTs for a specified column; no bounds che
ck | |
| | | | |
| skipping to change at line 2091 | | skipping to change at line 2454 | |
| arma_inline | | arma_inline | |
| const eT* | | const eT* | |
| Mat<eT>::memptr() const | | Mat<eT>::memptr() const | |
| { | | { | |
| return mem; | | return mem; | |
| } | | } | |
| | | | |
| //! print contents of the matrix (to the cout stream), | | //! print contents of the matrix (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print(const std::string extra_text) const | | Mat<eT>::print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| const std::streamsize orig_width = cout.width(); | | const std::streamsize orig_width = cout.width(); | |
| | | | |
| skipping to change at line 2114 | | skipping to change at line 2477 | |
| | | | |
| cout.width(orig_width); | | cout.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, true); | | arma_ostream::print(cout, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the matrix to a user specified stream, | | //! print contents of the matrix to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print(std::ostream& user_stream, const std::string extra_text) con
st | | Mat<eT>::print(std::ostream& user_stream, const std::string extra_text) con
st | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| const std::streamsize orig_width = user_stream.width(); | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| skipping to change at line 2137 | | skipping to change at line 2500 | |
| | | | |
| user_stream.width(orig_width); | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, true); | | arma_ostream::print(user_stream, *this, true); | |
| } | | } | |
| | | | |
| //! print contents of the transposed version of the matrix (to the cout str
eam), | | //! print contents of the transposed version of the matrix (to the cout str
eam), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print_trans(const std::string extra_text) const | | Mat<eT>::print_trans(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT> tmp; | | Mat<eT> tmp; | |
| op_trans::apply_noalias(tmp, *this); | | op_trans::apply_noalias(tmp, *this); | |
| | | | |
| tmp.print(extra_text); | | tmp.print(extra_text); | |
| } | | } | |
| | | | |
| //! print contents of the transposed version of matrix to a user specified
stream, | | //! print contents of the transposed version of matrix to a user specified
stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the precision and cell width are modified. | | //! the precision and cell width are modified. | |
|
| //! on return, the stream's flags are restored to their original values. | | //! on return, the stream's state are restored to their original values. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::print_trans(std::ostream& user_stream, const std::string extra_tex
t) const | | Mat<eT>::print_trans(std::ostream& user_stream, const std::string extra_tex
t) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT> tmp; | | Mat<eT> tmp; | |
| op_trans::apply_noalias(tmp, *this); | | op_trans::apply_noalias(tmp, *this); | |
| | | | |
| tmp.print(user_stream, extra_text); | | tmp.print(user_stream, extra_text); | |
| } | | } | |
| | | | |
| //! print contents of the matrix (to the cout stream), | | //! print contents of the matrix (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified | | //! the stream's state are used as is and are not modified | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print(const std::string extra_text) const | | Mat<eT>::raw_print(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| | | | |
| skipping to change at line 2193 | | skipping to change at line 2556 | |
| cout << extra_text << '\n'; | | cout << extra_text << '\n'; | |
| | | | |
| cout.width(orig_width); | | cout.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(cout, *this, false); | | arma_ostream::print(cout, *this, false); | |
| } | | } | |
| | | | |
| //! print contents of the matrix to a user specified stream, | | //! print contents of the matrix to a user specified stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified. | | //! the stream's state are used as is and are not modified. | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print(std::ostream& user_stream, const std::string extra_text)
const | | Mat<eT>::raw_print(std::ostream& user_stream, const std::string extra_text)
const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| | | | |
| skipping to change at line 2216 | | skipping to change at line 2579 | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
| | | | |
| user_stream.width(orig_width); | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, false); | | arma_ostream::print(user_stream, *this, false); | |
| } | | } | |
| | | | |
| //! print contents of the transposed version of the matrix (to the cout str
eam), | | //! print contents of the transposed version of the matrix (to the cout str
eam), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified | | //! the stream's state are used as is and are not modified | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print_trans(const std::string extra_text) const | | Mat<eT>::raw_print_trans(const std::string extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT> tmp; | | Mat<eT> tmp; | |
| op_trans::apply_noalias(tmp, *this); | | op_trans::apply_noalias(tmp, *this); | |
| | | | |
| tmp.raw_print(extra_text); | | tmp.raw_print(extra_text); | |
| } | | } | |
| | | | |
| //! print contents of the transposed version of the matrix to a user specif
ied stream, | | //! print contents of the transposed version of the matrix to a user specif
ied stream, | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
|
| //! the stream's flags are used as is and are not modified. | | //! the stream's state are used as is and are not modified. | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::raw_print_trans(std::ostream& user_stream, const std::string extra
_text) const | | Mat<eT>::raw_print_trans(std::ostream& user_stream, const std::string extra
_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT> tmp; | | Mat<eT> tmp; | |
| op_trans::apply_noalias(tmp, *this); | | op_trans::apply_noalias(tmp, *this); | |
| | | | |
| tmp.raw_print(user_stream, extra_text); | | tmp.raw_print(user_stream, extra_text); | |
| } | | } | |
| | | | |
| //! change the matrix to have user specified dimensions (data is not preser
ved) | | //! change the matrix to have user specified dimensions (data is not preser
ved) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| | | Mat<eT>::set_size(const u32 in_elem) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | switch(vec_state) | |
| | | { | |
| | | case 0: | |
| | | case 1: | |
| | | init(in_elem, 1); | |
| | | break; | |
| | | | |
| | | case 2: | |
| | | init(1, in_elem); | |
| | | break; | |
| | | | |
| | | default: | |
| | | ; | |
| | | } | |
| | | } | |
| | | | |
| | | //! change the matrix to have user specified dimensions (data is not preser | |
| | | ved) | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| Mat<eT>::set_size(const u32 in_rows, const u32 in_cols) | | Mat<eT>::set_size(const u32 in_rows, const u32 in_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(in_rows, in_cols); | | init(in_rows, in_cols); | |
| } | | } | |
| | | | |
| //! change the matrix to have user specified dimensions (data is preserved) | | //! change the matrix to have user specified dimensions (data is preserved) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| | | | |
| skipping to change at line 2291 | | skipping to change at line 2678 | |
| | | | |
| //! fill the matrix with the specified value | | //! fill the matrix with the specified value | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::fill(const eT val) | | Mat<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* local_ptr = memptr(); | | arrayops::inplace_set( memptr(), val, n_elem ); | |
| const u32 local_n_elem = n_elem; | | } | |
| | | | |
| u32 i,j; | | | |
| | | | |
|
| for(i=0, j=1; j<local_n_elem; i+=2, j+=2) | | template<typename eT> | |
| { | | inline | |
| local_ptr[i] = val; | | void | |
| local_ptr[j] = val; | | Mat<eT>::zeros() | |
| } | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
|
| if(i < local_n_elem) | | fill(eT(0)); | |
| { | | | |
| local_ptr[i] = val; | | | |
| } | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::zeros() | | Mat<eT>::zeros(const u32 in_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | set_size(in_elem); | |
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::zeros(const u32 in_rows, const u32 in_cols) | | Mat<eT>::zeros(const u32 in_rows, const u32 in_cols) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | |
| | | | |
| set_size(in_rows, in_cols); | | set_size(in_rows, in_cols); | |
|
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::ones() | | Mat<eT>::ones() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| fill(eT(1)); | | fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| | | Mat<eT>::ones(const u32 in_elem) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | set_size(in_elem); | |
| | | | |
| | | fill(eT(1)); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| Mat<eT>::ones(const u32 in_rows, const u32 in_cols) | | Mat<eT>::ones(const u32 in_rows, const u32 in_cols) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d
") % in_rows % in_cols ); | |
| | | | |
| set_size(in_rows, in_cols); | | set_size(in_rows, in_cols); | |
|
| | | | |
| fill(eT(1)); | | fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::reset() | | Mat<eT>::reset() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(0,0); | | init(0,0); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::set_real(const Base<typename Mat<eT>::pod_type,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat_aux::set_real(*this, X); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::set_imag(const Base<typename Mat<eT>::pod_type,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | Mat_aux::set_imag(*this, X); | |
| | | } | |
| | | | |
| //! save the matrix to a file | | //! save the matrix to a file | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| Mat<eT>::save(const std::string name, const file_type type, const bool prin
t_status) const | | Mat<eT>::save(const std::string name, const file_type type, const bool prin
t_status) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| bool save_okay; | | bool save_okay; | |
| | | | |
| | | | |
| skipping to change at line 2916 | | skipping to change at line 3337 | |
| typename Mat<eT>::const_row_iterator | | typename Mat<eT>::const_row_iterator | |
| Mat<eT>::end_row(const u32 row_num) const | | Mat<eT>::end_row(const u32 row_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of boun
ds" ); | | arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of boun
ds" ); | |
| | | | |
| return typename Mat<eT>::const_row_iterator(*this, row_num + 1); | | return typename Mat<eT>::const_row_iterator(*this, row_num + 1); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<u32 fixed_n_rows, u32 fixed_n_cols> | |
| | | arma_inline | |
| | | void | |
| | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::mem_setup() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | if(fixed_n_elem > 0) | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = fixed_n_rows; | |
| | | access::rw(Mat<eT>::n_cols) = fixed_n_cols; | |
| | | access::rw(Mat<eT>::n_elem) = fixed_n_elem; | |
| | | access::rw(Mat<eT>::vec_state) = 0; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = (fixed_n_elem > Mat_prealloc::mem_n_el | |
| | | em) ? mem_local_extra : mem_local; | |
| | | } | |
| | | else | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = 0; | |
| | | access::rw(Mat<eT>::n_cols) = 0; | |
| | | access::rw(Mat<eT>::n_elem) = 0; | |
| | | access::rw(Mat<eT>::vec_state) = 0; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = 0; | |
| | | } | |
| | | } | |
| | | | |
| //! prefix ++ | | //! prefix ++ | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| void | | void | |
| Mat_aux::prefix_pp(Mat<eT>& x) | | Mat_aux::prefix_pp(Mat<eT>& x) | |
| { | | { | |
| eT* memptr = x.memptr(); | | eT* memptr = x.memptr(); | |
| const u32 n_elem = x.n_elem; | | const u32 n_elem = x.n_elem; | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| skipping to change at line 3044 | | skipping to change at line 3493 | |
| | | | |
| //! postfix ++ for complex numbers (work around for limitations of the std:
:complex class) | | //! postfix ++ for complex numbers (work around for limitations of the std:
:complex class) | |
| template<typename T> | | template<typename T> | |
| arma_inline | | arma_inline | |
| void | | void | |
| Mat_aux::postfix_mm(Mat< std::complex<T> >& x) | | Mat_aux::postfix_mm(Mat< std::complex<T> >& x) | |
| { | | { | |
| x -= T(1); | | x -= T(1); | |
| } | | } | |
| | | | |
|
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_real(Mat<eT>& out, const Base<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const unwrap<T1> tmp(X.get_ref()); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Mat::set_real()" ); | |
| | | | |
| | | out = A; | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_real(Mat< std::complex<T> >& out, const Base<T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | (is_Mat<T1>::value == true) ? Mat_aux::set_real_via_unwrap(out, X) : Mat_ | |
| | | aux::set_real_via_proxy(out, X); | |
| | | } | |
| | | | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_imag(Mat<eT>& out, const Base<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | (is_Mat<T1>::value == true) ? Mat_aux::set_imag_via_unwrap(out, X) : Mat_ | |
| | | aux::set_imag_via_proxy(out, X); | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_real_via_unwrap(Mat< std::complex<T> >& out, const Base<T,T1>& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const unwrap<T1> tmp(X.get_ref()); | |
| | | const Mat<T>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Mat::set_real()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | const T* A_mem = A.memptr(); | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].real() = A_mem[i]; | |
| | | out_mem[i] = std::complex<T>( A_mem[i], out_mem[i].imag() ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_imag_via_unwrap(Mat< std::complex<T> >& out, const Base<T,T1>& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const unwrap<T1> tmp(X.get_ref()); | |
| | | const Mat<T>& A = tmp.M; | |
| | | | |
| | | arma_debug_assert_same_size( out, A, "Mat::set_imag()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| | | const T* A_mem = A.memptr(); | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | // out_mem[i].imag() = A_mem[i]; | |
| | | out_mem[i] = std::complex<T>(out_mem[i].real(), A_mem[i]); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_real_via_proxy(Mat< std::complex<T> >& out, const Base<T,T1>& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const Proxy<T1> P(X.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size( out.n_rows, out.n_cols, P.n_rows, P.n_cols, | |
| | | "Mat::set_real()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].real() = P[i]; | |
| | | out_mem[i] = std::complex<T>( P[i], out_mem[i].imag() ); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | void | |
| | | Mat_aux::set_imag_via_proxy(Mat< std::complex<T> >& out, const Base<T,T1>& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | const Proxy<T1> P(X.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size( out.n_rows, out.n_cols, P.n_rows, P.n_cols, | |
| | | "Mat::set_imag()" ); | |
| | | | |
| | | const u32 n_elem = out.n_elem; | |
| | | eT* out_mem = out.memptr(); | |
| | | | |
| | | for(u32 i=0; i<n_elem; ++i) | |
| | | { | |
| | | //out_mem[i].imag() = P[i]; | |
| | | out_mem[i] = std::complex<T>( out_mem[i].real(), P[i] ); | |
| | | } | |
| | | } | |
| | | | |
| | | #ifdef ARMA_EXTRA_MAT_MEAT | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 105 change blocks. |
| 274 lines changed or deleted | | 894 lines changed or added | |
|
| Mat_proto.hpp | | Mat_proto.hpp | |
| | | | |
| skipping to change at line 19 | | skipping to change at line 19 | |
| // 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 Mat | | //! \addtogroup Mat | |
| //! @{ | | //! @{ | |
| | | | |
|
| | | struct Mat_prealloc | |
| | | { | |
| | | static const u32 mem_n_elem = 16; | |
| | | }; | |
| | | | |
| //! Dense matrix class | | //! Dense matrix class | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class Mat : public Base< eT, Mat<eT> > | | class Mat : public Base< eT, Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; //!< the type of el
ements stored in the matrix | | typedef eT elem_type; //!< the type of el
ements stored in the matrix | |
| typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-c
omplex, pod_type is same as eT. otherwise, pod_type is the underlying type
used by std::complex | | typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-c
omplex, pod_type is same as eT. otherwise, pod_type is the underlying type
used by std::complex | |
| | | | |
|
| const u32 n_rows; //!< number of rows in the matrix (read-only) | | const u32 n_rows; //!< number of rows in the matrix (read-only) | |
| const u32 n_cols; //!< number of columns in the matrix (read-only) | | const u32 n_cols; //!< number of columns in the matrix (read-only) | |
| const u32 n_elem; //!< number of elements in the matrix (read-only) | | const u32 n_elem; //!< number of elements in the matrix (read-only) | |
| const bool use_aux_mem; //!< true if externally managed memory is being u | | const u16 vec_state; //!< 0: matrix layout; 1: column vector layout; 2: r | |
| sed (read-only) | | ow vector layout | |
| | | const u16 mem_state; | |
| | | | |
| | | // mem_state = 0: normal matrix that can be resized; | |
| | | // mem_state = 1: use auxiliary memory until change in the number of elem | |
| | | ents is requested; | |
| | | // mem_state = 2: use auxiliary memory and don't allow the number of elem | |
| | | ents to be changed; | |
| | | // mem_state = 3: fixed size via template based size specification. | |
| | | | |
| arma_aligned const eT* const mem; //!< pointer to the memory used by the
matrix (memory is read-only) | | arma_aligned const eT* const mem; //!< pointer to the memory used by the
matrix (memory is read-only) | |
| | | | |
| protected: | | protected: | |
|
| arma_aligned eT mem_local[ 16 ]; | | arma_aligned eT mem_local[ Mat_prealloc::mem_n_elem ]; | |
| | | | |
| public: | | public: | |
| | | | |
| inline ~Mat(); | | inline ~Mat(); | |
| inline Mat(); | | inline Mat(); | |
| | | | |
| inline Mat(const u32 in_rows, const u32 in_cols); | | inline Mat(const u32 in_rows, const u32 in_cols); | |
| | | | |
| inline Mat(const char* text); | | inline Mat(const char* text); | |
| inline const Mat& operator=(const char* text); | | inline const Mat& operator=(const char* text); | |
| inline Mat(const std::string& text); | | inline Mat(const std::string& text); | |
| inline const Mat& operator=(const std::string& text); | | inline const Mat& operator=(const std::string& text); | |
| | | | |
|
| inline Mat( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols,
const bool copy_aux_mem = true); | | inline Mat( eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols,
const bool copy_aux_mem = true, const bool strict = true); | |
| inline Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
; | | inline Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
; | |
| | | | |
| arma_inline const Mat& operator=(const eT val); | | arma_inline const Mat& operator=(const eT val); | |
| arma_inline const Mat& operator+=(const eT val); | | arma_inline const Mat& operator+=(const eT val); | |
| arma_inline const Mat& operator-=(const eT val); | | arma_inline const Mat& operator-=(const eT val); | |
| arma_inline const Mat& operator*=(const eT val); | | arma_inline const Mat& operator*=(const eT val); | |
| arma_inline const Mat& operator/=(const eT val); | | arma_inline const Mat& operator/=(const eT val); | |
| | | | |
| inline Mat(const Mat& m); | | inline Mat(const Mat& m); | |
| inline const Mat& operator=(const Mat& m); | | inline const Mat& operator=(const Mat& m); | |
| | | | |
| skipping to change at line 115 | | skipping to change at line 126 | |
| | | | |
| arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2); | | arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2); | |
| arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2)
const; | | arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2)
const; | |
| | | | |
| arma_inline subview<eT> cols(const u32 in_col1, const u32 in_col2); | | arma_inline subview<eT> cols(const u32 in_col1, const u32 in_col2); | |
| arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2)
const; | | arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2)
const; | |
| | | | |
| arma_inline subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2); | | arma_inline subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2); | |
| arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2) const; | | arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1
, const u32 in_row2, const u32 in_col2) const; | |
| | | | |
|
| | | arma_inline subview<eT> submat(const span& row_span, const span& co | |
| | | l_span); | |
| | | arma_inline const subview<eT> submat(const span& row_span, const span& co | |
| | | l_span) const; | |
| | | | |
| arma_inline diagview<eT> diag(const s32 in_id = 0); | | arma_inline diagview<eT> diag(const s32 in_id = 0); | |
| arma_inline const diagview<eT> diag(const s32 in_id = 0) const; | | arma_inline const diagview<eT> diag(const s32 in_id = 0) const; | |
| | | | |
| inline void swap_rows(const u32 in_row1, const u32 in_row2); | | inline void swap_rows(const u32 in_row1, const u32 in_row2); | |
| inline void swap_cols(const u32 in_col1, const u32 in_col2); | | inline void swap_cols(const u32 in_col1, const u32 in_col2); | |
| | | | |
|
| | | inline void shed_row(const u32 row_num); | |
| | | inline void shed_col(const u32 col_num); | |
| | | | |
| | | inline void shed_rows(const u32 in_row1, const u32 in_row2); | |
| | | inline void shed_cols(const u32 in_col1, const u32 in_col2); | |
| | | | |
| | | inline void insert_rows(const u32 row_num, const u32 N, const bool set_to | |
| | | _zero = true); | |
| | | inline void insert_cols(const u32 col_num, const u32 N, const bool set_to | |
| | | _zero = true); | |
| | | | |
| | | template<typename T1> inline void insert_rows(const u32 row_num, const Ba | |
| | | se<eT,T1>& X); | |
| | | template<typename T1> inline void insert_cols(const u32 col_num, const Ba | |
| | | se<eT,T1>& X); | |
| | | | |
| template<typename T1, typename op_type> inline Mat(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline Mat(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator+=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator+=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator-=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator-=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator*=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator*=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator%=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator%=(cons
t Op<T1, op_type>& X); | |
| template<typename T1, typename op_type> inline const Mat& operator/=(cons
t Op<T1, op_type>& X); | | template<typename T1, typename op_type> inline const Mat& operator/=(cons
t Op<T1, op_type>& X); | |
| | | | |
| template<typename T1, typename eop_type> inline Mat(con
st eOp<T1, eop_type>& X); | | template<typename T1, typename eop_type> inline Mat(con
st eOp<T1, eop_type>& X); | |
| template<typename T1, typename eop_type> inline const Mat& operator=(con
st eOp<T1, eop_type>& X); | | template<typename T1, typename eop_type> inline const Mat& operator=(con
st eOp<T1, eop_type>& X); | |
| | | | |
| skipping to change at line 188 | | skipping to change at line 214 | |
| arma_inline eT at (const u32 in_row, const u32 in_col) const; | | arma_inline eT at (const u32 in_row, const u32 in_col) const; | |
| arma_inline eT& operator() (const u32 in_row, const u32 in_col); | | arma_inline eT& operator() (const u32 in_row, const u32 in_col); | |
| arma_inline eT operator() (const u32 in_row, const u32 in_col) const; | | arma_inline eT operator() (const u32 in_row, const u32 in_col) const; | |
| | | | |
| arma_inline const Mat& operator++(); | | arma_inline const Mat& operator++(); | |
| arma_inline void operator++(int); | | arma_inline void operator++(int); | |
| | | | |
| arma_inline const Mat& operator--(); | | arma_inline const Mat& operator--(); | |
| arma_inline void operator--(int); | | arma_inline void operator--(int); | |
| | | | |
|
| arma_inline bool is_vec() const; | | arma_inline bool is_vec() const; | |
| arma_inline bool is_square() const; | | arma_inline bool is_square() const; | |
| arma_inline bool is_finite() const; | | arma_inline bool is_finite() const; | |
|
| | | arma_inline bool is_empty() const; | |
| | | | |
| | | arma_inline bool in_range(const u32 i) const; | |
| | | arma_inline bool in_range(const u32 in_row, const u32 in_col) const; | |
| | | | |
| arma_inline eT* colptr(const u32 in_col); | | arma_inline eT* colptr(const u32 in_col); | |
| arma_inline const eT* colptr(const u32 in_col) const; | | arma_inline const eT* colptr(const u32 in_col) const; | |
| | | | |
| arma_inline eT* memptr(); | | arma_inline eT* memptr(); | |
| arma_inline const eT* memptr() const; | | arma_inline const eT* memptr() const; | |
| | | | |
| inline void print(const std::string extra_text = "") const; | | inline void print(const std::string extra_text = "") const; | |
| inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | | inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | |
| | | | |
| | | | |
| skipping to change at line 213 | | skipping to change at line 243 | |
| | | | |
| inline void raw_print(const std::string extra_text = "") const; | | inline void raw_print(const std::string extra_text = "") const; | |
| inline void raw_print(std::ostream& user_stream, const std::string extra_
text = "") const; | | inline void raw_print(std::ostream& user_stream, const std::string extra_
text = "") const; | |
| | | | |
| inline void raw_print_trans(const std::string extra_text = "") const; | | inline void raw_print_trans(const std::string extra_text = "") const; | |
| inline void raw_print_trans(std::ostream& user_stream, const std::string
extra_text = "") const; | | inline void raw_print_trans(std::ostream& user_stream, const std::string
extra_text = "") const; | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| inline void copy_size(const Mat<eT2>& m); | | inline void copy_size(const Mat<eT2>& m); | |
| | | | |
|
| | | inline void set_size(const u32 in_elem); | |
| inline void set_size(const u32 in_rows, const u32 in_cols); | | inline void set_size(const u32 in_rows, const u32 in_cols); | |
| inline void reshape(const u32 in_rows, const u32 in_cols, const u32 dim
= 0); | | inline void reshape(const u32 in_rows, const u32 in_cols, const u32 dim
= 0); | |
| | | | |
| arma_hot inline void fill(const eT val); | | arma_hot inline void fill(const eT val); | |
| | | | |
| inline void zeros(); | | inline void zeros(); | |
|
| | | inline void zeros(const u32 in_elem); | |
| inline void zeros(const u32 in_rows, const u32 in_cols); | | inline void zeros(const u32 in_rows, const u32 in_cols); | |
| | | | |
| inline void ones(); | | inline void ones(); | |
|
| | | inline void ones(const u32 in_elem); | |
| inline void ones(const u32 in_rows, const u32 in_cols); | | inline void ones(const u32 in_rows, const u32 in_cols); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| | | | |
|
| | | template<typename T1> inline void set_real(const Base<pod_type,T1>& X); | |
| | | template<typename T1> inline void set_imag(const Base<pod_type,T1>& X); | |
| | | | |
| inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| | | | |
| inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | |
| inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | |
| | | | |
| inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | | inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | |
| inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | | inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | |
| | | | |
| inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | | inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | |
| inline bool quiet_load( std::istream& is, const file_type type = a
uto_detect); | | inline bool quiet_load( std::istream& is, const file_type type = a
uto_detect); | |
| | | | |
|
| // iterators | | // for container-like functionality | |
| | | | |
| | | typedef eT value_type; | |
| | | typedef u32 size_type; | |
| | | | |
| typedef eT* iterator; | | typedef eT* iterator; | |
| typedef const eT* const_iterator; | | typedef const eT* const_iterator; | |
| | | | |
| typedef eT* col_iterator; | | typedef eT* col_iterator; | |
| typedef const eT* const_col_iterator; | | typedef const eT* const_col_iterator; | |
| | | | |
| class row_iterator | | class row_iterator | |
| { | | { | |
| public: | | public: | |
| | | | |
| skipping to change at line 309 | | skipping to change at line 348 | |
| | | | |
| inline col_iterator end_col (const u32 col_num); | | inline col_iterator end_col (const u32 col_num); | |
| inline const_col_iterator end_col (const u32 col_num) const; | | inline const_col_iterator end_col (const u32 col_num) const; | |
| | | | |
| inline row_iterator begin_row(const u32 row_num); | | inline row_iterator begin_row(const u32 row_num); | |
| inline const_row_iterator begin_row(const u32 row_num) const; | | inline const_row_iterator begin_row(const u32 row_num) const; | |
| | | | |
| inline row_iterator end_row (const u32 row_num); | | inline row_iterator end_row (const u32 row_num); | |
| inline const_row_iterator end_row (const u32 row_num) const; | | inline const_row_iterator end_row (const u32 row_num) const; | |
| | | | |
|
| | | // inline void clear(); | |
| | | // inline void resize(const u32 in_n_elem); | |
| | | // arma_inline bool empty() const; | |
| | | // arma_inline u32 size() const; | |
| | | | |
| | | template<u32 fixed_n_rows, u32 fixed_n_cols> | |
| | | class fixed : public Mat<eT> | |
| | | { | |
| | | private: | |
| | | | |
| | | static const u32 fixed_n_elem = fixed_n_rows * fixed_n_cols; | |
| | | | |
| | | arma_aligned eT mem_local_extra[ ( fixed_n_elem > Mat_prealloc::mem_n_e | |
| | | lem ) ? fixed_n_elem : 1 ]; | |
| | | | |
| | | arma_inline void mem_setup(); | |
| | | | |
| | | public: | |
| | | | |
| | | inline fixed() { mem_setup(); } | |
| | | | |
| | | inline fixed(const char* text) { mem_setup(); Mat | |
| | | <eT>::operator=(text); } | |
| | | inline const Mat& operator=(const char* text) { Mat | |
| | | <eT>::operator=(text); return *this; } | |
| | | inline fixed(const std::string& text) { mem_setup(); Mat | |
| | | <eT>::operator=(text); } | |
| | | inline const Mat& operator=(const std::string& text) { Mat | |
| | | <eT>::operator=(text); return *this; } | |
| | | | |
| | | inline const Mat& operator=(const eT val) { Mat<eT>::operator=(val); re | |
| | | turn *this; } | |
| | | | |
| | | template<typename T1> | |
| | | inline fixed(const Base<eT,T1>& A) { mem_setup(); Mat<eT>::operator=(A. | |
| | | get_ref()); } | |
| | | | |
| | | template<typename T1> | |
| | | inline const Mat& operator=(const Base<eT,T1>& A) { Mat<eT>::operator=( | |
| | | A.get_ref()); return *this; } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline explicit fixed(const Base<pod_type,T1>& A, const Base<pod_type,T | |
| | | 2>& B) { mem_setup(); Mat<eT>::init(A,B); } | |
| | | }; | |
| | | | |
| | | #ifdef ARMA_EXTRA_MAT_PROTO | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_PROTO) | |
| | | #endif | |
| | | | |
| protected: | | protected: | |
| | | | |
| inline void init(const u32 in_rows, const u32 in_cols); | | inline void init(const u32 in_rows, const u32 in_cols); | |
| inline void init(const std::string& text); | | inline void init(const std::string& text); | |
| inline void init(const Mat& x); | | inline void init(const Mat& x); | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline void init(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); | |
| | | | |
| | | inline void steal_mem(Mat& X); | |
| | | | |
| inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons
t u32 aux_n_cols); | | inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons
t u32 aux_n_cols); | |
| | | | |
| friend class Cube<eT>; | | friend class Cube<eT>; | |
| friend class glue_join; | | friend class glue_join; | |
| }; | | }; | |
| | | | |
| class Mat_aux | | class Mat_aux | |
| { | | { | |
| public: | | public: | |
| | | | |
| | | | |
| skipping to change at line 336 | | skipping to change at line 421 | |
| template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | | template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | | template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | |
| template<typename T> arma_inline static void postfix_pp(Mat< std::comple
x<T> >& x); | | template<typename T> arma_inline static void postfix_pp(Mat< std::comple
x<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void prefix_mm(Mat<eT>& x); | | template<typename eT> arma_inline static void prefix_mm(Mat<eT>& x); | |
| template<typename T> arma_inline static void prefix_mm(Mat< std::complex
<T> >& x); | | template<typename T> arma_inline static void prefix_mm(Mat< std::complex
<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_mm(Mat<eT>& x); | | template<typename eT> arma_inline static void postfix_mm(Mat<eT>& x); | |
| template<typename T> arma_inline static void postfix_mm(Mat< std::comple
x<T> >& x); | | template<typename T> arma_inline static void postfix_mm(Mat< std::comple
x<T> >& x); | |
|
| | | | |
| | | template<typename eT, typename T1> inline static void set_real(Mat<eT>& | |
| | | out, const Base<eT,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_real(Mat< std:: | |
| | | complex<T> >& out, const Base< T,T1>& X); | |
| | | | |
| | | template<typename eT, typename T1> inline static void set_imag(Mat<eT>& | |
| | | out, const Base<eT,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag(Mat< std:: | |
| | | complex<T> >& out, const Base< T,T1>& X); | |
| | | | |
| | | template<typename T, typename T1> inline static void set_real_via_unwrap | |
| | | (Mat< std::complex<T> >& out, const Base< T,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag_via_unwrap | |
| | | (Mat< std::complex<T> >& out, const Base< T,T1>& X); | |
| | | | |
| | | template<typename T, typename T1> inline static void set_real_via_proxy( | |
| | | Mat< std::complex<T> >& out, const Base< T,T1>& X); | |
| | | template<typename T, typename T1> inline static void set_imag_via_proxy( | |
| | | Mat< std::complex<T> >& out, const Base< T,T1>& X); | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 16 change blocks. |
| 9 lines changed or deleted | | 131 lines changed or added | |
|
| Row_meat.hpp | | Row_meat.hpp | |
| | | | |
| skipping to change at line 22 | | skipping to change at line 22 | |
| // 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 Row | | //! \addtogroup Row | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row() | | Row<eT>::Row() | |
|
| : Mat<eT>() | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | | |
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const u32 in_n_elem) | | Row<eT>::Row(const u32 in_n_elem) | |
|
| : Mat<eT>(1,in_n_elem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | | |
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| | | Mat<eT>::init(1, in_n_elem); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const u32 in_n_rows, const u32 in_n_cols) | | Row<eT>::Row(const u32 in_n_rows, const u32 in_n_cols) | |
|
| : Mat<eT>(in_n_rows, in_n_cols) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 2; | |
| ); | | | |
| | | Mat<eT>::init(in_n_rows, in_n_cols); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const char* text) | | Row<eT>::Row(const char* text) | |
|
| : Mat<eT>(text) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 2; | |
| ); | | | |
| | | Mat<eT>::operator=(text); | |
| } | | } | |
| | | | |
| 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; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const std::string& text) | | Row<eT>::Row(const std::string& text) | |
|
| : Mat<eT>(text) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 2; | |
| ); | | | |
| | | Mat<eT>::operator=(text); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
| Row<eT>::operator=(const std::string& text) | | Row<eT>::operator=(const std::string& 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; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Row<eT>::Row(const Row<eT>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Row<eT>& | | const Row<eT>& | |
|
| Row<eT>::operator=(const Row<eT>& X) | | Row<eT>::operator=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(val); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
|
| Row<eT>::Row(const Mat<eT>& X) | | Row<eT>::Row(const Base<eT,T1>& X) | |
| : Mat<eT>(X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 2; | |
| ); | | | |
| } | | | |
| | | | |
|
| template<typename eT> | | Mat<eT>::operator=(X.get_ref()); | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const Mat<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> | | template<typename eT> | |
|
| | | template<typename T1> | |
| inline | | inline | |
| const Row<eT>& | | const Row<eT>& | |
|
| Row<eT>::operator*=(const Mat<eT>& X) | | Row<eT>::operator=(const Base<eT,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator*=(X); | | Mat<eT>::operator=(X.get_ref()); | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| return *this; | | | |
| } | | | |
| | | | |
| //! construct a row vector from a given auxiliary array | | | |
| template<typename eT> | | | |
| inline | | | |
| Row<eT>::Row(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) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! construct a row vector from a given auxiliary array | | | |
| template<typename eT> | | | |
| inline | | | |
| Row<eT>::Row(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols) | | | |
| : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | return *this; | |
| } | | } | |
| | | | |
| //! construct a row vector from a given auxiliary array | | //! construct a row vector from a given auxiliary array | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Row<eT>::Row(eT* aux_mem, const u32 aux_length, const bool copy_aux_mem) | | Row<eT>::Row(eT* aux_mem, const u32 aux_length, const bool copy_aux_mem, co | |
| : Mat<eT>(aux_mem, 1, aux_length, copy_aux_mem) | | nst bool strict) | |
| | | : Mat<eT>(aux_mem, 1, aux_length, copy_aux_mem, strict) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // Mat<eT>::set_size(1, aux_length); | | access::rw(Mat<eT>::vec_state) = 2; | |
| // arma_check( (Mat<eT>::n_elem != aux_length), "Row(): don't know how to | | | |
| handle the given array" ); | | | |
| // | | | |
| // syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem ); | | | |
| } | | } | |
| | | | |
| //! construct a row vector from a given auxiliary array | | //! construct a row vector from a given auxiliary array | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const eT* aux_mem, const u32 aux_length) | | Row<eT>::Row(const eT* aux_mem, const u32 aux_length) | |
| : Mat<eT>(aux_mem, 1, aux_length) | | : Mat<eT>(aux_mem, 1, aux_length) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // Mat<eT>::set_size(1, aux_length); | | access::rw(Mat<eT>::vec_state) = 2; | |
| // arma_check( (Mat<eT>::n_elem != aux_length), "Row(): don't know how to | | | |
| handle the given array" ); | | | |
| // | | | |
| // syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem ); | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| Row<eT>::Row | | Row<eT>::Row | |
| ( | | ( | |
| const Base<typename Row<eT>::pod_type, T1>& A, | | const Base<typename Row<eT>::pod_type, T1>& A, | |
| const Base<typename Row<eT>::pod_type, T2>& B | | const Base<typename Row<eT>::pod_type, T2>& B | |
| ) | | ) | |
|
| : Mat<eT>(A,B) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| Row<eT>::Row(const subview<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<eT>& X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| Mat<eT>::operator=(X); | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
|
| return *this; | | Mat<eT>::init(A,B); | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const subview<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> | | template<typename eT> | |
| inline | | inline | |
| Row<eT>::Row(const subview_cube<eT>& X) | | Row<eT>::Row(const subview_cube<eT>& X) | |
|
| : Mat<eT>(X) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | access::rw(Mat<eT>::vec_state) = 2; | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const subview_cube<eT>& X) | | | |
| { | | | |
| 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 | | | |
| 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; | | | |
| } | | } | |
| | | | |
|
| //! construct a row vector from given a diagview | | | |
| template<typename eT> | | | |
| inline | | | |
| Row<eT>::Row(const diagview<eT>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| 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" | | | |
| ); | | | |
| } | | | |
| | | | |
| //! 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 subview_cube<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::operator=(X); | | Mat<eT>::operator=(X); | |
| | | | |
|
| //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" | | | |
| ); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const diagview<eT>& X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator*=(X); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| mat_injector< Row<eT> > | | mat_injector< Row<eT> > | |
| Row<eT>::operator<<(const eT val) | | Row<eT>::operator<<(const eT val) | |
| { | | { | |
| return mat_injector< Row<eT> >(*this, val); | | return mat_injector< Row<eT> >(*this, val); | |
| } | | } | |
| | | | |
| skipping to change at line 381 | | skipping to change at line 245 | |
| const subview_row<eT> | | const subview_row<eT> | |
| Row<eT>::cols(const u32 in_col1, const u32 in_col2) | | Row<eT>::cols(const u32 in_col1, const u32 in_col2) | |
| const | | const | |
| { | | { | |
| arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) )
, "Row::cols(): indices out of bounds or incorrectly used"); | | 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); | | return subview_row<eT>(*this, 0, in_col1, in_col2); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| template<typename T1, typename op_type> | | | |
| inline | | | |
| Row<eT>::Row(const Op<T1, op_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const Op<T1, op_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const Op<T1, op_type>& 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> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| Row<eT>::Row(const eOp<T1, eop_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const eOp<T1, eop_type>& 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> | | | |
| template<typename T1, typename eop_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const eOp<T1, eop_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| Row<eT>::Row(const mtOp<eT, T1, op_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const mtOp<eT, T1, op_type>& 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> | | | |
| template<typename T1, typename op_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const mtOp<eT, T1, op_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| Row<eT>::Row(const Glue<T1, T2, glue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const Glue<T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const Glue<T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| Row<eT>::Row(const eGlue<T1, T2, eglue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const eGlue<T1, T2, eglue_type>& 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> | | | |
| template<typename T1, typename T2, typename eglue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const eGlue<T1, T2, eglue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| Row<eT>::Row(const mtGlue<eT, T1, T2, glue_type>& X) | | | |
| : Mat<eT>(X) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& 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> | | | |
| template<typename T1, typename T2, typename glue_type> | | | |
| inline | | | |
| const Row<eT>& | | | |
| Row<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& 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 | | | |
| void | | | |
| Row<eT>::set_size(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::set_size(1,in_n_elem); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ); | | | |
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row::set_size(): incompatible dimensi | | | |
| ons" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::reshape(const u32 in_rows, const u32 in_cols, const u32 dim) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::reshape(in_rows, in_cols, dim); | | | |
| | | | |
| arma_debug_check( (in_rows > 1), "Row::set_size(): incompatible dimension | | | |
| s" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename eT2> | | | |
| inline | | | |
| void | | | |
| Row<eT>::copy_size(const Mat<eT2>& x) | | | |
| { | | | |
| 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 ); | | | |
| | | | |
| arma_debug_check( (x.n_rows > 1), "Row::copy_size(): incompatible dimensi | | | |
| ons" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::zeros() | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::zeros(); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::zeros(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::zeros(1, in_n_elem); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ); | | | |
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row<eT>::zeros(): incompatible dimens | | | |
| ions" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::ones() | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::ones(); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::ones(const u32 in_n_elem) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::ones(1, in_n_elem); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::ones(const u32 in_n_rows, const u32 in_n_cols) | | | |
| { | | | |
| 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 ); | | | |
| | | | |
| arma_debug_check( (in_n_rows > 1), "Row<eT>::ones(): incompatible dimensi | | | |
| ons" ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::load(const std::string name, const file_type type, const bool prin | | | |
| t_status) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::load(name, type, print_status); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::load(std::istream& is, const file_type type, const bool print_stat | | | |
| us) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::load(is, type, print_status); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::quiet_load(const std::string name, const file_type type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::quiet_load(name, type); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Row<eT>::quiet_load(std::istream& is, const file_type type) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::quiet_load(is, type); | | | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" | | | |
| ); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | inline | |
| typename Row<eT>::row_iterator | | typename Row<eT>::row_iterator | |
| Row<eT>::begin_row(const u32 row_num) | | Row<eT>::begin_row(const u32 row_num) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o
f bounds"); | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o
f bounds"); | |
| | | | |
| return Mat<eT>::memptr(); | | return Mat<eT>::memptr(); | |
| } | | } | |
| | | | |
| skipping to change at line 837 | | skipping to change at line 292 | |
| typename Row<eT>::const_row_iterator | | typename Row<eT>::const_row_iterator | |
| Row<eT>::end_row(const u32 row_num) const | | Row<eT>::end_row(const u32 row_num) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of
bounds"); | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of
bounds"); | |
| | | | |
| return Mat<eT>::memptr() + Mat<eT>::n_cols; | | return Mat<eT>::memptr() + Mat<eT>::n_cols; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<u32 fixed_n_elem> | |
| | | arma_inline | |
| | | void | |
| | | Row<eT>::fixed<fixed_n_elem>::mem_setup() | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | if(fixed_n_elem > 0) | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = 1; | |
| | | access::rw(Mat<eT>::n_cols) = fixed_n_elem; | |
| | | access::rw(Mat<eT>::n_elem) = fixed_n_elem; | |
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = (fixed_n_elem > Mat_prealloc::mem_n_el | |
| | | em) ? mem_local_extra : Mat<eT>::mem_local; | |
| | | } | |
| | | else | |
| | | { | |
| | | access::rw(Mat<eT>::n_rows) = 0; | |
| | | access::rw(Mat<eT>::n_cols) = 0; | |
| | | access::rw(Mat<eT>::n_elem) = 0; | |
| | | access::rw(Mat<eT>::vec_state) = 2; | |
| | | access::rw(Mat<eT>::mem_state) = 3; | |
| | | access::rw(Mat<eT>::mem) = 0; | |
| | | } | |
| | | } | |
| | | | |
| | | #ifdef ARMA_EXTRA_ROW_MEAT | |
| | | #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_MEAT) | |
| | | #endif | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 37 change blocks. |
| 630 lines changed or deleted | | 68 lines changed or added | |
|
| subview_cube_meat.hpp | | subview_cube_meat.hpp | |
| | | | |
| skipping to change at line 91 | | skipping to change at line 91 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const eT val) | | subview_cube<eT>::operator+= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 slice = 0; slice < n_slices; ++slice) | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_slices = n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < local_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < n_cols; ++col) | | for(u32 col = 0; col < local_n_cols; ++col) | |
| { | | { | |
|
| eT* coldata = slice_colptr(slice,col); | | arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows ); | |
| | | | |
| for(u32 row = 0; row < n_rows; ++row) | | | |
| { | | | |
| coldata[row] += val; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator-= (const eT val) | | subview_cube<eT>::operator-= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 slice = 0; slice < n_slices; ++slice) | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_slices = n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < local_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col < local_n_cols; ++col) | |
| { | | { | |
|
| eT* coldata = slice_colptr(slice,col); | | arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows ) | |
| | | ; | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| coldata[row] -= val; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator*= (const eT val) | | subview_cube<eT>::operator*= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 slice = 0; slice < n_slices; ++slice) | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_slices = n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < local_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col < local_n_cols; ++col) | |
| { | | { | |
|
| eT* coldata = slice_colptr(slice,col); | | arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| coldata[row] *= val; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator/= (const eT val) | | subview_cube<eT>::operator/= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 slice = 0; slice < n_slices; ++slice) | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_slices = n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < local_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col < local_n_cols; ++col) | |
| { | | { | |
|
| eT* coldata = slice_colptr(slice,col); | | arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| coldata[row] /= val; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator= (const BaseCube<eT,T1>& in) | | subview_cube<eT>::operator= (const BaseCube<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap_cube<T1> tmp(in.get_ref()); | | const unwrap_cube<T1> tmp(in.get_ref()); | |
| | | | |
| const Cube<eT>& x = tmp.M; | | const Cube<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "copy into subcube"); | | arma_debug_assert_same_size(t, x, "copy into subcube"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | syslib::copy_elem( t.slice_colptr(slice,col), x.slice_colptr(slice,co | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | l), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] = x_coldata[row]; | | | |
| } | | | |
| | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const BaseCube<eT,T1>& in) | | subview_cube<eT>::operator+= (const BaseCube<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap_cube<T1> tmp(in.get_ref()); | | const unwrap_cube<T1> tmp(in.get_ref()); | |
| | | | |
| const Cube<eT>& x = tmp.M; | | const Cube<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube addition"); | | arma_debug_assert_same_size(t, x, "cube addition"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(sli | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | ce,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] += x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator-= (const BaseCube<eT,T1>& in) | | subview_cube<eT>::operator-= (const BaseCube<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap_cube<T1> tmp(in.get_ref()); | | const unwrap_cube<T1> tmp(in.get_ref()); | |
| | | | |
| const Cube<eT>& x = tmp.M; | | const Cube<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube subtraction"); | | arma_debug_assert_same_size(t, x, "cube subtraction"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(sl | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | ice,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] -= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator%= (const BaseCube<eT,T1>& in) | | subview_cube<eT>::operator%= (const BaseCube<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap_cube<T1> tmp(in.get_ref()); | | const unwrap_cube<T1> tmp(in.get_ref()); | |
| | | | |
| const Cube<eT>& x = tmp.M; | | const Cube<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube schur product"); | | arma_debug_assert_same_size(t, x, "cube schur product"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slic | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | e,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] *= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator/= (const BaseCube<eT,T1>& in) | | subview_cube<eT>::operator/= (const BaseCube<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const unwrap_cube<T1> tmp(in.get_ref()); | | const unwrap_cube<T1> tmp(in.get_ref()); | |
| | | | |
| const Cube<eT>& x = tmp.M; | | const Cube<eT>& x = tmp.M; | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise cube division"); | | arma_debug_assert_same_size(t, x, "element-wise cube division"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slic | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | e,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] /= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! x.subcube(...) = y.subcube(...) | | //! x.subcube(...) = y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator= (const subview_cube<eT>& x_in) | | subview_cube<eT>::operator= (const subview_cube<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); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "copy into subcube"); | | arma_debug_assert_same_size(t, x, "copy into subcube"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | syslib::copy_elem( t.slice_colptr(slice,col), x.slice_colptr(slice,co | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | l), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] = x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview_cube; | | delete tmp_subview_cube; | |
| delete tmp_cube; | | delete tmp_cube; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 384 | | skipping to change at line 359 | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube addition"); | | arma_debug_assert_same_size(t, x, "cube addition"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(sli | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | ce,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] += x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview_cube; | | delete tmp_subview_cube; | |
| delete tmp_cube; | | delete tmp_cube; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 423 | | skipping to change at line 396 | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube subtraction"); | | arma_debug_assert_same_size(t, x, "cube subtraction"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(sl | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | ice,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] -= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview_cube; | | delete tmp_subview_cube; | |
| delete tmp_cube; | | delete tmp_cube; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 462 | | skipping to change at line 433 | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise cube multiplication"); | | arma_debug_assert_same_size(t, x, "element-wise cube multiplication"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slic | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | e,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] *= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview_cube; | | delete tmp_subview_cube; | |
| delete tmp_cube; | | delete tmp_cube; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 501 | | skipping to change at line 470 | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | | Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m)
: 0; | |
| const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | | const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>
(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x
_in.aux_col2, x_in.aux_slice2) : 0; | |
| const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | | const subview_cube<eT>& x = overlap ? (*tmp_subview_cube)
: x_in; | |
| | | | |
| subview_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise cube division"); | | arma_debug_assert_same_size(t, x, "element-wise cube division"); | |
| | | | |
|
| for(u32 slice = 0; slice < t.n_slices; ++slice) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | const u32 t_n_slices = t.n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < t_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
|
| eT* t_coldata = t.slice_colptr(slice,col); | | arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slic | |
| const eT* x_coldata = x.slice_colptr(slice,col); | | e,col), t_n_rows ); | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] /= x_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview_cube; | | delete tmp_subview_cube; | |
| delete tmp_cube; | | delete tmp_cube; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 538 | | skipping to change at line 505 | |
| { | | { | |
| 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_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "copy into subcube"); | | arma_debug_assert_same_size(t, x, "copy into subcube"); | |
| | | | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.slice_colptr(t.aux_slice1, col); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
| for(u32 row = 0; row < t.n_rows; ++row) | | | |
| { | | | |
| t_coldata[row] = x_coldata[row]; | | | |
| } | | | |
| | | | |
|
| | | for(u32 col = 0; col < t_n_cols; ++col) | |
| | | { | |
| | | syslib:copy_elem( t.slice_colptr(t_aux_slice1, col), x.colptr(col), t_n | |
| | | _rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator+= (const Base<eT,T1>& in) | | subview_cube<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_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube addition"); | | arma_debug_assert_same_size(t, x, "cube addition"); | |
| | | | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.slice_colptr(t.aux_slice1, col); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < t.n_rows; ++row) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
| t_coldata[row] += x_coldata[row]; | | arrayops::inplace_plus( t.slice_colptr(t_aux_slice1, col), x.colptr(col | |
| } | | ), t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator-= (const Base<eT,T1>& in) | | subview_cube<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_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube subtraction"); | | arma_debug_assert_same_size(t, x, "cube subtraction"); | |
| | | | |
|
| for(u32 col = 0; col < t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.slice_colptr(t.aux_slice1, col); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < t.n_rows; ++row) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
| t_coldata[row] -= x_coldata[row]; | | arrayops::inplace_minus( t.slice_colptr(t_aux_slice1, col), x.colptr(co | |
| } | | l), t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator%= (const Base<eT,T1>& in) | | subview_cube<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_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "cube schur product"); | | arma_debug_assert_same_size(t, x, "cube schur product"); | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.slice_colptr(t.aux_slice1, col); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
| t_coldata[row] *= x_coldata[row]; | | arrayops::inplace_mul( t.slice_colptr(t_aux_slice1, col), x.colptr(col) | |
| } | | , t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::operator/= (const Base<eT,T1>& in) | | subview_cube<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_cube<eT>& t = *this; | | subview_cube<eT>& t = *this; | |
| | | | |
| arma_debug_assert_same_size(t, x, "element-wise cube division"); | | arma_debug_assert_same_size(t, x, "element-wise cube division"); | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.slice_colptr(t.aux_slice1, col); | | const u32 t_aux_slice1 = t.aux_slice1; | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col = 0; col < t_n_cols; ++col) | |
| { | | { | |
| t_coldata[row] /= x_coldata[row]; | | arrayops::inplace_div( t.slice_colptr(t_aux_slice1, col), x.colptr(col) | |
| } | | , t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::fill(const eT val) | | subview_cube<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 slice = 0; slice < n_slices; ++slice) | | const u32 local_n_rows = n_rows; | |
| | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_slices = n_slices; | |
| | | | |
| | | for(u32 slice = 0; slice < local_n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col < n_cols; ++col) | | for(u32 col = 0; col < local_n_cols; ++col) | |
| { | | { | |
|
| eT* coldata = slice_colptr(slice,col); | | arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows ); | |
| | | | |
| for(u32 row = 0; row < n_rows; ++row) | | | |
| { | | | |
| coldata[row] = val; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::zeros() | | subview_cube<eT>::zeros() | |
| { | | { | |
| | | | |
| skipping to change at line 706 | | skipping to change at line 661 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| fill(eT(1)); | | fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview_cube<eT>::operator[](const u32 i) | | subview_cube<eT>::operator[](const u32 i) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview_cube::operator[]: cube is read-only"); | | | |
| | | | |
| const u32 in_slice = i / n_elem_slice; | | const u32 in_slice = i / n_elem_slice; | |
| const u32 offset = in_slice * n_elem_slice; | | const u32 offset = in_slice * n_elem_slice; | |
| const u32 j = i - offset; | | const u32 j = i - offset; | |
| | | | |
| const u32 in_col = j / n_rows; | | const u32 in_col = j / n_rows; | |
| const u32 in_row = j % n_rows; | | const u32 in_row = j % n_rows; | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| skipping to change at line 740 | | skipping to change at line 693 | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview_cube<eT>::operator()(const u32 i) | | subview_cube<eT>::operator()(const u32 i) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview_cube::operator(): matrix is read-only"
); | | | |
| arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of
bounds"); | | arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of
bounds"); | |
| | | | |
| const u32 in_slice = i / n_elem_slice; | | const u32 in_slice = i / n_elem_slice; | |
| const u32 offset = in_slice * n_elem_slice; | | const u32 offset = in_slice * n_elem_slice; | |
| const u32 j = i - offset; | | const u32 j = i - offset; | |
| | | | |
| const u32 in_col = j / n_rows; | | const u32 in_col = j / n_rows; | |
| const u32 in_row = j % n_rows; | | const u32 in_row = j % n_rows; | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| | | | |
| skipping to change at line 777 | | skipping to change at line 729 | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview_cube<eT>::operator()(const u32 in_row, const u32 in_col, const u32
in_slice) | | subview_cube<eT>::operator()(const u32 in_row, const u32 in_col, const u32
in_slice) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview_cube::operator(): matrix is read-only"
); | | | |
| arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice
>= n_slices) ), "subview_cube::operator(): location out of bounds"); | | arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice
>= n_slices) ), "subview_cube::operator(): location out of bounds"); | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
| subview_cube<eT>::operator()(const u32 in_row, const u32 in_col, const u32
in_slice) const | | subview_cube<eT>::operator()(const u32 in_row, const u32 in_col, const u32
in_slice) const | |
| | | | |
| skipping to change at line 800 | | skipping to change at line 751 | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview_cube<eT>::at(const u32 in_row, const u32 in_col, const u32 in_slice
) | | subview_cube<eT>::at(const u32 in_row, const u32 in_col, const u32 in_slice
) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview_cube::at(): cube is read-only"); | | | |
| | | | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
| subview_cube<eT>::at(const u32 in_row, const u32 in_col, const u32 in_slice
) const | | subview_cube<eT>::at(const u32 in_row, const u32 in_col, const u32 in_slice
) const | |
| { | | { | |
| const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_
col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT* | | eT* | |
| subview_cube<eT>::slice_colptr(const u32 in_slice, const u32 in_col) | | subview_cube<eT>::slice_colptr(const u32 in_slice, const u32 in_col) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview_cube::slice_colptr(): cube is read-onl | | | |
| y"); | | | |
| | | | |
| return & access::rw((*m_ptr).mem[ (in_slice + aux_slice1)*m.n_elem_slice
+ (in_col + aux_col1)*m.n_rows + aux_row1 ]); | | return & access::rw((*m_ptr).mem[ (in_slice + aux_slice1)*m.n_elem_slice
+ (in_col + aux_col1)*m.n_rows + aux_row1 ]); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const eT* | | const eT* | |
| subview_cube<eT>::slice_colptr(const u32 in_slice, const u32 in_col) const | | subview_cube<eT>::slice_colptr(const u32 in_slice, const u32 in_col) const | |
| { | | { | |
| return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_co
l1)*m.n_rows + aux_row1 ]; | | return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_co
l1)*m.n_rows + aux_row1 ]; | |
| } | | } | |
| | | | |
| skipping to change at line 867 | | skipping to change at line 814 | |
| ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | | ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) ) | |
| ); | | ); | |
| | | | |
| const bool slice_overlap = | | const bool slice_overlap = | |
| ( | | ( | |
| ( (x.aux_slice1 >= t.aux_slice1) && (x.aux_slice1 <= t.aux_slice2) ) | | ( (x.aux_slice1 >= t.aux_slice1) && (x.aux_slice1 <= t.aux_slice2) ) | |
| || | | || | |
| ( (x.aux_slice2 >= t.aux_slice1) && (x.aux_slice2 <= t.aux_slice2) ) | | ( (x.aux_slice2 >= t.aux_slice1) && (x.aux_slice2 <= t.aux_slice2) ) | |
| ); | | ); | |
| | | | |
|
| return (row_overlap & col_overlap & slice_overlap); | | const bool overlap = ( (row_overlap == true) && (col_overlap == true) & | |
| | | & (slice_overlap == true) ); | |
| | | | |
| | | return overlap; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview_cube<eT>::check_overlap(const Mat<eT>& x) const | | subview_cube<eT>::check_overlap(const Mat<eT>& x) const | |
| { | | { | |
| const subview_cube<eT>& t = *this; | | const subview_cube<eT>& t = *this; | |
| | | | |
| | | | |
| skipping to change at line 915 | | skipping to change at line 864 | |
| // | | // | |
| | | | |
| const u32 n_rows = in.n_rows; | | const u32 n_rows = in.n_rows; | |
| const u32 n_cols = in.n_cols; | | const u32 n_cols = in.n_cols; | |
| const u32 n_slices = in.n_slices; | | const u32 n_slices = in.n_slices; | |
| | | | |
| out.set_size(n_rows, n_cols, n_slices); | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols =
%d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_sl
ices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n
_cols % in.m.n_slices); | | arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols =
%d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_sl
ices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n
_cols % in.m.n_slices); | |
| | | | |
|
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice < n_slices; ++slice) | |
| { | | { | |
|
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col < n_cols; ++col) | |
| { | | { | |
|
| eT* out_coldata = out.slice_colptr(slice,col); | | syslib::copy_elem( out.slice_colptr(slice,col), in.slice_colptr(slice | |
| const eT* in_coldata = in.slice_colptr(slice,col); | | ,col), n_rows ); | |
| | | | |
| 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 948 | | skipping to change at line 890 | |
| //! mat X = Y.subcube(...) | | //! mat X = Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::extract(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::extract(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (in.n_slices != 1), "subview_cube::extract(): given sub
cube doesn't have exactly one slice" ); | | arma_debug_check( (in.n_slices != 1), "subview_cube::extract(): given sub
cube doesn't have exactly one slice" ); | |
| | | | |
|
| out.set_size(in.n_rows, in.n_cols); | | const u32 n_rows = in.n_rows; | |
| | | const u32 n_cols = in.n_cols; | |
| | | const u32 aux_slice1 = in.aux_slice1; | |
| | | | |
|
| for(u32 col = 0; col < in.n_cols; ++col) | | out.set_size(n_rows, n_cols); | |
| { | | | |
| const eT* in_coldata = in.slice_colptr(in.aux_slice1, col); | | | |
| eT* out_coldata = out.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < in.n_rows; ++row) | | for(u32 col = 0; col < n_cols; ++col) | |
| { | | { | |
| out_coldata[row] = in_coldata[row]; | | syslib::copy_elem( out.colptr(col), in.slice_colptr(aux_slice1, col), n | |
| } | | _rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! cube X += Y.subcube(...) | | //! cube X += Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 980 | | skipping to change at line 920 | |
| arma_debug_assert_same_size(out, in, "cube addition"); | | arma_debug_assert_same_size(out, in, "cube addition"); | |
| | | | |
| 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; | |
| const u32 n_slices = out.n_slices; | | const u32 n_slices = out.n_slices; | |
| | | | |
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice<n_slices; ++slice) | |
| { | | { | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
|
| eT* out_coldata = out.slice_colptr(slice,col); | | arrayops::inplace_plus( out.slice_colptr(slice,col), in.slice_colptr( | |
| const eT* in_coldata = in.slice_colptr(slice,col); | | slice,col), n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| out_coldata[row] += in_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! cube X -= Y.subcube(...) | | //! cube X -= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::minus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::minus_inplace(Cube<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 1009 | | skipping to change at line 943 | |
| arma_debug_assert_same_size(out, in, "cube subtraction"); | | arma_debug_assert_same_size(out, in, "cube subtraction"); | |
| | | | |
| 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; | |
| const u32 n_slices = out.n_slices; | | const u32 n_slices = out.n_slices; | |
| | | | |
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice<n_slices; ++slice) | |
| { | | { | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
|
| eT* out_coldata = out.slice_colptr(slice,col); | | arrayops::inplace_minus( out.slice_colptr(slice,col), in.slice_colptr | |
| const eT* in_coldata = in.slice_colptr(slice,col); | | (slice,col), n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| out_coldata[row] -= in_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! cube X %= Y.subcube(...) | | //! cube X %= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::schur_inplace(Cube<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::schur_inplace(Cube<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 1038 | | skipping to change at line 966 | |
| arma_debug_assert_same_size(out, in, "cube schur product"); | | arma_debug_assert_same_size(out, in, "cube schur product"); | |
| | | | |
| 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; | |
| const u32 n_slices = out.n_slices; | | const u32 n_slices = out.n_slices; | |
| | | | |
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice<n_slices; ++slice) | |
| { | | { | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
|
| eT* out_coldata = out.slice_colptr(slice,col); | | arrayops::inplace_mul( out.slice_colptr(slice,col), in.slice_colptr(s | |
| const eT* in_coldata = in.slice_colptr(slice,col); | | lice,col), n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| out_coldata[row] *= in_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! cube X /= Y.subcube(...) | | //! cube X /= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::div_inplace(Cube<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::div_inplace(Cube<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 1067 | | skipping to change at line 989 | |
| arma_debug_assert_same_size(out, in, "element-wise cube division"); | | arma_debug_assert_same_size(out, in, "element-wise cube division"); | |
| | | | |
| 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; | |
| const u32 n_slices = out.n_slices; | | const u32 n_slices = out.n_slices; | |
| | | | |
| for(u32 slice = 0; slice<n_slices; ++slice) | | for(u32 slice = 0; slice<n_slices; ++slice) | |
| { | | { | |
| for(u32 col = 0; col<n_cols; ++col) | | for(u32 col = 0; col<n_cols; ++col) | |
| { | | { | |
|
| eT* out_coldata = out.slice_colptr(slice,col); | | arrayops::inplace_div( out.slice_colptr(slice,col), in.slice_colptr(s | |
| const eT* in_coldata = in.slice_colptr(slice,col); | | lice,col), n_rows ); | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | | |
| out_coldata[row] /= in_coldata[row]; | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! mat X += Y.subcube(...) | | //! mat X += Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix addition"); | | arma_debug_assert_same_size(out, in, "matrix addition"); | |
| | | | |
|
| for(u32 col = 0; col < in.n_cols; ++col) | | const u32 in_n_rows = in.n_rows; | |
| { | | const u32 in_n_cols = in.n_cols; | |
| const eT* in_coldata = in.slice_colptr(in.aux_slice1, col); | | const u32 in_aux_slice1 = in.aux_slice1; | |
| eT* out_coldata = out.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < in.n_rows; ++row) | | for(u32 col = 0; col < in_n_cols; ++col) | |
| { | | { | |
| out_coldata[row] += in_coldata[row]; | | arrayops::inplace_plus( out.colptr(col), in.slice_colptr(in_aux_slice1, | |
| } | | col), in_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! mat X -= Y.subcube(...) | | //! mat X -= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::minus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::minus_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix subtraction"); | | arma_debug_assert_same_size(out, in, "matrix subtraction"); | |
| | | | |
|
| for(u32 col = 0; col < in.n_cols; ++col) | | const u32 in_n_rows = in.n_rows; | |
| { | | const u32 in_n_cols = in.n_cols; | |
| const eT* in_coldata = in.slice_colptr(in.aux_slice1, col); | | const u32 in_aux_slice1 = in.aux_slice1; | |
| eT* out_coldata = out.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < in.n_rows; ++row) | | for(u32 col = 0; col < in_n_cols; ++col) | |
| { | | { | |
| out_coldata[row] -= in_coldata[row]; | | arrayops::inplace_minus( out.colptr(col), in.slice_colptr(in_aux_slice1 | |
| } | | , col), in_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! mat X %= Y.subcube(...) | | //! mat X %= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::schur_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::schur_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix schur product"); | | arma_debug_assert_same_size(out, in, "matrix schur product"); | |
| | | | |
|
| for(u32 col = 0; col < in.n_cols; ++col) | | const u32 in_n_rows = in.n_rows; | |
| { | | const u32 in_n_cols = in.n_cols; | |
| const eT* in_coldata = in.slice_colptr(in.aux_slice1, col); | | const u32 in_aux_slice1 = in.aux_slice1; | |
| eT* out_coldata = out.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < in.n_rows; ++row) | | for(u32 col = 0; col < in_n_cols; ++col) | |
| { | | { | |
| out_coldata[row] *= in_coldata[row]; | | arrayops::inplace_mul( out.colptr(col), in.slice_colptr(in_aux_slice1, | |
| } | | col), in_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! mat X /= Y.subcube(...) | | //! mat X /= Y.subcube(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview_cube<eT>::div_inplace(Mat<eT>& out, const subview_cube<eT>& in) | | subview_cube<eT>::div_inplace(Mat<eT>& out, const subview_cube<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix element-wise division"); | | arma_debug_assert_same_size(out, in, "matrix element-wise division"); | |
| | | | |
|
| for(u32 col = 0; col < in.n_cols; ++col) | | const u32 in_n_rows = in.n_rows; | |
| { | | const u32 in_n_cols = in.n_cols; | |
| const eT* in_coldata = in.slice_colptr(in.aux_slice1, col); | | const u32 in_aux_slice1 = in.aux_slice1; | |
| eT* out_coldata = out.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row < in.n_rows; ++row) | | for(u32 col = 0; col < in_n_cols; ++col) | |
| { | | { | |
| out_coldata[row] /= in_coldata[row]; | | arrayops::inplace_div( out.colptr(col), in.slice_colptr(in_aux_slice1, | |
| } | | col), in_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 87 change blocks. |
| 273 lines changed or deleted | | 203 lines changed or added | |
|
| subview_meat.hpp | | subview_meat.hpp | |
| | | | |
| skipping to change at line 61 | | skipping to change at line 61 | |
| , n_rows(1 + in_row2 - in_row1) | | , n_rows(1 + in_row2 - in_row1) | |
| , n_cols(1 + in_col2 - in_col1) | | , n_cols(1 + in_col2 - in_col1) | |
| , n_elem(n_rows*n_cols) | | , n_elem(n_rows*n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| subview<eT>::fill(const eT val) | | subview<eT>::operator+= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 col = 0; col<n_cols; ++col) | | const u32 local_n_cols = n_cols; | |
| { | | const u32 local_n_rows = n_rows; | |
| eT* coldata = colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | if(local_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| { | | { | |
|
| coldata[row] = val; | | at(0, col) += val; | |
| } | | } | |
| } | | } | |
|
| | | else | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| subview<eT>::operator+= (const eT val) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| for(u32 col = 0; col<n_cols; ++col) | | | |
| { | | { | |
|
| eT* coldata = colptr(col); | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | | |
| for(u32 row = 0; row<n_rows; ++row) | | | |
| { | | { | |
|
| coldata[row] += val; | | arrayops::inplace_plus( colptr(col), val, local_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator-= (const eT val) | | subview<eT>::operator-= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 col = 0; col<n_cols; ++col) | | const u32 local_n_cols = n_cols; | |
| { | | const u32 local_n_rows = n_rows; | |
| eT* coldata = colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | if(local_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| { | | { | |
|
| coldata[row] -= val; | | at(0, col) -= val; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus( colptr(col), val, local_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator*= (const eT val) | | subview<eT>::operator*= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 col = 0; col<n_cols; ++col) | | const u32 local_n_cols = n_cols; | |
| { | | const u32 local_n_rows = n_rows; | |
| eT* coldata = colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | if(local_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| { | | { | |
|
| coldata[row] *= val; | | at(0, col) *= val; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( colptr(col), val, local_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator/= (const eT val) | | subview<eT>::operator/= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| for(u32 col = 0; col<n_cols; ++col) | | const u32 local_n_cols = n_cols; | |
| { | | const u32 local_n_rows = n_rows; | |
| eT* coldata = colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | if(local_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| { | | { | |
|
| coldata[row] /= val; | | at(0, col) /= val; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_div( colptr(col), val, local_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | arma_inline | |
| void | | void | |
|
| subview<eT>::operator_equ_mat(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"); | |
| | | | |
|
| const u32 t_n_cols = t.n_cols; | | | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
|
| | | | |
| for(u32 col=0; col<t_n_cols; ++col) | | | |
| { | | | |
| syslib::copy_elem( t.colptr(col), x.colptr(col), t_n_rows ); | | | |
| } | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1> | | | |
| inline | | | |
| void | | | |
| subview<eT>::operator_equ_proxy(const Base<eT,T1>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const Proxy<T1> x(in.get_ref()); | | | |
| | | | |
| subview<eT>& t = *this; | | | |
| | | | |
| arma_debug_assert_same_size(t, x, "insert into submatrix"); | | | |
| | | | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
|
| const u32 t_n_rows = t.n_rows; | | | |
| | | | |
|
| for(u32 col = 0; col<t_n_cols; ++col) | | if(t_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(u32 row = 0; row<t_n_rows; ++row) | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] = x.at(row,col); | | at(0,col) = x_mem[col]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | syslib::copy_elem( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<typename T1> | | | |
| arma_inline | | | |
| void | | | |
| subview<eT>::operator= (const Base<eT,T1>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| (is_Mat<T1>::value == true) ? operator_equ_mat(in) : operator_equ_proxy(i | | | |
| n); | | | |
| } | | } | |
| | | | |
| 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 Proxy<T1> x(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | 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) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| | | if(t_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] += x.at(row,col); | | at(0,col) += x_mem[col]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| 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 Proxy<T1> x(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | 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) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| | | if(t_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] -= x.at(row,col); | | at(0,col) -= x_mem[col]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| 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 Proxy<T1> x(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | 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) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| | | if(t_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] *= x.at(row,col); | | at(0,col) *= x_mem[col]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| 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 Proxy<T1> x(in.get_ref()); | | const unwrap<T1> tmp(in.get_ref()); | |
| | | 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) | | const u32 t_n_rows = t.n_rows; | |
| | | const u32 t_n_cols = t.n_cols; | |
| | | | |
| | | if(t_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] /= x.at(row,col); | | at(0,col) /= x_mem[col]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! 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(); | |
| | | | |
| | | | |
| skipping to change at line 346 | | skipping to change at line 363 | |
| 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"); | |
| | | | |
| const u32 t_n_cols = t.n_cols; | | const u32 t_n_cols = t.n_cols; | |
| const u32 t_n_rows = t.n_rows; | | const u32 t_n_rows = t.n_rows; | |
| | | | |
|
| for(u32 col = 0; col<t_n_cols; ++col) | | if(t_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | t.at(0,col) = x.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| syslib::copy_elem( t.colptr(col), x.colptr(col), t_n_rows ); | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | syslib::copy_elem( t.colptr(col), x.colptr(col), t_n_rows ); | |
| | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| 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) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.colptr(col); | | | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | if(t_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] += x_coldata[row]; | | t.at(0,col) += x.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
|
| | | if(overlap) | |
| | | { | |
| | | delete tmp_subview; | |
| | | delete tmp_mat; | |
| | | } | |
| } | | } | |
| | | | |
| 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 subtraction"); | | arma_debug_assert_same_size(t, x, "matrix subtraction"); | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.colptr(col); | | | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | if(t_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] -= x_coldata[row]; | | t.at(0,col) -= x.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 443 | | skipping to change at line 487 | |
| 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 schur product"); | | arma_debug_assert_same_size(t, x, "matrix schur product"); | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.colptr(col); | | | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | if(t_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] *= x_coldata[row]; | | t.at(0,col) *= x.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 479 | | skipping to change at line 530 | |
| 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, "element-wise matrix division"); | | arma_debug_assert_same_size(t, x, "element-wise matrix division"); | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | const u32 t_n_rows = t.n_rows; | |
| { | | const u32 t_n_cols = t.n_cols; | |
| eT* t_coldata = t.colptr(col); | | | |
| const eT* x_coldata = x.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<t.n_rows; ++row) | | if(t_n_rows == 1) | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| | | { | |
| | | t.at(0,col) /= x.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<t_n_cols; ++col) | |
| { | | { | |
|
| t_coldata[row] /= x_coldata[row]; | | arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| subview<eT>::zeros() | | subview<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| subview<eT>& t = *this; | | const u32 local_n_cols = n_cols; | |
| | | const u32 local_n_rows = n_rows; | |
| | | | |
|
| for(u32 col = 0; col<t.n_cols; ++col) | | if(local_n_rows == 1) | |
| { | | { | |
|
| eT* t_coldata = t.colptr(col); | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | | |
| for(u32 row = 0; row<t.n_rows; ++row) | | | |
| { | | { | |
|
| t_coldata[row] = eT(0); | | at(0,col) = val; | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | else | |
| | | { | |
| | | for(u32 col=0; col<local_n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_set( colptr(col), val, local_n_rows ); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | subview<eT>::zeros() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | (*this).fill(eT(0)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview<eT>::operator[](const u32 i) | | subview<eT>::operator[](const u32 i) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview::operator[]: matrix is read-only"); | | | |
| | | | |
| const u32 in_col = i / n_rows; | | const u32 in_col = i / n_rows; | |
| const u32 in_row = i % n_rows; | | const u32 in_row = i % n_rows; | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
| | | | |
| skipping to change at line 551 | | skipping to change at line 621 | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview<eT>::operator()(const u32 i) | | subview<eT>::operator()(const u32 i) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only"); | | | |
| arma_debug_check( (i >= n_elem), "subview::operator(): index out of bound
s"); | | arma_debug_check( (i >= n_elem), "subview::operator(): index out of bound
s"); | |
| | | | |
| const u32 in_col = i / n_rows; | | const u32 in_col = i / n_rows; | |
| const u32 in_row = i % n_rows; | | const u32 in_row = i % n_rows; | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 580 | | skipping to change at line 649 | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview<eT>::operator()(const u32 in_row, const u32 in_col) | | subview<eT>::operator()(const u32 in_row, const u32 in_col) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only"); | | | |
| arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::o
perator(): index out of bounds"); | | arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::o
perator(): index out of bounds"); | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
| subview<eT>::operator()(const u32 in_row, const u32 in_col) const | | subview<eT>::operator()(const u32 in_row, const u32 in_col) const | |
| | | | |
| skipping to change at line 603 | | skipping to change at line 671 | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| subview<eT>::at(const u32 in_row, const u32 in_col) | | subview<eT>::at(const u32 in_row, const u32 in_col) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview::at(): matrix is read-only"); | | | |
| | | | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return access::rw( (*m_ptr).mem[index] ); | | return access::rw( (*m_ptr).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
| subview<eT>::at(const u32 in_row, const u32 in_col) const | | subview<eT>::at(const u32 in_row, const u32 in_col) const | |
| { | | { | |
| const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT* | | eT* | |
| subview<eT>::colptr(const u32 in_col) | | subview<eT>::colptr(const u32 in_col) | |
| { | | { | |
|
| arma_check( (m_ptr == 0), "subview::colptr(): matrix is read-only"); | | | |
| | | | |
| return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1
]); | | return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1
]); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const eT* | | const eT* | |
| subview<eT>::colptr(const u32 in_col) const | | subview<eT>::colptr(const u32 in_col) const | |
| { | | { | |
| return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; | | return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; | |
| } | | } | |
| | | | |
| skipping to change at line 663 | | skipping to change at line 727 | |
| ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) ) | | ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) ) | |
| ); | | ); | |
| | | | |
| const bool col_overlap = | | const bool col_overlap = | |
| ( | | ( | |
| ( (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); | | const bool overlap = ( (row_overlap == true) && (col_overlap == true) ) | |
| | | ; | |
| | | | |
| | | return overlap; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview<eT>::is_vec() const | | subview<eT>::is_vec() const | |
| { | | { | |
| return ( (n_rows == 1) || (n_cols == 1) ); | | return ( (n_rows == 1) || (n_cols == 1) ); | |
| } | | } | |
| | | | |
| skipping to change at line 704 | | skipping to change at line 770 | |
| 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(in.is_vec() == true) | | if(in.is_vec() == true) | |
| { | | { | |
| if(n_cols == 1) // a column vector | | if(n_cols == 1) // a column vector | |
| { | | { | |
| arma_extra_debug_print("subview::extract(): copying col (going across
rows)"); | | arma_extra_debug_print("subview::extract(): copying col (going across
rows)"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | // in.colptr(0) the first column of the subview, taking into account | |
| const eT* in_coldata = in.colptr(0); // the first column of the subv | | any row offset | |
| iew, taking into account any row offset | | syslib::copy_elem( out.memptr(), in.colptr(0), n_rows ); | |
| | | | |
| for(u32 row=0; row<n_rows; ++row) | | | |
| { | | | |
| out_mem[row] = in_coldata[row]; | | | |
| } | | | |
| } | | } | |
| else // a row vector | | else // a row vector | |
| { | | { | |
| arma_extra_debug_print("subview::extract(): copying row (going across
columns)"); | | arma_extra_debug_print("subview::extract(): copying row (going across
columns)"); | |
| | | | |
| const Mat<eT>& X = in.m; | | const Mat<eT>& X = in.m; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 row = in.aux_row1; | | const u32 row = in.aux_row1; | |
| const u32 start_col = in.aux_col1; | | const u32 start_col = in.aux_col1; | |
| | | | |
| skipping to change at line 759 | | skipping to change at line 820 | |
| void | | void | |
| subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in) | | subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix addition"); | | arma_debug_assert_same_size(out, in, "matrix addition"); | |
| | | | |
| 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) | | if(n_rows == 1) | |
| { | | { | |
|
| eT* out_coldata = out.colptr(col); | | eT* out_mem = out.memptr(); | |
| 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]; | | out_mem[col] += in.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_plus(out.colptr(col), in.colptr(col), n_rows); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! X -= Y.submat(...) | | //! X -= Y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in) | | subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix subtraction"); | | arma_debug_assert_same_size(out, in, "matrix subtraction"); | |
| | | | |
| 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) | | if(n_rows == 1) | |
| { | | { | |
|
| eT* out_coldata = out.colptr(col); | | eT* out_mem = out.memptr(); | |
| 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]; | | out_mem[col] -= in.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_minus(out.colptr(col), in.colptr(col), n_rows); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! X %= Y.submat(...) | | //! X %= Y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in) | | subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "matrix schur product"); | | arma_debug_assert_same_size(out, in, "matrix schur product"); | |
| | | | |
| 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) | | if(n_rows == 1) | |
| { | | { | |
|
| eT* out_coldata = out.colptr(col); | | eT* out_mem = out.memptr(); | |
| 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]; | | out_mem[col] *= in.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<n_cols; ++col) | |
| | | { | |
| | | arrayops::inplace_mul(out.colptr(col), in.colptr(col), n_rows); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! X /= Y.submat(...) | | //! X /= Y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in) | | subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out, in, "element-wise matrix division"); | | arma_debug_assert_same_size(out, in, "element-wise matrix division"); | |
| | | | |
| 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) | | if(n_rows == 1) | |
| { | | { | |
|
| eT* out_coldata = out.colptr(col); | | eT* out_mem = out.memptr(); | |
| const eT* in_coldata = in.colptr(col); | | | |
| | | | |
|
| for(u32 row = 0; row<n_rows; ++row) | | for(u32 col=0; col<n_cols; ++col) | |
| | | { | |
| | | out_mem[col] /= in.at(0,col); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(u32 col=0; col<n_cols; ++col) | |
| { | | { | |
|
| out_coldata[row] /= in_coldata[row]; | | arrayops::inplace_div(out.colptr(col), in.colptr(col), n_rows); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| | | | |
End of changes. 106 change blocks. |
| 183 lines changed or deleted | | 268 lines changed or added | |
|