| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 2933 | | skipping to change at line 2933 | |
| inline | | inline | |
| const subview<eT> | | const subview<eT> | |
| Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat
& s) const | | Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat
& s) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| return (*this).submat(in_row1, in_col1, s); | | return (*this).submat(in_row1, in_col1, s); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| | | inline | |
| | | subview<eT> | |
| | | Mat<eT>::head_rows(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds"); | |
| | | | |
| | | return subview<eT>(*this, 0, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview<eT> | |
| | | Mat<eT>::head_rows(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds"); | |
| | | | |
| | | return subview<eT>(*this, 0, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | subview<eT> | |
| | | Mat<eT>::tail_rows(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds"); | |
| | | | |
| | | const uword start_row = n_rows - N; | |
| | | | |
| | | return subview<eT>(*this, start_row, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview<eT> | |
| | | Mat<eT>::tail_rows(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds"); | |
| | | | |
| | | const uword start_row = n_rows - N; | |
| | | | |
| | | return subview<eT>(*this, start_row, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | subview<eT> | |
| | | Mat<eT>::head_cols(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds"); | |
| | | | |
| | | return subview<eT>(*this, 0, 0, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview<eT> | |
| | | Mat<eT>::head_cols(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds"); | |
| | | | |
| | | return subview<eT>(*this, 0, 0, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | subview<eT> | |
| | | Mat<eT>::tail_cols(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds"); | |
| | | | |
| | | const uword start_col = n_cols - N; | |
| | | | |
| | | return subview<eT>(*this, 0, start_col, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const subview<eT> | |
| | | Mat<eT>::tail_cols(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds"); | |
| | | | |
| | | const uword start_col = n_cols - N; | |
| | | | |
| | | return subview<eT>(*this, 0, start_col, n_rows, N); | |
| | | } | |
| | | | |
| | | 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 6519 | | skipping to change at line 6623 | |
| #endif | | #endif | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const fixed<fixed_n_r
ows, fixed_n_cols>& X) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const fixed<fixed_n_r
ows, fixed_n_cols>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT* dest = (use_extra) ? mem_local_extra : mem_local; | | if(this != &X) | |
| const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; | | { | |
| | | eT* dest = (use_extra) ? mem_local_extra : mem_local; | |
| | | const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; | |
| | | | |
|
| arrayops::copy( dest, src, fixed_n_elem ); | | arrayops::copy( dest, src, fixed_n_elem ); | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| | | template<typename T1, typename eop_type> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eOp<T1, eop_typ | |
| | | e>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); | |
| | | | |
| | | const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X | |
| | | .P.is_alias(*this)); | |
| | | | |
| | | if(bad_alias == false) | |
| | | { | |
| | | arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), | |
| | | X.get_n_cols(), "Mat::fixed::operator="); | |
| | | | |
| | | eop_type::apply(*this, X); | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_extra_debug_print("bad_alias = true"); | |
| | | | |
| | | Mat<eT> tmp(X); | |
| | | | |
| | | (*this) = tmp; | |
| | | } | |
| | | | |
| | | return *this; | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| | | template<typename T1, typename T2, typename eglue_type> | |
| | | inline | |
| | | const Mat<eT>& | |
| | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eGlue<T1, T2, e | |
| | | glue_type>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); | |
| | | arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); | |
| | | | |
| | | const bool bad_alias = | |
| | | ( | |
| | | (eGlue<T1, T2, eglue_type>::proxy1_type::has_subview && X.P1.is_alias | |
| | | (*this)) | |
| | | || | |
| | | (eGlue<T1, T2, eglue_type>::proxy2_type::has_subview && X.P2.is_alias | |
| | | (*this)) | |
| | | ); | |
| | | | |
| | | if(bad_alias == false) | |
| | | { | |
| | | arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), | |
| | | X.get_n_cols(), "Mat::fixed::operator="); | |
| | | | |
| | | eglue_type::apply(*this, X); | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_extra_debug_print("bad_alias = true"); | |
| | | | |
| | | Mat<eT> tmp(X); | |
| | | | |
| | | (*this) = tmp; | |
| | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| const Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat
_fixed_type, op_htrans > | | const Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat
_fixed_type, op_htrans > | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::t() const | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::t() const | |
| { | | { | |
| | | | |
End of changes. 3 change blocks. |
| 3 lines changed or deleted | | 185 lines changed or added | |
|
| SpMat_bones.hpp | | SpMat_bones.hpp | |
| // Copyright (C) 2011-2014 Ryan Curtin | | // Copyright (C) 2011-2014 Ryan Curtin | |
|
| // Copyright (C) 2012-2014 Conrad Sanderson | | // Copyright (C) 2012-2015 Conrad Sanderson | |
| // Copyright (C) 2011 Matthew Amidon | | // Copyright (C) 2011 Matthew Amidon | |
| // | | // | |
| // 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 SpMat | | //! \addtogroup SpMat | |
| //! @{ | | //! @{ | |
| | | | |
| //! Sparse matrix class, with data stored in compressed sparse column (CSC)
format | | //! Sparse matrix class, with data stored in compressed sparse column (CSC)
format | |
| | | | |
| skipping to change at line 77 | | skipping to change at line 77 | |
| * | | * | |
| * The col_ptrs array is set by the init() function (which is called by t
he | | * The col_ptrs array is set by the init() function (which is called by t
he | |
| * constructors and set_size() and other functions that set the size of t
he | | * constructors and set_size() and other functions that set the size of t
he | |
| * matrix), so allocating col_ptrs by hand should not be necessary. | | * matrix), so allocating col_ptrs by hand should not be necessary. | |
| */ | | */ | |
| 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) | | #if defined(ARMA_USE_CXX11) | |
| inline SpMat(SpMat&& m); | | inline SpMat(SpMat&& m); | |
| inline const SpMat& operator=(SpMat&& m); | | inline const SpMat& operator=(SpMat&& m); | |
| | | | |
| skipping to change at line 194 | | skipping to change at line 194 | |
| | | | |
| inline SpSubview<eT> operator()(const uword row_num, const spa
n& col_span); | | inline SpSubview<eT> operator()(const uword row_num, const spa
n& col_span); | |
| inline const SpSubview<eT> operator()(const uword row_num, const spa
n& col_span) const; | | inline const SpSubview<eT> operator()(const uword row_num, const spa
n& col_span) const; | |
| | | | |
| arma_inline SpSubview<eT> col(const uword col_num); | | arma_inline SpSubview<eT> col(const uword col_num); | |
| arma_inline const SpSubview<eT> col(const uword col_num) const; | | arma_inline const SpSubview<eT> col(const uword col_num) const; | |
| | | | |
| inline SpSubview<eT> operator()(const span& row_span, const uw
ord col_num); | | inline SpSubview<eT> operator()(const span& row_span, const uw
ord col_num); | |
| inline const SpSubview<eT> operator()(const span& row_span, const uw
ord col_num) const; | | inline const SpSubview<eT> operator()(const span& row_span, const uw
ord col_num) const; | |
| | | | |
|
| /** | | | |
| * Row- and column-related functions. | | | |
| */ | | | |
| inline void swap_rows(const uword in_row1, const uword in_row2); | | | |
| inline void swap_cols(const uword in_col1, const uword in_col2); | | | |
| | | | |
| inline void shed_row(const uword row_num); | | | |
| inline void shed_col(const uword col_num); | | | |
| | | | |
| inline void shed_rows(const uword in_row1, const uword in_row2); | | | |
| inline void shed_cols(const uword in_col1, const uword in_col2); | | | |
| | | | |
| 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 SpSubview<eT> submat(const uword in_row1, const uword i
n_col1, const SizeMat& s); | |
| | | | |
| skipping to change at line 227 | | skipping to change at line 215 | |
| | | | |
| 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 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; | | arma_inline const SpSubview<eT> operator()(const uword in_row1, const uwo
rd in_col1, const SizeMat& s) const; | |
| | | | |
|
| | | inline SpSubview<eT> head_rows(const uword N); | |
| | | inline const SpSubview<eT> head_rows(const uword N) const; | |
| | | | |
| | | inline SpSubview<eT> tail_rows(const uword N); | |
| | | inline const SpSubview<eT> tail_rows(const uword N) const; | |
| | | | |
| | | inline SpSubview<eT> head_cols(const uword N); | |
| | | inline const SpSubview<eT> head_cols(const uword N) const; | |
| | | | |
| | | inline SpSubview<eT> tail_cols(const uword N); | |
| | | inline const SpSubview<eT> tail_cols(const uword N) const; | |
| | | | |
| | | inline void swap_rows(const uword in_row1, const uword in_row2); | |
| | | inline void swap_cols(const uword in_col1, const uword in_col2); | |
| | | | |
| | | inline void shed_row(const uword row_num); | |
| | | inline void shed_col(const uword col_num); | |
| | | | |
| | | inline void shed_rows(const uword in_row1, const uword in_row2); | |
| | | inline void shed_cols(const uword in_col1, const uword in_col2); | |
| | | | |
| /** | | /** | |
| * 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; | |
| | | | |
End of changes. 4 change blocks. |
| 14 lines changed or deleted | | 23 lines changed or added | |
|
| SpMat_meat.hpp | | SpMat_meat.hpp | |
| // Copyright (C) 2011-2014 Ryan Curtin | | // Copyright (C) 2011-2014 Ryan Curtin | |
|
| // Copyright (C) 2012-2014 Conrad Sanderson | | // Copyright (C) 2012-2015 Conrad Sanderson | |
| // Copyright (C) 2011 Matthew Amidon | | // Copyright (C) 2011 Matthew Amidon | |
| // | | // | |
| // 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 SpMat | | //! \addtogroup SpMat | |
| //! @{ | | //! @{ | |
| | | | |
| /** | | /** | |
| | | | |
| skipping to change at line 1744 | | skipping to change at line 1744 | |
| (col_num >= n_cols) | | (col_num >= n_cols) | |
| || | | || | |
| ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows))
) | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows))
) | |
| , | | , | |
| "SpMat::operator(): indices out of bounds or incorrectly used" | | "SpMat::operator(): indices out of bounds or incorrectly used" | |
| ); | | ); | |
| | | | |
| return SpSubview<eT>(*this, in_row1, col_num, submat_n_rows, 1); | | return SpSubview<eT>(*this, in_row1, col_num, submat_n_rows, 1); | |
| } | | } | |
| | | | |
|
| /** | | template<typename eT> | |
| * Swap in_row1 with in_row2. | | arma_inline | |
| */ | | SpSubview<eT> | |
| | | SpMat<eT>::rows(const uword in_row1, const uword in_row2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| | | "SpMat::rows(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::rows(const uword in_row1, const uword in_row2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| | | "SpMat::rows(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::cols(const uword in_col1, const uword in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| | | "SpMat::cols(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::cols(const uword in_col1, const uword in_col2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| | | "SpMat::cols(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ | |
| | | row2, const uword in_col2) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | |
| | | in_col2 >= n_cols), | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c | |
| | | ols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | arma_inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ | |
| | | row2, const uword in_col2) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | |
| | | in_col2 >= n_cols), | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | const uword subview_n_rows = in_row2 - in_row1 + 1; | |
| | | const uword subview_n_cols = in_col2 - in_col1 + 1; | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c | |
| | | ols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | 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 | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::submat(const span& row_span, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const bool row_all = row_span.whole; | |
| | | const bool col_all = col_span.whole; | |
| | | | |
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | const uword in_row2 = row_span.b; | |
| | | const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + | |
| | | 1; | |
| | | | |
| | | const uword in_col1 = col_all ? 0 : col_span.a; | |
| | | const uword in_col2 = col_span.b; | |
| | | const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + | |
| | | 1; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| | | ) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col | |
| | | s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::submat(const span& row_span, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | const bool row_all = row_span.whole; | |
| | | const bool col_all = col_span.whole; | |
| | | | |
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| | | const uword in_row1 = row_all ? 0 : row_span.a; | |
| | | const uword in_row2 = row_span.b; | |
| | | const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + | |
| | | 1; | |
| | | | |
| | | const uword in_col1 = col_all ? 0 : col_span.a; | |
| | | const uword in_col2 = col_span.b; | |
| | | const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + | |
| | | 1; | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | |
| | | ) | |
| | | || | |
| | | ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | |
| | | ) | |
| | | , | |
| | | "SpMat::submat(): indices out of bounds or incorrectly used" | |
| | | ); | |
| | | | |
| | | return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col | |
| | | s); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::operator()(const span& row_span, const span& col_span) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return submat(row_span, col_span); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::operator()(const span& row_span, const span& col_span) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | 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); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::head_rows(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "SpMat::head_rows(): size out of bounds") | |
| | | ; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::head_rows(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "SpMat::head_rows(): size out of bounds") | |
| | | ; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::tail_rows(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "SpMat::tail_rows(): size out of bounds") | |
| | | ; | |
| | | | |
| | | const uword start_row = n_rows - N; | |
| | | | |
| | | return SpSubview<eT>(*this, start_row, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::tail_rows(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_rows), "SpMat::tail_rows(): size out of bounds") | |
| | | ; | |
| | | | |
| | | const uword start_row = n_rows - N; | |
| | | | |
| | | return SpSubview<eT>(*this, start_row, 0, N, n_cols); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::head_cols(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "SpMat::head_cols(): size out of bounds") | |
| | | ; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, 0, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::head_cols(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "SpMat::head_cols(): size out of bounds") | |
| | | ; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, 0, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | SpSubview<eT> | |
| | | SpMat<eT>::tail_cols(const uword N) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "SpMat::tail_cols(): size out of bounds") | |
| | | ; | |
| | | | |
| | | const uword start_col = n_cols - N; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, start_col, n_rows, N); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | inline | |
| | | const SpSubview<eT> | |
| | | SpMat<eT>::tail_cols(const uword N) const | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check( (N > n_cols), "SpMat::tail_cols(): size out of bounds") | |
| | | ; | |
| | | | |
| | | const uword start_col = n_cols - N; | |
| | | | |
| | | return SpSubview<eT>(*this, 0, start_col, n_rows, N); | |
| | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| SpMat<eT>::swap_rows(const uword in_row1, const uword in_row2) | | SpMat<eT>::swap_rows(const uword in_row1, const uword in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 >= n_rows) || (in_row2 >= n_rows), | | (in_row1 >= n_rows) || (in_row2 >= n_rows), | |
| | | | |
| skipping to change at line 1855 | | skipping to change at line 2216 | |
| } | | } | |
| | | | |
| // Now set the row index correctly. | | // Now set the row index correctly. | |
| access::rw(row_indices[loc2]) = in_row1; | | access::rw(row_indices[loc2]) = in_row1; | |
| | | | |
| } | | } | |
| /* else: no need to swap anything; both values are zero */ | | /* else: no need to swap anything; both values are zero */ | |
| } | | } | |
| } | | } | |
| | | | |
|
| /** | | | |
| * Swap in_col1 with in_col2. | | | |
| */ | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| SpMat<eT>::swap_cols(const uword in_col1, const uword in_col2) | | SpMat<eT>::swap_cols(const uword in_col1, const uword in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| // slow but works | | // slow but works | |
| for(uword lrow = 0; lrow < n_rows; ++lrow) | | for(uword lrow = 0; lrow < n_rows; ++lrow) | |
| { | | { | |
| eT tmp = at(lrow, in_col1); | | eT tmp = at(lrow, in_col1); | |
| at(lrow, in_col1) = at(lrow, in_col2); | | at(lrow, in_col1) = at(lrow, in_col2); | |
|
| at(lrow, in_col2) = tmp; | | at(lrow, in_col2) = tmp; | |
| } | | } | |
| } | | | |
| | | | |
| /** | | | |
| * Remove the row row_num. | | | |
| */ | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| SpMat<eT>::shed_row(const uword row_num) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| arma_debug_check (row_num >= n_rows, "SpMat::shed_row(): out of bounds"); | | | |
| | | | |
| shed_rows (row_num, row_num); | | | |
| } | | | |
| | | | |
| /** | | | |
| * Remove the column col_num. | | | |
| */ | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| SpMat<eT>::shed_col(const uword col_num) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| arma_debug_check (col_num >= n_cols, "SpMat::shed_col(): out of bounds"); | | | |
| | | | |
| shed_cols(col_num, col_num); | | | |
| } | | | |
| | | | |
| /** | | | |
| * Remove all rows between (and including) in_row1 and in_row2. | | | |
| */ | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| SpMat<eT>::shed_rows(const uword in_row1, const uword in_row2) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | | |
| "SpMat::shed_rows(): indices out of bounds or incorectly used" | | | |
| ); | | | |
| | | | |
| uword i, j; | | | |
| // Store the length of values | | | |
| uword vlength = n_nonzero; | | | |
| // Store the length of col_ptrs | | | |
| uword clength = n_cols + 1; | | | |
| | | | |
| // This is O(n * n_cols) and inplace, there may be a faster way, though. | | | |
| for (i = 0, j = 0; i < vlength; ++i) | | | |
| { | | | |
| // Store the row of the ith element. | | | |
| const uword lrow = row_indices[i]; | | | |
| // Is the ith element in the range of rows we want to remove? | | | |
| if (lrow >= in_row1 && lrow <= in_row2) | | | |
| { | | | |
| // Increment our "removed elements" counter. | | | |
| ++j; | | | |
| | | | |
| // Adjust the values of col_ptrs each time we remove an element. | | | |
| // Basically, the length of one column reduces by one, and everything | | | |
| to | | | |
| // its right gets reduced by one to represent all the elements being | | | |
| // shifted to the left by one. | | | |
| for(uword k = 0; k < clength; ++k) | | | |
| { | | | |
| if (col_ptrs[k] > (i - j + 1)) | | | |
| { | | | |
| --access::rw(col_ptrs[k]); | | | |
| } | | | |
| } | | | |
| } | | | |
| else | | | |
| { | | | |
| // We shift the element we checked to the left by how many elements | | | |
| // we have removed. | | | |
| // j = 0 until we remove the first element. | | | |
| if (j != 0) | | | |
| { | | | |
| access::rw(row_indices[i - j]) = (lrow > in_row2) ? (lrow - (in_row | | | |
| 2 - in_row1 + 1)) : lrow; | | | |
| access::rw(values[i - j]) = values[i]; | | | |
| } | | | |
| } | | | |
| } | | | |
| | | | |
| // j is the number of elements removed. | | | |
| | | | |
| // Shrink the vectors. This will copy the memory. | | | |
| mem_resize(n_nonzero - j); | | | |
| | | | |
| // Adjust row and element counts. | | | |
| access::rw(n_rows) = n_rows - (in_row2 - in_row1) - 1; | | | |
| access::rw(n_elem) = n_rows * n_cols; | | | |
| } | | | |
| | | | |
| /** | | | |
| * Remove all columns between (and including) in_col1 and in_col2. | | | |
| */ | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| SpMat<eT>::shed_cols(const uword in_col1, const uword in_col2) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | | |
| "SpMat::shed_cols(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| // First we find the locations in values and row_indices for the column e | | | |
| ntries. | | | |
| uword col_beg = col_ptrs[in_col1]; | | | |
| uword col_end = col_ptrs[in_col2 + 1]; | | | |
| | | | |
| // Then we find the number of entries in the column. | | | |
| uword diff = col_end - col_beg; | | | |
| | | | |
| if (diff > 0) | | | |
| { | | | |
| eT* new_values = memory::acquire_chunked<eT> (n_nonzero - dif | | | |
| f); | | | |
| uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero - dif | | | |
| f); | | | |
| | | | |
| // Copy first part. | | | |
| if (col_beg != 0) | | | |
| { | | | |
| arrayops::copy(new_values, values, col_beg); | | | |
| arrayops::copy(new_row_indices, row_indices, col_beg); | | | |
| } | | | |
| | | | |
| // Copy second part. | | | |
| if (col_end != n_nonzero) | | | |
| { | | | |
| arrayops::copy(new_values + col_beg, values + col_end, n_nonzero - co | | | |
| l_end); | | | |
| arrayops::copy(new_row_indices + col_beg, row_indices + col_end, n_no | | | |
| nzero - col_end); | | | |
| } | | | |
| | | | |
| memory::release(values); | | | |
| memory::release(row_indices); | | | |
| | | | |
| access::rw(values) = new_values; | | | |
| access::rw(row_indices) = new_row_indices; | | | |
| | | | |
| // Update counts and such. | | | |
| access::rw(n_nonzero) -= diff; | | | |
| } | | | |
| | | | |
| // Update column pointers. | | | |
| const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); | | | |
| | | | |
| uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 2); | | | |
| new_col_ptrs[new_n_cols + 1] = std::numeric_limits<uword>::max(); | | | |
| | | | |
| // Copy first set of columns (no manipulation required). | | | |
| if (in_col1 != 0) | | | |
| { | | | |
| arrayops::copy(new_col_ptrs, col_ptrs, in_col1); | | | |
| } | | | |
| | | | |
| // Copy second set of columns (manipulation required). | | | |
| uword cur_col = in_col1; | | | |
| for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) | | | |
| { | | | |
| new_col_ptrs[cur_col] = col_ptrs[i] - diff; | | | |
| } | | | |
| | | | |
| memory::release(col_ptrs); | | | |
| access::rw(col_ptrs) = new_col_ptrs; | | | |
| | | | |
| // We update the element and column counts, and we're done. | | | |
| access::rw(n_cols) = new_n_cols; | | | |
| access::rw(n_elem) = n_cols * n_rows; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| SpSubview<eT> | | | |
| SpMat<eT>::rows(const uword in_row1, const uword in_row2) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | | |
| "SpMat::rows(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| const SpSubview<eT> | | | |
| SpMat<eT>::rows(const uword in_row1, const uword in_row2) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_row1 > in_row2) || (in_row2 >= n_rows), | | | |
| "SpMat::rows(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| SpSubview<eT> | | | |
| SpMat<eT>::cols(const uword in_col1, const uword in_col2) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | | |
| "SpMat::cols(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_cols = in_col2 - in_col1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| arma_inline | | | |
| const SpSubview<eT> | | | |
| SpMat<eT>::cols(const uword in_col1, const uword in_col2) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| arma_debug_check | | | |
| ( | | | |
| (in_col1 > in_col2) || (in_col2 >= n_cols), | | | |
| "SpMat::cols(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_cols = in_col2 - in_col1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| SpSubview<eT> | | void | |
| SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ | | SpMat<eT>::shed_row(const uword row_num) | |
| row2, const uword in_col2) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_debug_check (row_num >= n_rows, "SpMat::shed_row(): out of bounds"); | |
| | | | |
|
| arma_debug_check | | shed_rows (row_num, row_num); | |
| ( | | | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | | | |
| in_col2 >= n_cols), | | | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | | |
| const uword subview_n_cols = in_col2 - in_col1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c | | | |
| ols); | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| const SpSubview<eT> | | void | |
| SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ | | SpMat<eT>::shed_col(const uword col_num) | |
| row2, const uword in_col2) const | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_debug_check (col_num >= n_cols, "SpMat::shed_col(): out of bounds"); | |
| | | | |
|
| arma_debug_check | | shed_cols(col_num, col_num); | |
| ( | | | |
| (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || ( | | | |
| in_col2 >= n_cols), | | | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
| const uword subview_n_rows = in_row2 - in_row1 + 1; | | | |
| const uword subview_n_cols = in_col2 - in_col1 + 1; | | | |
| | | | |
| return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c | | | |
| ols); | | | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| arma_inline | | inline | |
| SpSubview<eT> | | void | |
| SpMat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& | | SpMat<eT>::shed_rows(const uword in_row1, const uword in_row2) | |
| s) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | 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 | | arma_debug_check | |
| ( | | ( | |
|
| ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows | | (in_row1 > in_row2) || (in_row2 >= n_rows), | |
| ) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), | | "SpMat::shed_rows(): indices out of bounds or incorectly used" | |
| "SpMat::submat(): indices or size out of bounds" | | | |
| ); | | ); | |
| | | | |
|
| return SpSubview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols); | | uword i, j; | |
| } | | // Store the length of values | |
| | | uword vlength = n_nonzero; | |
| | | // Store the length of col_ptrs | |
| | | uword clength = n_cols + 1; | |
| | | | |
|
| template<typename eT> | | // This is O(n * n_cols) and inplace, there may be a faster way, though. | |
| arma_inline | | for (i = 0, j = 0; i < vlength; ++i) | |
| const SpSubview<eT> | | { | |
| SpMat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& | | // Store the row of the ith element. | |
| s) const | | const uword lrow = row_indices[i]; | |
| { | | // Is the ith element in the range of rows we want to remove? | |
| arma_extra_debug_sigprint(); | | if (lrow >= in_row1 && lrow <= in_row2) | |
| | | { | |
| | | // Increment our "removed elements" counter. | |
| | | ++j; | |
| | | | |
|
| const uword l_n_rows = n_rows; | | // Adjust the values of col_ptrs each time we remove an element. | |
| const uword l_n_cols = n_cols; | | // Basically, the length of one column reduces by one, and everything | |
| | | to | |
| | | // its right gets reduced by one to represent all the elements being | |
| | | // shifted to the left by one. | |
| | | for(uword k = 0; k < clength; ++k) | |
| | | { | |
| | | if (col_ptrs[k] > (i - j + 1)) | |
| | | { | |
| | | --access::rw(col_ptrs[k]); | |
| | | } | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | // We shift the element we checked to the left by how many elements | |
| | | // we have removed. | |
| | | // j = 0 until we remove the first element. | |
| | | if (j != 0) | |
| | | { | |
| | | access::rw(row_indices[i - j]) = (lrow > in_row2) ? (lrow - (in_row | |
| | | 2 - in_row1 + 1)) : lrow; | |
| | | access::rw(values[i - j]) = values[i]; | |
| | | } | |
| | | } | |
| | | } | |
| | | | |
|
| const uword s_n_rows = s.n_rows; | | // j is the number of elements removed. | |
| const uword s_n_cols = s.n_cols; | | | |
| | | | |
|
| arma_debug_check | | // Shrink the vectors. This will copy the memory. | |
| ( | | mem_resize(n_nonzero - j); | |
| ((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); | | // Adjust row and element counts. | |
| | | access::rw(n_rows) = n_rows - (in_row2 - in_row1) - 1; | |
| | | access::rw(n_elem) = n_rows * n_cols; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
|
| SpSubview<eT> | | void | |
| SpMat<eT>::submat(const span& row_span, const span& col_span) | | SpMat<eT>::shed_cols(const uword in_col1, const uword in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const bool row_all = row_span.whole; | | | |
| const bool col_all = col_span.whole; | | | |
| | | | |
| const uword local_n_rows = n_rows; | | | |
| const uword local_n_cols = n_cols; | | | |
| | | | |
| const uword in_row1 = row_all ? 0 : row_span.a; | | | |
| const uword in_row2 = row_span.b; | | | |
| const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + | | | |
| 1; | | | |
| | | | |
| const uword in_col1 = col_all ? 0 : col_span.a; | | | |
| const uword in_col2 = col_span.b; | | | |
| const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + | | | |
| 1; | | | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | | (in_col1 > in_col2) || (in_col2 >= n_cols), | |
| ) | | "SpMat::shed_cols(): indices out of bounds or incorrectly used" | |
| || | | | |
| ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | | | |
| ) | | | |
| , | | | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | | |
| ); | | ); | |
| | | | |
|
| return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col | | // First we find the locations in values and row_indices for the column e | |
| s); | | ntries. | |
| } | | uword col_beg = col_ptrs[in_col1]; | |
| | | uword col_end = col_ptrs[in_col2 + 1]; | |
| template<typename eT> | | | |
| inline | | | |
| const SpSubview<eT> | | | |
| SpMat<eT>::submat(const span& row_span, const span& col_span) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| const bool row_all = row_span.whole; | | | |
| const bool col_all = col_span.whole; | | | |
| | | | |
|
| const uword local_n_rows = n_rows; | | // Then we find the number of entries in the column. | |
| const uword local_n_cols = n_cols; | | uword diff = col_end - col_beg; | |
| | | | |
|
| const uword in_row1 = row_all ? 0 : row_span.a; | | if (diff > 0) | |
| const uword in_row2 = row_span.b; | | { | |
| const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + | | eT* new_values = memory::acquire_chunked<eT> (n_nonzero - dif | |
| 1; | | f); | |
| | | uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero - dif | |
| | | f); | |
| | | | |
|
| const uword in_col1 = col_all ? 0 : col_span.a; | | // Copy first part. | |
| const uword in_col2 = col_span.b; | | if (col_beg != 0) | |
| const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + | | { | |
| 1; | | arrayops::copy(new_values, values, col_beg); | |
| | | arrayops::copy(new_row_indices, row_indices, col_beg); | |
| | | } | |
| | | | |
|
| arma_debug_check | | // Copy second part. | |
| ( | | if (col_end != n_nonzero) | |
| ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) | | { | |
| ) | | arrayops::copy(new_values + col_beg, values + col_end, n_nonzero - co | |
| || | | l_end); | |
| ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) | | arrayops::copy(new_row_indices + col_beg, row_indices + col_end, n_no | |
| ) | | nzero - col_end); | |
| , | | } | |
| "SpMat::submat(): indices out of bounds or incorrectly used" | | | |
| ); | | | |
| | | | |
|
| return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col | | memory::release(values); | |
| s); | | memory::release(row_indices); | |
| } | | | |
| | | | |
|
| template<typename eT> | | access::rw(values) = new_values; | |
| inline | | access::rw(row_indices) = new_row_indices; | |
| SpSubview<eT> | | | |
| SpMat<eT>::operator()(const span& row_span, const span& col_span) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| return submat(row_span, col_span); | | // Update counts and such. | |
| } | | access::rw(n_nonzero) -= diff; | |
| | | } | |
| | | | |
|
| template<typename eT> | | // Update column pointers. | |
| inline | | const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); | |
| const SpSubview<eT> | | | |
| SpMat<eT>::operator()(const span& row_span, const span& col_span) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| return submat(row_span, col_span); | | uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 2); | |
| } | | new_col_ptrs[new_n_cols + 1] = std::numeric_limits<uword>::max(); | |
| | | | |
|
| template<typename eT> | | // Copy first set of columns (no manipulation required). | |
| arma_inline | | if (in_col1 != 0) | |
| SpSubview<eT> | | { | |
| SpMat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeM | | arrayops::copy(new_col_ptrs, col_ptrs, in_col1); | |
| at& s) | | } | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| return (*this).submat(in_row1, in_col1, s); | | // Copy second set of columns (manipulation required). | |
| } | | uword cur_col = in_col1; | |
| | | for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) | |
| | | { | |
| | | new_col_ptrs[cur_col] = col_ptrs[i] - diff; | |
| | | } | |
| | | | |
|
| template<typename eT> | | memory::release(col_ptrs); | |
| arma_inline | | access::rw(col_ptrs) = new_col_ptrs; | |
| 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); | | // We update the element and column counts, and we're done. | |
| | | access::rw(n_cols) = new_n_cols; | |
| | | access::rw(n_elem) = n_cols * n_rows; | |
| } | | } | |
| | | | |
| /** | | /** | |
| * 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> | |
| | | | |
| skipping to change at line 2474 | | skipping to change at line 2560 | |
| return (n_rows == n_cols); | | return (n_rows == n_cols); | |
| } | | } | |
| | | | |
| //! returns true if all of the elements are finite | | //! returns true if all of the elements are finite | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| SpMat<eT>::is_finite() const | | SpMat<eT>::is_finite() const | |
| { | | { | |
|
| for(uword i = 0; i < n_nonzero; i++) | | return arrayops::is_finite(values, n_nonzero); | |
| { | | | |
| if(arma_isfinite(values[i]) == false) | | | |
| { | | | |
| return false; | | | |
| } | | | |
| } | | | |
| | | | |
| return true; // No infinite values. | | | |
| } | | } | |
| | | | |
| //! returns true if the given index is currently in range | | //! returns true if the given index is currently in range | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| SpMat<eT>::in_range(const uword i) const | | SpMat<eT>::in_range(const uword i) const | |
| { | | { | |
| return (i < n_elem); | | return (i < n_elem); | |
| | | | |
| skipping to change at line 4527 | | skipping to change at line 4605 | |
| const uword old_n_nonzero = n_nonzero; | | const uword old_n_nonzero = n_nonzero; | |
| | | | |
| --access::rw(n_nonzero); // Remove one from the count of nonzero el
ements. | | --access::rw(n_nonzero); // Remove one from the count of nonzero el
ements. | |
| | | | |
| // Found it. Now remove it. | | // Found it. Now remove it. | |
| | | | |
| // Figure out the actual amount of memory currently allocated and t
he actual amount that will be required | | // Figure out the actual amount of memory currently allocated and t
he actual amount that will be required | |
| // NOTE: this relies on memory::acquire_chunked() being used for th
e 'values' and 'row_indices' arrays | | // NOTE: this relies on memory::acquire_chunked() being used for th
e 'values' and 'row_indices' arrays | |
| | | | |
| const uword n_alloc = memory::enlarge_to_mult_of_chunksize(old_
n_nonzero + 1); | | const uword n_alloc = memory::enlarge_to_mult_of_chunksize(old_
n_nonzero + 1); | |
|
| const uword n_alloc_mod = memory::enlarge_to_mult_of_chunksize(n_no
nzero + 1); | | const uword n_alloc_mod = memory::enlarge_to_mult_of_chunksize(n_no
nzero + 1); | |
| | | | |
| // If possible, avoid time-consuming memory allocation | | // If possible, avoid time-consuming memory allocation | |
| if(n_alloc_mod == n_alloc) | | if(n_alloc_mod == n_alloc) | |
| { | | { | |
| if (pos < n_nonzero) // remember, we decremented n_nonzero | | if (pos < n_nonzero) // remember, we decremented n_nonzero | |
| { | | { | |
|
| arrayops::copy_forwards(access::rwp(values) + pos, values
+ pos + 1, (n_nonzero - pos) + 1); | | arrayops::copy_forwards(access::rwp(values) + pos, values
+ pos + 1, (n_nonzero - pos) + 1); | |
| arrayops::copy_forwards(access::rwp(row_indices) + pos, row_ind
ices + pos + 1, (n_nonzero - pos) + 1); | | arrayops::copy_forwards(access::rwp(row_indices) + pos, row_ind
ices + pos + 1, (n_nonzero - pos) + 1); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| // Make new arrays. | | // Make new arrays. | |
| eT* new_values = memory::acquire_chunked<eT> (n_nonzero
+ 1); | | eT* new_values = memory::acquire_chunked<eT> (n_nonzero
+ 1); | |
| uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero
+ 1); | | uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero
+ 1); | |
| | | | |
| if (pos > 0) | | if (pos > 0) | |
| | | | |
End of changes. 39 change blocks. |
| 433 lines changed or deleted | | 519 lines changed or added | |
|
| arma_rng.hpp | | arma_rng.hpp | |
|
| // Copyright (C) 2013-2014 Conrad Sanderson | | // Copyright (C) 2013-2015 Conrad Sanderson | |
| // Copyright (C) 2013-2014 NICTA (www.nicta.com.au) | | // Copyright (C) 2013-2015 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 arma_rng | | //! \addtogroup arma_rng | |
| //! @{ | | //! @{ | |
| | | | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
|
| #undef ARMA_USE_CXX11_RNG | | #undef ARMA_USE_EXTERN_CXX11_RNG | |
| #endif | | #endif | |
| | | | |
|
| #if defined(ARMA_USE_CXX11_RNG) | | #if !defined(ARMA_USE_CXX11) | |
| | | #undef ARMA_USE_EXTERN_CXX11_RNG | |
| | | #endif | |
| | | | |
| | | #if defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| extern thread_local arma_rng_cxx11 arma_rng_cxx11_instance; | | extern thread_local arma_rng_cxx11 arma_rng_cxx11_instance; | |
|
| // thread_local arma_rng_cxx11 arma_rng_cxx11_instance; | | // namespace { thread_local arma_rng_cxx11 arma_rng_cxx11_instance; } | |
| #endif | | #endif | |
| | | | |
| class arma_rng | | class arma_rng | |
| { | | { | |
| public: | | public: | |
| | | | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| typedef arma_rng_alt::seed_type seed_type; | | typedef arma_rng_alt::seed_type seed_type; | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| typedef arma_rng_cxx11::seed_type seed_type; | | typedef arma_rng_cxx11::seed_type seed_type; | |
| #else | | #else | |
| typedef arma_rng_cxx98::seed_type seed_type; | | typedef arma_rng_cxx98::seed_type seed_type; | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| static const int rng_method = 2; | | static const int rng_method = 2; | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| static const int rng_method = 1; | | static const int rng_method = 1; | |
| #else | | #else | |
| static const int rng_method = 0; | | static const int rng_method = 0; | |
| #endif | | #endif | |
| | | | |
| inline static void set_seed(const seed_type val); | | inline static void set_seed(const seed_type val); | |
| inline static void set_seed_random(); | | inline static void set_seed_random(); | |
| | | | |
| template<typename eT> struct randi; | | template<typename eT> struct randi; | |
| template<typename eT> struct randu; | | template<typename eT> struct randu; | |
| | | | |
| skipping to change at line 56 | | skipping to change at line 60 | |
| }; | | }; | |
| | | | |
| inline | | inline | |
| void | | void | |
| arma_rng::set_seed(const arma_rng::seed_type val) | | arma_rng::set_seed(const arma_rng::seed_type val) | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| arma_rng_alt::set_seed(val); | | arma_rng_alt::set_seed(val); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| arma_rng_cxx11_instance.set_seed(val); | | arma_rng_cxx11_instance.set_seed(val); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_rng_cxx98::set_seed(val); | | arma_rng_cxx98::set_seed(val); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 147 | | skipping to change at line 151 | |
| template<typename eT> | | template<typename eT> | |
| struct arma_rng::randi | | struct arma_rng::randi | |
| { | | { | |
| arma_inline | | arma_inline | |
| operator eT () | | operator eT () | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| return eT( arma_rng_alt::randi_val() ); | | return eT( arma_rng_alt::randi_val() ); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| return eT( arma_rng_cxx11_instance.randi_val() ); | | return eT( arma_rng_cxx11_instance.randi_val() ); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| return eT( arma_rng_cxx98::randi_val() ); | | return eT( arma_rng_cxx98::randi_val() ); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| inline | | inline | |
| static | | static | |
| int | | int | |
| max_val() | | max_val() | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| return arma_rng_alt::randi_max_val(); | | return arma_rng_alt::randi_max_val(); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| return arma_rng_cxx11::randi_max_val(); | | return arma_rng_cxx11::randi_max_val(); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| return arma_rng_cxx98::randi_max_val(); | | return arma_rng_cxx98::randi_max_val(); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| inline | | inline | |
| static | | static | |
| void | | void | |
| fill(eT* mem, const uword N, const int a, const int b) | | fill(eT* mem, const uword N, const int a, const int b) | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| return arma_rng_alt::randi_fill(mem, N, a, b); | | return arma_rng_alt::randi_fill(mem, N, a, b); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| return arma_rng_cxx11_instance.randi_fill(mem, N, a, b); | | return arma_rng_cxx11_instance.randi_fill(mem, N, a, b); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| return arma_rng_cxx98::randi_fill(mem, N, a, b); | | return arma_rng_cxx98::randi_fill(mem, N, a, b); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| }; | | }; | |
| | | | |
| skipping to change at line 209 | | skipping to change at line 213 | |
| template<typename eT> | | template<typename eT> | |
| struct arma_rng::randu | | struct arma_rng::randu | |
| { | | { | |
| arma_inline | | arma_inline | |
| operator eT () | | operator eT () | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| return eT( arma_rng_alt::randu_val() ); | | return eT( arma_rng_alt::randu_val() ); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| return eT( arma_rng_cxx11_instance.randu_val() ); | | return eT( arma_rng_cxx11_instance.randu_val() ); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| return eT( arma_rng_cxx98::randu_val() ); | | return eT( arma_rng_cxx98::randu_val() ); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 280 | | skipping to change at line 284 | |
| template<typename eT> | | template<typename eT> | |
| struct arma_rng::randn | | struct arma_rng::randn | |
| { | | { | |
| inline | | inline | |
| operator eT () const | | operator eT () const | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| return eT( arma_rng_alt::randn_val() ); | | return eT( arma_rng_alt::randn_val() ); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| return eT( arma_rng_cxx11_instance.randn_val() ); | | return eT( arma_rng_cxx11_instance.randn_val() ); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| return eT( arma_rng_cxx98::randn_val() ); | | return eT( arma_rng_cxx98::randn_val() ); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| arma_inline | | arma_inline | |
| static | | static | |
| void | | void | |
| dual_val(eT& out1, eT& out2) | | dual_val(eT& out1, eT& out2) | |
| { | | { | |
| #if defined(ARMA_RNG_ALT) | | #if defined(ARMA_RNG_ALT) | |
| { | | { | |
| arma_rng_alt::randn_dual_val(out1, out2); | | arma_rng_alt::randn_dual_val(out1, out2); | |
| } | | } | |
|
| #elif defined(ARMA_USE_CXX11_RNG) | | #elif defined(ARMA_USE_EXTERN_CXX11_RNG) | |
| { | | { | |
| arma_rng_cxx11_instance.randn_dual_val(out1, out2); | | arma_rng_cxx11_instance.randn_dual_val(out1, out2); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_rng_cxx98::randn_dual_val(out1, out2); | | arma_rng_cxx98::randn_dual_val(out1, out2); | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| | | | |
End of changes. 13 change blocks. |
| 14 lines changed or deleted | | 18 lines changed or added | |
|
| arrayops_meat.hpp | | arrayops_meat.hpp | |
|
| // Copyright (C) 2011-2014 Conrad Sanderson | | // Copyright (C) 2011-2015 Conrad Sanderson | |
| // Copyright (C) 2011-2014 NICTA (www.nicta.com.au) | | // Copyright (C) 2011-2015 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 arrayops | | //! \addtogroup arrayops | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| | | | |
| skipping to change at line 62 | | skipping to change at line 62 | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::copy_forwards(eT* dest, const eT* src, const uword n_elem) | | arrayops::copy_forwards(eT* dest, const eT* src, const uword n_elem) | |
| { | | { | |
| // can't use std::memcpy(), as we don't know how it copies data | | // can't use std::memcpy(), as we don't know how it copies data | |
|
| uword i,j; | | uword j; | |
| | | | |
|
| for(i=0, j=1; j < n_elem; i+=2, j+=2) | | for(j=1; j < n_elem; j+=2) | |
| { | | { | |
|
| dest[i] = src[i]; | | const eT tmp_i = (*src); src++; | |
| dest[j] = src[j]; | | const eT tmp_j = (*src); src++; | |
| | | | |
| | | (*dest) = tmp_i; dest++; | |
| | | (*dest) = tmp_j; dest++; | |
| } | | } | |
| | | | |
|
| if(i < n_elem) | | if((j-1) < n_elem) | |
| { | | { | |
|
| dest[i] = src[i]; | | (*dest) = (*src); | |
| } | | } | |
| } | | } | |
| | | | |
|
| // template<typename eT> | | | |
| // arma_hot | | | |
| // inline | | | |
| // void | | | |
| // arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) | | | |
| // { | | | |
| // // can't use std::memcpy(), as we don't know how it copies data | | | |
| // | | | |
| // switch(n_elem) | | | |
| // { | | | |
| // default: | | | |
| // for(uword i = (n_elem-1); i >= 1; --i) { dest[i] = src[i]; } | | | |
| // // NOTE: the 'break' statement has been deliberately omitted | | | |
| // case 1: | | | |
| // dest[0] = src[0]; | | | |
| // case 0: | | | |
| // ; | | | |
| // } | | | |
| // } | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) | | arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) | |
| { | | { | |
| // can't use std::memcpy(), as we don't know how it copies data | | // can't use std::memcpy(), as we don't know how it copies data | |
| | | | |
|
| switch(n_elem) | | // for(uword i=0; i < n_elem; ++i) | |
| | | // { | |
| | | // const uword j = n_elem-i-1; | |
| | | // | |
| | | // dest[j] = src[j]; | |
| | | // } | |
| | | | |
| | | if(n_elem > 0) | |
| { | | { | |
|
| default: | | eT* dest_it = &(dest[n_elem-1]); | |
| { | | const eT* src_it = &( src[n_elem-1]); | |
| uword i, j; | | | |
| for(i = (n_elem-1), j = (n_elem-2); j >= 2; i-=2, j-=2) | | | |
| { | | | |
| const eT tmp_i = src[i]; | | | |
| const eT tmp_j = src[j]; | | | |
| | | | |
|
| dest[i] = tmp_i; | | uword j; | |
| dest[j] = tmp_j; | | for(j=1; j < n_elem; j+=2) | |
| } | | { | |
| | | const eT tmp_i = (*src_it); src_it--; | |
| | | const eT tmp_j = (*src_it); src_it--; | |
| | | | |
|
| // j is less than 2: it can be 1 or 0 | | (*dest_it) = tmp_i; dest_it--; | |
| // i is j+1, ie. less than 3: it can be 2 or 1 | | (*dest_it) = tmp_j; dest_it--; | |
| | | } | |
| | | | |
|
| if(i == 2) | | if((j-1) < n_elem) | |
| { | | { | |
| dest[2] = src[2]; | | (*dest_it) = (*src_it); | |
| } | | | |
| } | | } | |
|
| // NOTE: the 'break' statement has been deliberately omitted | | | |
| case 2: | | | |
| dest[1] = src[1]; | | | |
| case 1: | | | |
| dest[0] = src[0]; | | | |
| case 0: | | | |
| ; | | | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::fill_zeros(eT* dest, const uword n_elem) | | arrayops::fill_zeros(eT* dest, const uword n_elem) | |
| { | | { | |
| arrayops::inplace_set(dest, eT(0), n_elem); | | arrayops::inplace_set(dest, eT(0), n_elem); | |
| | | | |
| skipping to change at line 200 | | skipping to change at line 180 | |
| | | | |
| out = out_eT(in); | | out = out_eT(in); | |
| } | | } | |
| | | | |
| template<typename out_eT, typename in_eT> | | template<typename out_eT, typename in_eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::convert(out_eT* dest, const in_eT* src, const uword n_elem) | | arrayops::convert(out_eT* dest, const in_eT* src, const uword n_elem) | |
| { | | { | |
|
| uword i,j; | | if(is_same_type<out_eT,in_eT>::value) | |
| | | { | |
| | | const out_eT* src2 = (const out_eT*)src; | |
| | | | |
|
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | if(dest != src2) { arrayops::copy(dest, src2, n_elem); } | |
| | | | |
| | | return; | |
| | | } | |
| | | | |
| | | uword j; | |
| | | | |
| | | for(j=1; j<n_elem; j+=2) | |
| { | | { | |
|
| const in_eT tmp_i = src[i]; | | const in_eT tmp_i = (*src); src++; | |
| const in_eT tmp_j = src[j]; | | const in_eT tmp_j = (*src); src++; | |
| | | | |
| // dest[i] = out_eT( tmp_i ); | | // dest[i] = out_eT( tmp_i ); | |
| // dest[j] = out_eT( tmp_j ); | | // dest[j] = out_eT( tmp_j ); | |
| | | | |
|
| dest[i] = (is_signed<out_eT>::value) | | (*dest) = (is_signed<out_eT>::value) | |
| ? out_eT( tmp_i ) | | ? out_eT( tmp_i ) | |
| : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_i, in_eT(0))
? out_eT(0) : out_eT(tmp_i) ); | | : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_i, in_eT(0))
? out_eT(0) : out_eT(tmp_i) ); | |
| | | | |
|
| dest[j] = (is_signed<out_eT>::value) | | dest++; | |
| | | | |
| | | (*dest) = (is_signed<out_eT>::value) | |
| ? out_eT( tmp_j ) | | ? out_eT( tmp_j ) | |
| : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_j, in_eT(0))
? out_eT(0) : out_eT(tmp_j) ); | | : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_j, in_eT(0))
? out_eT(0) : out_eT(tmp_j) ); | |
|
| | | dest++; | |
| } | | } | |
| | | | |
|
| if(i < n_elem) | | if((j-1) < n_elem) | |
| { | | { | |
|
| const in_eT tmp_i = src[i]; | | const in_eT tmp_i = (*src); | |
| | | | |
| // dest[i] = out_eT( tmp_i ); | | // dest[i] = out_eT( tmp_i ); | |
| | | | |
|
| dest[i] = (is_signed<out_eT>::value) | | (*dest) = (is_signed<out_eT>::value) | |
| ? out_eT( tmp_i ) | | ? out_eT( tmp_i ) | |
| : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_i, in_eT(0))
? out_eT(0) : out_eT(tmp_i) ); | | : ( cond_rel< is_signed<in_eT>::value >::lt(tmp_i, in_eT(0))
? out_eT(0) : out_eT(tmp_i) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename out_eT, typename in_eT> | | template<typename out_eT, typename in_eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::convert_cx(out_eT* dest, const in_eT* src, const uword n_elem) | | arrayops::convert_cx(out_eT* dest, const in_eT* src, const uword n_elem) | |
| { | | { | |
|
| uword i,j; | | uword j; | |
| | | | |
|
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(j=1; j<n_elem; j+=2) | |
| { | | { | |
|
| arrayops::convert_cx_scalar( dest[i], src[i] ); | | arrayops::convert_cx_scalar( (*dest), (*src) ); dest++; src++; | |
| arrayops::convert_cx_scalar( dest[j], src[j] ); | | arrayops::convert_cx_scalar( (*dest), (*src) ); dest++; src++; | |
| } | | } | |
| | | | |
|
| if(i < n_elem) | | if((j-1) < n_elem) | |
| { | | { | |
|
| arrayops::convert_cx_scalar( dest[i], src[i] ); | | arrayops::convert_cx_scalar( (*dest), (*src) ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| arrayops::inplace_plus(eT* dest, const eT* src, const uword n_elem) | | arrayops::inplace_plus(eT* dest, const eT* src, const uword n_elem) | |
| { | | { | |
| if(memory::is_aligned(dest)) | | if(memory::is_aligned(dest)) | |
| | | | |
| skipping to change at line 911 | | skipping to change at line 903 | |
| return val1 * val2; | | return val1 * val2; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| arma_pure | | arma_pure | |
| inline | | inline | |
| bool | | bool | |
| arrayops::is_finite(const eT* src, const uword n_elem) | | arrayops::is_finite(const eT* src, const uword n_elem) | |
| { | | { | |
|
| uword i,j; | | uword j; | |
| | | | |
|
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(j=1; j<n_elem; j+=2) | |
| { | | { | |
|
| const eT val_i = src[i]; | | const eT val_i = (*src); src++; | |
| const eT val_j = src[j]; | | const eT val_j = (*src); src++; | |
| | | | |
| if( (arma_isfinite(val_i) == false) || (arma_isfinite(val_j) == false)
) | | if( (arma_isfinite(val_i) == false) || (arma_isfinite(val_j) == false)
) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| | | | |
|
| if(i < n_elem) | | if((j-1) < n_elem) | |
| { | | { | |
|
| if(arma_isfinite(src[i]) == false) | | if(arma_isfinite(*src) == false) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| // TODO: this function is currently not used | | // TODO: this function is currently not used | |
| template<typename eT> | | template<typename eT> | |
| | | | |
End of changes. 32 change blocks. |
| 73 lines changed or deleted | | 65 lines changed or added | |
|
| fn_conv_to.hpp | | fn_conv_to.hpp | |
|
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2015 Conrad Sanderson | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2015 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_conv_to | | //! \addtogroup fn_conv_to | |
| //! @{ | | //! @{ | |
| | | | |
| //! conversion from Armadillo Base and BaseCube objects to scalars | | //! conversion from Armadillo Base and BaseCube objects to scalars | |
| //! (kept only for compatibility with old code; use as_scalar() instead for
Base objects like Mat) | | //! (kept only for compatibility with old code; use as_scalar() instead for
Base objects like Mat) | |
| | | | |
| skipping to change at line 42 | | skipping to change at line 42 | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| out_eT | | out_eT | |
| conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_not_cx
<in_eT>::result* junk) | | conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_not_cx
<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | | arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | | |
| | | | |
|
| arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have
exactly one element" ); | | arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't
have exactly one element" ); | |
| | | | |
|
| return out_eT(X.mem[0]); | | return out_eT(Proxy<T1>::prefer_at_accessor ? P.at(0,0) : P[0]); | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| out_eT | | out_eT | |
| conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_cx_onl
y<in_eT>::result* junk) | | conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_cx_onl
y<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | | arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | | |
| | | | |
|
| arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have
exactly one element" ); | | arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't
have exactly one element" ); | |
| | | | |
| out_eT out; | | out_eT out; | |
| | | | |
|
| arrayops::convert_cx_scalar(out, X.mem[0]); | | arrayops::convert_cx_scalar(out, (Proxy<T1>::prefer_at_accessor ? P.at(0,
0) : P[0])); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| out_eT | | out_eT | |
| conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_no
t_cx<in_eT>::result* junk) | | conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_no
t_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | | arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.get_ref()); | | const ProxyCube<T1> P(in.get_ref()); | |
| const Cube<in_eT>& X = tmp.M; | | | |
| | | | |
|
| arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have
exactly one element" ); | | arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't
have exactly one element" ); | |
| | | | |
|
| return out_eT(X.mem[0]); | | return out_eT(ProxyCube<T1>::prefer_at_accessor ? P.at(0,0,0) : P[0]); | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| out_eT | | out_eT | |
| conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_cx
_only<in_eT>::result* junk) | | conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_cx
_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | | arma_type_check(( is_supported_elem_type<out_eT>::value == false )); | |
| | | | |
|
| const unwrap_cube<T1> tmp(in.get_ref()); | | const ProxyCube<T1> P(in.get_ref()); | |
| const Cube<in_eT>& X = tmp.M; | | | |
| | | | |
|
| arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have
exactly one element" ); | | arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't
have exactly one element" ); | |
| | | | |
| out_eT out; | | out_eT out; | |
| | | | |
|
| arrayops::convert_cx_scalar(out, X.mem[0]); | | arrayops::convert_cx_scalar(out, (ProxyCube<T1>::prefer_at_accessor ? P.a
t(0,0,0) : P[0])); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| //! conversion to Armadillo matrices from Armadillo Base objects, as well a
s from std::vector | | //! conversion to Armadillo matrices from Armadillo Base objects, as well a
s from std::vector | |
| template<typename out_eT> | | template<typename out_eT> | |
| class conv_to< Mat<out_eT> > | | class conv_to< Mat<out_eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename
arma_not_cx<in_eT>::result* junk = 0); | | inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename
arma_not_cx<in_eT>::result* junk = 0); | |
| | | | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename
arma_cx_only<in_eT>::result* junk = 0); | | inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename
arma_cx_only<in_eT>::result* junk = 0); | |
| | | | |
|
| | | template<typename T1> | |
| | | inline static Mat<out_eT> from(const SpBase<out_eT, T1>& in); | |
| | | | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typena
me arma_not_cx<in_eT>::result* junk = 0); | | inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typena
me arma_not_cx<in_eT>::result* junk = 0); | |
| | | | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typena
me arma_cx_only<in_eT>::result* junk = 0); | | inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typena
me arma_cx_only<in_eT>::result* junk = 0); | |
| }; | | }; | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Mat<out_eT> | | Mat<out_eT> | |
| conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | | conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| Mat<out_eT> out(X.n_rows, X.n_cols); | | Mat<out_eT> out(X.n_rows, X.n_cols); | |
| | | | |
|
| arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Mat<out_eT> | | Mat<out_eT> | |
| conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | | conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| Mat<out_eT> out(X.n_rows, X.n_cols); | | Mat<out_eT> out(X.n_rows, X.n_cols); | |
| | | | |
|
| arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
|
| | | template<typename T1> | |
| | | inline | |
| | | Mat<out_eT> | |
| | | conv_to< Mat<out_eT> >::from(const SpBase<out_eT, T1>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return Mat<out_eT>(in.get_ref()); | |
| | | } | |
| | | | |
| | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Mat<out_eT> | | Mat<out_eT> | |
| conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | | conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| const uword N = uword( in.size() ); | | const uword N = uword( in.size() ); | |
| | | | |
| Mat<out_eT> out(N, 1); | | Mat<out_eT> out(N, 1); | |
| | | | |
| if(N > 0) | | if(N > 0) | |
| { | | { | |
|
| out_eT* out_mem = out.memptr(); | | arrayops::convert( out.memptr(), &(in[0]), N ); | |
| const in_eT* in_mem = &(in[0]); | | | |
| | | | |
| for(uword i=0; i<N; ++i) | | | |
| { | | | |
| out_mem[i] = out_eT( in_mem[i] ); | | | |
| } | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Mat<out_eT> | | Mat<out_eT> | |
| conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | | conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| Mat<out_eT> out(in.size(), 1); | | const uword N = uword( in.size() ); | |
| | | | |
| typename std::vector<in_eT>::const_iterator in_begin = in.begin(); | | | |
| typename std::vector<in_eT>::const_iterator in_end = in.end(); | | | |
| | | | |
| typename Mat<out_eT>::iterator out_begin = out.begin(); | | | |
| typename Mat<out_eT>::iterator out_end = out.end(); | | | |
| | | | |
|
| typename std::vector<in_eT>::const_iterator in_it; | | Mat<out_eT> out(N, 1); | |
| typename Mat<out_eT>::iterator out_it; | | | |
| | | | |
|
| for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it !=
out_end); ++in_it, ++out_it) | | if(N > 0) | |
| { | | { | |
|
| out_eT& out_elem = (*out_it); | | arrayops::convert_cx( out.memptr(), &(in[0]), N ); | |
| const in_eT& in_elem = (*in_it); | | | |
| | | | |
| arrayops::convert_cx_scalar(out_elem, in_elem); | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| //! conversion to Armadillo row vectors from Armadillo Base objects, as wel
l as from std::vector | | //! conversion to Armadillo row vectors from Armadillo Base objects, as wel
l as from std::vector | |
| template<typename out_eT> | | template<typename out_eT> | |
| class conv_to< Row<out_eT> > | | class conv_to< Row<out_eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| skipping to change at line 258 | | skipping to change at line 252 | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Row<out_eT> | | Row<out_eT> | |
| conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | | conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
| Row<out_eT> out(X.n_elem); | | Row<out_eT> out(X.n_elem); | |
| | | | |
|
| arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Row<out_eT> | | Row<out_eT> | |
| conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | | conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
| Row<out_eT> out(X.n_rows, X.n_cols); | | Row<out_eT> out(X.n_rows, X.n_cols); | |
| | | | |
|
| arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Row<out_eT> | | Row<out_eT> | |
| conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | | conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| const uword N = uword( in.size() ); | | const uword N = uword( in.size() ); | |
| | | | |
| Row<out_eT> out(N); | | Row<out_eT> out(N); | |
| | | | |
| if(N > 0) | | if(N > 0) | |
| { | | { | |
|
| out_eT* out_mem = out.memptr(); | | arrayops::convert( out.memptr(), &(in[0]), N ); | |
| const in_eT* in_mem = &(in[0]); | | | |
| | | | |
| for(uword i=0; i<N; ++i) | | | |
| { | | | |
| out_mem[i] = out_eT( in_mem[i] ); | | | |
| } | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Row<out_eT> | | Row<out_eT> | |
| conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | | conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| Row<out_eT> out( in.size() ); | | const uword N = uword( in.size() ); | |
| | | | |
| typename std::vector<in_eT>::const_iterator in_begin = in.begin(); | | | |
| typename std::vector<in_eT>::const_iterator in_end = in.end(); | | | |
| | | | |
| typename Row<out_eT>::iterator out_begin = out.begin(); | | | |
| typename Row<out_eT>::iterator out_end = out.end(); | | | |
| | | | |
|
| typename std::vector<in_eT>::const_iterator in_it; | | Row<out_eT> out(N); | |
| typename Row<out_eT>::iterator out_it; | | | |
| | | | |
|
| for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it !=
out_end); ++in_it, ++out_it) | | if(N > 0) | |
| { | | { | |
|
| out_eT& out_elem = (*out_it); | | arrayops::convert_cx( out.memptr(), &(in[0]), N ); | |
| const in_eT& in_elem = (*in_it); | | | |
| | | | |
| arrayops::convert_cx_scalar(out_elem, in_elem); | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| //! conversion to Armadillo column vectors from Armadillo Base objects, as
well as from std::vector | | //! conversion to Armadillo column vectors from Armadillo Base objects, as
well as from std::vector | |
| template<typename out_eT> | | template<typename out_eT> | |
| class conv_to< Col<out_eT> > | | class conv_to< Col<out_eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| skipping to change at line 377 | | skipping to change at line 355 | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Col<out_eT> | | Col<out_eT> | |
| conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | | conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
| Col<out_eT> out(X.n_elem); | | Col<out_eT> out(X.n_elem); | |
| | | | |
|
| arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Col<out_eT> | | Col<out_eT> | |
| conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | | conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma
_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
| Col<out_eT> out(X.n_rows, X.n_cols); | | Col<out_eT> out(X.n_rows, X.n_cols); | |
| | | | |
|
| arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Col<out_eT> | | Col<out_eT> | |
| conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | | conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| const uword N = uword( in.size() ); | | const uword N = uword( in.size() ); | |
| | | | |
| Col<out_eT> out(N); | | Col<out_eT> out(N); | |
| | | | |
| if(N > 0) | | if(N > 0) | |
| { | | { | |
|
| out_eT* out_mem = out.memptr(); | | arrayops::convert( out.memptr(), &(in[0]), N ); | |
| const in_eT* in_mem = &(in[0]); | | | |
| | | | |
| for(uword i=0; i<N; ++i) | | | |
| { | | | |
| out_mem[i] = out_eT( in_mem[i] ); | | | |
| } | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT> | | template<typename in_eT> | |
| inline | | inline | |
| Col<out_eT> | | Col<out_eT> | |
| conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | | conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename a
rma_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| Col<out_eT> out( in.size() ); | | const uword N = uword( in.size() ); | |
| | | | |
| typename std::vector<in_eT>::const_iterator in_begin = in.begin(); | | | |
| typename std::vector<in_eT>::const_iterator in_end = in.end(); | | | |
| | | | |
| typename Col<out_eT>::iterator out_begin = out.begin(); | | | |
| typename Col<out_eT>::iterator out_end = out.end(); | | | |
| | | | |
|
| typename std::vector<in_eT>::const_iterator in_it; | | Col<out_eT> out(N); | |
| typename Col<out_eT>::iterator out_it; | | | |
| | | | |
|
| for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it !=
out_end); ++in_it, ++out_it) | | if(N > 0) | |
| { | | { | |
|
| out_eT& out_elem = (*out_it); | | arrayops::convert_cx( out.memptr(), &(in[0]), N ); | |
| const in_eT& in_elem = (*in_it); | | | |
| | | | |
| arrayops::convert_cx_scalar(out_elem, in_elem); | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
|
| | | template<typename out_eT> | |
| | | class conv_to< SpMat<out_eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | template<typename T1> | |
| | | inline static SpMat<out_eT> from(const Base<out_eT, T1>& in); | |
| | | }; | |
| | | | |
| | | template<typename out_eT> | |
| | | template<typename T1> | |
| | | inline | |
| | | SpMat<out_eT> | |
| | | conv_to< SpMat<out_eT> >::from(const Base<out_eT, T1>& in) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | return SpMat<out_eT>(in.get_ref()); | |
| | | } | |
| | | | |
| //! conversion to Armadillo cubes from Armadillo BaseCube objects | | //! conversion to Armadillo cubes from Armadillo BaseCube objects | |
| template<typename out_eT> | | template<typename out_eT> | |
| class conv_to< Cube<out_eT> > | | class conv_to< Cube<out_eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const type
name arma_not_cx<in_eT>::result* junk = 0); | | inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const type
name arma_not_cx<in_eT>::result* junk = 0); | |
| | | | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| | | | |
| skipping to change at line 495 | | skipping to change at line 477 | |
| conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename
arma_not_cx<in_eT>::result* junk) | | conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename
arma_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| const unwrap_cube<T1> tmp( in.get_ref() ); | | const unwrap_cube<T1> tmp( in.get_ref() ); | |
| const Cube<in_eT>& X = tmp.M; | | const Cube<in_eT>& X = tmp.M; | |
| | | | |
| Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices); | | Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices); | |
| | | | |
|
| arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| Cube<out_eT> | | Cube<out_eT> | |
| conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename
arma_cx_only<in_eT>::result* junk) | | conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename
arma_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| const unwrap_cube<T1> tmp( in.get_ref() ); | | const unwrap_cube<T1> tmp( in.get_ref() ); | |
| const Cube<in_eT>& X = tmp.M; | | const Cube<in_eT>& X = tmp.M; | |
| | | | |
| Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices); | | Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices); | |
| | | | |
|
| arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); | | arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| //! conversion to std::vector from Armadillo Base objects | | //! conversion to std::vector from Armadillo Base objects | |
| template<typename out_eT> | | template<typename out_eT> | |
| class conv_to< std::vector<out_eT> > | | class conv_to< std::vector<out_eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| | | | |
| skipping to change at line 541 | | skipping to change at line 523 | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| std::vector<out_eT> | | std::vector<out_eT> | |
| conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typen
ame arma_not_cx<in_eT>::result* junk) | | conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typen
ame arma_not_cx<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
| const uword N = X.n_elem; | | const uword N = X.n_elem; | |
| | | | |
| std::vector<out_eT> out(N); | | std::vector<out_eT> out(N); | |
| | | | |
| if(N > 0) | | if(N > 0) | |
| { | | { | |
|
| out_eT* out_mem = &(out[0]); | | arrayops::convert( &(out[0]), X.memptr(), N ); | |
| const in_eT* X_mem = X.memptr(); | | | |
| | | | |
| for(uword i=0; i<N; ++i) | | | |
| { | | | |
| out_mem[i] = out_eT( X_mem[i] ); | | | |
| } | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename out_eT> | | template<typename out_eT> | |
| template<typename in_eT, typename T1> | | template<typename in_eT, typename T1> | |
| inline | | inline | |
| std::vector<out_eT> | | std::vector<out_eT> | |
| conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typen
ame arma_cx_only<in_eT>::result* junk) | | conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typen
ame arma_cx_only<in_eT>::result* junk) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
|
| const unwrap<T1> tmp(in.get_ref()); | | const quasi_unwrap<T1> tmp(in.get_ref()); | |
| const Mat<in_eT>& X = tmp.M; | | const Mat<in_eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | | arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "
conv_to(): given object can't be interpreted as a vector" ); | |
| | | | |
|
| std::vector<out_eT> out(X.n_elem); | | const uword N = X.n_elem; | |
| | | | |
| typename Mat<in_eT>::const_iterator X_begin = X.begin(); | | | |
| typename Mat<in_eT>::const_iterator X_end = X.end(); | | | |
| | | | |
| typename std::vector<out_eT>::iterator out_begin = out.begin(); | | | |
| typename std::vector<out_eT>::iterator out_end = out.end(); | | | |
| | | | |
|
| typename Mat<in_eT>::const_iterator X_it; | | std::vector<out_eT> out(N); | |
| typename std::vector<out_eT>::iterator out_it; | | | |
| | | | |
|
| for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out
_end); ++X_it, ++out_it) | | if(N > 0) | |
| { | | { | |
|
| out_eT& out_elem = (*out_it); | | arrayops::convert_cx( &(out[0]), X.memptr(), N ); | |
| const in_eT& X_elem = (*X_it); | | | |
| | | | |
| arrayops::convert_cx_scalar(out_elem, X_elem); | | | |
| } | | } | |
| | | | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 52 change blocks. |
| 126 lines changed or deleted | | 92 lines changed or added | |
|