Cube_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 Cube
00018 //! @{
00019 
00020 //! Dense cube class
00021 
00022 template<typename eT>
00023 class Cube : public BaseCube< eT, Cube<eT> >
00024   {
00025   public:
00026   
00027   typedef eT                                elem_type; //!< the type of elements stored in the cube
00028   typedef typename get_pod_type<eT>::result pod_type;  //!< if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std::complex
00029   
00030   const u32  n_rows;       //!< number of rows in each slice (read-only)
00031   const u32  n_cols;       //!< number of columns in each slice (read-only)
00032   const u32  n_elem_slice; //!< number of elements in each slice (read-only)
00033   const u32  n_slices;     //!< number of slices in the cube (read-only)
00034   const u32  n_elem;       //!< number of elements in the cube (read-only)
00035   const bool use_aux_mem;  //!< true if externally managed memory is being used (read-only)
00036   
00037   arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array containing pointers to Mat instances (one for each slice)
00038   arma_aligned const eT*       const mem;      //!< pointer to the memory used by the cube (memory is read-only)
00039   
00040   protected:
00041   arma_aligned Mat<eT>* mat_ptrs_local[ 16 ];
00042   arma_aligned eT            mem_local[ 64 ];
00043   
00044   
00045   public:
00046   
00047   inline ~Cube();
00048   inline  Cube();
00049   
00050   inline Cube(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00051   
00052   inline Cube(      eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const u32 aux_n_slices, const bool copy_aux_mem = true);
00053   inline Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const u32 aux_n_slices);
00054   
00055   arma_inline const Cube&  operator=(const eT val);
00056   arma_inline const Cube& operator+=(const eT val);
00057   arma_inline const Cube& operator-=(const eT val);
00058   arma_inline const Cube& operator*=(const eT val);
00059   arma_inline const Cube& operator/=(const eT val);
00060   
00061   inline                   Cube(const Cube& m);
00062   inline const Cube&  operator=(const Cube& m);
00063   inline const Cube& operator+=(const Cube& m);
00064   inline const Cube& operator-=(const Cube& m);
00065   inline const Cube& operator%=(const Cube& m);
00066   inline const Cube& operator/=(const Cube& m);
00067 
00068   template<typename T1, typename T2>
00069   inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
00070 
00071   inline                   Cube(const subview_cube<eT>& X);
00072   inline const Cube&  operator=(const subview_cube<eT>& X);
00073   inline const Cube& operator+=(const subview_cube<eT>& X);
00074   inline const Cube& operator-=(const subview_cube<eT>& X);
00075   inline const Cube& operator%=(const subview_cube<eT>& X);
00076   inline const Cube& operator/=(const subview_cube<eT>& X);
00077 
00078   arma_inline       Mat<eT>& slice(const u32 in_slice);
00079   arma_inline const Mat<eT>& slice(const u32 in_slice) const;
00080   
00081   arma_inline       subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2);
00082   arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2) const;
00083   
00084   arma_inline       subview_cube<eT> subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u32 in_slice2);
00085   arma_inline const subview_cube<eT> subcube(const u32 in_row1, const u32 in_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u32 in_slice2) const;
00086 
00087 
00088   template<typename T1, typename op_type> inline                   Cube(const OpCube<T1, op_type>& X);
00089   template<typename T1, typename op_type> inline const Cube&  operator=(const OpCube<T1, op_type>& X);
00090   template<typename T1, typename op_type> inline const Cube& operator+=(const OpCube<T1, op_type>& X);
00091   template<typename T1, typename op_type> inline const Cube& operator-=(const OpCube<T1, op_type>& X);
00092   template<typename T1, typename op_type> inline const Cube& operator%=(const OpCube<T1, op_type>& X);
00093   template<typename T1, typename op_type> inline const Cube& operator/=(const OpCube<T1, op_type>& X);
00094   
00095   template<typename T1, typename eop_type> inline                   Cube(const eOpCube<T1, eop_type>& X);
00096   template<typename T1, typename eop_type> inline const Cube&  operator=(const eOpCube<T1, eop_type>& X);
00097   template<typename T1, typename eop_type> inline const Cube& operator+=(const eOpCube<T1, eop_type>& X);
00098   template<typename T1, typename eop_type> inline const Cube& operator-=(const eOpCube<T1, eop_type>& X);
00099   template<typename T1, typename eop_type> inline const Cube& operator%=(const eOpCube<T1, eop_type>& X);
00100   template<typename T1, typename eop_type> inline const Cube& operator/=(const eOpCube<T1, eop_type>& X);
00101   
00102   template<typename T1, typename T2, typename glue_type> inline                   Cube(const GlueCube<T1, T2, glue_type>& X);
00103   template<typename T1, typename T2, typename glue_type> inline const Cube&  operator=(const GlueCube<T1, T2, glue_type>& X);
00104   template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const GlueCube<T1, T2, glue_type>& X);
00105   template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const GlueCube<T1, T2, glue_type>& X);
00106   template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const GlueCube<T1, T2, glue_type>& X);
00107   template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const GlueCube<T1, T2, glue_type>& X);
00108   
00109   template<typename T1, typename T2, typename eglue_type> inline                   Cube(const eGlueCube<T1, T2, eglue_type>& X);
00110   template<typename T1, typename T2, typename eglue_type> inline const Cube&  operator=(const eGlueCube<T1, T2, eglue_type>& X);
00111   template<typename T1, typename T2, typename eglue_type> inline const Cube& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
00112   template<typename T1, typename T2, typename eglue_type> inline const Cube& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
00113   template<typename T1, typename T2, typename eglue_type> inline const Cube& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
00114   template<typename T1, typename T2, typename eglue_type> inline const Cube& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
00115   
00116   arma_inline eT& operator[] (const u32 i);
00117   arma_inline eT  operator[] (const u32 i) const;
00118   arma_inline eT& operator() (const u32 i);
00119   arma_inline eT  operator() (const u32 i) const;
00120   
00121   arma_inline eT& at         (const u32 in_row, const u32 in_col, const u32 in_slice);
00122   arma_inline eT  at         (const u32 in_row, const u32 in_col, const u32 in_slice) const;
00123   arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32 in_slice);
00124   arma_inline eT  operator() (const u32 in_row, const u32 in_col, const u32 in_slice) const;
00125 
00126   arma_inline const Cube& operator++();
00127   arma_inline void        operator++(int);
00128 
00129   arma_inline const Cube& operator--();
00130   arma_inline void        operator--(int);
00131 
00132   arma_inline bool is_finite() const;
00133 
00134   arma_inline       eT* memptr();
00135   arma_inline const eT* memptr() const;
00136 
00137   arma_inline       eT* slice_memptr(const u32 slice);
00138   arma_inline const eT* slice_memptr(const u32 slice) const;
00139 
00140   arma_inline       eT* slice_colptr(const u32 in_slice, const u32 in_col);
00141   arma_inline const eT* slice_colptr(const u32 in_slice, const u32 in_col) const;
00142   
00143   inline void print(const std::string extra_text = "") const;
00144   inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
00145 
00146   inline void raw_print(const std::string extra_text = "") const;
00147   inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
00148 
00149   inline void  set_size(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00150   
00151   template<typename eT2> inline void copy_size(const Cube<eT2>& m);
00152 
00153   inline void fill(const eT val);
00154   
00155   inline void zeros();
00156   inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00157   
00158   inline void ones();
00159   inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00160   
00161   inline void reset();
00162   
00163   
00164   inline bool save(const std::string   name, const file_type type = arma_binary, const bool print_status = true) const;
00165   inline bool save(      std::ostream& os,   const file_type type = arma_binary, const bool print_status = true) const;
00166   
00167   inline bool load(const std::string   name, const file_type type = auto_detect, const bool print_status = true);
00168   inline bool load(      std::istream& is,   const file_type type = auto_detect, const bool print_status = true);
00169   
00170   inline bool quiet_save(const std::string   name, const file_type type = arma_binary) const;
00171   inline bool quiet_save(      std::ostream& os,   const file_type type = arma_binary) const;
00172   
00173   inline bool quiet_load(const std::string   name, const file_type type = auto_detect);
00174   inline bool quiet_load(      std::istream& is,   const file_type type = auto_detect);
00175   
00176   
00177   // iterators
00178   
00179   typedef       eT*       iterator;
00180   typedef const eT* const_iterator;
00181   
00182   typedef       eT*       slice_iterator;
00183   typedef const eT* const_slice_iterator;
00184   
00185   inline       iterator begin();
00186   inline const_iterator begin() const;
00187   
00188   inline       iterator end();
00189   inline const_iterator end()   const;
00190   
00191   inline       slice_iterator begin_slice(const u32 slice_num);
00192   inline const_slice_iterator begin_slice(const u32 slice_num) const;
00193   
00194   inline       slice_iterator end_slice(const u32 slice_num);
00195   inline const_slice_iterator end_slice(const u32 slice_num)   const;
00196   
00197   
00198   protected:
00199   
00200   inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00201   inline void init(const Cube& x);
00202   
00203   inline void delete_mat();
00204   inline void create_mat();
00205   };
00206 
00207 
00208 
00209 class Cube_aux
00210   {
00211   public:
00212 
00213   template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
00214   template<typename T>  arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
00215   
00216   template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x);
00217   template<typename T>  arma_inline static void postfix_pp(Cube< std::complex<T> >& x);
00218   
00219   template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
00220   template<typename T>  arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
00221   
00222   template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
00223   template<typename T>  arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
00224   };
00225 
00226 
00227 
00228 //! @}