1 #ifndef QNANO_NEW_TENSOR3_DEFINED_H 2 #define QNANO_NEW_TENSOR3_DEFINED_H 16 inline size_t get_index(
size_t i,
size_t j,
size_t k)
const{
17 return (i*size[1]+j)*size[2]+k;
21 inline size_t get_totalsize()
const{
return size[0]*size[1]*size[2]; }
25 void allocate(){ data=
new T[get_totalsize()]; }
26 void deallocate(){
delete[] data; }
28 inline size_t get_size(
size_t i)
const{
return size[i];}
29 void resize(
size_t i,
size_t j,
size_t k){
30 size[0]=i; size[1]=j; size[2]=k;
35 const T &operator()(
size_t i,
size_t j,
size_t k)
const{
36 return data[get_index(i,j,k)];
38 T &operator()(
size_t i,
size_t j,
size_t k){
39 return data[get_index(i,j,k)];
41 const T &get_check(
int i,
int j,
int k){
42 if(i<0 || i>=(
int)size[0] || j<0 || j>=(
int)size[1] || k<0 || k>=(
int)size[2] ){
43 std::cerr<<
"Tensor3: out of bounds!"<<std::endl;
46 return data[get_index(i,j,k)];
52 resize(other.get_size(0),other.get_size(1),other.get_size(2));
53 for(
size_t i=0; i<get_totalsize(); i++){
54 data[i]=other.data[i];
65 size[0]=size[1]=size[2]=0;
69 size[0]=i; size[1]=j; size[2]=k;
Class to store a rank-3 (complex) tensor, i.e., a matrix:
Definition: Tensor3.h:9