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

Fix Base.similar for physical and contractible network types #149

Merged
merged 3 commits into from
Mar 9, 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
5 changes: 3 additions & 2 deletions src/networks/infinitesquarenetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
Base.eltype(::Type{InfiniteSquareNetwork{O}}) where {O} = O

Base.copy(n::InfiniteSquareNetwork) = InfiniteSquareNetwork(copy(unitcell(n)))
function Base.similar(n::InfiniteSquareNetwork, args...)
return InfiniteSquareNetwork(similar(unitcell(n), args...))
function Base.similar(n::InfiniteSquareNetwork, T::Type{TorA}=scalartype(n)) where {TorA}
return InfiniteSquareNetwork(map(t -> similar(t, T), unitcell(n)))

Check warning on line 34 in src/networks/infinitesquarenetwork.jl

View check run for this annotation

Codecov / codecov/patch

src/networks/infinitesquarenetwork.jl#L33-L34

Added lines #L33 - L34 were not covered by tests
end
function Base.repeat(n::InfiniteSquareNetwork, counts...)
return InfiniteSquareNetwork(repeat(unitcell(n), counts...))
Expand All @@ -53,6 +53,7 @@
virtualspace(n::InfiniteSquareNetwork, r::Int, c::Int, dir) = virtualspace(n[r, c], dir)

## Vector interface

function VectorInterface.scalartype(::Type{T}) where {T<:InfiniteSquareNetwork}
return scalartype(eltype(T))
end
Expand Down
13 changes: 12 additions & 1 deletion src/operators/infinitepepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@
Base.eltype(A::InfinitePEPO) = eltype(typeof(A))

Base.copy(A::InfinitePEPO) = InfinitePEPO(copy(unitcell(A)))
Base.similar(A::InfinitePEPO, args...) = InfinitePEPO(similar(unitcell(A), args...))
function Base.similar(A::InfinitePEPO, T::Type{TorA}=scalartype(A)) where {TorA}
return InfinitePEPO(map(t -> similar(t, T), unitcell(A)))

Check warning on line 135 in src/operators/infinitepepo.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/infinitepepo.jl#L134-L135

Added lines #L134 - L135 were not covered by tests
end
Base.repeat(A::InfinitePEPO, counts...) = InfinitePEPO(repeat(unitcell(A), counts...))

Base.getindex(A::InfinitePEPO, args...) = Base.getindex(unitcell(A), args...)
Expand Down Expand Up @@ -169,6 +171,15 @@
)
end

## Vector interface

function VectorInterface.scalartype(::Type{NT}) where {NT<:InfinitePEPO}
return scalartype(eltype(NT))

Check warning on line 177 in src/operators/infinitepepo.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/infinitepepo.jl#L176-L177

Added lines #L176 - L177 were not covered by tests
end
function VectorInterface.zerovector(A::InfinitePEPO)
return InfinitePEPO(zerovector(unitcell(A)))

Check warning on line 180 in src/operators/infinitepepo.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/infinitepepo.jl#L179-L180

Added lines #L179 - L180 were not covered by tests
end

## (Approximate) equality
function Base.:(==)(A₁::InfinitePEPO, A₂::InfinitePEPO)
return all(zip(unitcell(A₁), unitcell(A₂))) do (p₁, p₂)
Expand Down
15 changes: 13 additions & 2 deletions src/states/infinitepartitionfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@
Base.eltype(A::InfinitePartitionFunction) = eltype(typeof(A))

Base.copy(A::InfinitePartitionFunction) = InfinitePartitionFunction(copy(unitcell(A)))
function Base.similar(A::InfinitePartitionFunction, args...)
return InfinitePartitionFunction(similar(unitcell(A), args...))
function Base.similar(

Check warning on line 123 in src/states/infinitepartitionfunction.jl

View check run for this annotation

Codecov / codecov/patch

src/states/infinitepartitionfunction.jl#L123

Added line #L123 was not covered by tests
A::InfinitePartitionFunction, T::Type{TorA}=scalartype(A)
) where {TorA}
return InfinitePartitionFunction(map(t -> similar(t, T), unitcell(A)))

Check warning on line 126 in src/states/infinitepartitionfunction.jl

View check run for this annotation

Codecov / codecov/patch

src/states/infinitepartitionfunction.jl#L126

Added line #L126 was not covered by tests
end
function Base.repeat(A::InfinitePartitionFunction, counts...)
return InfinitePartitionFunction(repeat(unitcell(A), counts...))
Expand All @@ -147,6 +149,15 @@
return InfiniteSquareNetwork(unitcell(state))
end

## Vector interface

function VectorInterface.scalartype(::Type{NT}) where {NT<:InfinitePartitionFunction}
return scalartype(eltype(NT))

Check warning on line 155 in src/states/infinitepartitionfunction.jl

View check run for this annotation

Codecov / codecov/patch

src/states/infinitepartitionfunction.jl#L154-L155

Added lines #L154 - L155 were not covered by tests
end
function VectorInterface.zerovector(A::InfinitePartitionFunction)
return InfinitePartitionFunction(zerovector(unitcell(A)))

Check warning on line 158 in src/states/infinitepartitionfunction.jl

View check run for this annotation

Codecov / codecov/patch

src/states/infinitepartitionfunction.jl#L157-L158

Added lines #L157 - L158 were not covered by tests
end

## (Approximate) equality
function Base.:(==)(A₁::InfinitePartitionFunction, A₂::InfinitePartitionFunction)
return all(zip(unitcell(A₁), unitcell(A₂))) do (p₁, p₂)
Expand Down
4 changes: 3 additions & 1 deletion src/states/infinitepeps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
Base.eltype(A::InfinitePEPS) = eltype(typeof(A))

Base.copy(A::InfinitePEPS) = InfinitePEPS(copy(unitcell(A)))
Base.similar(A::InfinitePEPS, args...) = InfinitePEPS(similar(unitcell(A), args...))
function Base.similar(A::InfinitePEPS, T::Type{TorA}=scalartype(A)) where {TorA}
return InfinitePEPS(map(t -> similar(t, T), unitcell(A)))

Check warning on line 126 in src/states/infinitepeps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/infinitepeps.jl#L125-L126

Added lines #L125 - L126 were not covered by tests
end
Base.repeat(A::InfinitePEPS, counts...) = InfinitePEPS(repeat(unitcell(A), counts...))

Base.getindex(A::InfinitePEPS, args...) = Base.getindex(unitcell(A), args...)
Expand Down