From 4a4027aa558e95a064aa928b3b05605a0a0b4428 Mon Sep 17 00:00:00 2001 From: Paul Andrey <paul.andrey@inria.fr> Date: Mon, 20 Jan 2025 15:51:08 +0100 Subject: [PATCH] Fix possible issues with numpy 2 and future torch versions. --- declearn/metrics/_classif.py | 2 +- declearn/metrics/_roc_auc.py | 4 ++-- declearn/model/sklearn/_sgd.py | 2 +- declearn/model/torch/_model.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/declearn/metrics/_classif.py b/declearn/metrics/_classif.py index 5486d774..c50e31f9 100644 --- a/declearn/metrics/_classif.py +++ b/declearn/metrics/_classif.py @@ -219,7 +219,7 @@ class MulticlassAccuracyPrecisionRecall(Metric[ClassifConfmat]): "f-score": 2 * diag / (pred + true), } # Convert NaNs resulting from zero-division to zero. - scores = {k: np.nan_to_num(v, copy=False) for k, v in scores.items()} + scores = {k: np.nan_to_num(v) for k, v in scores.items()} # Add a copy of the confusion matrix and return. scores["confusion"] = confmat.copy() return scores diff --git a/declearn/metrics/_roc_auc.py b/declearn/metrics/_roc_auc.py index 65cb8cf3..f5bfb986 100644 --- a/declearn/metrics/_roc_auc.py +++ b/declearn/metrics/_roc_auc.py @@ -291,8 +291,8 @@ class BinaryRocAUC(Metric[AurocState]): fneg = self._states.fneg[::-1] # Compute true- and false-positive rates and derive AUC. with np.errstate(invalid="ignore"): - tpr = np.nan_to_num(tpos / (tpos + fneg), copy=False) - fpr = np.nan_to_num(fpos / (fpos + tneg), copy=False) + tpr = np.nan_to_num(tpos / (tpos + fneg)) + fpr = np.nan_to_num(fpos / (fpos + tneg)) auc = sklearn.metrics.auc(fpr, tpr) return { "tpr": tpr, diff --git a/declearn/model/sklearn/_sgd.py b/declearn/model/sklearn/_sgd.py index c0c8aba0..c1e0c49a 100644 --- a/declearn/model/sklearn/_sgd.py +++ b/declearn/model/sklearn/_sgd.py @@ -445,7 +445,7 @@ class SklearnSGDModel(Model): raise TypeError( f"Invalid data type for 'SklearnSGDModel': '{type(array)}'." ) - return array.astype(self._dtype, copy=False) # type: ignore + return array.astype(self._dtype) # type: ignore def _compute_sample_gradient( self, diff --git a/declearn/model/torch/_model.py b/declearn/model/torch/_model.py index 1ad81596..0fefdcba 100644 --- a/declearn/model/torch/_model.py +++ b/declearn/model/torch/_model.py @@ -167,9 +167,9 @@ class TorchModel(Model): ) -> Self: """Instantiate a TorchModel from a configuration dict.""" with io.BytesIO(bytes.fromhex(config["model"])) as buffer: - model = torch.load(buffer) + model = torch.load(buffer, weights_only=False) with io.BytesIO(bytes.fromhex(config["loss"])) as buffer: - loss = torch.load(buffer) + loss = torch.load(buffer, weights_only=False) if config.get("compile", False) and hasattr(torch, "compile"): model = torch.compile(model) return cls(model=model, loss=loss) -- GitLab