Skip to content

Commit

Permalink
Adding regression tests for binomial coefficient overflow.
Browse files Browse the repository at this point in the history
Follow-up to #156.
  • Loading branch information
dhermes committed Jan 4, 2020
1 parent ce54b48 commit c4e473a
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tests/unit/test__curve_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,119 @@ def test_quadratic(self):
expected[1, :] = 2.0 * s_vals * (2.0 * s_vals - 1.0)
self.assertEqual(result, expected)

def test_binomial_overflow_int32(self):
s_vals = np.asfortranarray([0.5])
degree = 30
nodes = np.eye(degree + 1, order="F")

expected = np.asfortranarray(
[
1.0,
30.0,
435.0,
4060.0,
27405.0,
142506.0,
593775.0,
2035800.0,
5852925.0,
14307150.0,
30045015.0,
54627300.0,
86493225.0,
119759850.0,
145422675.0,
155117520.0,
145422675.0,
119759850.0,
86493225.0,
54627300.0,
30045015.0,
14307150.0,
5852925.0,
2035800.0,
593775.0,
142506.0,
27405.0,
4060.0,
435.0,
30.0,
1.0,
]
)
evaluated = self._call_function_under_test(nodes, s_vals)
binomial_coefficients = evaluated.flatten() * 2.0 ** degree
self.assertEqual(expected, binomial_coefficients)

def test_binomial_roundoff(self):
s_vals = np.asfortranarray([0.5])
degree = 55
nodes = np.eye(degree + 1, order="F")

expected = np.asfortranarray(
[
1.0,
55.0,
1485.0,
26235.0,
341055.0,
3478761.0,
28989675.0,
202927725.0,
1217566350.0,
6358402050.0,
29248649430.0,
119653565850.0,
438729741450.0,
1451182990950.0,
4353548972850.0,
11899700525790.0,
29749251314475.0,
68248282427325.0,
144079707346575.0,
280576272201225.0,
505037289962205.0,
841728816603675.0,
1300853625660225.0,
1866442158555975.0,
2488589544741300.0,
3085851035479212.0,
3560597348629859.5,
3824345300380219.5,
3824345300380219.5,
3560597348629859.5,
3085851035479211.5,
2488589544741299.5,
1866442158555974.5,
1300853625660224.8,
841728816603674.9,
505037289962204.94,
280576272201224.94,
144079707346574.97,
68248282427324.984,
29749251314474.992,
11899700525789.996,
4353548972849.9985,
1451182990949.9995,
438729741449.9998,
119653565849.99995,
29248649429.99999,
6358402049.999997,
1217566349.9999995,
202927724.9999999,
28989674.999999985,
3478760.999999998,
341054.9999999998,
26234.999999999985,
1484.999999999999,
54.999999999999964,
1.0,
],
)
evaluated = self._call_function_under_test(nodes, s_vals)
binomial_coefficients = evaluated.flatten() * 2.0 ** degree
self.assertEqual(expected, binomial_coefficients)


@utils.needs_speedup
class Test_speedup_evaluate_multi(Test__evaluate_multi):
Expand Down

0 comments on commit c4e473a

Please sign in to comment.