From e867a7a8c9ab10549d76218ce7090a09856c4e02 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Thu, 20 Nov 2025 16:24:17 +0100 Subject: [PATCH] tensor: generalized reinterpretation as matrix --- tensor.cc | 2 +- tensor.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tensor.cc b/tensor.cc index 6f76662..a8202ab 100644 --- a/tensor.cc +++ b/tensor.cc @@ -1731,7 +1731,7 @@ for(int i=0; i uu=unwind_index(I); ushape=uu.shape; - um=uu.matrix(); + um=uu.matrix(1); } int mini=um.nrows(); if(um.ncols() u(um.nrows(),mini),vt(mini,um.ncols()); diff --git a/tensor.h b/tensor.h index fcbfe67..e7152f6 100644 --- a/tensor.h +++ b/tensor.h @@ -248,7 +248,12 @@ public: explicit Tensor(const NRVec &x); explicit Tensor(const NRMat &x, bool flat=false); explicit Tensor(const NRSMat &x); - NRMat matrix() const {return NRMat(data,data.size()/groupsizes[0],groupsizes[0],0);}; //reinterpret as matrix with column index being the tensor's leftmost index group (typically the unwound single index) //@@@generalize to column index being n leftmost tensor index groups + NRMat matrix(int n=1) const //reinterpret as matrix with column index being the tensor's n leftmost index groups (typically the unwound single index) + { + if(n<0||n>shape.size()) laerror("wrong number n in tensor:: matrix()"); + LA_largeindex ncol = (n==shape.size()) ? data.size() : cumsizes[n]; + return NRMat(data,data.size()/ncol,ncol,0); + }; bool is_named() const {if(names.size()==0) return false; if(names.size()!=myrank) laerror("bad number of index names"); return true;}; bool is_uniquely_named() const; //no repeated names