subview_proto.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup subview
00018 //! @{
00019 
00020 
00021 //! Class for storing data required to construct or apply operations to a submatrix
00022 //! (i.e. where the submatrix starts and ends as well as a reference/pointer to the original matrix),
00023 template<typename eT>
00024 class subview : public Base<eT, subview<eT> >
00025   {
00026   public:    arma_aligned const Mat<eT>& m;
00027   protected: arma_aligned       Mat<eT>* m_ptr;
00028   
00029   public:
00030   
00031   typedef eT                                       elem_type;
00032   typedef typename get_pod_type<elem_type>::result pod_type;
00033 
00034   const u32 aux_row1;
00035   const u32 aux_col1;
00036   
00037   const u32 aux_row2;
00038   const u32 aux_col2;
00039   
00040   const u32 n_rows;
00041   const u32 n_cols;
00042   const u32 n_elem;
00043   
00044   
00045   protected:
00046   
00047   arma_inline subview(const Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2,  const u32 in_col2);
00048   arma_inline subview(      Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2,  const u32 in_col2);
00049   
00050   
00051   public:
00052   
00053   inline ~subview();
00054   
00055   inline void operator+= (const eT val);
00056   inline void operator-= (const eT val);
00057   inline void operator*= (const eT val);
00058   inline void operator/= (const eT val);
00059   
00060   template<typename T1> inline void operator_equ_mat  (const Base<eT,T1>& x);
00061   template<typename T1> inline void operator_equ_proxy(const Base<eT,T1>& x);
00062   
00063   // deliberately returning void
00064   template<typename T1> inline void operator=  (const Base<eT,T1>& x);
00065   template<typename T1> inline void operator+= (const Base<eT,T1>& x);
00066   template<typename T1> inline void operator-= (const Base<eT,T1>& x);
00067   template<typename T1> inline void operator%= (const Base<eT,T1>& x);
00068   template<typename T1> inline void operator/= (const Base<eT,T1>& x);
00069   
00070   inline void operator=  (const subview& x);
00071   inline void operator+= (const subview& x);
00072   inline void operator-= (const subview& x);
00073   inline void operator%= (const subview& x);
00074   inline void operator/= (const subview& x);
00075   
00076   inline static void extract(Mat<eT>& out, const subview& in);
00077   
00078   inline static void  plus_inplace(Mat<eT>& out, const subview& in);
00079   inline static void minus_inplace(Mat<eT>& out, const subview& in);
00080   inline static void schur_inplace(Mat<eT>& out, const subview& in);
00081   inline static void   div_inplace(Mat<eT>& out, const subview& in);
00082   
00083   inline void fill(const eT val);
00084   inline void zeros();
00085   
00086   arma_inline eT& operator[](const u32 i);
00087   arma_inline eT  operator[](const u32 i) const;
00088   
00089   arma_inline eT& operator()(const u32 i);
00090   arma_inline eT  operator()(const u32 i) const;
00091   
00092   arma_inline eT& operator()(const u32 in_row, const u32 in_col);
00093   arma_inline eT  operator()(const u32 in_row, const u32 in_col) const;
00094   
00095   arma_inline eT&         at(const u32 in_row, const u32 in_col);
00096   arma_inline eT          at(const u32 in_row, const u32 in_col) const;
00097   
00098   arma_inline       eT* colptr(const u32 in_col);
00099   arma_inline const eT* colptr(const u32 in_col) const;
00100   
00101   inline bool check_overlap(const subview& x) const;
00102   
00103   inline bool is_vec() const;
00104   
00105   
00106   private:
00107   
00108   friend class Mat<eT>;
00109   subview();
00110   };
00111 
00112 
00113 
00114 template<typename eT>
00115 class subview_col : public subview<eT>
00116   {
00117   public:
00118   
00119   typedef eT                                       elem_type;
00120   typedef typename get_pod_type<elem_type>::result pod_type;
00121   
00122   inline void operator= (const subview<eT>& x);
00123   inline void operator= (const subview_col& x);
00124   
00125   template<typename T1>
00126   inline void operator= (const Base<eT,T1>& x);
00127   
00128   
00129   protected:
00130   
00131   arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col);
00132   arma_inline subview_col(      Mat<eT>& in_m, const u32 in_col);
00133   
00134   arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2);
00135   arma_inline subview_col(      Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2);
00136   
00137   
00138   private:
00139   
00140   friend class Mat<eT>;
00141   friend class Col<eT>;
00142   
00143   subview_col();
00144   };
00145 
00146 
00147 
00148 template<typename eT>
00149 class subview_row : public subview<eT>
00150   {
00151   public:
00152   
00153   typedef eT                                       elem_type;
00154   typedef typename get_pod_type<elem_type>::result pod_type;
00155   
00156   inline void operator= (const subview<eT>& x);
00157   inline void operator= (const subview_row& x);
00158   
00159   template<typename T1>
00160   inline void operator= (const Base<eT,T1>& x);
00161   
00162   
00163   protected:
00164   
00165   arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row);
00166   arma_inline subview_row(      Mat<eT>& in_m, const u32 in_row);
00167   
00168   arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2);
00169   arma_inline subview_row(      Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2);
00170   
00171   
00172   private:
00173   
00174   friend class Mat<eT>;
00175   friend class Row<eT>;
00176   
00177   subview_row();
00178   };
00179 
00180 
00181 
00182 //! @}