| Cube_bones.hpp | | Cube_bones.hpp | |
| | | | |
| skipping to change at line 51 | | skipping to change at line 51 | |
| | | | |
| protected: | | protected: | |
| arma_align_mem Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; | | arma_align_mem Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; | |
| arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; | | arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; | |
| | | | |
| public: | | public: | |
| | | | |
| inline ~Cube(); | | inline ~Cube(); | |
| inline Cube(); | | inline Cube(); | |
| | | | |
|
| inline Cube(const uword in_rows, const uword in_cols, const uword in_slic
es); | | inline Cube(const uword in_rows, const uword in_cols, const uwor
d in_slices); | |
| | | | |
| template<typename fill_type> | | template<typename fill_type> | |
| inline Cube(const uword in_rows, const uword in_cols, const uword in_slic
es, const fill::fill_class<fill_type>& f); | | inline Cube(const uword in_rows, const uword in_cols, const uword in_slic
es, const fill::fill_class<fill_type>& f); | |
| | | | |
| #if defined(ARMA_USE_CXX11) | | #if defined(ARMA_USE_CXX11) | |
| inline Cube(Cube&& m); | | inline Cube(Cube&& m); | |
| inline const Cube& operator=(Cube&& m); | | inline const Cube& operator=(Cube&& m); | |
| #endif | | #endif | |
| | | | |
| inline Cube( eT* aux_mem, const uword aux_n_rows, const uword aux_n_
cols, const uword aux_n_slices, const bool copy_aux_mem = true, const bool
strict = true); | | inline Cube( eT* aux_mem, const uword aux_n_rows, const uword aux_n_
cols, const uword aux_n_slices, const bool copy_aux_mem = true, const bool
strict = true); | |
| | | | |
| skipping to change at line 96 | | skipping to change at line 96 | |
| | | | |
| arma_inline Mat<eT>& slice(const uword in_slice); | | arma_inline Mat<eT>& slice(const uword in_slice); | |
| arma_inline const Mat<eT>& slice(const uword in_slice) const; | | arma_inline const Mat<eT>& slice(const uword in_slice) const; | |
| | | | |
| arma_inline subview_cube<eT> slices(const uword in_slice1, const uw
ord in_slice2); | | arma_inline subview_cube<eT> slices(const uword in_slice1, const uw
ord in_slice2); | |
| arma_inline const subview_cube<eT> slices(const uword in_slice1, const uw
ord in_slice2) const; | | arma_inline const subview_cube<eT> slices(const uword in_slice1, const uw
ord in_slice2) const; | |
| | | | |
| arma_inline subview_cube<eT> subcube(const uword in_row1, const uwo
rd in_col1, const uword in_slice1, const uword in_row2, const uword in_col2
, const uword in_slice2); | | arma_inline subview_cube<eT> subcube(const uword in_row1, const uwo
rd in_col1, const uword in_slice1, const uword in_row2, const uword in_col2
, const uword in_slice2); | |
| arma_inline const subview_cube<eT> subcube(const uword in_row1, const uwo
rd in_col1, const uword in_slice1, const uword in_row2, const uword in_col2
, const uword in_slice2) const; | | arma_inline const subview_cube<eT> subcube(const uword in_row1, const uwo
rd in_col1, const uword in_slice1, const uword in_row2, const uword in_col2
, const uword in_slice2) const; | |
| | | | |
|
| | | inline subview_cube<eT> subcube(const uword in_row1, const uwo | |
| | | rd in_col1, const uword in_slice1, const SizeCube& s); | |
| | | inline const subview_cube<eT> subcube(const uword in_row1, const uwo | |
| | | rd in_col1, const uword in_slice1, const SizeCube& s) const; | |
| | | | |
| inline subview_cube<eT> subcube(const span& row_span, const sp
an& col_span, const span& slice_span); | | inline subview_cube<eT> subcube(const span& row_span, const sp
an& col_span, const span& slice_span); | |
| inline const subview_cube<eT> subcube(const span& row_span, const sp
an& col_span, const span& slice_span) const; | | inline const subview_cube<eT> subcube(const span& row_span, const sp
an& col_span, const span& slice_span) const; | |
| | | | |
| inline subview_cube<eT> operator()(const span& row_span, const
span& col_span, const span& slice_span); | | inline subview_cube<eT> operator()(const span& row_span, const
span& col_span, const span& slice_span); | |
| inline const subview_cube<eT> operator()(const span& row_span, const
span& col_span, const span& slice_span) const; | | inline const subview_cube<eT> operator()(const span& row_span, const
span& col_span, const span& slice_span) const; | |
| | | | |
|
| | | inline subview_cube<eT> operator()(const uword in_row1, const | |
| | | uword in_col1, const uword in_slice1, const SizeCube& s); | |
| | | inline const subview_cube<eT> operator()(const uword in_row1, const | |
| | | uword in_col1, const uword in_slice1, const SizeCube& s) const; | |
| | | | |
| arma_inline subview_cube<eT> tube(const uword in_row1, const uword
in_col1); | | arma_inline subview_cube<eT> tube(const uword in_row1, const uword
in_col1); | |
| arma_inline const subview_cube<eT> tube(const uword in_row1, const uword
in_col1) const; | | arma_inline const subview_cube<eT> tube(const uword in_row1, const uword
in_col1) const; | |
| | | | |
| arma_inline subview_cube<eT> tube(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2); | | arma_inline subview_cube<eT> tube(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2); | |
| arma_inline const subview_cube<eT> tube(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2) const; | | arma_inline const subview_cube<eT> tube(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2) const; | |
| | | | |
|
| | | arma_inline subview_cube<eT> tube(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s); | |
| | | arma_inline const subview_cube<eT> tube(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s) const; | |
| | | | |
| inline subview_cube<eT> tube(const span& row_span, const span&
col_span); | | inline subview_cube<eT> tube(const span& row_span, const span&
col_span); | |
| inline const subview_cube<eT> tube(const span& row_span, const span&
col_span) const; | | inline const subview_cube<eT> tube(const span& row_span, const span&
col_span) const; | |
| | | | |
| inline void shed_slice(const uword slice_num); | | inline void shed_slice(const uword slice_num); | |
| | | | |
| inline void shed_slices(const uword in_slice1, const uword in_slice2); | | inline void shed_slices(const uword in_slice1, const uword in_slice2); | |
| | | | |
| inline void insert_slices(const uword slice_num, const uword N, const boo
l set_to_zero = true); | | inline void insert_slices(const uword slice_num, const uword N, const boo
l set_to_zero = true); | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 201 | | skipping to change at line 210 | |
| | | | |
| arma_inline arma_warn_unused bool is_finite() const; | | arma_inline arma_warn_unused bool is_finite() const; | |
| arma_inline arma_warn_unused bool is_empty() const; | | arma_inline arma_warn_unused bool is_empty() const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword i) const; | | arma_inline arma_warn_unused bool in_range(const uword i) const; | |
| arma_inline arma_warn_unused bool in_range(const span& x) const; | | arma_inline arma_warn_unused bool in_range(const span& x) const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col, const uword in_slice) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col, const uword in_slice) const; | |
| inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span, const span& slice_span) const; | | inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span, const span& slice_span) const; | |
| | | | |
|
| | | inline arma_warn_unused bool in_range(const uword in_row, const uw | |
| | | ord in_col, const uword in_slice, const SizeCube& s) const; | |
| | | | |
| arma_inline arma_warn_unused eT* memptr(); | | arma_inline arma_warn_unused eT* memptr(); | |
| arma_inline arma_warn_unused const eT* memptr() const; | | arma_inline arma_warn_unused const eT* memptr() const; | |
| | | | |
| arma_inline arma_warn_unused eT* slice_memptr(const uword slice); | | arma_inline arma_warn_unused eT* slice_memptr(const uword slice); | |
| arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) co
nst; | | arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) co
nst; | |
| | | | |
| arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice,
const uword in_col); | | arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice,
const uword in_col); | |
| arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice,
const uword in_col) const; | | arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice,
const uword in_col) const; | |
| | | | |
| inline void impl_print(const std::string& extra_text) const; | | inline void impl_print(const std::string& extra_text) const; | |
| | | | |
| skipping to change at line 294 | | skipping to change at line 305 | |
| inline slice_iterator begin_slice(const uword slice_num); | | inline slice_iterator begin_slice(const uword slice_num); | |
| inline const_slice_iterator begin_slice(const uword slice_num) const; | | inline const_slice_iterator begin_slice(const uword slice_num) const; | |
| | | | |
| inline slice_iterator end_slice(const uword slice_num); | | inline slice_iterator end_slice(const uword slice_num); | |
| inline const_slice_iterator end_slice(const uword slice_num) const; | | inline const_slice_iterator end_slice(const uword slice_num) const; | |
| | | | |
| inline void clear(); | | inline void clear(); | |
| inline bool empty() const; | | inline bool empty() const; | |
| inline uword size() const; | | inline uword size() const; | |
| | | | |
|
| // inline void swap(Cube& B); // TODO | | inline void swap(Cube& B); | |
| | | | |
| inline void steal_mem(Cube& X); //!< don't use this unless you're writin
g code internal to Armadillo | | inline void steal_mem(Cube& X); //!< don't use this unless you're writin
g code internal to Armadillo | |
| | | | |
| template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices> cl
ass fixed; | | template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices> cl
ass fixed; | |
| | | | |
| protected: | | protected: | |
| | | | |
| inline void init_cold(); | | inline void init_cold(); | |
| inline void init_warm(const uword in_rows, const uword in_cols, const uwo
rd in_slices); | | inline void init_warm(const uword in_rows, const uword in_cols, const uwo
rd in_slices); | |
| | | | |
| | | | |
End of changes. 6 change blocks. |
| 2 lines changed or deleted | | 20 lines changed or added | |
|
| Cube_meat.hpp | | Cube_meat.hpp | |
| | | | |
| skipping to change at line 149 | | skipping to change at line 149 | |
| ( | | ( | |
| ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) ) | | ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) ) | |
| ? ( (float(n_rows) * float(n_cols) * float(n_slices)) > float(ARMA_
MAX_UWORD) ) | | ? ( (float(n_rows) * float(n_cols) * float(n_slices)) > float(ARMA_
MAX_UWORD) ) | |
| : false | | : false | |
| ), | | ), | |
| "Cube::init(): requested size is too large" | | "Cube::init(): requested size is too large" | |
| ); | | ); | |
| | | | |
| if(n_elem <= Cube_prealloc::mem_n_elem) | | if(n_elem <= Cube_prealloc::mem_n_elem) | |
| { | | { | |
|
| | | arma_extra_debug_print("Cube::init(): using local memory"); | |
| | | | |
| access::rw(mem) = mem_local; | | access::rw(mem) = mem_local; | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_extra_debug_print("Cube::init(): allocating memory"); | | arma_extra_debug_print("Cube::init(): allocating memory"); | |
| | | | |
| access::rw(mem) = memory::acquire<eT>(n_elem); | | access::rw(mem) = memory::acquire<eT>(n_elem); | |
|
| | | | |
| arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" ); | | | |
| } | | } | |
| | | | |
| if(n_elem == 0) | | if(n_elem == 0) | |
| { | | { | |
| access::rw(n_rows) = 0; | | access::rw(n_rows) = 0; | |
| access::rw(n_cols) = 0; | | access::rw(n_cols) = 0; | |
| access::rw(n_elem_slice) = 0; | | access::rw(n_elem_slice) = 0; | |
| access::rw(n_slices) = 0; | | access::rw(n_slices) = 0; | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 251 | | skipping to change at line 251 | |
| arma_extra_debug_print("Cube::init(): freeing memory"); | | arma_extra_debug_print("Cube::init(): freeing memory"); | |
| | | | |
| memory::release( access::rw(mem) ); | | memory::release( access::rw(mem) ); | |
| } | | } | |
| } | | } | |
| | | | |
| access::rw(mem_state) = 0; | | access::rw(mem_state) = 0; | |
| | | | |
| if(new_n_elem <= Cube_prealloc::mem_n_elem) | | if(new_n_elem <= Cube_prealloc::mem_n_elem) | |
| { | | { | |
|
| | | arma_extra_debug_print("Cube::init(): using local memory"); | |
| | | | |
| access::rw(mem) = mem_local; | | access::rw(mem) = mem_local; | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_extra_debug_print("Cube::init(): allocating memory"); | | arma_extra_debug_print("Cube::init(): allocating memory"); | |
| | | | |
| access::rw(mem) = memory::acquire<eT>(new_n_elem); | | access::rw(mem) = memory::acquire<eT>(new_n_elem); | |
|
| | | | |
| arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" ); | | | |
| } | | } | |
| | | | |
| if(new_n_elem > 0) | | if(new_n_elem > 0) | |
| { | | { | |
| access::rw(n_rows) = in_n_rows; | | access::rw(n_rows) = in_n_rows; | |
| access::rw(n_cols) = in_n_cols; | | access::rw(n_cols) = in_n_cols; | |
| access::rw(n_elem_slice) = in_n_rows*in_n_cols; | | access::rw(n_elem_slice) = in_n_rows*in_n_cols; | |
| access::rw(n_slices) = in_n_slices; | | access::rw(n_slices) = in_n_slices; | |
| access::rw(n_elem) = new_n_elem; | | access::rw(n_elem) = new_n_elem; | |
| | | | |
| | | | |
| skipping to change at line 853 | | skipping to change at line 853 | |
| const uword subcube_n_cols = in_col2 - in_col1 + 1; | | const uword subcube_n_cols = in_col2 - in_col1 + 1; | |
| const uword subcube_n_slices = in_slice2 - in_slice1 + 1; | | const uword subcube_n_slices = in_slice2 - in_slice1 + 1; | |
| | | | |
| return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row
s, subcube_n_cols, subcube_n_slices); | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_row
s, subcube_n_cols, subcube_n_slices); | |
| } | | } | |
| | | | |
| //! creation of subview_cube (generic subcube) | | //! creation of subview_cube (generic subcube) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| subview_cube<eT> | | subview_cube<eT> | |
|
| | | Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_ | |
| | | slice1, const SizeCube& s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | const uword l_n_slices = n_slices; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | const uword s_n_slices = s.n_slices; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_c | |
| | | ols) || ( in_slice1 >= l_n_slices) | |
| | | || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_c | |
| | | ols) || ((in_slice1 + s_n_slices) > l_n_slices), | |
| | | "Cube::subcube(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n | |
| | | _cols, s_n_slices); | |
| | | } | |
| | | | |
| | | //! creation of subview_cube (generic subcube) | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview_cube<eT> | |
| | | Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_ | |
| | | slice1, const SizeCube& s) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | const uword l_n_slices = n_slices; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | const uword s_n_slices = s.n_slices; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_c | |
| | | ols) || ( in_slice1 >= l_n_slices) | |
| | | || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_c | |
| | | ols) || ((in_slice1 + s_n_slices) > l_n_slices), | |
| | | "Cube::subcube(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n | |
| | | _cols, s_n_slices); | |
| | | } | |
| | | | |
| | | //! creation of subview_cube (generic subcube) | |
| | | template<typename eT> | |
| | | inline | |
| | | subview_cube<eT> | |
| Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) | | Cube<eT>::subcube(const span& row_span, const span& col_span, const span& s
lice_span) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool row_all = row_span.whole; | | const bool row_all = row_span.whole; | |
| const bool col_all = col_span.whole; | | const bool col_all = col_span.whole; | |
| const bool slice_all = slice_span.whole; | | const bool slice_all = slice_span.whole; | |
| | | | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| | | | |
| skipping to change at line 954 | | skipping to change at line 1006 | |
| inline | | inline | |
| const subview_cube<eT> | | const subview_cube<eT> | |
| Cube<eT>::operator()(const span& row_span, const span& col_span, const span
& slice_span) const | | Cube<eT>::operator()(const span& row_span, const span& col_span, const span
& slice_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return (*this).subcube(row_span, col_span, slice_span); | | return (*this).subcube(row_span, col_span, slice_span); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | inline | |
| | | subview_cube<eT> | |
| | | Cube<eT>::operator()(const uword in_row1, const uword in_col1, const uword | |
| | | in_slice1, const SizeCube& s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).subcube(in_row1, in_col1, in_slice1, s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview_cube<eT> | |
| | | Cube<eT>::operator()(const uword in_row1, const uword in_col1, const uword | |
| | | in_slice1, const SizeCube& s) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).subcube(in_row1, in_col1, in_slice1, s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| arma_inline | | arma_inline | |
| subview_cube<eT> | | subview_cube<eT> | |
| Cube<eT>::tube(const uword in_row1, const uword in_col1) | | Cube<eT>::tube(const uword in_row1, const uword in_col1) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ((in_row1 >= n_rows) || (in_col1 >= n_cols)), | | ((in_row1 >= n_rows) || (in_col1 >= n_cols)), | |
| "Cube::tube(): indices out of bounds" | | "Cube::tube(): indices out of bounds" | |
| | | | |
| skipping to change at line 1026 | | skipping to change at line 1098 | |
| "Cube::tube(): indices out of bounds or incorrectly used" | | "Cube::tube(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| const uword subcube_n_rows = in_row2 - in_row1 + 1; | | const uword subcube_n_rows = in_row2 - in_row1 + 1; | |
| const uword subcube_n_cols = in_col2 - in_col1 + 1; | | const uword subcube_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcu
be_n_cols, n_slices); | | return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcu
be_n_cols, n_slices); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | subview_cube<eT> | |
| | | Cube<eT>::tube(const uword in_row1, const uword in_col1, const SizeMat& s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "Cube::tube(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n | |
| | | _slices); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview_cube<eT> | |
| | | Cube<eT>::tube(const uword in_row1, const uword in_col1, const SizeMat& s) | |
| | | const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "Cube::tube(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview_cube<eT>(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n | |
| | | _slices); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| subview_cube<eT> | | subview_cube<eT> | |
| Cube<eT>::tube(const span& row_span, const span& col_span) | | Cube<eT>::tube(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; | |
| const bool col_all = col_span.whole; | | const bool col_all = col_span.whole; | |
| | | | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| skipping to change at line 2195 | | skipping to change at line 2311 | |
| const uword in_slice1 = slice_span.a; | | const uword in_slice1 = slice_span.a; | |
| const uword in_slice2 = slice_span.b; | | const uword in_slice2 = slice_span.b; | |
| | | | |
| const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2)
&& (in_row2 < n_rows) ); | | const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2)
&& (in_row2 < n_rows) ); | |
| const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2)
&& (in_col2 < n_cols) ); | | const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2)
&& (in_col2 < n_cols) ); | |
| const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice
2) && (in_slice2 < n_slices) ); | | const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice
2) && (in_slice2 < n_slices) ); | |
| | | | |
| return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) ); | | return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) ); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | arma_warn_unused | |
| | | bool | |
| | | Cube<eT>::in_range(const uword in_row, const uword in_col, const uword in_s | |
| | | lice, const SizeCube& s) const | |
| | | { | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | const uword l_n_slices = n_slices; | |
| | | | |
| | | if( | |
| | | ( in_row >= l_n_rows) || ( in_col >= l_n_col | |
| | | s) || ( in_slice >= l_n_slices) | |
| | | || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_col | |
| | | s) || ((in_slice + s.n_slices) > l_n_slices) | |
| | | ) | |
| | | { | |
| | | return false; | |
| | | } | |
| | | else | |
| | | { | |
| | | return true; | |
| | | } | |
| | | } | |
| | | | |
| //! returns a pointer to array of eTs used by the cube | | //! returns a pointer to array of eTs used by the cube | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT* | | eT* | |
| Cube<eT>::memptr() | | Cube<eT>::memptr() | |
| { | | { | |
| return const_cast<eT*>(mem); | | return const_cast<eT*>(mem); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 2509 | | skipping to change at line 2648 | |
| return (*this).fill(eT(1)); | | return (*this).fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::randu() | | Cube<eT>::randu() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eop_aux_randu<eT>::fill( memptr(), n_elem ); | | arma_rng::randu<eT>::fill( memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::randu(const uword in_rows, const uword in_cols, const uword in_sl
ices) | | Cube<eT>::randu(const uword in_rows, const uword in_cols, const uword in_sl
ices) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 2533 | | skipping to change at line 2672 | |
| return (*this).randu(); | | return (*this).randu(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::randn() | | Cube<eT>::randn() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eop_aux_randn<eT>::fill( memptr(), n_elem ); | | arma_rng::randn<eT>::fill( memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Cube<eT>& | | const Cube<eT>& | |
| Cube<eT>::randn(const uword in_rows, const uword in_cols, const uword in_sl
ices) | | Cube<eT>::randn(const uword in_rows, const uword in_cols, const uword in_sl
ices) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 3075 | | skipping to change at line 3214 | |
| | | | |
| //! returns the number of elements in this cube | | //! returns the number of elements in this cube | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| uword | | uword | |
| Cube<eT>::size() const | | Cube<eT>::size() const | |
| { | | { | |
| return n_elem; | | return n_elem; | |
| } | | } | |
| | | | |
|
| // template<typename eT> | | template<typename eT> | |
| // inline | | inline | |
| // void | | void | |
| // Cube<eT>::swap(Cube<eT>& B) | | Cube<eT>::swap(Cube<eT>& B) | |
| // { | | { | |
| // // TODO | | Cube<eT>& A = (*this); | |
| // } | | | |
| | | arma_extra_debug_sigprint(arma_boost::format("A = %x B = %x") % &A % &B | |
| | | ); | |
| | | | |
| | | if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem > Cube_prealloc | |
| | | ::mem_n_elem) && (B.n_elem > Cube_prealloc::mem_n_elem) ) | |
| | | { | |
| | | A.delete_mat(); | |
| | | B.delete_mat(); | |
| | | | |
| | | std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); | |
| | | std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); | |
| | | std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); | |
| | | std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); | |
| | | std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); | |
| | | std::swap( access::rw(A.mem), access::rw(B.mem) ); | |
| | | | |
| | | A.create_mat(); | |
| | | B.create_mat(); | |
| | | } | |
| | | else | |
| | | if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem <= Cube_preallo | |
| | | c::mem_n_elem) && (B.n_elem <= Cube_prealloc::mem_n_elem) ) | |
| | | { | |
| | | A.delete_mat(); | |
| | | B.delete_mat(); | |
| | | | |
| | | std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); | |
| | | std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); | |
| | | std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); | |
| | | std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); | |
| | | std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); | |
| | | | |
| | | const uword N = (std::max)(A.n_elem, B.n_elem); | |
| | | | |
| | | eT* A_mem = A.memptr(); | |
| | | eT* B_mem = B.memptr(); | |
| | | | |
| | | for(uword i=0; i<N; ++i) { std::swap( A_mem[i], B_mem[i] ); } | |
| | | | |
| | | A.create_mat(); | |
| | | B.create_mat(); | |
| | | } | |
| | | else | |
| | | { | |
| | | // generic swap | |
| | | | |
| | | if(A.n_elem <= B.n_elem) | |
| | | { | |
| | | Cube<eT> C = A; | |
| | | | |
| | | A.steal_mem(B); | |
| | | B.steal_mem(C); | |
| | | } | |
| | | else | |
| | | { | |
| | | Cube<eT> C = B; | |
| | | | |
| | | B.steal_mem(A); | |
| | | A.steal_mem(C); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| //! try to steal the memory from a given cube; | | //! try to steal the memory from a given cube; | |
| //! if memory can't be stolen, copy the given cube | | //! if memory can't be stolen, copy the given cube | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Cube<eT>::steal_mem(Cube<eT>& x) | | Cube<eT>::steal_mem(Cube<eT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(this != &x) | | if(this != &x) | |
| { | | { | |
|
| if( (mem_state <= 1) && (x.mem_state <= 1) && (x.n_elem > Cube_prealloc
::mem_n_elem) ) | | if( (mem_state <= 1) && ( ((x.mem_state == 0) && (x.n_elem > Cube_preal
loc::mem_n_elem)) || (x.mem_state == 1) ) ) | |
| { | | { | |
| reset(); | | reset(); | |
| | | | |
| const uword x_n_slices = x.n_slices; | | const uword x_n_slices = x.n_slices; | |
| | | | |
| access::rw(n_rows) = x.n_rows; | | access::rw(n_rows) = x.n_rows; | |
| access::rw(n_cols) = x.n_cols; | | access::rw(n_cols) = x.n_cols; | |
| access::rw(n_elem_slice) = x.n_elem_slice; | | access::rw(n_elem_slice) = x.n_elem_slice; | |
| access::rw(n_slices) = x_n_slices; | | access::rw(n_slices) = x_n_slices; | |
| access::rw(n_elem) = x.n_elem; | | access::rw(n_elem) = x.n_elem; | |
|
| | | access::rw(mem_state) = x.mem_state; | |
| access::rw(mem) = x.mem; | | access::rw(mem) = x.mem; | |
| | | | |
| if(x_n_slices > Cube_prealloc::mat_ptrs_size) | | if(x_n_slices > Cube_prealloc::mat_ptrs_size) | |
| { | | { | |
| access::rw( mat_ptrs) = x.mat_ptrs; | | access::rw( mat_ptrs) = x.mat_ptrs; | |
| access::rw(x.mat_ptrs) = 0; | | access::rw(x.mat_ptrs) = 0; | |
| } | | } | |
| else | | else | |
| { | | { | |
| access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local
); | | access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local
); | |
| | | | |
End of changes. 13 change blocks. |
| 14 lines changed or deleted | | 234 lines changed or added | |
|
| Mat_bones.hpp | | Mat_bones.hpp | |
| | | | |
| skipping to change at line 184 | | skipping to change at line 184 | |
| | | | |
| inline subview<eT> rows(const span& row_span); | | inline subview<eT> rows(const span& row_span); | |
| inline const subview<eT> rows(const span& row_span) const; | | inline const subview<eT> rows(const span& row_span) const; | |
| | | | |
| arma_inline subview<eT> cols(const span& col_span); | | arma_inline subview<eT> cols(const span& col_span); | |
| arma_inline const subview<eT> cols(const span& col_span) const; | | arma_inline const subview<eT> cols(const span& col_span) const; | |
| | | | |
| arma_inline subview<eT> submat(const uword in_row1, const uword in_
col1, const uword in_row2, const uword in_col2); | | arma_inline subview<eT> submat(const uword in_row1, const uword in_
col1, const uword in_row2, const uword in_col2); | |
| arma_inline const subview<eT> submat(const uword in_row1, const uword in_
col1, const uword in_row2, const uword in_col2) const; | | arma_inline const subview<eT> submat(const uword in_row1, const uword in_
col1, const uword in_row2, const uword in_col2) const; | |
| | | | |
|
| | | arma_inline subview<eT> submat(const uword in_row1, const uword in_ | |
| | | col1, const SizeMat& s); | |
| | | arma_inline const subview<eT> submat(const uword in_row1, const uword in_ | |
| | | col1, const SizeMat& s) const; | |
| | | | |
| inline subview<eT> submat (const span& row_span, const span
& col_span); | | inline subview<eT> submat (const span& row_span, const span
& col_span); | |
| inline const subview<eT> submat (const span& row_span, const span
& col_span) const; | | inline const subview<eT> submat (const span& row_span, const span
& col_span) const; | |
| | | | |
| inline subview<eT> operator()(const span& row_span, const span
& col_span); | | inline subview<eT> operator()(const span& row_span, const span
& col_span); | |
| inline const subview<eT> operator()(const span& row_span, const span
& col_span) const; | | inline const subview<eT> operator()(const span& row_span, const span
& col_span) const; | |
| | | | |
|
| | | inline subview<eT> operator()(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s); | |
| | | inline const subview<eT> operator()(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s) const; | |
| | | | |
| template<typename T1> arma_inline subview_elem1<eT,T1> elem(const B
ase<uword,T1>& a); | | template<typename T1> arma_inline subview_elem1<eT,T1> elem(const B
ase<uword,T1>& a); | |
| template<typename T1> arma_inline const subview_elem1<eT,T1> elem(const B
ase<uword,T1>& a) const; | | template<typename T1> arma_inline const subview_elem1<eT,T1> elem(const B
ase<uword,T1>& a) const; | |
| | | | |
| template<typename T1> arma_inline subview_elem1<eT,T1> operator()(c
onst Base<uword,T1>& a); | | template<typename T1> arma_inline subview_elem1<eT,T1> operator()(c
onst Base<uword,T1>& a); | |
| template<typename T1> arma_inline const subview_elem1<eT,T1> operator()(c
onst Base<uword,T1>& a) const; | | template<typename T1> arma_inline const subview_elem1<eT,T1> operator()(c
onst Base<uword,T1>& a) const; | |
| | | | |
| template<typename T1, typename T2> arma_inline subview_elem2<eT,T1,
T2> elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci); | | template<typename T1, typename T2> arma_inline subview_elem2<eT,T1,
T2> elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci); | |
| template<typename T1, typename T2> arma_inline const subview_elem2<eT,T1,
T2> elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci) const; | | template<typename T1, typename T2> arma_inline const subview_elem2<eT,T1,
T2> elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci) const; | |
| | | | |
| template<typename T1, typename T2> arma_inline subview_elem2<eT,T1,
T2> submat(const Base<uword,T1>& ri, const Base<uword,T2>& ci); | | template<typename T1, typename T2> arma_inline subview_elem2<eT,T1,
T2> submat(const Base<uword,T1>& ri, const Base<uword,T2>& ci); | |
| | | | |
| skipping to change at line 329 | | skipping to change at line 335 | |
| inline arma_warn_unused bool is_finite() const; | | inline arma_warn_unused bool is_finite() const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword ii) const; | | arma_inline arma_warn_unused bool in_range(const uword ii) const; | |
| arma_inline arma_warn_unused bool in_range(const span& x ) const; | | arma_inline arma_warn_unused bool in_range(const span& x ) const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | |
| | | | |
|
| | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uwor | |
| | | d in_col, const SizeMat& s) const; | |
| | | | |
| arma_inline arma_warn_unused eT* colptr(const uword in_col); | | arma_inline arma_warn_unused eT* colptr(const uword in_col); | |
| arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; | | arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; | |
| | | | |
| arma_inline arma_warn_unused eT* memptr(); | | arma_inline arma_warn_unused eT* memptr(); | |
| arma_inline arma_warn_unused const eT* memptr() const; | | arma_inline arma_warn_unused const eT* memptr() const; | |
| | | | |
| inline void impl_print(const std::string& extra_text) const; | | inline void impl_print(const std::string& extra_text) const; | |
| inline void impl_print(std::ostream& user_stream, const std::string& extr
a_text) const; | | inline void impl_print(std::ostream& user_stream, const std::string& extr
a_text) const; | |
| | | | |
| inline void impl_raw_print(const std::string& extra_text) const; | | inline void impl_raw_print(const std::string& extra_text) const; | |
| inline void impl_raw_print(std::ostream& user_stream, const std::string&
extra_text) const; | | inline void impl_raw_print(std::ostream& user_stream, const std::string&
extra_text) const; | |
| | | | |
| template<typename eT2, typename expr> | | template<typename eT2, typename expr> | |
| inline void copy_size(const Base<eT2,expr>& X); | | inline void copy_size(const Base<eT2,expr>& X); | |
| | | | |
| inline void set_size(const uword in_elem); | | inline void set_size(const uword in_elem); | |
| inline void set_size(const uword in_rows, const uword in_cols); | | inline void set_size(const uword in_rows, const uword in_cols); | |
| | | | |
| inline void resize(const uword in_elem); | | inline void resize(const uword in_elem); | |
| inline void resize(const uword in_rows, const uword in_cols); | | inline void resize(const uword in_rows, const uword in_cols); | |
|
| | | | |
| inline void reshape(const uword in_rows, const uword in_cols, const uwor
d dim = 0); | | inline void reshape(const uword in_rows, const uword in_cols, const uwor
d dim = 0); | |
| | | | |
| template<typename functor> | | template<typename functor> | |
| inline const Mat& transform(functor F); | | inline const Mat& transform(functor F); | |
| | | | |
| template<typename functor> | | template<typename functor> | |
| inline const Mat& imbue(functor F); | | inline const Mat& imbue(functor F); | |
| | | | |
| arma_hot inline const Mat& fill(const eT val); | | arma_hot inline const Mat& fill(const eT val); | |
| | | | |
| | | | |
End of changes. 4 change blocks. |
| 0 lines changed or deleted | | 14 lines changed or added | |
|
| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 147 | | skipping to change at line 147 | |
| ( | | ( | |
| ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) | | ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) | |
| ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) ) | | ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) ) | |
| : false | | : false | |
| ), | | ), | |
| "Mat::init(): requested size is too large" | | "Mat::init(): requested size is too large" | |
| ); | | ); | |
| | | | |
| if(n_elem <= arma_config::mat_prealloc) | | if(n_elem <= arma_config::mat_prealloc) | |
| { | | { | |
|
| | | arma_extra_debug_print("Mat::init(): using local memory"); | |
| | | | |
| access::rw(mem) = mem_local; | | access::rw(mem) = mem_local; | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_extra_debug_print("Mat::init(): allocating memory"); | | arma_extra_debug_print("Mat::init(): allocating memory"); | |
| | | | |
| access::rw(mem) = memory::acquire<eT>(n_elem); | | access::rw(mem) = memory::acquire<eT>(n_elem); | |
|
| | | | |
| arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); | | | |
| } | | } | |
| } | | } | |
| | | | |
| //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | | //! internal matrix construction; if the requested size is small enough, me
mory from the stack is used. otherwise memory is allocated via 'new' | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols) | | Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols) | |
| { | | { | |
| arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | | arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols
= %d") % in_n_rows % in_n_cols ); | |
| | | | |
| skipping to change at line 202 | | skipping to change at line 202 | |
| in_n_cols = 1; | | in_n_cols = 1; | |
| } | | } | |
| else | | else | |
| if(t_vec_state == 2) | | if(t_vec_state == 2) | |
| { | | { | |
| in_n_rows = 1; | | in_n_rows = 1; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| arma_debug_set_error | | if(t_vec_state == 1) | |
| ( | | { | |
| err_state, | | arma_debug_set_error | |
| err_msg, | | ( | |
| ( ((t_vec_state == 1) && (in_n_cols != 1)) || ((t_vec_state == 2) & | | err_state, | |
| & (in_n_rows != 1)) ), | | err_msg, | |
| "Mat::init(): object is a row or column vector; requested size is n | | (in_n_cols != 1), | |
| ot compatible" | | "Mat::init(): requested size is not compatible with column vector | |
| ); | | layout" | |
| | | ); | |
| | | } | |
| | | else | |
| | | if(t_vec_state == 2) | |
| | | { | |
| | | arma_debug_set_error | |
| | | ( | |
| | | err_state, | |
| | | err_msg, | |
| | | (in_n_rows != 1), | |
| | | "Mat::init(): requested size is not compatible with row vector la | |
| | | yout" | |
| | | ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // ensure that n_elem can hold the result of (n_rows * n_cols) | | // ensure that n_elem can hold the result of (n_rows * n_cols) | |
| | | | |
| arma_debug_set_error | | arma_debug_set_error | |
| ( | | ( | |
| err_state, | | err_state, | |
| err_msg, | | err_msg, | |
| ( | | ( | |
| | | | |
| skipping to change at line 258 | | skipping to change at line 272 | |
| if(old_n_elem > arma_config::mat_prealloc) | | if(old_n_elem > arma_config::mat_prealloc) | |
| { | | { | |
| arma_extra_debug_print("Mat::init(): freeing memory"); | | arma_extra_debug_print("Mat::init(): freeing memory"); | |
| | | | |
| memory::release( access::rw(mem) ); | | memory::release( access::rw(mem) ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(new_n_elem <= arma_config::mat_prealloc) | | if(new_n_elem <= arma_config::mat_prealloc) | |
| { | | { | |
|
| | | arma_extra_debug_print("Mat::init(): using local memory"); | |
| | | | |
| access::rw(mem) = mem_local; | | access::rw(mem) = mem_local; | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_extra_debug_print("Mat::init(): allocating memory"); | | arma_extra_debug_print("Mat::init(): allocating memory"); | |
| | | | |
| access::rw(mem) = memory::acquire<eT>(new_n_elem); | | access::rw(mem) = memory::acquire<eT>(new_n_elem); | |
|
| | | | |
| arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); | | | |
| } | | } | |
| | | | |
| access::rw(n_rows) = in_n_rows; | | access::rw(n_rows) = in_n_rows; | |
| access::rw(n_cols) = in_n_cols; | | access::rw(n_cols) = in_n_cols; | |
| access::rw(n_elem) = new_n_elem; | | access::rw(n_elem) = new_n_elem; | |
| access::rw(mem_state) = 0; | | access::rw(mem_state) = 0; | |
| } | | } | |
| } | | } | |
| | | | |
| //! create the matrix from a textual description | | //! create the matrix from a textual description | |
| | | | |
| skipping to change at line 336 | | skipping to change at line 350 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(text); | | init(text); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! internal function to create the matrix from a textual description | | //! internal function to create the matrix from a textual description | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::init(const std::string& text) | | Mat<eT>::init(const std::string& text_orig) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | const bool replace_commas = (is_cx<eT>::yes) ? false : ( text_orig.find(' | |
| | | ,') != std::string::npos ); | |
| | | | |
| | | std::string* text_mod = (replace_commas) ? new std::string(text_orig) : N | |
| | | ULL; | |
| | | | |
| | | const std::string& text = (replace_commas) ? ( std::replace((*text_mod).b | |
| | | egin(), (*text_mod).end(), ',', ' '), (*text_mod) ) : text_orig; | |
| | | | |
| // | | // | |
| // work out the size | | // work out the size | |
| | | | |
| uword t_n_rows = 0; | | uword t_n_rows = 0; | |
| uword t_n_cols = 0; | | uword t_n_cols = 0; | |
| | | | |
| bool t_n_cols_found = false; | | bool t_n_cols_found = false; | |
| | | | |
| std::string token; | | std::string token; | |
| | | | |
| std::string::size_type line_start = 0; | | std::string::size_type line_start = 0; | |
| std::string::size_type line_end = 0; | | std::string::size_type line_end = 0; | |
| | | | |
|
| | | std::stringstream line_stream; | |
| | | | |
| while( line_start < text.length() ) | | while( line_start < text.length() ) | |
| { | | { | |
|
| | | | |
| line_end = text.find(';', line_start); | | line_end = text.find(';', line_start); | |
| | | | |
| if(line_end == std::string::npos) | | if(line_end == std::string::npos) | |
|
| | | { | |
| line_end = text.length()-1; | | line_end = text.length()-1; | |
|
| | | } | |
| | | | |
| std::string::size_type line_len = line_end - line_start + 1; | | std::string::size_type line_len = line_end - line_start + 1; | |
|
| std::stringstream line_stream( text.substr(line_start,line_len) ); | | | |
| | | line_stream.clear(); | |
| | | line_stream.str( text.substr(line_start,line_len) ); | |
| | | | |
| 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(line_n_cols > 0) | | if(line_n_cols > 0) | |
| { | | { | |
| if(t_n_cols_found == false) | | if(t_n_cols_found == false) | |
| { | | { | |
|
| t_n_cols = line_n_cols; | | t_n_cols = line_n_cols; | |
| t_n_cols_found = true; | | t_n_cols_found = true; | |
| } | | } | |
| else | | else | |
|
| | | { | |
| arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent n
umber of columns in given string"); | | arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent n
umber of columns in given string"); | |
|
| | | } | |
| | | | |
| ++t_n_rows; | | ++t_n_rows; | |
| } | | } | |
|
| line_start = line_end+1; | | | |
| | | | |
|
| | | line_start = line_end+1; | |
| } | | } | |
| | | | |
| Mat<eT>& x = *this; | | Mat<eT>& x = *this; | |
| x.set_size(t_n_rows, t_n_cols); | | x.set_size(t_n_rows, t_n_cols); | |
| | | | |
| line_start = 0; | | line_start = 0; | |
|
| line_end = 0; | | line_end = 0; | |
| | | | |
| uword urow = 0; | | uword urow = 0; | |
| | | | |
| while( line_start < text.length() ) | | while( line_start < text.length() ) | |
| { | | { | |
|
| | | | |
| line_end = text.find(';', line_start); | | line_end = text.find(';', line_start); | |
| | | | |
| if(line_end == std::string::npos) | | if(line_end == std::string::npos) | |
|
| | | { | |
| line_end = text.length()-1; | | line_end = text.length()-1; | |
|
| | | } | |
| | | | |
| std::string::size_type line_len = line_end - line_start + 1; | | std::string::size_type line_len = line_end - line_start + 1; | |
|
| std::stringstream line_stream( text.substr(line_start,line_len) ); | | | |
| | | line_stream.clear(); | |
| | | line_stream.str( text.substr(line_start,line_len) ); | |
| | | | |
| // uword ucol = 0; | | // uword ucol = 0; | |
| // while(line_stream >> token) | | // while(line_stream >> token) | |
| // { | | // { | |
| // x.at(urow,ucol) = strtod(token.c_str(), 0); | | // x.at(urow,ucol) = strtod(token.c_str(), 0); | |
| // ++ucol; | | // ++ucol; | |
| // } | | // } | |
| | | | |
| uword ucol = 0; | | uword ucol = 0; | |
| eT val; | | eT val; | |
| while(line_stream >> val) | | while(line_stream >> val) | |
| { | | { | |
| x.at(urow,ucol) = val; | | x.at(urow,ucol) = val; | |
| ++ucol; | | ++ucol; | |
| } | | } | |
| | | | |
| ++urow; | | ++urow; | |
| line_start = line_end+1; | | line_start = line_end+1; | |
| } | | } | |
| | | | |
|
| | | if(replace_commas) | |
| | | { | |
| | | delete text_mod; | |
| | | } | |
| } | | } | |
| | | | |
| //! create the matrix from std::vector | | //! create the matrix from std::vector | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const std::vector<eT>& x) | | Mat<eT>::Mat(const std::vector<eT>& x) | |
| : n_rows(uword(x.size())) | | : n_rows(uword(x.size())) | |
| , n_cols(1) | | , n_cols(1) | |
| , n_elem(uword(x.size())) | | , n_elem(uword(x.size())) | |
| , vec_state(0) | | , vec_state(0) | |
| | | | |
| skipping to change at line 496 | | skipping to change at line 530 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| init(list); | | init(list); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| Mat<eT>::Mat(Mat<eT>&& in_mat) | | Mat<eT>::Mat(Mat<eT>&& X) | |
| : n_rows(0) | | : n_rows (X.n_rows) | |
| , n_cols(0) | | , n_cols (X.n_cols) | |
| , n_elem(0) | | , n_elem (X.n_elem) | |
| , vec_state(0) | | , vec_state(0 ) | |
| , mem_state(0) | | , mem_state(0 ) | |
| , mem() | | , mem ( ) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % th | |
| arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") | | is % &X); | |
| % this % &in_mat); | | | |
| | | if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || ( | |
| | | X.mem_state == 1) || (X.mem_state == 2) ) | |
| | | { | |
| | | access::rw(mem_state) = X.mem_state; | |
| | | access::rw(mem) = X.mem; | |
| | | | |
| | | access::rw(X.n_rows) = 0; | |
| | | access::rw(X.n_cols) = 0; | |
| | | access::rw(X.n_elem) = 0; | |
| | | access::rw(X.mem_state) = 0; | |
| | | access::rw(X.mem) = 0; | |
| | | } | |
| | | else | |
| | | { | |
| | | init_cold(); | |
| | | | |
|
| (*this).steal_mem(in_mat); | | arrayops::copy( memptr(), X.mem, X.n_elem ); | |
| | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
|
| Mat<eT>::operator=(Mat<eT>&& in_mat) | | Mat<eT>::operator=(Mat<eT>&& X) | |
| { | | { | |
|
| arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x")
% this % &in_mat); | | arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % th
is % &X); | |
| | | | |
|
| (*this).steal_mem(in_mat); | | (*this).steal_mem(X); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| #endif | | #endif | |
| | | | |
| //! Set the matrix to be equal to the specified scalar. | | //! Set the matrix to be equal to the specified scalar. | |
| //! NOTE: the size of the matrix will be 1x1 | | //! NOTE: the size of the matrix will be 1x1 | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| | | | |
| skipping to change at line 704 | | skipping to change at line 753 | |
| { | | { | |
| for(uword ucol=0; ucol < local_n_cols; ++ucol) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| for(uword urow=0; urow < local_n_rows; ++urow) | | for(uword urow=0; urow < local_n_rows; ++urow) | |
| { | | { | |
| *out_mem = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol)); | | *out_mem = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol)); | |
| out_mem++; | | out_mem++; | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! EXPERIMENTAL: swap the contents of this matrix, denoted as matrix A, wi
th given matrix B | | //! swap the contents of this matrix, denoted as matrix A, with given matri
x B | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::swap(Mat<eT>& B) | | Mat<eT>::swap(Mat<eT>& B) | |
| { | | { | |
| Mat<eT>& A = (*this); | | Mat<eT>& A = (*this); | |
| | | | |
| arma_extra_debug_sigprint(arma_boost::format("A = %x B = %x") % &A % &B
); | | arma_extra_debug_sigprint(arma_boost::format("A = %x B = %x") % &A % &B
); | |
| | | | |
|
| arma_debug_check( (A.vec_state != B.vec_state), "Mat::swap(): incompatibl | | bool layout_ok = false; | |
| e object types" ); | | | |
| | | if(A.vec_state == B.vec_state) | |
| | | { | |
| | | layout_ok = true; | |
| | | } | |
| | | else | |
| | | { | |
| | | const uhword A_vec_state = A.vec_state; | |
| | | const uhword B_vec_state = B.vec_state; | |
| | | | |
| | | const bool A_absorbs_B = (A_vec_state == 0) || ( (A_vec_state == 1) && | |
| | | (B.n_cols == 1) ) || ( (A_vec_state == 2) && (B.n_rows == 1) ); | |
| | | const bool B_absorbs_A = (B_vec_state == 0) || ( (B_vec_state == 1) && | |
| | | (A.n_cols == 1) ) || ( (B_vec_state == 2) && (A.n_rows == 1) ); | |
| | | | |
| | | layout_ok = A_absorbs_B && B_absorbs_A; | |
| | | } | |
| | | | |
| const uhword A_mem_state = A.mem_state; | | const uhword A_mem_state = A.mem_state; | |
| const uhword B_mem_state = B.mem_state; | | const uhword B_mem_state = B.mem_state; | |
| | | | |
|
| if( (A_mem_state == 0) && (B_mem_state == 0) ) | | if( (A_mem_state == 0) && (B_mem_state == 0) && layout_ok ) | |
| { | | { | |
| const uword A_n_elem = A.n_elem; | | const uword A_n_elem = A.n_elem; | |
| const uword B_n_elem = B.n_elem; | | const uword B_n_elem = B.n_elem; | |
| | | | |
| const bool A_use_local_mem = (A_n_elem <= arma_config::mat_prealloc); | | const bool A_use_local_mem = (A_n_elem <= arma_config::mat_prealloc); | |
| const bool B_use_local_mem = (B_n_elem <= arma_config::mat_prealloc); | | const bool B_use_local_mem = (B_n_elem <= arma_config::mat_prealloc); | |
| | | | |
| if( (A_use_local_mem == false) && (B_use_local_mem == false) ) | | if( (A_use_local_mem == false) && (B_use_local_mem == false) ) | |
| { | | { | |
| std::swap( access::rw(A.mem), access::rw(B.mem) ); | | std::swap( access::rw(A.mem), access::rw(B.mem) ); | |
| | | | |
| skipping to change at line 772 | | skipping to change at line 836 | |
| | | | |
| access::rw(B.mem) = A.mem; | | access::rw(B.mem) = A.mem; | |
| access::rw(A.mem) = A_mem_local; | | access::rw(A.mem) = A_mem_local; | |
| } | | } | |
| | | | |
| std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); | | std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); | |
| std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); | | std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); | |
| std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); | | std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); | |
| } | | } | |
| else | | else | |
|
| if( (A_mem_state == 3) && (B_mem_state == 3) ) | | if( (A_mem_state <= 2) && (B_mem_state <= 2) && (A.n_elem == B.n_elem) &&
layout_ok ) | |
| { | | { | |
|
| arma_debug_check( ((A.n_rows != B.n_rows) || (A.n_cols != B.n_cols)), " | | std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); | |
| Mat::swap(): incompatible object types" ); | | std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); | |
| | | | |
| const uword N = A.n_elem; | | const uword N = A.n_elem; | |
| | | | |
| eT* A_mem = A.memptr(); | | eT* A_mem = A.memptr(); | |
| eT* B_mem = B.memptr(); | | eT* B_mem = B.memptr(); | |
| | | | |
| for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } | | for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } | |
| } | | } | |
| else | | else | |
|
| | | if( (A.n_rows == B.n_rows) && (A.n_cols == B.n_cols) ) | |
| { | | { | |
|
| arma_bad("Mat::swap(): incompatible object types"); | | const uword N = A.n_elem; | |
| | | | |
| | | eT* A_mem = A.memptr(); | |
| | | eT* B_mem = B.memptr(); | |
| | | | |
| | | for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } | |
| | | } | |
| | | else | |
| | | { | |
| | | // generic swap to handle remaining cases | |
| | | | |
| | | if(A.n_elem <= B.n_elem) | |
| | | { | |
| | | Mat<eT> C = A; | |
| | | | |
| | | A.steal_mem(B); | |
| | | B.steal_mem(C); | |
| | | } | |
| | | else | |
| | | { | |
| | | Mat<eT> C = B; | |
| | | | |
| | | B.steal_mem(A); | |
| | | A.steal_mem(C); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! try to steal the memory from a given matrix; | | //! try to steal the memory from a given matrix; | |
| //! if memory can't be stolen, copy the given matrix | | //! if memory can't be stolen, copy the given matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::steal_mem(Mat<eT>& x) | | Mat<eT>::steal_mem(Mat<eT>& x) | |
| { | | { | |
| | | | |
| skipping to change at line 817 | | skipping to change at line 907 | |
| const uword t_mem_state = mem_state; | | const uword t_mem_state = mem_state; | |
| | | | |
| bool layout_ok = false; | | bool layout_ok = false; | |
| | | | |
| if(t_vec_state == x_vec_state) | | if(t_vec_state == x_vec_state) | |
| { | | { | |
| layout_ok = true; | | layout_ok = true; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if( (t_vec_state == 1) && ( x_n_cols == 1) ) | | if( (t_vec_state == 1) && (x_n_cols == 1) ) { layout_ok = true; } | |
| { | | if( (t_vec_state == 2) && (x_n_rows == 1) ) { layout_ok = true; } | |
| layout_ok = true; | | | |
| } | | | |
| | | | |
| if( (t_vec_state == 2) && ( x_n_rows == 1) ) | | | |
| { | | | |
| layout_ok = true; | | | |
| } | | | |
| } | | } | |
| | | | |
|
| if( (t_mem_state <= 1) && (x_mem_state <= 1) && (x_n_elem > arma_config
::mat_prealloc) && (layout_ok == true) ) | | if( (t_mem_state <= 1) && ( ((x_mem_state == 0) && (x_n_elem > arma_con
fig::mat_prealloc)) || (x_mem_state == 1) ) && layout_ok ) | |
| { | | { | |
| reset(); | | reset(); | |
|
| // note: calling reset() also prevents fixed size matrices from chang
ing size or using non-local memory | | | |
| | | | |
|
| access::rw(n_rows) = x_n_rows; | | access::rw(n_rows) = x_n_rows; | |
| access::rw(n_cols) = x_n_cols; | | access::rw(n_cols) = x_n_cols; | |
| access::rw(n_elem) = x_n_elem; | | access::rw(n_elem) = x_n_elem; | |
| access::rw(mem) = x.mem; | | access::rw(mem_state) = x_mem_state; | |
| | | access::rw(mem) = x.mem; | |
| | | | |
| access::rw(x.n_rows) = 0; | | access::rw(x.n_rows) = 0; | |
| access::rw(x.n_cols) = 0; | | access::rw(x.n_cols) = 0; | |
| access::rw(x.n_elem) = 0; | | access::rw(x.n_elem) = 0; | |
| access::rw(x.mem_state) = 0; | | access::rw(x.mem_state) = 0; | |
| access::rw(x.mem) = 0; | | access::rw(x.mem) = 0; | |
| } | | } | |
| else | | else | |
| { | | { | |
| (*this).operator=(x); | | (*this).operator=(x); | |
| | | | |
| skipping to change at line 2011 | | skipping to change at line 2094 | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| const SpProxy<T1> p(m.get_ref()); | | const SpProxy<T1> p(m.get_ref()); | |
| | | | |
| access::rw(n_rows) = p.get_n_rows(); | | access::rw(n_rows) = p.get_n_rows(); | |
| access::rw(n_cols) = p.get_n_cols(); | | access::rw(n_cols) = p.get_n_cols(); | |
| access::rw(n_elem) = p.get_n_elem(); | | access::rw(n_elem) = p.get_n_elem(); | |
| | | | |
| init_cold(); | | init_cold(); | |
|
| fill(eT(0)); | | | |
| | | zeros(); | |
| | | | |
| typename SpProxy<T1>::const_iterator_type it = p.begin(); | | typename SpProxy<T1>::const_iterator_type it = p.begin(); | |
| typename SpProxy<T1>::const_iterator_type it_end = p.end(); | | typename SpProxy<T1>::const_iterator_type it_end = p.end(); | |
| | | | |
| while(it != it_end) | | while(it != it_end) | |
| { | | { | |
| at(it.row(), it.col()) = (*it); | | at(it.row(), it.col()) = (*it); | |
| ++it; | | ++it; | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 2035 | | skipping to change at line 2119 | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::operator=(const SpBase<eT, T1>& m) | | Mat<eT>::operator=(const SpBase<eT, T1>& m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const SpProxy<T1> p(m.get_ref()); | | const SpProxy<T1> p(m.get_ref()); | |
| | | | |
| init_warm(p.get_n_rows(), p.get_n_cols()); | | init_warm(p.get_n_rows(), p.get_n_cols()); | |
| | | | |
|
| fill(eT(0)); | | zeros(); | |
| | | | |
| typename SpProxy<T1>::const_iterator_type it = p.begin(); | | typename SpProxy<T1>::const_iterator_type it = p.begin(); | |
| typename SpProxy<T1>::const_iterator_type it_end = p.end(); | | typename SpProxy<T1>::const_iterator_type it_end = p.end(); | |
| | | | |
| while(it != it_end) | | while(it != it_end) | |
| { | | { | |
| at(it.row(), it.col()) = (*it); | | at(it.row(), it.col()) = (*it); | |
| ++it; | | ++it; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 2605 | | skipping to change at line 2689 | |
| ); | | ); | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| const uword subview_n_cols = in_col2 - in_col1 + 1; | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_col
s); | | return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_col
s); | |
| } | | } | |
| | | | |
| //! creation of subview (submatrix) | | //! creation of subview (submatrix) | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | subview<eT> | |
| | | Mat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "Mat::submat(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols); | |
| | | } | |
| | | | |
| | | //! creation of subview (submatrix) | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const subview<eT> | |
| | | Mat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& s) | |
| | | const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "Mat::submat(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return subview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols); | |
| | | } | |
| | | | |
| | | //! creation of subview (submatrix) | |
| | | template<typename eT> | |
| inline | | inline | |
| subview<eT> | | subview<eT> | |
| Mat<eT>::submat(const span& row_span, const span& col_span) | | Mat<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; | |
| const bool col_all = col_span.whole; | | const bool col_all = col_span.whole; | |
| | | | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| skipping to change at line 2692 | | skipping to change at line 2822 | |
| inline | | inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::operator()(const span& row_span, const span& col_span) const | | Mat<eT>::operator()(const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return (*this).submat(row_span, col_span); | | return (*this).submat(row_span, col_span); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | inline | |
| | | subview<eT> | |
| | | Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat | |
| | | & s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).submat(in_row1, in_col1, s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview<eT> | |
| | | Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat | |
| | | & s) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).submat(in_row1, in_col1, s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
| subview_elem1<eT,T1> | | subview_elem1<eT,T1> | |
| Mat<eT>::elem(const Base<uword,T1>& a) | | Mat<eT>::elem(const Base<uword,T1>& a) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return subview_elem1<eT,T1>(*this, a); | | return subview_elem1<eT,T1>(*this, a); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 4481 | | skipping to change at line 4631 | |
| | | | |
| const uword in_col1 = col_span.a; | | const uword in_col1 = col_span.a; | |
| const uword in_col2 = col_span.b; | | const uword in_col2 = col_span.b; | |
| | | | |
| const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (i
n_row2 < n_rows) ); | | const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (i
n_row2 < n_rows) ); | |
| const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (i
n_col2 < n_cols) ); | | const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (i
n_col2 < n_cols) ); | |
| | | | |
| return ( (rows_ok == true) && (cols_ok == true) ); | | return ( (rows_ok == true) && (cols_ok == true) ); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | arma_inline | |
| | | arma_warn_unused | |
| | | bool | |
| | | Mat<eT>::in_range(const uword in_row, const uword in_col, const SizeMat& s) | |
| | | const | |
| | | { | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) | |
| | | > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) | |
| | | { | |
| | | return false; | |
| | | } | |
| | | else | |
| | | { | |
| | | return true; | |
| | | } | |
| | | } | |
| | | | |
| //! returns a pointer to array of eTs for a specified column; no bounds che
ck | | //! returns a pointer to array of eTs for a specified column; no bounds che
ck | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT* | | eT* | |
| Mat<eT>::colptr(const uword in_col) | | Mat<eT>::colptr(const uword in_col) | |
| { | | { | |
| return & access::rw(mem[in_col*n_rows]); | | return & access::rw(mem[in_col*n_rows]); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 4888 | | skipping to change at line 5057 | |
| return fill(eT(1)); | | return fill(eT(1)); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randu() | | Mat<eT>::randu() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eop_aux_randu<eT>::fill( memptr(), n_elem ); | | arma_rng::randu<eT>::fill( memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randu(const uword in_elem) | | Mat<eT>::randu(const uword in_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 4924 | | skipping to change at line 5093 | |
| return (*this).randu(); | | return (*this).randu(); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randn() | | Mat<eT>::randn() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eop_aux_randn<eT>::fill( memptr(), n_elem ); | | arma_rng::randn<eT>::fill( memptr(), n_elem ); | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randn(const uword in_elem) | | Mat<eT>::randn(const uword in_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
End of changes. 46 change blocks. |
| 63 lines changed or deleted | | 243 lines changed or added | |
|
| SpMat_bones.hpp | | SpMat_bones.hpp | |
| | | | |
| skipping to change at line 66 | | skipping to change at line 66 | |
| * row row_indices[col_ptrs[i]]. This array is of length (n_cols + 2); t
he | | * row row_indices[col_ptrs[i]]. This array is of length (n_cols + 2); t
he | |
| * element col_ptrs[n_cols] should be equal to n_nonzero, and the element | | * element col_ptrs[n_cols] should be equal to n_nonzero, and the element | |
| * col_ptrs[n_cols + 1] is an invalid very large value that ensures the | | * col_ptrs[n_cols + 1] is an invalid very large value that ensures the | |
| * integrity of iterators. | | * integrity of iterators. | |
| */ | | */ | |
| const uword* const col_ptrs; | | const uword* const col_ptrs; | |
| | | | |
| inline SpMat(); //! Size will be 0x0 (empty). | | inline SpMat(); //! Size will be 0x0 (empty). | |
| inline ~SpMat(); | | inline ~SpMat(); | |
| | | | |
|
| inline SpMat(const uword in_rows, const uword in_cols); | | inline SpMat(const uword in_rows, const uword in_cols); | |
| | | | |
| inline SpMat(const char* text); | | inline SpMat(const char* text); | |
| inline const SpMat& operator=(const char* text); | | inline const SpMat& operator=(const char* text); | |
| inline SpMat(const std::string& text); | | inline SpMat(const std::string& text); | |
| inline const SpMat& operator=(const std::string& text); | | inline const SpMat& operator=(const std::string& text); | |
| inline SpMat(const SpMat<eT>& x); | | inline SpMat(const SpMat<eT>& x); | |
| | | | |
|
| | | #if defined(ARMA_USE_CXX11) | |
| | | inline SpMat(SpMat&& m); | |
| | | inline const SpMat& operator=(SpMat&& m); | |
| | | #endif | |
| | | | |
| template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& loc
ations, const Base<eT,T2>& values, const bool sort_locations = true); | | template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& loc
ations, const Base<eT,T2>& values, const bool sort_locations = true); | |
| template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& loc
ations, const Base<eT,T2>& values, const uword n_rows, const uword n_cols,
const bool sort_locations = true); | | template<typename T1, typename T2> inline SpMat(const Base<uword,T1>& loc
ations, const Base<eT,T2>& values, const uword n_rows, const uword n_cols,
const bool sort_locations = true); | |
| | | | |
| template<typename T1, typename T2, typename T3> inline SpMat(const Base<u
word,T1>& rowind, const Base<uword,T2>& colptr, const Base<eT,T3>& values,
const uword n_rows, const uword n_cols); | | template<typename T1, typename T2, typename T3> inline SpMat(const Base<u
word,T1>& rowind, const Base<uword,T2>& colptr, const Base<eT,T3>& values,
const uword n_rows, const uword n_cols); | |
| | | | |
| inline const SpMat& operator=(const eT val); //! Sets size to 1x1. | | inline const SpMat& operator=(const eT val); //! Sets size to 1x1. | |
| inline const SpMat& operator*=(const eT val); | | inline const SpMat& operator*=(const eT val); | |
| inline const SpMat& operator/=(const eT val); | | inline const SpMat& operator/=(const eT val); | |
| // operator+=(val) and operator-=(val) are not defined as they don't make
sense for sparse matrices | | // operator+=(val) and operator-=(val) are not defined as they don't make
sense for sparse matrices | |
| | | | |
| | | | |
| skipping to change at line 192 | | skipping to change at line 197 | |
| | | | |
| arma_inline SpSubview<eT> rows(const uword in_row1, const uword in_
row2); | | arma_inline SpSubview<eT> rows(const uword in_row1, const uword in_
row2); | |
| arma_inline const SpSubview<eT> rows(const uword in_row1, const uword in_
row2) const; | | arma_inline const SpSubview<eT> rows(const uword in_row1, const uword in_
row2) const; | |
| | | | |
| arma_inline SpSubview<eT> cols(const uword in_col1, const uword in_
col2); | | arma_inline SpSubview<eT> cols(const uword in_col1, const uword in_
col2); | |
| arma_inline const SpSubview<eT> cols(const uword in_col1, const uword in_
col2) const; | | arma_inline const SpSubview<eT> cols(const uword in_col1, const uword in_
col2) const; | |
| | | | |
| arma_inline SpSubview<eT> submat(const uword in_row1, const uword i
n_col1, const uword in_row2, const uword in_col2); | | arma_inline SpSubview<eT> submat(const uword in_row1, const uword i
n_col1, const uword in_row2, const uword in_col2); | |
| arma_inline const SpSubview<eT> submat(const uword in_row1, const uword i
n_col1, const uword in_row2, const uword in_col2) const; | | arma_inline const SpSubview<eT> submat(const uword in_row1, const uword i
n_col1, const uword in_row2, const uword in_col2) const; | |
| | | | |
|
| | | arma_inline SpSubview<eT> submat(const uword in_row1, const uword i | |
| | | n_col1, const SizeMat& s); | |
| | | arma_inline const SpSubview<eT> submat(const uword in_row1, const uword i | |
| | | n_col1, const SizeMat& s) const; | |
| | | | |
| inline SpSubview<eT> submat (const span& row_span, const sp
an& col_span); | | inline SpSubview<eT> submat (const span& row_span, const sp
an& col_span); | |
| inline const SpSubview<eT> submat (const span& row_span, const sp
an& col_span) const; | | inline const SpSubview<eT> submat (const span& row_span, const sp
an& col_span) const; | |
| | | | |
| 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; | |
| | | | |
|
| | | arma_inline SpSubview<eT> operator()(const uword in_row1, const uwo | |
| | | rd in_col1, const SizeMat& s); | |
| | | arma_inline const SpSubview<eT> operator()(const uword in_row1, const uwo | |
| | | rd in_col1, const SizeMat& s) const; | |
| | | | |
| /** | | /** | |
| * Element access; access the i'th element (works identically to the Mat
accessors). | | * Element access; access the i'th element (works identically to the Mat
accessors). | |
| * If there is nothing at element i, 0 is returned. | | * If there is nothing at element i, 0 is returned. | |
| * | | * | |
| * @param i Element to access. | | * @param i Element to access. | |
| */ | | */ | |
| arma_inline arma_warn_unused SpValProxy<SpMat<eT> > operator[] (const uwo
rd i); | | arma_inline arma_warn_unused SpValProxy<SpMat<eT> > operator[] (const uwo
rd i); | |
| arma_inline arma_warn_unused eT operator[] (const uwo
rd i) const; | | arma_inline arma_warn_unused eT operator[] (const uwo
rd i) const; | |
| arma_inline arma_warn_unused SpValProxy<SpMat<eT> > at (const uwo
rd i); | | arma_inline arma_warn_unused SpValProxy<SpMat<eT> > at (const uwo
rd i); | |
| arma_inline arma_warn_unused eT at (const uwo
rd i) const; | | arma_inline arma_warn_unused eT at (const uwo
rd i) const; | |
| | | | |
| skipping to change at line 238 | | skipping to change at line 249 | |
| inline arma_warn_unused bool is_finite() const; | | inline arma_warn_unused bool is_finite() const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword i) const; | | arma_inline arma_warn_unused bool in_range(const uword i) const; | |
| arma_inline arma_warn_unused bool in_range(const span& x) const; | | arma_inline arma_warn_unused bool in_range(const span& x) const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | |
| | | | |
|
| | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uwor | |
| | | d in_col, const SizeMat& s) const; | |
| | | | |
| /** | | /** | |
| * Printing the matrix. | | * Printing the matrix. | |
| * | | * | |
| * @param extra_text Text to prepend to output. | | * @param extra_text Text to prepend to output. | |
| */ | | */ | |
| inline void impl_print(const std::string& extra_text) const; | | inline void impl_print(const std::string& extra_text) const; | |
| inline void impl_print(std::ostream& user_stream, const std::string& extr
a_text) const; | | inline void impl_print(std::ostream& user_stream, const std::string& extr
a_text) const; | |
| | | | |
| inline void impl_raw_print(const std::string& extra_text) const; | | inline void impl_raw_print(const std::string& extra_text) const; | |
| inline void impl_raw_print(std::ostream& user_stream, const std::string&
extra_text) const; | | inline void impl_raw_print(std::ostream& user_stream, const std::string&
extra_text) const; | |
| | | | |
| skipping to change at line 287 | | skipping to change at line 300 | |
| inline const SpMat& zeros(const uword in_elem); | | inline const SpMat& zeros(const uword in_elem); | |
| inline const SpMat& zeros(const uword in_rows, const uword in_cols); | | inline const SpMat& zeros(const uword in_rows, const uword in_cols); | |
| | | | |
| inline const SpMat& eye(); | | inline const SpMat& eye(); | |
| inline const SpMat& eye(const uword in_rows, const uword in_cols); | | inline const SpMat& eye(const uword in_rows, const uword in_cols); | |
| | | | |
| inline const SpMat& speye(); | | inline const SpMat& speye(); | |
| inline const SpMat& speye(const uword in_rows, const uword in_cols); | | inline const SpMat& speye(const uword in_rows, const uword in_cols); | |
| | | | |
| inline const SpMat& sprandu(const uword in_rows, const uword in_cols, con
st double density); | | inline const SpMat& sprandu(const uword in_rows, const uword in_cols, con
st double density); | |
|
| | | | |
| inline const SpMat& sprandn(const uword in_rows, const uword in_cols, con
st double density); | | inline const SpMat& sprandn(const uword in_rows, const uword in_cols, con
st double density); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| | | | |
| /** | | /** | |
| * 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; | |
| | | | |
End of changes. 6 change blocks. |
| 1 lines changed or deleted | | 20 lines changed or added | |
|
| SpMat_meat.hpp | | SpMat_meat.hpp | |
| | | | |
| skipping to change at line 45 | | skipping to change at line 45 | |
| | | | |
| /** | | /** | |
| * 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); | |
| | | | |
|
| // If necessary, release the memory. | | if(values ) { memory::release(access::rw(values)); } | |
| if (values) | | if(row_indices) { memory::release(access::rw(row_indices)); } | |
| { | | if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } | |
| // values being non-NULL implies row_indices is non-NULL. | | | |
| memory::release(access::rw(values)); | | | |
| memory::release(access::rw(row_indices)); | | | |
| } | | | |
| | | | |
| // Column pointers always must be deleted. | | | |
| memory::release(access::rw(col_ptrs)); | | | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Constructor with size given. | | * Constructor with size given. | |
| */ | | */ | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| SpMat<eT>::SpMat(const uword in_rows, const uword in_cols) | | SpMat<eT>::SpMat(const uword in_rows, const uword in_cols) | |
| : n_rows(0) | | : n_rows(0) | |
| , n_cols(0) | | , n_cols(0) | |
| | | | |
| skipping to change at line 151 | | skipping to change at line 144 | |
| , vec_state(0) | | , vec_state(0) | |
| , values(NULL) | | , values(NULL) | |
| , row_indices(NULL) | | , row_indices(NULL) | |
| , col_ptrs(NULL) | | , col_ptrs(NULL) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| init(x); | | init(x); | |
| } | | } | |
| | | | |
|
| | | #if defined(ARMA_USE_CXX11) | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpMat<eT>::SpMat(SpMat<eT>&& in_mat) | |
| | | : n_rows(0) | |
| | | , n_cols(0) | |
| | | , n_elem(0) | |
| | | , n_nonzero(0) | |
| | | , vec_state(0) | |
| | | , values(NULL) | |
| | | , row_indices(NULL) | |
| | | , col_ptrs(NULL) | |
| | | { | |
| | | arma_extra_debug_sigprint_this(this); | |
| | | arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") | |
| | | % this % &in_mat); | |
| | | | |
| | | (*this).steal_mem(in_mat); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpMat<eT>& | |
| | | SpMat<eT>::operator=(SpMat<eT>&& in_mat) | |
| | | { | |
| | | arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") | |
| | | % this % &in_mat); | |
| | | | |
| | | (*this).steal_mem(in_mat); | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | #endif | |
| | | | |
| //! Insert a large number of values at once. | | //! Insert a large number of values at once. | |
| //! locations.row[0] should be row indices, locations.row[1] should be colu
mn indices, | | //! locations.row[0] should be row indices, locations.row[1] should be colu
mn indices, | |
| //! and values should be the corresponding values. | | //! and values should be the corresponding values. | |
| //! If sort_locations is false, then it is assumed that the locations and v
alues | | //! If sort_locations is false, then it is assumed that the locations and v
alues | |
| //! are already sorted in column-major ordering. | | //! are already sorted in column-major ordering. | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
| SpMat<eT>::SpMat(const Base<uword,T1>& locations_expr, const Base<eT,T2>& v
als_expr, const bool sort_locations) | | SpMat<eT>::SpMat(const Base<uword,T1>& locations_expr, const Base<eT,T2>& v
als_expr, const bool sort_locations) | |
| : n_rows(0) | | : n_rows(0) | |
| | | | |
| skipping to change at line 2239 | | skipping to change at line 2266 | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| const uword subview_n_cols = in_col2 - in_col1 + 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); | | return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c
ols); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& | |
| | | s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "SpMat::submat(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& | |
| | | s) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | |
| | | ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | |
| | | "SpMat::submat(): indices or size out of bounds" | |
| | | ); | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols); | |
| | | } | |
| | | | |
| | | 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; | |
| const bool col_all = col_span.whole; | | const bool col_all = col_span.whole; | |
| | | | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| | | | |
| const uword in_row1 = row_all ? 0 : row_span.a; | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | | |
| skipping to change at line 2274 | | skipping to change at line 2345 | |
| , | | , | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| 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(); | |
| | | | |
| const bool row_all = row_span.whole; | | const bool row_all = row_span.whole; | |
| const bool col_all = col_span.whole; | | const bool col_all = col_span.whole; | |
| | | | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| | | | |
| const uword in_row1 = row_all ? 0 : row_span.a; | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | | |
| skipping to change at line 2324 | | skipping to change at line 2395 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const SpSubview<eT> | | const SpSubview<eT> | |
| SpMat<eT>::operator()(const span& row_span, const span& col_span) const | | SpMat<eT>::operator()(const span& row_span, const span& col_span) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return submat(row_span, col_span); | | return submat(row_span, col_span); | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | arma_inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeM | |
| | | at& s) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).submat(in_row1, in_col1, s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeM | |
| | | at& s) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return (*this).submat(in_row1, in_col1, s); | |
| | | } | |
| | | | |
| /** | | /** | |
| * Element access; acces the i'th element (works identically to the Mat acc
essors). | | * Element access; acces the i'th element (works identically to the Mat acc
essors). | |
| * If there is nothing at element i, 0 is returned. | | * If there is nothing at element i, 0 is returned. | |
| * | | * | |
| * @param i Element to access. | | * @param i Element to access. | |
| */ | | */ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| | | | |
| skipping to change at line 2605 | | skipping to change at line 2696 | |
| const uword in_col1 = col_span.a; | | const uword in_col1 = col_span.a; | |
| const uword in_col2 = col_span.b; | | const uword in_col2 = col_span.b; | |
| | | | |
| const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (i
n_row2 < n_rows) ); | | const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (i
n_row2 < n_rows) ); | |
| const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (i
n_col2 < n_cols) ); | | const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (i
n_col2 < n_cols) ); | |
| | | | |
| return ( (rows_ok == true) && (cols_ok == true) ); | | return ( (rows_ok == true) && (cols_ok == true) ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | arma_inline | |
| | | arma_warn_unused | |
| | | bool | |
| | | SpMat<eT>::in_range(const uword in_row, const uword in_col, const SizeMat& | |
| | | s) const | |
| | | { | |
| | | const uword l_n_rows = n_rows; | |
| | | const uword l_n_cols = n_cols; | |
| | | | |
| | | if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) | |
| | | > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) | |
| | | { | |
| | | return false; | |
| | | } | |
| | | else | |
| | | { | |
| | | return true; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| SpMat<eT>::impl_print(const std::string& extra_text) const | | SpMat<eT>::impl_print(const std::string& extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(extra_text.length() != 0) | | if(extra_text.length() != 0) | |
| { | | { | |
| const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); | | const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); | |
| | | | |
| | | | |
| skipping to change at line 3010 | | skipping to change at line 3120 | |
| | | | |
| zeros(in_rows, in_cols); | | zeros(in_rows, in_cols); | |
| | | | |
| mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); | | mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); | |
| | | | |
| if(n_nonzero == 0) | | if(n_nonzero == 0) | |
| { | | { | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| eop_aux_randu<eT>::fill( access::rwp(values), n_nonzero ); | | arma_rng::randu<eT>::fill( access::rwp(values), n_nonzero ); | |
| | | | |
| uvec indices = linspace<uvec>( 0u, in_rows*in_cols-1, n_nonzero ); | | uvec indices = linspace<uvec>( 0u, in_rows*in_cols-1, n_nonzero ); | |
| | | | |
| // perturb the indices | | // perturb the indices | |
| for(uword i=1; i < n_nonzero-1; ++i) | | for(uword i=1; i < n_nonzero-1; ++i) | |
| { | | { | |
| const uword index_left = indices[i-1]; | | const uword index_left = indices[i-1]; | |
| const uword index_right = indices[i+1]; | | const uword index_right = indices[i+1]; | |
| | | | |
| const uword center = (index_left + index_right) / 2; | | const uword center = (index_left + index_right) / 2; | |
| | | | |
| skipping to change at line 3085 | | skipping to change at line 3195 | |
| | | | |
| zeros(in_rows, in_cols); | | zeros(in_rows, in_cols); | |
| | | | |
| mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); | | mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); | |
| | | | |
| if(n_nonzero == 0) | | if(n_nonzero == 0) | |
| { | | { | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
|
| eop_aux_randn<eT>::fill( access::rwp(values), n_nonzero ); | | arma_rng::randn<eT>::fill( access::rwp(values), n_nonzero ); | |
| | | | |
| uvec indices = linspace<uvec>( 0u, in_rows*in_cols-1, n_nonzero ); | | uvec indices = linspace<uvec>( 0u, in_rows*in_cols-1, n_nonzero ); | |
| | | | |
| // perturb the indices | | // perturb the indices | |
| for(uword i=1; i < n_nonzero-1; ++i) | | for(uword i=1; i < n_nonzero-1; ++i) | |
| { | | { | |
| const uword index_left = indices[i-1]; | | const uword index_left = indices[i-1]; | |
| const uword index_right = indices[i+1]; | | const uword index_right = indices[i+1]; | |
| | | | |
| const uword center = (index_left + index_right) / 2; | | const uword center = (index_left + index_right) / 2; | |
| | | | |
| skipping to change at line 3904 | | skipping to change at line 4014 | |
| // Steal memory from another matrix. | | // Steal memory from another matrix. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| SpMat<eT>::steal_mem(SpMat<eT>& x) | | SpMat<eT>::steal_mem(SpMat<eT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(this != &x) | | if(this != &x) | |
| { | | { | |
|
| // Release all the memory. | | if(values ) { memory::release(access::rw(values)); } | |
| memory::release(values); | | if(row_indices) { memory::release(access::rw(row_indices)); } | |
| memory::release(row_indices); | | if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } | |
| memory::release(col_ptrs); | | | |
| | | access::rw(n_rows) = x.n_rows; | |
| // We'll have to copy everything about the other matrix. | | access::rw(n_cols) = x.n_cols; | |
| const uword x_n_rows = x.n_rows; | | access::rw(n_elem) = x.n_elem; | |
| const uword x_n_cols = x.n_cols; | | access::rw(n_nonzero) = x.n_nonzero; | |
| const uword x_n_elem = x.n_elem; | | | |
| const uword x_n_nonzero = x.n_nonzero; | | | |
| | | | |
| access::rw(n_rows) = x_n_rows; | | | |
| access::rw(n_cols) = x_n_cols; | | | |
| access::rw(n_elem) = x_n_elem; | | | |
| access::rw(n_nonzero) = x_n_nonzero; | | | |
| | | | |
| access::rw(values) = x.values; | | access::rw(values) = x.values; | |
| access::rw(row_indices) = x.row_indices; | | access::rw(row_indices) = x.row_indices; | |
| access::rw(col_ptrs) = x.col_ptrs; | | access::rw(col_ptrs) = x.col_ptrs; | |
| | | | |
| // Set other matrix to empty. | | // Set other matrix to empty. | |
| access::rw(x.n_rows) = 0; | | access::rw(x.n_rows) = 0; | |
| access::rw(x.n_cols) = 0; | | access::rw(x.n_cols) = 0; | |
| access::rw(x.n_elem) = 0; | | access::rw(x.n_elem) = 0; | |
| access::rw(x.n_nonzero) = 0; | | access::rw(x.n_nonzero) = 0; | |
| | | | |
End of changes. 10 change blocks. |
| 29 lines changed or deleted | | 142 lines changed or added | |
|
| armadillo | | armadillo | |
| | | | |
| skipping to change at line 15 | | skipping to change at line 15 | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| #ifndef ARMA_INCLUDES | | #ifndef ARMA_INCLUDES | |
| #define ARMA_INCLUDES | | #define ARMA_INCLUDES | |
| | | | |
| #include <cstdlib> | | #include <cstdlib> | |
| #include <cstring> | | #include <cstring> | |
| #include <climits> | | #include <climits> | |
| #include <cmath> | | #include <cmath> | |
|
| | | #include <ctime> | |
| | | | |
| #include <iostream> | | #include <iostream> | |
| #include <fstream> | | #include <fstream> | |
| #include <sstream> | | #include <sstream> | |
| #include <stdexcept> | | #include <stdexcept> | |
| #include <limits> | | #include <limits> | |
| #include <algorithm> | | #include <algorithm> | |
| #include <complex> | | #include <complex> | |
| #include <vector> | | #include <vector> | |
| | | | |
| #include "armadillo_bits/config.hpp" | | #include "armadillo_bits/config.hpp" | |
| #include "armadillo_bits/compiler_setup.hpp" | | #include "armadillo_bits/compiler_setup.hpp" | |
| #include "armadillo_bits/undefine_conflicts.hpp" | | #include "armadillo_bits/undefine_conflicts.hpp" | |
| | | | |
| #if defined(ARMA_USE_CXX11) | | #if defined(ARMA_USE_CXX11) | |
| #include <initializer_list> | | #include <initializer_list> | |
| #include <cstdint> | | #include <cstdint> | |
|
| // TODO: extend wall_clock class to use C++11 chrono library | | #include <chrono> | |
| #endif | | #include <random> | |
| | | | |
|
| #if !defined(ARMA_HAVE_GETTIMEOFDAY) && !defined(ARMA_USE_BOOST_DATE) | | #undef ARMA_USE_BOOST_DATE | |
| #include <ctime> | | | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_HAVE_GETTIMEOFDAY) | | #if defined(ARMA_HAVE_GETTIMEOFDAY) | |
| #include <sys/time.h> | | #include <sys/time.h> | |
| #undef ARMA_USE_BOOST_DATE | | #undef ARMA_USE_BOOST_DATE | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_USE_BOOST_DATE) | | #if defined(ARMA_USE_BOOST_DATE) | |
| #include <boost/date_time/posix_time/posix_time.hpp> | | #include <boost/date_time/posix_time/posix_time.hpp> | |
| #endif | | #endif | |
| | | | |
| skipping to change at line 94 | | skipping to change at line 94 | |
| #endif | | #endif | |
| | | | |
| //! \namespace arma namespace for Armadillo classes and functions | | //! \namespace arma namespace for Armadillo classes and functions | |
| namespace arma | | namespace arma | |
| { | | { | |
| | | | |
| // preliminaries | | // preliminaries | |
| | | | |
| #include "armadillo_bits/forward_bones.hpp" | | #include "armadillo_bits/forward_bones.hpp" | |
| #include "armadillo_bits/arma_static_check.hpp" | | #include "armadillo_bits/arma_static_check.hpp" | |
|
| #include "armadillo_bits/typedef.hpp" | | #include "armadillo_bits/typedef_elem.hpp" | |
| #include "armadillo_bits/typedef_blas_int.hpp" | | #include "armadillo_bits/typedef_elem_check.hpp" | |
| | | #include "armadillo_bits/typedef_mat.hpp" | |
| #include "armadillo_bits/format_wrap.hpp" | | #include "armadillo_bits/format_wrap.hpp" | |
| #include "armadillo_bits/arma_version.hpp" | | #include "armadillo_bits/arma_version.hpp" | |
| #include "armadillo_bits/arma_config.hpp" | | #include "armadillo_bits/arma_config.hpp" | |
| #include "armadillo_bits/traits.hpp" | | #include "armadillo_bits/traits.hpp" | |
| #include "armadillo_bits/promote_type.hpp" | | #include "armadillo_bits/promote_type.hpp" | |
| #include "armadillo_bits/upgrade_val.hpp" | | #include "armadillo_bits/upgrade_val.hpp" | |
| #include "armadillo_bits/restrictors.hpp" | | #include "armadillo_bits/restrictors.hpp" | |
| #include "armadillo_bits/access.hpp" | | #include "armadillo_bits/access.hpp" | |
|
| #include "armadillo_bits/memory.hpp" | | | |
| #include "armadillo_bits/span.hpp" | | #include "armadillo_bits/span.hpp" | |
|
| | | #include "armadillo_bits/distr_param.hpp" | |
| #include "armadillo_bits/constants.hpp" | | #include "armadillo_bits/constants.hpp" | |
| #include "armadillo_bits/constants_compat.hpp" | | #include "armadillo_bits/constants_compat.hpp" | |
| | | | |
|
| | | #if defined(ARMA_USE_CXX11_RNG) | |
| | | #include "armadillo_bits/arma_rng_cxx11.hpp" | |
| | | #include "armadillo_bits/arma_rng.hpp" | |
| | | #else | |
| | | #include "armadillo_bits/arma_rng_cxx98.hpp" | |
| | | #include "armadillo_bits/arma_rng.hpp" | |
| | | #endif | |
| | | | |
| // | | // | |
| // class prototypes | | // class prototypes | |
| | | | |
| #include "armadillo_bits/Base_bones.hpp" | | #include "armadillo_bits/Base_bones.hpp" | |
| #include "armadillo_bits/BaseCube_bones.hpp" | | #include "armadillo_bits/BaseCube_bones.hpp" | |
| #include "armadillo_bits/SpBase_bones.hpp" | | #include "armadillo_bits/SpBase_bones.hpp" | |
| | | | |
| #include "armadillo_bits/blas_bones.hpp" | | #include "armadillo_bits/blas_bones.hpp" | |
| #include "armadillo_bits/lapack_bones.hpp" | | #include "armadillo_bits/lapack_bones.hpp" | |
| #include "armadillo_bits/atlas_bones.hpp" | | #include "armadillo_bits/atlas_bones.hpp" | |
| | | | |
| skipping to change at line 136 | | skipping to change at line 145 | |
| #include "armadillo_bits/podarray_bones.hpp" | | #include "armadillo_bits/podarray_bones.hpp" | |
| #include "armadillo_bits/auxlib_bones.hpp" | | #include "armadillo_bits/auxlib_bones.hpp" | |
| | | | |
| #include "armadillo_bits/injector_bones.hpp" | | #include "armadillo_bits/injector_bones.hpp" | |
| | | | |
| #include "armadillo_bits/Mat_bones.hpp" | | #include "armadillo_bits/Mat_bones.hpp" | |
| #include "armadillo_bits/Col_bones.hpp" | | #include "armadillo_bits/Col_bones.hpp" | |
| #include "armadillo_bits/Row_bones.hpp" | | #include "armadillo_bits/Row_bones.hpp" | |
| #include "armadillo_bits/Cube_bones.hpp" | | #include "armadillo_bits/Cube_bones.hpp" | |
| #include "armadillo_bits/xvec_htrans_bones.hpp" | | #include "armadillo_bits/xvec_htrans_bones.hpp" | |
|
| | | #include "armadillo_bits/SizeMat_bones.hpp" | |
| | | #include "armadillo_bits/SizeCube_bones.hpp" | |
| | | | |
| #include "armadillo_bits/SpValProxy_bones.hpp" | | #include "armadillo_bits/SpValProxy_bones.hpp" | |
| #include "armadillo_bits/SpMat_bones.hpp" | | #include "armadillo_bits/SpMat_bones.hpp" | |
| #include "armadillo_bits/SpCol_bones.hpp" | | #include "armadillo_bits/SpCol_bones.hpp" | |
| #include "armadillo_bits/SpRow_bones.hpp" | | #include "armadillo_bits/SpRow_bones.hpp" | |
| #include "armadillo_bits/SpSubview_bones.hpp" | | #include "armadillo_bits/SpSubview_bones.hpp" | |
| | | | |
|
| #include "armadillo_bits/typedef_fixed.hpp" | | #include "armadillo_bits/typedef_mat_fixed.hpp" | |
| | | | |
| #include "armadillo_bits/field_bones.hpp" | | #include "armadillo_bits/field_bones.hpp" | |
| #include "armadillo_bits/subview_bones.hpp" | | #include "armadillo_bits/subview_bones.hpp" | |
| #include "armadillo_bits/subview_elem1_bones.hpp" | | #include "armadillo_bits/subview_elem1_bones.hpp" | |
| #include "armadillo_bits/subview_elem2_bones.hpp" | | #include "armadillo_bits/subview_elem2_bones.hpp" | |
| #include "armadillo_bits/subview_field_bones.hpp" | | #include "armadillo_bits/subview_field_bones.hpp" | |
| #include "armadillo_bits/subview_cube_bones.hpp" | | #include "armadillo_bits/subview_cube_bones.hpp" | |
| #include "armadillo_bits/diagview_bones.hpp" | | #include "armadillo_bits/diagview_bones.hpp" | |
| #include "armadillo_bits/subview_each_bones.hpp" | | #include "armadillo_bits/subview_each_bones.hpp" | |
| | | | |
| | | | |
| skipping to change at line 239 | | skipping to change at line 250 | |
| #include "armadillo_bits/glue_cor_bones.hpp" | | #include "armadillo_bits/glue_cor_bones.hpp" | |
| #include "armadillo_bits/glue_kron_bones.hpp" | | #include "armadillo_bits/glue_kron_bones.hpp" | |
| #include "armadillo_bits/glue_cross_bones.hpp" | | #include "armadillo_bits/glue_cross_bones.hpp" | |
| #include "armadillo_bits/glue_join_bones.hpp" | | #include "armadillo_bits/glue_join_bones.hpp" | |
| #include "armadillo_bits/glue_relational_bones.hpp" | | #include "armadillo_bits/glue_relational_bones.hpp" | |
| #include "armadillo_bits/glue_solve_bones.hpp" | | #include "armadillo_bits/glue_solve_bones.hpp" | |
| #include "armadillo_bits/glue_conv_bones.hpp" | | #include "armadillo_bits/glue_conv_bones.hpp" | |
| #include "armadillo_bits/glue_toeplitz_bones.hpp" | | #include "armadillo_bits/glue_toeplitz_bones.hpp" | |
| #include "armadillo_bits/glue_hist_bones.hpp" | | #include "armadillo_bits/glue_hist_bones.hpp" | |
| #include "armadillo_bits/glue_histc_bones.hpp" | | #include "armadillo_bits/glue_histc_bones.hpp" | |
|
| | | #include "armadillo_bits/glue_max_bones.hpp" | |
| | | #include "armadillo_bits/glue_min_bones.hpp" | |
| | | | |
| #include "armadillo_bits/spop_max_bones.hpp" | | #include "armadillo_bits/spop_max_bones.hpp" | |
| #include "armadillo_bits/spop_min_bones.hpp" | | #include "armadillo_bits/spop_min_bones.hpp" | |
| #include "armadillo_bits/spop_sum_bones.hpp" | | #include "armadillo_bits/spop_sum_bones.hpp" | |
| #include "armadillo_bits/spop_strans_bones.hpp" | | #include "armadillo_bits/spop_strans_bones.hpp" | |
| #include "armadillo_bits/spop_htrans_bones.hpp" | | #include "armadillo_bits/spop_htrans_bones.hpp" | |
| #include "armadillo_bits/spop_misc_bones.hpp" | | #include "armadillo_bits/spop_misc_bones.hpp" | |
| #include "armadillo_bits/spop_mean_bones.hpp" | | #include "armadillo_bits/spop_mean_bones.hpp" | |
| #include "armadillo_bits/spop_var_bones.hpp" | | #include "armadillo_bits/spop_var_bones.hpp" | |
| | | | |
| #include "armadillo_bits/spglue_plus_bones.hpp" | | #include "armadillo_bits/spglue_plus_bones.hpp" | |
| #include "armadillo_bits/spglue_minus_bones.hpp" | | #include "armadillo_bits/spglue_minus_bones.hpp" | |
| #include "armadillo_bits/spglue_times_bones.hpp" | | #include "armadillo_bits/spglue_times_bones.hpp" | |
| | | | |
| // | | // | |
|
| // debugging functions | | // low-level debugging and memory handling functions | |
| | | | |
| #include "armadillo_bits/debug.hpp" | | #include "armadillo_bits/debug.hpp" | |
|
| | | #include "armadillo_bits/memory.hpp" | |
| | | | |
| // | | // | |
| // | | // | |
| | | | |
| #include "armadillo_bits/cmath_wrap.hpp" | | #include "armadillo_bits/cmath_wrap.hpp" | |
| | | | |
| // | | // | |
| // classes that underlay metaprogramming | | // classes that underlay metaprogramming | |
| | | | |
| #include "armadillo_bits/unwrap.hpp" | | #include "armadillo_bits/unwrap.hpp" | |
| | | | |
| skipping to change at line 411 | | skipping to change at line 425 | |
| #include "armadillo_bits/fn_cumsum.hpp" | | #include "armadillo_bits/fn_cumsum.hpp" | |
| #include "armadillo_bits/fn_symmat.hpp" | | #include "armadillo_bits/fn_symmat.hpp" | |
| #include "armadillo_bits/fn_syl_lyap.hpp" | | #include "armadillo_bits/fn_syl_lyap.hpp" | |
| #include "armadillo_bits/fn_hist.hpp" | | #include "armadillo_bits/fn_hist.hpp" | |
| #include "armadillo_bits/fn_histc.hpp" | | #include "armadillo_bits/fn_histc.hpp" | |
| #include "armadillo_bits/fn_unique.hpp" | | #include "armadillo_bits/fn_unique.hpp" | |
| #include "armadillo_bits/fn_fft.hpp" | | #include "armadillo_bits/fn_fft.hpp" | |
| #include "armadillo_bits/fn_fft2.hpp" | | #include "armadillo_bits/fn_fft2.hpp" | |
| #include "armadillo_bits/fn_any.hpp" | | #include "armadillo_bits/fn_any.hpp" | |
| #include "armadillo_bits/fn_all.hpp" | | #include "armadillo_bits/fn_all.hpp" | |
|
| | | #include "armadillo_bits/fn_size.hpp" | |
| | | #include "armadillo_bits/fn_numel.hpp" | |
| | | #include "armadillo_bits/fn_inplace_strans.hpp" | |
| | | #include "armadillo_bits/fn_inplace_trans.hpp" | |
| | | #include "armadillo_bits/fn_randi.hpp" | |
| | | | |
| #include "armadillo_bits/fn_speye.hpp" | | #include "armadillo_bits/fn_speye.hpp" | |
| #include "armadillo_bits/fn_spones.hpp" | | #include "armadillo_bits/fn_spones.hpp" | |
| #include "armadillo_bits/fn_sprandn.hpp" | | #include "armadillo_bits/fn_sprandn.hpp" | |
| #include "armadillo_bits/fn_sprandu.hpp" | | #include "armadillo_bits/fn_sprandu.hpp" | |
| | | | |
| // misc stuff | | // misc stuff | |
| | | | |
| #include "armadillo_bits/hdf5_misc.hpp" | | #include "armadillo_bits/hdf5_misc.hpp" | |
| #include "armadillo_bits/fft_engine.hpp" | | #include "armadillo_bits/fft_engine.hpp" | |
| | | | |
| skipping to change at line 449 | | skipping to change at line 468 | |
| #include "armadillo_bits/podarray_meat.hpp" | | #include "armadillo_bits/podarray_meat.hpp" | |
| #include "armadillo_bits/auxlib_meat.hpp" | | #include "armadillo_bits/auxlib_meat.hpp" | |
| | | | |
| #include "armadillo_bits/injector_meat.hpp" | | #include "armadillo_bits/injector_meat.hpp" | |
| | | | |
| #include "armadillo_bits/Mat_meat.hpp" | | #include "armadillo_bits/Mat_meat.hpp" | |
| #include "armadillo_bits/Col_meat.hpp" | | #include "armadillo_bits/Col_meat.hpp" | |
| #include "armadillo_bits/Row_meat.hpp" | | #include "armadillo_bits/Row_meat.hpp" | |
| #include "armadillo_bits/Cube_meat.hpp" | | #include "armadillo_bits/Cube_meat.hpp" | |
| #include "armadillo_bits/xvec_htrans_meat.hpp" | | #include "armadillo_bits/xvec_htrans_meat.hpp" | |
|
| | | #include "armadillo_bits/SizeMat_meat.hpp" | |
| | | #include "armadillo_bits/SizeCube_meat.hpp" | |
| | | | |
| #include "armadillo_bits/field_meat.hpp" | | #include "armadillo_bits/field_meat.hpp" | |
| #include "armadillo_bits/subview_meat.hpp" | | #include "armadillo_bits/subview_meat.hpp" | |
| #include "armadillo_bits/subview_elem1_meat.hpp" | | #include "armadillo_bits/subview_elem1_meat.hpp" | |
| #include "armadillo_bits/subview_elem2_meat.hpp" | | #include "armadillo_bits/subview_elem2_meat.hpp" | |
| #include "armadillo_bits/subview_field_meat.hpp" | | #include "armadillo_bits/subview_field_meat.hpp" | |
| #include "armadillo_bits/subview_cube_meat.hpp" | | #include "armadillo_bits/subview_cube_meat.hpp" | |
| #include "armadillo_bits/diagview_meat.hpp" | | #include "armadillo_bits/diagview_meat.hpp" | |
| #include "armadillo_bits/subview_each_meat.hpp" | | #include "armadillo_bits/subview_each_meat.hpp" | |
| | | | |
| | | | |
| skipping to change at line 526 | | skipping to change at line 547 | |
| #include "armadillo_bits/glue_cor_meat.hpp" | | #include "armadillo_bits/glue_cor_meat.hpp" | |
| #include "armadillo_bits/glue_kron_meat.hpp" | | #include "armadillo_bits/glue_kron_meat.hpp" | |
| #include "armadillo_bits/glue_cross_meat.hpp" | | #include "armadillo_bits/glue_cross_meat.hpp" | |
| #include "armadillo_bits/glue_join_meat.hpp" | | #include "armadillo_bits/glue_join_meat.hpp" | |
| #include "armadillo_bits/glue_relational_meat.hpp" | | #include "armadillo_bits/glue_relational_meat.hpp" | |
| #include "armadillo_bits/glue_solve_meat.hpp" | | #include "armadillo_bits/glue_solve_meat.hpp" | |
| #include "armadillo_bits/glue_conv_meat.hpp" | | #include "armadillo_bits/glue_conv_meat.hpp" | |
| #include "armadillo_bits/glue_toeplitz_meat.hpp" | | #include "armadillo_bits/glue_toeplitz_meat.hpp" | |
| #include "armadillo_bits/glue_hist_meat.hpp" | | #include "armadillo_bits/glue_hist_meat.hpp" | |
| #include "armadillo_bits/glue_histc_meat.hpp" | | #include "armadillo_bits/glue_histc_meat.hpp" | |
|
| | | #include "armadillo_bits/glue_max_meat.hpp" | |
| | | #include "armadillo_bits/glue_min_meat.hpp" | |
| | | | |
| #include "armadillo_bits/spop_max_meat.hpp" | | #include "armadillo_bits/spop_max_meat.hpp" | |
| #include "armadillo_bits/spop_min_meat.hpp" | | #include "armadillo_bits/spop_min_meat.hpp" | |
| #include "armadillo_bits/spop_sum_meat.hpp" | | #include "armadillo_bits/spop_sum_meat.hpp" | |
| #include "armadillo_bits/spop_strans_meat.hpp" | | #include "armadillo_bits/spop_strans_meat.hpp" | |
| #include "armadillo_bits/spop_htrans_meat.hpp" | | #include "armadillo_bits/spop_htrans_meat.hpp" | |
| #include "armadillo_bits/spop_misc_meat.hpp" | | #include "armadillo_bits/spop_misc_meat.hpp" | |
| #include "armadillo_bits/spop_mean_meat.hpp" | | #include "armadillo_bits/spop_mean_meat.hpp" | |
| #include "armadillo_bits/spop_var_meat.hpp" | | #include "armadillo_bits/spop_var_meat.hpp" | |
| | | | |
| | | | |
End of changes. 15 change blocks. |
| 9 lines changed or deleted | | 32 lines changed or added | |
|
| auxlib_meat.hpp | | auxlib_meat.hpp | |
| | | | |
| skipping to change at line 2100 | | skipping to change at line 2100 | |
| | | | |
| lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; | | lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
| lapack::gesvd<eT> | | lapack::gesvd<eT> | |
| ( | | ( | |
| &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &l
du, V.memptr(), &ldvt, work.memptr(), &lwork, &info | | &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &l
du, V.memptr(), &ldvt, work.memptr(), &lwork, &info | |
| ); | | ); | |
| | | | |
|
| op_strans::apply(V,V); // op_strans will work out that an in-place t
ranspose can be done | | op_strans::apply_mat_inplace(V); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| | | | |
| skipping to change at line 2196 | | skipping to change at line 2196 | |
| &m, &n, | | &m, &n, | |
| A.memptr(), &lda, | | A.memptr(), &lda, | |
| S.memptr(), | | S.memptr(), | |
| U.memptr(), &ldu, | | U.memptr(), &ldu, | |
| V.memptr(), &ldvt, | | V.memptr(), &ldvt, | |
| work.memptr(), &lwork, | | work.memptr(), &lwork, | |
| rwork.memptr(), | | rwork.memptr(), | |
| &info | | &info | |
| ); | | ); | |
| | | | |
|
| op_htrans::apply(V,V); // op_htrans will work out that an in-place t
ranspose can be done | | op_htrans::apply_mat_inplace(V); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| | | | |
| skipping to change at line 2331 | | skipping to change at line 2331 | |
| &jobu, &jobvt, | | &jobu, &jobvt, | |
| &m, &n, | | &m, &n, | |
| A.memptr(), &lda, | | A.memptr(), &lda, | |
| S.memptr(), | | S.memptr(), | |
| U.memptr(), &ldu, | | U.memptr(), &ldu, | |
| V.memptr(), &ldvt, | | V.memptr(), &ldvt, | |
| work.memptr(), &lwork, | | work.memptr(), &lwork, | |
| &info | | &info | |
| ); | | ); | |
| | | | |
|
| op_strans::apply(V,V); // op_strans will work out that an in-place t
ranspose can be done | | op_strans::apply_mat_inplace(V); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| | | | |
| skipping to change at line 2472 | | skipping to change at line 2472 | |
| &m, &n, | | &m, &n, | |
| A.memptr(), &lda, | | A.memptr(), &lda, | |
| S.memptr(), | | S.memptr(), | |
| U.memptr(), &ldu, | | U.memptr(), &ldu, | |
| V.memptr(), &ldvt, | | V.memptr(), &ldvt, | |
| work.memptr(), &lwork, | | work.memptr(), &lwork, | |
| rwork.memptr(), | | rwork.memptr(), | |
| &info | | &info | |
| ); | | ); | |
| | | | |
|
| op_htrans::apply(V,V); // op_strans will work out that an in-place t
ranspose can be done | | op_htrans::apply_mat_inplace(V); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| | | | |
| skipping to change at line 2535 | | skipping to change at line 2535 | |
| podarray<eT> work( static_cast<uword>(lwork ) ); | | podarray<eT> work( static_cast<uword>(lwork ) ); | |
| podarray<blas_int> iwork( static_cast<uword>(8*min_mn) ); | | podarray<blas_int> iwork( static_cast<uword>(8*min_mn) ); | |
| | | | |
| lapack::gesdd<eT> | | lapack::gesdd<eT> | |
| ( | | ( | |
| &jobz, &m, &n, | | &jobz, &m, &n, | |
| A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | | A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | |
| work.memptr(), &lwork, iwork.memptr(), &info | | work.memptr(), &lwork, iwork.memptr(), &info | |
| ); | | ); | |
| | | | |
|
| op_strans::apply(V,V); // op_strans will work out that an in-place tra
nspose can be done | | op_strans::apply_mat_inplace(V); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_stop("svd(): use of LAPACK needs to be enabled"); | | arma_stop("svd(): use of LAPACK needs to be enabled"); | |
| | | | |
| skipping to change at line 2599 | | skipping to change at line 2599 | |
| podarray<T> rwork( static_cast<uword>(5*min_mn*min_mn + 7*min_mn
) ); | | podarray<T> rwork( static_cast<uword>(5*min_mn*min_mn + 7*min_mn
) ); | |
| podarray<blas_int> iwork( static_cast<uword>(8*min_mn
) ); | | podarray<blas_int> iwork( static_cast<uword>(8*min_mn
) ); | |
| | | | |
| lapack::cx_gesdd<T> | | lapack::cx_gesdd<T> | |
| ( | | ( | |
| &jobz, &m, &n, | | &jobz, &m, &n, | |
| A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | | A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | |
| work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info | | work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info | |
| ); | | ); | |
| | | | |
|
| op_htrans::apply(V,V); // op_htrans will work out that an in-place tra | | op_htrans::apply_mat_inplace(V); | |
| nspose can be done | | | |
| | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(U); | |
| | | arma_ignore(S); | |
| | | arma_ignore(V); | |
| | | arma_ignore(X); | |
| | | arma_stop("svd(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::svd_dc_econ(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Base<eT,T1>& | |
| | | X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | Mat<eT> A(X.get_ref()); | |
| | | | |
| | | char jobz = 'S'; | |
| | | | |
| | | blas_int m = blas_int(A.n_rows); | |
| | | blas_int n = blas_int(A.n_cols); | |
| | | blas_int min_mn = (std::min)(m,n); | |
| | | blas_int lda = blas_int(A.n_rows); | |
| | | blas_int ldu = m; | |
| | | blas_int ldvt = min_mn; | |
| | | blas_int lwork = 3 * ( 3*min_mn + 4*min_mn*min_mn + 3*min_mn + std::ma | |
| | | x(m,n) ); // based on lapack 3.4 docs, which have a slightly different fo | |
| | | rmula to lapack 3.1 docs | |
| | | blas_int info = 0; | |
| | | | |
| | | if(A.is_empty()) | |
| | | { | |
| | | U.eye(); | |
| | | S.reset(); | |
| | | V.eye( static_cast<uword>(n), static_cast<uword>(min_mn) ); | |
| | | return true; | |
| | | } | |
| | | | |
| | | S.set_size( static_cast<uword>(min_mn) ); | |
| | | | |
| | | U.set_size( static_cast<uword>(m), static_cast<uword>(min_mn) ); | |
| | | | |
| | | V.set_size( static_cast<uword>(min_mn), static_cast<uword>(n) ); | |
| | | | |
| | | podarray<eT> work( static_cast<uword>(lwork ) ); | |
| | | podarray<blas_int> iwork( static_cast<uword>(8*min_mn) ); | |
| | | | |
| | | lapack::gesdd<eT> | |
| | | ( | |
| | | &jobz, &m, &n, | |
| | | A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | |
| | | work.memptr(), &lwork, iwork.memptr(), &info | |
| | | ); | |
| | | | |
| | | op_strans::apply_mat_inplace(V); | |
| | | | |
| | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(U); | |
| | | arma_ignore(S); | |
| | | arma_ignore(V); | |
| | | arma_ignore(X); | |
| | | arma_stop("svd(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::svd_dc_econ(Mat< std::complex<T> >& U, Col<T>& S, Mat< std::complex | |
| | | <T> >& V, const Base< std::complex<T>, T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | typedef std::complex<T> eT; | |
| | | | |
| | | Mat<eT> A(X.get_ref()); | |
| | | | |
| | | char jobz = 'S'; | |
| | | | |
| | | blas_int m = blas_int(A.n_rows); | |
| | | blas_int n = blas_int(A.n_cols); | |
| | | blas_int min_mn = (std::min)(m,n); | |
| | | blas_int max_mn = (std::max)(m,n); | |
| | | blas_int lda = blas_int(A.n_rows); | |
| | | blas_int ldu = m; | |
| | | blas_int ldvt = min_mn; | |
| | | blas_int lwork = 3 * (min_mn*min_mn + 2*min_mn + max_mn); | |
| | | blas_int lrwork = min_mn * (std::max)( 5*min_mn+7, 2*max_mn + 2*min_mn+ | |
| | | 1 ); // based on lapack 3.4 docs, which have a different formula to lapack | |
| | | 3.1 docs | |
| | | blas_int info = 0; | |
| | | | |
| | | if(A.is_empty()) | |
| | | { | |
| | | U.eye(); | |
| | | S.reset(); | |
| | | V.eye( static_cast<uword>(n), static_cast<uword>(min_mn) ); | |
| | | return true; | |
| | | } | |
| | | | |
| | | S.set_size( static_cast<uword>(min_mn) ); | |
| | | | |
| | | U.set_size( static_cast<uword>(m), static_cast<uword>(min_mn) ); | |
| | | | |
| | | V.set_size( static_cast<uword>(min_mn), static_cast<uword>(n) ); | |
| | | | |
| | | podarray<eT> work( static_cast<uword>(lwork ) ); | |
| | | podarray<T> rwork( static_cast<uword>(lrwork ) ); | |
| | | podarray<blas_int> iwork( static_cast<uword>(8*min_mn) ); | |
| | | | |
| | | lapack::cx_gesdd<T> | |
| | | ( | |
| | | &jobz, &m, &n, | |
| | | A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, | |
| | | work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info | |
| | | ); | |
| | | | |
| | | op_htrans::apply_mat_inplace(V); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(U); | | arma_ignore(U); | |
| arma_ignore(S); | | arma_ignore(S); | |
| arma_ignore(V); | | arma_ignore(V); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_stop("svd(): use of LAPACK needs to be enabled"); | | arma_stop("svd(): use of LAPACK needs to be enabled"); | |
| | | | |
| skipping to change at line 3097 | | skipping to change at line 3226 | |
| bool | | bool | |
| auxlib::lyap(Mat<eT>& X, const Mat<eT>& A, const Mat<eT>& Q) | | auxlib::lyap(Mat<eT>& X, const Mat<eT>& A, const Mat<eT>& Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (A.is_square() == false), "lyap(): matrix A is not squa
re"); | | arma_debug_check( (A.is_square() == false), "lyap(): matrix A is not squa
re"); | |
| arma_debug_check( (Q.is_square() == false), "lyap(): matrix Q is not squa
re"); | | arma_debug_check( (Q.is_square() == false), "lyap(): matrix Q is not squa
re"); | |
| arma_debug_check( (A.n_rows != Q.n_rows), "lyap(): matrices A and Q hav
e different dimensions"); | | arma_debug_check( (A.n_rows != Q.n_rows), "lyap(): matrices A and Q hav
e different dimensions"); | |
| | | | |
| Mat<eT> htransA; | | Mat<eT> htransA; | |
|
| op_htrans::apply_noalias(htransA, A); | | op_htrans::apply_mat_noalias(htransA, A); | |
| | | | |
| const Mat<eT> mQ = -Q; | | const Mat<eT> mQ = -Q; | |
| | | | |
| return auxlib::syl(X, A, htransA, mQ); | | return auxlib::syl(X, A, htransA, mQ); | |
| } | | } | |
| | | | |
| // | | // | |
| // dlyap (solution of the discrete Lyapunov equation AXA^H - X + Q = 0) | | // dlyap (solution of the discrete Lyapunov equation AXA^H - X + Q = 0) | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| | | | |
End of changes. 7 change blocks. |
| 8 lines changed or deleted | | 142 lines changed or added | |
|
| debug.hpp | | debug.hpp | |
| | | | |
| skipping to change at line 98 | | skipping to change at line 98 | |
| out << "error: " << x << '\n'; | | out << "error: " << x << '\n'; | |
| out << '\n'; | | out << '\n'; | |
| out.flush(); | | out.flush(); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(x); | | arma_ignore(x); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
|
| throw std::logic_error(""); | | throw std::logic_error( std::string(x) ); | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_cold | | arma_cold | |
| arma_noinline | | arma_noinline | |
| static | | static | |
| void | | 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(); | |
| | | | |
| skipping to change at line 150 | | skipping to change at line 150 | |
| out.flush(); | | out.flush(); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(x); | | arma_ignore(x); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| if(hurl == true) | | if(hurl == true) | |
| { | | { | |
|
| throw std::runtime_error(""); | | throw std::runtime_error( std::string(x) ); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // arma_print | | // arma_print | |
| | | | |
| arma_cold | | arma_cold | |
| inline | | inline | |
| void | | void | |
| arma_print() | | arma_print() | |
| | | | |
| skipping to change at line 964 | | skipping to change at line 964 | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // macros | | // macros | |
| | | | |
| // #define ARMA_STRING1(x) #x | | // #define ARMA_STRING1(x) #x | |
| // #define ARMA_STRING2(x) ARMA_STRING1(x) | | // #define ARMA_STRING2(x) ARMA_STRING1(x) | |
| // #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) | | // #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) | |
| | | | |
|
| #if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG) | | #if defined(ARMA_NO_DEBUG) | |
| | | | |
| #define arma_debug_print arma_print | | | |
| #define arma_debug_warn arma_warn | | | |
| #define arma_debug_check arma_check | | | |
| #define arma_debug_set_error arma_set_error | | | |
| #define arma_debug_assert_same_size arma_assert_same_size | | | |
| #define arma_debug_assert_mul_size arma_assert_mul_size | | | |
| #define arma_debug_assert_trans_mul_size arma_assert_trans_mul_size | | | |
| #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat | | | |
| | | | |
| #else | | | |
| | | | |
| #undef ARMA_EXTRA_DEBUG | | #undef ARMA_EXTRA_DEBUG | |
| | | | |
| #define arma_debug_print true ? (void)0 : arma_print | | #define arma_debug_print true ? (void)0 : arma_print | |
| #define arma_debug_warn true ? (void)0 : arma_warn | | #define arma_debug_warn true ? (void)0 : arma_warn | |
| #define arma_debug_check true ? (void)0 : arma_check | | #define arma_debug_check true ? (void)0 : arma_check | |
| #define arma_debug_set_error true ? (void)0 : arma_set_error | | #define arma_debug_set_error true ? (void)0 : arma_set_error | |
| #define arma_debug_assert_same_size true ? (void)0 : arma_assert_sam
e_size | | #define arma_debug_assert_same_size true ? (void)0 : arma_assert_sam
e_size | |
| #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul
_size | | #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul
_size | |
| #define arma_debug_assert_trans_mul_size true ? (void)0 : arma_assert_tra
ns_mul_size | | #define arma_debug_assert_trans_mul_size true ? (void)0 : arma_assert_tra
ns_mul_size | |
| #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_assert_cub
e_as_mat | | #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_assert_cub
e_as_mat | |
| | | | |
|
| | | #else | |
| | | | |
| | | #define arma_debug_print arma_print | |
| | | #define arma_debug_warn arma_warn | |
| | | #define arma_debug_check arma_check | |
| | | #define arma_debug_set_error arma_set_error | |
| | | #define arma_debug_assert_same_size arma_assert_same_size | |
| | | #define arma_debug_assert_mul_size arma_assert_mul_size | |
| | | #define arma_debug_assert_trans_mul_size arma_assert_trans_mul_size | |
| | | #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat | |
| | | | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_EXTRA_DEBUG) | | #if defined(ARMA_EXTRA_DEBUG) | |
| | | | |
| #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_b
ktprint | | #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_b
ktprint | |
| #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_t
hisprint | | #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_t
hisprint | |
| #define arma_extra_debug_print arma_print | | #define arma_extra_debug_print arma_print | |
| #define arma_extra_debug_warn arma_warn | | #define arma_extra_debug_warn arma_warn | |
| #define arma_extra_debug_check arma_check | | #define arma_extra_debug_check arma_check | |
| | | | |
| | | | |
| skipping to change at line 1037 | | skipping to change at line 1037 | |
| const bool little_endian = (endian_test.b[0] == 1); | | const bool little_endian = (endian_test.b[0] == 1); | |
| const char* nickname = ARMA_VERSION_NAME; | | const char* nickname = ARMA_VERSION_NAME; | |
| | | | |
| std::ostream& out = get_stream_err1(); | | std::ostream& out = get_stream_err1(); | |
| | | | |
| out << "@ ---" << '\n'; | | out << "@ ---" << '\n'; | |
| out << "@ Armadillo " | | out << "@ Armadillo " | |
| << arma_version::major << '.' << arma_version::minor << '.' <<
arma_version::patch | | << arma_version::major << '.' << arma_version::minor << '.' <<
arma_version::patch | |
| << " (" << nickname << ")\n"; | | << " (" << nickname << ")\n"; | |
| | | | |
|
| out << "@ arma_config::mat_prealloc = " << arma_config::mat_preal | | out << "@ arma_config::use_wrapper = " << arma_config::use_wrapper | |
| loc << " element(s)\n"; | | << '\n'; | |
| out << "@ arma_config::atlas = " << arma_config::atlas | | out << "@ arma_config::use_cxx11 = " << arma_config::use_cxx11 | |
| << '\n'; | | << '\n'; | |
| out << "@ arma_config::lapack = " << arma_config::lapack | | out << "@ arma_config::lapack = " << arma_config::lapack | |
| << '\n'; | | << '\n'; | |
| out << "@ arma_config::blas = " << arma_config::blas | | out << "@ arma_config::blas = " << arma_config::blas | |
| << '\n'; | | << '\n'; | |
| out << "@ arma_config::boost = " << arma_config::boost | | out << "@ arma_config::atlas = " << arma_config::atlas | |
| << '\n'; | | << '\n'; | |
| out << "@ arma_config::boost_date = " << arma_config::boost_dat | | out << "@ arma_config::hdf5 = " << arma_config::hdf5 | |
| e << '\n'; | | << '\n'; | |
| out << "@ arma_config::good_comp = " << arma_config::good_comp | | out << "@ arma_config::boost = " << arma_config::boost | |
| << '\n'; | | << '\n'; | |
| out << "@ arma_config::extra_code = " << arma_config::extra_cod | | out << "@ arma_config::boost_date = " << arma_config::boost_date | |
| e << '\n'; | | << '\n'; | |
| out << "@ arma_config::use_cxx11 = " << arma_config::use_cxx11 | | out << "@ arma_config::good_comp = " << arma_config::good_comp | |
| << '\n'; | | << '\n'; | |
| | | out << "@ arma_config::extra_code = " << arma_config::extra_code | |
| | | << '\n'; | |
| | | out << "@ arma_config::mat_prealloc = " << arma_config::mat_preallo | |
| | | c << '\n'; | |
| out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; | | out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; | |
| out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; | | out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; | |
| out << "@ sizeof(int) = " << sizeof(int) << '\n'; | | out << "@ sizeof(int) = " << sizeof(int) << '\n'; | |
| out << "@ sizeof(long) = " << sizeof(long) << '\n'; | | out << "@ sizeof(long) = " << sizeof(long) << '\n'; | |
| out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; | | out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; | |
| out << "@ little_endian = " << little_endian << '\n'; | | out << "@ little_endian = " << little_endian << '\n'; | |
| out << "@ ---" << std::endl; | | out << "@ ---" << std::endl; | |
| } | | } | |
| | | | |
| }; | | }; | |
| | | | |
End of changes. 5 change blocks. |
| 32 lines changed or deleted | | 36 lines changed or added | |
|
| field_bones.hpp | | field_bones.hpp | |
| // Copyright (C) 2008-2013 Conrad Sanderson | | // Copyright (C) 2008-2013 Conrad Sanderson | |
|
| // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup field | | //! \addtogroup field | |
| //! @{ | | //! @{ | |
| | | | |
| struct field_prealloc_n_elem | | struct field_prealloc_n_elem | |
| | | | |
| skipping to change at line 89 | | skipping to change at line 89 | |
| | | | |
| inline subview_field<oT> rows(const uword in_row1, const uword in_r
ow2); | | inline subview_field<oT> rows(const uword in_row1, const uword in_r
ow2); | |
| inline const subview_field<oT> rows(const uword in_row1, const uword in_r
ow2) const; | | inline const subview_field<oT> rows(const uword in_row1, const uword in_r
ow2) const; | |
| | | | |
| inline subview_field<oT> cols(const uword in_col1, const uword in_c
ol2); | | inline subview_field<oT> cols(const uword in_col1, const uword in_c
ol2); | |
| inline const subview_field<oT> cols(const uword in_col1, const uword in_c
ol2) const; | | inline const subview_field<oT> cols(const uword in_col1, const uword in_c
ol2) const; | |
| | | | |
| inline subview_field<oT> subfield(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2); | | inline subview_field<oT> subfield(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2); | |
| inline const subview_field<oT> subfield(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2) const; | | inline const subview_field<oT> subfield(const uword in_row1, const uword
in_col1, const uword in_row2, const uword in_col2) const; | |
| | | | |
|
| | | inline subview_field<oT> subfield(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s); | |
| | | inline const subview_field<oT> subfield(const uword in_row1, const uword | |
| | | in_col1, const SizeMat& s) const; | |
| | | | |
| inline subview_field<oT> subfield (const span& row_span, const spa
n& col_span); | | inline subview_field<oT> subfield (const span& row_span, const spa
n& col_span); | |
| inline const subview_field<oT> subfield (const span& row_span, const spa
n& col_span) const; | | inline const subview_field<oT> subfield (const span& row_span, const spa
n& col_span) const; | |
| | | | |
| inline subview_field<oT> operator()(const span& row_span, const spa
n& col_span); | | inline subview_field<oT> operator()(const span& row_span, const spa
n& col_span); | |
| inline const subview_field<oT> operator()(const span& row_span, const spa
n& col_span) const; | | inline const subview_field<oT> operator()(const span& row_span, const spa
n& col_span) const; | |
| | | | |
|
| | | inline subview_field<oT> operator()(const uword in_row1, const uwor | |
| | | d in_col1, const SizeMat& s); | |
| | | inline const subview_field<oT> operator()(const uword in_row1, const uwor | |
| | | d in_col1, const SizeMat& s) const; | |
| | | | |
| inline void print(const std::string extra_text = "") const; | | inline void print(const std::string extra_text = "") const; | |
| inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | | inline void print(std::ostream& user_stream, const std::string extra_text
= "") const; | |
| | | | |
| inline void fill(const oT& x); | | inline void fill(const oT& x); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| inline void reset_objects(); | | inline void reset_objects(); | |
| | | | |
| arma_inline bool is_empty() const; | | arma_inline bool is_empty() const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword i) const; | | arma_inline arma_warn_unused bool in_range(const uword i) const; | |
| arma_inline arma_warn_unused bool in_range(const span& x) const; | | arma_inline arma_warn_unused bool in_range(const span& x) const; | |
| | | | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const uw
ord in_col) const; | |
| arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const uword in_row, const sp
an& col_span) const; | |
| arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | | arma_inline arma_warn_unused bool in_range(const span& row_span, const sp
an& col_span) const; | |
| | | | |
|
| | | arma_inline arma_warn_unused bool in_range(const uword in_row, const uwor | |
| | | d in_col, const SizeMat& s) const; | |
| | | | |
| inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | | inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const; | |
| | | | |
| inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load(const std::string name, const file_type type = auto_de
tect, const bool print_status = true); | |
| inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | | inline bool load( std::istream& is, const file_type type = auto_de
tect, const bool print_status = true); | |
| | | | |
| inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | | inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const; | |
| inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | | inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const; | |
| | | | |
| inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | | inline bool quiet_load(const std::string name, const file_type type = a
uto_detect); | |
| | | | |
End of changes. 4 change blocks. |
| 1 lines changed or deleted | | 14 lines changed or added | |
|
| fn_det.hpp | | fn_det.hpp | |
| | | | |
| skipping to change at line 29 | | skipping to change at line 29 | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return auxlib::det(X, slow); | | return auxlib::det(X, slow); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | arma_warn_unused | |
| | | typename T1::elem_type | |
| | | det | |
| | | ( | |
| | | const Base<typename T1::elem_type,T1>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method | |
| | | specified" ); | |
| | | | |
| | | const bool slow = (sig == 's'); | |
| | | | |
| | | return auxlib::det(X, slow); | |
| | | } | |
| | | | |
| //! determinant of diagmat | | //! determinant of diagmat | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| arma_warn_unused | | arma_warn_unused | |
| typename T1::elem_type | | typename T1::elem_type | |
| det | | det | |
| ( | | ( | |
| const Op<T1, op_diagmat>& X, | | const Op<T1, op_diagmat>& X, | |
| const bool slow = false | | const bool slow = false | |
| ) | | ) | |
| | | | |
| skipping to change at line 67 | | skipping to change at line 90 | |
| } | | } | |
| | | | |
| if(i < N) | | if(i < N) | |
| { | | { | |
| val1 *= A[i]; | | val1 *= A[i]; | |
| } | | } | |
| | | | |
| return val1 * val2; | | return val1 * val2; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | arma_warn_unused | |
| | | typename T1::elem_type | |
| | | det | |
| | | ( | |
| | | const Op<T1, op_diagmat>& X, | |
| | | const char* method | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method | |
| | | specified" ); | |
| | | | |
| | | return det(X, false); | |
| | | } | |
| | | | |
| //! determinant of a triangular matrix | | //! determinant of a triangular matrix | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| arma_warn_unused | | arma_warn_unused | |
| typename T1::elem_type | | typename T1::elem_type | |
| det | | det | |
| ( | | ( | |
| const Op<T1, op_trimat>& X, | | const Op<T1, op_trimat>& X, | |
| const bool slow = false | | const bool slow = false | |
| ) | | ) | |
| | | | |
| skipping to change at line 107 | | skipping to change at line 149 | |
| } | | } | |
| | | | |
| if(i < N) | | if(i < N) | |
| { | | { | |
| val1 *= P.at(i,i); | | val1 *= P.at(i,i); | |
| } | | } | |
| | | | |
| return val1 * val2; | | return val1 * val2; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | arma_warn_unused | |
| | | typename T1::elem_type | |
| | | det | |
| | | ( | |
| | | const Op<T1, op_trimat>& X, | |
| | | const char* method | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method | |
| | | specified" ); | |
| | | | |
| | | return det(X, false); | |
| | | } | |
| | | | |
| //! determinant of inv(A), without doing the inverse operation | | //! determinant of inv(A), without doing the inverse operation | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| arma_warn_unused | | arma_warn_unused | |
| typename T1::elem_type | | typename T1::elem_type | |
| det | | det | |
| ( | | ( | |
|
| const Op<T1,op_inv>& in, | | const Op<T1,op_inv>& X, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| eT tmp = det(in.m, slow); | | const eT tmp = det(X.m, slow); | |
| | | | |
| arma_warn( (tmp == eT(0)), "det(): warning: denominator is zero" ); | | arma_warn( (tmp == eT(0)), "det(): warning: denominator is zero" ); | |
| | | | |
| return eT(1) / tmp; | | return eT(1) / tmp; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | arma_warn_unused | |
| | | typename T1::elem_type | |
| | | det | |
| | | ( | |
| | | const Op<T1,op_inv>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method | |
| | | specified" ); | |
| | | | |
| | | const bool slow = (sig == 's'); | |
| | | | |
| | | return det(X, slow); | |
| | | } | |
| | | | |
| //! determinant of trans(A) | | //! determinant of trans(A) | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| arma_warn_unused | | arma_warn_unused | |
| typename T1::elem_type | | typename T1::elem_type | |
| det | | det | |
| ( | | ( | |
| const Op<T1,op_htrans>& in, | | const Op<T1,op_htrans>& in, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk1
= 0, | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk1
= 0, | |
| const typename arma_not_cx<typename T1::elem_type>::result* junk2
= 0 | | const typename arma_not_cx<typename T1::elem_type>::result* junk2
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk1); | | arma_ignore(junk1); | |
| arma_ignore(junk2); | | arma_ignore(junk2); | |
| | | | |
| return auxlib::det(in.m, slow); // bypass op_htrans | | return auxlib::det(in.m, slow); // bypass op_htrans | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | arma_warn_unused | |
| | | typename T1::elem_type | |
| | | det | |
| | | ( | |
| | | const Op<T1,op_htrans>& in, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk1 | |
| | | = 0, | |
| | | const typename arma_not_cx<typename T1::elem_type>::result* junk2 | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk1); | |
| | | arma_ignore(junk2); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method | |
| | | specified" ); | |
| | | | |
| | | const bool slow = (sig == 's'); | |
| | | | |
| | | return auxlib::det(in.m, slow); // bypass op_htrans | |
| | | } | |
| | | | |
| template<typename T> | | template<typename T> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| const typename arma_scalar_only<T>::result & | | const typename arma_scalar_only<T>::result & | |
| det(const T& x) | | det(const T& x) | |
| { | | { | |
| return x; | | return x; | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 7 change blocks. |
| 2 lines changed or deleted | | 121 lines changed or added | |
|
| fn_inv.hpp | | fn_inv.hpp | |
|
| // Copyright (C) 2008-2011 Conrad Sanderson | | // Copyright (C) 2008-2013 Conrad Sanderson | |
| // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup fn_inv | | //! \addtogroup fn_inv | |
| //! @{ | | //! @{ | |
| | | | |
| //! delayed matrix inverse (general matrices) | | //! delayed matrix inverse (general matrices) | |
| template<typename T1> | | template<typename T1> | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return Op<T1, op_inv>(X.get_ref(), ((slow == false) ? 0 : 1), 0); | | return Op<T1, op_inv>(X.get_ref(), ((slow == false) ? 0 : 1), 0); | |
| } | | } | |
| | | | |
|
| //! remove the inverse operation if applied twice consecutively | | | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
|
| const T1& | | const Op<T1, op_inv> | |
| inv(const Op<T1, op_inv>& X, const bool slow = false) | | inv | |
| | | ( | |
| | | const Base<typename T1::elem_type,T1>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| arma_ignore(slow); | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
|
| return X.m; | | arma_debug_check( ((sig != 's') && (sig != 'f')), "inv(): unknown method | |
| | | specified" ); | |
| | | | |
| | | return Op<T1, op_inv>(X.get_ref(), ((sig == 'f') ? 0 : 1), 0); | |
| } | | } | |
| | | | |
| //! delayed matrix inverse (triangular matrices) | | //! delayed matrix inverse (triangular matrices) | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
| const Op<T1, op_inv_tr> | | const Op<T1, op_inv_tr> | |
| inv | | inv | |
| ( | | ( | |
| const Op<T1, op_trimat>& X, | | const Op<T1, op_trimat>& X, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(slow); | | arma_ignore(slow); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return Op<T1, op_inv_tr>(X.m, X.aux_uword_a, 0); | | return Op<T1, op_inv_tr>(X.m, X.aux_uword_a, 0); | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | arma_inline | |
| | | const Op<T1, op_inv_tr> | |
| | | inv | |
| | | ( | |
| | | const Op<T1, op_trimat>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "inv(): unknown method | |
| | | specified" ); | |
| | | | |
| | | return Op<T1, op_inv_tr>(X.m, X.aux_uword_a, 0); | |
| | | } | |
| | | | |
| //! delayed matrix inverse (symmetric positive definite matrices) | | //! delayed matrix inverse (symmetric positive definite matrices) | |
| template<typename T1> | | template<typename T1> | |
| arma_inline | | arma_inline | |
| const Op<T1, op_inv_sympd> | | const Op<T1, op_inv_sympd> | |
| inv | | inv | |
| ( | | ( | |
| const Op<T1, op_sympd>& X, | | const Op<T1, op_sympd>& X, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(slow); | | arma_ignore(slow); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return Op<T1, op_inv_sympd>(X.m, 0, 0); | | return Op<T1, op_inv_sympd>(X.m, 0, 0); | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| | | arma_inline | |
| | | const Op<T1, op_inv_sympd> | |
| | | inv | |
| | | ( | |
| | | const Op<T1, op_sympd>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "inv(): unknown method | |
| | | specified" ); | |
| | | | |
| | | return Op<T1, op_inv_sympd>(X.m, 0, 0); | |
| | | } | |
| | | | |
| | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| inv | | inv | |
| ( | | ( | |
| Mat<typename T1::elem_type>& out, | | Mat<typename T1::elem_type>& out, | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| | | | |
| skipping to change at line 102 | | skipping to change at line 150 | |
| out = inv(X,slow); | | out = inv(X,slow); | |
| } | | } | |
| catch(std::runtime_error&) | | catch(std::runtime_error&) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | template<typename T1> | |
| | | inline | |
| | | bool | |
| | | inv | |
| | | ( | |
| | | Mat<typename T1::elem_type>& out, | |
| | | const Base<typename T1::elem_type,T1>& X, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | try | |
| | | { | |
| | | out = inv(X,method); | |
| | | } | |
| | | catch(std::runtime_error&) | |
| | | { | |
| | | return false; | |
| | | } | |
| | | | |
| | | return true; | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 8 change blocks. |
| 7 lines changed or deleted | | 88 lines changed or added | |
|
| fn_solve.hpp | | fn_solve.hpp | |
|
| // Copyright (C) 2009-2011 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup fn_solve | | //! \addtogroup fn_solve | |
| //! @{ | | //! @{ | |
| | | | |
| //! Solve a system of linear equations, i.e., A*X = B, where X is unknown. | | //! Solve a system of linear equations, i.e., A*X = B, where X is unknown. | |
| //! For a square matrix A, this function is conceptually the same as X = in
v(A)*B, | | //! For a square matrix A, this function is conceptually the same as X = in
v(A)*B, | |
| | | | |
| skipping to change at line 38 | | skipping to change at line 38 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return Glue<T1, T2, glue_solve>(A.get_ref(), B.get_ref(), ((slow == false
) ? 0 : 1) ); | | return Glue<T1, T2, glue_solve>(A.get_ref(), B.get_ref(), ((slow == false
) ? 0 : 1) ); | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
|
| | | const Glue<T1, T2, glue_solve> | |
| | | solve | |
| | | ( | |
| | | const Base<typename T1::elem_type,T1>& A, | |
| | | const Base<typename T1::elem_type,T2>& B, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "solve(): unknown metho | |
| | | d specified" ); | |
| | | | |
| | | return Glue<T1, T2, glue_solve>( A.get_ref(), B.get_ref(), ((sig == 'f') | |
| | | ? 0 : 1) ); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| const Glue<T1, T2, glue_solve_tr> | | const Glue<T1, T2, glue_solve_tr> | |
| solve | | solve | |
| ( | | ( | |
| const Op<T1, op_trimat>& A, | | const Op<T1, op_trimat>& A, | |
| const Base<typename T1::elem_type,T2>& B, | | const Base<typename T1::elem_type,T2>& B, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(slow); | | arma_ignore(slow); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| return Glue<T1, T2, glue_solve_tr>(A.m, B.get_ref(), A.aux_uword_a); | | return Glue<T1, T2, glue_solve_tr>(A.m, B.get_ref(), A.aux_uword_a); | |
| } | | } | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| inline | | inline | |
|
| | | const Glue<T1, T2, glue_solve_tr> | |
| | | solve | |
| | | ( | |
| | | const Op<T1, op_trimat>& A, | |
| | | const Base<typename T1::elem_type,T2>& B, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | const char sig = method[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'f')), "solve(): unknown metho | |
| | | d specified" ); | |
| | | | |
| | | return Glue<T1, T2, glue_solve_tr>(A.m, B.get_ref(), A.aux_uword_a); | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| bool | | bool | |
| solve | | solve | |
| ( | | ( | |
| Mat<typename T1::elem_type>& out, | | Mat<typename T1::elem_type>& out, | |
| const Base<typename T1::elem_type,T1>& A, | | const Base<typename T1::elem_type,T1>& A, | |
| const Base<typename T1::elem_type,T2>& B, | | const Base<typename T1::elem_type,T2>& B, | |
| const bool slow = false, | | const bool slow = false, | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| | | | |
| skipping to change at line 81 | | skipping to change at line 123 | |
| out = solve( A.get_ref(), B.get_ref(), slow ); | | out = solve( A.get_ref(), B.get_ref(), slow ); | |
| } | | } | |
| catch(std::runtime_error&) | | catch(std::runtime_error&) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | bool | |
| | | solve | |
| | | ( | |
| | | Mat<typename T1::elem_type>& out, | |
| | | const Base<typename T1::elem_type,T1>& A, | |
| | | const Base<typename T1::elem_type,T2>& B, | |
| | | const char* method, | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | try | |
| | | { | |
| | | out = solve( A.get_ref(), B.get_ref(), method ); | |
| | | } | |
| | | catch(std::runtime_error&) | |
| | | { | |
| | | return false; | |
| | | } | |
| | | | |
| | | return true; | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 4 change blocks. |
| 2 lines changed or deleted | | 77 lines changed or added | |
|
| fn_sort_index.hpp | | fn_sort_index.hpp | |
|
| // Copyright (C) 2009-2012 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup fn_sort_index | | //! \addtogroup fn_sort_index | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| struct arma_sort_index_packet | | struct arma_sort_index_packet | |
| | | | |
| skipping to change at line 44 | | skipping to change at line 44 | |
| | | | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_inline | | arma_inline | |
| bool | | bool | |
| operator() (const arma_sort_index_packet<T1,T2>& A, const arma_sort_index
_packet<T1,T2>& B) const | | operator() (const arma_sort_index_packet<T1,T2>& A, const arma_sort_index
_packet<T1,T2>& B) const | |
| { | | { | |
| return (A.val > B.val); | | return (A.val > B.val); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| template<typename umat_elem_type, typename eT, const uword sort_direction,
const uword sort_type> | | template<typename umat_elem_type, typename eT, const uword sort_type, const
uword sort_stable> | |
| void | | void | |
| inline | | inline | |
| sort_index_helper(umat_elem_type* out_mem, const eT* in_mem, const uword n_
elem) | | sort_index_helper(umat_elem_type* out_mem, const eT* in_mem, const uword n_
elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| std::vector< arma_sort_index_packet<eT, umat_elem_type> > packet_vec(n_el
em); | | std::vector< arma_sort_index_packet<eT, umat_elem_type> > packet_vec(n_el
em); | |
| | | | |
| for(uword i=0; i<n_elem; ++i) | | for(uword i=0; i<n_elem; ++i) | |
| { | | { | |
| packet_vec[i].val = in_mem[i]; | | packet_vec[i].val = in_mem[i]; | |
| packet_vec[i].index = i; | | packet_vec[i].index = i; | |
| } | | } | |
| | | | |
|
| if(sort_direction == 0) | | if(sort_type == 0) | |
| { | | { | |
| // ascend | | // ascend | |
| | | | |
| arma_sort_index_helper_ascend comparator; | | arma_sort_index_helper_ascend comparator; | |
| | | | |
|
| if(sort_type == 0) | | if(sort_stable == 0) | |
| { | | { | |
| std::sort( packet_vec.begin(), packet_vec.end(), comparator ); | | std::sort( packet_vec.begin(), packet_vec.end(), comparator ); | |
| } | | } | |
| else | | else | |
| { | | { | |
| std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); | | std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| // descend | | // descend | |
| | | | |
| arma_sort_index_helper_descend comparator; | | arma_sort_index_helper_descend comparator; | |
| | | | |
|
| if(sort_type == 0) | | if(sort_stable == 0) | |
| { | | { | |
| std::sort( packet_vec.begin(), packet_vec.end(), comparator ); | | std::sort( packet_vec.begin(), packet_vec.end(), comparator ); | |
| } | | } | |
| else | | else | |
| { | | { | |
| std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); | | std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); | |
| } | | } | |
| } | | } | |
| | | | |
| for(uword i=0; i<n_elem; ++i) | | for(uword i=0; i<n_elem; ++i) | |
| | | | |
| skipping to change at line 102 | | skipping to change at line 102 | |
| out_mem[i] = packet_vec[i].index; | | out_mem[i] = packet_vec[i].index; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| umat | | umat | |
| sort_index | | sort_index | |
| ( | | ( | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
|
| const uword sort_direction = 0, | | const uword sort_type = 0, | |
| const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 | | const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(X.get_ref()); | | const unwrap<T1> tmp(X.get_ref()); | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| skipping to change at line 125 | | skipping to change at line 125 | |
| { | | { | |
| return umat(); | | return umat(); | |
| } | | } | |
| | | | |
| arma_debug_check( (A.is_vec() == false), "sort_index(): currently only ha
ndles vectors"); | | arma_debug_check( (A.is_vec() == false), "sort_index(): currently only ha
ndles vectors"); | |
| | | | |
| typedef typename umat::elem_type out_elem_type; | | typedef typename umat::elem_type out_elem_type; | |
| | | | |
| umat out(A.n_rows, A.n_cols); | | umat out(A.n_rows, A.n_cols); | |
| | | | |
|
| if(sort_direction == 0) | | if(sort_type == 0) | |
| { | | { | |
| sort_index_helper<out_elem_type, eT, 0, 0>(out.memptr(), A.mem, A.n_ele
m); | | sort_index_helper<out_elem_type, eT, 0, 0>(out.memptr(), A.mem, A.n_ele
m); | |
| } | | } | |
| else | | else | |
| { | | { | |
| sort_index_helper<out_elem_type, eT, 1, 0>(out.memptr(), A.mem, A.n_ele
m); | | sort_index_helper<out_elem_type, eT, 1, 0>(out.memptr(), A.mem, A.n_ele
m); | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| umat | | umat | |
| stable_sort_index | | stable_sort_index | |
| ( | | ( | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
|
| const uword sort_direction = 0, | | const uword sort_type = 0, | |
| const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 | | const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> tmp(X.get_ref()); | | const unwrap<T1> tmp(X.get_ref()); | |
| const Mat<eT>& A = tmp.M; | | const Mat<eT>& A = tmp.M; | |
| | | | |
| skipping to change at line 166 | | skipping to change at line 166 | |
| { | | { | |
| return umat(); | | return umat(); | |
| } | | } | |
| | | | |
| arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently
only handles vectors"); | | arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently
only handles vectors"); | |
| | | | |
| typedef typename umat::elem_type out_elem_type; | | typedef typename umat::elem_type out_elem_type; | |
| | | | |
| umat out(A.n_rows, A.n_cols); | | umat out(A.n_rows, A.n_cols); | |
| | | | |
|
| if(sort_direction == 0) | | if(sort_type == 0) | |
| | | { | |
| | | sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_ele | |
| | | m); | |
| | | } | |
| | | else | |
| | | { | |
| | | sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_ele | |
| | | m); | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | typename | |
| | | enable_if2 | |
| | | < | |
| | | ( (is_arma_type<T1>::value == true) && (is_same_type<T2, char>::value == | |
| | | true) && (is_cx<typename T1::elem_type>::value == false) ), | |
| | | umat | |
| | | >::result | |
| | | sort_index | |
| | | ( | |
| | | const T1& X, | |
| | | const T2* sort_direction | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | if(A.is_empty() == true) | |
| | | { | |
| | | return umat(); | |
| | | } | |
| | | | |
| | | arma_debug_check( (A.is_vec() == false), "sort_index(): currently only ha | |
| | | ndles vectors"); | |
| | | | |
| | | const char sig = sort_direction[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 'a') && (sig != 'd')), "sort_index(): unknown | |
| | | sort direction" ); | |
| | | | |
| | | typedef typename umat::elem_type out_elem_type; | |
| | | | |
| | | umat out(A.n_rows, A.n_cols); | |
| | | | |
| | | if(sig == 'a') | |
| | | { | |
| | | sort_index_helper<out_elem_type, eT, 0, 0>(out.memptr(), A.mem, A.n_ele | |
| | | m); | |
| | | } | |
| | | else | |
| | | { | |
| | | sort_index_helper<out_elem_type, eT, 1, 0>(out.memptr(), A.mem, A.n_ele | |
| | | m); | |
| | | } | |
| | | | |
| | | return out; | |
| | | } | |
| | | | |
| | | template<typename T1, typename T2> | |
| | | inline | |
| | | typename | |
| | | enable_if2 | |
| | | < | |
| | | ( (is_arma_type<T1>::value == true) && (is_same_type<T2, char>::value == | |
| | | true) && (is_cx<typename T1::elem_type>::value == false) ), | |
| | | umat | |
| | | >::result | |
| | | stable_sort_index | |
| | | ( | |
| | | const T1& X, | |
| | | const T2* sort_direction | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> tmp(X); | |
| | | const Mat<eT>& A = tmp.M; | |
| | | | |
| | | if(A.is_empty() == true) | |
| | | { | |
| | | return umat(); | |
| | | } | |
| | | | |
| | | arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently | |
| | | only handles vectors"); | |
| | | | |
| | | const char sig = sort_direction[0]; | |
| | | | |
| | | arma_debug_check( ((sig != 'a') && (sig != 'd')), "stable_sort_index(): u | |
| | | nknown sort direction" ); | |
| | | | |
| | | typedef typename umat::elem_type out_elem_type; | |
| | | | |
| | | umat out(A.n_rows, A.n_cols); | |
| | | | |
| | | if(sig == 'a') | |
| { | | { | |
| sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_ele
m); | | sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_ele
m); | |
| } | | } | |
| else | | else | |
| { | | { | |
| sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_ele
m); | | sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_ele
m); | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
End of changes. 9 change blocks. |
| 10 lines changed or deleted | | 116 lines changed or added | |
|
| fn_svd.hpp | | fn_svd.hpp | |
|
| // Copyright (C) 2009-2011 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup fn_svd | | //! \addtogroup fn_svd | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| | | | |
| skipping to change at line 71 | | skipping to change at line 71 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| svd | | svd | |
| ( | | ( | |
| Mat<typename T1::elem_type>& U, | | Mat<typename T1::elem_type>& U, | |
| Col<typename T1::pod_type >& S, | | Col<typename T1::pod_type >& S, | |
| Mat<typename T1::elem_type>& V, | | Mat<typename T1::elem_type>& V, | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
|
| const char* method = "", | | const char* method = "standard", | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)
(&V)) ), | | ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)
(&V)) ), | |
| "svd(): two or more output objects are the same object" | | "svd(): two or more output objects are the same object" | |
| ); | | ); | |
| | | | |
|
| bool use_divide_and_conquer = false; | | | |
| | | | |
| const char sig = method[0]; | | const char sig = method[0]; | |
| | | | |
|
| switch(sig) | | arma_debug_check( ((sig != 's') && (sig != 'd')), "svd(): unknown method | |
| { | | specified" ); | |
| case '\0': | | | |
| case 's': | | | |
| break; | | | |
| | | | |
| case 'd': | | | |
| use_divide_and_conquer = true; | | | |
| break; | | | |
| | | | |
| default: | | | |
| { | | | |
| arma_stop("svd(): unknown method specified"); | | | |
| return false; | | | |
| } | | | |
| } | | | |
| | | | |
| // auxlib::svd() makes an internal copy of X | | // auxlib::svd() makes an internal copy of X | |
|
| const bool status = (use_divide_and_conquer == false) ? auxlib::svd(U, S,
V, X) : auxlib::svd_dc(U, S, V, X); | | const bool status = (sig == 'd') ? auxlib::svd_dc(U, S, V, X) : auxlib::s
vd(U, S, V, X); | |
| | | | |
| if(status == false) | | if(status == false) | |
| { | | { | |
| U.reset(); | | U.reset(); | |
| S.reset(); | | S.reset(); | |
| V.reset(); | | V.reset(); | |
| arma_bad("svd(): failed to converge", false); | | arma_bad("svd(): failed to converge", false); | |
| } | | } | |
| | | | |
| return status; | | return status; | |
| | | | |
| skipping to change at line 128 | | skipping to change at line 111 | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| svd_econ | | svd_econ | |
| ( | | ( | |
| Mat<typename T1::elem_type>& U, | | Mat<typename T1::elem_type>& U, | |
| Col<typename T1::pod_type >& S, | | Col<typename T1::pod_type >& S, | |
| Mat<typename T1::elem_type>& V, | | Mat<typename T1::elem_type>& V, | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
|
| const char mode = 'b', | | const char mode, | |
| | | const char* method = "standard", | |
| const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk
= 0 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)
(&V)) ), | | ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)
(&V)) ), | |
| "svd_econ(): two or more output objects are the same object" | | "svd_econ(): two or more output objects are the same object" | |
| ); | | ); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( (mode != 'l') && (mode != 'r') && (mode != 'b') ), | | ( (mode != 'l') && (mode != 'r') && (mode != 'b') ), | |
|
| "svd_econ(): parameter 'mode' is incorrect" | | "svd_econ(): parameter 'mode' or 'side' is incorrect" | |
| ); | | ); | |
| | | | |
|
| // auxlib::svd_econ() makes an internal copy of X | | const char sig = method[0]; | |
| const bool status = auxlib::svd_econ(U, S, V, X, mode); | | | |
| | | arma_debug_check( ((sig != 's') && (sig != 'd')), "svd_econ(): unknown me | |
| | | thod specified" ); | |
| | | | |
| | | const bool status = ((mode == 'b') && (sig == 'd')) ? auxlib::svd_dc_econ | |
| | | (U, S, V, X) : auxlib::svd_econ(U, S, V, X, mode); | |
| | | | |
| if(status == false) | | if(status == false) | |
| { | | { | |
| U.reset(); | | U.reset(); | |
| S.reset(); | | S.reset(); | |
| V.reset(); | | V.reset(); | |
| arma_bad("svd_econ(): failed to converge", false); | | arma_bad("svd_econ(): failed to converge", false); | |
| } | | } | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| | | inline | |
| | | bool | |
| | | svd_econ | |
| | | ( | |
| | | Mat<typename T1::elem_type>& U, | |
| | | Col<typename T1::pod_type >& S, | |
| | | Mat<typename T1::elem_type>& V, | |
| | | const Base<typename T1::elem_type,T1>& X, | |
| | | const char* side = "both", | |
| | | const char* method = "standard", | |
| | | const typename arma_blas_type_only<typename T1::elem_type>::result* junk | |
| | | = 0 | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | return svd_econ(U,S,V,X,side[0],method); | |
| | | } | |
| | | | |
| | | // TODO: remove this function in version 4.0 | |
| | | template<typename T1> | |
| arma_deprecated | | arma_deprecated | |
| inline | | inline | |
| bool | | bool | |
| svd_thin | | svd_thin | |
| ( | | ( | |
| Mat<typename T1::elem_type>& U, | | Mat<typename T1::elem_type>& U, | |
| Col<typename T1::pod_type >& S, | | Col<typename T1::pod_type >& S, | |
| Mat<typename T1::elem_type>& V, | | Mat<typename T1::elem_type>& V, | |
| const Base<typename T1::elem_type,T1>& X, | | const Base<typename T1::elem_type,T1>& X, | |
| const char mode = 'b', | | const char mode = 'b', | |
| | | | |
End of changes. 9 change blocks. |
| 26 lines changed or deleted | | 38 lines changed or added | |
|
| mul_gemm.hpp | | mul_gemm.hpp | |
| | | | |
| skipping to change at line 125 | | skipping to change at line 125 | |
| else if( (use_alpha == true ) && (use_beta == false) ) { C.at(co
l_A,col_B) = alpha*acc; } | | else if( (use_alpha == true ) && (use_beta == false) ) { C.at(co
l_A,col_B) = alpha*acc; } | |
| else if( (use_alpha == false) && (use_beta == true ) ) { C.at(co
l_A,col_B) = acc + beta*C.at(col_A,col_B); } | | else if( (use_alpha == false) && (use_beta == true ) ) { C.at(co
l_A,col_B) = acc + beta*C.at(col_A,col_B); } | |
| else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(co
l_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } | | else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(co
l_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| if( (do_trans_A == false) && (do_trans_B == true) ) | | if( (do_trans_A == false) && (do_trans_B == true) ) | |
| { | | { | |
| Mat<eT> BB; | | Mat<eT> BB; | |
|
| op_strans::apply_noalias(BB, B); | | op_strans::apply_mat_noalias(BB, B); | |
| | | | |
| gemm_emul_large<false, false, use_alpha, use_beta>::apply(C, A, BB, a
lpha, beta); | | gemm_emul_large<false, false, use_alpha, use_beta>::apply(C, A, BB, a
lpha, beta); | |
| } | | } | |
| else | | else | |
| if( (do_trans_A == true) && (do_trans_B == true) ) | | if( (do_trans_A == true) && (do_trans_B == true) ) | |
| { | | { | |
| // mat B_tmp = trans(B); | | // mat B_tmp = trans(B); | |
| // dgemm_arma<true, false, use_alpha, use_beta>::apply(C, A, B_tmp,
alpha, beta); | | // dgemm_arma<true, false, use_alpha, use_beta>::apply(C, A, B_tmp,
alpha, beta); | |
| | | | |
| // By using the trans(A)*trans(B) = trans(B*A) equivalency, | | // By using the trans(A)*trans(B) = trans(B*A) equivalency, | |
| | | | |
| skipping to change at line 198 | | skipping to change at line 198 | |
| | | | |
| if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) && (A_n_rows == B_n_rows)
&& (B_n_rows == B_n_cols) ) | | if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) && (A_n_rows == B_n_rows)
&& (B_n_rows == B_n_cols) ) | |
| { | | { | |
| if(do_trans_B == false) | | if(do_trans_B == false) | |
| { | | { | |
| gemm_emul_tinysq<do_trans_A, use_alpha, use_beta>::apply(C, A, B, a
lpha, beta); | | gemm_emul_tinysq<do_trans_A, use_alpha, use_beta>::apply(C, A, B, a
lpha, beta); | |
| } | | } | |
| else | | else | |
| { | | { | |
| Mat<eT> BB(A_n_rows, A_n_rows); | | Mat<eT> BB(A_n_rows, A_n_rows); | |
|
| op_strans::apply_noalias_tinysq(BB, B); | | op_strans::apply_mat_noalias_tinysq(BB, B); | |
| | | | |
| gemm_emul_tinysq<do_trans_A, use_alpha, use_beta>::apply(C, A, BB,
alpha, beta); | | gemm_emul_tinysq<do_trans_A, use_alpha, use_beta>::apply(C, A, BB,
alpha, beta); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| gemm_emul_large<do_trans_A, do_trans_B, use_alpha, use_beta>::apply(C
, A, B, alpha, beta); | | gemm_emul_large<do_trans_A, do_trans_B, use_alpha, use_beta>::apply(C
, A, B, alpha, beta); | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 232 | | skipping to change at line 232 | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| // "better than nothing" handling of hermitian transposes for complex n
umber matrices | | // "better than nothing" handling of hermitian transposes for complex n
umber matrices | |
| | | | |
| Mat<eT> tmp_A; | | Mat<eT> tmp_A; | |
| Mat<eT> tmp_B; | | Mat<eT> tmp_B; | |
| | | | |
|
| if(do_trans_A) { op_htrans::apply_noalias(tmp_A, A); } | | if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } | |
| if(do_trans_B) { op_htrans::apply_noalias(tmp_B, B); } | | if(do_trans_B) { op_htrans::apply_mat_noalias(tmp_B, B); } | |
| | | | |
| const Mat<eT>& AA = (do_trans_A == false) ? A : tmp_A; | | const Mat<eT>& AA = (do_trans_A == false) ? A : tmp_A; | |
| const Mat<eT>& BB = (do_trans_B == false) ? B : tmp_B; | | const Mat<eT>& BB = (do_trans_B == false) ? B : tmp_B; | |
| | | | |
| const uword A_n_rows = AA.n_rows; | | const uword A_n_rows = AA.n_rows; | |
| const uword A_n_cols = AA.n_cols; | | const uword A_n_cols = AA.n_cols; | |
| | | | |
| const uword B_n_rows = BB.n_rows; | | const uword B_n_rows = BB.n_rows; | |
| const uword B_n_cols = BB.n_cols; | | const uword B_n_cols = BB.n_cols; | |
| | | | |
| | | | |
End of changes. 3 change blocks. |
| 4 lines changed or deleted | | 4 lines changed or added | |
|
| op_cx_scalar_meat.hpp | | op_cx_scalar_meat.hpp | |
| | | | |
| skipping to change at line 282 | | skipping to change at line 282 | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_times>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_times>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| // TODO: implement handling for ProxyCube<T1>::prefer_at_accessor == true | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| for(uword i=0; i<n_elem; ++i) | | { | |
| | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A[i] * k; | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| out_mem[i] = A[i] * k; | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = A.at(row,col,slice) * k; ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cx_scalar_plus::apply | | op_cx_scalar_plus::apply | |
| ( | | ( | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_plus>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_plus>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| out_mem[i] = A[i] + k; | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A[i] + k; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = A.at(row,col,slice) + k; ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cx_scalar_minus_pre::apply | | op_cx_scalar_minus_pre::apply | |
| ( | | ( | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_minus_pre>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_minus_pre>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| | | { | |
| | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k - A[i]; | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| out_mem[i] = k - A[i]; | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = k - A.at(row,col,slice); ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cx_scalar_minus_post::apply | | op_cx_scalar_minus_post::apply | |
| ( | | ( | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_minus_post>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_minus_post>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| | | { | |
| | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A[i] - k; | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| out_mem[i] = A[i] - k; | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = A.at(row,col,slice) - k; ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cx_scalar_div_pre::apply | | op_cx_scalar_div_pre::apply | |
| ( | | ( | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_div_pre>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_div_pre>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| out_mem[i] = k / A[i]; | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = k / A[i]; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = k / A.at(row,col,slice); ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_cx_scalar_div_post::apply | | op_cx_scalar_div_post::apply | |
| ( | | ( | |
| Cube< typename std::complex<typename T1::pod_type> >& out, | | Cube< typename std::complex<typename T1::pod_type> >& out, | |
| const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_div_post>& X | | const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_sc
alar_div_post>& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<typename T1::pod_type> eT; | | typedef typename std::complex<typename T1::pod_type> eT; | |
| | | | |
| const ProxyCube<T1> A(X.m); | | const ProxyCube<T1> A(X.m); | |
| | | | |
|
| out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); | | const uword n_rows = A.get_n_rows(); | |
| | | const uword n_cols = A.get_n_cols(); | |
| | | const uword n_slices = A.get_n_slices(); | |
| | | | |
| | | out.set_size(n_rows, n_cols, n_slices); | |
| | | | |
| const eT k = X.aux_out_eT; | | const eT k = X.aux_out_eT; | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| | | { | |
| | | for(uword i=0; i<n_elem; ++i) | |
| | | { | |
| | | out_mem[i] = A[i] / k; | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| out_mem[i] = A[i] / k; | | for(uword slice = 0; slice < n_slices; ++slice) | |
| | | for(uword col = 0; col < n_cols; ++col ) | |
| | | for(uword row = 0; row < n_rows; ++row ) | |
| | | { | |
| | | *out_mem = A.at(row,col,slice) / k; ++out_mem; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 18 change blocks. |
| 19 lines changed or deleted | | 114 lines changed or added | |
|
| op_htrans_meat.hpp | | op_htrans_meat.hpp | |
|
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2013 Conrad Sanderson | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2012 Ryan Curtin | | // Copyright (C) 2012 Ryan Curtin | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup op_htrans | | //! \addtogroup op_htrans | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| arma_inline | | arma_inline | |
| void | | void | |
|
| op_htrans::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const typename arm
a_not_cx<eT>::result* junk) | | op_htrans::apply_mat_noalias(Mat<eT>& out, const Mat<eT>& A, const typename
arma_not_cx<eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| op_strans::apply_noalias(out, A); | | op_strans::apply_mat_noalias(out, A); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| op_htrans::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const typename arm
a_cx_only<eT>::result* junk) | | op_htrans::apply_mat_noalias(Mat<eT>& out, const Mat<eT>& A, const typename
arma_cx_only<eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| 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; | |
| | | | |
| out.set_size(A_n_cols, A_n_rows); | | out.set_size(A_n_cols, A_n_rows); | |
| | | | |
| if( (A_n_cols == 1) || (A_n_rows == 1) ) | | if( (A_n_cols == 1) || (A_n_rows == 1) ) | |
| | | | |
| skipping to change at line 69 | | skipping to change at line 69 | |
| out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) ); | | out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| arma_inline | | arma_inline | |
| void | | void | |
|
| op_htrans::apply(Mat<eT>& out, const Mat<eT>& A, const typename arma_not_cx
<eT>::result* junk) | | op_htrans::apply_mat_inplace(Mat<eT>& out, const typename arma_not_cx<eT>::
result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| op_strans::apply(out, A); | | op_strans::apply_mat_inplace(out); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| op_htrans::apply(Mat<eT>& out, const Mat<eT>& A, const typename arma_cx_onl
y<eT>::result* junk) | | op_htrans::apply_mat_inplace(Mat<eT>& out, const typename arma_cx_only<eT>:
:result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| if(&out != &A) | | const uword n_rows = out.n_rows; | |
| { | | const uword n_cols = out.n_cols; | |
| op_htrans::apply_noalias(out, A); | | | |
| } | | if(n_rows == n_cols) | |
| else | | | |
| { | | { | |
|
| const uword n_rows = out.n_rows; | | arma_extra_debug_print("doing in-place hermitian transpose of a square | |
| const uword n_cols = out.n_cols; | | matrix"); | |
| | | | |
|
| if(n_rows == n_cols) | | for(uword col=0; col < n_cols; ++col) | |
| { | | { | |
|
| arma_extra_debug_print("doing in-place hermitian transpose of a squar
e matrix"); | | eT* coldata = out.colptr(col); | |
| | | | |
|
| for(uword col=0; col < n_cols; ++col) | | out.at(col,col) = std::conj( out.at(col,col) ); | |
| { | | | |
| eT* coldata = out.colptr(col); | | | |
| | | | |
|
| out.at(col,col) = std::conj( out.at(col,col) ); | | for(uword row=(col+1); row < n_rows; ++row) | |
| | | { | |
| | | const eT val1 = std::conj(coldata[row]); | |
| | | const eT val2 = std::conj(out.at(col,row)); | |
| | | | |
|
| for(uword row=(col+1); row < n_rows; ++row) | | out.at(col,row) = val1; | |
| { | | coldata[row] = val2; | |
| const eT val1 = std::conj(coldata[row]); | | | |
| const eT val2 = std::conj(out.at(col,row)); | | | |
| | | | |
| out.at(col,row) = val1; | | | |
| coldata[row] = val2; | | | |
| } | | | |
| } | | } | |
| } | | } | |
|
| else | | } | |
| { | | else | |
| Mat<eT> tmp; | | { | |
| op_htrans::apply_noalias(tmp, A); | | Mat<eT> tmp; | |
| | | | |
|
| out.steal_mem(tmp); | | op_htrans::apply_mat_noalias(tmp, out); | |
| } | | | |
| | | out.steal_mem(tmp); | |
| } | | } | |
|
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_hot | |
| | | arma_inline | |
| | | void | |
| | | op_htrans::apply_mat(Mat<eT>& out, const Mat<eT>& A, const typename arma_no | |
| | | t_cx<eT>::result* junk) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | op_strans::apply_mat(out, A); | |
| | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | arma_hot | |
| | | inline | |
| | | void | |
| | | op_htrans::apply_mat(Mat<eT>& out, const Mat<eT>& A, const typename arma_cx | |
| | | _only<eT>::result* junk) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | if(&out != &A) | |
| | | { | |
| | | op_htrans::apply_mat_noalias(out, A); | |
| | | } | |
| | | else | |
| | | { | |
| | | op_htrans::apply_mat_inplace(out); | |
| | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| op_htrans::apply_proxy(Mat<typename T1::elem_type>& out, const T1& X) | | op_htrans::apply_proxy(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Proxy<T1> P(X); | | const Proxy<T1> P(X); | |
| | | | |
| // allow detection of in-place transpose | | // allow detection of in-place transpose | |
| if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1
>::fake_mat == false) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1
>::fake_mat == false) ) | |
| { | | { | |
| const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q); | | const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q); | |
| | | | |
|
| op_htrans::apply(out, tmp.M); | | op_htrans::apply_mat(out, tmp.M); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const uword n_rows = P.get_n_rows(); | | const uword n_rows = P.get_n_rows(); | |
| const uword n_cols = P.get_n_cols(); | | const uword n_cols = P.get_n_cols(); | |
| | | | |
| const bool is_alias = P.is_alias(out); | | const bool is_alias = P.is_alias(out); | |
| | | | |
| if( (resolves_to_vector<T1>::value == true) && (Proxy<T1>::prefer_at_ac
cessor == false) ) | | if( (resolves_to_vector<T1>::value == true) && (Proxy<T1>::prefer_at_ac
cessor == false) ) | |
| { | | { | |
| | | | |
End of changes. 19 change blocks. |
| 36 lines changed or deleted | | 63 lines changed or added | |
|
| op_pinv_meat.hpp | | op_pinv_meat.hpp | |
|
| // Copyright (C) 2009-2011 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2009-2010 Dimitrios Bouzas | | // Copyright (C) 2009-2010 Dimitrios Bouzas | |
| // Copyright (C) 2011 Stanislav Funiak | | // Copyright (C) 2011 Stanislav Funiak | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup op_pinv | | //! \addtogroup op_pinv | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
|
| op_pinv::direct_pinv(Mat<eT>& out, const Mat<eT>& A, const eT in_tol) | | op_pinv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pinv>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename get_pod_type<eT>::result T; | | typedef typename T1::elem_type eT; | |
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
|
| T tol = access::tmp_real(in_tol); | | const bool use_divide_and_conquer = (in.aux_uword_a == 1); | |
| | | | |
| | | T tol = access::tmp_real(in.aux); | |
| | | | |
| arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); | | arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); | |
| | | | |
|
| const uword n_rows = A.n_rows; | | const Proxy<T1> P(in.m); | |
| const uword n_cols = A.n_cols; | | | |
| | | const uword n_rows = P.get_n_rows(); | |
| | | const uword n_cols = P.get_n_cols(); | |
| | | | |
| | | if( (n_rows*n_cols) == 0 ) | |
| | | { | |
| | | out.set_size(n_cols,n_rows); | |
| | | return; | |
| | | } | |
| | | | |
| // economical SVD decomposition | | // economical SVD decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col< T> s; | | Col< T> s; | |
| Mat<eT> V; | | Mat<eT> V; | |
| | | | |
|
| const bool status = (n_cols > n_rows) ? auxlib::svd_econ(U,s,V,trans(A),' | | bool status = false; | |
| b') : auxlib::svd_econ(U,s,V,A,'b'); | | | |
| | | if(use_divide_and_conquer) | |
| | | { | |
| | | status = (n_cols > n_rows) ? auxlib::svd_dc_econ(U, s, V, trans(P.Q)) : | |
| | | auxlib::svd_dc_econ(U, s, V, P.Q); | |
| | | } | |
| | | else | |
| | | { | |
| | | status = (n_cols > n_rows) ? auxlib::svd_econ(U, s, V, trans(P.Q), 'b') | |
| | | : auxlib::svd_econ(U, s, V, P.Q, 'b'); | |
| | | } | |
| | | | |
| if(status == false) | | if(status == false) | |
| { | | { | |
| out.reset(); | | out.reset(); | |
| arma_bad("pinv(): svd failed"); | | arma_bad("pinv(): svd failed"); | |
| return; | | return; | |
| } | | } | |
| | | | |
| const uword s_n_elem = s.n_elem; | | const uword s_n_elem = s.n_elem; | |
| const T* s_mem = s.memptr(); | | const T* s_mem = s.memptr(); | |
| | | | |
| skipping to change at line 58 | | skipping to change at line 78 | |
| { | | { | |
| tol = (std::max)(n_rows, n_cols) * eop_aux::direct_eps( op_max::direct_
max(s_mem, s_n_elem) ); | | tol = (std::max)(n_rows, n_cols) * eop_aux::direct_eps( op_max::direct_
max(s_mem, s_n_elem) ); | |
| } | | } | |
| | | | |
| // count non zero valued elements in s | | // count non zero valued elements in s | |
| | | | |
| uword count = 0; | | uword count = 0; | |
| | | | |
| for(uword i = 0; i < s_n_elem; ++i) | | for(uword i = 0; i < s_n_elem; ++i) | |
| { | | { | |
|
| if(s_mem[i] > tol) | | if(s_mem[i] > tol) { ++count; } | |
| { | | | |
| ++count; | | | |
| } | | | |
| } | | } | |
| | | | |
|
| if(count != 0) | | if(count > 0) | |
| { | | { | |
| Col<T> s2(count); | | Col<T> s2(count); | |
| | | | |
| T* s2_mem = s2.memptr(); | | T* s2_mem = s2.memptr(); | |
| | | | |
| uword count2 = 0; | | uword count2 = 0; | |
| | | | |
| for(uword i=0; i < s_n_elem; ++i) | | for(uword i=0; i < s_n_elem; ++i) | |
| { | | { | |
| const T val = s_mem[i]; | | const T val = s_mem[i]; | |
| | | | |
|
| if(val > tol) | | if(val > tol) { s2_mem[count2] = T(1) / val; ++count2; } | |
| { | | | |
| s2_mem[count2] = T(1) / val; | | | |
| ++count2; | | | |
| } | | | |
| } | | } | |
| | | | |
| if(n_rows >= n_cols) | | if(n_rows >= n_cols) | |
| { | | { | |
|
| out = ( V.n_cols > count ? V.cols(0,count-1) : V ) * diagmat(s2) * tr
ans( U.n_cols > count ? U.cols(0,count-1) : U ); | | out = ( (V.n_cols > count) ? V.cols(0,count-1) : V ) * diagmat(s2) *
trans( (U.n_cols > count) ? U.cols(0,count-1) : U ); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| out = ( U.n_cols > count ? U.cols(0,count-1) : U ) * diagmat(s2) * tr
ans( V.n_cols > count ? V.cols(0,count-1) : V ); | | out = ( (U.n_cols > count) ? U.cols(0,count-1) : U ) * diagmat(s2) *
trans( (V.n_cols > count) ? V.cols(0,count-1) : V ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| out.zeros(n_cols, n_rows); | | out.zeros(n_cols, n_rows); | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename T1> | | | |
| inline | | | |
| void | | | |
| op_pinv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_pinv>& in) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| typedef typename T1::elem_type eT; | | | |
| | | | |
| const unwrap<T1> tmp(in.m); | | | |
| const Mat<eT>& A = tmp.M; | | | |
| | | | |
| op_pinv::direct_pinv(out, A, in.aux); | | | |
| } | | | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 13 change blocks. |
| 37 lines changed or deleted | | 36 lines changed or added | |
|
| op_princomp_meat.hpp | | op_princomp_meat.hpp | |
|
| // Copyright (C) 2010-2012 Conrad Sanderson | | // Copyright (C) 2010-2013 Conrad Sanderson | |
| // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010 Dimitrios Bouzas | | // Copyright (C) 2010 Dimitrios Bouzas | |
| // Copyright (C) 2011 Stanislav Funiak | | // Copyright (C) 2011 Stanislav Funiak | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup op_princomp | | //! \addtogroup op_princomp | |
| //! @{ | | //! @{ | |
| | | | |
| | | | |
| skipping to change at line 47 | | skipping to change at line 47 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col<eT> s; | | Col<eT> s; | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
| //U.reset(); // TODO: do we need this ? U will get automatically dele | | | |
| ted anyway | | | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| skipping to change at line 144 | | skipping to change at line 139 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col<eT> s; | | Col<eT> s; | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
| // U.reset(); | | | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| skipping to change at line 222 | | skipping to change at line 212 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col<eT> s; | | Col<eT> s; | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| | | | |
| if(svd_ok == false) | | | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
|
| // U.reset(); | | if(svd_ok == false) { return false; } | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| skipping to change at line 286 | | skipping to change at line 271 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const unwrap<T1> Y( X.get_ref() ); | | const unwrap<T1> Y( X.get_ref() ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| if(in.n_elem != 0) | | if(in.n_elem != 0) | |
| { | | { | |
|
| | | Mat<eT> tmp = in; tmp.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col<eT> s; | | Col<eT> s; | |
| | | | |
|
| const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | | const bool svd_ok = svd(U, s, coeff_out, tmp); | |
| | | | |
| const bool svd_ok = svd(U,s,coeff_out, tmp); | | | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| } | | } | |
| else | | else | |
| { | | { | |
| coeff_out.eye(in.n_cols, in.n_cols); | | coeff_out.eye(in.n_cols, in.n_cols); | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| | | | |
| skipping to change at line 342 | | skipping to change at line 324 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
|
| Col<T> s; | | Col< T> s; | |
| | | | |
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | | |
| | | | |
|
| if(svd_ok == false) | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
|
| //U.reset(); | | if(svd_ok == false) { return false; } | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| skipping to change at line 437 | | skipping to change at line 414 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col< T> s; | | Col< T> s; | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
| // U.reset(); | | | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| Col<T> s_tmp = zeros< Col<T> >(n_cols); | | Col<T> s_tmp = zeros< Col<T> >(n_cols); | |
| s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); | | s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); | |
| s = s_tmp; | | s = s_tmp; | |
| } | | } | |
| | | | |
| // compute the eigenvalues of the principal vectors | | // compute the eigenvalues of the principal vectors | |
| latent_out = s%s; | | latent_out = s%s; | |
|
| | | | |
| } | | } | |
| else // 0 or 1 samples | | else // 0 or 1 samples | |
| { | | { | |
| coeff_out.eye(n_cols, n_cols); | | coeff_out.eye(n_cols, n_cols); | |
| | | | |
| score_out.copy_size(in); | | score_out.copy_size(in); | |
| score_out.zeros(); | | score_out.zeros(); | |
| | | | |
| latent_out.set_size(n_cols); | | latent_out.set_size(n_cols); | |
| latent_out.zeros(); | | latent_out.zeros(); | |
| | | | |
| skipping to change at line 516 | | skipping to change at line 487 | |
| | | | |
| const unwrap_check<T1> Y( X.get_ref(), score_out ); | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
|
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in; score_out.each_row() -= mean(in); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col< T> s; | | Col< T> s; | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out,score_out); | | const bool svd_ok = svd(U, s, coeff_out, score_out); | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| | | | |
| // U.reset(); | | | |
| | | | |
| // normalize the eigenvalues | | // normalize the eigenvalues | |
| s /= std::sqrt( double(n_rows - 1) ); | | s /= std::sqrt( double(n_rows - 1) ); | |
| | | | |
| // project the samples to the principals | | // project the samples to the principals | |
| score_out *= coeff_out; | | score_out *= coeff_out; | |
| | | | |
| if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | | if(n_rows <= n_cols) // number of samples is less than their dimensiona
lity | |
| { | | { | |
| score_out.cols(n_rows-1,n_cols-1).zeros(); | | score_out.cols(n_rows-1,n_cols-1).zeros(); | |
| | | | |
| skipping to change at line 579 | | skipping to change at line 545 | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::pod_type T; | | typedef typename T1::pod_type T; | |
| typedef std::complex<T> eT; | | typedef std::complex<T> eT; | |
| | | | |
| const unwrap<T1> Y( X.get_ref() ); | | const unwrap<T1> Y( X.get_ref() ); | |
| const Mat<eT>& in = Y.M; | | const Mat<eT>& in = Y.M; | |
| | | | |
| if(in.n_elem != 0) | | if(in.n_elem != 0) | |
| { | | { | |
|
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col< T> s; | | Col< T> s; | |
| | | | |
|
| const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | | Mat<eT> tmp = in; tmp.each_row() -= mean(in); | |
| | | | |
|
| const bool svd_ok = svd(U,s,coeff_out, tmp); | | const bool svd_ok = svd(U, s, coeff_out, tmp); | |
| | | | |
|
| if(svd_ok == false) | | if(svd_ok == false) { return false; } | |
| { | | | |
| return false; | | | |
| } | | | |
| } | | } | |
| else | | else | |
| { | | { | |
| coeff_out.eye(in.n_cols, in.n_cols); | | coeff_out.eye(in.n_cols, in.n_cols); | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| | | | |
End of changes. 28 change blocks. |
| 68 lines changed or deleted | | 30 lines changed or added | |
|
| op_strans_meat.hpp | | op_strans_meat.hpp | |
| | | | |
| skipping to change at line 17 | | skipping to change at line 17 | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup op_strans | | //! \addtogroup op_strans | |
| //! @{ | | //! @{ | |
| | | | |
| //! for tiny square matrices (size <= 4x4) | | //! for tiny square matrices (size <= 4x4) | |
| template<typename eT, typename TA> | | template<typename eT, typename TA> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| op_strans::apply_noalias_tinysq(Mat<eT>& out, const TA& A) | | op_strans::apply_mat_noalias_tinysq(Mat<eT>& out, const TA& A) | |
| { | | { | |
| const eT* Am = A.memptr(); | | const eT* Am = A.memptr(); | |
| eT* outm = out.memptr(); | | eT* outm = out.memptr(); | |
| | | | |
| switch(A.n_rows) | | switch(A.n_rows) | |
| { | | { | |
| case 1: | | case 1: | |
| { | | { | |
| outm[0] = Am[0]; | | outm[0] = Am[0]; | |
| } | | } | |
| | | | |
| skipping to change at line 91 | | skipping to change at line 91 | |
| ; | | ; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! Immediate transpose of a dense matrix | | //! Immediate transpose of a dense matrix | |
| template<typename eT, typename TA> | | template<typename eT, typename TA> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| op_strans::apply_noalias(Mat<eT>& out, const TA& A) | | op_strans::apply_mat_noalias(Mat<eT>& out, const TA& A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword A_n_cols = A.n_cols; | | const uword A_n_cols = A.n_cols; | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| | | | |
| out.set_size(A_n_cols, A_n_rows); | | out.set_size(A_n_cols, A_n_rows); | |
| | | | |
| if( (TA::is_row) || (TA::is_col) || (A_n_cols == 1) || (A_n_rows == 1) ) | | if( (TA::is_row) || (TA::is_col) || (A_n_cols == 1) || (A_n_rows == 1) ) | |
| { | | { | |
| arrayops::copy( out.memptr(), A.memptr(), A.n_elem ); | | arrayops::copy( out.memptr(), A.memptr(), A.n_elem ); | |
| } | | } | |
| else | | else | |
| { | | { | |
| if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) | | if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) | |
| { | | { | |
|
| op_strans::apply_noalias_tinysq(out, A); | | op_strans::apply_mat_noalias_tinysq(out, A); | |
| } | | } | |
| else | | else | |
| { | | { | |
| for(uword k=0; k < A_n_cols; ++k) | | for(uword k=0; k < A_n_cols; ++k) | |
| { | | { | |
| uword i, j; | | uword i, j; | |
| | | | |
| const eT* colptr = A.colptr(k); | | const eT* colptr = A.colptr(k); | |
| | | | |
| for(i=0, j=1; j < A_n_rows; i+=2, j+=2) | | for(i=0, j=1; j < A_n_rows; i+=2, j+=2) | |
| | | | |
| skipping to change at line 136 | | skipping to change at line 136 | |
| | | | |
| if(i < A_n_rows) | | if(i < A_n_rows) | |
| { | | { | |
| out.at(k, i) = colptr[i]; | | out.at(k, i) = colptr[i]; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| template<typename eT, typename TA> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| op_strans::apply(Mat<eT>& out, const TA& A) | | op_strans::apply_mat_inplace(Mat<eT>& out) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| if(&out != &A) | | const uword n_rows = out.n_rows; | |
| { | | const uword n_cols = out.n_cols; | |
| op_strans::apply_noalias(out, A); | | | |
| } | | if(n_rows == n_cols) | |
| else | | | |
| { | | { | |
|
| const uword n_rows = A.n_rows; | | arma_extra_debug_print("op_strans::apply(): doing in-place transpose of | |
| const uword n_cols = A.n_cols; | | a square matrix"); | |
| | | | |
| | | const uword N = n_rows; | |
| | | | |
|
| if(n_rows == n_cols) | | for(uword k=0; k < N; ++k) | |
| { | | { | |
|
| arma_extra_debug_print("op_strans::apply(): doing in-place transpose
of a square matrix"); | | eT* colptr = out.colptr(k); | |
| | | | |
|
| const uword N = n_rows; | | uword i,j; | |
| | | | |
|
| for(uword k=0; k < N; ++k) | | for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) | |
| { | | { | |
|
| eT* colptr = out.colptr(k); | | std::swap(out.at(k,i), colptr[i]); | |
| | | std::swap(out.at(k,j), colptr[j]); | |
| uword i,j; | | } | |
| | | | |
| for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) | | | |
| { | | | |
| std::swap(out.at(k,i), colptr[i]); | | | |
| std::swap(out.at(k,j), colptr[j]); | | | |
| } | | | |
| | | | |
|
| if(i < N) | | if(i < N) | |
| { | | { | |
| std::swap(out.at(k,i), colptr[i]); | | std::swap(out.at(k,i), colptr[i]); | |
| } | | | |
| } | | } | |
| } | | } | |
|
| else | | } | |
| { | | else | |
| Mat<eT> tmp; | | { | |
| op_strans::apply_noalias(tmp, A); | | Mat<eT> tmp; | |
| | | | |
|
| out.steal_mem(tmp); | | op_strans::apply_mat_noalias(tmp, out); | |
| } | | | |
| | | out.steal_mem(tmp); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT, typename TA> | |
| | | arma_hot | |
| | | inline | |
| | | void | |
| | | op_strans::apply_mat(Mat<eT>& out, const TA& A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(&out != &A) | |
| | | { | |
| | | op_strans::apply_mat_noalias(out, A); | |
| | | } | |
| | | else | |
| | | { | |
| | | op_strans::apply_mat_inplace(out); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| op_strans::apply_proxy(Mat<typename T1::elem_type>& out, const T1& X) | | op_strans::apply_proxy(Mat<typename T1::elem_type>& out, const T1& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const Proxy<T1> P(X); | | const Proxy<T1> P(X); | |
| | | | |
| // allow detection of in-place transpose | | // allow detection of in-place transpose | |
| if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1
>::fake_mat == false) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) && (Proxy<T1
>::fake_mat == false) ) | |
| { | | { | |
| const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q); | | const unwrap<typename Proxy<T1>::stored_type> tmp(P.Q); | |
| | | | |
|
| op_strans::apply(out, tmp.M); | | op_strans::apply_mat(out, tmp.M); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const uword n_rows = P.get_n_rows(); | | const uword n_rows = P.get_n_rows(); | |
| const uword n_cols = P.get_n_cols(); | | const uword n_cols = P.get_n_cols(); | |
| | | | |
| const bool is_alias = P.is_alias(out); | | const bool is_alias = P.is_alias(out); | |
| | | | |
| if( (resolves_to_vector<T1>::value == true) && (Proxy<T1>::prefer_at_ac
cessor == false) ) | | if( (resolves_to_vector<T1>::value == true) && (Proxy<T1>::prefer_at_ac
cessor == false) ) | |
| { | | { | |
| | | | |
End of changes. 16 change blocks. |
| 36 lines changed or deleted | | 49 lines changed or added | |
|
| running_stat_vec_bones.hpp | | running_stat_vec_bones.hpp | |
|
| // Copyright (C) 2009-2011 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup running_stat_vec | | //! \addtogroup running_stat_vec | |
| //! @{ | | //! @{ | |
| | | | |
|
| | | template<typename obj_type, bool> struct rsv_get_elem_type | |
| | | { }; | |
| | | template<typename obj_type> struct rsv_get_elem_type<obj_type, false> | |
| | | { typedef obj_type elem_type; }; | |
| | | template<typename obj_type> struct rsv_get_elem_type<obj_type, true> | |
| | | { typedef typename obj_type::elem_type elem_type; }; | |
| | | | |
| //! Class for keeping statistics of a continuously sampled process / signal
. | | //! Class for keeping statistics of a continuously sampled process / signal
. | |
| //! Useful if the storage of individual samples is not necessary or desired
. | | //! Useful if the storage of individual samples is not necessary or desired
. | |
| //! Also useful if the number of samples is not known beforehand or exceeds | | //! Also useful if the number of samples is not known beforehand or exceeds | |
| //! available memory. | | //! available memory. | |
|
| template<typename eT> | | template<typename obj_type> | |
| class running_stat_vec | | class running_stat_vec | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| | | // voodoo for compatibility with old user code | |
| | | typedef typename rsv_get_elem_type<obj_type, is_Mat<obj_type>::value>::el | |
| | | em_type eT; | |
| | | | |
| typedef typename get_pod_type<eT>::result T; | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| inline ~running_stat_vec(); | | inline ~running_stat_vec(); | |
|
| inline running_stat_vec(const bool in_calc_cov = false); | | inline running_stat_vec(const bool in_calc_cov = false); // TODO: inves
tigate char* overload, eg. "calc_cov", "no_calc_cov" | |
| | | | |
| inline running_stat_vec(const running_stat_vec& in_rsv); | | inline running_stat_vec(const running_stat_vec& in_rsv); | |
| | | | |
| inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); | | inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); | |
| | | | |
|
| template<typename T1> arma_hot inline void operator() (const Base< | | template<typename T1> arma_hot inline void operator() (const Base< | |
| T, T1>& X); | | T, T1>& X); | |
| template<typename T1> arma_hot inline void operator() (const Base< std::c | | template<typename T1> arma_hot inline void operator() (const Base<std::co | |
| omplex<T>, T1>& X); | | mplex<T>, T1>& X); | |
| | | | |
| inline void reset(); | | inline void reset(); | |
| | | | |
| inline const Mat<eT>& mean() const; | | inline const Mat<eT>& mean() const; | |
| | | | |
| inline const Mat< T>& var (const uword norm_type = 0); | | inline const Mat< T>& var (const uword norm_type = 0); | |
| inline Mat< T> stddev(const uword norm_type = 0) const; | | inline Mat< T> stddev(const uword norm_type = 0) const; | |
| inline const Mat<eT>& cov (const uword norm_type = 0); | | inline const Mat<eT>& cov (const uword norm_type = 0); | |
| | | | |
| inline const Mat<eT>& min() const; | | inline const Mat<eT>& min() const; | |
| | | | |
| skipping to change at line 77 | | skipping to change at line 84 | |
| arma_aligned Mat<eT> tmp1; | | arma_aligned Mat<eT> tmp1; | |
| arma_aligned Mat<eT> tmp2; | | arma_aligned Mat<eT> tmp2; | |
| | | | |
| friend class running_stat_vec_aux; | | friend class running_stat_vec_aux; | |
| }; | | }; | |
| | | | |
| class running_stat_vec_aux | | class running_stat_vec_aux | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline static void update_stats(running_stat_vec< eT >& x, c | | inline static void | |
| onst Mat<eT>& sample); | | update_stats | |
| | | ( | |
| template<typename T> | | running_stat_vec<obj_type>& x, | |
| inline static void update_stats(running_stat_vec< std::complex<T> >& x, c | | const Mat<typename running_stat_vec<obj_type>::eT>& sa | |
| onst Mat< T>& sample); | | mple, | |
| | | const typename arma_not_cx<typename running_stat_vec<obj_type>::eT>::re | |
| template<typename T> | | sult* junk = 0 | |
| inline static void update_stats(running_stat_vec< std::complex<T> >& x, c | | ); | |
| onst Mat< std::complex<T> >& sample); | | | |
| | | template<typename obj_type> | |
| // | | inline static void | |
| | | update_stats | |
| template<typename eT> | | ( | |
| inline static Mat<eT> var(const running_stat_vec< eT >& x, c | | running_stat_vec<obj_type>& x, | |
| onst uword norm_type = 0); | | const Mat<std::complex< typename running_stat_vec<obj_type>::T | |
| | | > >& sample, | |
| template<typename T> | | const typename arma_not_cx<typename running_stat_vec<obj_type>::e | |
| inline static Mat< T> var(const running_stat_vec< std::complex<T> >& x, c | | T>::result* junk = 0 | |
| onst uword norm_type = 0); | | ); | |
| | | | |
| // | | template<typename obj_type> | |
| | | inline static void | |
| template<typename eT> | | update_stats | |
| inline static Mat< eT > cov(const running_stat_vec< eT >& | | ( | |
| x, const uword norm_type = 0); | | running_stat_vec<obj_type>& x, | |
| | | const Mat< typename running_stat_vec<obj_type>::T >& s | |
| template<typename T> | | ample, | |
| inline static Mat< std::complex<T> > cov(const running_stat_vec< std::com | | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::r | |
| plex<T> >& x, const uword norm_type = 0); | | esult* junk = 0 | |
| | | ); | |
| | | | |
| | | template<typename obj_type> | |
| | | inline static void | |
| | | update_stats | |
| | | ( | |
| | | running_stat_vec<obj_type>& x, | |
| | | const Mat<typename running_stat_vec<obj_type>::eT>& s | |
| | | ample, | |
| | | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::r | |
| | | esult* junk = 0 | |
| | | ); | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 7 change blocks. |
| 39 lines changed or deleted | | 62 lines changed or added | |
|
| running_stat_vec_meat.hpp | | running_stat_vec_meat.hpp | |
|
| // Copyright (C) 2009-2011 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup running_stat_vec | | //! \addtogroup running_stat_vec | |
| //! @{ | | //! @{ | |
| | | | |
|
| template<typename eT> | | template<typename obj_type> | |
| running_stat_vec<eT>::~running_stat_vec() | | running_stat_vec<obj_type>::~running_stat_vec() | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename obj_type> | |
| running_stat_vec<eT>::running_stat_vec(const bool in_calc_cov) | | running_stat_vec<obj_type>::running_stat_vec(const bool in_calc_cov) | |
| : calc_cov(in_calc_cov) | | : calc_cov(in_calc_cov) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename obj_type> | |
| running_stat_vec<eT>::running_stat_vec(const running_stat_vec<eT>& in_rsv) | | running_stat_vec<obj_type>::running_stat_vec(const running_stat_vec<obj_typ | |
| | | e>& in_rsv) | |
| : calc_cov (in_rsv.calc_cov) | | : calc_cov (in_rsv.calc_cov) | |
| , counter (in_rsv.counter) | | , counter (in_rsv.counter) | |
| , r_mean (in_rsv.r_mean) | | , r_mean (in_rsv.r_mean) | |
| , r_var (in_rsv.r_var) | | , r_var (in_rsv.r_var) | |
| , r_cov (in_rsv.r_cov) | | , r_cov (in_rsv.r_cov) | |
| , min_val (in_rsv.min_val) | | , min_val (in_rsv.min_val) | |
| , max_val (in_rsv.max_val) | | , max_val (in_rsv.max_val) | |
| , min_val_norm(in_rsv.min_val_norm) | | , min_val_norm(in_rsv.min_val_norm) | |
| , max_val_norm(in_rsv.max_val_norm) | | , max_val_norm(in_rsv.max_val_norm) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| } | | } | |
| | | | |
|
| template<typename eT> | | template<typename obj_type> | |
| const running_stat_vec<eT>& | | const running_stat_vec<obj_type>& | |
| running_stat_vec<eT>::operator=(const running_stat_vec<eT>& in_rsv) | | running_stat_vec<obj_type>::operator=(const running_stat_vec<obj_type>& in_ | |
| | | rsv) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| access::rw(calc_cov) = in_rsv.calc_cov; | | access::rw(calc_cov) = in_rsv.calc_cov; | |
| | | | |
| counter = in_rsv.counter; | | counter = in_rsv.counter; | |
| r_mean = in_rsv.r_mean; | | r_mean = in_rsv.r_mean; | |
| r_var = in_rsv.r_var; | | r_var = in_rsv.r_var; | |
| r_cov = in_rsv.r_cov; | | r_cov = in_rsv.r_cov; | |
| min_val = in_rsv.min_val; | | min_val = in_rsv.min_val; | |
| max_val = in_rsv.max_val; | | max_val = in_rsv.max_val; | |
| min_val_norm = in_rsv.min_val_norm; | | min_val_norm = in_rsv.min_val_norm; | |
| max_val_norm = in_rsv.max_val_norm; | | max_val_norm = in_rsv.max_val_norm; | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! update statistics to reflect new sample | | //! update statistics to reflect new sample | |
|
| template<typename eT> | | template<typename obj_type> | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec<eT>::operator() (const Base<typename get_pod_type<eT>::res
ult, T1>& X) | | running_stat_vec<obj_type>::operator() (const Base<typename running_stat_ve
c<obj_type>::T, T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| //typedef typename get_pod_type<eT>::result T; | | const unwrap<T1> tmp(X.get_ref()); | |
| | | const Mat<T>& sample = tmp.M; | |
| const unwrap<T1> tmp(X.get_ref()); | | | |
| const Mat<eT>& sample = tmp.M; | | | |
| | | | |
| if( sample.is_empty() ) | | if( sample.is_empty() ) | |
| { | | { | |
| return; | | return; | |
| } | | } | |
| | | | |
| if( sample.is_finite() == false ) | | if( sample.is_finite() == false ) | |
| { | | { | |
| arma_warn(true, "running_stat_vec: sample ignored as it has non-finite
elements"); | | arma_warn(true, "running_stat_vec: sample ignored as it has non-finite
elements"); | |
| return; | | return; | |
| } | | } | |
| | | | |
| running_stat_vec_aux::update_stats(*this, sample); | | running_stat_vec_aux::update_stats(*this, sample); | |
| } | | } | |
| | | | |
|
| //! update statistics to reflect new sample (version for complex numbers) | | template<typename obj_type> | |
| template<typename eT> | | | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec<eT>::operator() (const Base<std::complex<typename get_pod_
type<eT>::result>, T1>& X) | | running_stat_vec<obj_type>::operator() (const Base< std::complex<typename r
unning_stat_vec<obj_type>::T>, T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| //typedef typename std::complex<typename get_pod_type<eT>::result> eT; | | const unwrap<T1> tmp(X.get_ref()); | |
| | | | |
|
| const unwrap<T1> tmp(X.get_ref()); | | const Mat< std::complex<T> >& sample = tmp.M; | |
| const Mat<eT>& sample = tmp.M; | | | |
| | | | |
| if( sample.is_empty() ) | | if( sample.is_empty() ) | |
| { | | { | |
| return; | | return; | |
| } | | } | |
| | | | |
| if( sample.is_finite() == false ) | | if( sample.is_finite() == false ) | |
| { | | { | |
| arma_warn(true, "running_stat_vec: sample ignored as it has non-finite
elements"); | | arma_warn(true, "running_stat_vec: sample ignored as it has non-finite
elements"); | |
| return; | | return; | |
| } | | } | |
| | | | |
| running_stat_vec_aux::update_stats(*this, sample); | | running_stat_vec_aux::update_stats(*this, sample); | |
| } | | } | |
| | | | |
| //! set all statistics to zero | | //! set all statistics to zero | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec<eT>::reset() | | running_stat_vec<obj_type>::reset() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| counter.reset(); | | counter.reset(); | |
| | | | |
| r_mean.reset(); | | r_mean.reset(); | |
| r_var.reset(); | | r_var.reset(); | |
| r_cov.reset(); | | r_cov.reset(); | |
| | | | |
| min_val.reset(); | | min_val.reset(); | |
| | | | |
| skipping to change at line 145 | | skipping to change at line 141 | |
| max_val_norm.reset(); | | max_val_norm.reset(); | |
| | | | |
| r_var_dummy.reset(); | | r_var_dummy.reset(); | |
| r_cov_dummy.reset(); | | r_cov_dummy.reset(); | |
| | | | |
| tmp1.reset(); | | tmp1.reset(); | |
| tmp2.reset(); | | tmp2.reset(); | |
| } | | } | |
| | | | |
| //! mean or average value | | //! mean or average value | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| const Mat<eT>& | | const Mat< typename running_stat_vec<obj_type>::eT >& | |
| running_stat_vec<eT>::mean() const | | running_stat_vec<obj_type>::mean() const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return r_mean; | | return r_mean; | |
| } | | } | |
| | | | |
| //! variance | | //! variance | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| const Mat<typename get_pod_type<eT>::result>& | | const Mat< typename running_stat_vec<obj_type>::T >& | |
| running_stat_vec<eT>::var(const uword norm_type) | | running_stat_vec<obj_type>::var(const uword norm_type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const T N = counter.value(); | | const T N = counter.value(); | |
| | | | |
| if(N > T(1)) | | if(N > T(1)) | |
| { | | { | |
| if(norm_type == 0) | | if(norm_type == 0) | |
| { | | { | |
| return r_var; | | return r_var; | |
| | | | |
| skipping to change at line 190 | | skipping to change at line 186 | |
| else | | else | |
| { | | { | |
| r_var_dummy.zeros(r_mean.n_rows, r_mean.n_cols); | | r_var_dummy.zeros(r_mean.n_rows, r_mean.n_cols); | |
| | | | |
| return r_var_dummy; | | return r_var_dummy; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! standard deviation | | //! standard deviation | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| Mat<typename get_pod_type<eT>::result> | | Mat< typename running_stat_vec<obj_type>::T > | |
| running_stat_vec<eT>::stddev(const uword norm_type) const | | running_stat_vec<obj_type>::stddev(const uword norm_type) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const T N = counter.value(); | | const T N = counter.value(); | |
| | | | |
| if(N > T(1)) | | if(N > T(1)) | |
| { | | { | |
| if(norm_type == 0) | | if(norm_type == 0) | |
| { | | { | |
| return sqrt(r_var); | | return sqrt(r_var); | |
| | | | |
| skipping to change at line 219 | | skipping to change at line 215 | |
| return sqrt( (N_minus_1/N) * r_var ); | | return sqrt( (N_minus_1/N) * r_var ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| return Mat<T>(); | | return Mat<T>(); | |
| } | | } | |
| } | | } | |
| | | | |
| //! covariance | | //! covariance | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| const Mat<eT>& | | const Mat< typename running_stat_vec<obj_type>::eT >& | |
| running_stat_vec<eT>::cov(const uword norm_type) | | running_stat_vec<obj_type>::cov(const uword norm_type) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(calc_cov == true) | | if(calc_cov == true) | |
| { | | { | |
| const T N = counter.value(); | | const T N = counter.value(); | |
| | | | |
| if(N > T(1)) | | if(N > T(1)) | |
| { | | { | |
| if(norm_type == 0) | | if(norm_type == 0) | |
| | | | |
| skipping to change at line 262 | | skipping to change at line 258 | |
| else | | else | |
| { | | { | |
| r_cov_dummy.reset(); | | r_cov_dummy.reset(); | |
| | | | |
| return r_cov_dummy; | | return r_cov_dummy; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! vector with minimum values | | //! vector with minimum values | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| const Mat<eT>& | | const Mat< typename running_stat_vec<obj_type>::eT >& | |
| running_stat_vec<eT>::min() const | | running_stat_vec<obj_type>::min() const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return min_val; | | return min_val; | |
| } | | } | |
| | | | |
| //! vector with maximum values | | //! vector with maximum values | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| const Mat<eT>& | | const Mat< typename running_stat_vec<obj_type>::eT >& | |
| running_stat_vec<eT>::max() const | | running_stat_vec<obj_type>::max() const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return max_val; | | return max_val; | |
| } | | } | |
| | | | |
| //! number of samples so far | | //! number of samples so far | |
|
| template<typename eT> | | template<typename obj_type> | |
| inline | | inline | |
|
| typename get_pod_type<eT>::result | | typename running_stat_vec<obj_type>::T | |
| running_stat_vec<eT>::count() const | | running_stat_vec<obj_type>::count() const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return counter.value(); | | return counter.value(); | |
| } | | } | |
| | | | |
| // | | // | |
| | | | |
|
| //! update statistics to reflect new sample | | //! update statistics to reflect new sample (version for non-complex number | |
| template<typename eT> | | s) | |
| | | template<typename obj_type> | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec_aux::update_stats(running_stat_vec<eT>& x, const Mat<eT>& | | running_stat_vec_aux::update_stats | |
| sample) | | ( | |
| | | running_stat_vec<obj_type>& x, | |
| | | const Mat<typename running_stat_vec<obj_type>::eT>& samp | |
| | | le, | |
| | | const typename arma_not_cx<typename running_stat_vec<obj_type>::eT>::resu | |
| | | lt* junk | |
| | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
|
| typedef typename running_stat_vec<eT>::T T; | | typedef typename running_stat_vec<obj_type>::eT eT; | |
| | | typedef typename running_stat_vec<obj_type>::T T; | |
| | | | |
| const T N = x.counter.value(); | | const T N = x.counter.value(); | |
| | | | |
| if(N > T(0)) | | if(N > T(0)) | |
| { | | { | |
| arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dime
nsionality mismatch"); | | arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dime
nsionality mismatch"); | |
| | | | |
| const uword n_elem = sample.n_elem; | | const uword n_elem = sample.n_elem; | |
| const eT* sample_mem = sample.memptr(); | | const eT* sample_mem = sample.memptr(); | |
| eT* r_mean_mem = x.r_mean.memptr(); | | eT* r_mean_mem = x.r_mean.memptr(); | |
| | | | |
| skipping to change at line 390 | | skipping to change at line 393 | |
| const uword n_elem = sample.n_elem; | | const uword n_elem = sample.n_elem; | |
| const eT* sample_mem = sample.memptr(); | | const eT* sample_mem = sample.memptr(); | |
| eT* r_mean_mem = x.r_mean.memptr(); | | eT* r_mean_mem = x.r_mean.memptr(); | |
| eT* min_val_mem = x.min_val.memptr(); | | eT* min_val_mem = x.min_val.memptr(); | |
| eT* max_val_mem = x.max_val.memptr(); | | eT* max_val_mem = x.max_val.memptr(); | |
| | | | |
| for(uword i=0; i<n_elem; ++i) | | for(uword i=0; i<n_elem; ++i) | |
| { | | { | |
| const eT val = sample_mem[i]; | | const eT val = sample_mem[i]; | |
| | | | |
|
| r_mean_mem[i] = val; | | r_mean_mem[i] = val; | |
| min_val_mem[i] = val; | | min_val_mem[i] = val; | |
| max_val_mem[i] = val; | | max_val_mem[i] = val; | |
| } | | } | |
| } | | } | |
| | | | |
| x.counter++; | | x.counter++; | |
| } | | } | |
| | | | |
|
| //! update statistics to reflect new sample (version for complex numbers) | | //! update statistics to reflect new sample (version for non-complex number | |
| template<typename T> | | s, complex sample) | |
| | | template<typename obj_type> | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec_aux::update_stats(running_stat_vec< std::complex<T> >& x, | | running_stat_vec_aux::update_stats | |
| const Mat<T>& sample) | | ( | |
| | | running_stat_vec<obj_type>& x, | |
| | | const Mat<std::complex< typename running_stat_vec<obj_type>::T > | |
| | | >& sample, | |
| | | const typename arma_not_cx<typename running_stat_vec<obj_type>::eT> | |
| | | ::result* junk | |
| | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
|
| const Mat< std::complex<T> > tmp = conv_to< Mat< std::complex<T> > >::fro
m(sample); | | typedef typename running_stat_vec<obj_type>::eT eT; | |
| | | | |
|
| running_stat_vec_aux::update_stats(x, tmp); | | running_stat_vec_aux::update_stats(x, conv_to< Mat<eT> >::from(sample)); | |
| } | | } | |
| | | | |
|
| //! alter statistics to reflect new sample (version for complex numbers) | | //! update statistics to reflect new sample (version for complex numbers, n | |
| template<typename T> | | on-complex sample) | |
| | | template<typename obj_type> | |
| inline | | inline | |
| void | | void | |
|
| running_stat_vec_aux::update_stats(running_stat_vec< std::complex<T> >& x, | | running_stat_vec_aux::update_stats | |
| const Mat< std::complex<T> >& sample) | | ( | |
| | | running_stat_vec<obj_type>& x, | |
| | | const Mat<typename running_stat_vec<obj_type>::T >& sam | |
| | | ple, | |
| | | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::res | |
| | | ult* junk | |
| | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename running_stat_vec<obj_type>::eT eT; | |
| | | | |
|
| typedef typename std::complex<T> eT; | | running_stat_vec_aux::update_stats(x, conv_to< Mat<eT> >::from(sample)); | |
| | | } | |
| | | | |
| | | //! alter statistics to reflect new sample (version for complex numbers, co | |
| | | mplex sample) | |
| | | template<typename obj_type> | |
| | | inline | |
| | | void | |
| | | running_stat_vec_aux::update_stats | |
| | | ( | |
| | | running_stat_vec<obj_type>& x, | |
| | | const Mat<typename running_stat_vec<obj_type>::eT>& sam | |
| | | ple, | |
| | | const typename arma_cx_only<typename running_stat_vec<obj_type>::eT>::res | |
| | | ult* junk | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename running_stat_vec<obj_type>::eT eT; | |
| | | typedef typename running_stat_vec<obj_type>::T T; | |
| | | | |
| const T N = x.counter.value(); | | const T N = x.counter.value(); | |
| | | | |
| if(N > T(0)) | | if(N > T(0)) | |
| { | | { | |
| arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dime
nsionality mismatch"); | | arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dime
nsionality mismatch"); | |
| | | | |
| const uword n_elem = sample.n_elem; | | const uword n_elem = sample.n_elem; | |
| const eT* sample_mem = sample.memptr(); | | const eT* sample_mem = sample.memptr(); | |
| eT* r_mean_mem = x.r_mean.memptr(); | | eT* r_mean_mem = x.r_mean.memptr(); | |
| | | | |
| skipping to change at line 483 | | skipping to change at line 518 | |
| max_val_norm_mem[i] = val_norm; | | max_val_norm_mem[i] = val_norm; | |
| max_val_mem[i] = val; | | max_val_mem[i] = val; | |
| } | | } | |
| | | | |
| const eT& r_mean_val = r_mean_mem[i]; | | const eT& r_mean_val = r_mean_mem[i]; | |
| | | | |
| r_var_mem[i] = N_minus_1/N * r_var_mem[i] + std::norm(val - r_mean_va
l)/N_plus_1; | | r_var_mem[i] = N_minus_1/N * r_var_mem[i] + std::norm(val - r_mean_va
l)/N_plus_1; | |
| | | | |
| r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; | | r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; | |
| } | | } | |
|
| | | | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): give
n sample is not a vector"); | | arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): give
n sample is not a vector"); | |
| | | | |
| x.r_mean.set_size(sample.n_rows, sample.n_cols); | | x.r_mean.set_size(sample.n_rows, sample.n_cols); | |
| | | | |
| x.r_var.zeros(sample.n_rows, sample.n_cols); | | x.r_var.zeros(sample.n_rows, sample.n_cols); | |
| | | | |
| if(x.calc_cov == true) | | if(x.calc_cov == true) | |
| | | | |
| skipping to change at line 517 | | skipping to change at line 551 | |
| eT* min_val_mem = x.min_val.memptr(); | | eT* min_val_mem = x.min_val.memptr(); | |
| eT* max_val_mem = x.max_val.memptr(); | | eT* max_val_mem = x.max_val.memptr(); | |
| T* min_val_norm_mem = x.min_val_norm.memptr(); | | T* min_val_norm_mem = x.min_val_norm.memptr(); | |
| T* max_val_norm_mem = x.max_val_norm.memptr(); | | T* max_val_norm_mem = x.max_val_norm.memptr(); | |
| | | | |
| for(uword i=0; i<n_elem; ++i) | | for(uword i=0; i<n_elem; ++i) | |
| { | | { | |
| const eT& val = sample_mem[i]; | | const eT& val = sample_mem[i]; | |
| const T val_norm = std::norm(val); | | const T val_norm = std::norm(val); | |
| | | | |
|
| r_mean_mem[i] = val; | | r_mean_mem[i] = val; | |
| min_val_mem[i] = val; | | min_val_mem[i] = val; | |
| max_val_mem[i] = val; | | max_val_mem[i] = val; | |
| | | | |
| min_val_norm_mem[i] = val_norm; | | min_val_norm_mem[i] = val_norm; | |
| max_val_norm_mem[i] = val_norm; | | max_val_norm_mem[i] = val_norm; | |
| } | | } | |
| } | | } | |
| | | | |
| x.counter++; | | x.counter++; | |
| } | | } | |
| | | | |
End of changes. 44 change blocks. |
| 65 lines changed or deleted | | 110 lines changed or added | |
|
| subview_meat.hpp | | subview_meat.hpp | |
| // Copyright (C) 2008-2013 Conrad Sanderson | | // Copyright (C) 2008-2013 Conrad Sanderson | |
| // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) | |
|
| // Copyright (C) 2011 James Sanders | | // Copyright (C) 2011 James Sanders | |
| | | // Copyright (C) 2013 Ryan Curtin | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup subview | | //! \addtogroup subview | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| | | | |
| skipping to change at line 725 | | skipping to change at line 726 | |
| | | | |
| if(ii < s_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
| s_col_data[ii] /= P.at(ii,ucol); | | s_col_data[ii] /= P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | subview<eT>::operator=(const SpBase<eT, T1>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpProxy<T1> p(x.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols( | |
| | | ), "copy into submatrix"); | |
| | | | |
| | | // Clear the subview. | |
| | | zeros(); | |
| | | | |
| | | // Iterate through the sparse subview and set the nonzero values appropri | |
| | | ately. | |
| | | typename SpProxy<T1>::const_iterator_type cit = p.begin(); | |
| | | | |
| | | while (cit != p.end()) | |
| | | { | |
| | | at(cit.row(), cit.col()) = *cit; | |
| | | ++cit; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | subview<eT>::operator+=(const SpBase<eT, T1>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpProxy<T1> p(x.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols( | |
| | | ), "addition"); | |
| | | | |
| | | // Iterate through the sparse subview and add its values. | |
| | | typename SpProxy<T1>::const_iterator_type cit = p.begin(); | |
| | | | |
| | | while (cit != p.end()) | |
| | | { | |
| | | at(cit.row(), cit.col()) += *cit; | |
| | | ++cit; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | subview<eT>::operator-=(const SpBase<eT, T1>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpProxy<T1> p(x.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols( | |
| | | ), "subtraction"); | |
| | | | |
| | | // Iterate through the sparse subview and subtract its values. | |
| | | typename SpProxy<T1>::const_iterator_type cit = p.begin(); | |
| | | | |
| | | while (cit != p.end()) | |
| | | { | |
| | | at(cit.row(), cit.col()) -= *cit; | |
| | | ++cit; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | subview<eT>::operator%=(const SpBase<eT, T1>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | // Temporary sparse matrix to hold the values we need. | |
| | | SpMat<eT> tmp = x.get_ref(); | |
| | | | |
| | | arma_debug_assert_same_size(n_rows, n_cols, tmp.n_rows, tmp.n_cols, "elem | |
| | | ent-wise multiplication"); | |
| | | | |
| | | // Iterate over nonzero values. | |
| | | // Any zero values in the sparse expression will result in a zero in our | |
| | | subview. | |
| | | typename SpMat<eT>::const_iterator cit = tmp.begin(); | |
| | | | |
| | | while (cit != tmp.end()) | |
| | | { | |
| | | // Set elements before this one to zero. | |
| | | tmp.at(cit.row(), cit.col()) *= at(cit.row(), cit.col()); | |
| | | ++cit; | |
| | | } | |
| | | | |
| | | // Now set the subview equal to that. | |
| | | *this = tmp; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | void | |
| | | subview<eT>::operator/=(const SpBase<eT, T1>& x) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const SpProxy<T1> p(x.get_ref()); | |
| | | | |
| | | arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols( | |
| | | ), "element-wise division"); | |
| | | | |
| | | // This is probably going to fill your subview with a bunch of NaNs, | |
| | | // so I'm not going to bother to implement it fast. | |
| | | // You can have slow NaNs. They're fine too. | |
| | | for (uword c = 0; c < n_cols; ++c) | |
| | | for (uword r = 0; r < n_rows; ++r) | |
| | | { | |
| | | at(r, c) /= p.at(r, c); | |
| | | } | |
| | | } | |
| | | | |
| //! x.submat(...) = y.submat(...) | | //! x.submat(...) = y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const subview<eT>& x_in) | | subview<eT>::operator= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| | | | |
| skipping to change at line 1208 | | skipping to change at line 1328 | |
| const uword N = (std::min)(n_rows, n_cols); | | const uword N = (std::min)(n_rows, n_cols); | |
| | | | |
| for(uword ii=0; ii < N; ++ii) | | for(uword ii=0; ii < N; ++ii) | |
| { | | { | |
| at(ii,ii) = eT(1); | | at(ii,ii) = eT(1); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| | | void | |
| | | subview<eT>::randu() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| | | if(local_n_rows == 1) | |
| | | { | |
| | | for(uword ii=0; ii < local_n_cols; ++ii) | |
| | | { | |
| | | at(0,ii) = eT(arma_rng::randu<eT>()); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(uword ii=0; ii < local_n_cols; ++ii) | |
| | | { | |
| | | arma_rng::randu<eT>::fill( colptr(ii), local_n_rows ); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | subview<eT>::randn() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| | | if(local_n_rows == 1) | |
| | | { | |
| | | for(uword ii=0; ii < local_n_cols; ++ii) | |
| | | { | |
| | | at(0,ii) = eT(arma_rng::randn<eT>()); | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | for(uword ii=0; ii < local_n_cols; ++ii) | |
| | | { | |
| | | arma_rng::randn<eT>::fill( colptr(ii), local_n_rows ); | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| eT | | eT | |
| subview<eT>::at_alt(const uword ii) const | | subview<eT>::at_alt(const uword ii) const | |
| { | | { | |
| return operator[](ii); | | return operator[](ii); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
| subview<eT>::operator[](const uword ii) | | subview<eT>::operator[](const uword ii) | |
| | | | |
End of changes. 3 change blocks. |
| 1 lines changed or deleted | | 180 lines changed or added | |
|