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   // deliberately returning void
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   template<typename T1> inline void operator/= (const Base<eT,T1>& x);
00066   
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   inline void operator/= (const subview& x);
00072   
00073   inline static void extract(Mat<eT>& out, const subview& in);
00074   
00075   inline static void  plus_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>::result 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>::result 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 //! @}