📄 implementation.h
字号:
/* -*- c++ -*- *********************************************************************** * Scientific Library(GNU Public Licence) * * dense 3D tensor structure * * Author: Pierre Aubert paubert@mathinsa.insa-lyon.fr * * $Id: implementation.h,v 1.2 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_IMPLEMENTATION_H#define SL_MATRIX_STRUCTURES_TENSOR3_IMPLEMENTATION_H#ifdef HAVE_NAMESPACEnamespace sl {#endif // ---------------------------------------------------------------------- // CONSTRUCTOR // ---------------------------------------------------------------------- Tensor3::Tensor3( ) : my_n(0),my_p(0), my_q(0), my_data_length(0), my_offset(0) {} // ---------------------------------------------------------------------- // CONSTRUCTOR // ---------------------------------------------------------------------- Tensor3::Tensor3( Index const& n ) : my_n(n), my_p(n), my_q(n), my_data_length(n*n*n) { computeOffset(); } // ---------------------------------------------------------------------- // CONSTRUCTOR // ---------------------------------------------------------------------- Tensor3::Tensor3( Index const& n, Index const& p ) : my_n(n), my_p(p), my_q(p), my_data_length(n*p*p) { computeOffset(); } // ---------------------------------------------------------------------- // CONSTRUCTOR // ---------------------------------------------------------------------- Tensor3::Tensor3( Index const& n, Index const& p, Index const& q ) : my_n(n), my_p(p), my_q(q), my_data_length(n*p*q) { computeOffset(); } // ---------------------------------------------------------------------- // resize() // ---------------------------------------------------------------------- void Tensor3::resize( Index const n ) { my_n = n; my_p = n; my_q = n; computeOffset(); } // ---------------------------------------------------------------------- // resize() // ---------------------------------------------------------------------- void Tensor3::resize( Index const n, Index const p ) { my_n = n; my_p = p; my_q = p; computeOffset(); } // ---------------------------------------------------------------------- // resize() // ---------------------------------------------------------------------- void Tensor3::resize( Index const n, Index const p, Index const q ) { my_n = n; my_p = p; my_q = q; computeOffset(); } // ---------------------------------------------------------------------- // rows() // ---------------------------------------------------------------------- Index Tensor3::rows() const { return my_n; } // ---------------------------------------------------------------------- // cols() // ---------------------------------------------------------------------- Index Tensor3::cols() const { return my_p; } // ---------------------------------------------------------------------- // depth() // ---------------------------------------------------------------------- Index Tensor3::depth() const { return my_q; } // ---------------------------------------------------------------------- // size() // ---------------------------------------------------------------------- Index Tensor3::size() const { Index sz = my_n*my_p*my_q; assert( sz <= my_data_length ); return sz; } // ---------------------------------------------------------------------- // firstInRow() // ---------------------------------------------------------------------- Index Tensor3::firstInRow( Index const row ) const { return 1; } // ---------------------------------------------------------------------- // firstInCol() // ---------------------------------------------------------------------- Index Tensor3::firstInCol( Index const col ) const { return 1; } // ---------------------------------------------------------------------- // firstInDepth() // ---------------------------------------------------------------------- Index Tensor3::firstInDepth( Index const col ) const { return 1; } // ---------------------------------------------------------------------- // lastInRow() // ---------------------------------------------------------------------- Index Tensor3::lastInRow( Index const row ) const { return my_n; } // ---------------------------------------------------------------------- // lastInCol() // ---------------------------------------------------------------------- Index Tensor3::lastInCol( Index const col ) const { return my_p; } // ---------------------------------------------------------------------- // lastInDepth() // ---------------------------------------------------------------------- Index Tensor3::lastInDepth( Index const col ) const { return my_q; } // ---------------------------------------------------------------------- // offset() // ---------------------------------------------------------------------- Index Tensor3::offset() const { return my_offset; } // ---------------------------------------------------------------------- // computeOffset() // ---------------------------------------------------------------------- void Tensor3::computeOffset() { my_offset = map(1,1,1); } // ---------------------------------------------------------------------- // constructor // ---------------------------------------------------------------------- Tensor3Iterator::Tensor3Iterator( structure_t const* structure, Index const i, Index const j, Index const k ) : GeneralIterator3D(structure->rows(), structure->cols(), structure->depth(), i,j,k,0) { my_o = Tensor3Iterator::map_fast(i,j,k); } // ---------------------------------------------------------------------- // map() // ---------------------------------------------------------------------- Index Tensor3Iterator::map( Index const& row, Index const& col, Index const& dep ) { assert( MinIndex <= row && row <= my_n ); assert( MinIndex <= col && col <= my_p ); assert( MinIndex <= dep && dep <= my_q ); return map_fast(row,col,dep); } // ---------------------------------------------------------------------- // map_fast() // ---------------------------------------------------------------------- inline Index Tensor3Iterator::map_fast( Index const& row, Index const& col, Index const& dep ) { return my_q*(my_p*row+col)+dep-(my_q*(my_p+1)+1); } // ---------------------------------------------------------------------- // operator++() // ---------------------------------------------------------------------- void Tensor3Iterator::operator++() { cerr << " IN iter++ i=" << my_i << " j=" << my_j << " k=" << my_k << endl; if (++my_k > my_q) { my_k = MinIndex; if (++my_j > my_p) { my_j = MinIndex; if( ++my_i > my_n ) { my_ok = false; } } } ++my_o; cerr << "OUT iter++ i=" << my_i << " j=" << my_j << " k=" << my_k << " o=" << my_o << endl; } // ---------------------------------------------------------------------- // incDepth() // ---------------------------------------------------------------------- void Tensor3Iterator::incDepth() { throw eNotYetImplemented; } // ---------------------------------------------------------------------- // incRow() // ---------------------------------------------------------------------- void Tensor3Iterator::incRow() { throw eNotYetImplemented; } // ---------------------------------------------------------------------- // incCol() // ---------------------------------------------------------------------- void Tensor3Iterator::incCol() { throw eNotYetImplemented; } #ifdef HAVE_NAMESPACE}#endif#endif// end of SL_MATRIX_STRUCTURES_TENSOR3_IMPLEMENTATION_H definition(s)// do not write anything after this line!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -