1 #ifndef QNANO_NEW_TENSOR2_DEFINED_H 2 #define QNANO_NEW_TENSOR2_DEFINED_H 7 #include "tools/Reader.h" 17 inline size_t get_index(
size_t i,
size_t j)
const{
22 inline size_t get_totalsize()
const{
return size[0]*size[1]; }
26 void allocate(){ data=
new T[get_totalsize()]; }
27 void deallocate(){
delete[] data; }
29 inline size_t get_size(
size_t i)
const{
return size[i];}
30 void resize(
size_t i,
size_t j){
36 size_t ts=get_totalsize();
37 for(
size_t i=0; i<ts; i++)data[i]=0.;
40 const T &operator()(
size_t i,
size_t j)
const{
41 return data[get_index(i,j)];
43 T &operator()(
size_t i,
size_t j){
44 return data[get_index(i,j)];
46 const T &get_check(
int i,
int j){
47 if(i<0 || i>=(
int)size[0] || j<0 || j>=(
int)size[1] ){
48 std::cerr<<
"Tensor2: out of bounds!"<<std::endl;
51 return data[get_index(i,j)];
54 void swap_lines(
size_t l1,
size_t l2){
55 for(
size_t k=0; k<size[1]; k++){
56 T tmp=data[get_index(l1,k)];
57 data[get_index(l1,k)]=data[get_index(l2,k)];
58 data[get_index(l2,k)]=tmp;
65 resize(other.get_size(0),other.get_size(1));
66 for(
size_t i=0; i<get_totalsize(); i++){
67 data[i]=other.data[i];
Class to store a rank-2 (complex) tensor, i.e., a matrix:
Definition: Tensor2.h:10