get ITensor slice array-wise

Hi!

From Add support for setting slices of an ITensor by mtfishman · Pull Request #535 · ITensor/ITensors.jl · GitHub, I see that it is possible to set ITensors elements array-wise.
I was wondering if it is possible to similarly get ITensor elements Array-wise. Something like getting B in the following:

using ITensors
i = Index(2)
j = Index(2)
k = Index(2)
l = Index(2)

A = randomITensor(i,j,k,l)
B = A[i=>1, j=>2, k=>1:end, l=>1:end] 

In this case, B would result in a 2x2 array or, even better, an ITensor with indices (i,j).

I am using Julia v1.7.0 and ITensors v0.3.18

Thanks in advance for any reply!

The closest thing we have right now to do that kind of slicing is:

julia> using ITensors

julia> i, j, k, l = Index.((2, 2, 2, 2))
((dim=2|id=477), (dim=2|id=714), (dim=2|id=447), (dim=2|id=498))

julia> A = randomITensor(i, j, k, l)
ITensor ord=4 (dim=2|id=477) (dim=2|id=714) (dim=2|id=447) (dim=2|id=498)
NDTensors.Dense{Float64, Vector{Float64}}

julia> B = A * onehot(i => 1, j => 2)
ITensor ord=2 (dim=2|id=447) (dim=2|id=498)
NDTensors.Dense{Float64, Vector{Float64}}
2 Likes

thank you very much for the quick reply, this is exactly what I needed!

1 Like