Cube_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 Cube
00017 //! @{
00018 
00019 //! Dense cube class
00020 
00021 template<typename eT>
00022 class Cube : public BaseCube< eT, Cube<eT> >
00023   {
00024   public:
00025   
00026   typedef eT elem_type;  //!< the type of elements stored in the cube
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 each slice (read-only)
00034   const u32  n_cols;       //!< number of columns in each slice (read-only)
00035   const u32  n_elem_slice; //!< number of elements in each slice (read-only)
00036   const u32  n_slices;     //!< number of slices in the cube (read-only)
00037   const u32  n_elem;       //!< number of elements in the cube (read-only)
00038   const bool use_aux_mem;  //!< true if externally managed memory is being used (read-only)
00039   
00040   arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array containing pointers to Mat instances (one for each slice)
00041   arma_aligned const eT*       const mem;      //!< pointer to the memory used by the cube (memory is read-only)
00042   
00043   protected:
00044   arma_aligned Mat<eT>* mat_ptrs_local[ 16 ];
00045   arma_aligned eT            mem_local[ 64 ];
00046   
00047   
00048   public:
00049   
00050   inline ~Cube();
00051   inline  Cube();
00052   
00053   inline Cube(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00054   
00055   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);
00056   inline Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const u32 aux_n_slices);
00057   
00058   arma_inline const Cube&  operator=(const eT val);
00059   arma_inline const Cube& operator+=(const eT val);
00060   arma_inline const Cube& operator-=(const eT val);
00061   arma_inline const Cube& operator*=(const eT val);
00062   arma_inline const Cube& operator/=(const eT val);
00063   
00064   inline                   Cube(const Cube& m);
00065   inline const Cube&  operator=(const Cube& m);
00066   inline const Cube& operator+=(const Cube& m);
00067   inline const Cube& operator-=(const Cube& m);
00068   inline const Cube& operator%=(const Cube& m);
00069   inline const Cube& operator/=(const Cube& m);
00070 
00071   template<typename T1, typename T2>
00072   inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
00073 
00074   inline                   Cube(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   inline const Cube& operator-=(const subview_cube<eT>& X);
00078   inline const Cube& operator%=(const subview_cube<eT>& X);
00079   inline const Cube& operator/=(const subview_cube<eT>& X);
00080 
00081   arma_inline       Mat<eT>& slice(const u32 in_slice);
00082   arma_inline const Mat<eT>& slice(const u32 in_slice) const;
00083   
00084   arma_inline       subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2);
00085   arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2) const;
00086   
00087   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);
00088   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;
00089 
00090 
00091   template<typename T1, typename op_cube_type> inline                   Cube(const OpCube<T1, op_cube_type>& X);
00092   template<typename T1, typename op_cube_type> inline const Cube&  operator=(const OpCube<T1, op_cube_type>& X);
00093   template<typename T1, typename op_cube_type> inline const Cube& operator+=(const OpCube<T1, op_cube_type>& X);
00094   template<typename T1, typename op_cube_type> inline const Cube& operator-=(const OpCube<T1, op_cube_type>& X);
00095   template<typename T1, typename op_cube_type> inline const Cube& operator%=(const OpCube<T1, op_cube_type>& X);
00096   template<typename T1, typename op_cube_type> inline const Cube& operator/=(const OpCube<T1, op_cube_type>& X);
00097   
00098   
00099   template<typename T1, typename T2, typename glue_cube_type> inline                   Cube(const GlueCube<T1, T2, glue_cube_type>& X);
00100   template<typename T1, typename T2, typename glue_cube_type> inline const Cube&  operator=(const GlueCube<T1, T2, glue_cube_type>& X);
00101   template<typename T1, typename T2, typename glue_cube_type> inline const Cube& operator+=(const GlueCube<T1, T2, glue_cube_type>& X);
00102   template<typename T1, typename T2, typename glue_cube_type> inline const Cube& operator-=(const GlueCube<T1, T2, glue_cube_type>& X);
00103   template<typename T1, typename T2, typename glue_cube_type> inline const Cube& operator%=(const GlueCube<T1, T2, glue_cube_type>& X);
00104   template<typename T1, typename T2, typename glue_cube_type> inline const Cube& operator/=(const GlueCube<T1, T2, glue_cube_type>& X);
00105   
00106   
00107   arma_inline eT& operator[] (const u32 i);
00108   arma_inline eT  operator[] (const u32 i) const;
00109   arma_inline eT& operator() (const u32 i);
00110   arma_inline eT  operator() (const u32 i) const;
00111   
00112   arma_inline eT& at         (const u32 in_row, const u32 in_col, const u32 in_slice);
00113   arma_inline eT  at         (const u32 in_row, const u32 in_col, const u32 in_slice) const;
00114   arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32 in_slice);
00115   arma_inline eT  operator() (const u32 in_row, const u32 in_col, const u32 in_slice) const;
00116 
00117   arma_inline const Cube& operator++();
00118   arma_inline void        operator++(int);
00119 
00120   arma_inline const Cube& operator--();
00121   arma_inline void        operator--(int);
00122 
00123   arma_inline bool is_finite() const;
00124 
00125   arma_inline       eT* memptr();
00126   arma_inline const eT* memptr() const;
00127 
00128   arma_inline       eT* slice_memptr(const u32 slice);
00129   arma_inline const eT* slice_memptr(const u32 slice) const;
00130 
00131   arma_inline       eT* slice_colptr(const u32 in_slice, const u32 in_col);
00132   arma_inline const eT* slice_colptr(const u32 in_slice, const u32 in_col) const;
00133   
00134   inline void print(const std::string extra_text = "") const;
00135   inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
00136 
00137   inline void raw_print(const std::string extra_text = "") const;
00138   inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const;
00139 
00140   inline void  set_size(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00141   
00142   template<typename eT2> inline void copy_size(const Cube<eT2>& m);
00143 
00144   inline void fill(const eT val);
00145   
00146   inline void zeros();
00147   inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00148   
00149   inline void ones();
00150   inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00151   
00152   inline void reset();
00153   
00154   inline void save(const std::string name, const file_type type = arma_binary) const;
00155   inline void load(const std::string name, const file_type type = auto_detect);
00156   
00157   
00158   protected:
00159   
00160   inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slices);
00161   inline void init(const Cube& x);
00162   
00163   inline void delete_mat();
00164   inline void create_mat();
00165   };
00166 
00167 
00168 
00169 class Cube_aux
00170   {
00171   public:
00172 
00173   template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
00174   template<typename T>  arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
00175   
00176   template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x);
00177   template<typename T>  arma_inline static void postfix_pp(Cube< std::complex<T> >& x);
00178   
00179   template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
00180   template<typename T>  arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
00181   
00182   template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
00183   template<typename T>  arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
00184   };
00185 
00186 
00187 
00188 //! @}