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   inline bool is_vec() const;
00101   
00102   
00103   private:
00104   
00105   friend class Mat<eT>;
00106   subview();
00107   };
00108 
00109 
00110 
00111 template<typename eT>
00112 class subview_col : public subview<eT>
00113   {
00114   public:
00115   
00116   typedef eT elem_type;
00117   typedef typename get_pod_type<elem_type>::pod_type pod_type;
00118   
00119   inline void operator= (const subview<eT>& x);
00120   inline void operator= (const subview_col& x);
00121   
00122   template<typename T1>
00123   inline void operator= (const Base<eT,T1>& x);
00124   
00125   
00126   protected:
00127   
00128   arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col);
00129   arma_inline subview_col(      Mat<eT>& in_m, const u32 in_col);
00130   
00131   arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2);
00132   arma_inline subview_col(      Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2);
00133   
00134   
00135   private:
00136   
00137   friend class Mat<eT>;
00138   friend class Col<eT>;
00139   
00140   subview_col();
00141   };
00142 
00143 
00144 
00145 template<typename eT>
00146 class subview_row : public subview<eT>
00147   {
00148   public:
00149   
00150   typedef eT elem_type;
00151   typedef typename get_pod_type<elem_type>::pod_type pod_type;
00152   
00153   inline void operator= (const subview<eT>& x);
00154   inline void operator= (const subview_row& x);
00155   
00156   template<typename T1>
00157   inline void operator= (const Base<eT,T1>& x);
00158   
00159   
00160   protected:
00161   
00162   arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row);
00163   arma_inline subview_row(      Mat<eT>& in_m, const u32 in_row);
00164   
00165   arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2);
00166   arma_inline subview_row(      Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2);
00167   
00168   
00169   private:
00170   
00171   friend class Mat<eT>;
00172   friend class Row<eT>;
00173   
00174   subview_row();
00175   };
00176 
00177 
00178 
00179 //! @}