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

[ENHANCEMENT] Define LinearAlgebra.diag and LinearAlgebra.diagind for ITensors #805

Closed
mtfishman opened this issue Jan 26, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@mtfishman
Copy link
Member

mtfishman commented Jan 26, 2022

Define overloads of LinearAlgebra.diag and LinearAlgebra.diagind for ITensors to make it easier to work with diagonal entries (iterate, modify, etc.). A corner case will be figuring out how to handle the block sparse case in a good way (i.e. only iterating over the diagonals of nonzero diagonal blocks, if that is the desired behavior).

Note that conversion to Tensor can help with manipulating diagonal entries:

julia> using ITensors, ITensors.NDTensors, LinearAlgebra

julia> i = Index(2)
(dim=2|id=887)

julia> A = randomITensor(i', i);

julia> @show A;
A = ITensor ord=2
Dim 1: (dim=2|id=887)'
Dim 2: (dim=2|id=887)
Dense{Float64, Vector{Float64}}
 2×2
  1.9193797093690799  0.16138987630693938
 -1.141571133623248   0.43841019457419206

julia> d = diag(tensor(A))
Dim 1: 2
Dense{Float64, SubArray{Float64, 1, Vector{Float64}, Tuple{StepRange{Int64, Int64}}, true}}
 2-element
 1.9193797093690799
 0.43841019457419206

julia> for i in 1:length(d)
         d[i] = d[i]^2
       end

julia> @show A;
A = ITensor ord=2
Dim 1: (dim=2|id=887)'
Dim 2: (dim=2|id=887)
Dense{Float64, Vector{Float64}}
 2×2
  3.6840184687377335  0.16138987630693938
 -1.141571133623248   0.19220349870658093
@mtfishman mtfishman added the enhancement New feature or request label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant