| Col_meat.hpp | | Col_meat.hpp | |
| | | | |
| skipping to change at line 692 | | skipping to change at line 692 | |
| void | | void | |
| Col<eT>::load(std::istream& is, const file_type type) | | Col<eT>::load(std::istream& is, const file_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::load(is, type); | | Mat<eT>::load(is, type); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | typename Col<eT>::row_iterator | |
| | | Col<eT>::begin_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o | |
| | | f bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + row_num; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Col<eT>::const_row_iterator | |
| | | Col<eT>::begin_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o | |
| | | f bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + row_num; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Col<eT>::row_iterator | |
| | | Col<eT>::end_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of | |
| | | bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + row_num + 1; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Col<eT>::const_row_iterator | |
| | | Col<eT>::end_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of | |
| | | bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + row_num + 1; | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 52 lines changed or added | |
|
| Cube_meat.hpp | | Cube_meat.hpp | |
| | | | |
| skipping to change at line 1686 | | skipping to change at line 1686 | |
| case ppm_binary: | | case ppm_binary: | |
| diskio::load_ppm_binary(*this, "[istream]", is); | | diskio::load_ppm_binary(*this, "[istream]", is); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("Cube::load(): unsupported file type"); | | arma_stop("Cube::load(): unsupported file type"); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::iterator | |
| | | Cube<eT>::begin() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::const_iterator | |
| | | Cube<eT>::begin() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::iterator | |
| | | Cube<eT>::end() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr() + n_elem; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::const_iterator | |
| | | Cube<eT>::end() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr() + n_elem; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::slice_iterator | |
| | | Cube<eT>::begin_slice(const u32 slice_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of b | |
| | | ounds"); | |
| | | | |
| | | return slice_memptr(slice_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::const_slice_iterator | |
| | | Cube<eT>::begin_slice(const u32 slice_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of b | |
| | | ounds"); | |
| | | | |
| | | return slice_memptr(slice_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::slice_iterator | |
| | | Cube<eT>::end_slice(const u32 slice_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bou | |
| | | nds"); | |
| | | | |
| | | return slice_memptr(slice_num) + n_elem_slice; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Cube<eT>::const_slice_iterator | |
| | | Cube<eT>::end_slice(const u32 slice_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bou | |
| | | nds"); | |
| | | | |
| | | return slice_memptr(slice_num) + n_elem_slice; | |
| | | } | |
| | | | |
| //! 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; | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 92 lines changed or added | |
|
| Cube_proto.hpp | | Cube_proto.hpp | |
| | | | |
| skipping to change at line 166 | | skipping to change at line 166 | |
| 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(); | |
| | | | |
| inline void save(const std::string name, const file_type type = arma_bi
nary) const; | | inline void save(const std::string name, const file_type type = arma_bi
nary) const; | |
| inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | | inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | |
| | | | |
| inline void load(const std::string name, const file_type type = auto_de
tect); | | inline void load(const std::string name, const file_type type = auto_de
tect); | |
| inline void load( std::istream& is, const file_type type = auto_de
tect); | | inline void load( std::istream& is, const file_type type = auto_de
tect); | |
| | | | |
|
| | | // iterators | |
| | | | |
| | | typedef eT* iterator; | |
| | | typedef const eT* const_iterator; | |
| | | | |
| | | typedef eT* slice_iterator; | |
| | | typedef const eT* const_slice_iterator; | |
| | | | |
| | | inline iterator begin(); | |
| | | inline const_iterator begin() const; | |
| | | | |
| | | inline iterator end(); | |
| | | inline const_iterator end() const; | |
| | | | |
| | | inline slice_iterator begin_slice(const u32 slice_num); | |
| | | inline const_slice_iterator begin_slice(const u32 slice_num) const; | |
| | | | |
| | | inline slice_iterator end_slice(const u32 slice_num); | |
| | | inline const_slice_iterator end_slice(const u32 slice_num) const; | |
| | | | |
| 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); | |
| | | | |
| inline void delete_mat(); | | inline void delete_mat(); | |
| inline void create_mat(); | | inline void create_mat(); | |
| }; | | }; | |
| | | | |
| class Cube_aux | | class Cube_aux | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 20 lines changed or added | |
|
| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 2265 | | skipping to change at line 2265 | |
| case pgm_binary: | | case pgm_binary: | |
| diskio::load_pgm_binary(*this, "[istream]", is); | | diskio::load_pgm_binary(*this, "[istream]", is); | |
| break; | | break; | |
| | | | |
| default: | | default: | |
| arma_stop("Mat::load(): unsupported file type"); | | arma_stop("Mat::load(): unsupported file type"); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const u32 in_row) | |
| | | : M (in_M ) | |
| | | , row(in_row) | |
| | | , col(0 ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT& | |
| | | Mat<eT>::row_iterator::operator*() | |
| | | { | |
| | | return M.at(row,col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::row_iterator& | |
| | | Mat<eT>::row_iterator::operator++() | |
| | | { | |
| | | ++col; | |
| | | | |
| | | if(col >= M.n_cols) | |
| | | { | |
| | | col = 0; | |
| | | ++row; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::row_iterator::operator++(int) | |
| | | { | |
| | | operator++(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::row_iterator& | |
| | | Mat<eT>::row_iterator::operator--() | |
| | | { | |
| | | if(col > 0) | |
| | | { | |
| | | --col; | |
| | | } | |
| | | else | |
| | | { | |
| | | if(row > 0) | |
| | | { | |
| | | col = M.n_cols - 1; | |
| | | --row; | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::row_iterator::operator--(int) | |
| | | { | |
| | | operator--(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) | |
| | | const | |
| | | { | |
| | | return ( (row != X.row) || (col != X.col) ) ? true : false; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) | |
| | | const | |
| | | { | |
| | | return ( (row == X.row) && (col == X.col) ) ? true : false; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const | |
| | | u32 in_row) | |
| | | : M (in_M ) | |
| | | , row(in_row) | |
| | | , col(0 ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>::row_iterator | |
| | | & X) | |
| | | : M (X.M) | |
| | | , row(X.row) | |
| | | , col(X.col) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | eT | |
| | | Mat<eT>::const_row_iterator::operator*() const | |
| | | { | |
| | | return M.at(row,col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_row_iterator& | |
| | | Mat<eT>::const_row_iterator::operator++() | |
| | | { | |
| | | ++col; | |
| | | | |
| | | if(col >= M.n_cols) | |
| | | { | |
| | | col = 0; | |
| | | ++row; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::const_row_iterator::operator++(int) | |
| | | { | |
| | | operator++(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_row_iterator& | |
| | | Mat<eT>::const_row_iterator::operator--() | |
| | | { | |
| | | if(col > 0) | |
| | | { | |
| | | --col; | |
| | | } | |
| | | else | |
| | | { | |
| | | if(row > 0) | |
| | | { | |
| | | col = M.n_cols - 1; | |
| | | --row; | |
| | | } | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | Mat<eT>::const_row_iterator::operator--(int) | |
| | | { | |
| | | operator--(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_i | |
| | | terator& X) const | |
| | | { | |
| | | return ( (row != X.row) || (col != X.col) ) ? true : false; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_i | |
| | | terator& X) const | |
| | | { | |
| | | return ( (row == X.row) && (col == X.col) ) ? true : false; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::iterator | |
| | | Mat<eT>::begin() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_iterator | |
| | | Mat<eT>::begin() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::iterator | |
| | | Mat<eT>::end() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr() + n_elem; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_iterator | |
| | | Mat<eT>::end() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return memptr() + n_elem; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::col_iterator | |
| | | Mat<eT>::begin_col(const u32 col_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds" | |
| | | ); | |
| | | | |
| | | return colptr(col_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_col_iterator | |
| | | Mat<eT>::begin_col(const u32 col_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds" | |
| | | ); | |
| | | | |
| | | return colptr(col_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::col_iterator | |
| | | Mat<eT>::end_col(const u32 col_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); | |
| | | | |
| | | return colptr(col_num) + n_rows; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_col_iterator | |
| | | Mat<eT>::end_col(const u32 col_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); | |
| | | | |
| | | return colptr(col_num) + n_rows; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::row_iterator | |
| | | Mat<eT>::begin_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bo | |
| | | unds" ); | |
| | | | |
| | | return typename Mat<eT>::row_iterator(*this, row_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_row_iterator | |
| | | Mat<eT>::begin_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bo | |
| | | unds" ); | |
| | | | |
| | | return typename Mat<eT>::const_row_iterator(*this, row_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::row_iterator | |
| | | Mat<eT>::end_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of boun | |
| | | ds" ); | |
| | | | |
| | | return typename Mat<eT>::row_iterator(*this, row_num + 1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Mat<eT>::const_row_iterator | |
| | | Mat<eT>::end_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | 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); | |
| | | } | |
| | | | |
| //! 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; | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 332 lines changed or added | |
|
| Mat_proto.hpp | | Mat_proto.hpp | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 26 | |
| //! \addtogroup Mat | | //! \addtogroup Mat | |
| //! @{ | | //! @{ | |
| | | | |
| //! Dense matrix class | | //! Dense matrix class | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class Mat : public Base< eT, Mat<eT> > | | class Mat : public Base< eT, Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| typedef eT elem_type; //!< the typ | | typedef eT elem_type; //!< the type of el | |
| e of elements stored in the matrix | | ements stored in the matrix | |
| typedef typename get_pod_type<elem_type>::result pod_type; //!< if eT i | | typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-c | |
| s non-complex, pod_type is same as eT. otherwise, pod_type is the underlyin | | omplex, pod_type is same as eT. otherwise, pod_type is the underlying type | |
| g type used by std::complex | | 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
sed (read-only) | | const bool use_aux_mem; //!< true if externally managed memory is being u
sed (read-only) | |
| | | | |
| arma_aligned const eT* const mem; //!< pointer to 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[ 16 ]; | |
| | | | |
| skipping to change at line 212 | | skipping to change at line 212 | |
| 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(); | |
| | | | |
| inline void save(const std::string name, const file_type type = arma_bi
nary) const; | | inline void save(const std::string name, const file_type type = arma_bi
nary) const; | |
| inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | | inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | |
| | | | |
| inline void load(const std::string name, const file_type type = auto_de
tect); | | inline void load(const std::string name, const file_type type = auto_de
tect); | |
| inline void load( std::istream& is, const file_type type = auto_de
tect); | | inline void load( std::istream& is, const file_type type = auto_de
tect); | |
| | | | |
|
| | | // iterators | |
| | | | |
| | | typedef eT* iterator; | |
| | | typedef const eT* const_iterator; | |
| | | | |
| | | typedef eT* col_iterator; | |
| | | typedef const eT* const_col_iterator; | |
| | | | |
| | | class row_iterator | |
| | | { | |
| | | public: | |
| | | | |
| | | inline row_iterator(Mat<eT>& in_M, const u32 in_row); | |
| | | | |
| | | inline eT& operator* (); | |
| | | | |
| | | inline row_iterator& operator++(); | |
| | | inline void operator++(int); | |
| | | | |
| | | inline row_iterator& operator--(); | |
| | | inline void operator--(int); | |
| | | | |
| | | inline bool operator!=(const row_iterator& X) const; | |
| | | inline bool operator==(const row_iterator& X) const; | |
| | | | |
| | | arma_aligned Mat<eT>& M; | |
| | | arma_aligned u32 row; | |
| | | arma_aligned u32 col; | |
| | | }; | |
| | | | |
| | | class const_row_iterator | |
| | | { | |
| | | public: | |
| | | | |
| | | const_row_iterator(const Mat<eT>& in_M, const u32 in_row); | |
| | | const_row_iterator(const row_iterator& X); | |
| | | | |
| | | inline eT operator*() const; | |
| | | | |
| | | inline const_row_iterator& operator++(); | |
| | | inline void operator++(int); | |
| | | | |
| | | inline const_row_iterator& operator--(); | |
| | | inline void operator--(int); | |
| | | | |
| | | inline bool operator!=(const const_row_iterator& X) const; | |
| | | inline bool operator==(const const_row_iterator& X) const; | |
| | | | |
| | | arma_aligned const Mat<eT>& M; | |
| | | arma_aligned u32 row; | |
| | | arma_aligned u32 col; | |
| | | }; | |
| | | | |
| | | inline iterator begin(); | |
| | | inline const_iterator begin() const; | |
| | | | |
| | | inline iterator end(); | |
| | | inline const_iterator end() const; | |
| | | | |
| | | inline col_iterator begin_col(const u32 col_num); | |
| | | inline const_col_iterator begin_col(const u32 col_num) const; | |
| | | | |
| | | inline col_iterator end_col (const u32 col_num); | |
| | | inline const_col_iterator end_col (const u32 col_num) const; | |
| | | | |
| | | inline row_iterator begin_row(const u32 row_num); | |
| | | inline const_row_iterator begin_row(const u32 row_num) const; | |
| | | | |
| | | inline row_iterator end_row (const u32 row_num); | |
| | | inline const_row_iterator end_row (const u32 row_num) const; | |
| | | | |
| protected: | | protected: | |
| | | | |
| inline void init(const u32 in_rows, const u32 in_cols); | | inline void init(const u32 in_rows, const u32 in_cols); | |
| inline void init(const std::string& text); | | inline void init(const std::string& text); | |
| inline void init(const Mat& x); | | inline void init(const Mat& x); | |
| | | | |
| inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons
t u32 aux_n_cols); | | 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; | |
| }; | | }; | |
| | | | |
| class Mat_aux | | class Mat_aux | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x); | | template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x); | |
| template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | | template<typename T> arma_inline static void prefix_pp(Mat< std::complex
<T> >& x); | |
| | | | |
| template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | | template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x); | |
| | | | |
End of changes. 3 change blocks. |
| 5 lines changed or deleted | | 77 lines changed or added | |
|
| Row_meat.hpp | | Row_meat.hpp | |
| | | | |
| skipping to change at line 663 | | skipping to change at line 663 | |
| void | | void | |
| Row<eT>::load(std::istream& is, const file_type type) | | Row<eT>::load(std::istream& is, const file_type type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>::load(is, type); | | Mat<eT>::load(is, type); | |
| | | | |
| arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | | arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | typename Row<eT>::row_iterator | |
| | | Row<eT>::begin_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o | |
| | | f bounds"); | |
| | | | |
| | | return Mat<eT>::memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Row<eT>::const_row_iterator | |
| | | Row<eT>::begin_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out o | |
| | | f bounds"); | |
| | | | |
| | | return Mat<eT>::memptr(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Row<eT>::row_iterator | |
| | | Row<eT>::end_row(const u32 row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of | |
| | | bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + Mat<eT>::n_cols; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename Row<eT>::const_row_iterator | |
| | | Row<eT>::end_row(const u32 row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of | |
| | | bounds"); | |
| | | | |
| | | return Mat<eT>::memptr() + Mat<eT>::n_cols; | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 52 lines changed or added | |
|
| armadillo | | armadillo | |
| | | | |
| skipping to change at line 175 | | skipping to change at line 175 | |
| #include "armadillo_bits/op_dotext_proto.hpp" | | #include "armadillo_bits/op_dotext_proto.hpp" | |
| #include "armadillo_bits/op_flip_proto.hpp" | | #include "armadillo_bits/op_flip_proto.hpp" | |
| #include "armadillo_bits/op_princomp_proto.hpp" | | #include "armadillo_bits/op_princomp_proto.hpp" | |
| #include "armadillo_bits/op_princomp_cov_proto.hpp" | | #include "armadillo_bits/op_princomp_cov_proto.hpp" | |
| | | | |
| #include "armadillo_bits/glue_times_proto.hpp" | | #include "armadillo_bits/glue_times_proto.hpp" | |
| #include "armadillo_bits/glue_cov_proto.hpp" | | #include "armadillo_bits/glue_cov_proto.hpp" | |
| #include "armadillo_bits/glue_cor_proto.hpp" | | #include "armadillo_bits/glue_cor_proto.hpp" | |
| #include "armadillo_bits/glue_kron_proto.hpp" | | #include "armadillo_bits/glue_kron_proto.hpp" | |
| #include "armadillo_bits/glue_cross_proto.hpp" | | #include "armadillo_bits/glue_cross_proto.hpp" | |
|
| | | #include "armadillo_bits/glue_join_proto.hpp" | |
| | | | |
| // | | // | |
| // debugging functions | | // debugging functions | |
| | | | |
| #include "armadillo_bits/debug.hpp" | | #include "armadillo_bits/debug.hpp" | |
| | | | |
| // | | // | |
| // classes that underlay metaprogramming | | // classes that underlay metaprogramming | |
| | | | |
| #include "armadillo_bits/Proxy.hpp" | | #include "armadillo_bits/Proxy.hpp" | |
| | | | |
| skipping to change at line 290 | | skipping to change at line 291 | |
| #include "armadillo_bits/fn_prod.hpp" | | #include "armadillo_bits/fn_prod.hpp" | |
| #include "armadillo_bits/fn_eps.hpp" | | #include "armadillo_bits/fn_eps.hpp" | |
| #include "armadillo_bits/fn_pinv.hpp" | | #include "armadillo_bits/fn_pinv.hpp" | |
| #include "armadillo_bits/fn_rank.hpp" | | #include "armadillo_bits/fn_rank.hpp" | |
| #include "armadillo_bits/fn_kron.hpp" | | #include "armadillo_bits/fn_kron.hpp" | |
| #include "armadillo_bits/fn_flip.hpp" | | #include "armadillo_bits/fn_flip.hpp" | |
| #include "armadillo_bits/fn_as_scalar.hpp" | | #include "armadillo_bits/fn_as_scalar.hpp" | |
| #include "armadillo_bits/fn_princomp.hpp" | | #include "armadillo_bits/fn_princomp.hpp" | |
| #include "armadillo_bits/fn_princomp_cov.hpp" | | #include "armadillo_bits/fn_princomp_cov.hpp" | |
| #include "armadillo_bits/fn_cross.hpp" | | #include "armadillo_bits/fn_cross.hpp" | |
|
| | | #include "armadillo_bits/fn_join.hpp" | |
| | | #include "armadillo_bits/fn_find.hpp" | |
| | | | |
| // | | // | |
| // class meat | | // class meat | |
| | | | |
| #include "armadillo_bits/gemm.hpp" | | #include "armadillo_bits/gemm.hpp" | |
| #include "armadillo_bits/gemv.hpp" | | #include "armadillo_bits/gemv.hpp" | |
| #include "armadillo_bits/gemm_mixed.hpp" | | #include "armadillo_bits/gemm_mixed.hpp" | |
| | | | |
| #include "armadillo_bits/eop_core_meat.hpp" | | #include "armadillo_bits/eop_core_meat.hpp" | |
| #include "armadillo_bits/eop_cube_core_meat.hpp" | | #include "armadillo_bits/eop_cube_core_meat.hpp" | |
| | | | |
| skipping to change at line 353 | | skipping to change at line 356 | |
| #include "armadillo_bits/op_dotext_meat.hpp" | | #include "armadillo_bits/op_dotext_meat.hpp" | |
| #include "armadillo_bits/op_flip_meat.hpp" | | #include "armadillo_bits/op_flip_meat.hpp" | |
| #include "armadillo_bits/op_princomp_meat.hpp" | | #include "armadillo_bits/op_princomp_meat.hpp" | |
| #include "armadillo_bits/op_princomp_cov_meat.hpp" | | #include "armadillo_bits/op_princomp_cov_meat.hpp" | |
| | | | |
| #include "armadillo_bits/glue_times_meat.hpp" | | #include "armadillo_bits/glue_times_meat.hpp" | |
| #include "armadillo_bits/glue_cov_meat.hpp" | | #include "armadillo_bits/glue_cov_meat.hpp" | |
| #include "armadillo_bits/glue_cor_meat.hpp" | | #include "armadillo_bits/glue_cor_meat.hpp" | |
| #include "armadillo_bits/glue_kron_meat.hpp" | | #include "armadillo_bits/glue_kron_meat.hpp" | |
| #include "armadillo_bits/glue_cross_meat.hpp" | | #include "armadillo_bits/glue_cross_meat.hpp" | |
|
| | | #include "armadillo_bits/glue_join_meat.hpp" | |
| } | | } | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 3 change blocks. |
| 0 lines changed or deleted | | 4 lines changed or added | |
|
| diskio_meat.hpp | | diskio_meat.hpp | |
| | | | |
| skipping to change at line 1174 | | skipping to change at line 1174 | |
| static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; | | static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; | |
| static const std::string P5 = "P5"; | | static const std::string P5 = "P5"; | |
| | | | |
| podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); | | podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
| | | | |
| f.read(raw_header.memptr(), ARMA_MAT_TXT.length()); | | f.read(raw_header.memptr(), ARMA_MAT_TXT.length()); | |
| raw_header[ARMA_MAT_TXT.length()] = '\0'; | | raw_header[ARMA_MAT_TXT.length()] = '\0'; | |
| | | | |
|
| | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) | | if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) | |
| { | | { | |
| load_arma_ascii(x, name, f); | | load_arma_ascii(x, name, f); | |
| } | | } | |
| else | | else | |
| if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length())) | | if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length())) | |
| | | | |
| skipping to change at line 1632 | | skipping to change at line 1633 | |
| static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; | | static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; | |
| static const std::string P6 = "P6"; | | static const std::string P6 = "P6"; | |
| | | | |
| podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); | | podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
| | | | |
| f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); | | f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); | |
| raw_header[ARMA_CUB_TXT.length()] = '\0'; | | raw_header[ARMA_CUB_TXT.length()] = '\0'; | |
| | | | |
|
| | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) | | if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) | |
| { | | { | |
| load_arma_ascii(x, name, f); | | load_arma_ascii(x, name, f); | |
| } | | } | |
| else | | else | |
| if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) | | if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) | |
| | | | |
| skipping to change at line 1970 | | skipping to change at line 1972 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | arma_type_check<is_Mat<T1>::value == false>::apply(); | |
| | | | |
| static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | | static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | |
| static const std::string P6 = "P6"; | | static const std::string P6 = "P6"; | |
| | | | |
| podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | | podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
|
| | | | |
| f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); | | f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); | |
|
| | | | |
| | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| raw_header[ARMA_FLD_BIN.length()] = '\0'; | | raw_header[ARMA_FLD_BIN.length()] = '\0'; | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length())) | | if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length())) | |
| { | | { | |
| load_arma_binary(x, name, f); | | load_arma_binary(x, name, f); | |
| } | | } | |
| | | | |
End of changes. 4 change blocks. |
| 0 lines changed or deleted | | 5 lines changed or added | |
|
| eop_aux.hpp | | eop_aux.hpp | |
| | | | |
| skipping to change at line 42 | | skipping to change at line 42 | |
| arma_inline | | arma_inline | |
| operator std::complex<T> () | | operator std::complex<T> () | |
| { | | { | |
| return std::complex<T>( T(eop_aux_rand<T>()), T(eop_aux_rand<T>()) ); | | return std::complex<T>( T(eop_aux_rand<T>()), T(eop_aux_rand<T>()) ); | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| struct eop_aux_randn | | struct eop_aux_randn | |
| { | | { | |
|
| // TODO: implement a more efficient method for randn() | | // // rudimentary method, based on the central limit theorem | |
| | | // // http://en.wikipedia.org/wiki/Central_limit_theorem | |
| | | // inline | |
| | | // operator eT () const | |
| | | // { | |
| | | // const u32 N = 12; // N must be >= 12 and an even number | |
| | | // const u32 N2 = N/2; | |
| // | | // | |
|
| // possible option: | | // eT acc = eT(0); | |
| // Marsaglia and Tsang Ziggurat technique to transform from a uniform to | | // | |
| a normal distribution. | | // for(u32 i=0; i<N2; ++i) | |
| // G. Marsaglia, W.W. Tsang. | | // { | |
| // "Ziggurat method for generating random variables", | | // const eT tmp1 = eT(std::rand()) / eT(RAND_MAX); | |
| // J. Statistical Software, vol 5, 2000. | | // const eT tmp2 = eT(std::rand()) / eT(RAND_MAX); | |
| // http://www.jstatsoft.org/v05/i08/ | | // acc += tmp1+tmp2; | |
| | | // } | |
| | | // | |
| | | // return acc - eT(N2); | |
| | | // } | |
| | | | |
|
| | | // polar form of the Box-Muller transformation | |
| | | // http://en.wikipedia.org/wiki/Box-Muller_transformation | |
| | | // http://en.wikipedia.org/wiki/Marsaglia_polar_method | |
| inline | | inline | |
| operator eT () const | | operator eT () const | |
| { | | { | |
|
| const u32 N = 12; // N must be >= 12 and an even number | | // make sure we are internally using at least floats | |
| const u32 N2 = N/2; | | typedef typename promote_type<eT,float>::result eTp; | |
| | | | |
|
| eT acc = eT(0); | | eTp tmp1; | |
| | | eTp tmp2; | |
| | | eTp w; | |
| | | | |
|
| for(u32 i=0; i<N2; ++i) | | do | |
| { | | { | |
|
| const eT tmp1 = eT(std::rand()) / eT(RAND_MAX); | | tmp1 = eTp(2) * eTp(std::rand()) / eTp(RAND_MAX) - eTp(1); | |
| const eT tmp2 = eT(std::rand()) / eT(RAND_MAX); | | tmp2 = eTp(2) * eTp(std::rand()) / eTp(RAND_MAX) - eTp(1); | |
| acc += tmp1+tmp2; | | w = tmp1*tmp1 + tmp2*tmp2; | |
| } | | } | |
|
| | | while ( w >= eTp(1) ); | |
| | | | |
|
| return acc - eT(N2); | | return eT( tmp1 * std::sqrt( (eTp(-2) * std::log(w)) / w) ); | |
| } | | } | |
| | | | |
|
| | | // other methods: | |
| | | // http://en.wikipedia.org/wiki/Ziggurat_algorithm | |
| | | // | |
| | | // Marsaglia and Tsang Ziggurat technique to transform from a uniform to | |
| | | a normal distribution. | |
| | | // G. Marsaglia, W.W. Tsang. | |
| | | // "Ziggurat method for generating random variables", | |
| | | // J. Statistical Software, vol 5, 2000. | |
| | | // http://www.jstatsoft.org/v05/i08/ | |
| }; | | }; | |
| | | | |
| template<typename T> | | template<typename T> | |
| struct eop_aux_randn< std::complex<T> > | | struct eop_aux_randn< std::complex<T> > | |
| { | | { | |
| arma_inline | | arma_inline | |
| operator std::complex<T> () const | | operator std::complex<T> () const | |
| { | | { | |
| return std::complex<T>( T(eop_aux_randn<T>()), T(eop_aux_randn<T>()) ); | | return std::complex<T>( T(eop_aux_randn<T>()), T(eop_aux_randn<T>()) ); | |
| } | | } | |
| | | | |
End of changes. 10 change blocks. |
| 16 lines changed or deleted | | 41 lines changed or added | |
|
| field_meat.hpp | | field_meat.hpp | |
| | | | |
| skipping to change at line 638 | | skipping to change at line 638 | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); | | arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| mem[i] = new oT; | | mem[i] = new oT; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| | | template<typename oT> | |
| | | inline | |
| | | field<oT>::iterator::iterator(field<oT>& in_M, const bool at_end) | |
| | | : M(in_M) | |
| | | , i( (at_end == false) ? 0 : in_M.n_elem ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | oT& | |
| | | field<oT>::iterator::operator*() | |
| | | { | |
| | | return M[i]; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::iterator& | |
| | | field<oT>::iterator::operator++() | |
| | | { | |
| | | ++i; | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::iterator::operator++(int) | |
| | | { | |
| | | operator++(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::iterator& | |
| | | field<oT>::iterator::operator--() | |
| | | { | |
| | | if(i > 0) | |
| | | { | |
| | | --i; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::iterator::operator--(int) | |
| | | { | |
| | | operator--(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | bool | |
| | | field<oT>::iterator::operator!=(const typename field<oT>::iterator& X) cons | |
| | | t | |
| | | { | |
| | | return (i != X.i); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | bool | |
| | | field<oT>::iterator::operator==(const typename field<oT>::iterator& X) cons | |
| | | t | |
| | | { | |
| | | return (i == X.i); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | field<oT>::const_iterator::const_iterator(const field<oT>& in_M, const bool | |
| | | at_end) | |
| | | : M(in_M) | |
| | | , i( (at_end == false) ? 0 : in_M.n_elem ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | field<oT>::const_iterator::const_iterator(const field<oT>::iterator& X) | |
| | | : M(X.M) | |
| | | , i(X.i) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | const oT& | |
| | | field<oT>::const_iterator::operator*() const | |
| | | { | |
| | | return M[i]; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::const_iterator& | |
| | | field<oT>::const_iterator::operator++() | |
| | | { | |
| | | ++i; | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::const_iterator::operator++(int) | |
| | | { | |
| | | operator++(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::const_iterator& | |
| | | field<oT>::const_iterator::operator--() | |
| | | { | |
| | | if(i > 0) | |
| | | { | |
| | | --i; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | void | |
| | | field<oT>::const_iterator::operator--(int) | |
| | | { | |
| | | operator--(); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | bool | |
| | | field<oT>::const_iterator::operator!=(const typename field<oT>::const_itera | |
| | | tor& X) const | |
| | | { | |
| | | return (i != X.i); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | bool | |
| | | field<oT>::const_iterator::operator==(const typename field<oT>::const_itera | |
| | | tor& X) const | |
| | | { | |
| | | return (i == X.i); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::iterator | |
| | | field<oT>::begin() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return field<oT>::iterator(*this); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::const_iterator | |
| | | field<oT>::begin() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return field<oT>::const_iterator(*this); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::iterator | |
| | | field<oT>::end() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return field<oT>::iterator(*this, true); | |
| | | } | |
| | | | |
| | | template<typename oT> | |
| | | inline | |
| | | typename field<oT>::const_iterator | |
| | | field<oT>::end() const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return field<oT>::const_iterator(*this, true); | |
| | | } | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename oT> | | template<typename oT> | |
| inline | | inline | |
| void | | void | |
| field_aux::reset_objects(field<oT>& x) | | field_aux::reset_objects(field<oT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 198 lines changed or added | |
|
| field_proto.hpp | | field_proto.hpp | |
| | | | |
| skipping to change at line 102 | | skipping to change at line 102 | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| inline void reset_objects(); | | inline void reset_objects(); | |
| | | | |
| inline void save(const std::string name, const file_type type = arma_bi
nary) const; | | inline void save(const std::string name, const file_type type = arma_bi
nary) const; | |
| inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | | inline void save( std::ostream& os, const file_type type = arma_bi
nary) const; | |
| | | | |
| inline void load(const std::string name, const file_type type = auto_de
tect); | | inline void load(const std::string name, const file_type type = auto_de
tect); | |
| inline void load( std::istream& is, const file_type type = auto_de
tect); | | inline void load( std::istream& is, const file_type type = auto_de
tect); | |
| | | | |
|
| | | // iterators | |
| | | | |
| | | class iterator | |
| | | { | |
| | | public: | |
| | | | |
| | | inline iterator(field<oT>& in_M, const bool at_end = false); | |
| | | | |
| | | inline oT& operator* (); | |
| | | | |
| | | inline iterator& operator++(); | |
| | | inline void operator++(int); | |
| | | | |
| | | inline iterator& operator--(); | |
| | | inline void operator--(int); | |
| | | | |
| | | inline bool operator!=(const iterator& X) const; | |
| | | inline bool operator==(const iterator& X) const; | |
| | | | |
| | | arma_aligned field<oT>& M; | |
| | | arma_aligned u32 i; | |
| | | }; | |
| | | | |
| | | class const_iterator | |
| | | { | |
| | | public: | |
| | | | |
| | | const_iterator(const field<oT>& in_M, const bool at_end = false); | |
| | | const_iterator(const iterator& X); | |
| | | | |
| | | inline const oT& operator*() const; | |
| | | | |
| | | inline const_iterator& operator++(); | |
| | | inline void operator++(int); | |
| | | | |
| | | inline const_iterator& operator--(); | |
| | | inline void operator--(int); | |
| | | | |
| | | inline bool operator!=(const const_iterator& X) const; | |
| | | inline bool operator==(const const_iterator& X) const; | |
| | | | |
| | | arma_aligned const field<oT>& M; | |
| | | arma_aligned u32 i; | |
| | | }; | |
| | | | |
| | | inline iterator begin(); | |
| | | inline const_iterator begin() const; | |
| | | | |
| | | inline iterator end(); | |
| | | inline const_iterator end() const; | |
| | | | |
| private: | | private: | |
| | | | |
| inline void init(const field<oT>& x); | | inline void init(const field<oT>& x); | |
| inline void init(const u32 n_rows_in, const u32 n_cols_in); | | inline void init(const u32 n_rows_in, const u32 n_cols_in); | |
| | | | |
| inline void delete_objects(); | | inline void delete_objects(); | |
| inline void create_objects(); | | inline void create_objects(); | |
| | | | |
| friend class field_aux; | | friend class field_aux; | |
| friend class subview_field<oT>; | | friend class subview_field<oT>; | |
| | | | |
End of changes. 1 change blocks. |
| 0 lines changed or deleted | | 51 lines changed or added | |
|
| fn_norm.hpp | | fn_norm.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 fn_norm | | //! \addtogroup fn_norm | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
|
| typename T1::elem_type | | typename T1::pod_type | |
| norm_unwrap(const Base<typename T1::elem_type,T1>& X, const u32 k) | | norm_unwrap(const Base<typename T1::elem_type,T1>& X, const u32 k) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
|
| | | typedef typename T1::pod_type T; | |
| | | | |
| const unwrap<T1> tmp(X.get_ref()); | | const unwrap<T1> tmp(X.get_ref()); | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| arma_debug_check( (A.n_elem == 0), "norm(): given
object has no elements" ); | | arma_debug_check( (A.n_elem == 0), "norm(): given
object has no elements" ); | |
| arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
object must be a vector" ); | | arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
object must be a vector" ); | |
| arma_debug_check( (k == 0), "norm(): k mus
t be greater than zero" ); | | arma_debug_check( (k == 0), "norm(): k mus
t be greater than zero" ); | |
| | | | |
| const eT* A_mem = A.memptr(); | | const eT* A_mem = A.memptr(); | |
| const u32 N = A.n_elem; | | const u32 N = A.n_elem; | |
| | | | |
| if(k==1) | | if(k==1) | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| acc += std::abs(A_mem[i]); | | acc += std::abs(A_mem[i]); | |
| } | | } | |
| | | | |
| return acc; | | return acc; | |
| } | | } | |
| else | | else | |
| if(k==2) | | if(k==2) | |
| | | | |
| skipping to change at line 63 | | skipping to change at line 64 | |
| if(is_complex<eT>::value == false) | | if(is_complex<eT>::value == false) | |
| { | | { | |
| eT acc = eT(0); | | eT acc = eT(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| const eT tmp = A_mem[i]; | | const eT tmp = A_mem[i]; | |
| acc += tmp*tmp; | | acc += tmp*tmp; | |
| } | | } | |
| | | | |
|
| return std::sqrt(acc); | | return std::sqrt(access::tmp_real(acc)); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
|
| acc += std::abs(A_mem[i]); | | const T tmp = std::abs(A_mem[i]); | |
| | | acc += tmp*tmp; | |
| } | | } | |
| | | | |
| return std::sqrt(acc); | | return std::sqrt(acc); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| acc += std::pow(std::abs(A_mem[i]), int(k)); | | acc += std::pow(std::abs(A_mem[i]), int(k)); | |
| } | | } | |
| | | | |
|
| return std::pow(acc, eT(1)/eT(k)); | | return std::pow(acc, T(1)/T(k)); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | arma_hot | |
| | | inline | |
| | | typename T1::pod_type | |
| | | norm_unwrap(const Base<typename T1::elem_type,T1>& X, const char* method) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | typedef typename T1::pod_type T; | |
| | | | |
| | | const unwrap<T1> tmp(X.get_ref()); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | arma_debug_check( (A.n_elem == 0), "norm(): given | |
| | | object has no elements" ); | |
| | | arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given | |
| | | object must be a vector" ); | |
| | | | |
| | | const eT* A_mem = A.memptr(); | |
| | | const u32 N = A.n_elem; | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm | |
| | | { | |
| | | T max_val = std::abs(A_mem[0]); | |
| | | | |
| | | for(u32 i=1; i<N; ++i) | |
| | | { | |
| | | const T tmp_val = std::abs(A_mem[i]); | |
| | | | |
| | | if(tmp_val > max_val) | |
| | | { | |
| | | max_val = tmp_val; | |
| | | } | |
| | | } | |
| | | | |
| | | return max_val; | |
| | | } | |
| | | else | |
| | | if(sig == '-') // min norm | |
| | | { | |
| | | T min_val = std::abs(A_mem[0]); | |
| | | | |
| | | for(u32 i=1; i<N; ++i) | |
| | | { | |
| | | const T tmp_val = std::abs(A_mem[i]); | |
| | | | |
| | | if(tmp_val < min_val) | |
| | | { | |
| | | min_val = tmp_val; | |
| | | } | |
| | | } | |
| | | | |
| | | return min_val; | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_stop("norm(): unknown norm type"); | |
| | | | |
| | | return T(0); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
|
| typename T1::elem_type | | typename T1::pod_type | |
| norm_proxy(const Base<typename T1::elem_type,T1>& X, const u32 k) | | norm_proxy(const Base<typename T1::elem_type,T1>& X, const u32 k) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
|
| | | typedef typename T1::pod_type T; | |
| | | | |
| const Proxy<T1> A(X.get_ref()); | | const Proxy<T1> A(X.get_ref()); | |
| | | | |
| arma_debug_check( (A.n_elem == 0), "norm(): given
object has no elements" ); | | arma_debug_check( (A.n_elem == 0), "norm(): given
object has no elements" ); | |
| arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
object must be a vector" ); | | arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
object must be a vector" ); | |
| arma_debug_check( (k == 0), "norm(): k mus
t be greater than zero" ); | | arma_debug_check( (k == 0), "norm(): k mus
t be greater than zero" ); | |
| | | | |
| const u32 N = A.n_elem; | | const u32 N = A.n_elem; | |
| | | | |
| if(k==1) | | if(k==1) | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| acc += std::abs(A[i]); | | acc += std::abs(A[i]); | |
| } | | } | |
| | | | |
| return acc; | | return acc; | |
| } | | } | |
| else | | else | |
| if(k==2) | | if(k==2) | |
| | | | |
| skipping to change at line 133 | | skipping to change at line 200 | |
| if(is_complex<eT>::value == false) | | if(is_complex<eT>::value == false) | |
| { | | { | |
| eT acc = eT(0); | | eT acc = eT(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| const eT tmp = A[i]; | | const eT tmp = A[i]; | |
| acc += tmp*tmp; | | acc += tmp*tmp; | |
| } | | } | |
| | | | |
|
| return std::sqrt(acc); | | return std::sqrt(access::tmp_real(acc)); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
|
| acc += std::abs(A[i]); | | const T tmp = std::abs(A[i]); | |
| | | acc += tmp*tmp; | |
| } | | } | |
| | | | |
| return std::sqrt(acc); | | return std::sqrt(acc); | |
|
| | | | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT acc = eT(0); | | T acc = T(0); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| acc += std::pow(std::abs(A[i]), int(k)); | | acc += std::pow(std::abs(A[i]), int(k)); | |
| } | | } | |
| | | | |
|
| return std::pow(acc, eT(1)/eT(k)); | | return std::pow(acc, T(1)/T(k)); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| | | arma_hot | |
| | | inline | |
| | | typename T1::pod_type | |
| | | norm_proxy(const Base<typename T1::elem_type,T1>& X, const char* method) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | typedef typename T1::pod_type T; | |
| | | | |
| | | const Proxy<T1> A(X.get_ref()); | |
| | | | |
| | | arma_debug_check( (A.n_elem == 0), "norm(): given | |
| | | object has no elements" ); | |
| | | arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given | |
| | | object must be a vector" ); | |
| | | | |
| | | const u32 N = A.n_elem; | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm | |
| | | { | |
| | | T max_val = std::abs(A[0]); | |
| | | | |
| | | for(u32 i=1; i<N; ++i) | |
| | | { | |
| | | const T tmp_val = std::abs(A[i]); | |
| | | | |
| | | if(tmp_val > max_val) | |
| | | { | |
| | | max_val = tmp_val; | |
| | | } | |
| | | } | |
| | | | |
| | | return max_val; | |
| | | } | |
| | | else | |
| | | if(sig == '-') // min norm | |
| | | { | |
| | | T min_val = std::abs(A[0]); | |
| | | | |
| | | for(u32 i=1; i<N; ++i) | |
| | | { | |
| | | const T tmp_val = std::abs(A[i]); | |
| | | | |
| | | if(tmp_val < min_val) | |
| | | { | |
| | | min_val = tmp_val; | |
| | | } | |
| | | } | |
| | | | |
| | | return min_val; | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_stop("norm(): unknown norm type"); | |
| | | | |
| | | return T(0); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
|
| typename T1::elem_type | | typename T1::pod_type | |
| norm(const Base<typename T1::elem_type,T1>& X, const u32 k) | | norm(const Base<typename T1::elem_type,T1>& X, const u32 k) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(is_Mat<T1>::value == true) | | if(is_Mat<T1>::value == true) | |
| { | | { | |
| return norm_unwrap(X, k); | | return norm_unwrap(X, k); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return norm_proxy(X, k); | | return norm_proxy(X, k); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | arma_inline | |
| | | arma_warn_unused | |
| | | typename T1::pod_type | |
| | | norm(const Base<typename T1::elem_type,T1>& X, const char* method) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(is_Mat<T1>::value == true) | |
| | | { | |
| | | return norm_unwrap(X, method); | |
| | | } | |
| | | else | |
| | | { | |
| | | return norm_proxy(X, method); | |
| | | } | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 19 change blocks. |
| 16 lines changed or deleted | | 167 lines changed or added | |
|