Mat_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 Mat
00017 //! @{
00018 
00019 //! Dense matrix class
00020 
00021 template<typename eT>
00022 class Mat : public Base< eT, Mat<eT> >
00023   {
00024   public:
00025   
00026   typedef eT elem_type;  //!< the type of elements stored in the matrix
00027   
00028   typedef typename get_pod_type<elem_type>::pod_type pod_type;
00029   //!< if eT is std::complex, pod_type is the underlying type used by std::complex.
00030   //!< otherwise pod_type is the same as elem_type
00031   
00032   
00033   const u32  n_rows;      //!< number of rows in the matrix (read-only)
00034   const u32  n_cols;      //!< number of columns in the matrix (read-only)
00035   const u32  n_elem;      //!< number of elements in the matrix (read-only)
00036   const bool use_aux_mem; //!< true if externally managed memory is being used (read-only)
00037   
00038   arma_aligned const eT* const mem;  //!< pointer to the memory used by the matrix (memory is read-only)
00039   
00040   protected:
00041   arma_aligned eT mem_local[ 16 ];
00042   
00043   
00044   public:
00045   
00046   inline ~Mat();
00047   inline  Mat();
00048   
00049   inline Mat(const u32 in_rows, const u32 in_cols);
00050   
00051   inline                  Mat(const char*        text);
00052   inline const Mat& operator=(const char*        text);
00053   inline                  Mat(const std::string& text);
00054   inline const Mat& operator=(const std::string& text);
00055   
00056   inline Mat(      eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const bool copy_aux_mem = true);
00057   inline Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols);
00058   
00059   arma_inline const Mat&  operator=(const eT val);
00060   arma_inline const Mat& operator+=(const eT val);
00061   arma_inline const Mat& operator-=(const eT val);
00062   arma_inline const Mat& operator*=(const eT val);
00063   arma_inline const Mat& operator/=(const eT val);
00064   
00065   inline                   Mat(const Mat& m);
00066   inline const Mat&  operator=(const Mat& m);
00067   inline const Mat& operator+=(const Mat& m);
00068   inline const Mat& operator-=(const Mat& m);
00069   inline const Mat& operator*=(const Mat& m);
00070   inline const Mat& operator%=(const Mat& m);
00071   inline const Mat& operator/=(const Mat& m);
00072 
00073   template<typename T1, typename T2>
00074   inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
00075 
00076   inline                   Mat(const subview<eT>& X);
00077   inline const Mat&  operator=(const subview<eT>& X);
00078   inline const Mat& operator+=(const subview<eT>& X);
00079   inline const Mat& operator-=(const subview<eT>& X);
00080   inline const Mat& operator*=(const subview<eT>& X);
00081   inline const Mat& operator%=(const subview<eT>& X);
00082   inline const Mat& operator/=(const subview<eT>& X);
00083 
00084   //inline explicit          Mat(const subview_cube<eT>& X);
00085   inline                   Mat(const subview_cube<eT>& X);
00086   inline const Mat&  operator=(const subview_cube<eT>& X);
00087   inline const Mat& operator+=(const subview_cube<eT>& X);
00088   inline const Mat& operator-=(const subview_cube<eT>& X);
00089   inline const Mat& operator*=(const subview_cube<eT>& X);
00090   inline const Mat& operator%=(const subview_cube<eT>& X);
00091   inline const Mat& operator/=(const subview_cube<eT>& X);
00092 
00093   
00094   //inline explicit          Mat(const diagview<eT>& X);
00095   inline                   Mat(const diagview<eT>& X);
00096   inline const Mat&  operator=(const diagview<eT>& X);
00097   
00098   arma_inline       subview_row<eT> row(const u32 row_num);
00099   arma_inline const subview_row<eT> row(const u32 row_num) const;
00100   
00101   arma_inline       subview_col<eT> col(const u32 col_num);
00102   arma_inline const subview_col<eT> col(const u32 col_num) const;
00103   
00104   arma_inline       subview<eT> rows(const u32 in_row1, const u32 in_row2);
00105   arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2) const;
00106   
00107   arma_inline       subview<eT> cols(const u32 in_col1, const u32 in_col2);
00108   arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2) const;
00109   
00110   arma_inline       subview<eT> submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2);
00111   arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2) const;
00112 
00113   arma_inline       diagview<eT> diag(const s32 in_id = 0);
00114   arma_inline const diagview<eT> diag(const s32 in_id = 0) const;
00115     
00116   inline void swap_rows(const u32 in_row1, const u32 in_row2);
00117   inline void swap_cols(const u32 in_col1, const u32 in_col2);
00118   
00119   template<typename T1, typename op_type> inline                   Mat(const Op<T1, op_type>& X);
00120   template<typename T1, typename op_type> inline const Mat&  operator=(const Op<T1, op_type>& X);
00121   template<typename T1, typename op_type> inline const Mat& operator+=(const Op<T1, op_type>& X);
00122   template<typename T1, typename op_type> inline const Mat& operator-=(const Op<T1, op_type>& X);
00123   template<typename T1, typename op_type> inline const Mat& operator*=(const Op<T1, op_type>& X);
00124   template<typename T1, typename op_type> inline const Mat& operator%=(const Op<T1, op_type>& X);
00125   template<typename T1, typename op_type> inline const Mat& operator/=(const Op<T1, op_type>& X);
00126   
00127   template<typename T1, typename T2, typename glue_type> inline                   Mat(const Glue<T1, T2, glue_type>& X);
00128   template<typename T1, typename T2, typename glue_type> inline const Mat&  operator=(const Glue<T1, T2, glue_type>& X);
00129   template<typename T1, typename T2, typename glue_type> inline const Mat& operator+=(const Glue<T1, T2, glue_type>& X);
00130   template<typename T1, typename T2, typename glue_type> inline const Mat& operator-=(const Glue<T1, T2, glue_type>& X);
00131   template<typename T1, typename T2, typename glue_type> inline const Mat& operator*=(const Glue<T1, T2, glue_type>& X);
00132   template<typename T1, typename T2, typename glue_type> inline const Mat& operator%=(const Glue<T1, T2, glue_type>& X);
00133   template<typename T1, typename T2, typename glue_type> inline const Mat& operator/=(const Glue<T1, T2, glue_type>& X);
00134   
00135   
00136   arma_inline eT& operator[] (const u32 i);
00137   arma_inline eT  operator[] (const u32 i) const;
00138   arma_inline eT& operator() (const u32 i);
00139   arma_inline eT  operator() (const u32 i) const;
00140   
00141   arma_inline eT& at         (const u32 in_row, const u32 in_col);
00142   arma_inline eT  at         (const u32 in_row, const u32 in_col) const;
00143   arma_inline eT& operator() (const u32 in_row, const u32 in_col);
00144   arma_inline eT  operator() (const u32 in_row, const u32 in_col) const;
00145   
00146   arma_inline const Mat& operator++();
00147   arma_inline void       operator++(int);
00148   
00149   arma_inline const Mat& operator--();
00150   arma_inline void       operator--(int);
00151   
00152   arma_inline bool is_vec() const;
00153   arma_inline bool is_square() const;
00154   arma_inline bool is_finite() const;
00155   
00156   arma_inline       eT* colptr(const u32 in_col);
00157   arma_inline const eT* colptr(const u32 in_col) const;
00158   
00159   arma_inline       eT* memptr();
00160   arma_inline const eT* memptr() const;
00161   
00162   inline void print(const std::string extra_text = "") const;
00163   inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
00164 
00165   inline void print_trans(const std::string extra_text = "") const;
00166   inline void print_trans(std::ostream& user_stream, const std::string extra_text = "") const;
00167 
00168   inline void raw_print(const std::string extra_text = "") const;
00169   inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
00170 
00171   inline void raw_print_trans(const std::string extra_text = "") const;
00172   inline void raw_print_trans(std::ostream& user_stream, const std::string extra_text = "") const;
00173 
00174   template<typename eT2>
00175   inline void copy_size(const Mat<eT2>& m);
00176   
00177   inline void  set_size(const u32 in_rows, const u32 in_cols);
00178   
00179   inline void fill(const eT val);
00180   
00181   inline void zeros();
00182   inline void zeros(const u32 in_rows, const u32 in_cols);
00183   
00184   inline void ones();
00185   inline void ones(const u32 in_rows, const u32 in_cols);
00186   
00187   inline void reset();
00188   
00189   inline void save(const std::string name, const file_type type = arma_binary) const;
00190   inline void load(const std::string name, const file_type type = auto_detect);
00191   
00192   
00193   protected: 
00194   
00195   inline void init(const u32 in_rows, const u32 in_cols);
00196   inline void init(const std::string& text);
00197   inline void init(const Mat& x);
00198   
00199   inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols);
00200   
00201   friend class Cube<eT>;
00202   };
00203 
00204 
00205 
00206 class Mat_aux
00207   {
00208   public:
00209 
00210   template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x);
00211   template<typename T>  arma_inline static void prefix_pp(Mat< std::complex<T> >& x);
00212   
00213   template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x);
00214   template<typename T>  arma_inline static void postfix_pp(Mat< std::complex<T> >& x);
00215   
00216   template<typename eT> arma_inline static void prefix_mm(Mat<eT>& x);
00217   template<typename T>  arma_inline static void prefix_mm(Mat< std::complex<T> >& x);
00218   
00219   template<typename eT> arma_inline static void postfix_mm(Mat<eT>& x);
00220   template<typename T>  arma_inline static void postfix_mm(Mat< std::complex<T> >& x);
00221   };
00222 
00223 
00224 
00225 //! @}