From 22e3d2fb63b816f9b1a4a178e7f5d989fdbb6707 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Thu, 29 Oct 2026 21:51:03 +0100 Subject: [PATCH] bugfixes in tensor --- tensor.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tensor.h b/tensor.h index 98f2e5c..dc3bdd7 100644 --- a/tensor.h +++ b/tensor.h @@ -107,8 +107,11 @@ public: Signedpointer(T *p, int s) : ptr(p),sgn(s) {}; //dereferencing *ptr should be ignored for sgn==0 const T operator=(const T rhs) {if(ptr_ok(ptr)) *ptr = signeddata(sgn,rhs); return rhs;} - void operator*=(const T rhs) {if(ptr_ok(ptr)) *ptr *= rhs;} - void operator/=(const T rhs) {if(ptr_ok(ptr)) *ptr /= rhs;} + //the element L is related to the stored value S by L=signeddata(sgn,S): S, -S, conj(S) (sgn 2) or -conj(S) (sgn -2) + //for sgn +-1: L*a = +-S*a, so S*=a; for sgn +-2: L*a = +-conj(S)*a = +-conj(S*conj(a)), so S*=conj(a) + //(signeddata(sgn,rhs) cannot be used here, for negative sgn it would also negate the factor) + void operator*=(const T rhs) {if(ptr_ok(ptr)) *ptr *= (sgn==2||sgn== -2)? LA_traits::conjugate(rhs) : rhs;} + void operator/=(const T rhs) {if(ptr_ok(ptr)) *ptr /= (sgn==2||sgn== -2)? LA_traits::conjugate(rhs) : rhs;} void operator+=(T rhs) {if(ptr_ok(ptr)) *ptr += signeddata(sgn,rhs);} void operator-=(T rhs) {if(ptr_ok(ptr)) *ptr -= signeddata(sgn,rhs);} };