working on tensor class
This commit is contained in:
parent
8bbbaa5bae
commit
baee11489b
13
t.cc
13
t.cc
@ -3202,7 +3202,18 @@ g.range=3;
|
|||||||
|
|
||||||
Tensor<double> epsilon(g);
|
Tensor<double> epsilon(g);
|
||||||
cout <<epsilon.size()<<endl;
|
cout <<epsilon.size()<<endl;
|
||||||
//cout <<epsilon(3,2,1)<<endl;
|
|
||||||
|
NRVec<LA_index> I({1,2,3});
|
||||||
|
NRVec<NRVec<LA_index> > II(I,1);
|
||||||
|
epsilon.lhs(II)=1;
|
||||||
|
II.copyonwrite();
|
||||||
|
II[0][0]=3;
|
||||||
|
II[0][1]=2;
|
||||||
|
II[0][2]=1;
|
||||||
|
|
||||||
|
epsilon *= 2.;
|
||||||
|
|
||||||
|
cout <<epsilon(II)<<endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +146,16 @@ return r;
|
|||||||
}
|
}
|
||||||
|
|
||||||
//@@@@todo flatindex
|
//@@@@todo flatindex
|
||||||
|
template<typename T>
|
||||||
|
LA_largeindex Tensor<T>::index(int *sign, const FLATINDEX &I) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//@@@@todo vindex
|
//@@@@todo vindex
|
||||||
|
template<typename T>
|
||||||
|
LA_largeindex Tensor<T>::vindex(int *sign, int i1, va_list args) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template class Tensor<double>;
|
template class Tensor<double>;
|
||||||
|
12
tensor.h
12
tensor.h
@ -44,7 +44,7 @@ int sgn;
|
|||||||
public:
|
public:
|
||||||
Signedpointer(T *p, int s) : ptr(p),sgn(s) {};
|
Signedpointer(T *p, int s) : ptr(p),sgn(s) {};
|
||||||
T& operator=(const T rhs) {if(sgn==0) return *ptr; if(sgn>0) *ptr=rhs; else *ptr = -rhs; return *ptr;}
|
T& operator=(const T rhs) {if(sgn==0) return *ptr; if(sgn>0) *ptr=rhs; else *ptr = -rhs; return *ptr;}
|
||||||
//@@@@@@operations on singedpointer as LHS of the non-const tensor.operator() expressions
|
//@@@@@@operations like += etc. on singedpointer as LHS of the non-const tensor.operator() expressions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -96,16 +96,16 @@ public:
|
|||||||
LA_largeindex getsize(); //set redundant data and return total size
|
LA_largeindex getsize(); //set redundant data and return total size
|
||||||
LA_largeindex size() const {return data.size();};
|
LA_largeindex size() const {return data.size();};
|
||||||
void copyonwrite() {shape.copyonwrite(); data.copyonwrite();};
|
void copyonwrite() {shape.copyonwrite(); data.copyonwrite();};
|
||||||
inline Signedpointer<T> operator[](const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer<T>(&data[i],sign);};
|
inline Signedpointer<T> lhs(const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer<T>(&data[i],sign);};
|
||||||
inline T operator()(const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
inline T operator()(const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
||||||
inline Signedpointer<T> operator[](const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer<T>(&data[i],sign);};
|
inline Signedpointer<T> lhs(const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer<T>(&data[i],sign);};
|
||||||
inline T operator()(const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
inline T operator()(const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
||||||
//inline Signedpointer<T> operator[](int i1...) {va_list args; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); return Signedpointer<T>(&data[i],sign); };
|
inline Signedpointer<T> lhs(int i1...) {va_list args; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); return Signedpointer<T>(&data[i],sign); };
|
||||||
//cannot have operator[] with variable number of argmuments
|
|
||||||
inline T operator()(int i1...) {va_list args; ; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
inline T operator()(int i1...) {va_list args; ; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); if(sign==0) return 0; return sign>0 ?data[i] : -data[i];};
|
||||||
//@@@do a 'set' operatiaon with va_arg instead
|
|
||||||
|
|
||||||
//NOTE: for sign==0 data[i] can be undefined pointer, avoid dereferencing it
|
//NOTE: for sign==0 data[i] can be undefined pointer, avoid dereferencing it
|
||||||
|
|
||||||
|
inline Tensor& operator*=(const T &a) {data*=a; return *this;};
|
||||||
|
|
||||||
//@@@TODO - unwinding to full size in a specified index
|
//@@@TODO - unwinding to full size in a specified index
|
||||||
//@@@TODO - contractions - basic and efficient
|
//@@@TODO - contractions - basic and efficient
|
||||||
|
Loading…
Reference in New Issue
Block a user