Skip to content

Commit 942121b

Browse files
committed
Update blockiterator
1 parent 8d289c6 commit 942121b

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/tensors/blockiterator.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@ Base.length(iter::BlockIterator) = length(iter.structure)
1515
Base.isdone(iter::BlockIterator, state...) = Base.isdone(iter.structure, state...)
1616

1717
# TODO: fast-path when structures are the same?
18-
# TODO: do we want f(c, bs...) or f(c, bs)?
1918
# TODO: implement scheduler
20-
# TODO: do we prefer `blocks(t, ts...)` instead or as well?
2119
"""
22-
foreachblock(f, t::AbstractTensorMap, ts::AbstractTensorMap...; [scheduler])
20+
foreachblock(f, ts::AbstractTensorMap...; [scheduler])
2321
2422
Apply `f` to each block of `t` and the corresponding blocks of `ts`.
2523
Optionally, `scheduler` can be used to parallelize the computation.
2624
This function is equivalent to the following loop:
2725
2826
```julia
29-
for (c, b) in blocks(t)
30-
bs = (b, block.(ts, c)...)
27+
for c in union(blocksectors.(ts)...)
28+
bs = map(t -> block(t, c), ts)
3129
f(c, bs)
3230
end
3331
```
3432
"""
3533
function foreachblock(f, t::AbstractTensorMap, ts::AbstractTensorMap...; scheduler=nothing)
36-
allsectors = union(blocksectors(t), blocksectors.(ts)...)
34+
tensors = (t, ts...)
35+
allsectors = union(blocksectors.(tensors)...)
3736
foreach(allsectors) do c
38-
return f(c, map(Base.Fix2(block, c), (t, ts...)))
37+
return f(c, block.(tensors, Ref(c)))
38+
end
39+
return nothing
40+
end
41+
function foreachblock(f, t::AbstractTensorMap; scheduler=nothing)
42+
foreach(blocks(t)) do (c, b)
43+
return f(c, (b,))
3944
end
4045
return nothing
4146
end

0 commit comments

Comments
 (0)