// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // 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 // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders //! \addtogroup subview //! @{ //! Class for storing data required to construct or apply operations to a submatrix //! (i.e. where the submatrix starts and ends as well as a reference/pointer to the original matrix), template class subview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Mat& m; static const bool is_row = false; static const bool is_col = false; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; protected: 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); public: inline ~subview(); template inline void inplace_op(const eT val ); template inline void inplace_op(const Base& x, const char* identifier); template inline void inplace_op(const subview& x, const char* identifier); // deliberately returning void inline void operator= (const eT val); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); inline void operator= (const subview& x); inline void operator+= (const subview& x); inline void operator-= (const subview& x); inline void operator%= (const subview& x); inline void operator/= (const subview& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); template inline void operator= (const SpBase& x); template inline void operator+= (const SpBase& x); template inline void operator-= (const SpBase& x); template inline void operator%= (const SpBase& x); template inline void operator/= (const SpBase& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); inline static void extract(Mat& out, const subview& in); inline static void plus_inplace(Mat& out, const subview& in); inline static void minus_inplace(Mat& out, const subview& in); inline static void schur_inplace(Mat& out, const subview& in); inline static void div_inplace(Mat& out, const subview& in); template inline void for_each(functor F); template inline void for_each(functor F) const; template inline void transform(functor F); template inline void imbue(functor F); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void eye(); inline void randu(); inline void randn(); inline eT at_alt (const uword ii) const; inline eT& operator[](const uword ii); inline eT operator[](const uword ii) const; inline eT& operator()(const uword ii); inline eT operator()(const uword ii) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline bool check_overlap(const subview& x) const; inline arma_warn_unused bool is_vec() const; inline arma_warn_unused bool is_finite() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; inline subview_row row(const uword row_num); inline const subview_row row(const uword row_num) const; inline subview_row operator()(const uword row_num, const span& col_span); inline const subview_row operator()(const uword row_num, const span& col_span) const; inline subview_col col(const uword col_num); inline const subview_col col(const uword col_num) const; inline subview_col operator()(const span& row_span, const uword col_num); inline const subview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; inline subview rows(const uword in_row1, const uword in_row2); inline const subview rows(const uword in_row1, const uword in_row2) const; inline subview cols(const uword in_col1, const uword in_col2); inline const subview cols(const uword in_col1, const uword in_col2) const; inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline subview submat (const span& row_span, const span& col_span); inline const subview submat (const span& row_span, const span& col_span) const; inline subview operator()(const span& row_span, const span& col_span); inline const subview operator()(const span& row_span, const span& col_span) const; inline subview_each1< subview, 0 > each_col(); inline subview_each1< subview, 1 > each_row(); template inline subview_each2< subview, 0, T1 > each_col(const Base& indices); template inline subview_each2< subview, 1, T1 > each_row(const Base& indices); #if defined(ARMA_USE_CXX11) inline void each_col(const std::function< void( Col&) >& F); inline void each_col(const std::function< void(const Col&) >& F) const; inline void each_row(const std::function< void( Row&) >& F); inline void each_row(const std::function< void(const Row&) >& F) const; #endif inline diagview diag(const sword in_id = 0); inline const diagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); private: friend class Mat; subview(); }; template class subview_col : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; const eT* colmem; inline void operator= (const subview& x); inline void operator= (const subview_col& x); inline void operator= (const eT val); template inline void operator= (const Base& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); arma_inline eT at_alt (const uword i) const; arma_inline eT& operator[](const uword i); arma_inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline subview_col rows(const uword in_row1, const uword in_row2); inline const subview_col rows(const uword in_row1, const uword in_row2) const; inline subview_col subvec(const uword in_row1, const uword in_row2); inline const subview_col subvec(const uword in_row1, const uword in_row2) const; inline subview_col head(const uword N); inline const subview_col head(const uword N) const; inline subview_col tail(const uword N); inline const subview_col tail(const uword N) const; protected: inline subview_col(const Mat& in_m, const uword in_col); inline subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); private: friend class Mat; friend class Col; friend class subview; subview_col(); }; template class subview_row : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = true; static const bool is_col = false; inline void operator= (const subview& x); inline void operator= (const subview_row& x); inline void operator= (const eT val); template inline void operator= (const Base& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline eT at_alt (const uword i) const; inline eT& operator[](const uword i); inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; inline subview_row cols(const uword in_col1, const uword in_col2); inline const subview_row cols(const uword in_col1, const uword in_col2) const; inline subview_row subvec(const uword in_col1, const uword in_col2); inline const subview_row subvec(const uword in_col1, const uword in_col2) const; inline subview_row head(const uword N); inline const subview_row head(const uword N) const; inline subview_row tail(const uword N); inline const subview_row tail(const uword N) const; protected: inline subview_row(const Mat& in_m, const uword in_row); inline subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); private: friend class Mat; friend class Row; friend class subview; subview_row(); }; template class subview_row_strans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_strans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; template class subview_row_htrans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_htrans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; //! @}