Skip to content

Commit

Permalink
Add test for compound binning correction
Browse files Browse the repository at this point in the history
  • Loading branch information
eguiraud committed Dec 1, 2023
1 parent 08f8776 commit f062258
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,6 @@ def test_unsupported_correction():
CorrectionWithGradient(schemas["categorical"])


def test_unsupported_compound_binning():
with pytest.raises(
ValueError,
match=(
"Correction 'compound non-uniform binning' contains a compound "
"Binning correction \\(one or more of the bin contents are not "
"simple scalars\\). This is not supported."
),
):
CorrectionWithGradient(schemas["compound-nonuniform-binning"])


def test_unsupported_flow_type():
with pytest.raises(
ValueError,
Expand Down Expand Up @@ -428,3 +416,13 @@ def test_formula_with_parameters(jit):
assert np.allclose(values, [5.0, 7.0])
assert len(grads) == 2
assert np.allclose(grads, [2.0, 2.0])


def test_unsupported_compound_binning():
cg = CorrectionWithGradient(schemas["compound-nonuniform-binning"])
value = cg.evaluate(0.5)
assert math.isclose(value, 0.5 * 0.5)

value, grad = jax.value_and_grad(cg.evaluate)(0.5)
assert math.isclose(value, 0.5 * 0.5)
assert math.isclose(grad, 1.0)

0 comments on commit f062258

Please sign in to comment.