CUDA: scalar indexing error on svd(tensor(a::ITensor))

Hi, I’m hitting a funny behavior doing an SVD on a NDTensors’ Tensor object.

For a rank-2 ITensor if I do

using ITensors, ITensors.NDTensors, CUDA

a = random_itensor(Index(10), Index(10))
ca = NDTensors.cu(a)

svd(tensor(a))  # works, but

svd(tensor(ca)) # fails with scalar indexing disallowed

# what’s even more curious is that, individually, if I do 

u = svd(tensor(ca))[1]  # this works! but then if I do 

println(u) # now this fails with scalar indexing!

to be honest I have no idea what’s going on … any hint?

running latest julia 1.11.5 and
[052768ef] CUDA v5.7.3
[0d1a4710] ITensorMPS v0.3.17
[9136182c] ITensors v0.9.6

thanks!

It looks like that is more of an issue with printing rather than the SVD function itself, if you want to print you could always convert back to CPU (that’s how printing should be implemented anyway to avoid this issue).

We can definitely fix that, though please note that in general NDTensors.jl is more meant as an internal package for ITensors.jl and generally isn’t meant to be used by external users (which is one of the reasons why it isn’t documented right now).

As part of the ITensors.jl rewrite we are working on splitting up NDTensors.jl into a suite of Julia array packages that will be better documented, less buggy, and easier to use for end users to use individually. Just pointing that out to say these kinds of issues will be improved once that is out, though it is a big effort so we don’t have a timeline for when that will be.

yea, I understand this is maybe not the best time for playing around with this with all the ongoing refactoring, I was using this svd(tensor()) as part of an attempt I did back then to save memory on some SVD operations on matrices since I had some out of memory problems when running on GPU some time ago, but for now I guess I can revert to the standard svd(ITensor).

anyway in case you’re interested in the issue, it doesn’t seem to be just about printing - it’s true as you said that doing u,s,v, ww = svd(tensor(ca)); (suppressing output) works, but then more funny stuff happens: doing u*u works (it can even print it!) but s*s; (even without printing) fails with scalar indexing, same for v*v;

thanks as always for developing this great library!