📄 tensor3.h
字号:
/* -*- c++ -*- *********************************************************************** * Scientific Library (GNU Public Licence) * * dense 3D tensor structure * * Author: Pierre Aubert paubert@mathinsa.insa-lyon.fr * * $Id: tensor3.h,v 1.3 1998/11/16 17:22:14 paubert Exp $ * * Suggestions: sl@mathinsa.insa-lyon.fr * Bugs: sl-bugs@mathinsa.insa-lyon.fr * * For more information, please see the sl++ Home Page: * http://wwwinfo.cern.ch/~ldeniau/sl.html * *********************************************************************** */#ifndef SL_MATRIX_STRUCTURES_TENSOR3_TENSOR3_H#define SL_MATRIX_STRUCTURES_TENSOR3_TENSOR3_H#ifndef SL_MATRIX_STRUCTURES_TENSOR3_H#error <sl/matrix/structures/tensor3/tensor3.h> must be included via <sl/matrix/structures/tensor3.h>#endif#ifdef HAVE_NAMESPACEnamespace sl {#endif /** @memo Structure for a dense 3D Array */ class Tensor3 : public MatrixStructure { /** @name Explanation dense rowmajor 3D array */ public: typedef Tensor3Iterator iterator_t; /** @name Constructor(s), Destructors(s) */ //@{ /// default constructor Tensor3 (); /// build a $n\times n\times n$ matrix explicit Tensor3 (Index const& n); /// build a $n\times p\times q$ matrix, with $p=q$. Tensor3 (Index const& n, Index const& p); /// build a $n\times p\times q$ matrix Tensor3 (Index const& n, Index const& p, Index const& q); // WARNING: Do NOT declare the copy constructor ! //@} /** @name operations on profil */ //@{ /// get size size_t size () const; /// resize void resize (size_t const n); /// resize void resize (size_t const n, size_t const p); /// resize void resize (size_t const n, size_t const p, size_t const q); //@} /** @name Access to element */ //@{ /// get number of rows Index rows() const; /// get number of cols Index cols() const; /// get depth Index depth() const; /// get number of rows Index n() const {return my_n;}; /// get number of cols Index p() const {return my_p;}; /// get number of cols Index q() const {return my_q;}; /// get first element in the i-th row Index firstInRow (Index const i) const; /// get first element in the j-th column Index firstInCol (Index const j) const; /// get first element in the k-th depth Index firstInDepth (Index const k) const; /// get last element in the i-th row Index lastInRow (Index const i) const; /// get last element in the j-th column Index lastInCol (Index const j) const; /// get last element in the k-th column Index lastInDepth(Index const k) const; /// true if the storage is by depth first and then by rows and then by column static Bool isDepthMajor () {return true;}; /// true if the storage is row major (C-like) static Bool isRowMajor () {return false;}; /// true if the storage is column major (fortran-like) static Bool isColumnMajor () {return false;}; /// set value template <typename T_value> T_value& get (T_value* const data, Index const i, Index const j, Index const k); /// get value template <typename T_value> T_value get (T_value const* const data, Index const i, Index const j, Index const k) const; /// set value fast template <typename T_value> T_value& get_fast (T_value* const data, Index const i, Index const j, Index const k); /// get value fast template <typename T_value> T_value get_fast (T_value const* const data, Index const i, Index const j, Index const k) const; /// true if matrix is factored Bool isFactored() const; /// set isFactored to true void setIsFactored(); /// set isFactored to false void setIsNotFactored(); /// map(MinIndex,MinIndex,MinIndex) Index offset () const; /// compute offset void computeOffset(); //@} private: // number of rows or columns UInt my_n; UInt my_p; UInt my_q; /// number of elements asked by user size_t my_data_length; /// offset is $map(1,1,1)$ UInt my_offset; /// is matrix factored ? Bool my_matrix_is_factored; /** map(i,j,k) find the position in the data array */ inline Index map (Index const i, Index const j, Index const k) const { assert( MinIndex <= i && i <= my_n ); assert( MinIndex <= j && j <= my_p ); assert( MinIndex <= k && k <= my_q ); return my_q*(my_p*i+j)+k; } /** same as map(i,j) but without any control */ inline Index map_fast (Index const i, Index const j, Index const k) const { return my_q*(my_p*i+j)+k; } // copy constructor is private to prevent unwanted allocation // WARNING: Do NOT declare the copy constructor ! // Tensor3( Tensor3 const& copy ) {}; }; // ---------------------------------------------------------------------- // get() // ---------------------------------------------------------------------- template <typename T_value> T_value& Tensor3::get(T_value* const data, Index const i, Index const j, Index const k) { return data[map(i,j,k)]; } // ---------------------------------------------------------------------- // get() // ---------------------------------------------------------------------- template <typename T_value> T_value Tensor3::get( T_value const* const data, Index const i, Index const j, Index const k) const { return data[map(i,j,k)]; } // ---------------------------------------------------------------------- // get_fast() // ---------------------------------------------------------------------- template <typename T_value> T_value& Tensor3::get_fast(T_value* const data, Index const i, Index const j, Index const k) { return data[map_fast(i,j,k)]; } // ---------------------------------------------------------------------- // get_fast() // ---------------------------------------------------------------------- template <typename T_value> T_value Tensor3::get_fast(T_value const* data, Index const i, Index const j, Index const k ) const { return data[map_fast(i,j,k)]; }#ifdef HAVE_NAMESPACE}#endif#endif// end of SL_MATRIX_STRUCTURES_TENSOR3_TENSOR3_H definition(s)// do not write anything after this line!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -