Skip to content

Commit

Permalink
fix: Use np.inf to avoid AttributeError
Browse files Browse the repository at this point in the history
* Avoids:

  AttributeError: `np.infty` was removed in the NumPy 2.0 release.
  Use `np.inf` instead.

  AttributeError: `np.Inf` was removed in the NumPy 2.0 release.
  Use `np.inf` instead.
  • Loading branch information
matthewfeickert committed Jun 18, 2024
1 parent e6ff6f9 commit d392abf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions ot/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class label

if (ys is not None) and (yt is not None):

if self.limit_max != np.infty:
if self.limit_max != np.inf:
self.limit_max = self.limit_max * nx.max(self.cost_)

# missing_labels is a (ns, nt) matrix of {0, 1} such that
Expand All @@ -519,7 +519,7 @@ class label
cost_correction = label_match * missing_labels * self.limit_max
# this operation is necessary because 0 * Inf = NAN
# thus is irrelevant when limit_max is finite
cost_correction = nx.nan_to_num(cost_correction, -np.infty)
cost_correction = nx.nan_to_num(cost_correction, -np.inf)
self.cost_ = nx.maximum(self.cost_, cost_correction)

# distribution estimation
Expand Down Expand Up @@ -1067,7 +1067,7 @@ class SinkhornTransport(BaseTransport):
method from :ref:`[66]
<references-sinkhorntransport>` and :ref:`[19]
<references-sinkhorntransport>`.
limit_max: float, optional (default=np.infty)
limit_max: float, optional (default=np.inf)
Controls the semi supervised mode. Transport between labeled source
and target samples of different classes will exhibit an cost defined
by this variable
Expand Down Expand Up @@ -1109,7 +1109,7 @@ def __init__(self, reg_e=1., method="sinkhorn_log", max_iter=1000,
tol=10e-9, verbose=False, log=False,
metric="sqeuclidean", norm=None,
distribution_estimation=distribution_estimation_uniform,
out_of_sample_map='continuous', limit_max=np.infty):
out_of_sample_map='continuous', limit_max=np.inf):

if out_of_sample_map not in ['ferradans', 'continuous']:
raise ValueError('Unknown out_of_sample_map method')
Expand Down Expand Up @@ -1417,7 +1417,7 @@ class SinkhornLpl1Transport(BaseTransport):
The kind of out of sample mapping to apply to transport samples
from a domain into another one. Currently the only possible option is
"ferradans" which uses the method proposed in :ref:`[6] <references-sinkhornlpl1transport>`.
limit_max: float, optional (default=np.infty)
limit_max: float, optional (default=np.inf)
Controls the semi supervised mode. Transport between labeled source
and target samples of different classes will exhibit a cost defined by
limit_max.
Expand Down Expand Up @@ -1450,7 +1450,7 @@ def __init__(self, reg_e=1., reg_cl=0.1,
tol=10e-9, verbose=False,
metric="sqeuclidean", norm=None,
distribution_estimation=distribution_estimation_uniform,
out_of_sample_map='ferradans', limit_max=np.infty):
out_of_sample_map='ferradans', limit_max=np.inf):
self.reg_e = reg_e
self.reg_cl = reg_cl
self.max_iter = max_iter
Expand Down
2 changes: 1 addition & 1 deletion ot/regpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def semi_relaxed_path(a: np.array, b: np.array, C: np.array, reg=1e-4,
active_index.append(i * m + j)
gamma_list = []
t_list = []
current_gamma = np.Inf
current_gamma = np.inf
augmented_H0 = construct_augmented_H(active_index, m, Hc, HrHr)
add_col = np.array([])
id_pop = -1
Expand Down

0 comments on commit d392abf

Please sign in to comment.