Speed up compute_metrics()#144
Merged
Merged
Conversation
…jects Build y_true [N,D,H], y_pred [N,D,H], q_pred [N,D,H,Q], and y_past [total_T, D] + indptr [N+1] once per window in compute_metrics, then pass to all metric.compute() calls. Avoids repeated column access and array construction per metric per dimension.
- Replace HF Dataset column access with pc.list_flatten + to_numpy for building y_true, y_pred, q_pred, y_past arrays (~100x faster) - Replace .cast(schema) + numpy finite check with pyarrow-native validation: check column names, list lengths, and pc.is_finite - Total evaluation_summary speedup: 18.6s -> 0.48s (39x) on 35-dim multivariate task with 10 windows
- Replace .cast() + numpy finite check with pyarrow-native validation: check column names, list lengths via pc.list_value_length, and pc.is_finite on flattened arrays - Fix combine_univariate_predictions_to_multivariate to use table.take() instead of Dataset.select() to avoid lazy _indices views - evaluation_summary: 18.6s -> 0.5s on 35-dim task with 10 windows
_safemean(arr, axis=(0, 1)) replaces the manual [self._safemean(arr[:, :, d]) for d in range(D)] pattern.
…per_item Passing lengths [N] is simpler than CSR-style indptr [N+1] — offsets are only needed inside _seasonal_error_per_item and are cheap to reconstruct. Rename back to _per_item to clarify return shape [N, D].
abdulfatir
approved these changes
May 18, 2026
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.
Issue #, if available:
Description of changes:
Metric.compute()to accept pre-built numpy arrays (y_true [N,H,D],y_pred [N,H,D],q_pred [N,H,D,Q],y_past [total_T, D]+y_past_lengths [N]) instead of HFDatasetobjects. Arrays are built once per window incompute_metricsand shared across all metrics.pc.list_flatten,pc.list_value_length,pc.is_finite) for array construction and prediction validation, replacing HF Dataset column access and the expensive.cast()+ numpy finite check.combine_univariate_predictions_to_multivariateto usetable.take()instead ofDataset.select(), avoiding lazy_indicesviews that break direct Arrow table access.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.