| SpMat_bones.hpp | | SpMat_bones.hpp | |
| | | | |
| skipping to change at line 141 | | skipping to change at line 141 | |
| | | | |
| // delayed binary ops | | // delayed binary ops | |
| template<typename T1, typename T2, typename spglue_type> inline
SpMat(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline
SpMat(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator=(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator+=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator+=(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator-=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator-=(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator*=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator*=(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator%=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator%=(const SpGlue<T1, T2, spglue_type>& X); | |
| template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator/=(const SpGlue<T1, T2, spglue_type>& X); | | template<typename T1, typename T2, typename spglue_type> inline const SpM
at& operator/=(const SpGlue<T1, T2, spglue_type>& X); | |
| | | | |
|
| | | // delayed mixted-type unary ops | |
| | | template<typename T1, typename spop_type> inline SpMat( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator+=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator-=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator*=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator%=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | template<typename T1, typename spop_type> inline const SpMat& operator/=( | |
| | | const mtSpOp<eT, T1, spop_type>& X); | |
| | | | |
| /** | | /** | |
| * Submatrix methods. | | * Submatrix methods. | |
| */ | | */ | |
| arma_inline SpSubview<eT> row(const uword row_num); | | arma_inline SpSubview<eT> row(const uword row_num); | |
| arma_inline const SpSubview<eT> row(const uword row_num) const; | | arma_inline const SpSubview<eT> row(const uword row_num) const; | |
| | | | |
| inline SpSubview<eT> operator()(const uword row_num, const spa
n& col_span); | | inline SpSubview<eT> operator()(const uword row_num, const spa
n& col_span); | |
| inline const SpSubview<eT> operator()(const uword row_num, const spa
n& col_span) const; | | inline const SpSubview<eT> operator()(const uword row_num, const spa
n& col_span) const; | |
| | | | |
| arma_inline SpSubview<eT> col(const uword col_num); | | arma_inline SpSubview<eT> col(const uword col_num); | |
| | | | |
| skipping to change at line 287 | | skipping to change at line 296 | |
| * Get the minimum or maximum of the matrix. | | * Get the minimum or maximum of the matrix. | |
| */ | | */ | |
| inline arma_warn_unused eT min() const; | | inline arma_warn_unused eT min() const; | |
| inline eT min(uword& index_of_min_val) const; | | inline eT min(uword& index_of_min_val) const; | |
| inline eT min(uword& row_of_min_val, uword& col_of_min_v
al) const; | | inline eT min(uword& row_of_min_val, uword& col_of_min_v
al) const; | |
| | | | |
| inline arma_warn_unused eT max() const; | | inline arma_warn_unused eT max() const; | |
| inline eT max(uword& index_of_max_val) const; | | inline eT max(uword& index_of_max_val) const; | |
| inline eT max(uword& row_of_min_val, uword& col_of_min_v
al) const; | | inline eT max(uword& row_of_min_val, uword& col_of_min_v
al) const; | |
| | | | |
|
| | | // saving and loading | |
| | | | |
| | | 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 load(const std::string name, const file_type type = arma_bi | |
| | | nary, const bool print_status = true); | |
| | | inline bool load( std::istream& is, const file_type type = arma_bi | |
| | | nary, 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( std::ostream& os, const file_type type = a | |
| | | rma_binary) const; | |
| | | | |
| | | inline bool quiet_load(const std::string name, const file_type type = a | |
| | | rma_binary); | |
| | | inline bool quiet_load( std::istream& is, const file_type type = a | |
| | | rma_binary); | |
| | | | |
| | | // TODO: speed up loading of sparse matrices stored as text files (ie. ra | |
| | | w_ascii and coord_ascii) | |
| | | // TODO: implement auto_detect for sparse matrices | |
| | | // TODO: modify docs to specify which formats are not applicable to spars | |
| | | e matrices | |
| | | | |
| // These forward declarations are necessary. | | // These forward declarations are necessary. | |
| class iterator_base; | | class iterator_base; | |
| class iterator; | | class iterator; | |
| class const_iterator; | | class const_iterator; | |
| class row_iterator; | | class row_iterator; | |
| class const_row_iterator; | | class const_row_iterator; | |
| | | | |
|
| // Iterator base provides comparison operators but not the actual logic o | | // Iterator base provides basic operators but not how to compare or how t | |
| n how | | o | |
| // to iterate. The validity of the position is not checked (that is left | | // iterate. | |
| up | | | |
| // to the user). | | | |
| class iterator_base | | class iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline iterator_base(const SpMat& in_M); | | inline iterator_base(const SpMat& in_M); | |
| inline iterator_base(const SpMat& in_M, const uword col, const uword po
s); | | inline iterator_base(const SpMat& in_M, const uword col, const uword po
s); | |
| | | | |
| inline arma_hot eT operator*() const; | | inline arma_hot eT operator*() const; | |
| | | | |
|
| inline arma_hot bool operator==(const iterator_base& rhs) const; | | | |
| inline arma_hot bool operator!=(const iterator_base& rhs) const; | | | |
| | | | |
| inline arma_hot bool operator==(const typename SpSubview<eT>::iterator_ | | | |
| base& rhs) const; | | | |
| inline arma_hot bool operator!=(const typename SpSubview<eT>::iterator_ | | | |
| base& rhs) const; | | | |
| | | | |
| // Don't hold location internally; call "dummy" methods to get that inf
ormation. | | // Don't hold location internally; call "dummy" methods to get that inf
ormation. | |
| arma_inline uword row() const { return M.row_indices[internal_pos]; } | | arma_inline uword row() const { return M.row_indices[internal_pos]; } | |
| arma_inline uword col() const { return internal_col; } | | arma_inline uword col() const { return internal_col; } | |
| arma_inline uword pos() const { return internal_pos; } | | arma_inline uword pos() const { return internal_pos; } | |
| | | | |
| arma_aligned const SpMat& M; | | arma_aligned const SpMat& M; | |
| arma_aligned uword internal_col; | | arma_aligned uword internal_col; | |
| arma_aligned uword internal_pos; | | arma_aligned uword internal_pos; | |
|
| | | | |
| | | // So that we satisfy the STL iterator types. | |
| | | typedef std::bidirectional_iterator_tag iterator_category; | |
| | | typedef eT value_type; | |
| | | typedef uword difference_type; // not certain | |
| | | on this one | |
| | | typedef const eT* pointer; | |
| | | typedef const eT& reference; | |
| }; | | }; | |
| | | | |
| class const_iterator : public iterator_base | | class const_iterator : public iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Ass
umes initial_pos is valid. | | inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Ass
umes initial_pos is valid. | |
| //! Once initialized, will be at the first nonzero value after the give
n position (using forward columnwise traversal). | | //! Once initialized, will be at the first nonzero value after the give
n position (using forward columnwise traversal). | |
| inline const_iterator(const SpMat& in_M, uword in_row, uword in_col); | | inline const_iterator(const SpMat& in_M, uword in_row, uword in_col); | |
| //! If you know the exact position of the iterator. in_row is a dummy
argument. | | //! If you know the exact position of the iterator. in_row is a dummy
argument. | |
| inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uw
ord in_pos); | | inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uw
ord in_pos); | |
| inline const_iterator(const const_iterator& other); | | inline const_iterator(const const_iterator& other); | |
| | | | |
| inline arma_hot const_iterator& operator++(); | | inline arma_hot const_iterator& operator++(); | |
|
| inline arma_hot void operator++(int); | | inline arma_hot const_iterator operator++(int); | |
| | | | |
| inline arma_hot const_iterator& operator--(); | | inline arma_hot const_iterator& operator--(); | |
|
| inline arma_hot void operator--(int); | | inline arma_hot const_iterator operator--(int); | |
| | | | |
| | | inline arma_hot bool operator==(const const_iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const const_iterator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const typename SpSubview<eT>::const_ite | |
| | | rator& rhs) const; | |
| | | inline arma_hot bool operator!=(const typename SpSubview<eT>::const_ite | |
| | | rator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const const_row_iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const const_row_iterator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const typename SpSubview<eT>::const_row | |
| | | _iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row | |
| | | _iterator& rhs) const; | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| * So that we can iterate over nonzero values, we need an iterator | | * So that we can iterate over nonzero values, we need an iterator | |
| * implementation. This can't be as simple as Mat's, which is just a poi
nter | | * implementation. This can't be as simple as Mat's, which is just a poi
nter | |
| * to an eT. If a value is set to 0 using this iterator, the iterator is
no | | * to an eT. If a value is set to 0 using this iterator, the iterator is
no | |
| * longer valid! | | * longer valid! | |
| */ | | */ | |
| class iterator : public const_iterator | | class iterator : public const_iterator | |
| { | | { | |
| | | | |
| skipping to change at line 359 | | skipping to change at line 398 | |
| | | | |
| inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in
_M, initial_pos) { } | | inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in
_M, initial_pos) { } | |
| inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterat
or(in_M, in_row, in_col) { } | | inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterat
or(in_M, in_row, in_col) { } | |
| inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos)
: const_iterator(in_M, in_row, in_col, in_pos) { } | | inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos)
: const_iterator(in_M, in_row, in_col, in_pos) { } | |
| inline iterator(const const_iterator& other) : const_iterator(other) {
} | | inline iterator(const const_iterator& other) : const_iterator(other) {
} | |
| | | | |
| inline arma_hot SpValProxy<SpMat<eT> > operator*(); | | inline arma_hot SpValProxy<SpMat<eT> > operator*(); | |
| | | | |
| // overloads needed for return type correctness | | // overloads needed for return type correctness | |
| inline arma_hot iterator& operator++(); | | inline arma_hot iterator& operator++(); | |
|
| inline arma_hot void operator++(int); | | inline arma_hot iterator operator++(int); | |
| | | | |
| inline arma_hot iterator& operator--(); | | inline arma_hot iterator& operator--(); | |
|
| inline arma_hot void operator--(int); | | inline arma_hot iterator operator--(int); | |
| | | | |
| | | // This has a different value_type than iterator_base. | |
| | | typedef SpValProxy<SpMat<eT> > value_type; | |
| | | typedef const SpValProxy<SpMat<eT> >* pointer; | |
| | | typedef const SpValProxy<SpMat<eT> >& reference; | |
| }; | | }; | |
| | | | |
| class const_row_iterator : public iterator_base | | class const_row_iterator : public iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0); | | inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0); | |
| //! Once initialized, will be at the first nonzero value after the give
n position (using forward row-wise traversal). | | //! Once initialized, will be at the first nonzero value after the give
n position (using forward row-wise traversal). | |
| inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col
); | | inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col
); | |
| inline const_row_iterator(const const_row_iterator& other); | | inline const_row_iterator(const const_row_iterator& other); | |
| | | | |
| inline arma_hot const_row_iterator& operator++(); | | inline arma_hot const_row_iterator& operator++(); | |
|
| inline arma_hot void operator++(int); | | inline arma_hot const_row_iterator operator++(int); | |
| | | | |
| inline arma_hot const_row_iterator& operator--(); | | inline arma_hot const_row_iterator& operator--(); | |
|
| inline arma_hot void operator--(int); | | inline arma_hot const_row_iterator operator--(int); | |
| | | | |
| uword internal_row; // Hold row internally because we use internal_pos
differently. | | uword internal_row; // Hold row internally because we use internal_pos
differently. | |
| uword actual_pos; // Actual position in matrix. | | uword actual_pos; // Actual position in matrix. | |
| | | | |
| arma_inline eT operator*() const { return iterator_base::M.values[actua
l_pos]; } | | arma_inline eT operator*() const { return iterator_base::M.values[actua
l_pos]; } | |
| | | | |
| arma_inline uword row() const { return internal_row; } | | arma_inline uword row() const { return internal_row; } | |
|
| | | | |
| | | inline arma_hot bool operator==(const const_iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const const_iterator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const typename SpSubview<eT>::const_ite | |
| | | rator& rhs) const; | |
| | | inline arma_hot bool operator!=(const typename SpSubview<eT>::const_ite | |
| | | rator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const const_row_iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const const_row_iterator& rhs) const; | |
| | | | |
| | | inline arma_hot bool operator==(const typename SpSubview<eT>::const_row | |
| | | _iterator& rhs) const; | |
| | | inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row | |
| | | _iterator& rhs) const; | |
| }; | | }; | |
| | | | |
| class row_iterator : public const_row_iterator | | class row_iterator : public const_row_iterator | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_ite
rator(in_M, initial_pos) { } | | inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_ite
rator(in_M, initial_pos) { } | |
| //! Once initialized, will be at the first nonzero value after the give
n position (using forward row-wise traversal). | | //! Once initialized, will be at the first nonzero value after the give
n position (using forward row-wise traversal). | |
| inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_ro
w_iterator(in_M, in_row, in_col) { } | | inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_ro
w_iterator(in_M, in_row, in_col) { } | |
| inline row_iterator(const row_iterator& other) : const_row_iterator(oth
er) { } | | inline row_iterator(const row_iterator& other) : const_row_iterator(oth
er) { } | |
| | | | |
| inline arma_hot SpValProxy<SpMat<eT> > operator*(); | | inline arma_hot SpValProxy<SpMat<eT> > operator*(); | |
| | | | |
| // overloads required for return type correctness | | // overloads required for return type correctness | |
| inline arma_hot row_iterator& operator++(); | | inline arma_hot row_iterator& operator++(); | |
|
| inline arma_hot void operator++(int); | | inline arma_hot row_iterator operator++(int); | |
| | | | |
| inline arma_hot row_iterator& operator--(); | | inline arma_hot row_iterator& operator--(); | |
|
| inline arma_hot void operator--(int); | | inline arma_hot row_iterator operator--(int); | |
| | | | |
| | | // This has a different value_type than iterator_base. | |
| | | typedef SpValProxy<SpMat<eT> > value_type; | |
| | | typedef const SpValProxy<SpMat<eT> >* pointer; | |
| | | typedef const SpValProxy<SpMat<eT> >& reference; | |
| }; | | }; | |
| | | | |
| inline iterator begin(); | | inline iterator begin(); | |
| inline const_iterator begin() const; | | inline const_iterator begin() const; | |
| | | | |
| inline iterator end(); | | inline iterator end(); | |
| inline const_iterator end() const; | | inline const_iterator end() const; | |
| | | | |
| inline iterator begin_col(const uword col_num); | | inline iterator begin_col(const uword col_num); | |
| inline const_iterator begin_col(const uword col_num) const; | | inline const_iterator begin_col(const uword col_num) const; | |
| | | | |
| skipping to change at line 440 | | skipping to change at line 501 | |
| inline uword size() const; | | inline uword size() const; | |
| | | | |
| /** | | /** | |
| * Resize memory. You are responsible for updating the column pointers a
nd | | * Resize memory. You are responsible for updating the column pointers a
nd | |
| * filling the new memory (if the new size is larger). If the new size i
s | | * filling the new memory (if the new size is larger). If the new size i
s | |
| * smaller, the first new_n_nonzero elements will be copied. n_nonzero i
s | | * smaller, the first new_n_nonzero elements will be copied. n_nonzero i
s | |
| * updated. | | * updated. | |
| */ | | */ | |
| inline void mem_resize(const uword new_n_nonzero); | | inline void mem_resize(const uword new_n_nonzero); | |
| | | | |
|
| inline void steal_mem(SpMat& X); //!< don't use this unless you're writin | | //! don't use this unless you're writing internal Armadillo code | |
| g internal Armadillo code | | inline void steal_mem(SpMat& X); | |
| | | | |
| | | //! don't use this unless you're writing internal Armadillo code | |
| | | template< typename T1, typename Functor> arma_hot inline voi | |
| | | d init_xform (const SpBase<eT, T1>& x, const Functor& func); | |
| | | template<typename eT2, typename T1, typename Functor> arma_hot inline voi | |
| | | d init_xform_mt(const SpBase<eT2,T1>& x, const Functor& func); | |
| | | | |
| protected: | | protected: | |
| | | | |
| /** | | /** | |
| * Initialize the matrix to the specified size. Data is not preserved, s
o the matrix is assumed to be entirely sparse (empty). | | * Initialize the matrix to the specified size. Data is not preserved, s
o the matrix is assumed to be entirely sparse (empty). | |
| */ | | */ | |
| inline void init(uword in_rows, uword in_cols); | | inline void init(uword in_rows, uword in_cols); | |
| | | | |
| /** | | /** | |
| * Initialize the matrix from text. Data is (of course) not preserved, a
nd | | * Initialize the matrix from text. Data is (of course) not preserved, a
nd | |
| | | | |
End of changes. 15 change blocks. |
| 23 lines changed or deleted | | 113 lines changed or added | |
|
| SpMat_iterators_meat.hpp | | SpMat_iterators_meat.hpp | |
| | | | |
| skipping to change at line 50 | | skipping to change at line 50 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| eT | | eT | |
| SpMat<eT>::iterator_base::operator*() const | | SpMat<eT>::iterator_base::operator*() const | |
| { | | { | |
| return M.values[internal_pos]; | | return M.values[internal_pos]; | |
| } | | } | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| arma_hot | | | |
| bool | | | |
| SpMat<eT>::iterator_base::operator==(const iterator_base& rhs) const | | | |
| { | | | |
| return (rhs.row() == row()) && (rhs.col() == internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| arma_hot | | | |
| bool | | | |
| SpMat<eT>::iterator_base::operator!=(const iterator_base& rhs) const | | | |
| { | | | |
| return (rhs.row() != row()) || (rhs.col() != internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| arma_hot | | | |
| bool | | | |
| SpMat<eT>::iterator_base::operator==(const typename SpSubview<eT>::iterator | | | |
| _base& rhs) const | | | |
| { | | | |
| return (rhs.row() == row()) && (rhs.col() == internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| arma_hot | | | |
| bool | | | |
| SpMat<eT>::iterator_base::operator!=(const typename SpSubview<eT>::iterator | | | |
| _base& rhs) const | | | |
| { | | | |
| return (rhs.row() != row()) || (rhs.col() != internal_col); | | | |
| } | | | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpMat::const_iterator implementation
// | | // SpMat::const_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpMat<eT>::const_iterator::const_iterator(const SpMat<eT>& in_M, uword init
ial_pos) | | SpMat<eT>::const_iterator::const_iterator(const SpMat<eT>& in_M, uword init
ial_pos) | |
| : iterator_base(in_M, 0, initial_pos) | | : iterator_base(in_M, 0, initial_pos) | |
| { | | { | |
| // Corner case for empty matrices. | | // Corner case for empty matrices. | |
| | | | |
| skipping to change at line 172 | | skipping to change at line 136 | |
| { | | { | |
| ++iterator_base::internal_col; | | ++iterator_base::internal_col; | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::const_iterator | |
| SpMat<eT>::const_iterator::operator++(int) | | SpMat<eT>::const_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::const_iterator tmp(*this); | |
| | | | |
| ++(*this); | | ++(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| typename SpMat<eT>::const_iterator& | | typename SpMat<eT>::const_iterator& | |
| SpMat<eT>::const_iterator::operator--() | | SpMat<eT>::const_iterator::operator--() | |
| { | | { | |
| //iterator_base::M.print("M"); | | //iterator_base::M.print("M"); | |
| | | | |
| | | | |
| skipping to change at line 206 | | skipping to change at line 174 | |
| | | | |
| --iterator_base::internal_col; | | --iterator_base::internal_col; | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::const_iterator | |
| SpMat<eT>::const_iterator::operator--(int) | | SpMat<eT>::const_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::const_iterator tmp(*this); | |
| | | | |
| --(*this); | | --(*this); | |
|
| | | | |
| | | return tmp; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator==(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator!=(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator==(const typename SpSubview<eT>::const_i | |
| | | terator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator!=(const typename SpSubview<eT>::const_i | |
| | | terator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator==(const const_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator!=(const const_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator==(const typename SpSubview<eT>::const_r | |
| | | ow_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_iterator::operator!=(const typename SpSubview<eT>::const_r | |
| | | ow_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpMat::iterator implementation
// | | // SpMat::iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| SpValProxy<SpMat<eT> > | | SpValProxy<SpMat<eT> > | |
| | | | |
| skipping to change at line 242 | | skipping to change at line 286 | |
| typename SpMat<eT>::iterator& | | typename SpMat<eT>::iterator& | |
| SpMat<eT>::iterator::operator++() | | SpMat<eT>::iterator::operator++() | |
| { | | { | |
| const_iterator::operator++(); | | const_iterator::operator++(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::iterator | |
| SpMat<eT>::iterator::operator++(int) | | SpMat<eT>::iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::iterator tmp(*this); | |
| | | | |
| const_iterator::operator++(); | | const_iterator::operator++(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| typename SpMat<eT>::iterator& | | typename SpMat<eT>::iterator& | |
| SpMat<eT>::iterator::operator--() | | SpMat<eT>::iterator::operator--() | |
| { | | { | |
| const_iterator::operator--(); | | const_iterator::operator--(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::iterator | |
| SpMat<eT>::iterator::operator--(int) | | SpMat<eT>::iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::iterator tmp(*this); | |
| | | | |
| const_iterator::operator--(); | | const_iterator::operator--(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpMat::const_row_iterator implementation
// | | // SpMat::const_row_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| /** | | /** | |
| * Initialize the const_row_iterator. | | * Initialize the const_row_iterator. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpMat<eT>::const_row_iterator::const_row_iterator(const SpMat<eT>& in_M, uw
ord initial_pos) | | SpMat<eT>::const_row_iterator::const_row_iterator(const SpMat<eT>& in_M, uw
ord initial_pos) | |
| : iterator_base(in_M, 0, initial_pos) | | : iterator_base(in_M, 0, initial_pos) | |
| , internal_row(0) | | , internal_row(0) | |
| , actual_pos(0) | | , actual_pos(0) | |
| { | | { | |
| // Corner case for empty matrix. | | // Corner case for empty matrix. | |
| if(in_M.n_nonzero == 0) | | if(in_M.n_nonzero == 0) | |
| { | | { | |
|
| iterator_base::internal_col = in_M.n_cols; | | iterator_base::internal_col = 0; | |
| | | internal_row = in_M.n_rows; | |
| return; | | return; | |
| } | | } | |
| | | | |
| // We don't count zeroes in our position count, so we have to find the no
nzero | | // We don't count zeroes in our position count, so we have to find the no
nzero | |
| // value corresponding to the given initial position. We assume initial_
pos | | // value corresponding to the given initial position. We assume initial_
pos | |
| // is valid. | | // is valid. | |
| | | | |
| // This is irritating because we don't know where the elements are in eac
h | | // This is irritating because we don't know where the elements are in eac
h | |
| // row. What we will do is loop across all columns looking for elements
in | | // row. What we will do is loop across all columns looking for elements
in | |
| // row 0 (and add to our sum), then in row 1, and so forth, until we get
to | | // row 0 (and add to our sum), then in row 1, and so forth, until we get
to | |
| | | | |
| skipping to change at line 430 | | skipping to change at line 483 | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Increment the row_iterator (but do not return anything. | | * Increment the row_iterator (but do not return anything. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::const_row_iterator | |
| SpMat<eT>::const_row_iterator::operator++(int) | | SpMat<eT>::const_row_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::const_row_iterator tmp(*this); | |
| | | | |
| ++(*this); | | ++(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Decrement the row_iterator. | | * Decrement the row_iterator. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| typename SpMat<eT>::const_row_iterator& | | typename SpMat<eT>::const_row_iterator& | |
| SpMat<eT>::const_row_iterator::operator--() | | SpMat<eT>::const_row_iterator::operator--() | |
| | | | |
| skipping to change at line 482 | | skipping to change at line 539 | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Decrement the row_iterator. | | * Decrement the row_iterator. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::const_row_iterator | |
| SpMat<eT>::const_row_iterator::operator--(int) | | SpMat<eT>::const_row_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::const_row_iterator tmp(*this); | |
| | | | |
| --(*this); | | --(*this); | |
|
| | | | |
| | | return tmp; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator==(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator!=(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator==(const typename SpSubview<eT>::con | |
| | | st_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator!=(const typename SpSubview<eT>::con | |
| | | st_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator==(const const_row_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator!=(const const_row_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator==(const typename SpSubview<eT>::con | |
| | | st_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | arma_hot | |
| | | bool | |
| | | SpMat<eT>::const_row_iterator::operator!=(const typename SpSubview<eT>::con | |
| | | st_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpMat::row_iterator implementation
// | | // SpMat::row_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| SpValProxy<SpMat<eT> > | | SpValProxy<SpMat<eT> > | |
| | | | |
| skipping to change at line 518 | | skipping to change at line 651 | |
| typename SpMat<eT>::row_iterator& | | typename SpMat<eT>::row_iterator& | |
| SpMat<eT>::row_iterator::operator++() | | SpMat<eT>::row_iterator::operator++() | |
| { | | { | |
| const_row_iterator::operator++(); | | const_row_iterator::operator++(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::row_iterator | |
| SpMat<eT>::row_iterator::operator++(int) | | SpMat<eT>::row_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::row_iterator tmp(*this); | |
| | | | |
| const_row_iterator::operator++(); | | const_row_iterator::operator++(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
| typename SpMat<eT>::row_iterator& | | typename SpMat<eT>::row_iterator& | |
| SpMat<eT>::row_iterator::operator--() | | SpMat<eT>::row_iterator::operator--() | |
| { | | { | |
| const_row_iterator::operator--(); | | const_row_iterator::operator--(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_hot | | arma_hot | |
|
| void | | typename SpMat<eT>::row_iterator | |
| SpMat<eT>::row_iterator::operator--(int) | | SpMat<eT>::row_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpMat<eT>::row_iterator tmp(*this); | |
| | | | |
| const_row_iterator::operator--(); | | const_row_iterator::operator--(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 26 change blocks. |
| 47 lines changed or deleted | | 212 lines changed or added | |
|
| SpMat_meat.hpp | | SpMat_meat.hpp | |
| | | | |
| skipping to change at line 30 | | skipping to change at line 30 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpMat<eT>::SpMat() | | SpMat<eT>::SpMat() | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| , n_elem(0) | | , n_elem(0) | |
| , n_nonzero(0) | | , n_nonzero(0) | |
| , vec_state(0) | | , vec_state(0) | |
| , values(memory::acquire_chunked<eT>(1)) | | , values(memory::acquire_chunked<eT>(1)) | |
| , row_indices(memory::acquire_chunked<uword>(1)) | | , row_indices(memory::acquire_chunked<uword>(1)) | |
|
| , col_ptrs(memory::acquire<uword>(1)) | | , col_ptrs(memory::acquire<uword>(2)) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| access::rw(values[0]) = 0; | | access::rw(values[0]) = 0; | |
| access::rw(row_indices[0]) = 0; | | access::rw(row_indices[0]) = 0; | |
| | | | |
| access::rw(col_ptrs[0]) = 0; // No elements. | | access::rw(col_ptrs[0]) = 0; // No elements. | |
|
| | | access::rw(col_ptrs[1]) = std::numeric_limits<uword>::max(); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Clean up the memory of a sparse matrix and destruct it. | | * Clean up the memory of a sparse matrix and destruct it. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpMat<eT>::~SpMat() | | SpMat<eT>::~SpMat() | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| skipping to change at line 1224 | | skipping to change at line 1225 | |
| , col_ptrs(NULL) | | , col_ptrs(NULL) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa
lse )); | | arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa
lse )); | |
| | | | |
| spglue_type::apply(*this, X); | | spglue_type::apply(*this, X); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | SpMat<eT>::SpMat(const mtSpOp<eT, T1, spop_type>& X) | |
| | | : n_rows(0) | |
| | | , n_cols(0) | |
| | | , n_elem(0) | |
| | | , n_nonzero(0) | |
| | | , vec_state(0) | |
| | | , values(NULL) // extra element set in application of sparse glue | |
| | | , row_indices(NULL) | |
| | | , col_ptrs(NULL) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| | | spop_type::apply(*this, X); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | spop_type::apply(*this, X); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator+=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpMat<eT> m(X); | |
| | | | |
| | | return (*this).operator+=(m); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator-=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpMat<eT> m(X); | |
| | | | |
| | | return (*this).operator-=(m); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator*=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpMat<eT> m(X); | |
| | | | |
| | | return (*this).operator*=(m); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator%=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpMat<eT> m(X); | |
| | | | |
| | | return (*this).operator%=(m); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1, typename spop_type> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator/=(const mtSpOp<eT, T1, spop_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpMat<eT> m(X); | |
| | | | |
| | | return (*this).operator/=(m); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| template<typename T1, typename T2, typename spglue_type> | | template<typename T1, typename T2, typename spglue_type> | |
| inline | | inline | |
| const SpMat<eT>& | | const SpMat<eT>& | |
| SpMat<eT>::operator=(const SpGlue<T1, T2, spglue_type>& X) | | SpMat<eT>::operator=(const SpGlue<T1, T2, spglue_type>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa
lse )); | | arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa
lse )); | |
| | | | |
| spglue_type::apply(*this, X); | | spglue_type::apply(*this, X); | |
| | | | |
| skipping to change at line 1750 | | skipping to change at line 1847 | |
| access::rw(values) = new_values; | | access::rw(values) = new_values; | |
| access::rw(row_indices) = new_row_indices; | | access::rw(row_indices) = new_row_indices; | |
| | | | |
| // Update counts and such. | | // Update counts and such. | |
| access::rw(n_nonzero) -= diff; | | access::rw(n_nonzero) -= diff; | |
| } | | } | |
| | | | |
| // Update column pointers. | | // Update column pointers. | |
| const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); | | const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); | |
| | | | |
|
| uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 1); | | uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 2); | |
| | | new_col_ptrs[new_n_cols + 1] = std::numeric_limits<uword>::max(); | |
| | | | |
| // Copy first set of columns (no manipulation required). | | // Copy first set of columns (no manipulation required). | |
| if (in_col1 != 0) | | if (in_col1 != 0) | |
| { | | { | |
| arrayops::copy(new_col_ptrs, col_ptrs, in_col1); | | arrayops::copy(new_col_ptrs, col_ptrs, in_col1); | |
| } | | } | |
| | | | |
| // Copy second set of columns (manipulation required). | | // Copy second set of columns (manipulation required). | |
| uword cur_col = in_col1; | | uword cur_col = in_col1; | |
| for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) | | for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) | |
| | | | |
| skipping to change at line 1871 | | skipping to change at line 1969 | |
| return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c
ols); | | return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c
ols); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| const SpSubview<eT> | | const SpSubview<eT> | |
| SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_
row2, const uword in_col2) const | | SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_
row2, const uword in_col2) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return submat(in_row1, in_col1, in_row2, in_col2); | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | |
| | | in_col2 >= n_cols), | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c | |
| | | ols); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT> | | SpSubview<eT> | |
| SpMat<eT>::submat (const span& row_span, const span& col_span) | | SpMat<eT>::submat (const span& row_span, const span& col_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool row_all = row_span.whole; | | const bool row_all = row_span.whole; | |
| | | | |
| skipping to change at line 1914 | | skipping to change at line 2021 | |
| return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col
s); | | return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col
s); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const SpSubview<eT> | | const SpSubview<eT> | |
| SpMat<eT>::submat (const span& row_span, const span& col_span) const | | SpMat<eT>::submat (const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| // Call the non-const version of this function, then cast back to const ( | | const bool row_all = row_span.whole; | |
| avoids code duplication). | | const bool col_all = col_span.whole; | |
| return const_cast<const SpSubview<eT> >(const_cast<SpMat<eT>* >(this)->su | | | |
| bmat(row_span, col_span)); | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | const uword in_row2 = row_span.b; | |
| | | const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + | |
| | | 1; | |
| | | | |
| | | const uword in_col1 = col_all ? 0 : col_span.a; | |
| | | const uword in_col2 = col_span.b; | |
| | | const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + | |
| | | 1; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| | | ) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col | |
| | | s); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT> | | SpSubview<eT> | |
| SpMat<eT>::operator()(const span& row_span, const span& col_span) | | SpMat<eT>::operator()(const span& row_span, const span& col_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return submat(row_span, col_span); | | return submat(row_span, col_span); | |
| | | | |
| skipping to change at line 2448 | | skipping to change at line 2577 | |
| void | | void | |
| SpMat<eT>::reshape(const uword in_rows, const uword in_cols, const uword di
m) | | SpMat<eT>::reshape(const uword in_rows, const uword in_cols, const uword di
m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if (dim == 0) | | if (dim == 0) | |
| { | | { | |
| // We have to modify all of the relevant row indices and the relevant c
olumn pointers. | | // We have to modify all of the relevant row indices and the relevant c
olumn pointers. | |
| // Iterate over all the points to do this. We won't be deleting any po
ints, but we will be modifying | | // Iterate over all the points to do this. We won't be deleting any po
ints, but we will be modifying | |
| // columns and rows. We'll have to store a new set of column vectors. | | // columns and rows. We'll have to store a new set of column vectors. | |
|
| uword* new_col_ptrs = memory::acquire<uword>(in_cols + 1); | | uword* new_col_ptrs = memory::acquire<uword>(in_cols + 2); | |
| | | new_col_ptrs[in_cols + 1] = std::numeric_limits<uword>::max(); | |
| | | | |
| uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1); | | uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1); | |
| access::rw(new_row_indices[n_nonzero]) = 0; | | access::rw(new_row_indices[n_nonzero]) = 0; | |
| | | | |
| arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1); | | arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1); | |
| | | | |
| for(const_iterator it = begin(); it != end(); it++) | | for(const_iterator it = begin(); it != end(); it++) | |
| { | | { | |
| uword vector_position = (it.col() * n_rows) + it.row(); | | uword vector_position = (it.col() * n_rows) + it.row(); | |
| new_row_indices[it.pos()] = vector_position % in_rows; | | new_row_indices[it.pos()] = vector_position % in_rows; | |
| | | | |
| skipping to change at line 2993 | | skipping to change at line 3123 | |
| { | | { | |
| get_position(location, row_of_max_val, col_of_max_val); | | get_position(location, row_of_max_val, col_of_max_val); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| return val; | | return val; | |
| | | | |
| } | | } | |
| | | | |
|
| | | //! save the matrix to a file | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::save(const std::string name, const file_type type, const bool pr | |
| | | int_status) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool save_okay; | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | // case raw_ascii: | |
| | | // save_okay = diskio::save_raw_ascii(*this, name); | |
| | | // break; | |
| | | | |
| | | // case csv_ascii: | |
| | | // save_okay = diskio::save_csv_ascii(*this, name); | |
| | | // break; | |
| | | | |
| | | case arma_binary: | |
| | | save_okay = diskio::save_arma_binary(*this, name); | |
| | | break; | |
| | | | |
| | | case coord_ascii: | |
| | | save_okay = diskio::save_coord_ascii(*this, name); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_warn(true, "SpMat::save(): unsupported file type"); | |
| | | save_okay = false; | |
| | | } | |
| | | | |
| | | arma_warn( (save_okay == false), "SpMat::save(): couldn't write to ", nam | |
| | | e); | |
| | | | |
| | | return save_okay; | |
| | | } | |
| | | | |
| | | //! save the matrix to a stream | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::save(std::ostream& os, const file_type type, const bool print_st | |
| | | atus) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool save_okay; | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | // case raw_ascii: | |
| | | // save_okay = diskio::save_raw_ascii(*this, os); | |
| | | // break; | |
| | | | |
| | | // case csv_ascii: | |
| | | // save_okay = diskio::save_csv_ascii(*this, os); | |
| | | // break; | |
| | | | |
| | | case arma_binary: | |
| | | save_okay = diskio::save_arma_binary(*this, os); | |
| | | break; | |
| | | | |
| | | case coord_ascii: | |
| | | save_okay = diskio::save_coord_ascii(*this, os); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_warn(true, "SpMat::save(): unsupported file type"); | |
| | | save_okay = false; | |
| | | } | |
| | | | |
| | | arma_warn( (save_okay == false), "SpMat::save(): couldn't write to the gi | |
| | | ven stream"); | |
| | | | |
| | | return save_okay; | |
| | | } | |
| | | | |
| | | //! load a matrix from a file | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::load(const std::string name, const file_type type, const bool pr | |
| | | int_status) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool load_okay; | |
| | | std::string err_msg; | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | // case auto_detect: | |
| | | // load_okay = diskio::load_auto_detect(*this, name, err_msg); | |
| | | // break; | |
| | | | |
| | | // case raw_ascii: | |
| | | // load_okay = diskio::load_raw_ascii(*this, name, err_msg); | |
| | | // break; | |
| | | | |
| | | // case csv_ascii: | |
| | | // load_okay = diskio::load_csv_ascii(*this, name, err_msg); | |
| | | // break; | |
| | | | |
| | | case arma_binary: | |
| | | load_okay = diskio::load_arma_binary(*this, name, err_msg); | |
| | | break; | |
| | | | |
| | | case coord_ascii: | |
| | | load_okay = diskio::load_coord_ascii(*this, name, err_msg); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_warn(true, "SpMat::load(): unsupported file type"); | |
| | | load_okay = false; | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | if(err_msg.length() > 0) | |
| | | { | |
| | | arma_warn(true, "SpMat::load(): ", err_msg, name); | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_warn(true, "SpMat::load(): couldn't read ", name); | |
| | | } | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | (*this).reset(); | |
| | | } | |
| | | | |
| | | return load_okay; | |
| | | } | |
| | | | |
| | | //! load a matrix from a stream | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::load(std::istream& is, const file_type type, const bool print_st | |
| | | atus) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool load_okay; | |
| | | std::string err_msg; | |
| | | | |
| | | switch(type) | |
| | | { | |
| | | // case auto_detect: | |
| | | // load_okay = diskio::load_auto_detect(*this, is, err_msg); | |
| | | // break; | |
| | | | |
| | | // case raw_ascii: | |
| | | // load_okay = diskio::load_raw_ascii(*this, is, err_msg); | |
| | | // break; | |
| | | | |
| | | // case csv_ascii: | |
| | | // load_okay = diskio::load_csv_ascii(*this, is, err_msg); | |
| | | // break; | |
| | | | |
| | | case arma_binary: | |
| | | load_okay = diskio::load_arma_binary(*this, is, err_msg); | |
| | | break; | |
| | | | |
| | | case coord_ascii: | |
| | | load_okay = diskio::load_coord_ascii(*this, is, err_msg); | |
| | | break; | |
| | | | |
| | | default: | |
| | | arma_warn(true, "SpMat::load(): unsupported file type"); | |
| | | load_okay = false; | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | if(err_msg.length() > 0) | |
| | | { | |
| | | arma_warn(true, "SpMat::load(): ", err_msg, "the given stream"); | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_warn(true, "SpMat::load(): couldn't load from the given stream") | |
| | | ; | |
| | | } | |
| | | } | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | (*this).reset(); | |
| | | } | |
| | | | |
| | | return load_okay; | |
| | | } | |
| | | | |
| | | //! save the matrix to a file, without printing any error messages | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::quiet_save(const std::string name, const file_type type) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).save(name, type, false); | |
| | | } | |
| | | | |
| | | //! save the matrix to a stream, without printing any error messages | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::quiet_save(std::ostream& os, const file_type type) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).save(os, type, false); | |
| | | } | |
| | | | |
| | | //! load a matrix from a file, without printing any error messages | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::quiet_load(const std::string name, const file_type type) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).load(name, type, false); | |
| | | } | |
| | | | |
| | | //! load a matrix from a stream, without printing any error messages | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpMat<eT>::quiet_load(std::istream& is, const file_type type) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).load(is, type, false); | |
| | | } | |
| | | | |
| /** | | /** | |
| * Initialize the matrix to the specified size. Data is not preserved, so
the matrix is assumed to be entirely sparse (empty). | | * Initialize the matrix to the specified size. Data is not preserved, so
the matrix is assumed to be entirely sparse (empty). | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| SpMat<eT>::init(uword in_rows, uword in_cols) | | SpMat<eT>::init(uword in_rows, uword in_cols) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 3046 | | skipping to change at line 3412 | |
| "SpMat::init(): requested size is too large" | | "SpMat::init(): requested size is too large" | |
| ); | | ); | |
| | | | |
| // Clean out the existing memory. | | // Clean out the existing memory. | |
| if (values) | | if (values) | |
| { | | { | |
| memory::release(values); | | memory::release(values); | |
| memory::release(row_indices); | | memory::release(row_indices); | |
| } | | } | |
| | | | |
|
| access::rw(values) = memory::acquire_chunked<eT>(1); | | access::rw(values) = memory::acquire_chunked<eT> (1); | |
| access::rw(row_indices) = memory::acquire_chunked<uword>(1); | | access::rw(row_indices) = memory::acquire_chunked<uword>(1); | |
| | | | |
| access::rw(values[0]) = 0; | | access::rw(values[0]) = 0; | |
| access::rw(row_indices[0]) = 0; | | access::rw(row_indices[0]) = 0; | |
| | | | |
| memory::release(col_ptrs); | | memory::release(col_ptrs); | |
| | | | |
| // Set the new size accordingly. | | // Set the new size accordingly. | |
| access::rw(n_rows) = in_rows; | | access::rw(n_rows) = in_rows; | |
| access::rw(n_cols) = in_cols; | | access::rw(n_cols) = in_cols; | |
| access::rw(n_elem) = (in_rows * in_cols); | | access::rw(n_elem) = (in_rows * in_cols); | |
| access::rw(n_nonzero) = 0; | | access::rw(n_nonzero) = 0; | |
| | | | |
|
| // Try to allocate the column pointers, filling them with 0. | | // Try to allocate the column pointers, filling them with 0, except for t | |
| access::rw(col_ptrs) = memory::acquire<uword>(in_cols + 1); | | he | |
| | | // last element which contains the maximum possible element (so iterators | |
| | | // terminate correctly). | |
| | | access::rw(col_ptrs) = memory::acquire<uword>(in_cols + 2); | |
| | | access::rw(col_ptrs[in_cols + 1]) = std::numeric_limits<uword>::max(); | |
| | | | |
| arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1); | | arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Initialize the matrix from a string. | | * Initialize the matrix from a string. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| | | | |
| skipping to change at line 3228 | | skipping to change at line 3597 | |
| { | | { | |
| // Figure out the actual amount of memory currently allocated | | // Figure out the actual amount of memory currently allocated | |
| // NOTE: this relies on memory::acquire_chunked() being used for the
'values' and 'row_indices' arrays | | // NOTE: this relies on memory::acquire_chunked() being used for the
'values' and 'row_indices' arrays | |
| const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero)
; | | const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero)
; | |
| | | | |
| if(n_alloc < new_n_nonzero) | | if(n_alloc < new_n_nonzero) | |
| { | | { | |
| eT* new_values = memory::acquire_chunked<eT> (new_n_nonze
ro + 1); | | eT* new_values = memory::acquire_chunked<eT> (new_n_nonze
ro + 1); | |
| uword* new_row_indices = memory::acquire_chunked<uword>(new_n_nonze
ro + 1); | | uword* new_row_indices = memory::acquire_chunked<uword>(new_n_nonze
ro + 1); | |
| | | | |
|
| access::rw(new_values[new_n_nonzero]) = 0; | | | |
| access::rw(new_row_indices[new_n_nonzero]) = 0; | | | |
| | | | |
| if(n_nonzero > 0) | | if(n_nonzero > 0) | |
| { | | { | |
| // Copy old elements. | | // Copy old elements. | |
| uword copy_size = std::min(n_nonzero, new_n_nonzero); | | uword copy_size = std::min(n_nonzero, new_n_nonzero); | |
| | | | |
| arrayops::copy(new_values, values, copy_size); | | arrayops::copy(new_values, values, copy_size); | |
| arrayops::copy(new_row_indices, row_indices, copy_size); | | arrayops::copy(new_row_indices, row_indices, copy_size); | |
| } | | } | |
| | | | |
| memory::release(values); | | memory::release(values); | |
| memory::release(row_indices); | | memory::release(row_indices); | |
| | | | |
| access::rw(values) = new_values; | | access::rw(values) = new_values; | |
| access::rw(row_indices) = new_row_indices; | | access::rw(row_indices) = new_row_indices; | |
| } | | } | |
|
| | | | |
| | | // Set the "fake end" of the matrix by setting the last value and row | |
| | | // index to 0. This helps the iterators work correctly. | |
| | | access::rw(values[new_n_nonzero]) = 0; | |
| | | access::rw(row_indices[new_n_nonzero]) = 0; | |
| } | | } | |
| | | | |
| access::rw(n_nonzero) = new_n_nonzero; | | access::rw(n_nonzero) = new_n_nonzero; | |
| } | | } | |
| } | | } | |
| | | | |
| // Steal memory from another matrix. | | // Steal memory from another matrix. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| | | | |
| skipping to change at line 3295 | | skipping to change at line 3666 | |
| access::rw(x.n_elem) = 0; | | access::rw(x.n_elem) = 0; | |
| access::rw(x.n_nonzero) = 0; | | access::rw(x.n_nonzero) = 0; | |
| | | | |
| access::rw(x.values) = NULL; | | access::rw(x.values) = NULL; | |
| access::rw(x.row_indices) = NULL; | | access::rw(x.row_indices) = NULL; | |
| access::rw(x.col_ptrs) = NULL; | | access::rw(x.col_ptrs) = NULL; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | template<typename T1, typename Functor> | |
| | | arma_hot | |
| | | inline | |
| | | void | |
| | | SpMat<eT>::init_xform(const SpBase<eT,T1>& A, const Functor& func) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | // if possible, avoid doing a copy and instead apply func to the generate | |
| | | d elements | |
| | | if(SpProxy<T1>::Q_created_by_proxy == true) | |
| | | { | |
| | | (*this) = A.get_ref(); | |
| | | | |
| | | const uword nnz = n_nonzero; | |
| | | | |
| | | eT* t_values = access::rwp(values); | |
| | | | |
| | | for(uword i=0; i < nnz; ++i) | |
| | | { | |
| | | t_values[i] = func(t_values[i]); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | init_xform_mt(A.get_ref(), func); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename eT2, typename T1, typename Functor> | |
| | | arma_hot | |
| | | inline | |
| | | void | |
| | | SpMat<eT>::init_xform_mt(const SpBase<eT2,T1>& A, const Functor& func) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpProxy<T1> P(A.get_ref()); | |
| | | | |
| | | if( (P.is_alias(*this) == true) || (is_SpMat<typename SpProxy<T1>::stored | |
| | | _type>::value == true) ) | |
| | | { | |
| | | // NOTE: unwrap_spmat will convert a submatrix to a matrix, which in ef | |
| | | fect takes care of aliasing with submatrices; | |
| | | // NOTE: however, when more delayed ops are implemented, more elaborate | |
| | | handling of aliasing will be necessary | |
| | | const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q); | |
| | | | |
| | | const SpMat<eT2>& x = tmp.M; | |
| | | | |
| | | if(void_ptr(this) != void_ptr(&x)) | |
| | | { | |
| | | init(x.n_rows, x.n_cols); | |
| | | | |
| | | // values and row_indices may not be null. | |
| | | if(values != NULL) | |
| | | { | |
| | | memory::release(values); | |
| | | memory::release(row_indices); | |
| | | } | |
| | | | |
| | | access::rw(values) = memory::acquire_chunked<eT> (x.n_nonzero | |
| | | + 1); | |
| | | access::rw(row_indices) = memory::acquire_chunked<uword>(x.n_nonzero | |
| | | + 1); | |
| | | | |
| | | arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + | |
| | | 1); | |
| | | arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + | |
| | | 1); | |
| | | | |
| | | access::rw(n_nonzero) = x.n_nonzero; | |
| | | } | |
| | | | |
| | | // initialise the elements array with a transformed version of the elem | |
| | | ents from x | |
| | | | |
| | | const uword nnz = n_nonzero; | |
| | | | |
| | | const eT2* x_values = x.values; | |
| | | eT* t_values = access::rwp(values); | |
| | | | |
| | | for(uword i=0; i < nnz; ++i) | |
| | | { | |
| | | t_values[i] = func(x_values[i]); // NOTE: func() must produce a val | |
| | | ue of type eT (ie. act as a convertor between eT2 and eT) | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | init(P.get_n_rows(), P.get_n_cols()); | |
| | | | |
| | | mem_resize(P.get_n_nonzero()); | |
| | | | |
| | | typename SpProxy<T1>::const_iterator_type it = P.begin(); | |
| | | | |
| | | while(it != P.end()) | |
| | | { | |
| | | access::rw(row_indices[it.pos()]) = it.row(); | |
| | | access::rw(values[it.pos()]) = func(*it); // NOTE: func() must prod | |
| | | uce a value of type eT (ie. act as a convertor between eT2 and eT) | |
| | | ++access::rw(col_ptrs[it.col() + 1]); | |
| | | ++it; | |
| | | } | |
| | | | |
| | | // Now sum column pointers. | |
| | | for(uword c = 1; c <= n_cols; ++c) | |
| | | { | |
| | | access::rw(col_ptrs[c]) += col_ptrs[c - 1]; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| typename SpMat<eT>::iterator | | typename SpMat<eT>::iterator | |
| SpMat<eT>::begin() | | SpMat<eT>::begin() | |
| { | | { | |
| return iterator(*this); | | return iterator(*this); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpMat<eT>::const_iterator | | typename SpMat<eT>::const_iterator | |
| | | | |
| skipping to change at line 3425 | | skipping to change at line 3900 | |
| | | | |
| access::rw(values) = memory::acquire_chunked<eT> (1); | | access::rw(values) = memory::acquire_chunked<eT> (1); | |
| access::rw(row_indices) = memory::acquire_chunked<uword>(1); | | access::rw(row_indices) = memory::acquire_chunked<uword>(1); | |
| | | | |
| access::rw(values[0]) = 0; | | access::rw(values[0]) = 0; | |
| access::rw(row_indices[0]) = 0; | | access::rw(row_indices[0]) = 0; | |
| } | | } | |
| | | | |
| memory::release(col_ptrs); | | memory::release(col_ptrs); | |
| | | | |
|
| access::rw(col_ptrs) = memory::acquire<uword>(n_cols + 1); | | access::rw(col_ptrs) = memory::acquire<uword>(n_cols + 2); | |
| | | access::rw(col_ptrs[n_cols + 1]) = std::numeric_limits<uword>::max(); | |
| | | | |
| arrayops::inplace_set(col_ptrs, eT(0), n_cols + 1); | | arrayops::inplace_set(col_ptrs, eT(0), n_cols + 1); | |
| | | | |
| access::rw(n_nonzero) = 0; | | access::rw(n_nonzero) = 0; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| SpMat<eT>::empty() const | | SpMat<eT>::empty() const | |
| | | | |
End of changes. 14 change blocks. |
| 15 lines changed or deleted | | 515 lines changed or added | |
|
| SpProxy.hpp | | SpProxy.hpp | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpMat<eT> stored_type; | | typedef SpMat<eT> stored_type; | |
| | | | |
| typedef typename SpMat<eT>::const_iterator const_iterator_type; | | typedef typename SpMat<eT>::const_iterator const_iterator_type; | |
| typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | | typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | |
| | | | |
|
| static const bool must_use_iterator = false; | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const SpMat<eT>& Q; | | arma_aligned const SpMat<eT>& Q; | |
| | | | |
| inline explicit SpProxy(const SpMat<eT>& A) | | inline explicit SpProxy(const SpMat<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 53 | | skipping to change at line 54 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.values;
} | | arma_inline const eT* get_values() const { return Q.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | | arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | |
| arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin_col(col_num); } | | nst { return Q.begin_col(col_num); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type end() const { | |
| } | | return Q.end(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_row_iterator_type end_row() const { | |
| ); } | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | | arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class SpProxy< SpCol<eT> > | | class SpProxy< SpCol<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpCol<eT> stored_type; | | typedef SpCol<eT> stored_type; | |
| | | | |
| typedef typename SpCol<eT>::const_iterator const_iterator_type; | | typedef typename SpCol<eT>::const_iterator const_iterator_type; | |
| typedef typename SpCol<eT>::const_row_iterator const_row_iterator_type; | | typedef typename SpCol<eT>::const_row_iterator const_row_iterator_type; | |
| | | | |
|
| static const bool must_use_iterator = false; | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = true; | | static const bool is_col = true; | |
| | | | |
| arma_aligned const SpCol<eT>& Q; | | arma_aligned const SpCol<eT>& Q; | |
| | | | |
| inline explicit SpProxy(const SpCol<eT>& A) | | inline explicit SpProxy(const SpCol<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 101 | | skipping to change at line 104 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.values;
} | | arma_inline const eT* get_values() const { return Q.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | | arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | |
| arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type end() const { | |
| } | | return Q.end(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_row_iterator_type end_row() const { | |
| ); } | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | | arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class SpProxy< SpRow<eT> > | | class SpProxy< SpRow<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpRow<eT> stored_type; | | typedef SpRow<eT> stored_type; | |
| | | | |
| typedef typename SpRow<eT>::const_iterator const_iterator_type; | | typedef typename SpRow<eT>::const_iterator const_iterator_type; | |
| typedef typename SpRow<eT>::const_row_iterator const_row_iterator_type; | | typedef typename SpRow<eT>::const_row_iterator const_row_iterator_type; | |
| | | | |
|
| static const bool must_use_iterator = false; | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = false; | |
| | | | |
| static const bool is_row = true; | | static const bool is_row = true; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const SpRow<eT>& Q; | | arma_aligned const SpRow<eT>& Q; | |
| | | | |
| inline explicit SpProxy(const SpRow<eT>& A) | | inline explicit SpProxy(const SpRow<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 149 | | skipping to change at line 154 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.values;
} | | arma_inline const eT* get_values() const { return Q.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | | arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | |
| arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin_col(col_num); } | | nst { return Q.begin_col(col_num); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type end() const { | |
| } | | return Q.end(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_row_iterator_type end_row() const { | |
| ); } | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | | arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class SpProxy< SpSubview<eT> > | | class SpProxy< SpSubview<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpSubview<eT> stored_type; | | typedef SpSubview<eT> stored_type; | |
| | | | |
| typedef typename SpSubview<eT>::const_iterator const_iterator_type; | | typedef typename SpSubview<eT>::const_iterator const_iterator_type; | |
| typedef typename SpSubview<eT>::const_row_iterator const_row_iterator_t
ype; | | typedef typename SpSubview<eT>::const_row_iterator const_row_iterator_t
ype; | |
| | | | |
|
| static const bool must_use_iterator = true; | | static const bool must_use_iterator = true; | |
| | | static const bool Q_created_by_proxy = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const SpSubview<eT>& Q; | | arma_aligned const SpSubview<eT>& Q; | |
| | | | |
| inline explicit SpProxy(const SpSubview<eT>& A) | | inline explicit SpProxy(const SpSubview<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 197 | | skipping to change at line 204 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.m.values;
} | | arma_inline const eT* get_values() const { return Q.m.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.m.row_indices
; } | | arma_inline const uword* get_row_indices() const { return Q.m.row_indices
; } | |
| arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin_col(col_num); } | | nst { return Q.begin_col(col_num); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type end() const { | |
| } | | return Q.end(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_row_iterator_type end_row() const { | |
| ); } | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q.m) == void_ptr(&X)); } | | arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(&
Q.m) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename T1, typename spop_type> | | template<typename T1, typename spop_type> | |
| class SpProxy< SpOp<T1, spop_type> > | | class SpProxy< SpOp<T1, spop_type> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpMat<eT> stored_type; | | typedef SpMat<eT> stored_type; | |
| | | | |
| typedef typename SpMat<eT>::const_iterator const_iterator_type; | | typedef typename SpMat<eT>::const_iterator const_iterator_type; | |
| typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | | typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | |
| | | | |
|
| static const bool must_use_iterator = false; | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = true; | |
| | | | |
| static const bool is_row = SpOp<T1, spop_type>::is_row; | | static const bool is_row = SpOp<T1, spop_type>::is_row; | |
| static const bool is_col = SpOp<T1, spop_type>::is_col; | | static const bool is_col = SpOp<T1, spop_type>::is_col; | |
| | | | |
| arma_aligned const SpMat<eT> Q; | | arma_aligned const SpMat<eT> Q; | |
| | | | |
| inline explicit SpProxy(const SpOp<T1, spop_type>& A) | | inline explicit SpProxy(const SpOp<T1, spop_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 246 | | skipping to change at line 255 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.values;
} | | arma_inline const eT* get_values() const { return Q.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | | arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | |
| arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin_col(col_num); } | | nst { return Q.begin_col(col_num); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type end() const { | |
| } | | return Q.end(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_row_iterator_type end_row() const { | |
| ); } | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } | | arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
| template<typename T1, typename T2, typename spglue_type> | | template<typename T1, typename T2, typename spglue_type> | |
| class SpProxy< SpGlue<T1, T2, spglue_type> > | | class SpProxy< SpGlue<T1, T2, spglue_type> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef SpMat<eT> stored_type; | | typedef SpMat<eT> stored_type; | |
| | | | |
| typedef typename SpMat<eT>::const_iterator const_iterator_type; | | typedef typename SpMat<eT>::const_iterator const_iterator_type; | |
| typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | | typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; | |
| | | | |
|
| static const bool must_use_iterator = false; | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = true; | |
| | | | |
| static const bool is_row = SpGlue<T1, T2, spglue_type>::is_row; | | static const bool is_row = SpGlue<T1, T2, spglue_type>::is_row; | |
| static const bool is_col = SpGlue<T1, T2, spglue_type>::is_col; | | static const bool is_col = SpGlue<T1, T2, spglue_type>::is_col; | |
| | | | |
| arma_aligned const SpMat<eT> Q; | | arma_aligned const SpMat<eT> Q; | |
| | | | |
| inline explicit SpProxy(const SpGlue<T1, T2, spglue_type>& A) | | inline explicit SpProxy(const SpGlue<T1, T2, spglue_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 295 | | skipping to change at line 306 | |
| arma_inline uword get_n_elem() const { return Q.n_elem; } | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[](const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline const eT* get_values() const { return Q.values;
} | | arma_inline const eT* get_values() const { return Q.values;
} | |
| arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | | arma_inline const uword* get_row_indices() const { return Q.row_indices;
} | |
| arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
} | |
| | | | |
|
| arma_inline const_iterator_type begin() const | | arma_inline const_iterator_type begin() co | |
| { return Q.begin(); } | | nst { return Q.begin(); } | |
| arma_inline const_iterator_type begin_col(const uword col_num) const | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| { return Q.begin_col(col_num); } | | nst { return Q.begin_col(col_num); } | |
| arma_inline const_row_iterator_type begin_row() const | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| { return Q.begin_row(); } | | nst { return Q.begin_row(row_num); } | |
| | | | |
| | | arma_inline const_iterator_type end() const { | |
| | | return Q.end(); } | |
| | | arma_inline const_row_iterator_type end_row() const { | |
| | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } | |
| | | }; | |
| | | | |
| | | template<typename out_eT, typename T1, typename spop_type> | |
| | | class SpProxy< mtSpOp<out_eT, T1, spop_type> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef out_eT elem_type; | |
| | | typedef typename T1::elem_type eT; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef SpMat<out_eT> stored_type; | |
| | | | |
| | | typedef typename SpMat<out_eT>::const_iterator const_iterator_type; | |
| | | typedef typename SpMat<out_eT>::const_row_iterator const_row_iterator_t | |
| | | ype; | |
| | | | |
| | | static const bool must_use_iterator = false; | |
| | | static const bool Q_created_by_proxy = true; | |
| | | | |
| | | static const bool is_row = mtSpOp<out_eT, T1, spop_type>::is_row; | |
| | | static const bool is_col = mtSpOp<out_eT, T1, spop_type>::is_col; | |
| | | | |
| | | arma_aligned const SpMat<out_eT> Q; | |
| | | | |
| | | inline explicit SpProxy(const mtSpOp<out_eT, T1, spop_type>& A) | |
| | | : Q(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } | |
| | | | |
| | | arma_inline elem_type operator[](const uword i) const | |
| | | { return Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return Q.at(row, col); } | |
| | | | |
| | | arma_inline const eT* get_values() const { return Q.values; | |
| | | } | |
| | | arma_inline const uword* get_row_indices() const { return Q.row_indices; | |
| | | } | |
| | | arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; | |
| | | } | |
| | | | |
|
| arma_inline const_iterator_type end() const { return Q.end(); | | arma_inline const_iterator_type begin() co | |
| } | | nst { return Q.begin(); } | |
| arma_inline const_row_iterator_type end_row() const { return Q.end_row( | | arma_inline const_iterator_type begin_col(const uword col_num) co | |
| ); } | | nst { return Q.begin_col(col_num); } | |
| | | arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co | |
| | | nst { return Q.begin_row(row_num); } | |
| | | | |
| | | arma_inline const_iterator_type end() const { | |
| | | return Q.end(); } | |
| | | arma_inline const_row_iterator_type end_row() const { | |
| | | return Q.end_row(); } | |
| | | arma_inline const_row_iterator_type end_row(const uword row_num) const { | |
| | | return Q.end_row(row_num); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } | | arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 13 change blocks. |
| 71 lines changed or deleted | | 152 lines changed or added | |
|
| SpSubview_bones.hpp | | SpSubview_bones.hpp | |
| | | | |
| skipping to change at line 103 | | skipping to change at line 103 | |
| arma_hot inline SpValProxy<SpSubview<eT> > at(const uword i); | | arma_hot inline SpValProxy<SpSubview<eT> > at(const uword i); | |
| arma_hot inline eT at(const uword i) const; | | arma_hot inline eT at(const uword i) const; | |
| | | | |
| arma_hot inline SpValProxy<SpSubview<eT> > at(const uword in_row, const u
word in_col); | | arma_hot inline SpValProxy<SpSubview<eT> > at(const uword in_row, const u
word in_col); | |
| arma_hot inline eT at(const uword in_row, const u
word in_col) const; | | arma_hot inline eT at(const uword in_row, const u
word in_col) const; | |
| | | | |
| inline bool check_overlap(const SpSubview& x) const; | | inline bool check_overlap(const SpSubview& x) const; | |
| | | | |
| inline bool is_vec() const; | | inline bool is_vec() const; | |
| | | | |
|
| | | inline SpSubview row(const uword row_num); | |
| | | inline const SpSubview row(const uword row_num) const; | |
| | | | |
| | | inline SpSubview col(const uword col_num); | |
| | | inline const SpSubview col(const uword col_num) const; | |
| | | | |
| | | inline SpSubview rows(const uword in_row1, const uword in_row2); | |
| | | inline const SpSubview rows(const uword in_row1, const uword in_row2) con | |
| | | st; | |
| | | | |
| | | inline SpSubview cols(const uword in_col1, const uword in_col2); | |
| | | inline const SpSubview cols(const uword in_col1, const uword in_col2) con | |
| | | st; | |
| | | | |
| | | inline SpSubview submat(const uword in_row1, const uword in_col1, c | |
| | | onst uword in_row2, const uword in_col2); | |
| | | inline const SpSubview submat(const uword in_row1, const uword in_col1, c | |
| | | onst uword in_row2, const uword in_col2) const; | |
| | | | |
| | | inline SpSubview submat(const span& row_span, const span& col_span) | |
| | | ; | |
| | | inline const SpSubview submat(const span& row_span, const span& col_span) | |
| | | const; | |
| | | | |
| | | inline SpSubview operator()(const uword row_num, const span& col_sp | |
| | | an); | |
| | | inline const SpSubview operator()(const uword row_num, const span& col_sp | |
| | | an) const; | |
| | | | |
| | | inline SpSubview operator()(const span& row_span, const uword col_n | |
| | | um); | |
| | | inline const SpSubview operator()(const span& row_span, const uword col_n | |
| | | um) const; | |
| | | | |
| | | inline SpSubview operator()(const span& row_span, const span& col_s | |
| | | pan); | |
| | | inline const SpSubview operator()(const span& row_span, const span& col_s | |
| | | pan) const; | |
| | | | |
| /* not yet | | /* not yet | |
| inline SpSubview_row<eT> row(const uword row_num); | | inline SpSubview_row<eT> row(const uword row_num); | |
| inline const SpSubview_row<eT> row(const uword row_num) const; | | inline const SpSubview_row<eT> row(const uword row_num) const; | |
| | | | |
| inline SpSubview_row<eT> operator()(const uword row_num, const
span& col_span); | | inline SpSubview_row<eT> operator()(const uword row_num, const
span& col_span); | |
| inline const SpSubview_row<eT> operator()(const uword row_num, const
span& col_span) const; | | inline const SpSubview_row<eT> operator()(const uword row_num, const
span& col_span) const; | |
| | | | |
| inline SpSubview_col<eT> col(const uword col_num); | | inline SpSubview_col<eT> col(const uword col_num); | |
| inline const SpSubview_col<eT> col(const uword col_num) const; | | inline const SpSubview_col<eT> col(const uword col_num) const; | |
| | | | |
| | | | |
| skipping to change at line 141 | | skipping to change at line 168 | |
| inline SpSubview<eT> operator()(const span& row_span, const sp
an& col_span); | | inline SpSubview<eT> operator()(const span& row_span, const sp
an& col_span); | |
| inline const SpSubview<eT> operator()(const span& row_span, const sp
an& col_span) const; | | inline const SpSubview<eT> operator()(const span& row_span, const sp
an& col_span) const; | |
| | | | |
| inline diagview<eT> diag(const s32 in_id = 0); | | inline diagview<eT> diag(const s32 in_id = 0); | |
| inline const diagview<eT> diag(const s32 in_id = 0) const; | | inline const diagview<eT> diag(const s32 in_id = 0) const; | |
| */ | | */ | |
| | | | |
| inline void swap_rows(const uword in_row1, const uword in_row2); | | inline void swap_rows(const uword in_row1, const uword in_row2); | |
| inline void swap_cols(const uword in_col1, const uword in_col2); | | inline void swap_cols(const uword in_col1, const uword in_col2); | |
| | | | |
|
| // Similar to SpMat iterators but automatically iterate over values not i | | // Forward declarations. | |
| n the subview. | | class iterator_base; | |
| | | class const_iterator; | |
| | | class iterator; | |
| | | class const_row_iterator; | |
| | | class row_iterator; | |
| | | | |
| | | // Similar to SpMat iterators but automatically iterates past and ignores | |
| | | values not in the subview. | |
| class iterator_base | | class iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline iterator_base(const SpSubview& in_M); | | inline iterator_base(const SpSubview& in_M); | |
| inline iterator_base(const SpSubview& in_M, const uword col, const uwor
d pos, const uword skip_pos); | | inline iterator_base(const SpSubview& in_M, const uword col, const uwor
d pos, const uword skip_pos); | |
| | | | |
| inline eT operator*() const; | | inline eT operator*() const; | |
| | | | |
|
| inline bool operator!=(const iterator_base& rhs) const; | | | |
| inline bool operator==(const iterator_base& rhs) const; | | | |
| | | | |
| inline bool operator!=(const typename SpMat<eT>::iterator_base& rhs) co | | | |
| nst; | | | |
| inline bool operator==(const typename SpMat<eT>::iterator_base& rhs) co | | | |
| nst; | | | |
| | | | |
| // Don't hold location internally; call "dummy" methods to get that inf
ormation. | | // Don't hold location internally; call "dummy" methods to get that inf
ormation. | |
| arma_inline uword row() const { return M.m.row_indices[internal_pos + s
kip_pos] - M.aux_row1; } | | arma_inline uword row() const { return M.m.row_indices[internal_pos + s
kip_pos] - M.aux_row1; } | |
| arma_inline uword col() const { return internal_col;
} | | arma_inline uword col() const { return internal_col;
} | |
| arma_inline uword pos() const { return internal_pos;
} | | arma_inline uword pos() const { return internal_pos;
} | |
| | | | |
| arma_aligned const SpSubview& M; | | arma_aligned const SpSubview& M; | |
| arma_aligned uword internal_col; | | arma_aligned uword internal_col; | |
| arma_aligned uword internal_pos; | | arma_aligned uword internal_pos; | |
| arma_aligned uword skip_pos; // not used in row_iterator or
const_row_iterator | | arma_aligned uword skip_pos; // not used in row_iterator or
const_row_iterator | |
|
| | | | |
| | | // So that we satisfy the STL iterator types. | |
| | | typedef std::bidirectional_iterator_tag iterator_category; | |
| | | typedef eT value_type; | |
| | | typedef uword difference_type; // not certain | |
| | | on this one | |
| | | typedef const eT* pointer; | |
| | | typedef const eT& reference; | |
| }; | | }; | |
| | | | |
| class const_iterator : public iterator_base | | class const_iterator : public iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); | | inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); | |
| inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col
); | | inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col
); | |
| inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col
, uword in_pos, uword skip_pos); | | inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col
, uword in_pos, uword skip_pos); | |
| inline const_iterator(const const_iterator& other); | | inline const_iterator(const const_iterator& other); | |
| | | | |
| inline const_iterator& operator++(); | | inline const_iterator& operator++(); | |
|
| inline void operator++(int); | | inline const_iterator operator++(int); | |
| | | | |
| inline const_iterator& operator--(); | | inline const_iterator& operator--(); | |
|
| inline void operator--(int); | | inline const_iterator operator--(int); | |
| | | | |
| | | inline bool operator!=(const const_iterator& rhs) const; | |
| | | inline bool operator==(const const_iterator& rhs) const; | |
| | | | |
| | | inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) c | |
| | | onst; | |
| | | inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) c | |
| | | onst; | |
| | | | |
| | | inline bool operator!=(const const_row_iterator& rhs) const; | |
| | | inline bool operator==(const const_row_iterator& rhs) const; | |
| | | | |
| | | inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rh | |
| | | s) const; | |
| | | inline bool operator==(const typename SpMat<eT>::const_row_iterator& rh | |
| | | s) const; | |
| }; | | }; | |
| | | | |
| class iterator : public const_iterator | | class iterator : public const_iterator | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_i
terator(in_M, initial_pos) { } | | inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_i
terator(in_M, initial_pos) { } | |
| inline iterator(SpSubview& in_M, const uword in_row, const uword in_col
) : const_iterator(in_M, in_row, in_col) { } | | inline iterator(SpSubview& in_M, const uword in_row, const uword in_col
) : const_iterator(in_M, in_row, in_col) { } | |
| inline iterator(SpSubview& in_M, const uword in_row, const uword in_col
, const uword in_pos, const uword skip_pos) : const_iterator(in_M, in_row,
in_col, in_pos, skip_pos) { } | | inline iterator(SpSubview& in_M, const uword in_row, const uword in_col
, const uword in_pos, const uword skip_pos) : const_iterator(in_M, in_row,
in_col, in_pos, skip_pos) { } | |
| inline iterator(const iterator& other) : const_iterator(other) { } | | inline iterator(const iterator& other) : const_iterator(other) { } | |
| | | | |
| inline SpValProxy<SpSubview<eT> > operator*(); | | inline SpValProxy<SpSubview<eT> > operator*(); | |
| | | | |
| // overloads needed for return type correctness | | // overloads needed for return type correctness | |
| inline iterator& operator++(); | | inline iterator& operator++(); | |
|
| inline void operator++(int); | | inline iterator operator++(int); | |
| | | | |
| inline iterator& operator--(); | | inline iterator& operator--(); | |
|
| inline void operator--(int); | | inline iterator operator--(int); | |
| | | | |
| | | // This has a different value_type than iterator_base. | |
| | | typedef SpValProxy<SpSubview<eT> > value_type; | |
| | | typedef const SpValProxy<SpSubview<eT> >* pointer; | |
| | | typedef const SpValProxy<SpSubview<eT> >& reference; | |
| }; | | }; | |
| | | | |
| class const_row_iterator : public iterator_base | | class const_row_iterator : public iterator_base | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0)
; | | inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0)
; | |
| inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in
_col); | | inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in
_col); | |
| inline const_row_iterator(const const_row_iterator& other); | | inline const_row_iterator(const const_row_iterator& other); | |
| | | | |
| inline const_row_iterator& operator++(); | | inline const_row_iterator& operator++(); | |
|
| inline void operator++(int); | | inline const_row_iterator operator++(int); | |
| | | | |
| inline const_row_iterator& operator--(); | | inline const_row_iterator& operator--(); | |
|
| inline void operator--(int); | | inline const_row_iterator operator--(int); | |
| | | | |
| uword internal_row; // Hold row internally because we use internal_pos
differently. | | uword internal_row; // Hold row internally because we use internal_pos
differently. | |
| uword actual_pos; // Actual position in subview's parent matrix. | | uword actual_pos; // Actual position in subview's parent matrix. | |
| | | | |
| arma_inline eT operator*() const { return iterator_base::M.m.values[act
ual_pos]; } | | arma_inline eT operator*() const { return iterator_base::M.m.values[act
ual_pos]; } | |
| | | | |
| arma_inline uword row() const { return internal_row; } | | arma_inline uword row() const { return internal_row; } | |
|
| | | | |
| | | inline bool operator!=(const const_iterator& rhs) const; | |
| | | inline bool operator==(const const_iterator& rhs) const; | |
| | | | |
| | | inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) c | |
| | | onst; | |
| | | inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) c | |
| | | onst; | |
| | | | |
| | | inline bool operator!=(const const_row_iterator& rhs) const; | |
| | | inline bool operator==(const const_row_iterator& rhs) const; | |
| | | | |
| | | inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rh | |
| | | s) const; | |
| | | inline bool operator==(const typename SpMat<eT>::const_row_iterator& rh | |
| | | s) const; | |
| }; | | }; | |
| | | | |
| class row_iterator : public const_row_iterator | | class row_iterator : public const_row_iterator | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row
_iterator(in_M, initial_pos) { } | | inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row
_iterator(in_M, initial_pos) { } | |
| inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : cons
t_row_iterator(in_M, in_row, in_col) { } | | inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : cons
t_row_iterator(in_M, in_row, in_col) { } | |
| inline row_iterator(const row_iterator& other) : const_row_iterator(oth
er) { } | | inline row_iterator(const row_iterator& other) : const_row_iterator(oth
er) { } | |
| | | | |
| inline SpValProxy<SpSubview<eT> > operator*(); | | inline SpValProxy<SpSubview<eT> > operator*(); | |
| | | | |
| // overloads needed for return type correctness | | // overloads needed for return type correctness | |
| inline row_iterator& operator++(); | | inline row_iterator& operator++(); | |
|
| inline void operator++(int); | | inline row_iterator operator++(int); | |
| | | | |
| inline row_iterator& operator--(); | | inline row_iterator& operator--(); | |
|
| inline void operator--(int); | | inline row_iterator operator--(int); | |
| | | | |
| | | // This has a different value_type than iterator_base. | |
| | | typedef SpValProxy<SpSubview<eT> > value_type; | |
| | | typedef const SpValProxy<SpSubview<eT> >* pointer; | |
| | | typedef const SpValProxy<SpSubview<eT> >& reference; | |
| }; | | }; | |
| | | | |
| inline iterator begin(); | | inline iterator begin(); | |
| inline const_iterator begin() const; | | inline const_iterator begin() const; | |
| | | | |
| inline iterator begin_col(const uword col_num); | | inline iterator begin_col(const uword col_num); | |
| inline const_iterator begin_col(const uword col_num) const; | | inline const_iterator begin_col(const uword col_num) const; | |
| | | | |
|
| inline row_iterator begin_row(); | | inline row_iterator begin_row(const uword row_num = 0); | |
| inline const_row_iterator begin_row() const; | | inline const_row_iterator begin_row(const uword row_num = 0) const; | |
| | | | |
| inline iterator end(); | | inline iterator end(); | |
| inline const_iterator end() const; | | inline const_iterator end() const; | |
| | | | |
| inline row_iterator end_row(); | | inline row_iterator end_row(); | |
| inline const_row_iterator end_row() const; | | inline const_row_iterator end_row() const; | |
| | | | |
|
| | | inline row_iterator end_row(const uword row_num = 0); | |
| | | inline const_row_iterator end_row(const uword row_num = 0) const; | |
| | | | |
| private: | | private: | |
| friend class SpMat<eT>; | | friend class SpMat<eT>; | |
| SpSubview(); | | SpSubview(); | |
| | | | |
| // For use by SpValProxy. We just update n_nonzero and pass the call on
to the matrix. | | // For use by SpValProxy. We just update n_nonzero and pass the call on
to the matrix. | |
| inline arma_hot arma_warn_unused eT& add_element(const uword in_row, con
st uword in_col, const eT in_val = 0.0); | | inline arma_hot arma_warn_unused eT& add_element(const uword in_row, con
st uword in_col, const eT in_val = 0.0); | |
| inline arma_hot void delete_element(const uword in_row,
const uword in_col); | | inline arma_hot void delete_element(const uword in_row,
const uword in_col); | |
| | | | |
| }; | | }; | |
| | | | |
| | | | |
End of changes. 15 change blocks. |
| 20 lines changed or deleted | | 111 lines changed or added | |
|
| SpSubview_iterators_meat.hpp | | SpSubview_iterators_meat.hpp | |
| | | | |
| skipping to change at line 50 | | skipping to change at line 50 | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| SpSubview<eT>::iterator_base::operator*() const | | SpSubview<eT>::iterator_base::operator*() const | |
| { | | { | |
| return M.m.values[internal_pos + skip_pos]; | | return M.m.values[internal_pos + skip_pos]; | |
| } | | } | |
| | | | |
|
| template<typename eT> | | | |
| inline | | | |
| bool | | | |
| SpSubview<eT>::iterator_base::operator==(const iterator_base& rhs) const | | | |
| { | | | |
| return (rhs.row() == row()) && (rhs.col() == internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| bool | | | |
| SpSubview<eT>::iterator_base::operator!=(const iterator_base& rhs) const | | | |
| { | | | |
| return (rhs.row() != row()) || (rhs.col() != internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| bool | | | |
| SpSubview<eT>::iterator_base::operator==(const typename SpMat<eT>::iterator | | | |
| _base& rhs) const | | | |
| { | | | |
| return (rhs.row() == row()) && (rhs.col() == internal_col); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| inline | | | |
| bool | | | |
| SpSubview<eT>::iterator_base::operator!=(const typename SpMat<eT>::iterator | | | |
| _base& rhs) const | | | |
| { | | | |
| return (rhs.row() != row()) || (rhs.col() != internal_col); | | | |
| } | | | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpSubview::const_iterator implementation
// | | // SpSubview::const_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co
nst uword initial_pos) | | SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co
nst uword initial_pos) | |
| : iterator_base(in_M, 0, initial_pos, 0) | | : iterator_base(in_M, 0, initial_pos, 0) | |
| { | | { | |
| // Corner case for empty subviews. | | // Corner case for empty subviews. | |
| | | | |
| skipping to change at line 104 | | skipping to change at line 72 | |
| iterator_base::internal_col = in_M.n_cols; | | iterator_base::internal_col = in_M.n_cols; | |
| iterator_base::skip_pos = in_M.m.n_nonzero; | | iterator_base::skip_pos = in_M.m.n_nonzero; | |
| return; | | return; | |
| } | | } | |
| | | | |
| // Figure out the row and column of the position. | | // Figure out the row and column of the position. | |
| // skip_pos holds the number of values which aren't part of this subview. | | // skip_pos holds the number of values which aren't part of this subview. | |
| const uword aux_col = iterator_base::M.aux_col1; | | const uword aux_col = iterator_base::M.aux_col1; | |
| const uword aux_row = iterator_base::M.aux_row1; | | const uword aux_row = iterator_base::M.aux_row1; | |
| const uword n_rows = iterator_base::M.n_rows; | | const uword n_rows = iterator_base::M.n_rows; | |
|
| | | const uword n_cols = iterator_base::M.n_cols; | |
| | | | |
| uword cur_pos = 0; // off by one because we might be searching for pos 0 | | uword cur_pos = 0; // off by one because we might be searching for pos 0 | |
| uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; | | uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; | |
| uword cur_col = 0; | | uword cur_col = 0; | |
| | | | |
| while(cur_pos < (iterator_base::internal_pos + 1)) | | while(cur_pos < (iterator_base::internal_pos + 1)) | |
| { | | { | |
| // Have we stepped forward a column (or multiple columns)? | | // Have we stepped forward a column (or multiple columns)? | |
|
| while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux
_col + 1]) | | while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au
x_col + 1]) && (cur_col < n_cols)) | |
| { | | { | |
| ++cur_col; | | ++cur_col; | |
| } | | } | |
| | | | |
| // See if the current position is in the subview. | | // See if the current position is in the subview. | |
| const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p
os]; | | const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p
os]; | |
| if(row_index < aux_row) | | if(row_index < aux_row) | |
| { | | { | |
| ++skip_pos; // not valid | | ++skip_pos; // not valid | |
| } | | } | |
| | | | |
| skipping to change at line 144 | | skipping to change at line 113 | |
| | | | |
| iterator_base::internal_col = cur_col; | | iterator_base::internal_col = cur_col; | |
| iterator_base::skip_pos = skip_pos; | | iterator_base::skip_pos = skip_pos; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co
nst uword in_row, const uword in_col) | | SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co
nst uword in_row, const uword in_col) | |
| : iterator_base(in_M, in_col, 0, 0) | | : iterator_base(in_M, in_col, 0, 0) | |
| { | | { | |
|
| | | // Corner case for empty subviews. | |
| | | if(in_M.n_nonzero == 0) | |
| | | { | |
| | | // We must be at the last position. | |
| | | iterator_base::internal_col = in_M.n_cols; | |
| | | iterator_base::skip_pos = in_M.m.n_nonzero; | |
| | | return; | |
| | | } | |
| | | | |
| // We have a destination we want to be just after, but don't know what po
sition that is. | | // We have a destination we want to be just after, but don't know what po
sition that is. | |
| // Because we have to count the points in this subview and not in this su
bview, this becomes a little difficult and slow. | | // Because we have to count the points in this subview and not in this su
bview, this becomes a little difficult and slow. | |
| const uword aux_col = iterator_base::M.aux_col1; | | const uword aux_col = iterator_base::M.aux_col1; | |
| const uword aux_row = iterator_base::M.aux_row1; | | const uword aux_row = iterator_base::M.aux_row1; | |
| const uword n_rows = iterator_base::M.n_rows; | | const uword n_rows = iterator_base::M.n_rows; | |
|
| | | const uword n_cols = iterator_base::M.n_cols; | |
| | | | |
| uword cur_pos = 0; | | uword cur_pos = 0; | |
| uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; | | uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; | |
| uword cur_col = 0; | | uword cur_col = 0; | |
| | | | |
| while(cur_col < in_col) | | while(cur_col < in_col) | |
| { | | { | |
| // See if the current position is in the subview. | | // See if the current position is in the subview. | |
| const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p
os]; | | const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p
os]; | |
| if(row_index < aux_row) | | if(row_index < aux_row) | |
| | | | |
| skipping to change at line 174 | | skipping to change at line 153 | |
| ++cur_pos; | | ++cur_pos; | |
| } | | } | |
| else | | else | |
| { | | { | |
| // skip to end of column | | // skip to end of column | |
| const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_c
ol + 1]; | | const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_c
ol + 1]; | |
| skip_pos += (next_colptr - (cur_pos + skip_pos)); | | skip_pos += (next_colptr - (cur_pos + skip_pos)); | |
| } | | } | |
| | | | |
| // Have we stepped forward a column (or multiple columns)? | | // Have we stepped forward a column (or multiple columns)? | |
|
| while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux
_col + 1]) | | while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au
x_col + 1]) && (cur_col < n_cols)) | |
| { | | { | |
| ++cur_col; | | ++cur_col; | |
| } | | } | |
| } | | } | |
| | | | |
| // Now we are either on the right column or ahead of it. | | // Now we are either on the right column or ahead of it. | |
| if(cur_col == in_col) | | if(cur_col == in_col) | |
| { | | { | |
| // We have to find the right row index. | | // We have to find the right row index. | |
| uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | | uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | |
| | | | |
| skipping to change at line 196 | | skipping to change at line 175 | |
| { | | { | |
| if(row_index < aux_row) | | if(row_index < aux_row) | |
| { | | { | |
| ++skip_pos; | | ++skip_pos; | |
| } | | } | |
| else | | else | |
| { | | { | |
| ++cur_pos; | | ++cur_pos; | |
| } | | } | |
| | | | |
|
| | | // Ensure we didn't step forward a column; if we did, we need to stop | |
| | | . | |
| | | while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + | |
| | | aux_col + 1]) && (cur_col < n_cols)) | |
| | | { | |
| | | ++cur_col; | |
| | | } | |
| | | | |
| | | if(cur_col != in_col) | |
| | | { | |
| | | break; | |
| | | } | |
| | | | |
| row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | | row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | |
| } | | } | |
| } | | } | |
| | | | |
| // Now we need to find the next valid position in the subview. | | // Now we need to find the next valid position in the subview. | |
| uword row_index; | | uword row_index; | |
| while(true) | | while(true) | |
| { | | { | |
| const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col
+ 1]; | | const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col
+ 1]; | |
| row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | | row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; | |
| | | | |
|
| | | // Are we at the last position? | |
| | | if(cur_col >= n_cols) | |
| | | { | |
| | | cur_col = n_cols; | |
| | | // Make sure we will be pointing at the last element in the parent ma | |
| | | trix. | |
| | | skip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero; | |
| | | break; | |
| | | } | |
| | | | |
| if(row_index < aux_row) | | if(row_index < aux_row) | |
| { | | { | |
| ++skip_pos; | | ++skip_pos; | |
| } | | } | |
| else if(row_index < (aux_row + n_rows)) | | else if(row_index < (aux_row + n_rows)) | |
| { | | { | |
| break; // found | | break; // found | |
| } | | } | |
| else | | else | |
| { | | { | |
| skip_pos += (next_colptr - (cur_pos + skip_pos)); | | skip_pos += (next_colptr - (cur_pos + skip_pos)); | |
| } | | } | |
| | | | |
| // Did we move any columns? | | // Did we move any columns? | |
|
| while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux
_col + 1]) | | while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au
x_col + 1]) && (cur_col < n_cols)) | |
| { | | { | |
| ++cur_col; | | ++cur_col; | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | // It is possible we have moved another column. | |
| | | while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_ | |
| | | col + 1]) && (cur_col < n_cols)) | |
| | | { | |
| | | ++cur_col; | |
| | | } | |
| | | | |
| iterator_base::internal_pos = cur_pos; | | iterator_base::internal_pos = cur_pos; | |
| iterator_base::skip_pos = skip_pos; | | iterator_base::skip_pos = skip_pos; | |
| iterator_base::internal_col = cur_col; | | iterator_base::internal_col = cur_col; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, uw
ord in_row, uword in_col, uword in_pos, uword skip_pos) | | SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, uw
ord in_row, uword in_col, uword in_pos, uword skip_pos) | |
| : iterator_base(in_M, in_col, in_pos, skip_pos) | | : iterator_base(in_M, in_col, in_pos, skip_pos) | |
| { | | { | |
| | | | |
| skipping to change at line 306 | | skipping to change at line 311 | |
| | | | |
| iterator_base::internal_pos = cur_pos; | | iterator_base::internal_pos = cur_pos; | |
| iterator_base::internal_col = cur_col; | | iterator_base::internal_col = cur_col; | |
| iterator_base::skip_pos = skip_pos; | | iterator_base::skip_pos = skip_pos; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::const_iterator | |
| SpSubview<eT>::const_iterator::operator++(int) | | SpSubview<eT>::const_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::const_iterator tmp(*this); | |
| | | | |
| ++(*this); | | ++(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::const_iterator& | | typename SpSubview<eT>::const_iterator& | |
| SpSubview<eT>::const_iterator::operator--() | | SpSubview<eT>::const_iterator::operator--() | |
| { | | { | |
| const uword aux_col = iterator_base::M.aux_col1; | | const uword aux_col = iterator_base::M.aux_col1; | |
| const uword aux_row = iterator_base::M.aux_row1; | | const uword aux_row = iterator_base::M.aux_row1; | |
| const uword n_rows = iterator_base::M.n_rows; | | const uword n_rows = iterator_base::M.n_rows; | |
| | | | |
| skipping to change at line 369 | | skipping to change at line 378 | |
| | | | |
| iterator_base::internal_pos = cur_pos; | | iterator_base::internal_pos = cur_pos; | |
| iterator_base::skip_pos = skip_pos; | | iterator_base::skip_pos = skip_pos; | |
| iterator_base::internal_col = cur_col; | | iterator_base::internal_col = cur_col; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::const_iterator | |
| SpSubview<eT>::const_iterator::operator--(int) | | SpSubview<eT>::const_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::const_iterator tmp(*this); | |
| | | | |
| --(*this); | | --(*this); | |
|
| | | | |
| | | return tmp; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator==(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator!=(const const_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator==(const typename SpMat<eT>::const_i | |
| | | terator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator!=(const typename SpMat<eT>::const_i | |
| | | terator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator==(const const_row_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator!=(const const_row_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator==(const typename SpMat<eT>::const_r | |
| | | ow_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter | |
| | | nal_col); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_iterator::operator!=(const typename SpMat<eT>::const_r | |
| | | ow_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter | |
| | | nal_col); | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpSubview<eT>::iterator implementation
// | | // SpSubview<eT>::iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpValProxy<SpSubview<eT> > | | SpValProxy<SpSubview<eT> > | |
| SpSubview<eT>::iterator::operator*() | | SpSubview<eT>::iterator::operator*() | |
| | | | |
| skipping to change at line 402 | | skipping to change at line 479 | |
| inline | | inline | |
| typename SpSubview<eT>::iterator& | | typename SpSubview<eT>::iterator& | |
| SpSubview<eT>::iterator::operator++() | | SpSubview<eT>::iterator::operator++() | |
| { | | { | |
| const_iterator::operator++(); | | const_iterator::operator++(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::iterator | |
| SpSubview<eT>::iterator::operator++(int) | | SpSubview<eT>::iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::iterator tmp(*this); | |
| | | | |
| const_iterator::operator++(); | | const_iterator::operator++(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::iterator& | | typename SpSubview<eT>::iterator& | |
| SpSubview<eT>::iterator::operator--() | | SpSubview<eT>::iterator::operator--() | |
| { | | { | |
| const_iterator::operator--(); | | const_iterator::operator--(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::iterator | |
| SpSubview<eT>::iterator::operator--(int) | | SpSubview<eT>::iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::iterator tmp(*this); | |
| | | | |
| const_iterator::operator--(); | | const_iterator::operator--(); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpSubview<eT>::const_row_iterator implementation
// | | // SpSubview<eT>::const_row_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>&
in_M, uword initial_pos) | | SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>&
in_M, uword initial_pos) | |
| : iterator_base(in_M, 0, initial_pos, 0) | | : iterator_base(in_M, 0, initial_pos, 0) | |
| , internal_row(0) | | , internal_row(0) | |
| , actual_pos(0) | | , actual_pos(0) | |
| { | | { | |
| // Corner case for empty subviews. | | // Corner case for empty subviews. | |
| if(in_M.n_nonzero == 0) | | if(in_M.n_nonzero == 0) | |
| { | | { | |
|
| iterator_base::internal_col = in_M.n_cols; | | iterator_base::internal_col = 0; | |
| | | internal_row = in_M.n_rows; | |
| iterator_base::skip_pos = in_M.m.n_nonzero; | | iterator_base::skip_pos = in_M.m.n_nonzero; | |
| return; | | return; | |
| } | | } | |
| | | | |
| const uword aux_col = iterator_base::M.aux_col1; | | const uword aux_col = iterator_base::M.aux_col1; | |
| const uword aux_row = iterator_base::M.aux_row1; | | const uword aux_row = iterator_base::M.aux_row1; | |
| const uword n_cols = iterator_base::M.n_cols; | | const uword n_cols = iterator_base::M.n_cols; | |
| | | | |
| // We don't know where the elements are in each row. What we will do is | | // We don't know where the elements are in each row. What we will do is | |
| // loop across all valid columns looking for elements in row 0 (and add t
o | | // loop across all valid columns looking for elements in row 0 (and add t
o | |
| | | | |
| skipping to change at line 500 | | skipping to change at line 586 | |
| // Out of columns. Loop back to the beginning and look on the next r
ow. | | // Out of columns. Loop back to the beginning and look on the next r
ow. | |
| cur_col = 0; | | cur_col = 0; | |
| cur_row++; | | cur_row++; | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>&
in_M, uword in_row, uword in_col) | | SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>&
in_M, uword in_row, uword in_col) | |
|
| : iterator_base(in_M, in_row, in_col, 0, 0) | | : iterator_base(in_M, in_col, 0, 0) | |
| , internal_row(0) | | , internal_row(0) | |
| , actual_pos(0) | | , actual_pos(0) | |
| { | | { | |
| // We have a destination we want to be just after, but don't know what th
at | | // We have a destination we want to be just after, but don't know what th
at | |
| // position is. Because we will have to loop over everything anyway, cre
ate | | // position is. Because we will have to loop over everything anyway, cre
ate | |
| // another iterator and loop it until it is at the right place, then take
its | | // another iterator and loop it until it is at the right place, then take
its | |
| // information. | | // information. | |
| const_row_iterator it(in_M, 0); | | const_row_iterator it(in_M, 0); | |
| while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col)
)) | | while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col)
)) | |
| { | | { | |
| | | | |
| skipping to change at line 524 | | skipping to change at line 610 | |
| iterator_base::internal_col = it.col(); | | iterator_base::internal_col = it.col(); | |
| iterator_base::internal_pos = it.pos(); | | iterator_base::internal_pos = it.pos(); | |
| iterator_base::skip_pos = it.skip_pos; | | iterator_base::skip_pos = it.skip_pos; | |
| internal_row = it.internal_row; | | internal_row = it.internal_row; | |
| actual_pos = it.actual_pos; | | actual_pos = it.actual_pos; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpSubview<eT>::const_row_iterator::const_row_iterator(const const_row_itera
tor& other) | | SpSubview<eT>::const_row_iterator::const_row_iterator(const const_row_itera
tor& other) | |
|
| : iterator_base(other) | | : iterator_base(other.M, other.internal_col, other.internal_pos, other.sk
ip_pos) | |
| , internal_row(other.internal_row) | | , internal_row(other.internal_row) | |
| , actual_pos(other.actual_pos) | | , actual_pos(other.actual_pos) | |
| { | | { | |
| // Nothing to do. | | // Nothing to do. | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::const_row_iterator& | | typename SpSubview<eT>::const_row_iterator& | |
| SpSubview<eT>::const_row_iterator::operator++() | | SpSubview<eT>::const_row_iterator::operator++() | |
| | | | |
| skipping to change at line 589 | | skipping to change at line 675 | |
| iterator_base::internal_col = cur_col; | | iterator_base::internal_col = cur_col; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::const_row_iterator | |
| SpSubview<eT>::const_row_iterator::operator++(int) | | SpSubview<eT>::const_row_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::const_row_iterator tmp(*this); | |
| | | | |
| ++(*this); | | ++(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::const_row_iterator& | | typename SpSubview<eT>::const_row_iterator& | |
| SpSubview<eT>::const_row_iterator::operator--() | | SpSubview<eT>::const_row_iterator::operator--() | |
| { | | { | |
| // We just need to find the previous element. | | // We just need to find the previous element. | |
| // if(iterator_base::pos == 0) | | // if(iterator_base::pos == 0) | |
| // { | | // { | |
| | | | |
| skipping to change at line 659 | | skipping to change at line 749 | |
| actual_pos = ind; | | actual_pos = ind; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::const_row_iterator | |
| SpSubview<eT>::const_row_iterator::operator--(int) | | SpSubview<eT>::const_row_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::const_row_iterator tmp(*this); | |
| | | | |
| --(*this); | | --(*this); | |
|
| | | | |
| | | return tmp; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator==(const const_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator!=(const const_iterator& rhs) co | |
| | | nst | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator==(const typename SpMat<eT>::con | |
| | | st_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator!=(const typename SpMat<eT>::con | |
| | | st_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator==(const const_row_iterator& rhs | |
| | | ) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator!=(const const_row_iterator& rhs | |
| | | ) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator==(const typename SpMat<eT>::con | |
| | | st_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col) | |
| | | ; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | SpSubview<eT>::const_row_iterator::operator!=(const typename SpMat<eT>::con | |
| | | st_row_iterator& rhs) const | |
| | | { | |
| | | return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col) | |
| | | ; | |
| } | | } | |
| | | | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| // SpSubview<eT>::row_iterator implementation
// | | // SpSubview<eT>::row_iterator implementation
// | |
| ///////////////////////////////////////////////////////////////////////////
//// | | ///////////////////////////////////////////////////////////////////////////
//// | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpValProxy<SpSubview<eT> > | | SpValProxy<SpSubview<eT> > | |
| SpSubview<eT>::row_iterator::operator*() | | SpSubview<eT>::row_iterator::operator*() | |
| | | | |
| skipping to change at line 692 | | skipping to change at line 850 | |
| inline | | inline | |
| typename SpSubview<eT>::row_iterator& | | typename SpSubview<eT>::row_iterator& | |
| SpSubview<eT>::row_iterator::operator++() | | SpSubview<eT>::row_iterator::operator++() | |
| { | | { | |
| const_row_iterator::operator++(); | | const_row_iterator::operator++(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::row_iterator | |
| SpSubview<eT>::row_iterator::operator++(int) | | SpSubview<eT>::row_iterator::operator++(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::row_iterator tmp(*this); | |
| | | | |
| ++(*this); | | ++(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::row_iterator& | | typename SpSubview<eT>::row_iterator& | |
| SpSubview<eT>::row_iterator::operator--() | | SpSubview<eT>::row_iterator::operator--() | |
| { | | { | |
| const_row_iterator::operator--(); | | const_row_iterator::operator--(); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| void | | typename SpSubview<eT>::row_iterator | |
| SpSubview<eT>::row_iterator::operator--(int) | | SpSubview<eT>::row_iterator::operator--(int) | |
| { | | { | |
|
| | | typename SpSubview<eT>::row_iterator tmp(*this); | |
| | | | |
| --(*this); | | --(*this); | |
|
| | | | |
| | | return tmp; | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 37 change blocks. |
| 48 lines changed or deleted | | 246 lines changed or added | |
|
| SpSubview_meat.hpp | | SpSubview_meat.hpp | |
| | | | |
| skipping to change at line 928 | | skipping to change at line 928 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| SpSubview<eT>::is_vec() const | | SpSubview<eT>::is_vec() const | |
| { | | { | |
| return ( (n_rows == 1) || (n_cols == 1) ); | | return ( (n_rows == 1) || (n_cols == 1) ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| | | SpSubview<eT> | |
| | | SpSubview<eT>::row(const uword row_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); | |
| | | | |
| | | return submat(row_num, 0, row_num, n_cols - 1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::row(const uword row_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); | |
| | | | |
| | | return submat(row_num, 0, row_num, n_cols - 1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::col(const uword col_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); | |
| | | | |
| | | return submat(0, col_num, n_rows - 1, col_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::col(const uword col_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); | |
| | | | |
| | | return submat(0, col_num, n_rows - 1, col_num); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::rows(const uword in_row1, const uword in_row2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| | | "SpSubview::rows(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(in_row1, 0, in_row2, n_cols - 1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::rows(const uword in_row1, const uword in_row2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| | | "SpSubview::rows(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(in_row1, 0, in_row2, n_cols - 1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::cols(const uword in_col1, const uword in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| | | "SpSubview::cols(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(0, in_col1, n_rows - 1, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::cols(const uword in_col1, const uword in_col2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| | | "SpSubview::cols(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(0, in_col1, n_rows - 1, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword | |
| | | in_row2, const uword in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i | |
| | | n_col2 >= n_cols), | |
| | | "SpSubview::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return access::rw(m).submat(in_row1 + aux_row1, in_col1 + aux_col1, in_ro | |
| | | w2 + aux_row1, in_col2 + aux_col1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword | |
| | | in_row2, const uword in_col2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i | |
| | | n_col2 >= n_cols), | |
| | | "SpSubview::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return m.submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row | |
| | | 1, in_col2 + aux_col1); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::submat(const span& row_span, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const bool row_all = row_span.whole; | |
| | | const bool col_all = row_span.whole; | |
| | | | |
| | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | const uword in_row2 = row_all ? n_rows : row_span.b; | |
| | | | |
| | | const uword in_col1 = col_all ? 0 : col_span.a; | |
| | | const uword in_col2 = col_all ? n_cols : col_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), | |
| | | "SpSubview::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(in_row1, in_col1, in_row2, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::submat(const span& row_span, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const bool row_all = row_span.whole; | |
| | | const bool col_all = row_span.whole; | |
| | | | |
| | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | const uword in_row2 = row_all ? n_rows - 1 : row_span.b; | |
| | | | |
| | | const uword in_col1 = col_all ? 0 : col_span.a; | |
| | | const uword in_col2 = col_all ? n_cols - 1 : col_span.b; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), | |
| | | "SpSubview::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return submat(in_row1, in_col1, in_row2, in_col2); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const uword row_num, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(span(row_num, row_num), col_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const uword row_num, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(span(row_num, row_num), col_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const span& row_span, const uword col_num) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(row_span, span(col_num, col_num)); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const span& row_span, const uword col_num) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(row_span, span(col_num, col_num)); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const span& row_span, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(row_span, col_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpSubview<eT>::operator()(const span& row_span, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(row_span, col_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| void | | void | |
| SpSubview<eT>::swap_rows(const uword in_row1, const uword in_row2) | | SpSubview<eT>::swap_rows(const uword in_row1, const uword in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview::
swap_rows(): invalid row index"); | | arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview::
swap_rows(): invalid row index"); | |
| | | | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col = aux_col1 + n_cols; | | const uword end_col = aux_col1 + n_cols; | |
| | | | |
| | | | |
| skipping to change at line 1001 | | skipping to change at line 1259 | |
| inline | | inline | |
| typename SpSubview<eT>::const_iterator | | typename SpSubview<eT>::const_iterator | |
| SpSubview<eT>::begin_col(const uword col_num) const | | SpSubview<eT>::begin_col(const uword col_num) const | |
| { | | { | |
| return const_iterator(*this, 0, col_num); | | return const_iterator(*this, 0, col_num); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::row_iterator | | typename SpSubview<eT>::row_iterator | |
|
| SpSubview<eT>::begin_row() | | SpSubview<eT>::begin_row(const uword row_num) | |
| { | | { | |
|
| return row_iterator(*this); | | return row_iterator(*this, row_num, 0); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::const_row_iterator | | typename SpSubview<eT>::const_row_iterator | |
|
| SpSubview<eT>::begin_row() const | | SpSubview<eT>::begin_row(const uword row_num) const | |
| { | | { | |
|
| return const_row_iterator(*this); | | return const_row_iterator(*this, row_num, 0); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::iterator | | typename SpSubview<eT>::iterator | |
| SpSubview<eT>::end() | | SpSubview<eT>::end() | |
| { | | { | |
| return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); | | return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1048 | | skipping to change at line 1306 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| typename SpSubview<eT>::const_row_iterator | | typename SpSubview<eT>::const_row_iterator | |
| SpSubview<eT>::end_row() const | | SpSubview<eT>::end_row() const | |
| { | | { | |
| return const_row_iterator(*this, n_nonzero); | | return const_row_iterator(*this, n_nonzero); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| | | typename SpSubview<eT>::row_iterator | |
| | | SpSubview<eT>::end_row(const uword row_num) | |
| | | { | |
| | | return row_iterator(*this, row_num + 1, 0); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | typename SpSubview<eT>::const_row_iterator | |
| | | SpSubview<eT>::end_row(const uword row_num) const | |
| | | { | |
| | | return const_row_iterator(*this, row_num + 1, 0); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| arma_hot | | arma_hot | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
| SpSubview<eT>::add_element(const uword in_row, const uword in_col, const eT
in_val) | | SpSubview<eT>::add_element(const uword in_row, const uword in_col, const eT
in_val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| // This may not actually add an element. | | // This may not actually add an element. | |
| const uword old_n_nonzero = m.n_nonzero; | | const uword old_n_nonzero = m.n_nonzero; | |
| eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_co
l1, in_val); | | eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_co
l1, in_val); | |
| | | | |
End of changes. 6 change blocks. |
| 4 lines changed or deleted | | 284 lines changed or added | |
|
| debug.hpp | | debug.hpp | |
| | | | |
| skipping to change at line 80 | | skipping to change at line 80 | |
| get_stream_err2() | | get_stream_err2() | |
| { | | { | |
| return arma_stream_err2<char>(NULL); | | return arma_stream_err2<char>(NULL); | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_stop | | // arma_stop | |
| | | | |
| //! print a message to get_stream_err1() and/or throw a logic_error excepti
on | | //! print a message to get_stream_err1() and/or throw a logic_error excepti
on | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_stop(const T1& x) | | arma_stop(const T1& x) | |
| { | | { | |
| #if defined(ARMA_PRINT_LOGIC_ERRORS) | | #if defined(ARMA_PRINT_LOGIC_ERRORS) | |
| { | | { | |
| std::ostream& out = get_stream_err1(); | | std::ostream& out = get_stream_err1(); | |
| | | | |
| out.flush(); | | out.flush(); | |
| | | | |
| out << '\n'; | | out << '\n'; | |
| out << "error: " << x << '\n'; | | out << "error: " << x << '\n'; | |
| | | | |
| skipping to change at line 106 | | skipping to change at line 106 | |
| #else | | #else | |
| { | | { | |
| arma_ignore(x); | | arma_ignore(x); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| throw std::logic_error(""); | | throw std::logic_error(""); | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_stop_bad_alloc(const T1& x) | | arma_stop_bad_alloc(const T1& x) | |
| { | | { | |
| std::ostream& out = get_stream_err1(); | | std::ostream& out = get_stream_err1(); | |
| | | | |
| out.flush(); | | out.flush(); | |
| | | | |
| out << '\n'; | | out << '\n'; | |
| out << "error: " << x << '\n'; | | out << "error: " << x << '\n'; | |
| out << '\n'; | | out << '\n'; | |
| out.flush(); | | out.flush(); | |
| | | | |
| throw std::bad_alloc(); | | throw std::bad_alloc(); | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_bad | | // arma_bad | |
| | | | |
| //! print a message to get_stream_err2() and/or throw a run-time error exce
ption | | //! print a message to get_stream_err2() and/or throw a run-time error exce
ption | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_bad(const T1& x, const bool hurl = true) | | arma_bad(const T1& x, const bool hurl = true) | |
| { | | { | |
| #if defined(ARMA_PRINT_RUNTIME_ERRORS) | | #if defined(ARMA_PRINT_RUNTIME_ERRORS) | |
| { | | { | |
| std::ostream& out = get_stream_err2(); | | std::ostream& out = get_stream_err2(); | |
| | | | |
| out.flush(); | | out.flush(); | |
| | | | |
| out << '\n'; | | out << '\n'; | |
| out << "error: " << x << '\n'; | | out << "error: " << x << '\n'; | |
| | | | |
| skipping to change at line 159 | | skipping to change at line 159 | |
| | | | |
| if(hurl == true) | | if(hurl == true) | |
| { | | { | |
| throw std::runtime_error(""); | | throw std::runtime_error(""); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_print | | // arma_print | |
| | | | |
|
| | | arma_cold | |
| inline | | inline | |
| void | | void | |
|
| arma_cold | | | |
| arma_print() | | arma_print() | |
| { | | { | |
| get_stream_err1() << std::endl; | | get_stream_err1() << std::endl; | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_print(const T1& x) | | arma_print(const T1& x) | |
| { | | { | |
| get_stream_err1() << x << std::endl; | | get_stream_err1() << x << std::endl; | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_print(const T1& x, const T2& y) | | arma_print(const T1& x, const T2& y) | |
| { | | { | |
| get_stream_err1() << x << y << std::endl; | | get_stream_err1() << x << y << std::endl; | |
| } | | } | |
| | | | |
| template<typename T1, typename T2, typename T3> | | template<typename T1, typename T2, typename T3> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_print(const T1& x, const T2& y, const T3& z) | | arma_print(const T1& x, const T2& y, const T3& z) | |
| { | | { | |
| get_stream_err1() << x << y << z << std::endl; | | get_stream_err1() << x << y << z << std::endl; | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_sigprint | | // arma_sigprint | |
| | | | |
| //! print a message the the log stream with a preceding @ character. | | //! print a message the the log stream with a preceding @ character. | |
| //! by default the log stream is cout. | | //! by default the log stream is cout. | |
| | | | |
| skipping to change at line 249 | | skipping to change at line 249 | |
| arma_thisprint(const void* this_ptr) | | arma_thisprint(const void* this_ptr) | |
| { | | { | |
| get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; | | get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_warn | | // arma_warn | |
| | | | |
| //! print a message to the warn stream | | //! print a message to the warn stream | |
| template<typename T1> | | template<typename T1> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_warn(const bool state, const T1& x) | | arma_warn(const bool state, const T1& x) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| get_stream_err2() << x << std::endl; | | get_stream_err2() << x << std::endl; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_warn(const bool state, const T1& x, const T2& y) | | arma_warn(const bool state, const T1& x, const T2& y) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| get_stream_err2() << x << y << std::endl; | | get_stream_err2() << x << y << std::endl; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1, typename T2, typename T3> | | template<typename T1, typename T2, typename T3> | |
|
| inline | | | |
| void | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | void | |
| arma_warn(const bool state, const T1& x, const T2& y, const T3& z) | | arma_warn(const bool state, const T1& x, const T2& y, const T3& z) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| get_stream_err2() << x << y << z << std::endl; | | get_stream_err2() << x << y << z << std::endl; | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_check | | // arma_check | |
| | | | |
| //! if state is true, abort program | | //! if state is true, abort program | |
| template<typename T1> | | template<typename T1> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_check(const bool state, const T1& x) | | arma_check(const bool state, const T1& x) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| arma_stop(arma_boost::str_wrapper(x)); | | arma_stop(arma_boost::str_wrapper(x)); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_check(const bool state, const T1& x, const T2& y) | | arma_check(const bool state, const T1& x, const T2& y) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| arma_stop( std::string(x) + std::string(y) ); | | arma_stop( std::string(x) + std::string(y) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_check_bad_alloc(const bool state, const T1& x) | | arma_check_bad_alloc(const bool state, const T1& x) | |
| { | | { | |
| if(state==true) | | if(state==true) | |
| { | | { | |
| arma_stop_bad_alloc(x); | | arma_stop_bad_alloc(x); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_set_error | | // arma_set_error | |
| | | | |
|
| | | arma_hot | |
| arma_inline | | arma_inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_set_error(bool& err_state, char*& err_msg, const bool expression, cons
t char* message) | | arma_set_error(bool& err_state, char*& err_msg, const bool expression, cons
t char* message) | |
| { | | { | |
| if(expression == true) | | if(expression == true) | |
| { | | { | |
| err_state = true; | | err_state = true; | |
| err_msg = const_cast<char*>(message); | | err_msg = const_cast<char*>(message); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // functions for generating strings indicating size errors | | // functions for generating strings indicating size errors | |
| | | | |
|
| inline | | | |
| std::string | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| | | std::string | |
| arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const
uword B_n_rows, const uword B_n_cols, const char* x) | | arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const
uword B_n_rows, const uword B_n_cols, const char* x) | |
| { | | { | |
| std::stringstream tmp; | | std::stringstream tmp; | |
| | | | |
| tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_
n_cols << " and " << B_n_rows << 'x' << B_n_cols; | | tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_
n_cols << " and " << B_n_rows << 'x' << B_n_cols; | |
| | | | |
| return tmp.str(); | | return tmp.str(); | |
| } | | } | |
| | | | |
|
| inline | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| std::string | | std::string | |
| arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const
uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword
B_n_slices, const char* x) | | arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const
uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword
B_n_slices, const char* x) | |
| { | | { | |
| std::stringstream tmp; | | std::stringstream tmp; | |
| | | | |
| tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_
cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x'
<< B_n_slices; | | tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_
cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x'
<< B_n_slices; | |
| | | | |
| return tmp.str(); | | return tmp.str(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| inline | | | |
| arma_cold | | arma_cold | |
|
| | | static | |
| std::string | | std::string | |
| arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, cons
t char* x) | | arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, cons
t char* x) | |
| { | | { | |
| std::stringstream tmp; | | std::stringstream tmp; | |
| | | | |
| tmp << x | | tmp << x | |
| << ": interpreting matrix as cube with dimenensions: " | | << ": interpreting matrix as cube with dimenensions: " | |
| << A.n_rows << 'x' << A.n_cols << 'x' << 1 | | << A.n_rows << 'x' << A.n_cols << 'x' << 1 | |
| << " or " | | << " or " | |
| << A.n_rows << 'x' << 1 << 'x' << A.n_cols | | << A.n_rows << 'x' << 1 << 'x' << A.n_cols | |
| | | | |
| skipping to change at line 403 | | skipping to change at line 403 | |
| arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo
rd B_n_rows, const uword B_n_cols, const char* x) | | arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo
rd B_n_rows, const uword B_n_cols, const char* x) | |
| { | | { | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given matrices have different sizes | | //! stop if given matrices have different sizes | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) | | arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given proxies have different sizes | | //! stop if given proxies have different sizes | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char*
x) | | arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char*
x) | |
| { | | { | |
| const uword A_n_rows = A.get_n_rows(); | | const uword A_n_rows = A.get_n_rows(); | |
| const uword A_n_cols = A.get_n_cols(); | | const uword A_n_cols = A.get_n_cols(); | |
| | | | |
| const uword B_n_rows = B.get_n_rows(); | | const uword B_n_rows = B.get_n_rows(); | |
| const uword B_n_cols = B.get_n_cols(); | | const uword B_n_cols = B.get_n_cols(); | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c
har* x) | | arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c
har* x) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char*
x) | | arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char*
x) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char*
x) | | arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char*
x) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x
) | | arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x
) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.get_n_rows(); | | const uword B_n_rows = B.get_n_rows(); | |
| const uword B_n_cols = B.get_n_cols(); | | const uword B_n_cols = B.get_n_cols(); | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x
) | | arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x
) | |
| { | | { | |
| const uword A_n_rows = A.get_n_rows(); | | const uword A_n_rows = A.get_n_rows(); | |
| const uword A_n_cols = A.get_n_cols(); | | const uword A_n_cols = A.get_n_cols(); | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const cha
r* x) | | arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const cha
r* x) | |
| { | | { | |
| const uword A_n_rows = A.get_n_rows(); | | const uword A_n_rows = A.get_n_rows(); | |
| const uword A_n_cols = A.get_n_cols(); | | const uword A_n_cols = A.get_n_cols(); | |
| | | | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| const uword B_n_cols = B.n_cols; | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const cha
r* x) | | arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const cha
r* x) | |
| { | | { | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| | | | |
| const uword B_n_rows = B.get_n_rows(); | | const uword B_n_rows = B.get_n_rows(); | |
| const uword B_n_cols = B.get_n_cols(); | | const uword B_n_cols = B.get_n_cols(); | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // functions for checking whether two cubes have the same dimensions | | // functions for checking whether two cubes have the same dimensions | |
| | | | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo
rd A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_
slices, const char* x) | | arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo
rd A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_
slices, const char* x) | |
| { | | { | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices) ) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given cubes have different sizes | | //! stop if given cubes have different sizes | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x
) | | arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x
) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const
char* x) | | arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const
char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const
char* x) | | arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const
char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices) ) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>&
B, const char* x) | | arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>&
B, const char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices)) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.
n_slices)) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given cube proxies have different sizes | | //! stop if given cube proxies have different sizes | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, con
st char* x) | | arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, con
st char* x) | |
| { | | { | |
| const uword A_n_rows = A.get_n_rows(); | | const uword A_n_rows = A.get_n_rows(); | |
| const uword A_n_cols = A.get_n_cols(); | | const uword A_n_cols = A.get_n_cols(); | |
| const uword A_n_slices = A.get_n_slices(); | | const uword A_n_slices = A.get_n_slices(); | |
| | | | |
| const uword B_n_rows = B.get_n_rows(); | | const uword B_n_rows = B.get_n_rows(); | |
| const uword B_n_cols = B.get_n_cols(); | | const uword B_n_cols = B.get_n_cols(); | |
| const uword B_n_slices = B.get_n_slices(); | | const uword B_n_slices = B.get_n_slices(); | |
| | | | |
| if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices)) | | if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_
n_slices)) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_
n_rows, B_n_cols, B_n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // functions for checking whether a cube or subcube can be interpreted as a
matrix (i.e. single slice) | | // functions for checking whether a cube or subcube can be interpreted as a
matrix (i.e. single slice) | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x) | | arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1)
) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1)
) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, 1, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, 1, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x) | | arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const
char* x) | | arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const
char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1)
) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1)
) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, 1, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
n_rows, B.n_cols, 1, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const
char* x) | | arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const
char* x) | |
| { | | { | |
| if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | | if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices)
) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
.n_cols, B.n_slices, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT, typename T1> | | template<typename eT, typename T1> | |
| inline | | inline | |
| | | | |
| skipping to change at line 850 | | skipping to change at line 850 | |
| arma_stop( tmp.str() ); | | arma_stop( tmp.str() ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // functions for checking whether two matrices have dimensions that are com
patible with the matrix multiply operation | | // functions for checking whether two matrices have dimensions that are com
patible with the matrix multiply operation | |
| | | | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uwor
d B_n_rows, const uword B_n_cols, const char* x) | | arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uwor
d B_n_rows, const uword B_n_cols, const char* x) | |
| { | | { | |
| if(A_n_cols != B_n_rows) | | if(A_n_cols != B_n_rows) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given matrices are incompatible for multiplication | | //! stop if given matrices are incompatible for multiplication | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) | | arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) | |
| { | | { | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| const uword B_n_rows = B.n_rows; | | const uword B_n_rows = B.n_rows; | |
| | | | |
| if(A_n_cols != B_n_rows) | | if(A_n_cols != B_n_rows) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| //! stop if given matrices are incompatible for multiplication | | //! stop if given matrices are incompatible for multiplication | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const bool do_tr
ans_A, const bool do_trans_B, const char* x) | | arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const bool do_tr
ans_A, const bool do_trans_B, const char* x) | |
| { | | { | |
| const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; | | const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; | |
| const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; | | const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; | |
| | | | |
| if(final_A_n_cols != final_B_n_rows) | | if(final_A_n_cols != final_B_n_rows) | |
| { | | { | |
| const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_col
s; | | const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_col
s; | |
| const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_row
s; | | const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_row
s; | |
| | | | |
| arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, fi
nal_B_n_rows, final_B_n_cols, x) ); | | arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, fi
nal_B_n_rows, final_B_n_cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char*
x) | | arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char*
x) | |
| { | | { | |
| if(A.n_cols != B.n_rows) | | if(A.n_cols != B.n_rows) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char*
x) | | arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char*
x) | |
| { | | { | |
| if(A.n_cols != B.n_rows) | | if(A.n_cols != B.n_rows) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT1, typename eT2> | | template<typename eT1, typename eT2> | |
|
| | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| arma_hot | | | |
| arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const ch
ar* x) | | arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const ch
ar* x) | |
| { | | { | |
| if(A.n_cols != B.n_rows) | | if(A.n_cols != B.n_rows) | |
| { | | { | |
| arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | | arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
cols, x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // macros | | // macros | |
| | | | |
| skipping to change at line 1002 | | skipping to change at line 1002 | |
| | | | |
| #if defined(ARMA_EXTRA_DEBUG) | | #if defined(ARMA_EXTRA_DEBUG) | |
| | | | |
| namespace junk | | namespace junk | |
| { | | { | |
| class arma_first_extra_debug_message | | class arma_first_extra_debug_message | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline | | inline | |
|
| arma_cold | | | |
| arma_first_extra_debug_message() | | arma_first_extra_debug_message() | |
| { | | { | |
| union | | union | |
| { | | { | |
| unsigned short a; | | unsigned short a; | |
| unsigned char b[sizeof(unsigned short)]; | | unsigned char b[sizeof(unsigned short)]; | |
| } endian_test; | | } endian_test; | |
| | | | |
| endian_test.a = 1; | | endian_test.a = 1; | |
| | | | |
| | | | |
End of changes. 85 change blocks. |
| 53 lines changed or deleted | | 52 lines changed or added | |
|
| diskio_bones.hpp | | diskio_bones.hpp | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2012 Conrad Sanderson | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
|
| // Copyright (C) 2012 Matthew Amidon | | | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // 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) | |
| | | | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 25 | |
| //! @{ | | //! @{ | |
| | | | |
| //! class for saving and loading matrices and fields | | //! class for saving and loading matrices and fields | |
| class diskio | | class diskio | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename eT> inline static std::string gen_txt_header(const Mat<
eT>& x); | | template<typename eT> inline static std::string gen_txt_header(const Mat<
eT>& x); | |
| template<typename eT> inline static std::string gen_bin_header(const Mat<
eT>& x); | | template<typename eT> inline static std::string gen_bin_header(const Mat<
eT>& x); | |
| | | | |
|
| template<typename eT> inline static std::string gen_txt_header(const SpMa
t<eT>& x); | | | |
| template<typename eT> inline static std::string gen_bin_header(const SpMa
t<eT>& x); | | template<typename eT> inline static std::string gen_bin_header(const SpMa
t<eT>& x); | |
| | | | |
| template<typename eT> inline static std::string gen_txt_header(const Cube
<eT>& x); | | template<typename eT> inline static std::string gen_txt_header(const Cube
<eT>& x); | |
| template<typename eT> inline static std::string gen_bin_header(const Cube
<eT>& x); | | template<typename eT> inline static std::string gen_bin_header(const Cube
<eT>& x); | |
| | | | |
| inline static file_type guess_file_type(std::istream& f); | | inline static file_type guess_file_type(std::istream& f); | |
| | | | |
| inline static char conv_to_hex_char(const u8 x); | | inline static char conv_to_hex_char(const u8 x); | |
| inline static void conv_to_hex(char* out, const u8 x); | | inline static void conv_to_hex(char* out, const u8 x); | |
| | | | |
| inline static std::string gen_tmp_name(const std::string& x); | | inline static std::string gen_tmp_name(const std::string& x); | |
| | | | |
| inline static bool safe_rename(const std::string& old_name, const std::st
ring& new_name); | | inline static bool safe_rename(const std::string& old_name, const std::st
ring& new_name); | |
| | | | |
|
| | | template<typename eT> inline static bool convert_naninf(eT& | |
| | | val, const std::string& token); | |
| | | template<typename T> inline static bool convert_naninf(std::complex<T>& | |
| | | val, const std::string& token); | |
| | | | |
| // | | // | |
| // matrix saving | | // matrix saving | |
| | | | |
| template<typename eT> inline static bool save_raw_ascii (const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_raw_ascii (const Mat<eT>&
x, const std::string& final_name); | |
| template<typename eT> inline static bool save_raw_binary (const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_raw_binary (const Mat<eT>&
x, const std::string& final_name); | |
| template<typename eT> inline static bool save_arma_ascii (const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_arma_ascii (const Mat<eT>&
x, const std::string& final_name); | |
| template<typename eT> inline static bool save_csv_ascii (const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_csv_ascii (const Mat<eT>&
x, const std::string& final_name); | |
| template<typename eT> inline static bool save_arma_binary(const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_arma_binary(const Mat<eT>&
x, const std::string& final_name); | |
| template<typename eT> inline static bool save_pgm_binary (const Mat<eT>&
x, const std::string& final_name); | | template<typename eT> inline static bool save_pgm_binary (const Mat<eT>&
x, const std::string& final_name); | |
| template<typename T> inline static bool save_pgm_binary (const Mat< std:
:complex<T> >& x, const std::string& final_name); | | template<typename T> inline static bool save_pgm_binary (const Mat< std:
:complex<T> >& x, const std::string& final_name); | |
| | | | |
| skipping to change at line 86 | | skipping to change at line 87 | |
| template<typename eT> inline static bool load_arma_ascii (Mat<eT>&
x, std::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_arma_ascii (Mat<eT>&
x, std::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_csv_ascii (Mat<eT>&
x, std::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_csv_ascii (Mat<eT>&
x, std::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_binary(Mat<eT>&
x, std::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_arma_binary(Mat<eT>&
x, std::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_pgm_binary (Mat<eT>&
x, std::istream& is, std::string& err_msg); | | template<typename eT> inline static bool load_pgm_binary (Mat<eT>&
x, std::istream& is, std::string& err_msg); | |
| template<typename T> inline static bool load_pgm_binary (Mat< std::compl
ex<T> >& x, std::istream& is, std::string& err_msg); | | template<typename T> inline static bool load_pgm_binary (Mat< std::compl
ex<T> >& x, std::istream& is, std::string& err_msg); | |
| template<typename eT> inline static bool load_auto_detect(Mat<eT>&
x, std::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_auto_detect(Mat<eT>&
x, std::istream& f, std::string& err_msg); | |
| | | | |
| inline static void pnm_skip_comments(std::istream& f); | | inline static void pnm_skip_comments(std::istream& f); | |
| | | | |
| // | | // | |
|
| // sparse saving | | // sparse matrix saving | |
| | | | |
|
| template<typename eT> inline static bool save_raw_ascii (const SpMat<eT> | | | |
| & x, const std::string& final_name); | | | |
| //template<typename eT> inline static bool save_raw_binary (const SpMat<e | | | |
| T>& x, const std::string& final_name); | | | |
| //template<typename eT> inline static bool save_arma_ascii (const SpMat<e | | | |
| T>& x, const std::string& final_name); | | | |
| //template<typename eT> inline static bool save_csv_ascii (const SpMat<e | | | |
| T>& x, const std::string& final_name); | | | |
| template<typename eT> inline static bool save_arma_binary(const SpMat<eT> | | | |
| & x, const std::string& final_name); | | | |
| //template<typename eT> inline static bool save_pgm_binary (const SpMat<e | | | |
| T>& x, const std::string& final_name); | | | |
| //template<typename T> inline static bool save_pgm_binary (const SpMat<s | | | |
| td::complex<T> >& x, const std::string& final_name); | | | |
| template<typename eT> inline static bool save_coord_ascii(const SpMat<eT>
& x, const std::string& final_name); | | template<typename eT> inline static bool save_coord_ascii(const SpMat<eT>
& x, const std::string& final_name); | |
|
| | | template<typename eT> inline static bool save_arma_binary(const SpMat<eT>
& x, const std::string& final_name); | |
| | | | |
|
| template<typename eT> inline static bool save_raw_ascii (const SpMat<eT> | | template<typename eT> inline static bool save_coord_ascii(const SpMat<eT> | |
| & x, std::ostream& f); | | & x, std::ostream& f); | |
| //template<typename eT> inline static bool save_raw_binary (const SpMat<e | | template<typename T> inline static bool save_coord_ascii(const SpMat< st | |
| T>& x, std::ostream& f); | | d::complex<T> >& x, std::ostream& f); | |
| //template<typename eT> inline static bool save_arma_ascii (const SpMat<e | | template<typename eT> inline static bool save_arma_binary(const SpMat<eT> | |
| T>& x, std::ostream& f); | | & x, std::ostream& f); | |
| //template<typename eT> inline static bool save_csv_ascii (const SpMat<e | | | |
| T>& x, std::ostream& f); | | | |
| template<typename eT> inline static bool save_arma_binary(const SpMat<eT> | | | |
| & x, std::ostream& f); | | | |
| //template<typename eT> inline static bool save_pgm_binary (const SpMat<e | | | |
| T>& x, std::ostream& f); | | | |
| //template<typename T> inline static bool save_pgm_binary (const SpMat<s | | | |
| td::complex<T> >& x, std::ostream& f); | | | |
| template<typename eT> inline static bool save_coord_ascii(const SpMat<eT> | | | |
| & x, std::ostream& f); | | | |
| | | | |
| // | | // | |
|
| // sparse loading | | // sparse matrix loading | |
| | | | |
|
| template<typename eT> inline static bool load_raw_ascii (SpMat<eT>& x, c | | | |
| onst std::string& name, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_raw_binary (SpMat<eT>& x, | | | |
| const std::string& name, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_arma_ascii (SpMat<eT>& x, | | | |
| const std::string& name, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_csv_ascii (SpMat<eT>& x, | | | |
| const std::string& name, std::string& err_msg); | | | |
| template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, c | | | |
| onst std::string& name, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_pgm_binary (SpMat<eT>& x, | | | |
| const std::string& name, std::string& err_msg); | | | |
| //template<typename T> inline static bool load_pgm_binary (SpMat<std::co | | | |
| mplex<T> >& x, const std::string& name, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_auto_detect(SpMat<eT>& x, | | | |
| const std::string& name, std::string& err_msg); | | | |
| template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, c
onst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, c
onst std::string& name, std::string& err_msg); | |
|
| | | template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, c
onst std::string& name, std::string& err_msg); | |
| | | | |
|
| template<typename eT> inline static bool load_raw_ascii (SpMat<eT>& x, s | | template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, | |
| td::istream& f, std::string& err_msg); | | std::istream& f, std::string& err_msg); | |
| //template<typename eT> inline static bool load_raw_binary (SpMat<eT>& x, | | template<typename T> inline static bool load_coord_ascii(SpMat< std::com | |
| std::istream& f, std::string& err_msg); | | plex<T> >& x, std::istream& f, std::string& err_msg); | |
| //template<typename eT> inline static bool load_arma_ascii (SpMat<eT>& x, | | template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, | |
| std::istream& f, std::string& err_msg); | | std::istream& f, std::string& err_msg); | |
| //template<typename eT> inline static bool load_csv_ascii (SpMat<eT>& x, | | | |
| std::istream& f, std::string& err_msg); | | | |
| template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, s | | | |
| td::istream& f, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_pgm_binary (SpMat<eT>& x, | | | |
| std::istream& is, std::string& err_msg); | | | |
| //template<typename T> inline static bool load_pgm_binary (SpMat<std::co | | | |
| mplex<T> >& x, std::istream& is, std::string& err_msg); | | | |
| //template<typename eT> inline static bool load_auto_detect(SpMat<eT>& x, | | | |
| std::istream& f, std::string& err_msg); | | | |
| template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, s | | | |
| td::istream& f, std::string& err_msg); | | | |
| | | | |
| // | | // | |
| // cube saving | | // cube saving | |
| | | | |
| template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, const std::string& name); | |
| | | | |
| template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, std::ostream& f); | | template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, std::ostream& f); | |
| | | | |
End of changes. 11 change blocks. |
| 68 lines changed or deleted | | 21 lines changed or added | |
|
| diskio_meat.hpp | | diskio_meat.hpp | |
| | | | |
| skipping to change at line 182 | | skipping to change at line 182 | |
| { | | { | |
| return std::string("ARMA_MAT_BIN_FC016"); | | return std::string("ARMA_MAT_BIN_FC016"); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return std::string(); | | return std::string(); | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
|
| //! Generate the first line of the header used for saving matrices in text | | | |
| format. | | | |
| //! Format: "ARMA_SPM_TXT_ABXYZ". | | | |
| //! A is one of: I (for integral types) or F (for floating point types). | | | |
| //! B is one of: U (for unsigned types), S (for signed types), N (for not a | | | |
| ppliable) or C (for complex types). | | | |
| //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i | | | |
| ndicates eight bytes. | | | |
| template<typename eT> | | | |
| inline | | | |
| std::string | | | |
| diskio::gen_txt_header(const SpMat<eT>& x) | | | |
| { | | | |
| arma_type_check(( is_supported_elem_type<eT>::value == false )); | | | |
| | | | |
| arma_ignore(x); | | | |
| | | | |
| if(is_u8<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IU001"); | | | |
| } | | | |
| else | | | |
| if(is_s8<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IS001"); | | | |
| } | | | |
| else | | | |
| if(is_u16<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IU002"); | | | |
| } | | | |
| else | | | |
| if(is_s16<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IS002"); | | | |
| } | | | |
| else | | | |
| if(is_u32<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IU004"); | | | |
| } | | | |
| else | | | |
| if(is_s32<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IS004"); | | | |
| } | | | |
| #if defined(ARMA_64BIT_WORD) | | | |
| else | | | |
| if(is_u64<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IU008"); | | | |
| } | | | |
| else | | | |
| if(is_s64<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_IS008"); | | | |
| } | | | |
| #endif | | | |
| else | | | |
| if(is_float<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_FN004"); | | | |
| } | | | |
| else | | | |
| if(is_double<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_FN008"); | | | |
| } | | | |
| else | | | |
| if(is_complex_float<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_FC008"); | | | |
| } | | | |
| else | | | |
| if(is_complex_double<eT>::value == true) | | | |
| { | | | |
| return std::string("ARMA_SPM_TXT_FC016"); | | | |
| } | | | |
| else | | | |
| { | | | |
| return std::string(); | | | |
| } | | | |
| } | | | |
| | | | |
| //! Generate the first line of the header used for saving matrices in binar
y format. | | //! Generate the first line of the header used for saving matrices in binar
y format. | |
| //! Format: "ARMA_SPM_BIN_ABXYZ". | | //! Format: "ARMA_SPM_BIN_ABXYZ". | |
| //! A is one of: I (for integral types) or F (for floating point types). | | //! A is one of: I (for integral types) or F (for floating point types). | |
| //! B is one of: U (for unsigned types), S (for signed types), N (for not a
ppliable) or C (for complex types). | | //! B is one of: U (for unsigned types), S (for signed types), N (for not a
ppliable) or C (for complex types). | |
| //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i
ndicates eight bytes. | | //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i
ndicates eight bytes. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| std::string | | std::string | |
| diskio::gen_bin_header(const SpMat<eT>& x) | | diskio::gen_bin_header(const SpMat<eT>& x) | |
| { | | { | |
| | | | |
| skipping to change at line 541 | | skipping to change at line 460 | |
| unsigned char* ptr = data.memptr(); | | unsigned char* ptr = data.memptr(); | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) ); | | f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) ); | |
| | | | |
| const bool load_okay = f.good(); | | const bool load_okay = f.good(); | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
|
| bool has_binary = false; | | bool has_binary = false; | |
| bool has_comma = false; | | bool has_comma = false; | |
| | | bool has_bracket = false; | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
| uword i = 0; | | uword i = 0; | |
| uword j = (N >= 2) ? 1 : 0; | | uword j = (N >= 2) ? 1 : 0; | |
| | | | |
| for(; j<N; i+=2, j+=2) | | for(; j<N; i+=2, j+=2) | |
| { | | { | |
| const unsigned char val_i = ptr[i]; | | const unsigned char val_i = ptr[i]; | |
| const unsigned char val_j = ptr[j]; | | const unsigned char val_j = ptr[j]; | |
| | | | |
| skipping to change at line 564 | | skipping to change at line 484 | |
| // the range checking can be made more elaborate | | // the range checking can be made more elaborate | |
| if( ((val_i <= 8) || (val_i >= 123)) || ((val_j <= 8) || (val_j >= 12
3)) ) | | if( ((val_i <= 8) || (val_i >= 123)) || ((val_j <= 8) || (val_j >= 12
3)) ) | |
| { | | { | |
| has_binary = true; | | has_binary = true; | |
| break; | | break; | |
| } | | } | |
| | | | |
| if( (val_i == ',') || (val_j == ',') ) | | if( (val_i == ',') || (val_j == ',') ) | |
| { | | { | |
| has_comma = true; | | has_comma = true; | |
|
| break; | | } | |
| | | | |
| | | if( (val_i == '(') || (val_j == '(') || (val_i == ')') || (val_j == ' | |
| | | )') ) | |
| | | { | |
| | | has_bracket = true; | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| return file_type_unknown; | | return file_type_unknown; | |
| } | | } | |
| | | | |
| if(has_binary) | | if(has_binary) | |
| { | | { | |
| return raw_binary; | | return raw_binary; | |
| } | | } | |
| | | | |
|
| if(has_comma) | | if(has_comma && (has_bracket == false)) | |
| { | | { | |
| return csv_ascii; | | return csv_ascii; | |
| } | | } | |
| | | | |
| return raw_ascii; | | return raw_ascii; | |
| } | | } | |
| | | | |
| inline | | inline | |
| char | | char | |
| diskio::conv_to_hex_char(const u8 x) | | diskio::conv_to_hex_char(const u8 x) | |
| | | | |
| skipping to change at line 716 | | skipping to change at line 640 | |
| std::remove(new_name.c_str()); | | std::remove(new_name.c_str()); | |
| | | | |
| const int mv_result = std::rename(old_name.c_str(), new_name.c_str()); | | const int mv_result = std::rename(old_name.c_str(), new_name.c_str()); | |
| | | | |
| save_okay = (mv_result == 0); | | save_okay = (mv_result == 0); | |
| } | | } | |
| | | | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | diskio::convert_naninf(eT& val, const std::string& token) | |
| | | { | |
| | | // see if the token represents a NaN or Inf | |
| | | | |
| | | if( (token.length() == 3) || (token.length() == 4) ) | |
| | | { | |
| | | const bool neg = (token[0] == '-'); | |
| | | const bool pos = (token[0] == '+'); | |
| | | | |
| | | const size_t offset = ( (neg || pos) && (token.length() == 4) ) ? 1 : 0 | |
| | | ; | |
| | | | |
| | | const std::string token2 = token.substr(offset, 3); | |
| | | | |
| | | if( (token2 == "inf") || (token2 == "Inf") || (token2 == "INF") ) | |
| | | { | |
| | | val = neg ? -(Datum<eT>::inf) : Datum<eT>::inf; | |
| | | | |
| | | return true; | |
| | | } | |
| | | else | |
| | | if( (token2 == "nan") || (token2 == "Nan") || (token2 == "NaN") || (tok | |
| | | en2 == "NAN") ) | |
| | | { | |
| | | val = neg ? -(Datum<eT>::nan) : Datum<eT>::nan; | |
| | | | |
| | | return true; | |
| | | } | |
| | | } | |
| | | | |
| | | return false; | |
| | | } | |
| | | | |
| | | template<typename T> | |
| | | inline | |
| | | bool | |
| | | diskio::convert_naninf(std::complex<T>& val, const std::string& token) | |
| | | { | |
| | | if( token.length() >= 5 ) | |
| | | { | |
| | | std::stringstream ss( token.substr(1, token.length()-2) ); // strip '( | |
| | | ' at the start and ')' at the end | |
| | | | |
| | | std::string token_real; | |
| | | std::string token_imag; | |
| | | | |
| | | std::getline(ss, token_real, ','); | |
| | | std::getline(ss, token_imag); | |
| | | | |
| | | std::stringstream ss_real(token_real); | |
| | | std::stringstream ss_imag(token_imag); | |
| | | | |
| | | T val_real = T(0); | |
| | | T val_imag = T(0); | |
| | | | |
| | | ss_real >> val_real; | |
| | | ss_imag >> val_imag; | |
| | | | |
| | | bool success_real = true; | |
| | | bool success_imag = true; | |
| | | | |
| | | if(ss_real.fail() == true) | |
| | | { | |
| | | success_real = diskio::convert_naninf( val_real, token_real ); | |
| | | } | |
| | | | |
| | | if(ss_imag.fail() == true) | |
| | | { | |
| | | success_imag = diskio::convert_naninf( val_imag, token_imag ); | |
| | | } | |
| | | | |
| | | val = std::complex<T>(val_real, val_imag); | |
| | | | |
| | | return (success_real && success_imag); | |
| | | } | |
| | | | |
| | | return false; | |
| | | } | |
| | | | |
| //! Save a matrix as raw text (no header, human readable). | | //! Save a matrix as raw text (no header, human readable). | |
| //! Matrices can be loaded in Matlab and Octave, as long as they don't have
complex elements. | | //! Matrices can be loaded in Matlab and Octave, as long as they don't have
complex elements. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_raw_ascii(const Mat<eT>& x, const std::string& final_name) | | diskio::save_raw_ascii(const Mat<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | | |
| skipping to change at line 1240 | | skipping to change at line 1243 | |
| // work out the size | | // work out the size | |
| | | | |
| uword f_n_rows = 0; | | uword f_n_rows = 0; | |
| uword f_n_cols = 0; | | uword f_n_cols = 0; | |
| | | | |
| bool f_n_cols_found = false; | | bool f_n_cols_found = false; | |
| | | | |
| std::string line_string; | | std::string line_string; | |
| std::string token; | | std::string token; | |
| | | | |
|
| | | std::stringstream line_stream; | |
| | | | |
| while( (f.good() == true) && (load_okay == true) ) | | while( (f.good() == true) && (load_okay == true) ) | |
| { | | { | |
| std::getline(f, line_string); | | std::getline(f, line_string); | |
| | | | |
| if(line_string.size() == 0) | | if(line_string.size() == 0) | |
| { | | { | |
| break; | | break; | |
| } | | } | |
| | | | |
|
| std::stringstream line_stream(line_string); | | line_stream.clear(); | |
| | | line_stream.str(line_string); | |
| | | | |
| uword line_n_cols = 0; | | uword line_n_cols = 0; | |
| | | | |
| while (line_stream >> token) | | while (line_stream >> token) | |
| { | | { | |
| ++line_n_cols; | | ++line_n_cols; | |
| } | | } | |
| | | | |
| if(f_n_cols_found == false) | | if(f_n_cols_found == false) | |
| { | | { | |
| | | | |
| skipping to change at line 1282 | | skipping to change at line 1288 | |
| ++f_n_rows; | | ++f_n_rows; | |
| } | | } | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| x.set_size(f_n_rows, f_n_cols); | | x.set_size(f_n_rows, f_n_cols); | |
| | | | |
|
| eT val; | | std::stringstream ss; | |
| | | | |
| for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) | | for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) | |
| { | | { | |
| for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) | | for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) | |
| { | | { | |
|
| f >> val; | | f >> token; | |
| | | | |
|
| if(f.fail() == false) | | ss.clear(); | |
| | | ss.str(token); | |
| | | | |
| | | eT val = eT(0); | |
| | | ss >> val; | |
| | | | |
| | | if(ss.fail() == false) | |
| { | | { | |
| x.at(row,col) = val; | | x.at(row,col) = val; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| load_okay = false; | | const bool success = diskio::convert_naninf( x.at(row,col), token | |
| err_msg = "couldn't interpret data in "; | | ); | |
| //break; | | | |
| | | if(success == false) | |
| | | { | |
| | | load_okay = false; | |
| | | err_msg = "couldn't interpret data in "; | |
| | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // an empty file indicates an empty matrix | | // an empty file indicates an empty matrix | |
| if( (f_n_cols_found == false) && (load_okay == true) ) | | if( (f_n_cols_found == false) && (load_okay == true) ) | |
| { | | { | |
| x.reset(); | | x.reset(); | |
| } | | } | |
| | | | |
| skipping to change at line 1410 | | skipping to change at line 1426 | |
| std::string f_header; | | std::string f_header; | |
| uword f_n_rows; | | uword f_n_rows; | |
| uword f_n_cols; | | uword f_n_cols; | |
| | | | |
| f >> f_header; | | f >> f_header; | |
| f >> f_n_rows; | | f >> f_n_rows; | |
| f >> f_n_cols; | | f >> f_n_cols; | |
| | | | |
| if(f_header == diskio::gen_txt_header(x)) | | if(f_header == diskio::gen_txt_header(x)) | |
| { | | { | |
|
| x.set_size(f_n_rows, f_n_cols); | | x.zeros(f_n_rows, f_n_cols); | |
| | | | |
| | | std::string token; | |
| | | std::stringstream ss; | |
| | | | |
| for(uword row=0; row < x.n_rows; ++row) | | for(uword row=0; row < x.n_rows; ++row) | |
| { | | { | |
| for(uword col=0; col < x.n_cols; ++col) | | for(uword col=0; col < x.n_cols; ++col) | |
| { | | { | |
|
| f >> x.at(row,col); | | f >> token; | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token); | |
| | | | |
| | | eT val = eT(0); | |
| | | ss >> val; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | x.at(row,col) = val; | |
| | | } | |
| | | else | |
| | | { | |
| | | diskio::convert_naninf( x.at(row,col), token ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| load_okay = f.good(); | | load_okay = f.good(); | |
| } | | } | |
| else | | else | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| err_msg = "incorrect header in "; | | err_msg = "incorrect header in "; | |
| } | | } | |
| | | | |
| skipping to change at line 1475 | | skipping to change at line 1509 | |
| | | | |
| // | | // | |
| // work out the size | | // work out the size | |
| | | | |
| uword f_n_rows = 0; | | uword f_n_rows = 0; | |
| uword f_n_cols = 0; | | uword f_n_cols = 0; | |
| | | | |
| std::string line_string; | | std::string line_string; | |
| std::string token; | | std::string token; | |
| | | | |
|
| | | std::stringstream line_stream; | |
| | | | |
| while( (f.good() == true) && (load_okay == true) ) | | while( (f.good() == true) && (load_okay == true) ) | |
| { | | { | |
| std::getline(f, line_string); | | std::getline(f, line_string); | |
| | | | |
| if(line_string.size() == 0) | | if(line_string.size() == 0) | |
| { | | { | |
| break; | | break; | |
| } | | } | |
| | | | |
|
| std::stringstream line_stream(line_string); | | line_stream.clear(); | |
| | | line_stream.str(line_string); | |
| | | | |
| uword line_n_cols = 0; | | uword line_n_cols = 0; | |
| | | | |
| while(line_stream.good() == true) | | while(line_stream.good() == true) | |
| { | | { | |
| std::getline(line_stream, token, ','); | | std::getline(line_stream, token, ','); | |
| ++line_n_cols; | | ++line_n_cols; | |
| } | | } | |
| | | | |
| if(f_n_cols < line_n_cols) | | if(f_n_cols < line_n_cols) | |
| | | | |
| skipping to change at line 1509 | | skipping to change at line 1546 | |
| ++f_n_rows; | | ++f_n_rows; | |
| } | | } | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| x.zeros(f_n_rows, f_n_cols); | | x.zeros(f_n_rows, f_n_cols); | |
| | | | |
| uword row = 0; | | uword row = 0; | |
| | | | |
|
| | | std::stringstream ss; | |
| | | | |
| while(f.good() == true) | | while(f.good() == true) | |
| { | | { | |
| std::getline(f, line_string); | | std::getline(f, line_string); | |
| | | | |
| if(line_string.size() == 0) | | if(line_string.size() == 0) | |
| { | | { | |
| break; | | break; | |
| } | | } | |
| | | | |
|
| std::stringstream line_stream(line_string); | | line_stream.clear(); | |
| | | line_stream.str(line_string); | |
| | | | |
| uword col = 0; | | uword col = 0; | |
| | | | |
| while(line_stream.good() == true) | | while(line_stream.good() == true) | |
| { | | { | |
| std::getline(line_stream, token, ','); | | std::getline(line_stream, token, ','); | |
| | | | |
|
| eT val; | | ss.clear(); | |
| | | ss.str(token); | |
| std::stringstream ss(token); | | | |
| | | | |
|
| | | eT val = eT(0); | |
| ss >> val; | | ss >> val; | |
| | | | |
| if(ss.fail() == false) | | if(ss.fail() == false) | |
| { | | { | |
| x.at(row,col) = val; | | x.at(row,col) = val; | |
| } | | } | |
|
| | | else | |
| | | { | |
| | | diskio::convert_naninf( x.at(row,col), token ); | |
| | | } | |
| | | | |
| ++col; | | ++col; | |
| } | | } | |
| | | | |
| ++row; | | ++row; | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 2001 | | skipping to change at line 2045 | |
| | | | |
| default: | | default: | |
| err_msg = "unknown data in "; | | err_msg = "unknown data in "; | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| | | | |
| return false; | | return false; | |
| } | | } | |
| | | | |
|
| | | // | |
| // sparse matrices | | // sparse matrices | |
|
| | | // | |
| | | | |
|
| //! Save a matrix as raw text (no header, human readable). | | //! Save a matrix in ASCII coord format | |
| //! Matrices can be loaded in Matlab and Octave, as long as they don't have | | | |
| complex elements. | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::save_raw_ascii(const SpMat<eT>& x, const std::string& final_name) | | diskio::save_coord_ascii(const SpMat<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | | |
|
| std::fstream f(tmp_name.c_str(), std::fstream::out); | | std::ofstream f(tmp_name.c_str()); | |
| | | | |
| bool save_okay = f.is_open(); | | bool save_okay = f.is_open(); | |
| | | | |
| if(save_okay == true) | | if(save_okay == true) | |
| { | | { | |
|
| save_okay = diskio::save_raw_ascii(x, f); | | save_okay = diskio::save_coord_ascii(x, f); | |
| | | | |
| f.flush(); | | f.flush(); | |
| f.close(); | | f.close(); | |
| | | | |
| if(save_okay == true) | | if(save_okay == true) | |
| { | | { | |
| save_okay = diskio::safe_rename(tmp_name, final_name); | | save_okay = diskio::safe_rename(tmp_name, final_name); | |
| } | | } | |
| } | | } | |
| | | | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
|
| //! Save a matrix as raw text (no header, human readable). | | //! Save a matrix in ASCII coord format | |
| //! Matrices can be loaded in Matlab and Octave, as long as they don't have | | | |
| complex elements. | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::save_raw_ascii(const SpMat<eT>& x, std::ostream& f) | | diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| uword cell_width; | | const ios::fmtflags orig_flags = f.flags(); | |
| | | | |
| // TODO: need sane values for complex numbers | | | |
| | | | |
|
| if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | | typename SpMat<eT>::const_iterator iter = x.begin(); | |
| { | | typename SpMat<eT>::const_iterator iter_end = x.end(); | |
| f.setf(ios::scientific); | | | |
| f.precision(10); | | | |
| cell_width = 18; | | | |
| } | | | |
| | | | |
|
| for(uword row=0; row < x.n_rows; ++row) | | for(; iter != iter_end; ++iter) | |
| { | | { | |
|
| for(uword col=0; col < x.n_cols; ++col) | | f.setf(ios::fixed); | |
| { | | | |
| f.put(' '); | | | |
| | | | |
|
| if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | | f << iter.row() << ' ' << iter.col() << ' '; | |
| { | | | |
| f.width(cell_width); | | | |
| } | | | |
| | | | |
|
| f << x.at(row,col); | | if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | |
| | | { | |
| | | f.setf(ios::scientific); | |
| | | f.precision(10); | |
| } | | } | |
| | | | |
|
| f.put('\n'); | | f << (*iter) << '\n'; | |
| } | | } | |
| | | | |
|
| return f.good(); | | // make sure it's possible to figure out the matrix size later | |
| } | | if( (x.n_rows > 0) && (x.n_cols > 0) ) | |
| | | { | |
| //// TODO: this function doesn't make sense for sparse matrices, as there i | | const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; | |
| s no universal definition of a "raw" CSC file | | const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; | |
| // //! Save a matrix as raw binary (no header) | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_raw_binary(const SpMat<eT>& x, const std::string& final_nam | | | |
| e) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const std::string tmp_name = diskio::gen_tmp_name(final_name); | | | |
| // | | | |
| // std::ofstream f(tmp_name.c_str(), std::fstream::binary); | | | |
| // | | | |
| // bool save_okay = f.is_open(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::save_raw_binary(x, f); | | | |
| // | | | |
| // f.flush(); | | | |
| // f.close(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::safe_rename(tmp_name, final_name); | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function doesn't make sense for sparse matrices, as there i | | if( x.at(max_row, max_col) == eT(0) ) | |
| s no universal definition of a "raw" CSC file | | { | |
| // template<typename eT> | | f.setf(ios::fixed); | |
| // inline | | | |
| // bool | | | |
| // diskio::save_raw_binary(const SpMat<eT>& x, std::ostream& f) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // //Write the dims of the matrix first | | | |
| // f.write( reinterpret_cast<const char*>(&x.n_rows), std::streamsize(siz | | | |
| eof(uword)) ); | | | |
| // f.write( reinterpret_cast<const char*>(&x.n_cols), std::streamsize(siz | | | |
| eof(uword)) ); | | | |
| // f.write( reinterpret_cast<const char*>(&x.n_nonzero), std::streamsize( | | | |
| sizeof(uword)) ); | | | |
| // | | | |
| // //Now write the data for the three vectors | | | |
| // f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x.n_ | | | |
| nonzero*sizeof(eT)) ); | | | |
| // f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize | | | |
| (x.n_nonzero*sizeof(uword)) ); | | | |
| // f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x | | | |
| .n_cols+1)*sizeof(uword)) ); | | | |
| // | | | |
| // return f.good(); | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | f << max_row << ' ' << max_col << " 0\n"; | |
| s; we can define our own format, or adapt an existing format | | } | |
| // //! Save a matrix in text format (human readable), | | } | |
| // //! with a header that indicates the matrix type as well as its dimensio | | | |
| ns | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_arma_ascii(const SpMat<eT>& x, const std::string& final_nam | | | |
| e) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const std::string tmp_name = diskio::gen_tmp_name(final_name); | | | |
| // | | | |
| // std::ofstream f(tmp_name.c_str()); | | | |
| // | | | |
| // bool save_okay = f.is_open(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::save_arma_ascii(x, f); | | | |
| // | | | |
| // f.flush(); | | | |
| // f.close(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::safe_rename(tmp_name, final_name); | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | const bool save_okay = f.good(); | |
| s; we can define our own format, or adapt an existing format | | | |
| // //! Save a matrix in text format (human readable), | | | |
| // //! with a header that indicates the matrix type as well as its dimensio | | | |
| ns | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_arma_ascii(const SpMat<eT>& x, std::ostream& f) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const ios::fmtflags orig_flags = f.flags(); | | | |
| // | | | |
| // f << diskio::gen_txt_header(x) << '\n'; | | | |
| // f << x.n_rows << ' ' << x.n_cols << '\n'; | | | |
| // | | | |
| // uword cell_width; | | | |
| // | | | |
| // // TODO: need sane values for complex numbers | | | |
| // | | | |
| // if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | | | |
| // { | | | |
| // f.setf(ios::scientific); | | | |
| // f.precision(10); | | | |
| // cell_width = 18; | | | |
| // } | | | |
| // | | | |
| // for(uword row=0; row < x.n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < x.n_cols; ++col) | | | |
| // { | | | |
| // f.put(' '); | | | |
| // | | | |
| // if( (is_float<eT>::value == true) || (is_double<eT>::value == true | | | |
| ) ) | | | |
| // { | | | |
| // f.width(cell_width); | | | |
| // } | | | |
| // | | | |
| // f << x.at(row,col); | | | |
| // } | | | |
| // | | | |
| // f.put('\n'); | | | |
| // } | | | |
| // | | | |
| // const bool save_okay = f.good(); | | | |
| // | | | |
| // f.flags(orig_flags); | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | f.flags(orig_flags); | |
| s | | | |
| // //! Save a matrix in CSV text format (human readable) | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_csv_ascii(const SpMat<eT>& x, const std::string& final_name | | | |
| ) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const std::string tmp_name = diskio::gen_tmp_name(final_name); | | | |
| // | | | |
| // std::ofstream f(tmp_name.c_str()); | | | |
| // | | | |
| // bool save_okay = f.is_open(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::save_csv_ascii(x, f); | | | |
| // | | | |
| // f.flush(); | | | |
| // f.close(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::safe_rename(tmp_name, final_name); | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | return save_okay; | |
| s | | } | |
| // //! Save a matrix in CSV text format (human readable) | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_csv_ascii(const SpMat<eT>& x, std::ostream& f) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const ios::fmtflags orig_flags = f.flags(); | | | |
| // | | | |
| // // TODO: need sane values for complex numbers | | | |
| // | | | |
| // if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) | | | |
| // { | | | |
| // f.setf(ios::scientific); | | | |
| // f.precision(10); | | | |
| // } | | | |
| // | | | |
| // uword x_n_rows = x.n_rows; | | | |
| // uword x_n_cols = x.n_cols; | | | |
| // | | | |
| // for(uword row=0; row < x_n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < x_n_cols; ++col) | | | |
| // { | | | |
| // f << x.at(row,col); | | | |
| // | | | |
| // if( col < (x_n_cols-1) ) | | | |
| // { | | | |
| // f.put(','); | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // f.put('\n'); | | | |
| // } | | | |
| // | | | |
| // const bool save_okay = f.good(); | | | |
| // | | | |
| // f.flags(orig_flags); | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| //! Save a matrix in binary format, | | //! Save a matrix in ASCII coord format (complex numbers) | |
| //! with a header that stores the matrix type as well as its dimensions | | template<typename T> | |
| template<typename eT> | | | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::save_arma_binary(const SpMat<eT>& x, const std::string& final_name) | | diskio::save_coord_ascii(const SpMat< std::complex<T> >& x, std::ostream& f
) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const ios::fmtflags orig_flags = f.flags(); | |
| | | | |
|
| std::ofstream f(tmp_name.c_str(), std::fstream::binary); | | typedef typename std::complex<T> eT; | |
| | | | |
|
| bool save_okay = f.is_open(); | | typename SpMat<eT>::const_iterator iter = x.begin(); | |
| | | typename SpMat<eT>::const_iterator iter_end = x.end(); | |
| | | | |
|
| if(save_okay == true) | | for(; iter != iter_end; ++iter) | |
| { | | { | |
|
| save_okay = diskio::save_arma_binary(x, f); | | f.setf(ios::fixed); | |
| | | | |
|
| f.flush(); | | f << iter.row() << ' ' << iter.col() << ' '; | |
| f.close(); | | | |
| | | | |
|
| if(save_okay == true) | | if( (is_float<T>::value == true) || (is_double<T>::value == true) ) | |
| { | | { | |
|
| save_okay = diskio::safe_rename(tmp_name, final_name); | | f.setf(ios::scientific); | |
| | | f.precision(10); | |
| } | | } | |
|
| | | | |
| | | const eT val = (*iter); | |
| | | | |
| | | f << val.real() << ' ' << val.imag() << '\n'; | |
| } | | } | |
| | | | |
|
| return save_okay; | | // make sure it's possible to figure out the matrix size later | |
| } | | if( (x.n_rows > 0) && (x.n_cols > 0) ) | |
| | | { | |
| | | const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; | |
| | | const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; | |
| | | | |
|
| //! Save a matrix in binary format, | | if( x.at(max_row, max_col) == eT(0) ) | |
| //! with a header that stores the matrix type as well as its dimensions | | { | |
| template<typename eT> | | f.setf(ios::fixed); | |
| inline | | | |
| bool | | | |
| diskio::save_arma_binary(const SpMat<eT>& x, std::ostream& f) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| //Write the dims of the matrix first | | | |
| f << diskio::gen_bin_header(x) << '\n'; | | | |
| f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n'; | | | |
| | | | |
| //Now write the data for the three vectors | | | |
| f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x.n_non | | | |
| zero*sizeof(eT)) ); | | | |
| f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize(x. | | | |
| n_nonzero*sizeof(uword)) ); | | | |
| f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x.n_ | | | |
| cols+1)*sizeof(uword)) ); | | | |
| | | | |
| return f.good(); | | | |
| } | | | |
| | | | |
|
| // //! Save a matrix as a PGM greyscale image | | f << max_row << ' ' << max_col << " 0 0\n"; | |
| // template<typename eT> | | } | |
| // inline | | } | |
| // bool | | | |
| // diskio::save_pgm_binary(const SpMat<eT>& x, const std::string& final_nam | | | |
| e) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // const std::string tmp_name = diskio::gen_tmp_name(final_name); | | | |
| // | | | |
| // std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::bin | | | |
| ary); | | | |
| // | | | |
| // bool save_okay = f.is_open(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::save_pgm_binary(x, f); | | | |
| // | | | |
| // f.flush(); | | | |
| // f.close(); | | | |
| // | | | |
| // if(save_okay == true) | | | |
| // { | | | |
| // save_okay = diskio::safe_rename(tmp_name, final_name); | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // return save_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Save a matrix as a PGM greyscale image | | const bool save_okay = f.good(); | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_pgm_binary(const SpMat<eT>& x, std::ostream& f) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // f << "P5" << '\n'; | | | |
| // f << x.n_cols << ' ' << x.n_rows << ' ' << x.n_cols*x.n_rows << '\n'; | | | |
| // f << 255 << '\n'; | | | |
| // | | | |
| // const uword n_elem = x.n_nonzero; | | | |
| // podarray<u8> tmp(n_elem); | | | |
| // | | | |
| // uword i = 0; | | | |
| // | | | |
| // for(uword row=0; row < x.n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < x.n_cols; ++col) | | | |
| // { | | | |
| // tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? | | | |
| // ++i; | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // f.write(reinterpret_cast<const char*>(tmp.mem), std::streamsize(x.n_ro | | | |
| ws*x.n_cols) ); | | | |
| // | | | |
| // return f.good(); | | | |
| // } | | | |
| | | | |
|
| // //! Save a matrix as a PGM greyscale image | | f.flags(orig_flags); | |
| // template<typename T> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::save_pgm_binary(const SpMat< std::complex<T> >& x, const std::st | | | |
| ring& final_name) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // const uchar_mat tmp = conv_to<uchar_mat>::from(x); | | | |
| // | | | |
| // return diskio::save_pgm_binary(tmp, final_name); | | | |
| // } | | | |
| | | | |
|
| // //! Save a matrix as a PGM greyscale image | | return save_okay; | |
| // template<typename T> | | } | |
| // inline | | | |
| // bool | | | |
| // diskio::save_pgm_binary(const SpMat< std::complex<T> >& x, std::ostream& | | | |
| f) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // const uchar_mat tmp = conv_to<uchar_mat>::from(x); | | | |
| // | | | |
| // return diskio::save_pgm_binary(tmp, f); | | | |
| // } | | | |
| | | | |
|
| //! Save a matrix in ASCII coord format | | //! Save a matrix in binary format, | |
| | | //! with a header that stores the matrix type as well as its dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::save_coord_ascii(const SpMat<eT>& x, const std::string& final_name) | | diskio::save_arma_binary(const SpMat<eT>& x, const std::string& final_name) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const std::string tmp_name = diskio::gen_tmp_name(final_name); | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | | |
|
| std::ofstream f(tmp_name.c_str()); | | std::ofstream f(tmp_name.c_str(), std::fstream::binary); | |
| | | | |
| bool save_okay = f.is_open(); | | bool save_okay = f.is_open(); | |
| | | | |
| if(save_okay == true) | | if(save_okay == true) | |
| { | | { | |
|
| save_okay = diskio::save_coord_ascii(x, f); | | save_okay = diskio::save_arma_binary(x, f); | |
| | | | |
| f.flush(); | | f.flush(); | |
| f.close(); | | f.close(); | |
| | | | |
| if(save_okay == true) | | if(save_okay == true) | |
| { | | { | |
| save_okay = diskio::safe_rename(tmp_name, final_name); | | save_okay = diskio::safe_rename(tmp_name, final_name); | |
| } | | } | |
| } | | } | |
| | | | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
|
| //! Save a matrix in ASCII coord format | | //! Save a matrix in binary format, | |
| | | //! with a header that stores the matrix type as well as its dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f) | | diskio::save_arma_binary(const SpMat<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| uword x_n_rows = x.n_rows; | | f << diskio::gen_bin_header(x) << '\n'; | |
| uword x_n_cols = x.n_cols; | | f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n'; | |
| uword x_n_nonzero = x.n_nonzero; | | | |
| | | | |
| //Put down the header | | | |
| f << x_n_rows << " " << x_n_cols << " " << x_n_nonzero << endl; | | | |
| | | | |
| typename SpMat<eT>::const_iterator iter = x.begin(); | | | |
| for(; iter != x.end(); iter++) | | | |
| f << iter.row() << " " << iter.col() << " " << *iter << endl; | | | |
| | | | |
|
| const bool save_okay = f.good(); | | f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x. | |
| | | n_nonzero*sizeof(eT)) ); | |
| | | f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize(x. | |
| | | n_nonzero*sizeof(uword)) ); | |
| | | f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x | |
| | | .n_cols+1)*sizeof(uword)) ); | |
| | | | |
|
| return save_okay; | | return f.good(); | |
| } | | } | |
| | | | |
|
| //! Load a matrix as raw text (no header, human readable). | | | |
| //! Can read matrices saved as text in Matlab and Octave. | | | |
| //! NOTE: this is much slower than reading a file with a header. | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::load_raw_ascii(SpMat<eT>& x, const std::string& name, std::string&
err_msg) | | diskio::load_coord_ascii(SpMat<eT>& x, const std::string& name, std::string
& err_msg) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| std::fstream f; | | std::fstream f; | |
|
| f.open(name.c_str(), std::fstream::in); | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
| bool load_okay = f.is_open(); | | bool load_okay = f.is_open(); | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
|
| load_okay = diskio::load_raw_ascii(x, f, err_msg); | | load_okay = diskio::load_coord_ascii(x, f, err_msg); | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
|
| //! Load a matrix as raw text (no header, human readable). | | | |
| //! Can read matrices saved as text in Matlab and Octave. | | | |
| //! NOTE: this is much slower than reading a file with a header. | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::load_raw_ascii(SpMat<eT>& x, std::istream& f, std::string& err_msg) | | diskio::load_coord_ascii(SpMat<eT>& x, std::istream& f, std::string& err_ms
g) | |
| { | | { | |
|
| arma_extra_debug_sigprint(); | | | |
| | | | |
| bool load_okay = f.good(); | | bool load_okay = f.good(); | |
| | | | |
| f.clear(); | | f.clear(); | |
| const std::fstream::pos_type pos1 = f.tellg(); | | const std::fstream::pos_type pos1 = f.tellg(); | |
| | | | |
| // | | // | |
| // work out the size | | // work out the size | |
| | | | |
| uword f_n_rows = 0; | | uword f_n_rows = 0; | |
| uword f_n_cols = 0; | | uword f_n_cols = 0; | |
|
| | | uword f_n_nz = 0; | |
| | | | |
|
| bool f_n_cols_found = false; | | bool size_found = false; | |
| | | | |
|
| std::string line_string; | | std::string line_string; | |
| std::string token; | | std::string token; | |
| | | | |
| | | std::stringstream line_stream; | |
| | | std::stringstream ss; | |
| | | | |
| | | uword last_line_row = 0; | |
| | | uword last_line_col = 0; | |
| | | | |
| | | bool first_line = true; | |
| | | bool weird_format = false; | |
| | | | |
| while( (f.good() == true) && (load_okay == true) ) | | while( (f.good() == true) && (load_okay == true) ) | |
| { | | { | |
| std::getline(f, line_string); | | std::getline(f, line_string); | |
| | | | |
| if(line_string.size() == 0) | | if(line_string.size() == 0) | |
| { | | { | |
| break; | | break; | |
| } | | } | |
| | | | |
|
| std::stringstream line_stream(line_string); | | line_stream.clear(); | |
| | | line_stream.str(line_string); | |
| | | | |
|
| uword line_n_cols = 0; | | uword line_row = 0; | |
| | | uword line_col = 0; | |
| | | | |
|
| while (line_stream >> token) | | // a valid line in co-ord format has at least 2 entries | |
| | | | |
| | | line_stream >> line_row; | |
| | | | |
| | | if(line_stream.good() == false) | |
| { | | { | |
|
| ++line_n_cols; | | load_okay = false; | |
| | | break; | |
| } | | } | |
| | | | |
|
| if(f_n_cols_found == false) | | line_stream >> line_col; | |
| | | | |
| | | size_found = true; | |
| | | | |
| | | if(f_n_rows < line_row) f_n_rows = line_row; | |
| | | if(f_n_cols < line_col) f_n_cols = line_col; | |
| | | | |
| | | if(first_line == true) | |
| { | | { | |
|
| f_n_cols = line_n_cols; | | first_line = false; | |
| f_n_cols_found = true; | | | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(line_n_cols != f_n_cols) | | if( (line_col < last_line_col) || ((line_row <= last_line_row) && (li
ne_col <= last_line_col)) ) | |
| { | | { | |
|
| err_msg = "inconsistent number of columns in "; | | weird_format = true; | |
| load_okay = false; | | | |
| } | | } | |
| } | | } | |
| | | | |
|
| ++f_n_rows; | | last_line_row = line_row; | |
| | | last_line_col = line_col; | |
| | | | |
| | | if(line_stream.good() == true) | |
| | | { | |
| | | eT final_val = eT(0); | |
| | | | |
| | | line_stream >> token; | |
| | | | |
| | | if(line_stream.fail() == false) | |
| | | { | |
| | | eT val = eT(0); | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token); | |
| | | | |
| | | ss >> val; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | final_val = val; | |
| | | } | |
| | | else | |
| | | { | |
| | | val = eT(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val, token ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val = val; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(final_val != eT(0)) | |
| | | { | |
| | | ++f_n_nz; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(size_found == true) | |
| | | { | |
| | | // take into account that indices start at 0 | |
| | | f_n_rows++; | |
| | | f_n_cols++; | |
| } | | } | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| x.set_size(f_n_rows, f_n_cols); | | x.set_size(f_n_rows, f_n_cols); | |
| | | | |
|
| eT val; | | if(weird_format == false) | |
| | | { | |
| | | x.mem_resize(f_n_nz); | |
| | | } | |
| | | | |
|
| for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) | | uword pos = 0; | |
| | | | |
| | | while(f.good() == true) | |
| { | | { | |
|
| for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) | | std::getline(f, line_string); | |
| | | | |
| | | if(line_string.size() == 0) | |
| | | { | |
| | | break; | |
| | | } | |
| | | | |
| | | line_stream.clear(); | |
| | | line_stream.str(line_string); | |
| | | | |
| | | uword line_row = 0; | |
| | | uword line_col = 0; | |
| | | | |
| | | line_stream >> line_row; | |
| | | line_stream >> line_col; | |
| | | | |
| | | eT final_val = eT(0); | |
| | | | |
| | | line_stream >> token; | |
| | | | |
| | | if(line_stream.fail() == false) | |
| { | | { | |
|
| f >> val; | | eT val = eT(0); | |
| if(f.fail() == false) | | | |
| | | ss.clear(); | |
| | | ss.str(token); | |
| | | | |
| | | ss >> val; | |
| | | | |
| | | if(ss.fail() == false) | |
| { | | { | |
|
| x.at(row,col) = val; | | final_val = val; | |
| | | } | |
| | | else | |
| | | { | |
| | | val = eT(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val, token ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val = val; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(final_val != eT(0)) | |
| | | { | |
| | | if(weird_format == false) | |
| | | { | |
| | | access::rw(x.row_indices[pos]) = line_row; | |
| | | access::rw(x.values[pos]) = final_val; | |
| | | ++access::rw(x.col_ptrs[line_col + 1]); | |
| | | | |
| | | ++pos; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| load_okay = false; | | x.at(line_row,line_col) = final_val; | |
| err_msg = "couldn't interpret data in "; | | | |
| //break; | | | |
| } | | } | |
| } | | } | |
| } | | } | |
|
| } | | | |
| | | | |
|
| // an empty file indicates an empty matrix | | if(weird_format == false) | |
| if( (f_n_cols_found == false) && (load_okay == true) ) | | { | |
| { | | for(uword c = 1; c <= f_n_cols; ++c) | |
| x.reset(); | | { | |
| | | access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; | |
| | | } | |
| | | } | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
|
| //TODO: this function doesn't make sense for sparse matrices, as there is n | | template<typename T> | |
| o universal definition of a "raw" CSC file | | inline | |
| // //! Load a matrix in binary format (no header); | | bool | |
| // //! the matrix is assumed to have one column | | diskio::load_coord_ascii(SpMat< std::complex<T> >& x, std::istream& f, std: | |
| // template<typename eT> | | :string& err_msg) | |
| // inline | | { | |
| // bool | | typedef std::complex<T> eT; | |
| // diskio::load_raw_binary(SpMat<eT>& x, const std::string& name, std::stri | | | |
| ng& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // std::ifstream f; | | | |
| // f.open(name.c_str(), std::fstream::binary); | | | |
| // | | | |
| // bool load_okay = f.is_open(); | | | |
| // | | | |
| // if(load_okay == true) | | | |
| // { | | | |
| // load_okay = diskio::load_raw_binary(x, f, err_msg); | | | |
| // f.close(); | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function doesn't make sense for sparse matrices, as there i | | bool load_okay = f.good(); | |
| s no universal definition of a "raw" CSC file | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_raw_binary(SpMat<eT>& x, std::istream& f, std::string& err_ | | | |
| msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // arma_ignore(err_msg); | | | |
| // | | | |
| // | | | |
| // //Make sure we are at top of file. | | | |
| // f.clear(); | | | |
| // | | | |
| // //Read the dimensions of the matrix | | | |
| // f.read( (char*) &access::rw(x.n_rows), std::streamsize(sizeof(uword)) | | | |
| ); | | | |
| // f.read( (char*) &access::rw(x.n_cols), std::streamsize(sizeof(uword)) | | | |
| ); | | | |
| // f.read( (char*) &access::rw(x.n_nonzero), std::streamsize(sizeof(uword | | | |
| )) ); | | | |
| // access::rw(x.n_elem) = x.n_rows * x.n_cols; | | | |
| // | | | |
| // //Allocate appropriate memory, then fill it. | | | |
| // eT* in_values = memory::acquire<eT>(x.n_nonzero); // TODO: BUG. use | | | |
| acquire_chunked | | | |
| // uword* in_row_indices = memory::acquire<uword>(x.n_nonzero); // TODO: | | | |
| BUG. use acquire_chunked | | | |
| // uword* in_col_ptrs = memory::acquire<uword>(x.n_cols + 1); | | | |
| // | | | |
| // f.read( reinterpret_cast<char*>(in_values), std::streamsize(x.n_nonzer | | | |
| o * sizeof(eT)) ); | | | |
| // f.read( reinterpret_cast<char*>(in_row_indices), std::streamsize(x.n_n | | | |
| onzero * sizeof(uword)) ); | | | |
| // f.read( reinterpret_cast<char*>(in_col_ptrs), std::streamsize((x.n_col | | | |
| s + 1) * sizeof(uword)) ); | | | |
| // | | | |
| // //Replace the current data in the sparse matrix | | | |
| // if(x.n_nonzero > 0) | | | |
| // { | | | |
| // memory::release(x.values); | | | |
| // memory::release(x.row_indices); | | | |
| // } | | | |
| // | | | |
| // memory::release(x.col_ptrs); | | | |
| // | | | |
| // access::rwp(x.values) = in_values; | | | |
| // access::rwp(x.row_indices) = in_row_indices; | | | |
| // access::rwp(x.col_ptrs) = in_col_ptrs; | | | |
| // | | | |
| // return f.good(); | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | f.clear(); | |
| s; we can define our own format, or adapt an existing format | | const std::fstream::pos_type pos1 = f.tellg(); | |
| // //! Load a matrix in text format (human readable), | | | |
| // //! with a header that indicates the matrix type as well as its dimensio | | | |
| ns | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_arma_ascii(SpMat<eT>& x, const std::string& name, std::stri | | | |
| ng& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // std::ifstream f(name.c_str()); | | | |
| // | | | |
| // bool load_okay = f.is_open(); | | | |
| // | | | |
| // if(load_okay == true) | | | |
| // { | | | |
| // load_okay = diskio::load_arma_ascii(x, f, err_msg); | | | |
| // f.close(); | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| //// TODO: this function needs to be reworked to save only non-zero element | | // | |
| s; we can define our own format, or adapt an existing format | | // work out the size | |
| // //! Load a matrix in text format (human readable), | | | |
| // //! with a header that indicates the matrix type as well as its dimensio | | | |
| ns | | | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_arma_ascii(SpMat<eT>& x, std::istream& f, std::string& err_ | | | |
| msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // bool load_okay = true; | | | |
| // | | | |
| // eT tmp; | | | |
| // std::string f_header; | | | |
| // uword f_n_rows; | | | |
| // uword f_n_cols; | | | |
| // | | | |
| // f >> f_header; | | | |
| // f >> f_n_rows; | | | |
| // f >> f_n_cols; | | | |
| // | | | |
| // if(f_header == diskio::gen_txt_header(x)) | | | |
| // { | | | |
| // x.set_size(f_n_rows, f_n_cols); | | | |
| // | | | |
| // for(uword row=0; row < x.n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < x.n_cols; ++col) | | | |
| // { | | | |
| // f >> tmp; | | | |
| // x.at(row,col) = tmp; | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // load_okay = f.good(); | | | |
| // } | | | |
| // else | | | |
| // { | | | |
| // load_okay = false; | | | |
| // err_msg = "incorrect header in "; | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Load a matrix in CSV text format (human readable) | | uword f_n_rows = 0; | |
| // template<typename eT> | | uword f_n_cols = 0; | |
| // inline | | uword f_n_nz = 0; | |
| // bool | | | |
| // diskio::load_csv_ascii(SpMat<eT>& x, const std::string& name, std::strin | | | |
| g& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // std::fstream f; | | | |
| // f.open(name.c_str(), std::fstream::in); | | | |
| // | | | |
| // bool load_okay = f.is_open(); | | | |
| // | | | |
| // if(load_okay == true) | | | |
| // { | | | |
| // load_okay = diskio::load_csv_ascii(x, f, err_msg); | | | |
| // f.close(); | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Load a matrix in CSV text format (human readable) | | bool size_found = false; | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_csv_ascii(SpMat<eT>& x, std::istream& f, std::string& err_m | | | |
| sg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // bool load_okay = f.good(); | | | |
| // | | | |
| // f.clear(); | | | |
| // const std::fstream::pos_type pos1 = f.tellg(); | | | |
| // | | | |
| // // | | | |
| // // work out the size | | | |
| // | | | |
| // uword f_n_rows = 0; | | | |
| // uword f_n_cols = 0; | | | |
| // | | | |
| // std::string line_string; | | | |
| // std::string token; | | | |
| // | | | |
| // while( (f.good() == true) && (load_okay == true) ) | | | |
| // { | | | |
| // std::getline(f, line_string); | | | |
| // | | | |
| // if(line_string.size() == 0) | | | |
| // { | | | |
| // break; | | | |
| // } | | | |
| // | | | |
| // std::stringstream line_stream(line_string); | | | |
| // | | | |
| // uword line_n_cols = 0; | | | |
| // | | | |
| // while(line_stream.good() == true) | | | |
| // { | | | |
| // std::getline(line_stream, token, ','); | | | |
| // ++line_n_cols; | | | |
| // } | | | |
| // | | | |
| // if(f_n_cols < line_n_cols) | | | |
| // { | | | |
| // f_n_cols = line_n_cols; | | | |
| // } | | | |
| // | | | |
| // ++f_n_rows; | | | |
| // } | | | |
| // | | | |
| // f.clear(); | | | |
| // f.seekg(pos1); | | | |
| // x.zeros(f_n_rows, f_n_cols); | | | |
| // | | | |
| // uword row = 0; | | | |
| // | | | |
| // while(f.good() == true) | | | |
| // { | | | |
| // std::getline(f, line_string); | | | |
| // | | | |
| // if(line_string.size() == 0) | | | |
| // { | | | |
| // break; | | | |
| // } | | | |
| // | | | |
| // std::stringstream line_stream(line_string); | | | |
| // | | | |
| // uword col = 0; | | | |
| // | | | |
| // while(line_stream.good() == true) | | | |
| // { | | | |
| // std::getline(line_stream, token, ','); | | | |
| // | | | |
| // eT val; | | | |
| // | | | |
| // std::stringstream ss(token); | | | |
| // | | | |
| // ss >> val; | | | |
| // | | | |
| // if(ss.fail() == false) | | | |
| // { | | | |
| // x.at(row,col) = val; | | | |
| // } | | | |
| // | | | |
| // ++col; | | | |
| // } | | | |
| // | | | |
| // ++row; | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| //! Load a matrix in binary format, | | std::string line_string; | |
| //! with a header that indicates the matrix type as well as its dimensions | | std::string token_real; | |
| template<typename eT> | | std::string token_imag; | |
| inline | | | |
| bool | | | |
| diskio::load_arma_binary(SpMat<eT>& x, const std::string& name, std::string | | | |
| & err_msg) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| std::ifstream f; | | std::stringstream line_stream; | |
| f.open(name.c_str(), std::fstream::binary); | | std::stringstream ss; | |
| | | | |
|
| bool load_okay = f.is_open(); | | uword last_line_row = 0; | |
| | | uword last_line_col = 0; | |
| | | | |
|
| if(load_okay == true) | | bool first_line = true; | |
| | | bool weird_format = false; | |
| | | | |
| | | while( (f.good() == true) && (load_okay == true) ) | |
| { | | { | |
|
| load_okay = diskio::load_arma_binary(x, f, err_msg); | | std::getline(f, line_string); | |
| f.close(); | | | |
| } | | | |
| | | | |
|
| return load_okay; | | if(line_string.size() == 0) | |
| } | | { | |
| | | break; | |
| | | } | |
| | | | |
|
| template<typename eT> | | line_stream.clear(); | |
| inline | | line_stream.str(line_string); | |
| bool | | | |
| diskio::load_arma_binary(SpMat<eT>& x, std::istream& f, std::string& err_ms | | | |
| g) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| bool load_okay = true; | | uword line_row = 0; | |
| | | uword line_col = 0; | |
| | | | |
|
| std::string f_header; | | // a valid line in co-ord format has at least 2 entries | |
| | | | |
|
| f >> f_header; | | line_stream >> line_row; | |
| f >> access::rw(x.n_rows); | | | |
| f >> access::rw(x.n_cols); | | | |
| f >> access::rw(x.n_nonzero); | | | |
| access::rw(x.n_elem) = x.n_rows*x.n_cols; | | | |
| | | | |
|
| if(f_header == diskio::gen_bin_header(x)) | | if(line_stream.good() == false) | |
| { | | { | |
| //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win | | load_okay = false; | |
| dows machine a newline could be two characters | | break; | |
| f.get(); | | } | |
| | | | |
|
| //Allocate memory for the incoming data | | line_stream >> line_col; | |
| eT* in_values = memory::acquire_chunked<eT> (x.n_nonzero); | | | |
| uword* in_row_indices = memory::acquire_chunked<uword>(x.n_nonzero); | | | |
| uword* in_col_ptrs = memory::acquire<uword> (x.n_cols + 1); | | | |
| | | | |
|
| f.read((char*) in_values, std::streamsize(x.n_nonzero * sizeof(eT)) ); | | size_found = true; | |
| f.read((char*) in_row_indices, std::streamsize(x.n_nonzero * sizeof(uwo | | | |
| rd)) ); | | | |
| f.read((char*) in_col_ptrs, std::streamsize((x.n_cols + 1) * sizeof(uwo | | | |
| rd)) ); | | | |
| | | | |
|
| //Stick new data into sparse matrix | | if(f_n_rows < line_row) f_n_rows = line_row; | |
| if (x.n_nonzero > 0) | | if(f_n_cols < line_col) f_n_cols = line_col; | |
| | | | |
| | | if(first_line == true) | |
| { | | { | |
|
| memory::release(x.values); | | first_line = false; | |
| memory::release(x.row_indices); | | | |
| } | | } | |
|
| | | else | |
| | | { | |
| | | if( (line_col < last_line_col) || ((line_row <= last_line_row) && (li | |
| | | ne_col <= last_line_col)) ) | |
| | | { | |
| | | weird_format = true; | |
| | | } | |
| | | } | |
| | | | |
| | | last_line_row = line_row; | |
| | | last_line_col = line_col; | |
| | | | |
|
| memory::release(x.col_ptrs); | | if(line_stream.good() == true) | |
| | | { | |
| | | T final_val_real = T(0); | |
| | | T final_val_imag = T(0); | |
| | | | |
|
| access::rw(x.values) = in_values; | | line_stream >> token_real; | |
| access::rw(x.row_indices) = in_row_indices; | | | |
| access::rw(x.col_ptrs) = in_col_ptrs; | | | |
| | | | |
|
| load_okay = f.good(); | | if(line_stream.fail() == false) | |
| | | { | |
| | | T val_real = T(0); | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token_real); | |
| | | | |
| | | ss >> val_real; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | final_val_real = val_real; | |
| | | } | |
| | | else | |
| | | { | |
| | | val_real = T(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val_real, token_real | |
| | | ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val_real = val_real; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | line_stream >> token_imag; | |
| | | | |
| | | if(line_stream.fail() == false) | |
| | | { | |
| | | T val_imag = T(0); | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token_imag); | |
| | | | |
| | | ss >> val_imag; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | final_val_imag = val_imag; | |
| | | } | |
| | | else | |
| | | { | |
| | | val_imag = T(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val_imag, token_imag | |
| | | ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val_imag = val_imag; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) | |
| | | { | |
| | | ++f_n_nz; | |
| | | } | |
| | | } | |
| } | | } | |
|
| else | | | |
| | | if(size_found == true) | |
| { | | { | |
|
| load_okay = false; | | // take into account that indices start at 0 | |
| err_msg = "incorrect header in "; | | f_n_rows++; | |
| | | f_n_cols++; | |
| } | | } | |
| | | | |
|
| return load_okay; | | if(load_okay == true) | |
| } | | { | |
| | | f.clear(); | |
| | | f.seekg(pos1); | |
| | | | |
|
| // //! Load a PGM greyscale image as a matrix | | x.set_size(f_n_rows, f_n_cols); | |
| // template<typename eT> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_pgm_binary(SpMat<eT>& x, const std::string& name, std::stri | | | |
| ng& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // | | | |
| // std::fstream f; | | | |
| // f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | | |
| // | | | |
| // bool load_okay = f.is_open(); | | | |
| // | | | |
| // if(load_okay == true) | | | |
| // { | | | |
| // load_okay = diskio::load_pgm_binary(x, f, err_msg); | | | |
| // f.close(); | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| ////! Load a PGM greyscale image as a matrix | | if(weird_format == false) | |
| // template<typename eT> | | { | |
| // inline | | x.mem_resize(f_n_nz); | |
| // bool | | } | |
| // diskio::load_pgm_binary(SpMat<eT>& x, std::istream& f, std::string& err_ | | | |
| msg) | | | |
| // { | | | |
| // bool load_okay = true; | | | |
| // | | | |
| // | | | |
| // std::string f_header; | | | |
| // f >> f_header; | | | |
| // | | | |
| // if(f_header == "P5") | | | |
| // { | | | |
| // uword f_n_rows = 0; | | | |
| // uword f_n_cols = 0; | | | |
| // int f_maxval = 0; | | | |
| // | | | |
| // diskio::pnm_skip_comments(f); | | | |
| // | | | |
| // f >> f_n_cols; | | | |
| // diskio::pnm_skip_comments(f); | | | |
| // | | | |
| // f >> f_n_rows; | | | |
| // diskio::pnm_skip_comments(f); | | | |
| // | | | |
| // f >> f_maxval; //grabing a redundant size value | | | |
| // | | | |
| // f >> f_maxval; | | | |
| // f.get(); | | | |
| // | | | |
| // if( (f_maxval > 0) || (f_maxval <= 65535) ) | | | |
| // { | | | |
| // x.set_size(f_n_rows,f_n_cols); | | | |
| // | | | |
| // if(f_maxval <= 255) | | | |
| // { | | | |
| // const uword n_elem = f_n_cols*f_n_rows; | | | |
| // podarray<u8> tmp(n_elem); | | | |
| // | | | |
| // f.read( reinterpret_cast<char*>(tmp.memptr()), std::streamsize(n | | | |
| _elem) ); | | | |
| // | | | |
| // uword i = 0; | | | |
| // | | | |
| // //cout << "f_n_cols = " << f_n_cols << endl; | | | |
| // //cout << "f_n_rows = " << f_n_rows << endl; | | | |
| // | | | |
| // | | | |
| // for(uword row=0; row < f_n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < f_n_cols; ++col) | | | |
| // { | | | |
| // x.at(row,col) = eT(tmp[i]); | | | |
| // ++i; | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // } | | | |
| // else | | | |
| // { | | | |
| // const uword n_elem = f_n_cols*f_n_rows; | | | |
| // podarray<u16> tmp(n_elem); | | | |
| // | | | |
| // f.read( reinterpret_cast<char *>(tmp.memptr()), std::streamsize( | | | |
| n_elem*2) ); | | | |
| // | | | |
| // uword i = 0; | | | |
| // | | | |
| // for(uword row=0; row < f_n_rows; ++row) | | | |
| // { | | | |
| // for(uword col=0; col < f_n_cols; ++col) | | | |
| // { | | | |
| // x.at(row,col) = eT(tmp[i]); | | | |
| // ++i; | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // } | | | |
| // | | | |
| // } | | | |
| // else | | | |
| // { | | | |
| // load_okay = false; | | | |
| // err_msg = "currently no code available to handle loading "; | | | |
| // } | | | |
| // | | | |
| // if(f.good() == false) | | | |
| // { | | | |
| // load_okay = false; | | | |
| // } | | | |
| // } | | | |
| // else | | | |
| // { | | | |
| // load_okay = false; | | | |
| // err_msg = "unsupported header in "; | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Load a PGM greyscale image as a matrix | | uword pos = 0; | |
| // template<typename T> | | | |
| // inline | | | |
| // bool | | | |
| // diskio::load_pgm_binary(SpMat< std::complex<T> >& x, const std::string& | | | |
| name, std::string& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // uchar_mat tmp; | | | |
| // const bool load_okay = diskio::load_pgm_binary(tmp, name, err_msg); | | | |
| // | | | |
| // x = conv_to< Mat< std::complex<T> > >::from(tmp); // TODO: BUG | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Load a PGM greyscale image as a matrix | | while(f.good() == true) | |
| // template<typename T> | | { | |
| // inline | | std::getline(f, line_string); | |
| // bool | | | |
| // diskio::load_pgm_binary(SpMat< std::complex<T> >& x, std::istream& is, s | | | |
| td::string& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // uchar_mat tmp; | | | |
| // const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); | | | |
| // | | | |
| // x = conv_to< Mat< std::complex<T> > >::from(tmp); // TODO: BUG | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Try to load a matrix by automatically determining its type | | if(line_string.size() == 0) | |
| // template<typename eT> | | { | |
| // inline | | break; | |
| // bool | | } | |
| // diskio::load_auto_detect(SpMat<eT>& x, const std::string& name, std::str | | | |
| ing& err_msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // std::fstream f; | | | |
| // f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | | |
| // | | | |
| // bool load_okay = f.is_open(); | | | |
| // | | | |
| // if(load_okay == true) | | | |
| // { | | | |
| // load_okay = diskio::load_auto_detect(x, f, err_msg); | | | |
| // f.close(); | | | |
| // } | | | |
| // | | | |
| // return load_okay; | | | |
| // } | | | |
| | | | |
|
| // //! Try to load a matrix by automatically determining its type | | line_stream.clear(); | |
| // template<typename eT> | | line_stream.str(line_string); | |
| // inline | | | |
| // bool | | uword line_row = 0; | |
| // diskio::load_auto_detect(SpMat<eT>& x, std::istream& f, std::string& err | | uword line_col = 0; | |
| _msg) | | | |
| // { | | | |
| // arma_extra_debug_sigprint(); | | | |
| // | | | |
| // static const std::string ARMA_SPM_TXT = "ARMA_SPM_TXT"; | | | |
| // static const std::string ARMA_SPM_BIN = "ARMA_SPM_BIN"; | | | |
| // static const std::string P5 = "P5"; | | | |
| // | | | |
| // podarray<char> raw_header(ARMA_SPM_TXT.length() + 1); | | | |
| // | | | |
| // std::streampos pos = f.tellg(); | | | |
| // | | | |
| // f.read( raw_header.memptr(), std::streamsize(ARMA_SPM_TXT.length()) ); | | | |
| // raw_header[ARMA_SPM_TXT.length()] = '\0'; | | | |
| // | | | |
| // f.clear(); | | | |
| // f.seekg(pos); | | | |
| // | | | |
| // const std::string header = raw_header.mem; | | | |
| // | | | |
| // if(ARMA_SPM_TXT == header.substr(0,ARMA_SPM_TXT.length())) | | | |
| // { | | | |
| // return load_arma_ascii(x, f, err_msg); | | | |
| // } | | | |
| // else | | | |
| // if(ARMA_SPM_BIN == header.substr(0,ARMA_SPM_BIN.length())) | | | |
| // { | | | |
| // return load_arma_binary(x, f, err_msg); | | | |
| // } | | | |
| // else | | | |
| // if(P5 == header.substr(0,P5.length())) | | | |
| // { | | | |
| // return load_pgm_binary(x, f, err_msg); | | | |
| // } | | | |
| // else | | | |
| // { | | | |
| // const file_type ft = guess_file_type(f); | | | |
| // | | | |
| // switch(ft) | | | |
| // { | | | |
| // case csv_ascii: | | | |
| // return load_csv_ascii(x, f, err_msg); | | | |
| // break; | | | |
| // | | | |
| // case raw_binary: | | | |
| // return load_raw_binary(x, f, err_msg); | | | |
| // break; | | | |
| // | | | |
| // case raw_ascii: | | | |
| // return load_raw_ascii(x, f, err_msg); | | | |
| // break; | | | |
| // | | | |
| // default: | | | |
| // err_msg = "unknown data in "; | | | |
| // return false; | | | |
| // } | | | |
| // } | | | |
| // | | | |
| // return false; | | | |
| // } | | | |
| | | | |
|
| | | line_stream >> line_row; | |
| | | line_stream >> line_col; | |
| | | | |
| | | T final_val_real = T(0); | |
| | | T final_val_imag = T(0); | |
| | | | |
| | | line_stream >> token_real; | |
| | | | |
| | | if(line_stream.fail() == false) | |
| | | { | |
| | | T val_real = T(0); | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token_real); | |
| | | | |
| | | ss >> val_real; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | final_val_real = val_real; | |
| | | } | |
| | | else | |
| | | { | |
| | | val_real = T(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val_real, token_real | |
| | | ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val_real = val_real; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | line_stream >> token_imag; | |
| | | | |
| | | if(line_stream.fail() == false) | |
| | | { | |
| | | T val_imag = T(0); | |
| | | | |
| | | ss.clear(); | |
| | | ss.str(token_imag); | |
| | | | |
| | | ss >> val_imag; | |
| | | | |
| | | if(ss.fail() == false) | |
| | | { | |
| | | final_val_imag = val_imag; | |
| | | } | |
| | | else | |
| | | { | |
| | | val_imag = T(0); | |
| | | | |
| | | const bool success = diskio::convert_naninf( val_imag, token_imag | |
| | | ); | |
| | | | |
| | | if(success == true) | |
| | | { | |
| | | final_val_imag = val_imag; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) | |
| | | { | |
| | | if(weird_format == false) | |
| | | { | |
| | | access::rw(x.row_indices[pos]) = line_row; | |
| | | access::rw(x.values[pos]) = std::complex<T>(final_val_real, | |
| | | final_val_imag); | |
| | | ++access::rw(x.col_ptrs[line_col + 1]); | |
| | | | |
| | | ++pos; | |
| | | } | |
| | | else | |
| | | { | |
| | | x.at(line_row,line_col) = std::complex<T>(final_val_real, final_v | |
| | | al_imag); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | if(weird_format == false) | |
| | | { | |
| | | for(uword c = 1; c <= f_n_cols; ++c) | |
| | | { | |
| | | access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | return load_okay; | |
| | | } | |
| | | | |
| | | //! Load a matrix in binary format, | |
| | | //! with a header that indicates the matrix type as well as its dimensions | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::load_coord_ascii(SpMat<eT>& x, const std::string& name, std::string
& err_msg) | | diskio::load_arma_binary(SpMat<eT>& x, const std::string& name, std::string
& err_msg) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| std::fstream f; | | std::ifstream f; | |
| f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | f.open(name.c_str(), std::fstream::binary); | |
| | | | |
| bool load_okay = f.is_open(); | | bool load_okay = f.is_open(); | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
|
| load_okay = diskio::load_coord_ascii(x, f, err_msg); | | load_okay = diskio::load_arma_binary(x, f, err_msg); | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
|
| diskio::load_coord_ascii(SpMat<eT>& x, std::istream& f, std::string& err_ms
g) | | diskio::load_arma_binary(SpMat<eT>& x, std::istream& f, std::string& err_ms
g) | |
| { | | { | |
|
| uword r,c,nz; | | arma_extra_debug_sigprint(); | |
| | | | |
|
| f >> r; f >> c; f >> nz; //Grab the header | | bool load_okay = true; | |
| x.set_size(r,c); | | | |
| | | | |
|
| for(size_t i = 0; i < nz; i++) | | std::string f_header; | |
| | | | |
| | | f >> f_header; | |
| | | | |
| | | if(f_header == diskio::gen_bin_header(x)) | |
| { | | { | |
|
| eT data; | | uword f_n_rows; | |
| uword row, col; | | uword f_n_cols; | |
| | | uword f_n_nz; | |
| | | | |
|
| f >> row; f >> col; f >> data; | | f >> f_n_rows; | |
| | | f >> f_n_cols; | |
| | | f >> f_n_nz; | |
| | | | |
|
| x.at(row,col) = data; | | //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win | |
| | | dows machine a newline could be two characters | |
| | | f.get(); | |
| | | | |
| | | x.set_size(f_n_rows, f_n_cols); | |
| | | | |
| | | x.mem_resize(f_n_nz); | |
| | | | |
| | | f.read( reinterpret_cast<char*>(access::rwp(x.values)), std::strea | |
| | | msize(x.n_nonzero*sizeof(eT)) ); | |
| | | f.read( reinterpret_cast<char*>(access::rwp(x.row_indices)), std::strea | |
| | | msize(x.n_nonzero*sizeof(uword)) ); | |
| | | f.read( reinterpret_cast<char*>(access::rwp(x.col_ptrs)), std::strea | |
| | | msize((x.n_cols+1)*sizeof(uword)) ); | |
| | | | |
| | | load_okay = f.good(); | |
| | | } | |
| | | else | |
| | | { | |
| | | load_okay = false; | |
| | | err_msg = "incorrect header in "; | |
| } | | } | |
| | | | |
|
| return f.good(); | | return load_okay; | |
| } | | } | |
| | | | |
| // cubes | | // cubes | |
| | | | |
| //! Save a cube as raw text (no header, human readable). | | //! Save a cube as raw text (no header, human readable). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_raw_ascii(const Cube<eT>& x, const std::string& final_name) | | diskio::save_raw_ascii(const Cube<eT>& x, const std::string& final_name) | |
| { | | { | |
| | | | |
End of changes. 140 change blocks. |
| 1131 lines changed or deleted | | 676 lines changed or added | |
|