diff --git a/Project.toml b/Project.toml index 776f09e..2dc99eb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorBase" uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7" authors = ["ITensor developers and contributors"] -version = "0.1.5" +version = "0.1.6" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/src/quirks.jl b/src/quirks.jl index c698da5..3b4179b 100644 --- a/src/quirks.jl +++ b/src/quirks.jl @@ -38,14 +38,31 @@ end using LinearAlgebra: qr, svd # TODO: Define this in `MatrixAlgebra.jl`/`TensorAlgebra.jl`. -function factorize(a::AbstractITensor, args...; maxdim=nothing, cutoff=nothing, kwargs...) +function factorize( + a::AbstractITensor, codomain_inds; maxdim=nothing, cutoff=nothing, kwargs... +) + # TODO: Perform this intersection in `TensorAlgebra.qr`/`TensorAlgebra.svd`? + # See https://github.com/ITensor/NamedDimsArrays.jl/issues/22. + codomain_inds′ = intersect(inds(a), codomain_inds) if isnothing(maxdim) && isnothing(cutoff) - Q, R = qr(a, args...) - return Q, R + Q, R = qr(a, codomain_inds′) + return Q, R, (; truncerr=zero(Bool),) else - error("Truncation in `factorize` not implemented yet.") - U, S, V = svd(a, args...; kwargs...) - return U, S * V + U, S, V = svd(a, codomain_inds′) + # TODO: This is just a stand-in for truncated SVD + # that only makes use of `maxdim`, just to get some + # functionality running in `ITensorMPS.jl`. + # Define a proper truncated SVD in + # `MatrixAlgebra.jl`/`TensorAlgebra.jl`. + r = Base.OneTo(min(maxdim, minimum(Int.(size(S))))) + u = commonind(U, S) + v = commonind(V, S) + us = uniqueinds(U, S) + vs = uniqueinds(V, S) + U′ = U[(us .=> :)..., u => r] + S′ = S[u => r, v => r] + V′ = V[v => r, (vs .=> :)...] + return U′, S′ * V′, (; truncerr=zero(Bool),) end end