tensor lhs() signedpointer debug diagnostics
This commit is contained in:
parent
f8b0cfa692
commit
4f8293dbf0
26
t.cc
26
t.cc
@ -3853,7 +3853,7 @@ for(int l=1; l<=n; ++l)
|
||||
}
|
||||
|
||||
|
||||
if(1)
|
||||
if(0)
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
@ -3879,7 +3879,29 @@ for(int l=1; l<=n; ++l)
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(1)
|
||||
{
|
||||
//tensor lhs operator() and signed pointer
|
||||
int n;
|
||||
cin >>n;
|
||||
INDEXGROUP shape;
|
||||
{
|
||||
shape.number=3;
|
||||
shape.symmetry= -1;
|
||||
shape.range=n;
|
||||
shape.offset=0;
|
||||
}
|
||||
Tensor<double> t(shape);
|
||||
t.clear();
|
||||
for(int i=0; i<n; ++i)
|
||||
for(int j=0; j<n; ++j)
|
||||
for(int k=0; k<n; ++k)
|
||||
{
|
||||
//cout <<t(i,j,k)<<endl;
|
||||
if(i!=j && i!=k &&j!=k) t.lhs(i,j,k) = 10.*random()/RAND_MAX;
|
||||
}
|
||||
cout <<t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
15
tensor.h
15
tensor.h
@ -46,8 +46,7 @@
|
||||
//@@@ will need to store vector of INDEX to the original tensor for the result's flatindex
|
||||
//@@@ will not be particularly efficient
|
||||
//
|
||||
//@@@conversions to/from fourindex, optional negative range for beta spin handling in some cases
|
||||
//@@@check operator() for all fourindex-tensor conversions
|
||||
//maybe optional negative range for beta spin handling in some cases of fourindex-tensor conversions
|
||||
//
|
||||
//@@@?general permutation of individual indices - check the indices in sym groups remain adjacent, calculate result's shape, loopover the result and permute using unwind_callback
|
||||
//
|
||||
@ -67,8 +66,16 @@ T *ptr;
|
||||
int sgn;
|
||||
public:
|
||||
Signedpointer(T *p, int s) : ptr(p),sgn(s) {};
|
||||
//dereferencing *ptr should intentionally segfault for sgn==0
|
||||
T& operator=(const T rhs) {if(sgn>0) *ptr=rhs; else *ptr = -rhs; return *ptr;}
|
||||
//dereferencing *ptr should be ignored for sgn==0
|
||||
const T operator=(const T rhs)
|
||||
{
|
||||
if(sgn>0) *ptr = rhs;
|
||||
if(sgn<0) *ptr = -rhs;
|
||||
#ifdef DEBUG
|
||||
if(sgn==0) laerror("dereferencing lhs Signedpointer to nonexistent tensor element");
|
||||
#endif
|
||||
return rhs;
|
||||
}
|
||||
T& operator*=(const T rhs) {*ptr *= rhs; return *ptr;}
|
||||
T& operator/=(const T rhs) {*ptr /= rhs; return *ptr;}
|
||||
T& operator+=(const T rhs) {if(sgn>0) *ptr += rhs; else *ptr -= rhs; return *ptr;}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user