@@ -71,16 +71,12 @@ struct FiniteMPS{A <: GenericMPSTensor, B <: MPSBondTensor} <: AbstractFiniteMPS
7171 return new {A, B} (ALs, ARs, ACs, Cs)
7272 end
7373
74- # constructor from spaces
75- function FiniteMPS {A, B} (
76- :: UndefInitializer , manifold:: FiniteMPSManifold
77- ) where {A <: GenericMPSTensor , B <: MPSBondTensor }
78- L = length (manifold)
79- ALs = Union{Missing, A}[A (undef, manifold[i]) for i in 1 : L]
74+ # undef constructor
75+ function FiniteMPS {A, B} (:: UndefInitializer , L:: Integer ) where {A, B}
76+ ALs = Vector {Union{Missing, A}} (missing , L)
8077 ARs = Vector {Union{Missing, A}} (missing , L)
8178 ACs = Vector {Union{Missing, A}} (missing , L)
8279 Cs = Vector {Union{Missing, B}} (missing , L + 1 )
83- Cs[end ] = B (undef, right_virtualspace (manifold, L) ← right_virtualspace (manifold, L))
8480 return new {A, B} (ALs, ARs, ACs, Cs)
8581 end
8682end
@@ -199,28 +195,27 @@ Constructors
199195===========================================================================================#
200196
201197function FiniteMPS (As:: Vector{<:GenericMPSTensor} ; normalize:: Bool = false )
202- # left-gauge the input tensors
198+ mps = FiniteMPS
199+
200+ # start with first in case eltype changes
203201 AL1, C = qr_compact (As[i])
204202 normalize && normalize! (C)
205- ALs = Vector {Union{Missing, typeof(AL1)}} (undef, length (As))
203+
204+ # instantiate the destination
205+ A = typeof (AL1)
206+ B = typeof (C)
207+ mps = FiniteMPS {A, B} (undef, length (As))
208+
209+ # left-gauge and fill the ALs and last C
210+ ALs = getfield (mps, :ALs )
206211 for i in eachindex (ALs)
207212 i == 1 && (ALs[i] = AL1; continue )
208-
209213 ALs[i], C = qr_compact! (_mul_front (C, As[i]))
210214 normalize && normalize! (C)
211215 end
216+ getfield (mps, :Cs )[end ] = C
212217
213- # generate the tensor storage
214- A = eltype (ALs)
215- ARs = Vector {Union{Missing, A}} (missing , N)
216- ACs = Vector {Union{Missing, A}} (missing , N)
217- B = typeof (C)
218- Cs = Vector {Union{Missing, B}} (missing , N + 1 )
219-
220- ALs .= As
221- Cs[end ] = C
222-
223- return FiniteMPS (ALs, ARs, ACs, Cs)
218+ return mps
224219end
225220
226221for f in (:zeros , :ones )
0 commit comments