@@ -15,8 +15,7 @@ struct TensorMap{T, S <: IndexSpace, N₁, N₂, A <: DenseVector{T}} <: Abstrac
1515 function TensorMap {T, S, N₁, N₂, A} (
1616 :: UndefInitializer , space:: TensorMapSpace{S, N₁, N₂}
1717 ) where {T, S <: IndexSpace , N₁, N₂, A <: DenseVector{T} }
18- d = fusionblockstructure (space). totaldim
19- data = A (undef, d)
18+ data = A (undef, dim (space))
2019 if ! isbitstype (T)
2120 zerovector! (data)
2221 end
@@ -31,8 +30,7 @@ struct TensorMap{T, S <: IndexSpace, N₁, N₂, A <: DenseVector{T}} <: Abstrac
3130 I = sectortype (S)
3231 T <: Real && ! (sectorscalartype (I) <: Real ) &&
3332 @warn (" Tensors with real data might be incompatible with sector type $I " , maxlog = 1 )
34- d = fusionblockstructure (space). totaldim
35- length (data) == d || throw (DimensionMismatch (" invalid length of data" ))
33+ length (data) == dim (space) || throw (DimensionMismatch (" invalid length of data" ))
3634 return new {T, S, N₁, N₂, A} (data, space)
3735 end
3836end
453451# -------------------------------------------------
454452block (t:: TensorMap , c:: Sector ) = blocks (t)[c]
455453
456- blocks (t:: TensorMap ) = BlockIterator (t, fusionblockstructure (t) . blockstructure )
454+ blocks (t:: TensorMap ) = BlockIterator (t, blockstructure ( space (t)) )
457455
458456function blocktype (:: Type{TT} ) where {TT <: TensorMap }
459457 A = storagetype (TT)
@@ -462,24 +460,26 @@ function blocktype(::Type{TT}) where {TT <: TensorMap}
462460end
463461
464462function Base. iterate (iter:: BlockIterator{<:TensorMap} , state... )
465- next = iterate (iter. structure, state... )
463+ next = iterate (pairs ( iter. structure) , state... )
466464 isnothing (next) && return next
467465 (c, (sz, r)), newstate = next
468466 return c => reshape (view (iter. t. data, r), sz), newstate
469467end
470468
471469function Base. getindex (iter:: BlockIterator{<:TensorMap} , c:: Sector )
472470 sectortype (iter. t) === typeof (c) || throw (SectorMismatch ())
473- (d₁, d₂), r = get (iter. structure, c) do
474- # is s is not a key, at least one of the two dimensions will be zero:
471+ found, token = gettoken (iter. structure, c)
472+ if found
473+ (d₁, d₂), r = gettokenvalue (iter. structure, token)
474+ return reshape (view (iter. t. data, r), (d₁, d₂))
475+ else
476+ # if c is not a key, at least one of the two dimensions will be zero:
475477 # it then does not matter where exactly we construct a view in `t.data`,
476478 # as it will have length zero anyway
477- d₁′ = blockdim (codomain (iter. t), c)
478- d₂′ = blockdim (domain (iter. t), c)
479- l = d₁′ * d₂′
480- return (d₁′, d₂′), 1 : l
479+ d₁ = blockdim (codomain (iter. t), c)
480+ d₂ = blockdim (domain (iter. t), c)
481+ return reshape (view (iter. t. data, 1 : (d₁ * d₂)), (d₁, d₂))
481482 end
482- return reshape (view (iter. t. data, r), (d₁, d₂))
483483end
484484
485485# Getting and setting the data at the subblock level
0 commit comments