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   
00037   arma_aligned const eT* const mem;  //!< pointer to memory used by the matrix (memory is read-only)
00038   
00039   protected:
00040   arma_aligned eT mem_local[ 16 ];
00041   
00042   
00043   public:
00044   
00045   inline ~Mat();
00046   inline  Mat();
00047   
00048   inline            Mat(const u32 in_rows, const u32 in_cols);
00049   inline void  set_size(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(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols);
00057   
00058   arma_inline const Mat&  operator=(const eT val);
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   
00064   inline                   Mat(const Mat& m);
00065   inline const Mat&  operator=(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 
00072   template<typename T1, typename T2>
00073   inline explicit Mat(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
00074 
00075   inline                   Mat(const subview<eT>& X);
00076   inline const Mat&  operator=(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   
00083   //inline explicit          Mat(const diagview<eT>& X);
00084   inline                   Mat(const diagview<eT>& X);
00085   inline const Mat&  operator=(const diagview<eT>& X);
00086   
00087   arma_inline       subview_row<eT> row(const u32 row_num);
00088   arma_inline const subview_row<eT> row(const u32 row_num) const;
00089   
00090   arma_inline       subview_col<eT> col(const u32 col_num);
00091   arma_inline const subview_col<eT> col(const u32 col_num) const;
00092   
00093   arma_inline       subview<eT> rows(const u32 in_row1, const u32 in_row2);
00094   arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2) const;
00095   
00096   arma_inline       subview<eT> cols(const u32 in_col1, const u32 in_col2);
00097   arma_inline const subview<eT> cols(const u32 in_col1, const u32 in_col2) const;
00098   
00099   arma_inline       subview<eT> submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2);
00100   arma_inline const subview<eT> submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2) const;
00101 
00102   arma_inline       diagview<eT> diag(const s32 in_id = 0);
00103   arma_inline const diagview<eT> diag(const s32 in_id = 0) const;
00104     
00105   inline void swap_rows(const u32 in_row1, const u32 in_row2);
00106   inline void swap_cols(const u32 in_col1, const u32 in_col2);
00107   
00108   template<typename T1, typename op_type> inline                   Mat(const Op<T1, op_type>& X);
00109   template<typename T1, typename op_type> inline const Mat&  operator=(const Op<T1, op_type>& X);
00110   template<typename T1, typename op_type> inline const Mat& operator+=(const Op<T1, op_type>& X);
00111   template<typename T1, typename op_type> inline const Mat& operator-=(const Op<T1, op_type>& X);
00112   template<typename T1, typename op_type> inline const Mat& operator*=(const Op<T1, op_type>& X);
00113   template<typename T1, typename op_type> inline const Mat& operator%=(const Op<T1, op_type>& X);
00114   template<typename T1, typename op_type> inline const Mat& operator/=(const Op<T1, op_type>& X);
00115   
00116   template<typename T1, typename T2, typename glue_type> inline                   Mat(const Glue<T1, T2, glue_type>& X);
00117   template<typename T1, typename T2, typename glue_type> inline const Mat&  operator=(const Glue<T1, T2, glue_type>& X);
00118   template<typename T1, typename T2, typename glue_type> inline const Mat& operator+=(const Glue<T1, T2, glue_type>& X);
00119   template<typename T1, typename T2, typename glue_type> inline const Mat& operator-=(const Glue<T1, T2, glue_type>& X);
00120   template<typename T1, typename T2, typename glue_type> inline const Mat& operator*=(const Glue<T1, T2, glue_type>& X);
00121   template<typename T1, typename T2, typename glue_type> inline const Mat& operator%=(const Glue<T1, T2, glue_type>& X);
00122   template<typename T1, typename T2, typename glue_type> inline const Mat& operator/=(const Glue<T1, T2, glue_type>& X);
00123   
00124   
00125   arma_inline eT& operator[] (const u32 i);
00126   arma_inline eT  operator[] (const u32 i) const;
00127   arma_inline eT& operator() (const u32 i);
00128   arma_inline eT  operator() (const u32 i) const;
00129   
00130   arma_inline eT& at         (const u32 in_row, const u32 in_col);
00131   arma_inline eT  at         (const u32 in_row, const u32 in_col) const;
00132   arma_inline eT& operator() (const u32 in_row, const u32 in_col);
00133   arma_inline eT  operator() (const u32 in_row, const u32 in_col) const;
00134 
00135   arma_inline const Mat& operator++();
00136   arma_inline void       operator++(int);
00137 
00138   arma_inline const Mat& operator--();
00139   arma_inline void       operator--(int);
00140 
00141   arma_inline bool is_vec() const;
00142   arma_inline bool is_square() const;
00143   arma_inline bool is_finite() const;
00144 
00145   arma_inline       eT* colptr(const u32 in_col);
00146   arma_inline const eT* colptr(const u32 in_col) const;
00147   
00148   arma_inline       eT* memptr();
00149   arma_inline const eT* memptr() const;
00150 
00151   inline void print(const std::string extra_text = "") const;
00152   inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
00153 
00154   inline void raw_print(const std::string extra_text = "") const;
00155   inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
00156 
00157   inline void fill(const eT val);
00158   inline void zeros();
00159   inline void zeros(const u32 in_rows, const u32 in_cols);
00160   
00161   inline void reset();
00162   
00163   inline void save(const std::string name, const file_type type = arma_binary) const;
00164   inline void load(const std::string name, const file_type type = auto_detect);
00165   
00166   
00167   protected: 
00168   
00169   inline void init(const u32 in_rows, const u32 in_cols);
00170   inline void init(const std::string& text);
00171   inline void init(const Mat& x);
00172   };
00173 
00174 
00175 
00176 class Mat_aux
00177   {
00178   public:
00179 
00180   template<typename eT> arma_inline static void prefix_pp(Mat<eT>& x);
00181   template<typename T>  arma_inline static void prefix_pp(Mat< std::complex<T> >& x);
00182   
00183   template<typename eT> arma_inline static void postfix_pp(Mat<eT>& x);
00184   template<typename T>  arma_inline static void postfix_pp(Mat< std::complex<T> >& x);
00185   
00186   template<typename eT> arma_inline static void prefix_mm(Mat<eT>& x);
00187   template<typename T>  arma_inline static void prefix_mm(Mat< std::complex<T> >& x);
00188   
00189   template<typename eT> arma_inline static void postfix_mm(Mat<eT>& x);
00190   template<typename T>  arma_inline static void postfix_mm(Mat< std::complex<T> >& x);
00191   };
00192 
00193 
00194 
00195 //! @}