From 08327fa976fa8503b611be75b13d31e96c672bf3 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 18 Jun 2024 03:49:35 -0500 Subject: [PATCH 1/4] build: Add support for NumPy 2.0 wheels [build wheels] * Add numpy>=2.0.0 to build-system requires to build NumPy 1.x and 2.x compatible wheels. - c.f. https://numpy.org/doc/stable/dev/depending_on_numpy.html#numpy-2-0-specific-advice - As NumPy 2.0 is Python 3.9+, also need to conditionally support 'oldest-supported-numpy' for Python 3.8. * Remove wheel from build-system requires as it is never required and injected automatically by setuptools only when needed. - c.f. https://learn.scientific-python.org/development/guides/packaging-classic/ --- pyproject.toml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 378920623..a83a59332 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,8 @@ [build-system] -requires = ["setuptools", "wheel", "oldest-supported-numpy", "cython>=0.23"] -build-backend = "setuptools.build_meta" \ No newline at end of file +requires = [ + "setuptools>=42", + "oldest-supported-numpy; python_version < '3.9'", + "numpy>=2.0.0; python_version >= '3.9'", + "cython>=0.23" +] +build-backend = "setuptools.build_meta" From 1a83b3e3b9b333cb84b859a23f5a6421b05c36a3 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 18 Jun 2024 11:29:30 -0500 Subject: [PATCH 2/4] build: Remove setup_requires metadata * Remove setup_requires as it is deprecated and should defer to PEP 517/518. - c.f. https://learn.scientific-python.org/development/guides/packaging-classic/#pep-517518-support-high-priority --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 72b1488b2..1d0b6fceb 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,6 @@ license='MIT', scripts=[], data_files=[], - setup_requires=["oldest-supported-numpy", "cython>=0.23"], install_requires=["numpy>=1.16", "scipy>=1.6"], python_requires=">=3.6", classifiers=[ From c801e413b2e4b7305e88409ba67ef970f0b81d6a Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 18 Jun 2024 04:08:55 -0500 Subject: [PATCH 3/4] fix: Use np.inf to avoid AttributeError * 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. --- ot/da.py | 12 ++++++------ ot/regpath.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ot/da.py b/ot/da.py index e4adaa546..2b28260ef 100644 --- a/ot/da.py +++ b/ot/da.py @@ -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 @@ -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 @@ -1067,7 +1067,7 @@ class SinkhornTransport(BaseTransport): method from :ref:`[66] ` and :ref:`[19] `. - 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 @@ -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') @@ -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] `. - 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. @@ -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 diff --git a/ot/regpath.py b/ot/regpath.py index 8a9b6d886..5e32e4fd1 100644 --- a/ot/regpath.py +++ b/ot/regpath.py @@ -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 From f34309baae4ad1892653212bed56c1251ae791a6 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Tue, 18 Jun 2024 04:41:22 -0500 Subject: [PATCH 4/4] docs: Add NumPy 2.0 support to release notes --- RELEASES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASES.md b/RELEASES.md index 51075c973..3908d079c 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -3,6 +3,7 @@ ## 0.9.4dev #### New features ++ NumPy 2.0 support is added (PR #629) + New quantized FGW solvers `ot.gromov.quantized_fused_gromov_wasserstein`, `ot.gromov.quantized_fused_gromov_wasserstein_samples` and `ot.gromov.quantized_fused_gromov_wasserstein_partitioned` (PR #603) + `ot.gromov._gw.solve_gromov_linesearch` now has an argument to specify if the matrices are symmetric in which case the computation can be done faster (PR #607). + Continuous entropic mapping (PR #613)