File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,3 +13,28 @@ Base.IteratorEltype(::BlockIterator) = Base.HasEltype()
1313Base. eltype (:: Type{<:BlockIterator{T}} ) where {T} = blocktype (T)
1414Base. length (iter:: BlockIterator ) = length (iter. structure)
1515Base. isdone (iter:: BlockIterator , state... ) = Base. isdone (iter. structure, state... )
16+
17+ # TODO : fast-path when structures are the same?
18+ # TODO : do we want f(c, bs...) or f(c, bs)?
19+ # TODO : implement scheduler
20+ # TODO : do we prefer `blocks(t, ts...)` instead or as well?
21+ """
22+ foreachblock(f, t::AbstractTensorMap, ts::AbstractTensorMap...; [scheduler])
23+
24+ Apply `f` to each block of `t` and the corresponding blocks of `ts`.
25+ Optionally, `scheduler` can be used to parallelize the computation.
26+ This function is equivalent to the following loop:
27+
28+ ```julia
29+ for (c, b) in blocks(t)
30+ bs = (b, block.(ts, c)...)
31+ f(c, bs)
32+ end
33+ ```
34+ """
35+ function foreachblock (f, t:: AbstractTensorMap , ts:: AbstractTensorMap... ; scheduler= nothing )
36+ foreach (blocks (t)) do (c, b)
37+ return f (c, (b, block .(ts, c)... ))
38+ end
39+ return nothing
40+ end
You can’t perform that action at this time.
0 commit comments