max@0: // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2010-2012 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup Proxy max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: class Proxy max@0: { max@0: public: max@0: inline Proxy(const T1& A) max@0: { max@0: arma_type_check(( is_arma_type::value == false )); max@0: } max@0: }; max@0: max@0: max@0: max@0: // ea_type is the "element accessor" type, max@0: // which can provide access to elements via operator[] max@0: max@0: template max@0: class Proxy< Mat > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const eT* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat& Q; max@0: max@0: inline explicit Proxy(const Mat& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< Col > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Col stored_type; max@0: typedef const eT* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Col& Q; max@0: max@0: inline explicit Proxy(const Col& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return 1; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< Row > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Row stored_type; max@0: typedef const eT* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Row& Q; max@0: max@0: inline explicit Proxy(const Row& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return 1; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< Gen > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Gen stored_type; max@0: typedef const Gen& ea_type; max@0: max@0: static const bool prefer_at_accessor = Gen::prefer_at_accessor; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Gen& Q; max@0: max@0: inline explicit Proxy(const Gen& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q; } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< Op > max@0: { max@0: public: max@0: max@0: typedef typename T1::elem_type elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const elem_type* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat Q; max@0: max@0: inline explicit Proxy(const Op& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< Glue > max@0: { max@0: public: max@0: max@0: typedef typename T1::elem_type elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const elem_type* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat Q; max@0: max@0: inline explicit Proxy(const Glue& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< subview > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef subview stored_type; max@0: typedef const subview& ea_type; max@0: max@0: static const bool prefer_at_accessor = true; max@0: static const bool has_subview = true; max@0: max@0: arma_aligned const subview& Q; max@0: max@0: inline explicit Proxy(const subview& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q; } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< subview_elem1 > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const eT* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat Q; max@0: max@0: inline explicit Proxy(const subview_elem1& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return 1; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< diagview > max@0: { max@0: public: max@0: max@0: typedef eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef diagview stored_type; max@0: typedef const diagview& ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = true; max@0: max@0: arma_aligned const diagview& Q; max@0: max@0: inline explicit Proxy(const diagview& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return 1; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q; } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } max@0: }; max@0: max@0: max@0: max@0: max@0: template max@0: class Proxy< eOp > max@0: { max@0: public: max@0: max@0: typedef typename T1::elem_type elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef eOp stored_type; max@0: typedef const eOp& ea_type; max@0: max@0: static const bool prefer_at_accessor = eOp::prefer_at_accessor; max@0: static const bool has_subview = eOp::has_subview; max@0: max@0: arma_aligned const eOp& Q; max@0: max@0: inline explicit Proxy(const eOp& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.get_n_rows(); } max@0: arma_inline uword get_n_cols() const { return Q.get_n_cols(); } max@0: arma_inline uword get_n_elem() const { return Q.get_n_elem(); } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q; } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return Q.P.is_alias(X); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< eGlue > max@0: { max@0: public: max@0: max@0: typedef typename T1::elem_type elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef eGlue stored_type; max@0: typedef const eGlue& ea_type; max@0: max@0: static const bool prefer_at_accessor = eGlue::prefer_at_accessor; max@0: static const bool has_subview = eGlue::has_subview; max@0: max@0: arma_aligned const eGlue& Q; max@0: max@0: inline explicit Proxy(const eGlue& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.get_n_rows(); } max@0: arma_inline uword get_n_cols() const { return Q.get_n_cols(); } max@0: arma_inline uword get_n_elem() const { return Q.get_n_elem(); } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q; } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< mtOp > max@0: { max@0: public: max@0: max@0: typedef out_eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const elem_type* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat Q; max@0: max@0: inline explicit Proxy(const mtOp& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: template max@0: class Proxy< mtGlue > max@0: { max@0: public: max@0: max@0: typedef out_eT elem_type; max@0: typedef typename get_pod_type::result pod_type; max@0: typedef Mat stored_type; max@0: typedef const elem_type* ea_type; max@0: max@0: static const bool prefer_at_accessor = false; max@0: static const bool has_subview = false; max@0: max@0: arma_aligned const Mat Q; max@0: max@0: inline explicit Proxy(const mtGlue& A) max@0: : Q(A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: arma_inline uword get_n_rows() const { return Q.n_rows; } max@0: arma_inline uword get_n_cols() const { return Q.n_cols; } max@0: arma_inline uword get_n_elem() const { return Q.n_elem; } max@0: max@0: arma_inline elem_type operator[] (const uword i) const { return Q[i]; } max@0: arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } max@0: max@0: arma_inline ea_type get_ea() const { return Q.memptr(); } max@0: max@0: template max@0: arma_inline bool is_alias(const Mat&) const { return false; } max@0: }; max@0: max@0: max@0: max@0: //! @}