Open
Conversation
vict0rsch
reviewed
Aug 1, 2025
|
|
||
| def aggregate_results(self, values: list[float | None]) -> Dict[str, Any]: | ||
| """Aggregate results into final metric values.""" | ||
| valid_values = [v for v in values if v is not None] |
Contributor
There was a problem hiding this comment.
Although not critical, I would consider using arrays rather than lists in such operations.
values = np.array(values, dtype=float)
valid_values = values[~np.isnan(values)]
...
success_values = (valid_values == self.config.target_value).sum()
success_rate = success_values.mean()
... # etc.
vict0rsch
reviewed
Aug 1, 2025
|
|
||
| def aggregate_results(self, values: list[float]) -> Dict[str, Any]: | ||
| """Aggregate results into final metric values.""" | ||
| valid_values = [v for v in values if not np.isnan(v)] |
Contributor
There was a problem hiding this comment.
Same, working with arrays would be faster.
Even such a simple manipulation is 10x faster with arrays:
In [1]: import numpy as np
In [2]: data = np.random.randint(0, 100, (10000,)).astype(float)
In [3]: data[data<5] = float("nan")
In [4]: values = data.tolist()
In [5]: %timeit [v for v in values if not np.isnan(v)]
3.73 ms ± 67.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [6]: %timeit (w:= np.array(values))[~np.isnan(w)]
267 µs ± 1.33 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
vict0rsch
approved these changes
Aug 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on @andaero and @smglsn12, and expands on the possible conditional metrics to write. This introduces a framework for both: