Skip to content

Commit 335ff0b

Browse files
authored
Add isfinite to mps types (#347)
* add Base.isfinite to mps types * add isfinite tests for FiniteMPS and InfiniteMPS --------- Co-authored-by: afeuerpfeil <[email protected]>
1 parent aae67b5 commit 335ff0b

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/states/finitemps.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ function Base.similar(ψ::FiniteMPS{A, B}) where {A, B}
311311
return FiniteMPS{A, B}(similar.ALs), similar.ARs), similar.ACs), similar.Cs))
312312
end
313313

314+
Base.isfinite::FiniteMPS) = true
315+
314316
Base.eachindex::FiniteMPS) = eachindex.AL)
315317
Base.eachindex(l::IndexStyle, ψ::FiniteMPS) = eachindex(l, ψ.AL)
316318
Base.checkbounds(::Type{Bool}, ψ::FiniteMPS, i::Integer) = 1 <= i <= length(ψ)

src/states/infinitemps.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Base.size(ψ::InfiniteMPS, args...) = size(ψ.AL, args...)
241241
Base.length::InfiniteMPS) = length.AL)
242242
Base.eltype::InfiniteMPS) = eltype(typeof(ψ))
243243
Base.eltype(::Type{<:InfiniteMPS{A}}) where {A} = A
244+
Base.isfinite::InfiniteMPS) = false
244245

245246
Base.copy::InfiniteMPS) = InfiniteMPS(copy.AL), copy.AR), copy.C), copy.AC))
246247
function Base.copy!::InfiniteMPS, ϕ::InfiniteMPS)

src/states/multilinemps.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Type that represents multiple lines of `InfiniteMPS` objects.
1313
virtualspaces::Matrix{<:Union{S, CompositeSpace{S}}) where
1414
{S<:ElementarySpace}
1515
MultilineMPS(As::AbstractMatrix{<:GenericMPSTensor}; kwargs...)
16-
MultilineMPS(ALs::AbstractMatrix{<:GenericMPSTensor},
16+
MultilineMPS(ALs::AbstractMatrix{<:GenericMPSTensor},
1717
C₀::AbstractVector{<:MPSBondTensor}; kwargs...)
1818
1919
See also: [`Multiline`](@ref)
@@ -101,6 +101,8 @@ Base.convert(::Type{InfiniteMPS}, st::MultilineMPS) = only(st)
101101
Base.eltype(t::MultilineMPS) = eltype(t[1])
102102
Base.copy!::MultilineMPS, ϕ::MultilineMPS) = (copy!.(parent(ψ), parent(ϕ)); ψ)
103103

104+
Base.isfinite::MultilineMPS) = false
105+
104106
for f_space in (:physicalspace, :left_virtualspace, :right_virtualspace)
105107
@eval $f_space(t::MultilineMPS, i::Int, j::Int) = $f_space(t[i], j)
106108
@eval $f_space(t::MultilineMPS, I::CartesianIndex{2}) = $f_space(t, Tuple(I)...)

test/states.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module TestStates
2424
L = rand(3:20)
2525
ψ = FiniteMPS(rand, elt, L, d, D)
2626

27+
@test isfinite(ψ)
2728
@test @constinferred physicalspace(ψ) == fill(d, L)
2829
@test all(x -> x D, @constinferred left_virtualspace(ψ))
2930
@test all(x -> x D, @constinferred right_virtualspace(ψ))
@@ -99,6 +100,7 @@ module TestStates
99100

100101
ψ = InfiniteMPS([rand(elt, D * d, D), rand(elt, D * d, D)]; tol)
101102

103+
@test !isfinite(ψ)
102104
@test physicalspace(ψ) == fill(d, 2)
103105
@test all(x -> x D, left_virtualspace(ψ))
104106
@test all(x -> x D, right_virtualspace(ψ))

0 commit comments

Comments
 (0)