FEAT: accept array-valued parameters - #583
Open
grayson-helmholz wants to merge 8 commits into
Open
Conversation
redeboer
force-pushed
the
FEAT/array-parameters
branch
from
August 31, 2026 14:44
9903461 to
83fb16a
Compare
redeboer
force-pushed
the
FEAT/array-parameters
branch
from
September 1, 2026 08:59
83fb16a to
c5371a1
Compare
redeboer
reviewed
Sep 1, 2026
Member
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'TensorWaves benchmark results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.
| Benchmark suite | Current: 1a4a844 | Previous: f5c1db9 | Ratio |
|---|---|---|---|
benchmarks/ampform.py::TestJPsiToGammaPiPi::test_fit[10000-jax] |
0.5013097544496096 iter/sec (stddev: 0) |
1.439081184425215 iter/sec (stddev: 0) |
2.87 |
This comment was automatically generated by workflow using github-action-benchmark.
Parameter values passed to ChiSquared and UnbinnedNLL may now be one-dimensional arrays of shape (p,), which are broadcast against the event axis so that the estimator returns one value per parameter point, all in a single backend-parallelized call. This makes it cheap to e.g. propagate fit uncertainties over bootstrapped parameter samples, as done in ComPWA/polarimetry. Behavior for scalar parameter values is unchanged. Closes #571
redeboer
force-pushed
the
FEAT/array-parameters
branch
from
September 1, 2026 09:30
c5371a1 to
4f87c81
Compare
redeboer
force-pushed
the
FEAT/array-parameters
branch
from
September 1, 2026 10:10
7c4412a to
1dca885
Compare
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.
Closes #571
✨ New features
Estimators now accept array-valued parameters. A parameter value of shape
(p,)representspparameter points, and the estimator returns an array ofpestimator values — one per point — computed in a single, backend-parallelized call. Scalar parameter values behave exactly as before and still yield a scalar.The main use case is propagating fit uncertainties: a set of bootstrapped or sampled parameter points can be evaluated in one vectorized call rather than in a Python loop, and on the JAX backend that call is JIT-compiled like any other estimator evaluation.
New public type alias
ParameterTypeintensorwaves.interface, which isParameterValue | Array. It is now used wherever a parameter value is accepted:ParametrizedFunction.__call__,Estimator.__call__, and the estimator implementations.ParameterValuekeeps its meaning and now documents itself as the scalar parameter type.Array parameters are given a trailing axis on entry, so that they broadcast against the event axis of a
DataSample, and the estimator reductions consequently reduce over the event axis (axis=-1) rather than over the whole array.Estimator.__call__is annotated as returningfloat | FloatArrayto reflect the new array case.New public type aliases
ArrayandFloatArrayintensorwaves.interface.Arrayisnp.ndarray[Any, np.dtype[ScalarT]], generic in its scalar type through the newScalarTtype variable, which defaults toAnyso that a bareArraystays dtype-agnostic.FloatArrayisArray[np.floating], for arrays that have to be real-valued.DataSampleis nowdict[str, Array].⚙️ Enhancements
Estimator.__call__and both estimator implementations are now@overload-ed, so that a mapping of scalar parameter values is typed as returningfloat, a mapping of arrays as returningFloatArray, and a mixed mapping asfloat | FloatArray. Callers no longer have to narrow the return type themselves.Function signatures that necessarily take a real-valued function are narrowed from$f_\mathbf{p}: X^m \rightarrow \mathbb{R}$ . Signatures that are genuinely dtype-agnostic keep a bare
ArraytoFloatArray:ChiSquared,UnbinnedNLL, andIntensityDistributionGenerator. This matches what their docstrings already state, namely that they work on an intensityArray, because a lambdified expression may well be complex-valued:ParametrizedBackendFunction,PositionalArgumentFunction,create_cached_function, andSympyDataTransformer.🔨 Maintenance
All remaining
np.ndarrayannotations are replaced with theArrayalias, so that the array type is defined in one place and can be narrowed per site. Sphinx is taught to resolve the new aliases (Array,FloatArray,ScalarT) throughapi_target_substitutionsandautodoc_type_aliases.typing-extensions >=4.4.0becomes a runtime dependency on Python <3.13, becauseScalarTneeds PEP 696 type-variable defaults.The callback logs in
ScipyMinimizernow reuse the estimator value that was just computed, instead of re-evaluating the estimator for the log and casting the cached value withfloat(). The cast on the value that is handed back to SciPy itself stays, since SciPy needs a scalar.Squash commit messages