Skip to content

Commit 72f1bac

Browse files
committed
Suppress runtime warning from numpy about using Inf in the multiplication
1 parent 99542c3 commit 72f1bac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ot/da.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# License: MIT License
1414

1515
import numpy as np
16+
import warnings
1617

1718
from .backend import get_backend
1819
from .bregman import sinkhorn, jcpot_barycenter
@@ -511,7 +512,11 @@ class label
511512
# that he cells (i, j) has -Inf where there's no correction necessary
512513
# by 'correction' we mean setting cost to a large value when
513514
# labels do not match
514-
cost_correction = label_match * missing_labels * self.limit_max
515+
# we suppress potential RuntimeWarning caused by Inf multiplication
516+
# (as we explicitly cover potential NANs later)
517+
with warnings.catch_warnings():
518+
warnings.simplefilter('ignore', category=RuntimeWarning)
519+
cost_correction = label_match * missing_labels * self.limit_max
515520
# this operation is necessary because 0 * Inf = NAN
516521
# thus is irrelevant when limit_max is finite
517522
cost_correction = nx.nan_to_num(cost_correction, -np.infty)

0 commit comments

Comments
 (0)