From 1bd82883d8fcb76be8fbdfc81f1e797560d0e6b7 Mon Sep 17 00:00:00 2001 From: David Loiseaux Date: Thu, 14 Aug 2025 10:06:31 +0200 Subject: [PATCH 1/2] lazy load torch --- pykeops/pykeops/__init__.py | 4 ++-- pykeops/pykeops/_test_install/__init__.py | 0 .../pykeops/{numpy/test_install.py => _test_install/numpy.py} | 0 .../pykeops/{torch/test_install.py => _test_install/torch.py} | 4 ++-- pykeops/setup.py | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 pykeops/pykeops/_test_install/__init__.py rename pykeops/pykeops/{numpy/test_install.py => _test_install/numpy.py} (100%) rename pykeops/pykeops/{torch/test_install.py => _test_install/torch.py} (97%) diff --git a/pykeops/pykeops/__init__.py b/pykeops/pykeops/__init__.py index 9d08d6e12..79329b7c8 100644 --- a/pykeops/pykeops/__init__.py +++ b/pykeops/pykeops/__init__.py @@ -98,10 +98,10 @@ def get_build_folder(): if numpy_found: - from .numpy.test_install import test_numpy_bindings + from ._test_install.numpy import test_numpy_bindings if torch_found: - from .torch.test_install import test_torch_bindings + from ._test_install.torch import test_torch_bindings # next line is to ensure that cache file for formulas is loaded at import from .common import keops_io diff --git a/pykeops/pykeops/_test_install/__init__.py b/pykeops/pykeops/_test_install/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pykeops/pykeops/numpy/test_install.py b/pykeops/pykeops/_test_install/numpy.py similarity index 100% rename from pykeops/pykeops/numpy/test_install.py rename to pykeops/pykeops/_test_install/numpy.py diff --git a/pykeops/pykeops/torch/test_install.py b/pykeops/pykeops/_test_install/torch.py similarity index 97% rename from pykeops/pykeops/torch/test_install.py rename to pykeops/pykeops/_test_install/torch.py index 541ec3231..46fd99a3f 100644 --- a/pykeops/pykeops/torch/test_install.py +++ b/pykeops/pykeops/_test_install/torch.py @@ -1,5 +1,3 @@ -import torch - from pykeops.common.utils import pyKeOps_Message formula = "SqNorm2(x - y)" @@ -11,6 +9,8 @@ def test_torch_bindings(): """ This function try to compile a simple keops formula using the pytorch binder. """ + + import torch x = torch.arange(1, 10, dtype=torch.float32).view(-1, 3) y = torch.arange(3, 9, dtype=torch.float32).view(-1, 3) diff --git a/pykeops/setup.py b/pykeops/setup.py index d8154d91f..3f52c7a58 100644 --- a/pykeops/setup.py +++ b/pykeops/setup.py @@ -55,6 +55,7 @@ "pykeops.torch.cluster", "pykeops.torch.generic", "pykeops.torch.lazytensor", + "pykeops._test_install", ], package_data={ "pykeops": [ From 5875668c0f3ef98b49a3ead84805e2dc5903b96f Mon Sep 17 00:00:00 2001 From: David Loiseaux Date: Thu, 14 Aug 2025 10:20:55 +0200 Subject: [PATCH 2/2] lint --- pykeops/pykeops/_test_install/torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pykeops/pykeops/_test_install/torch.py b/pykeops/pykeops/_test_install/torch.py index 46fd99a3f..97e05de47 100644 --- a/pykeops/pykeops/_test_install/torch.py +++ b/pykeops/pykeops/_test_install/torch.py @@ -11,6 +11,7 @@ def test_torch_bindings(): """ import torch + x = torch.arange(1, 10, dtype=torch.float32).view(-1, 3) y = torch.arange(3, 9, dtype=torch.float32).view(-1, 3)