File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,12 @@ def log1mexp_numpy(x):
243
243
For details, see
244
244
https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf
245
245
"""
246
- return np .where (x < 0.6931471805599453 , np .log (- np .expm1 (- x )), np .log1p (- np .exp (- x )))
246
+ x = np .asarray (x )
247
+ mask = x < 0.6931471805599453
248
+ x [mask ] = np .log (- np .expm1 (- x [mask ]))
249
+ mask = ~ mask
250
+ x [mask ] = np .log1p (- np .exp (- x [mask ]))
251
+ return x
247
252
248
253
249
254
def flatten_list (tensors ):
Original file line number Diff line number Diff line change @@ -153,6 +153,13 @@ def test_log1mexp():
153
153
npt .assert_allclose (actual_ , expected )
154
154
155
155
156
+ def test_log1mexp_numpy_no_warning ():
157
+ """Assert RuntimeWarning is not raised for very small numbers"""
158
+ with pytest .warns (None ) as record :
159
+ log1mexp_numpy (1e-25 )
160
+ assert not record
161
+
162
+
156
163
class TestLogDet (SeededTest ):
157
164
def setup_method (self ):
158
165
super ().setup_method ()
You can’t perform that action at this time.
0 commit comments