File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -349,3 +349,18 @@ function fusionblockstructure(W::HomSpace, ::GlobalLRUCache)
349349 end
350350 return structure
351351end
352+
353+ # Diagonal ranges
354+ # ----------------
355+ # TODO : is this something we want to cache?
356+ function diagonalblockstructure (W:: HomSpace )
357+ structure = SectorDict {sectortype(W),UnitRange{Int}} () # range
358+ offset = 0
359+ dom = domain (W)[1 ]
360+ for c in blocksectors (W)
361+ d = dim (dom, c)
362+ structure[c] = offset .+ (1 : d)
363+ offset + d
364+ end
365+ return structure
366+ end
Original file line number Diff line number Diff line change @@ -110,7 +110,21 @@ function block(d::DiagonalTensorMap, s::Sector)
110110 return Diagonal (view (d. data, 1 : 0 ))
111111end
112112
113- # TODO : is relying on generic AbstractTensorMap blocks sufficient?
113+ blocks (t:: DiagonalTensorMap ) = BlockIterator (t, diagonalblockstructure (space (t)))
114+ blocktype (:: Type{TT} ) where {TT<: DiagonalTensorMap } = Diagonal{eltype (TT),storagetype (TT)}
115+
116+ function Base. iterate (iter:: BlockIterator{<:DiagonalTensorMap} , state... )
117+ next = iterate (iter. structure, state... )
118+ isnothing (next) && return next
119+ (c, r), newstate = next
120+ return c => Diagonal (view (iter. t. data, r)), newstate
121+ end
122+
123+ function Base. getindex (iter:: BlockIterator{<:DiagonalTensorMap} , c:: Sector )
124+ sectortype (iter. t) === typeof (c) || throw (SectorMismatch ())
125+ r = get (iter. structure, c, 1 : 0 )
126+ return Diagonal (view (iter. t. data, r))
127+ end
114128
115129# Indexing and getting and setting the data at the subblock level
116130# -----------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments