max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // Copyright (C) 2011 James Sanders 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 subview max@0: //! @{ max@0: max@0: max@0: //! Class for storing data required to construct or apply operations to a submatrix max@0: //! (i.e. where the submatrix starts and ends as well as a reference/pointer to the original matrix), max@0: template max@0: class subview : public Base > max@0: { max@0: public: arma_aligned const Mat& m; max@0: protected: arma_aligned Mat* m_ptr; 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: max@0: const uword aux_row1; max@0: const uword aux_col1; max@0: max@0: const uword n_rows; max@0: const uword n_cols; max@0: const uword n_elem; max@0: max@0: max@0: protected: max@0: max@0: arma_inline subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); max@0: arma_inline subview( Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); max@0: max@0: max@0: public: max@0: max@0: inline ~subview(); max@0: max@0: inline void operator+= (const eT val); max@0: inline void operator-= (const eT val); max@0: inline void operator*= (const eT val); max@0: inline void operator/= (const eT val); max@0: max@0: // deliberately returning void max@0: template inline void operator= (const Base& x); max@0: template inline void operator+= (const Base& x); max@0: template inline void operator-= (const Base& x); max@0: template inline void operator%= (const Base& x); max@0: template inline void operator/= (const Base& x); max@0: max@0: inline void operator= (const subview& x); max@0: inline void operator+= (const subview& x); max@0: inline void operator-= (const subview& x); max@0: inline void operator%= (const subview& x); max@0: inline void operator/= (const subview& x); max@0: max@0: inline static void extract(Mat& out, const subview& in); max@0: max@0: inline static void plus_inplace(Mat& out, const subview& in); max@0: inline static void minus_inplace(Mat& out, const subview& in); max@0: inline static void schur_inplace(Mat& out, const subview& in); max@0: inline static void div_inplace(Mat& out, const subview& in); max@0: max@0: inline void fill(const eT val); max@0: inline void zeros(); max@0: inline void ones(); max@0: inline void eye(); max@0: max@0: inline eT& operator[](const uword i); max@0: inline eT operator[](const uword i) const; max@0: max@0: inline eT& operator()(const uword i); max@0: inline eT operator()(const uword i) const; max@0: max@0: inline eT& operator()(const uword in_row, const uword in_col); max@0: inline eT operator()(const uword in_row, const uword in_col) const; max@0: max@0: inline eT& at(const uword in_row, const uword in_col); max@0: inline eT at(const uword in_row, const uword in_col) const; max@0: max@0: arma_inline eT* colptr(const uword in_col); max@0: arma_inline const eT* colptr(const uword in_col) const; max@0: max@0: inline bool check_overlap(const subview& x) const; max@0: max@0: inline bool is_vec() const; max@0: max@0: inline subview_row row(const uword row_num); max@0: inline const subview_row row(const uword row_num) const; max@0: max@0: inline subview_row operator()(const uword row_num, const span& col_span); max@0: inline const subview_row operator()(const uword row_num, const span& col_span) const; max@0: max@0: inline subview_col col(const uword col_num); max@0: inline const subview_col col(const uword col_num) const; max@0: max@0: inline subview_col operator()(const span& row_span, const uword col_num); max@0: inline const subview_col operator()(const span& row_span, const uword col_num) const; max@0: max@0: inline Col unsafe_col(const uword col_num); max@0: inline const Col unsafe_col(const uword col_num) const; max@0: max@0: inline subview rows(const uword in_row1, const uword in_row2); max@0: inline const subview rows(const uword in_row1, const uword in_row2) const; max@0: max@0: inline subview cols(const uword in_col1, const uword in_col2); max@0: inline const subview cols(const uword in_col1, const uword in_col2) const; max@0: max@0: inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); max@0: inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; max@0: max@0: inline subview submat (const span& row_span, const span& col_span); max@0: inline const subview submat (const span& row_span, const span& col_span) const; max@0: max@0: inline subview operator()(const span& row_span, const span& col_span); max@0: inline const subview operator()(const span& row_span, const span& col_span) const; max@0: max@0: inline diagview diag(const sword in_id = 0); max@0: inline const diagview diag(const sword in_id = 0) const; max@0: max@0: inline void swap_rows(const uword in_row1, const uword in_row2); max@0: inline void swap_cols(const uword in_col1, const uword in_col2); max@0: max@0: max@0: // // primitive forward iterator max@0: // class iter max@0: // { max@0: // public: max@0: // max@0: // inline iter(const subview& in_M); max@0: // max@0: // arma_inline eT operator* () const; max@0: // max@0: // inline void operator++(); max@0: // inline void operator++(int); max@0: // max@0: // max@0: // private: max@0: // max@0: // arma_aligned const eT* mem; max@0: // max@0: // arma_aligned uword n_rows; max@0: // max@0: // arma_aligned uword row_start; max@0: // arma_aligned uword row_end_p1; max@0: // max@0: // arma_aligned uword row; max@0: // arma_aligned uword col; max@0: // arma_aligned uword i; max@0: // }; max@0: max@0: max@0: private: max@0: max@0: friend class Mat; max@0: subview(); max@0: }; max@0: max@0: max@0: max@0: template max@0: class subview_col : public 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: max@0: inline void operator= (const subview& x); max@0: inline void operator= (const subview_col& x); max@0: max@0: template max@0: inline void operator= (const Base& x); max@0: max@0: inline subview_col rows(const uword in_row1, const uword in_row2); max@0: inline const subview_col rows(const uword in_row1, const uword in_row2) const; max@0: max@0: inline subview_col subvec(const uword in_row1, const uword in_row2); max@0: inline const subview_col subvec(const uword in_row1, const uword in_row2) const; max@0: max@0: max@0: protected: max@0: max@0: inline subview_col(const Mat& in_m, const uword in_col); max@0: inline subview_col( Mat& in_m, const uword in_col); max@0: max@0: inline subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); max@0: inline subview_col( Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); max@0: max@0: max@0: private: max@0: max@0: friend class Mat; max@0: friend class Col; max@0: friend class subview; max@0: max@0: subview_col(); max@0: }; max@0: max@0: max@0: max@0: template max@0: class subview_row : public 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: max@0: inline void operator= (const subview& x); max@0: inline void operator= (const subview_row& x); max@0: max@0: template max@0: inline void operator= (const Base& x); max@0: max@0: inline subview_row cols(const uword in_col1, const uword in_col2); max@0: inline const subview_row cols(const uword in_col1, const uword in_col2) const; max@0: max@0: inline subview_row subvec(const uword in_col1, const uword in_col2); max@0: inline const subview_row subvec(const uword in_col1, const uword in_col2) const; max@0: max@0: max@0: protected: max@0: max@0: inline subview_row(const Mat& in_m, const uword in_row); max@0: inline subview_row( Mat& in_m, const uword in_row); max@0: max@0: inline subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); max@0: inline subview_row( Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); max@0: max@0: max@0: private: max@0: max@0: friend class Mat; max@0: friend class Row; max@0: friend class subview; max@0: max@0: subview_row(); max@0: }; max@0: max@0: max@0: max@0: //! @}