@@ -240,3 +240,28 @@ def test_2f1_grad(self, muts, hyp2f1_func, pars):
240240 offset = self ._2f1_validate (* pars )
241241 check = self ._2f1_grad_validate (* pars , offset = offset )
242242 assert np .allclose (grad , check )
243+
244+
245+ @pytest .mark .parametrize (
246+ "pars" ,
247+ [
248+ # taken from examples in issues tsdate/286, tsdate/289
249+ [1.104 , 0.0001125 , 118.1396 , 0.009052 , 1.0 , 0.001404 ],
250+ [2.7481 , 0.001221 , 344.94083 , 0.02329 , 3.0 , 0.00026624 ],
251+ ],
252+ )
253+ class TestSingular2F1 :
254+ """
255+ Test detection of cases where 2F1 is close to singular and DLMF 15.8.3
256+ suffers from catastrophic cancellation: in these cases, use DLMF 15.8.1
257+ even though it takes much longer to converge.
258+ """
259+
260+ def test_dlmf1583_throws_exception (self , pars ):
261+ with pytest .raises (Exception , match = "is singular" ):
262+ hypergeo ._hyp2f1_dlmf1583 (* pars )
263+
264+ def test_exception_uses_dlmf1581 (self , pars ):
265+ v1 , * _ = hypergeo ._hyp2f1 (* pars )
266+ v2 , * _ = hypergeo ._hyp2f1_dlmf1581 (* pars )
267+ assert np .isclose (v1 , v2 )
0 commit comments