sandialabs / pyttb

Python Tensor Toolbox
https://pyttb.readthedocs.io
BSD 2-Clause "Simplified" License
25 stars 13 forks source link

Display name does not match variable name #339

Closed tgkolda closed 1 week ago

tgkolda commented 1 week ago

In MATLAB Tensor Toolbox, the display function picks up the variable name.

Input:

X

Output:

X is a tensor of size 2 x 2 x 2
    X(:,:,1) = 
         1     3
         2     4
    X(:,:,2) = 
         5     7
         6     8

In pyttb, however, the tensor is always references as "tensor" and "data", no matter what its name is:

Input:

Y

Output:

tensor of shape (2, 2, 2)
data[0, :, :] =
[[1 5]
 [3 7]]
data[1, :, :] =
[[2 6]
 [4 8]]
ntjohnson1 commented 1 week ago

Hmm, I think there are some hacks we could do to try and infer the variable name so it can print it back. This seems to be a python vs MATLAB difference.

I'd consider the python approach would be for the user to type

Print(f"{Y=}")
tgkolda commented 1 week ago

When python displays an array, it echos its name, so there is surely a way to do this. In MATLAB, every class has a function called "display" that is called to display the object. It can access some special object called inputname(1) which we then use in the output. The approach you propose just puts "Y=" before but note that the MATLAB version reuses the name over and over again, in stating the size and printing the frontal slices.

tgkolda commented 1 week ago

Okay, Bing copilot has informed me that this is impossible. An example where MATLAB is way nice than Python! :-(