Skip to content

Commit cd3ea9f

Browse files
fix: Tensor conversion for expected aux and actual data (#1038)
* Make args of Model.expected_actualdata and Model.expected_auxdata tensors - Gives parity with Model.expected_data * Add tests for Model object interaction with own API
1 parent bff6b63 commit cd3ea9f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/pyhf/pdf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ def expected_auxdata(self, pars):
609609
Tensor: The expected data of the auxiliary pdf
610610
611611
"""
612+
tensorlib, _ = get_backend()
613+
pars = tensorlib.astensor(pars)
612614
return self.make_pdf(pars)[1].expected_data()
613615

614616
def _modifications(self, pars):
@@ -630,6 +632,8 @@ def expected_actualdata(self, pars):
630632
Tensor: The expected data of the main model (no auxiliary data)
631633
632634
"""
635+
tensorlib, _ = get_backend()
636+
pars = tensorlib.astensor(pars)
633637
return self.make_pdf(pars)[0].expected_data()
634638

635639
def expected_data(self, pars, include_auxdata=True):

tests/test_pdf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def test_pdf_basicapi_tests(backend):
133133
[60.0, 51.020408630], 1e-08
134134
)
135135

136+
assert tensorlib.tolist(pdf.expected_actualdata(pars)) == pytest.approx(
137+
[60.0], 1e-08
138+
)
139+
assert tensorlib.tolist(pdf.expected_auxdata(pars)) == pytest.approx(
140+
[51.020408630], 1e-08
141+
)
142+
136143
pdf = pyhf.simplemodels.hepdata_like(
137144
source['bindata']['sig'],
138145
source['bindata']['bkg'],

0 commit comments

Comments
 (0)