| Proxy.hpp | | Proxy.hpp | |
|
| // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010-2012 Conrad Sanderson | | // Copyright (C) 2010-2013 Conrad Sanderson | |
| // | | // | |
| // 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 Proxy | | //! \addtogroup Proxy | |
| //! @{ | | //! @{ | |
| | | | |
| // ea_type is the "element accessor" type, | | // ea_type is the "element accessor" type, | |
| // which can provide access to elements via operator[] | | // which can provide access to elements via operator[] | |
| | | | |
| skipping to change at line 585 | | skipping to change at line 585 | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline ea_type get_ea() const { return Q.memptr(); } | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_xtrans:
:is_alias(X); } | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_xtrans:
:is_alias(X); } | |
| }; | | }; | |
| | | | |
|
| | | template<typename eT> | |
| | | struct Proxy_subview_row_htrans_cx | |
| | | { | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<eT>::result pod_type; | |
| | | typedef subview_row_htrans<eT> stored_type; | |
| | | typedef const subview_row_htrans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | arma_aligned const subview_row_htrans<eT> Q; | |
| | | | |
| | | inline explicit Proxy_subview_row_htrans_cx(const Op<subview_row<eT>, op_ | |
| | | htrans>& A) | |
| | | : Q(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q | |
| | | .sv_row.m)) == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct Proxy_subview_row_htrans_non_cx | |
| | | { | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<eT>::result pod_type; | |
| | | typedef subview_row_strans<eT> stored_type; | |
| | | typedef const subview_row_strans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | arma_aligned const subview_row_strans<eT> Q; | |
| | | | |
| | | inline explicit Proxy_subview_row_htrans_non_cx(const Op<subview_row<eT>, | |
| | | op_htrans>& A) | |
| | | : Q(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q | |
| | | .sv_row.m)) == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename eT, bool condition> | |
| | | struct Proxy_subview_row_htrans_redirect {}; | |
| | | | |
| | | template<typename eT> | |
| | | struct Proxy_subview_row_htrans_redirect<eT, true> { typedef Proxy_subview | |
| | | _row_htrans_cx<eT> result; }; | |
| | | | |
| | | template<typename eT> | |
| | | struct Proxy_subview_row_htrans_redirect<eT, false> { typedef Proxy_subview | |
| | | _row_htrans_non_cx<eT> result; }; | |
| | | | |
| | | template<typename eT> | |
| | | class Proxy< Op<subview_row<eT>, op_htrans> > | |
| | | : public | |
| | | Proxy_subview_row_htrans_redirect | |
| | | < | |
| | | eT, | |
| | | is_complex<eT>::value | |
| | | >::result | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef | |
| | | typename | |
| | | Proxy_subview_row_htrans_redirect | |
| | | < | |
| | | eT, | |
| | | is_complex<eT>::value | |
| | | >::result | |
| | | Proxy_sv_row_ht; | |
| | | | |
| | | typedef typename Proxy_sv_row_ht::elem_type elem_type; | |
| | | typedef typename Proxy_sv_row_ht::pod_type pod_type; | |
| | | typedef typename Proxy_sv_row_ht::stored_type stored_type; | |
| | | typedef typename Proxy_sv_row_ht::ea_type ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = Proxy_sv_row_ht::prefer_at_accesso | |
| | | r; | |
| | | static const bool has_subview = Proxy_sv_row_ht::has_subview; | |
| | | static const bool is_fixed = Proxy_sv_row_ht::is_fixed; | |
| | | static const bool fake_mat = Proxy_sv_row_ht::fake_mat; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | using Proxy_sv_row_ht::Q; | |
| | | | |
| | | inline explicit Proxy(const Op<subview_row<eT>, op_htrans>& A) | |
| | | : Proxy_sv_row_ht(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return 1; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword) const { r | |
| | | eturn Q[row]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_sv_row_ | |
| | | ht::is_alias(X); } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | class Proxy< Op<subview_row<eT>, op_strans> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<eT>::result pod_type; | |
| | | typedef subview_row_strans<eT> stored_type; | |
| | | typedef const subview_row_strans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | arma_aligned const subview_row_strans<eT> Q; | |
| | | | |
| | | inline explicit Proxy(const Op<subview_row<eT>, op_strans>& A) | |
| | | : Q(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return 1; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword) const { r | |
| | | eturn Q[row]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q | |
| | | .sv_row.m)) == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename T> | |
| | | class Proxy< Op< Row< std::complex<T> >, op_htrans> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | typedef typename std::complex<T> elem_type; | |
| | | typedef T pod_type; | |
| | | typedef xvec_htrans<eT> stored_type; | |
| | | typedef const xvec_htrans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = false; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | const xvec_htrans<eT> Q; | |
| | | const Row<eT>& src; | |
| | | | |
| | | inline explicit Proxy(const Op< Row< std::complex<T> >, op_htrans>& A) | |
| | | : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) | |
| | | , src(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return 1; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword) const { r | |
| | | eturn Q[row]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return void_ptr(&src | |
| | | ) == void_ptr(&X); } | |
| | | }; | |
| | | | |
| | | template<typename T> | |
| | | class Proxy< Op< Col< std::complex<T> >, op_htrans> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | typedef typename std::complex<T> elem_type; | |
| | | typedef T pod_type; | |
| | | typedef xvec_htrans<eT> stored_type; | |
| | | typedef const xvec_htrans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = false; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = true; | |
| | | static const bool is_col = false; | |
| | | | |
| | | const xvec_htrans<eT> Q; | |
| | | const Col<eT>& src; | |
| | | | |
| | | inline explicit Proxy(const Op< Col< std::complex<T> >, op_htrans>& A) | |
| | | : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) | |
| | | , src(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return 1; } | |
| | | arma_inline uword get_n_cols() const { return Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword, const uword col) const { r | |
| | | eturn Q[col]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return void_ptr(&src | |
| | | ) == void_ptr(&X); } | |
| | | }; | |
| | | | |
| | | template<typename T> | |
| | | class Proxy< Op< subview_col< std::complex<T> >, op_htrans> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | typedef typename std::complex<T> elem_type; | |
| | | typedef T pod_type; | |
| | | typedef xvec_htrans<eT> stored_type; | |
| | | typedef const xvec_htrans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = true; | |
| | | static const bool is_col = false; | |
| | | | |
| | | const xvec_htrans<eT> Q; | |
| | | const subview_col<eT>& src; | |
| | | | |
| | | inline explicit Proxy(const Op< subview_col< std::complex<T> >, op_htrans | |
| | | >& A) | |
| | | : Q (A.m.colptr(0), A.m.n_rows, A.m.n_cols) | |
| | | , src(A.m) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return 1; } | |
| | | arma_inline uword get_n_cols() const { return Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword, const uword col) const { r | |
| | | eturn Q[col]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return void_ptr(&src | |
| | | .m) == void_ptr(&X); } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_htrans2_default | |
| | | { | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef Mat<elem_type> stored_type; | |
| | | typedef const elem_type* ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = false; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = false; | |
| | | | |
| | | arma_aligned const Mat<elem_type> Q; | |
| | | | |
| | | arma_hot | |
| | | inline Proxy_htrans2_default(const T1& A) | |
| | | : Q(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_htrans2_vector | |
| | | { | |
| | | inline Proxy_htrans2_vector(const T1&) {} | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_htrans2_vector< Op<T1, op_htrans2> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef eOp< Op<T1, op_htrans>, eop_scalar_times> stored_type; | |
| | | typedef const eOp< Op<T1, op_htrans>, eop_scalar_times>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = eOp< Op<T1, op_htrans>, eop_scalar | |
| | | _times>::prefer_at_accessor; | |
| | | static const bool has_subview = eOp< Op<T1, op_htrans>, eop_scalar | |
| | | _times>::has_subview; | |
| | | static const bool is_fixed = eOp< Op<T1, op_htrans>, eop_scalar | |
| | | _times>::is_fixed; | |
| | | static const bool fake_mat = eOp< Op<T1, op_htrans>, eop_scalar | |
| | | _times>::fake_mat; | |
| | | | |
| | | // NOTE: the Op class takes care of swapping row and col for op_htrans | |
| | | static const bool is_row = eOp< Op<T1, op_htrans>, eop_scalar_times>::is_ | |
| | | row; | |
| | | static const bool is_col = eOp< Op<T1, op_htrans>, eop_scalar_times>::is_ | |
| | | col; | |
| | | | |
| | | arma_aligned const Op<T1, op_htrans> R; | |
| | | arma_aligned const eOp< Op<T1, op_htrans>, eop_scalar_times > Q; | |
| | | | |
| | | inline explicit Proxy_htrans2_vector(const Op<T1, op_htrans2>& A) | |
| | | : R(A.m) | |
| | | , Q(R, A.aux) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows() | |
| | | ; } | |
| | | arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols() | |
| | | ; } | |
| | | arma_inline uword get_n_elem() const { return Q.get_n_elem(); | |
| | | } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Q.P.is_alias( | |
| | | X); } | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct Proxy_htrans2_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_htrans2_redirect<T1, false> { typedef Proxy_htrans2_default<T1 | |
| | | > result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_htrans2_redirect<T1, true> { typedef Proxy_htrans2_vector<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | class Proxy< Op<T1, op_htrans2> > | |
| | | : public | |
| | | Proxy_htrans2_redirect | |
| | | < | |
| | | Op<T1, op_htrans2>, | |
| | | ( (Op<T1, op_htrans2>::is_row) || (Op<T1, op_htrans2>::is_col) ) | |
| | | >::result | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef | |
| | | typename | |
| | | Proxy_htrans2_redirect | |
| | | < | |
| | | Op<T1, op_htrans2>, | |
| | | ( (Op<T1, op_htrans2>::is_row) || (Op<T1, op_htrans2>::is_col) ) | |
| | | >::result | |
| | | Proxy_htrans2; | |
| | | | |
| | | typedef typename Proxy_htrans2::elem_type elem_type; | |
| | | typedef typename Proxy_htrans2::pod_type pod_type; | |
| | | typedef typename Proxy_htrans2::stored_type stored_type; | |
| | | typedef typename Proxy_htrans2::ea_type ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = Proxy_htrans2::prefer_at_accessor; | |
| | | static const bool has_subview = Proxy_htrans2::has_subview; | |
| | | static const bool is_fixed = Proxy_htrans2::is_fixed; | |
| | | static const bool fake_mat = Proxy_htrans2::fake_mat; | |
| | | | |
| | | static const bool is_row = Proxy_htrans2::is_row; | |
| | | static const bool is_col = Proxy_htrans2::is_col; | |
| | | | |
| | | using Proxy_htrans2::Q; | |
| | | | |
| | | inline explicit Proxy(const Op<T1, op_htrans2>& A) | |
| | | : Proxy_htrans2(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Proxy_htrans2::get_n_rows() | |
| | | ; } | |
| | | arma_inline uword get_n_cols() const { return Proxy_htrans2::get_n_cols() | |
| | | ; } | |
| | | arma_inline uword get_n_elem() const { return Proxy_htrans2::get_n_elem() | |
| | | ; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return Q.at(row, col); } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Proxy_htrans2::get_ea(); } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_htrans2 | |
| | | ::is_alias(X); } | |
| | | }; | |
| | | | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| class Proxy< Glue<T1, T2, glue_type> > | | class Proxy< Glue<T1, T2, glue_type> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<elem_type> stored_type; | | typedef Mat<elem_type> stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| | | | |
| skipping to change at line 741 | | skipping to change at line 1171 | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const { r
eturn Q[i]; } | | arma_inline elem_type operator[] (const uword i) const { r
eturn Q[i]; } | |
| arma_inline elem_type at (const uword, const uword col) const { r
eturn Q[col]; } | | arma_inline elem_type at (const uword, const uword col) const { r
eturn Q[col]; } | |
| | | | |
| arma_inline ea_type get_ea() const { return Q; } | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q
.m)) == void_ptr(&X)); } | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q
.m)) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
|
| | | template<typename eT> | |
| | | class Proxy< subview_row_strans<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef subview_row_strans<eT> stored_type; | |
| | | typedef const subview_row_strans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | arma_aligned const subview_row_strans<eT>& Q; | |
| | | | |
| | | inline explicit Proxy(const subview_row_strans<eT>& A) | |
| | | : Q(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return 1; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword) const { r | |
| | | eturn Q[row]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q | |
| | | .sv_row.m)) == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | class Proxy< subview_row_htrans<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef subview_row_htrans<eT> stored_type; | |
| | | typedef const subview_row_htrans<eT>& ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = true; | |
| | | static const bool is_fixed = false; | |
| | | static const bool fake_mat = false; | |
| | | | |
| | | static const bool is_row = false; | |
| | | static const bool is_col = true; | |
| | | | |
| | | arma_aligned const subview_row_htrans<eT>& Q; | |
| | | | |
| | | inline explicit Proxy(const subview_row_htrans<eT>& A) | |
| | | : Q(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return 1; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const { r | |
| | | eturn Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword) const { r | |
| | | eturn Q[row]; } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q | |
| | | .sv_row.m)) == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| template<typename eT, typename T1> | | template<typename eT, typename T1> | |
| class Proxy< subview_elem1<eT,T1> > | | class Proxy< subview_elem1<eT,T1> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<eT> stored_type; | | typedef Mat<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| | | | |
End of changes. 3 change blocks. |
| 2 lines changed or deleted | | 557 lines changed or added | |
|
| diskio_bones.hpp | | diskio_bones.hpp | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2012 Conrad Sanderson | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
|
| | | // Copyright (C) 2012 Ryan Curtin | |
| | | // Copyright (C) 2013 Szabolcs Horvat | |
| // | | // | |
| // 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 diskio | | //! \addtogroup diskio | |
| //! @{ | | //! @{ | |
| | | | |
| //! class for saving and loading matrices and fields | | //! class for saving and loading matrices and fields | |
| class diskio | | class diskio | |
| | | | |
| skipping to change at line 108 | | skipping to change at line 110 | |
| template<typename T> inline static bool load_coord_ascii(SpMat< std::com
plex<T> >& x, std::istream& f, std::string& err_msg); | | template<typename T> inline static bool load_coord_ascii(SpMat< std::com
plex<T> >& x, std::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x,
std::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x,
std::istream& f, std::string& err_msg); | |
| | | | |
| // | | // | |
| // cube saving | | // cube saving | |
| | | | |
| template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, const std::string& name); | |
| template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, const std::string& name); | | template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, const std::string& name); | |
|
| | | template<typename eT> inline static bool save_hdf5_binary(const Cube<eT>&
x, const std::string& name); | |
| | | | |
| template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, std::ostream& f); | | template<typename eT> inline static bool save_raw_ascii (const Cube<eT>&
x, std::ostream& f); | |
| template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, std::ostream& f); | | template<typename eT> inline static bool save_raw_binary (const Cube<eT>&
x, std::ostream& f); | |
| template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, std::ostream& f); | | template<typename eT> inline static bool save_arma_ascii (const Cube<eT>&
x, std::ostream& f); | |
| template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, std::ostream& f); | | template<typename eT> inline static bool save_arma_binary(const Cube<eT>&
x, std::ostream& f); | |
| | | | |
| // | | // | |
| // cube loading | | // cube loading | |
| | | | |
| template<typename eT> inline static bool load_raw_ascii (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_raw_ascii (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
| template<typename eT> inline static bool load_raw_binary (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_raw_binary (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
|
| | | template<typename eT> inline static bool load_hdf5_binary(Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
| template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | | template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, co
nst std::string& name, std::string& err_msg); | |
| | | | |
| template<typename eT> inline static bool load_raw_ascii (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_raw_ascii (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_raw_binary (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_raw_binary (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, st
d::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, st
d::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, st
d::istream& f, std::string& err_msg); | |
| template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, st
d::istream& f, std::string& err_msg); | | template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, st
d::istream& f, std::string& err_msg); | |
| | | | |
| // | | // | |
| // field saving and loading | | // field saving and loading | |
| | | | |
End of changes. 3 change blocks. |
| 0 lines changed or deleted | | 4 lines changed or added | |
|
| diskio_meat.hpp | | diskio_meat.hpp | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2012 Conrad Sanderson | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
| // Copyright (C) 2012 Ryan Curtin | | // Copyright (C) 2012 Ryan Curtin | |
|
| | | // Copyright (C) 2013 Szabolcs Horvat | |
| // | | // | |
| // 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 diskio | | //! \addtogroup diskio | |
| //! @{ | | //! @{ | |
| | | | |
| //! Generate the first line of the header used for saving matrices in text
format. | | //! Generate the first line of the header used for saving matrices in text
format. | |
| //! Format: "ARMA_MAT_TXT_ABXYZ". | | //! Format: "ARMA_MAT_TXT_ABXYZ". | |
| | | | |
| skipping to change at line 1924 | | skipping to change at line 1925 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| uchar_mat tmp; | | uchar_mat tmp; | |
| const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); | | const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); | |
| | | | |
| x = conv_to< Mat< std::complex<T> > >::from(tmp); | | x = conv_to< Mat< std::complex<T> > >::from(tmp); | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
|
| | | //! Load a HDF5 file as a matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::load_hdf5_binary(Mat<eT>& x, const std::string& name, std::string&
err_msg) | | diskio::load_hdf5_binary(Mat<eT>& x, const std::string& name, std::string&
err_msg) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| #if defined(ARMA_USE_HDF5) | | #if defined(ARMA_USE_HDF5) | |
| { | | { | |
| | | | |
| | | | |
| skipping to change at line 2011 | | skipping to change at line 2013 | |
| if(H5Tequal(datatype, mat_type) > 0) | | if(H5Tequal(datatype, mat_type) > 0) | |
| { | | { | |
| // Load directly; H5S_ALL used so that we load the entire dataset
. | | // Load directly; H5S_ALL used so that we load the entire dataset
. | |
| hid_t read_status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL,
H5P_DEFAULT, void_ptr(x.memptr())); | | hid_t read_status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL,
H5P_DEFAULT, void_ptr(x.memptr())); | |
| | | | |
| if(read_status >= 0) { load_okay = true; } | | if(read_status >= 0) { load_okay = true; } | |
| } | | } | |
| else | | else | |
| { | | { | |
| // Load as another matrix and convert accordingly. | | // Load as another matrix and convert accordingly. | |
|
| hid_t read_status = hdf5_misc::load_and_convert_hdf5(x, dataset,
datatype, dims); | | hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(),
dataset, datatype, x.n_elem); | |
| | | | |
| if(read_status >= 0) { load_okay = true; } | | if(read_status >= 0) { load_okay = true; } | |
| } | | } | |
| | | | |
| // Now clean up. | | // Now clean up. | |
| H5Tclose(datatype); | | H5Tclose(datatype); | |
| H5Tclose(mat_type); | | H5Tclose(mat_type); | |
| H5Sclose(filespace); | | H5Sclose(filespace); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 3161 | | skipping to change at line 3163 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| f << diskio::gen_bin_header(x) << '\n'; | | f << diskio::gen_bin_header(x) << '\n'; | |
| f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; | | f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; | |
| | | | |
| f.write( reinterpret_cast<const char*>(x.mem), std::streamsize(x.n_elem*s
izeof(eT)) ); | | f.write( reinterpret_cast<const char*>(x.mem), std::streamsize(x.n_elem*s
izeof(eT)) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
|
| | | //! Save a cube as part of a HDF5 file | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | diskio::save_hdf5_binary(const Cube<eT>& x, const std::string& final_name) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_HDF5) | |
| | | { | |
| | | #if !defined(ARMA_PRINT_HDF5_ERRORS) | |
| | | { | |
| | | // Disable annoying HDF5 error messages. | |
| | | H5Eset_auto(H5E_DEFAULT, NULL, NULL); | |
| | | } | |
| | | #endif | |
| | | | |
| | | bool save_okay = false; | |
| | | | |
| | | const std::string tmp_name = diskio::gen_tmp_name(final_name); | |
| | | | |
| | | // Set up the file according to HDF5's preferences | |
| | | hid_t file = H5Fcreate(tmp_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5 | |
| | | P_DEFAULT); | |
| | | | |
| | | // We need to create a dataset, datatype, and dataspace | |
| | | hsize_t dims[3]; | |
| | | dims[2] = x.n_rows; | |
| | | dims[1] = x.n_cols; | |
| | | dims[0] = x.n_slices; | |
| | | | |
| | | hid_t dataspace = H5Screate_simple(3, dims, NULL); // treat the cube | |
| | | as a 3d array dataspace | |
| | | hid_t datatype = hdf5_misc::get_hdf5_type<eT>(); | |
| | | | |
| | | // If this returned something invalid, well, it's time to crash. | |
| | | arma_check(datatype == -1, "Cube::save(): unknown datatype for HDF5"); | |
| | | | |
| | | // MATLAB forces the users to specify a name at save time for HDF5; Oct | |
| | | ave | |
| | | // will use the default of 'dataset' unless otherwise specified, so we | |
| | | will | |
| | | // use that. | |
| | | hid_t dataset = H5Dcreate(file, "dataset", datatype, dataspace, H5P_DEF | |
| | | AULT, H5P_DEFAULT, H5P_DEFAULT); | |
| | | | |
| | | herr_t status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | |
| | | LT, x.mem); | |
| | | save_okay = (status >= 0); | |
| | | | |
| | | H5Dclose(dataset); | |
| | | H5Tclose(datatype); | |
| | | H5Sclose(dataspace); | |
| | | H5Fclose(file); | |
| | | | |
| | | if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final | |
| | | _name); } | |
| | | | |
| | | return save_okay; | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(x); | |
| | | arma_ignore(final_name); | |
| | | | |
| | | arma_stop("Cube::save(): use of HDF5 needs to be enabled"); | |
| | | | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| //! Load a cube as raw text (no header, human readable). | | //! Load a cube as raw text (no header, human readable). | |
| //! NOTE: this is much slower than reading a file with a header. | | //! NOTE: this is much slower than reading a file with a header. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::load_raw_ascii(Cube<eT>& x, const std::string& name, std::string& e
rr_msg) | | diskio::load_raw_ascii(Cube<eT>& x, const std::string& name, std::string& e
rr_msg) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT> tmp; | | Mat<eT> tmp; | |
| | | | |
| skipping to change at line 3403 | | skipping to change at line 3470 | |
| } | | } | |
| else | | else | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| err_msg = "incorrect header in "; | | err_msg = "incorrect header in "; | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| } | | } | |
| | | | |
|
| | | //! Load a HDF5 file as a cube | |
| | | template<typename eT> | |
| | | inline | |
| | | bool | |
| | | diskio::load_hdf5_binary(Cube<eT>& x, const std::string& name, std::string& | |
| | | err_msg) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_HDF5) | |
| | | { | |
| | | | |
| | | // These may be necessary to store the error handler (if we need to). | |
| | | herr_t (*old_func)(hid_t, void*); | |
| | | void *old_client_data; | |
| | | | |
| | | #if !defined(ARMA_PRINT_HDF5_ERRORS) | |
| | | { | |
| | | // Save old error handler. | |
| | | H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data); | |
| | | | |
| | | // Disable annoying HDF5 error messages. | |
| | | H5Eset_auto(H5E_DEFAULT, NULL, NULL); | |
| | | } | |
| | | #endif | |
| | | | |
| | | bool load_okay = false; | |
| | | | |
| | | hid_t fid = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); | |
| | | | |
| | | if(fid >= 0) | |
| | | { | |
| | | // MATLAB HDF5 dataset names are user-specified; | |
| | | // Octave tends to store the datasets in a group, with the actual dat | |
| | | aset being referred to as "value". | |
| | | // So we will search for "dataset" and "value", and if those are not | |
| | | found we will take the first dataset we do find. | |
| | | std::vector<std::string> searchNames; | |
| | | searchNames.push_back("dataset"); | |
| | | searchNames.push_back("value"); | |
| | | | |
| | | hid_t dataset = hdf5_misc::search_hdf5_file(searchNames, fid, 3, fals | |
| | | e); | |
| | | | |
| | | if(dataset >= 0) | |
| | | { | |
| | | hid_t filespace = H5Dget_space(dataset); | |
| | | | |
| | | // This must be <= 3 due to our search rules. | |
| | | const int ndims = H5Sget_simple_extent_ndims(filespace); | |
| | | | |
| | | hsize_t dims[3]; | |
| | | const herr_t query_status = H5Sget_simple_extent_dims(filespace, di | |
| | | ms, NULL); | |
| | | | |
| | | // arma_check(query_status < 0, "Cube::load(): cannot get size of H | |
| | | DF5 dataset"); | |
| | | if(query_status < 0) | |
| | | { | |
| | | err_msg = "cannot get size of HDF5 dataset in "; | |
| | | | |
| | | H5Sclose(filespace); | |
| | | H5Dclose(dataset); | |
| | | H5Fclose(fid); | |
| | | | |
| | | #if !defined(ARMA_PRINT_HDF5_ERRORS) | |
| | | { | |
| | | // Restore HDF5 error handler. | |
| | | H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); | |
| | | } | |
| | | #endif | |
| | | | |
| | | return false; | |
| | | } | |
| | | | |
| | | if (ndims == 1) { dims[1] = 1; dims[2] = 1; } // Vector case; one | |
| | | row/colum, several slices | |
| | | if (ndims == 2) { dims[2] = 1; } // Matrix case; one column, severa | |
| | | l rows/slices | |
| | | | |
| | | x.set_size(dims[2], dims[1], dims[0]); | |
| | | | |
| | | // Now we have to see what type is stored to figure out how to load | |
| | | it. | |
| | | hid_t datatype = H5Dget_type(dataset); | |
| | | hid_t mat_type = hdf5_misc::get_hdf5_type<eT>(); | |
| | | | |
| | | // If these are the same type, it is simple. | |
| | | if(H5Tequal(datatype, mat_type) > 0) | |
| | | { | |
| | | // Load directly; H5S_ALL used so that we load the entire dataset | |
| | | . | |
| | | hid_t read_status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, | |
| | | H5P_DEFAULT, void_ptr(x.memptr())); | |
| | | | |
| | | if(read_status >= 0) { load_okay = true; } | |
| | | } | |
| | | else | |
| | | { | |
| | | // Load as another matrix and convert accordingly. | |
| | | hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(), | |
| | | dataset, datatype, x.n_elem); | |
| | | | |
| | | if(read_status >= 0) { load_okay = true; } | |
| | | } | |
| | | | |
| | | // Now clean up. | |
| | | H5Tclose(datatype); | |
| | | H5Tclose(mat_type); | |
| | | H5Sclose(filespace); | |
| | | } | |
| | | | |
| | | H5Dclose(dataset); | |
| | | | |
| | | H5Fclose(fid); | |
| | | | |
| | | if(load_okay == false) | |
| | | { | |
| | | err_msg = "unsupported or incorrect HDF5 data in "; | |
| | | } | |
| | | } | |
| | | else | |
| | | { | |
| | | err_msg = "cannot open file "; | |
| | | } | |
| | | | |
| | | #if !defined(ARMA_PRINT_HDF5_ERRORS) | |
| | | { | |
| | | // Restore HDF5 error handler. | |
| | | H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); | |
| | | } | |
| | | #endif | |
| | | | |
| | | return load_okay; | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(x); | |
| | | arma_ignore(name); | |
| | | arma_ignore(err_msg); | |
| | | | |
| | | arma_stop("Cube::load(): use of HDF5 needs to be enabled"); | |
| | | | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| //! Try to load a cube by automatically determining its type | | //! Try to load a cube by automatically determining its type | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::load_auto_detect(Cube<eT>& x, const std::string& name, std::string&
err_msg) | | diskio::load_auto_detect(Cube<eT>& x, const std::string& name, std::string&
err_msg) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | #if defined(ARMA_USE_HDF5) | |
| | | // We're currently using the C bindings for the HDF5 library, which don | |
| | | 't support C++ streams | |
| | | if( H5Fis_hdf5(name.c_str()) ) { return load_hdf5_binary(x, name, err_m | |
| | | sg); } | |
| | | #endif | |
| | | | |
| std::fstream f; | | std::fstream f; | |
| f.open(name.c_str(), std::fstream::in | std::fstream::binary); | | f.open(name.c_str(), std::fstream::in | std::fstream::binary); | |
| | | | |
| bool load_okay = f.is_open(); | | bool load_okay = f.is_open(); | |
| | | | |
| if(load_okay == true) | | if(load_okay == true) | |
| { | | { | |
| load_okay = diskio::load_auto_detect(x, f, err_msg); | | load_okay = diskio::load_auto_detect(x, f, err_msg); | |
| f.close(); | | f.close(); | |
| } | | } | |
| | | | |
End of changes. 6 change blocks. |
| 1 lines changed or deleted | | 230 lines changed or added | |
|
| hdf5_misc.hpp | | hdf5_misc.hpp | |
| // Copyright (C) 2012 Ryan Curtin | | // Copyright (C) 2012 Ryan Curtin | |
| // Copyright (C) 2012 Conrad Sanderson | | // Copyright (C) 2012 Conrad Sanderson | |
|
| | | // Copyright (C) 2013 Szabolcs Horvat | |
| // | | // | |
| // 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 hdf5_misc | | //! \addtogroup hdf5_misc | |
| //! @{ | | //! @{ | |
| | | | |
| #if defined(ARMA_USE_HDF5) | | #if defined(ARMA_USE_HDF5) | |
| namespace hdf5_misc | | namespace hdf5_misc | |
| | | | |
| skipping to change at line 427 | | skipping to change at line 428 | |
| { | | { | |
| hdf5_search_info search_info = { names, num_dims, exact, -1, names.size()
}; | | hdf5_search_info search_info = { names, num_dims, exact, -1, names.size()
}; | |
| | | | |
| // We'll use the H5Ovisit to track potential entries. | | // We'll use the H5Ovisit to track potential entries. | |
| herr_t status = H5Ovisit(hdf5_file, H5_INDEX_NAME, H5_ITER_NATIVE, hdf5_s
earch_callback, void_ptr(&search_info)); | | herr_t status = H5Ovisit(hdf5_file, H5_INDEX_NAME, H5_ITER_NATIVE, hdf5_s
earch_callback, void_ptr(&search_info)); | |
| | | | |
| // Return the best match; it will be -1 if there was a problem. | | // Return the best match; it will be -1 if there was a problem. | |
| return (status < 0) ? -1 : search_info.best_match; | | return (status < 0) ? -1 : search_info.best_match; | |
| } | | } | |
| | | | |
|
| //! Load an HDF5 matrix into a Mat of type specified by datatype, | | //! Load an HDF5 matrix into an array of type specified by datatype, | |
| //! then convert that into the desired matrix 'dest'. | | //! then convert that into the desired array 'dest'. | |
| //! This should only be called when eT is not the datatype. | | //! This should only be called when eT is not the datatype. | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| hid_t | | hid_t | |
| load_and_convert_hdf5 | | load_and_convert_hdf5 | |
| ( | | ( | |
|
| Mat<eT>& dest, | | eT *dest, | |
| hid_t dataset, | | hid_t dataset, | |
| hid_t datatype, | | hid_t datatype, | |
| hsize_t* dims | | uword n_elem | |
| ) | | ) | |
| { | | { | |
|
| const uword n_rows = dims[0]; | | | |
| const uword n_cols = dims[1]; | | | |
| | | | |
| // We can't use nice template specializations here | | // We can't use nice template specializations here | |
| // as the determination of the type of 'datatype' must be done at runtime
. | | // as the determination of the type of 'datatype' must be done at runtime
. | |
| // So we end up with this ugliness... | | // So we end up with this ugliness... | |
| hid_t search_type; | | hid_t search_type; | |
| | | | |
| bool is_equal; | | bool is_equal; | |
| | | | |
| // u8 | | // u8 | |
| search_type = get_hdf5_type<u8>(); | | search_type = get_hdf5_type<u8>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<u8> m(n_rows, n_cols); | | Col<u8> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // s8 | | // s8 | |
| search_type = get_hdf5_type<s8>(); | | search_type = get_hdf5_type<s8>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<s8> m(n_rows, n_cols); | | Col<s8> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // u16 | | // u16 | |
| search_type = get_hdf5_type<u16>(); | | search_type = get_hdf5_type<u16>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<u16> m(n_rows, n_cols); | | Col<u16> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // s16 | | // s16 | |
| search_type = get_hdf5_type<s16>(); | | search_type = get_hdf5_type<s16>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<s16> m(n_rows, n_cols); | | Col<s16> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // u32 | | // u32 | |
| search_type = get_hdf5_type<u32>(); | | search_type = get_hdf5_type<u32>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<u32> m(n_rows, n_cols); | | Col<u32> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // s32 | | // s32 | |
| search_type = get_hdf5_type<s32>(); | | search_type = get_hdf5_type<s32>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<s32> m(n_rows, n_cols); | | Col<s32> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| #if defined(ARMA_USE_U64S64) | | #if defined(ARMA_USE_U64S64) | |
| { | | { | |
| // u64 | | // u64 | |
| search_type = get_hdf5_type<u64>(); | | search_type = get_hdf5_type<u64>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<u64> m(n_rows, n_cols); | | Col<u64> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | |
| LT, void_ptr(m.memptr())); | | LT, void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // s64 | | // s64 | |
| search_type = get_hdf5_type<s64>(); | | search_type = get_hdf5_type<s64>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<s64> m(n_rows, n_cols); | | Col<s64> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | |
| LT, void_ptr(m.memptr())); | | LT, void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| #if defined(ARMA_ALLOW_LONG) | | #if defined(ARMA_ALLOW_LONG) | |
| { | | { | |
| // ulng_t | | // ulng_t | |
| search_type = get_hdf5_type<ulng_t>(); | | search_type = get_hdf5_type<ulng_t>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<ulng_t> m(n_rows, n_cols); | | Col<ulng_t> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | |
| LT, void_ptr(m.memptr())); | | LT, void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // slng_t | | // slng_t | |
| search_type = get_hdf5_type<slng_t>(); | | search_type = get_hdf5_type<slng_t>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<slng_t> m(n_rows, n_cols); | | Col<slng_t> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAU | |
| LT, void_ptr(m.memptr())); | | LT, void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| // float | | // float | |
| search_type = get_hdf5_type<float>(); | | search_type = get_hdf5_type<float>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<float> m(n_rows, n_cols); | | Col<float> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // double | | // double | |
| search_type = get_hdf5_type<double>(); | | search_type = get_hdf5_type<double>(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat<double> m(n_rows, n_cols); | | Col<double> v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // complex float | | // complex float | |
| search_type = get_hdf5_type< std::complex<float> >(); | | search_type = get_hdf5_type< std::complex<float> >(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat< std::complex<float> > m(n_rows, n_cols); | | Col< std::complex<float> > v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert_cx(dest, v.memptr(), n_elem); // convert | |
| | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| // complex double | | // complex double | |
| search_type = get_hdf5_type< std::complex<double> >(); | | search_type = get_hdf5_type< std::complex<double> >(); | |
| is_equal = (H5Tequal(datatype, search_type) > 0); | | is_equal = (H5Tequal(datatype, search_type) > 0); | |
| H5Tclose(search_type); | | H5Tclose(search_type); | |
| | | | |
| if(is_equal) | | if(is_equal) | |
| { | | { | |
|
| Mat< std::complex<double> > m(n_rows, n_cols); | | Col< std::complex<double> > v(n_elem); | |
| hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | | hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT | |
| , void_ptr(m.memptr())); | | , void_ptr(v.memptr())); | |
| dest = conv_to< Mat<eT> >::from(m); // Convert. | | arrayops::convert_cx(dest, v.memptr(), n_elem); // convert | |
| | | | |
|
| H5Tclose(search_type); | | | |
| return status; | | return status; | |
| } | | } | |
| | | | |
| return -1; // Failure. | | return -1; // Failure. | |
| } | | } | |
| | | | |
| } // namespace hdf5_misc | | } // namespace hdf5_misc | |
| #endif // #if defined(ARMA_USE_HDF5) | | #endif // #if defined(ARMA_USE_HDF5) | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 19 change blocks. |
| 65 lines changed or deleted | | 63 lines changed or added | |
|
| op_median_meat.hpp | | op_median_meat.hpp | |
|
| // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2009-2012 Conrad Sanderson | | // Copyright (C) 2009-2013 Conrad Sanderson | |
| | | // Copyright (C) 2013 Ruslan Shestopalyuk | |
| // | | // | |
| // This Source Code Form is subject to the terms of the Mozilla Public | | // This Source Code Form is subject to the terms of the Mozilla Public | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | | // License, v. 2.0. If a copy of the MPL was not distributed with this | |
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| | | | |
| //! \addtogroup op_median | | //! \addtogroup op_median | |
| //! @{ | | //! @{ | |
| | | | |
| //! \brief | | //! \brief | |
| //! For each row or for each column, find the median value. | | //! For each row or for each column, find the median value. | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 25 | |
| //! The dimension, for which the medians are found, is set via the median()
function. | | //! The dimension, for which the medians are found, is set via the median()
function. | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_median::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_median>&
in) | | op_median::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_median>&
in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const unwrap_check<T1> tmp(in.m, out); | | | |
| const Mat<eT>& X = tmp.M; | | | |
| | | | |
| const uword X_n_rows = X.n_rows; | | | |
| const uword X_n_cols = X.n_cols; | | | |
| | | | |
| const uword dim = in.aux_uword_a; | | const uword dim = in.aux_uword_a; | |
| arma_debug_check( (dim > 1), "median(): incorrect usage. dim must be 0 or
1"); | | arma_debug_check( (dim > 1), "median(): incorrect usage. dim must be 0 or
1"); | |
| | | | |
|
| if(dim == 0) // in each column | | const Proxy<T1> P(in.m); | |
| { | | | |
| arma_extra_debug_print("op_median::apply(), dim = 0"); | | | |
| | | | |
|
| arma_debug_check( (X_n_rows == 0), "median(): given object has zero row
s" ); | | typedef typename Proxy<T1>::stored_type P_stored_type; | |
| | | | |
|
| out.set_size(1, X_n_cols); | | const bool is_alias = P.is_alias(out); | |
| | | | |
|
| std::vector<eT> tmp_vec(X_n_rows); | | if( (is_Mat<P_stored_type>::value == true) || is_alias ) | |
| | | { | |
| | | const unwrap_check<P_stored_type> tmp(P.Q, is_alias); | |
| | | | |
|
| for(uword col=0; col<X_n_cols; ++col) | | const typename unwrap_check<P_stored_type>::stored_type& X = tmp.M; | |
| | | | |
| | | const uword X_n_rows = X.n_rows; | |
| | | const uword X_n_cols = X.n_cols; | |
| | | | |
| | | if(dim == 0) // in each column | |
| { | | { | |
|
| const eT* colmem = X.colptr(col); | | arma_extra_debug_print("op_median::apply(), dim = 0"); | |
| | | | |
|
| for(uword row=0; row<X_n_rows; ++row) | | arma_debug_check( (X_n_rows == 0), "median(): given object has zero r | |
| | | ows" ); | |
| | | | |
| | | out.set_size(1, X_n_cols); | |
| | | | |
| | | std::vector<eT> tmp_vec(X_n_rows); | |
| | | | |
| | | for(uword col=0; col < X_n_cols; ++col) | |
| { | | { | |
|
| tmp_vec[row] = colmem[row]; | | arrayops::copy( &(tmp_vec[0]), X.colptr(col), X_n_rows ); | |
| | | | |
| | | out[col] = op_median::direct_median(tmp_vec); | |
| } | | } | |
|
| | | } | |
| | | else // in each row | |
| | | { | |
| | | arma_extra_debug_print("op_median::apply(), dim = 1"); | |
| | | | |
| | | arma_debug_check( (X_n_cols == 0), "median(): given object has zero c | |
| | | olumns" ); | |
| | | | |
| | | out.set_size(X_n_rows, 1); | |
| | | | |
| | | std::vector<eT> tmp_vec(X_n_cols); | |
| | | | |
| | | for(uword row=0; row < X_n_rows; ++row) | |
| | | { | |
| | | for(uword col=0; col < X_n_cols; ++col) { tmp_vec[col] = X.at(row, | |
| | | col); } | |
| | | | |
|
| out[col] = op_median::direct_median(tmp_vec); | | out[row] = op_median::direct_median(tmp_vec); | |
| | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
|
| if(dim == 1) // in each row | | | |
| { | | { | |
|
| arma_extra_debug_print("op_median::apply(), dim = 1"); | | const uword P_n_rows = P.get_n_rows(); | |
| | | const uword P_n_cols = P.get_n_cols(); | |
| | | | |
|
| arma_debug_check( (X_n_cols == 0), "median(): given object has zero col | | if(dim == 0) // in each column | |
| umns" ); | | { | |
| | | arma_extra_debug_print("op_median::apply(), dim = 0"); | |
| | | | |
|
| out.set_size(X_n_rows, 1); | | arma_debug_check( (P_n_rows == 0), "median(): given object has zero r
ows" ); | |
| | | | |
|
| std::vector<eT> tmp_vec(X_n_cols); | | out.set_size(1, P_n_cols); | |
| | | | |
|
| for(uword row=0; row<X_n_rows; ++row) | | std::vector<eT> tmp_vec(P_n_rows); | |
| { | | | |
| for(uword col=0; col<X_n_cols; ++col) | | for(uword col=0; col < P_n_cols; ++col) | |
| { | | { | |
|
| tmp_vec[col] = X.at(row,col); | | for(uword row=0; row < P_n_rows; ++row) { tmp_vec[row] = P.at(row, | |
| | | col); } | |
| | | | |
| | | out[col] = op_median::direct_median(tmp_vec); | |
| } | | } | |
|
| | | } | |
| | | else // in each row | |
| | | { | |
| | | arma_extra_debug_print("op_median::apply(), dim = 1"); | |
| | | | |
| | | arma_debug_check( (P_n_cols == 0), "median(): given object has zero c | |
| | | olumns" ); | |
| | | | |
|
| out[row] = op_median::direct_median(tmp_vec); | | out.set_size(P_n_rows, 1); | |
| | | | |
| | | std::vector<eT> tmp_vec(P_n_cols); | |
| | | | |
| | | for(uword row=0; row < P_n_rows; ++row) | |
| | | { | |
| | | for(uword col=0; col < P_n_cols; ++col) { tmp_vec[col] = P.at(row, | |
| | | col); } | |
| | | | |
| | | out[row] = op_median::direct_median(tmp_vec); | |
| | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! Implementation for complex numbers | | //! Implementation for complex numbers | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| void | | void | |
| op_median::apply(Mat< std::complex<T> >& out, const Op<T1,op_median>& in) | | op_median::apply(Mat< std::complex<T> >& out, const Op<T1,op_median>& in) | |
| { | | { | |
| | | | |
| skipping to change at line 168 | | skipping to change at line 210 | |
| ( | | ( | |
| const T1& X, | | const T1& X, | |
| const typename arma_not_cx<typename T1::elem_type>::result* junk | | const typename arma_not_cx<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| arma_ignore(junk); | | arma_ignore(junk); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| | | typedef typename Proxy<T1>::stored_type P_stored_type; | |
| | | | |
| const Proxy<T1> P(X); | | const Proxy<T1> P(X); | |
| | | | |
| const uword n_elem = P.get_n_elem(); | | const uword n_elem = P.get_n_elem(); | |
| | | | |
| arma_debug_check( (n_elem == 0), "median(): given object has no elements"
); | | arma_debug_check( (n_elem == 0), "median(): given object has no elements"
); | |
| | | | |
| std::vector<eT> tmp_vec(n_elem); | | std::vector<eT> tmp_vec(n_elem); | |
| | | | |
|
| if(Proxy<T1>::prefer_at_accessor == false) | | if(is_Mat<P_stored_type>::value == true) | |
| { | | { | |
|
| typedef typename Proxy<T1>::ea_type ea_type; | | const unwrap<P_stored_type> tmp(P.Q); | |
| | | | |
|
| ea_type A = P.get_ea(); | | const typename unwrap_check<P_stored_type>::stored_type& Y = tmp.M; | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | arrayops::copy( &(tmp_vec[0]), Y.memptr(), n_elem ); | |
| { | | | |
| tmp_vec[i] = A[i]; | | | |
| } | | | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const uword n_rows = P.get_n_rows(); | | if(Proxy<T1>::prefer_at_accessor == false) | |
| const uword n_cols = P.get_n_cols(); | | | |
| | | | |
| if(n_cols == 1) | | | |
| { | | { | |
|
| for(uword row=0; row < n_rows; ++row) | | typedef typename Proxy<T1>::ea_type ea_type; | |
| { | | | |
| tmp_vec[row] = P.at(row,0); | | ea_type A = P.get_ea(); | |
| } | | | |
| | | for(uword i=0; i<n_elem; ++i) { tmp_vec[i] = A[i]; } | |
| } | | } | |
| else | | else | |
|
| if(n_rows == 1) | | | |
| { | | { | |
|
| for(uword col=0; col < n_cols; ++col) | | const uword n_rows = P.get_n_rows(); | |
| | | const uword n_cols = P.get_n_cols(); | |
| | | | |
| | | if(n_cols == 1) | |
| { | | { | |
|
| tmp_vec[col] = P.at(0,col); | | for(uword row=0; row < n_rows; ++row) { tmp_vec[row] = P.at(row,0) | |
| | | ; } | |
| | | } | |
| | | else | |
| | | if(n_rows == 1) | |
| | | { | |
| | | for(uword col=0; col < n_cols; ++col) { tmp_vec[col] = P.at(0,col) | |
| | | ; } | |
| | | } | |
| | | else | |
| | | { | |
| | | arma_stop("op_median::median_vec(): expected a vector" ); | |
| } | | } | |
|
| } | | | |
| else | | | |
| { | | | |
| arma_stop("op_median::median_vec(): expected a vector" ); | | | |
| } | | } | |
| } | | } | |
| | | | |
| return op_median::direct_median(tmp_vec); | | return op_median::direct_median(tmp_vec); | |
| } | | } | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| typename T1::elem_type | | typename T1::elem_type | |
| op_median::median_vec | | op_median::median_vec | |
| | | | |
| skipping to change at line 311 | | skipping to change at line 357 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_median::direct_median(std::vector<eT>& X) | | op_median::direct_median(std::vector<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword n_elem = X.size(); | | const uword n_elem = X.size(); | |
| const uword half = n_elem/2; | | const uword half = n_elem/2; | |
| | | | |
|
| std::sort(X.begin(), X.end()); | | std::nth_element(X.begin(), X.begin() + half, X.end()); | |
| | | | |
| if((n_elem % 2) == 0) | | if((n_elem % 2) == 0) | |
| { | | { | |
|
| return op_mean::robust_mean(X[half-1], X[half]); | | return op_mean::robust_mean(*(std::max_element(X.begin(), X.begin() + h
alf)), X[half]); | |
| } | | } | |
| else | | else | |
| { | | { | |
| return X[half]; | | return X[half]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| void | | void | |
| | | | |
| skipping to change at line 338 | | skipping to change at line 384 | |
| uword& out_index1, | | uword& out_index1, | |
| uword& out_index2, | | uword& out_index2, | |
| std::vector< arma_cx_median_packet<T> >& X | | std::vector< arma_cx_median_packet<T> >& X | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword n_elem = X.size(); | | const uword n_elem = X.size(); | |
| const uword half = n_elem/2; | | const uword half = n_elem/2; | |
| | | | |
|
| std::sort(X.begin(), X.end()); | | std::nth_element(X.begin(), X.begin() + half, X.end()); | |
| | | | |
| if((n_elem % 2) == 0) | | if((n_elem % 2) == 0) | |
| { | | { | |
|
| out_index1 = X[half-1].index; | | out_index1 = std::max_element(X.begin(), X.begin() + half)->index; | |
| out_index2 = X[half ].index; | | out_index2 = X[half].index; | |
| } | | } | |
| else | | else | |
| { | | { | |
| out_index1 = X[half].index; | | out_index1 = X[half].index; | |
| out_index2 = out_index1; | | out_index2 = out_index1; | |
| } | | } | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 36 change blocks. |
| 57 lines changed or deleted | | 110 lines changed or added | |
|