Skip to content

Commit

Permalink
rewrite evaluable loops using Loop base class
Browse files Browse the repository at this point in the history
Currently there are 2.5 implementations for evaluable loops: `LoopSum`,
`LoopConcatenate` and `LoopConcatenateCombined`. The first loop is the most
common one (before sparsification). The second appears after sparsification.
The last loop is created only during the 'optimize for numpy' stage and is a
combination of several concatenates in a single loop for performance reasons.

This patch introduces a base class for evaluable loops and rewrites `LoopSum`
and `LoopConcatenate` as implementations of the base class. The base class
requires two methods to be implemented: one for initializing the output value
and one for updating the output value for each iteration.

Due to the generic nature of the base class, the method for updating the output
value is guarded with a multiprocessing lock if the loop is evaluated in
parallel, even when this is not necessary, e.g. for `LoopConcatenate`. To
minimize the impact of locking, the lock used to increment the loop index is
reused for updating the the output value.

In addition this patch replaces `LoopConcatenateCombined` with `LoopTuple`,
which supports any combination of loop evaluables, not just `LoopConcatenate`.
  • Loading branch information
joostvanzwieten committed Mar 21, 2024
1 parent 89977c8 commit 2371c9a
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 264 deletions.
Loading

0 comments on commit 2371c9a

Please sign in to comment.