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

Update TensorKit v0.14 #16

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"

[compat]
TensorKit = "0.13, 0.14"
TensorKit = "0.13,0.14"
julia = "1.10"

[extras]
Expand Down
23 changes: 13 additions & 10 deletions src/grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ mutable struct GrassmannTangent{T<:AbstractTensorMap,
function GrassmannTangent(W::AbstractTensorMap{TT₁,S,N₁,N₂},
Z::AbstractTensorMap{TT₂,S,N₁,N₂}) where {TT₁,TT₂,S,N₁,N₂}
T = typeof(W)
TT = promote_type(float(scalartype(W)), scalartype(Z))
M = similarstoragetype(W, TT)
Mr = similarstoragetype(W, real(TT))
TU = tensormaptype(S, N₁, 1, M)
TS = isreal(sectortype(S)) ? tensormaptype(S, 1, 1, Mr) : tensormaptype(S, 1, 1, M)
TV = tensormaptype(S, 1, N₂, M)
TU, TS, TV = _tsvd_types(Z)
return new{T,TU,TS,TV}(W, Z, nothing, nothing, nothing)
end
end

# output type of U, S, V in tsvd
function _tsvd_types(Z::AbstractTensorMap)
TUSV = Core.Compiler.return_type(tsvd, Tuple{typeof(Z)})
TU, TS, TV, = TUSV.types
return TU, TS, TV
end

function Base.copy(Δ::GrassmannTangent)
Δ′ = GrassmannTangent(Δ.W, copy(Δ.Z))
if Base.getfield(Δ, :U) !== nothing
Expand Down Expand Up @@ -246,8 +249,8 @@ function _sincosSV(α::Real, S::AbstractTensorMap, V::AbstractTensorMap)
bcSV = block(cSV, c)
bsSV = block(sSV, c)
bV = block(V, c)
Threads.@threads for j in 1:size(bV, 2)
@simd for i in 1:size(bV, 1)
Threads.@threads for j in axes(bV, 2)
@simd for i in axes(bV, 1)
sS, cS = sincos(α * bS[i, i])
# TODO: we are computing sin and cos above within the loop over j, while it is independent; moving it out the loop requires extra storage though.
bsSV[i, j] = sS * bV[i, j]
Expand All @@ -261,8 +264,8 @@ end
function _lmul!(S::AbstractTensorMap, V::AbstractTensorMap)
@inbounds for (c, bS) in blocks(S)
bV = block(V, c)
Threads.@threads for j in 1:size(bV, 2)
@simd for i in 1:size(bV, 1)
Threads.@threads for j in axes(bV, 2)
@simd for i in axes(bV, 1)
bV[i, j] *= bS[i, i]
end
end
Expand Down
Loading