From baee11489b1e38700291ddab9ef716b66e85be84 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Wed, 3 Apr 2024 22:14:24 +0200 Subject: [PATCH] working on tensor class --- t.cc | 13 ++++++++++++- tensor.cc | 8 ++++++++ tensor.h | 12 ++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/t.cc b/t.cc index a93fa46..c55b51a 100644 --- a/t.cc +++ b/t.cc @@ -3202,7 +3202,18 @@ g.range=3; Tensor epsilon(g); cout < I({1,2,3}); +NRVec > II(I,1); +epsilon.lhs(II)=1; +II.copyonwrite(); +II[0][0]=3; +II[0][1]=2; +II[0][2]=1; + +epsilon *= 2.; + +cout < +LA_largeindex Tensor::index(int *sign, const FLATINDEX &I) const +{ +} //@@@@todo vindex +template +LA_largeindex Tensor::vindex(int *sign, int i1, va_list args) const +{ +} template class Tensor; diff --git a/tensor.h b/tensor.h index 8a0fcbe..103cc9c 100644 --- a/tensor.h +++ b/tensor.h @@ -44,7 +44,7 @@ int sgn; public: 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;} -//@@@@@@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 size() const {return data.size();}; void copyonwrite() {shape.copyonwrite(); data.copyonwrite();}; - inline Signedpointer operator[](const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer(&data[i],sign);}; + inline Signedpointer lhs(const SUPERINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer(&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 Signedpointer operator[](const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer(&data[i],sign);}; + inline Signedpointer lhs(const FLATINDEX &I) {int sign; LA_largeindex i=index(&sign,I); return Signedpointer(&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 Signedpointer operator[](int i1...) {va_list args; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); return Signedpointer(&data[i],sign); }; - //cannot have operator[] with variable number of argmuments + inline Signedpointer lhs(int i1...) {va_list args; int sign; LA_largeindex i; va_start(args,i1); i= vindex(&sign, i1,args); return Signedpointer(&data[i],sign); }; 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 + + inline Tensor& operator*=(const T &a) {data*=a; return *this;}; //@@@TODO - unwinding to full size in a specified index //@@@TODO - contractions - basic and efficient