@@ -421,28 +421,35 @@ end
421421
422422# Getting and setting the data at the block level
423423# -------------------------------------------------
424- function block (t:: TensorMap , s:: Sector )
425- sectortype (t) == typeof (s) || throw (SectorMismatch ())
426- structure = fusionblockstructure (t). blockstructure
427- (d₁, d₂), r = get (structure, s) do
424+ block (t:: TensorMap , c:: Sector ) = blocks (t)[c]
425+
426+ blocks (t:: TensorMap ) = BlockIterator (t, fusionblockstructure (t). blockstructure)
427+
428+ function blocktype (:: Type{TT} ) where {TT<: TensorMap }
429+ A = storagetype (TT)
430+ T = eltype (A)
431+ return Base. ReshapedArray{T,2 ,SubArray{T,1 ,A,Tuple{UnitRange{Int}},true },Tuple{}}
432+ end
433+
434+ function Base. iterate (iter:: BlockIterator{<:TensorMap} , state... )
435+ next = iterate (iter. structure, state... )
436+ isnothing (next) && return next
437+ (c, (sz, r)), newstate = next
438+ return c => reshape (view (iter. t. data, r), sz), newstate
439+ end
440+
441+ function Base. getindex (iter:: BlockIterator{<:TensorMap} , c:: Sector )
442+ sectortype (iter. t) === typeof (c) || throw (SectorMismatch ())
443+ (d₁, d₂), r = get (iter. structure, c) do
428444 # is s is not a key, at least one of the two dimensions will be zero:
429445 # it then does not matter where exactly we construct a view in `t.data`,
430446 # as it will have length zero anyway
431- d₁′ = blockdim (codomain (t), s )
432- d₂′ = blockdim (domain (t), s )
447+ d₁′ = blockdim (codomain (iter . t), c )
448+ d₂′ = blockdim (domain (iter . t), c )
433449 l = d₁′ * d₂′
434450 return (d₁′, d₂′), 1 : l
435451 end
436- return reshape (view (t. data, r), (d₁, d₂))
437- end
438-
439- function blocks (t:: TensorMap )
440- structure = fusionblockstructure (t). blockstructure
441- iter = Base. Iterators. map (structure) do (c, ((d₁, d₂), r))
442- b = reshape (view (t. data, r), (d₁, d₂))
443- return c => b
444- end
445- return iter
452+ return reshape (view (iter. t. data, r), (d₁, d₂))
446453end
447454
448455# Indexing and getting and setting the data at the subblock level
@@ -559,18 +566,22 @@ function Base.show(io::IO, t::TensorMap)
559566 if sectortype (t) == Trivial
560567 Base. print_array (io, t[])
561568 println (io)
562- elseif FusionStyle (sectortype (t)) isa UniqueFusion
563- for (f₁, f₂) in fusiontrees (t)
564- println (io, " * Data for sector " , f₁. uncoupled, " ← " , f₂. uncoupled, " :" )
565- Base. print_array (io, t[f₁, f₂])
566- println (io)
567- end
568569 else
569- for (f₁, f₂) in fusiontrees (t)
570- println (io, " * Data for fusiontree " , f₁, " ← " , f₂, " :" )
571- Base. print_array (io, t[f₁, f₂])
572- println (io)
570+ for (c, b) in blocks (t)
571+ println (io, " * Data for sector $c :" )
572+ Base. print_array (io, b)
573573 end
574+ # for (f₁, f₂) in fusiontrees(t)
575+ # println(io, "* Data for sector ", f₁.uncoupled, " ← ", f₂.uncoupled, ":")
576+ # Base.print_array(io, t[f₁, f₂])
577+ # println(io)
578+ # end
579+ # else
580+ # for (f₁, f₂) in fusiontrees(t)
581+ # println(io, "* Data for fusiontree ", f₁, " ← ", f₂, ":")
582+ # Base.print_array(io, t[f₁, f₂])
583+ # println(io)
584+ # end
574585 end
575586end
576587
0 commit comments