Skip to content

Commit 8c8b851

Browse files
committed
fix possibly-in-place-copy
1 parent d06ac32 commit 8c8b851

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/states/infinitemps.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,19 @@ Base.size(ψ::InfiniteMPS, args...) = size(ψ.AL, args...)
237237
Base.length::InfiniteMPS) = length.AL)
238238
Base.eltype::InfiniteMPS) = eltype(typeof(ψ))
239239
Base.eltype(::Type{<:InfiniteMPS{A}}) where {A} = A
240+
240241
Base.copy::InfiniteMPS) = InfiniteMPS(copy.AL), copy.AR), copy.C), copy.AC))
241242
function Base.copy!::InfiniteMPS, ϕ::InfiniteMPS)
242-
copy!.(ψ.AL, ϕ.AL)
243-
copy!.(ψ.AR, ϕ.AR)
244-
copy!.(ψ.AC, ϕ.AC)
245-
copy!.(ψ.C, ϕ.C)
243+
ψ.AL .= _copy!!.(ψ.AL, ϕ.AL)
244+
ψ.AR .= _copy!!.(ψ.AR, ϕ.AR)
245+
ψ.AC .= _copy!!.(ψ.AC, ϕ.AC)
246+
ψ.C .= _copy!!.(ψ.C, ϕ.C)
246247
return ψ
247248
end
249+
# possible in-place copy
250+
function _copy!!(dst::AbstractTensorMap, src::AbstractTensorMap)
251+
return space(dst) == space(src) ? copy!(dst, src) : copy(src)
252+
end
248253

249254
function Base.complex::InfiniteMPS)
250255
scalartype(ψ) <: Complex && return ψ

0 commit comments

Comments
 (0)