@@ -15,27 +15,32 @@ Base.length(iter::BlockIterator) = length(iter.structure)
1515Base. 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
2422Apply `f` to each block of `t` and the corresponding blocks of `ts`.
2523Optionally, `scheduler` can be used to parallelize the computation.
2624This 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)
3230end
3331```
3432"""
3533function 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
4146end
0 commit comments