subview_proto.hpp

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