From 052c30fd9d3ec0b058b58e0425b872d4170df399 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Fri, 17 May 2024 16:27:10 +0200 Subject: [PATCH] working on tensor - outer product --- t.cc | 38 +++++++++++++++++++++++++++++++++++++- tensor.cc | 13 +++++++++++++ tensor.h | 4 +++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/t.cc b/t.cc index 0f2f662..46fe072 100644 --- a/t.cc +++ b/t.cc @@ -3295,7 +3295,7 @@ cout < e(g); +e.randomize(1.); +INDEXLIST il(2); +il[0]= {0,1}; +il[1]= {0,0}; +Tensor eu = e.unwind_indices(il); + +for(int i=0; i a({1.,10.,100.}); +NRVec b({1.,2.,3.}); +Tensor aa(a); +Tensor bb(b); +cout << aa*bb; +} + } diff --git a/tensor.cc b/tensor.cc index 95da674..a29639b 100644 --- a/tensor.cc +++ b/tensor.cc @@ -726,11 +726,16 @@ for(int i=0; i0) { newshape[ii++] = oldshape[i]; } + else + ++emptied_groups; + +if(emptied_groups) newshape.resize(newshape.size()-emptied_groups,true); Tensor r(newshape); if(r.rank()!=rank()) laerror("internal error 2 in unwind_indces"); @@ -1019,6 +1024,14 @@ return r; } +//outer product, rhs indices will be the less significant than this +template +Tensor Tensor::operator*(const Tensor &rhs) const +{ +Tensor r(rhs.shape.concat(shape)); +r.data= data.otimes2vec(rhs.data); +return r; +} diff --git a/tensor.h b/tensor.h index 77180a9..2a7ab90 100644 --- a/tensor.h +++ b/tensor.h @@ -36,9 +36,9 @@ #include "smat.h" #include "miscfunc.h" -//@@@todo - outer product //@@@permutation of individual indices??? how to treat the symmetry groups //@@@todo - index names and contraction by named index list +//@@@contraction inside one tensor namespace LA { @@ -159,6 +159,8 @@ public: inline Tensor& operator/=(const T &a) {data/=a; return *this;}; inline Tensor operator/(const T &a) const {Tensor r(*this); r /=a; return r;}; + Tensor operator*(const Tensor &rhs) const; //outer product + Tensor& conjugateme() {data.conjugateme(); return *this;}; inline Tensor conjugate() const {Tensor r(*this); r.conjugateme(); return r;};