optimizations
Build on RHEL9 / build (push) Successful in 2m52s
Build on RHEL8 / build (push) Successful in 3m31s
Run tests using data on local RHEL8 / build (push) Successful in 4m28s

This commit is contained in:
Erik Frojdh committed 2026-09-25 18:05:43 +02:00
1 parent 1693497609
commit 5beabf1888
8 files changed
+320 -80

No files matched your search

+18 -2
View File
@@ -37,7 +37,8 @@ template <typename Model> void bind_fit_model(py::module &m, const char *name) {
by ``Minimizer.LevenbergMarquardt``.
max_calls : int
Work budget per pixel: Minuit2 function calls, or model
evaluations for ``Minimizer.LevenbergMarquardt``. 0 selects
evaluations for ``Minimizer.LevenbergMarquardt`` (one per
iteration, two when a step crosses a limit). 0 selects
Minuit's default budget.
tolerance : float
EDM tolerance in Minuit's convention. Migrad and
@@ -217,8 +218,23 @@ fit_dispatch(const aare::FitModel<Model> &model,
"chi2"_a = return_image_data(chi2_out));
}
} else {
// Unweighted fit; parameter errors are still available when
// requested, as in the 1D path.
NDView<double, 3> dummy_err{};
if (model.compute_errors()) {
auto err_out =
new NDArray<double, 3>({y.shape(0), y.shape(1), npar}, 0.0);
aare::fit_3d<Model>(model, x_view, y_view, dummy_err,
par_out->view(), err_out->view(),
chi2_out->view(), n_threads);
return py::dict("par"_a = return_image_data(par_out),
"par_err"_a = return_image_data(err_out),
"chi2"_a = return_image_data(chi2_out));
}
NDView<double, 3> dummy_err_out{};
aare::fit_3d<Model>(model, x_view, y_view, dummy_err,
+7 -2
View File
@@ -179,20 +179,25 @@ def test_scurve_fit(cls, minimizer):
@pytest.mark.parametrize("with_errors", [False, True])
def test_fit_3d_matches_fit_1d(with_errors, minimizer):
@pytest.mark.parametrize("weighted", [False, True])
def test_fit_3d_matches_fit_1d(with_errors, weighted, minimizer):
x = np.linspace(-6.0, 6.0, 61)
rows, cols = 4, 3
y = np.empty((rows, cols, x.size))
for r in range(rows):
for c in range(cols):
y[r, c] = gaussian(x, 80.0 + 10.0 * r, -0.6 + 0.3 * c, 0.9 + 0.1 * r)
y_err = np.ones_like(y) if with_errors else None
y_err = np.ones_like(y) if weighted else None
model = aare.Gaussian(compute_errors=with_errors, minimizer=minimizer)
cube = model.fit(x, y, y_err, n_threads=3)
expected_keys = {"par", "par_err", "chi2"} if with_errors else {"par", "chi2"}
assert set(cube) == expected_keys
assert cube["par"].shape == (rows, cols, 3)
assert cube["chi2"].shape == (rows, cols)
if with_errors:
assert cube["par_err"].shape == (rows, cols, 3)
for r in range(rows):
for c in range(cols):
single = model.fit(x, y[r, c], None if y_err is None else y_err[r, c])