From 385a6f8d83c6563f7c3d66992b7776f49a152b0a Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Thu, 23 Jul 2020 20:46:10 -0500 Subject: [PATCH] Add mle.fit tests for shape of returns --- tests/test_infer.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_infer.py b/tests/test_infer.py index 089539816e..8634f7efe8 100644 --- a/tests/test_infer.py +++ b/tests/test_infer.py @@ -20,6 +20,36 @@ def check_uniform_type(in_list): ) +def test_mle_fit_default(tmpdir, hypotest_args): + """ + Check that the default return structure of pyhf.infer.mle.fit is as expected + """ + tb = pyhf.tensorlib + + _, data, model = hypotest_args + kwargs = {} + result = pyhf.infer.mle.fit(data, model, **kwargs) + # bestfit_pars + assert isinstance(result, type(tb.astensor(result))) + assert pyhf.tensorlib.shape(result) == (model.config.npars,) + + +def test_mle_fit_return_fitted_val(tmpdir, hypotest_args): + """ + Check that the return structure of pyhf.infer.mle.fit with the + return_fitted_val keyword arg is as expected + """ + tb = pyhf.tensorlib + + _, data, model = hypotest_args + kwargs = {"return_fitted_val": True} + result = pyhf.infer.mle.fit(data, model, **kwargs) + # bestfit_pars, twice_nll + assert pyhf.tensorlib.shape(result[0]) == (model.config.npars,) + assert isinstance(result[0], type(tb.astensor(result[0]))) + assert pyhf.tensorlib.shape(result[1]) == () + + def test_hypotest_default(tmpdir, hypotest_args): """ Check that the default return structure of pyhf.infer.hypotest is as expected