Skip to content
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
@@ -1,7 +1,7 @@
name = "ITensorBase"
uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.1.7"
version = "0.1.8"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
3 changes: 3 additions & 0 deletions src/ITensorBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
function specify_eltype(a::Zeros{UnspecifiedZero}, elt::Type)
return Zeros{elt}(axes(a))
end
function specify_eltype(a::AbstractArray, elt::Type)
return a

Check warning on line 169 in src/ITensorBase.jl

View check run for this annotation

Codecov / codecov/patch

src/ITensorBase.jl#L168-L169

Added lines #L168 - L169 were not covered by tests
end

# TODO: Use `adapt` to reach down into the storage.
function specify_eltype!(a::AbstractITensor, elt::Type)
Expand Down
54 changes: 34 additions & 20 deletions src/quirks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,48 @@
return a
end

# 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`.
function svd_truncated(a::AbstractITensor, codomain_inds; maxdim)
U, S, V = svd(a, codomain_inds)
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′

Check warning on line 54 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L44-L54

Added lines #L44 - L54 were not covered by tests
end

using LinearAlgebra: qr, svd
# TODO: Define this in `MatrixAlgebra.jl`/`TensorAlgebra.jl`.
function factorize(
a::AbstractITensor, codomain_inds; maxdim=nothing, cutoff=nothing, kwargs...
a::AbstractITensor, codomain_inds; maxdim=nothing, cutoff=nothing, ortho="left", 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, codomain_inds′)
return Q, R, (; truncerr=zero(Bool),)
codomain_inds′ = if ortho == "left"
intersect(inds(a), codomain_inds)
elseif ortho == "right"
setdiff(inds(a), codomain_inds)

Check warning on line 67 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L64-L67

Added lines #L64 - L67 were not covered by tests
else
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),)
error("Bad `ortho` input.")

Check warning on line 69 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L69

Added line #L69 was not covered by tests
end
F1, F2 = if isnothing(maxdim) && isnothing(cutoff)
qr(a, codomain_inds′)

Check warning on line 72 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L71-L72

Added lines #L71 - L72 were not covered by tests
else
U, S, V = svd_truncated(a, codomain_inds′; maxdim)
U, S * V

Check warning on line 75 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L74-L75

Added lines #L74 - L75 were not covered by tests
end
if ortho == "right"
F2, F1 = F1, F2

Check warning on line 78 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L77-L78

Added lines #L77 - L78 were not covered by tests
end
return F1, F2, (; truncerr=zero(Bool),)

Check warning on line 80 in src/quirks.jl

View check run for this annotation

Codecov / codecov/patch

src/quirks.jl#L80

Added line #L80 was not covered by tests
end

# TODO: Used in `ITensorMPS.jl`, decide where or if to define it.
Expand Down
Loading