Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TensorMap constructor is slow when applied to an array #155

Closed
ebelnikola opened this issue Oct 4, 2024 · 2 comments
Closed

TensorMap constructor is slow when applied to an array #155

ebelnikola opened this issue Oct 4, 2024 · 2 comments

Comments

@ebelnikola
Copy link

ebelnikola commented Oct 4, 2024

Hi!

I noticed that TensorMap constructor is extraordinarily slow when applied to an array. Here is a minimal example:

space=Z2Space(0=>10,1=>10);

@time A=TensorMap(randn,space⊗space←space⊗space); # takes time of roder 1e-4s
A_array=convert(Array,A);

@time A_copy_1=TensorMap(A_array,space⊗space←space⊗space); # takes time of order 10s
println(A_copy_1==A) # prints true

At the same time, the following code takes time of order 1e-4s:

@time begin
    dom=space⊗space
    codom=dom
    A_copy_2=TensorMap(zeros,codom←dom)

    for (f1,f2) in fusiontrees(A_copy_2)
        a3,a4=axes(dom,f2.uncoupled)
        a1,a2=axes(dom,f1.uncoupled)
        A_copy_2[f1,f2]=A_array[a1,a2,a3,a4]
    end
end
println(A_copy_1==A)
@ebelnikola ebelnikola closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
@ebelnikola ebelnikola reopened this Oct 5, 2024
@Jutho
Copy link
Owner

Jutho commented Oct 5, 2024

The code for this in the latest tagged version is indeed quite suboptimal, because this is not something that is expected to be used in computation-heavy parts of the code. We figured this would be used only to initialise some small tensors such as single-site operators or two-site hamiltonians. However, on the development version that we are currently working on, this has been improved quite dramatically, and this specifica example currently takes only order 2*10^-3 seconds on my computer.

@ebelnikola
Copy link
Author

I see, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants