Skip to content

Commit 4999722

Browse files
committed
Add block iterator for AdjointTensorMap
1 parent 9a75047 commit 4999722

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/tensors/adjoint.jl

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ storagetype(::Type{AdjointTensorMap{T,S,N₁,N₂,TT}}) where {T,S,N₁,N₂,TT}
2525
#----------------------
2626
block(t::AdjointTensorMap, s::Sector) = block(parent(t), s)'
2727

28-
function blocks(t::AdjointTensorMap)
29-
iter = Base.Iterators.map(blocks(parent(t))) do (c, b)
30-
return c => b'
31-
end
32-
return iter
28+
blocks(t::AdjointTensorMap) = BlockIterator(t, blocks(parent(t)))
29+
30+
function blocktype(::Type{TT}) where {T,TT<:AdjointTensorMap{T}}
31+
return Base.promote_op(adjoint, blocktype(T))
32+
end
33+
34+
function Base.iterate(iter::BlockIterator{<:AdjointTensorMap}, state...)
35+
next = iterate(iter.structure, state...)
36+
isnothing(next) && return next
37+
(c, b), newstate = next
38+
return c => adjoint(b), newstate
39+
end
40+
41+
function Base.getindex(iter::BlockIterator{<:AdjointTensorMap}, c::Sector)
42+
return adjoint(Base.getindex(iter.structure, c))
3343
end
3444

3545
function Base.getindex(t::AdjointTensorMap{T,S,N₁,N₂},

0 commit comments

Comments
 (0)