Skip to content

Commit d8b1104

Browse files
committed
filter slogdet warnings
1 parent 9f56088 commit d8b1104

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

smodels/statistics/simplifiedLikelihoods.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import numpy as np
2222
import math
2323
import copy
24+
import warnings
2425

2526
try:
2627
from smodels.base.smodelsLogging import logger
@@ -744,7 +745,27 @@ def findThetaHat(self, mu : float ):
744745
# self.cov_tot = model.totalCovariance (nsig)
745746
self.weight = np.linalg.inv(self.cov_tot)
746747
# self.coeff = 1.
747-
logdet = np.linalg.slogdet(self.cov_tot)
748+
749+
## to catch slogdet warnings on Mac, numpy 2.3.2
750+
## added by WW&SK, 14/08/2025
751+
with warnings.catch_warnings():
752+
warnings.filterwarnings(
753+
"ignore",
754+
message="divide by zero", # pattern 1
755+
category=RuntimeWarning
756+
)
757+
warnings.filterwarnings(
758+
"ignore",
759+
message="invalid value encountered", # pattern 2
760+
category=RuntimeWarning
761+
)
762+
warnings.filterwarnings(
763+
"ignore",
764+
message="overflow encountered", # pattern 3
765+
category=RuntimeWarning
766+
)
767+
logdet = np.linalg.slogdet(self.cov_tot)
768+
748769
self.logcoeff = -model.n / 2 * np.log(2 * np.pi) - 0.5 * logdet[1]
749770
# self.coeff = (2*np.pi)**(-model.n/2) * np.exp(-.5* logdet[1] )
750771
# print ( "coeff", self.coeff, "n", model.n, "det", np.linalg.slogdet ( self.cov_tot ) )

0 commit comments

Comments
 (0)