Skip to content

Commit 50ee61b

Browse files
Jammy2211claude
authored andcommitted
fix: make jax imports lazy in Grid2DContour properties
contour_list and contour_array did unconditional `import jax.numpy as jnp` inside their property bodies, which broke the numpy code path on Python 3.9 / 3.10 under the new optional [jax] extra. contour_list only used jax for an isinstance check (replaced with duck-typing on .array); contour_array's JAX-array construction is replaced with the numpy equivalent (the downstream consumer materialises to numpy anyway). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0835e33 commit 50ee61b

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

autoarray/operators/contour.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ def contour_array(self):
3838
if self._contour_array is not None:
3939
return self._contour_array
4040

41-
import jax.numpy as jnp
42-
4341
pixel_centres = geometry_util.grid_pixel_centres_2d_slim_from(
4442
grid_scaled_2d_slim=np.array(self.grid),
4543
shape_native=self.shape_native,
4644
pixel_scales=self.pixel_scales,
4745
).astype("int")
4846

49-
arr = jnp.zeros(self.shape_native)
50-
arr = arr.at[tuple(jnp.array(pixel_centres).T)].set(1)
47+
arr = np.zeros(self.shape_native)
48+
arr[tuple(pixel_centres.T)] = 1
5149

5250
return arr
5351

@@ -56,12 +54,12 @@ def contour_list(self):
5654
# make sure to use base numpy to convert JAX array back to a normal array
5755

5856
from skimage import measure
59-
import jax.numpy as jnp
6057

61-
if isinstance(self.contour_array, jnp.ndarray):
62-
contour_array = np.array(self.contour_array)
58+
contour_array = self.contour_array
59+
if hasattr(contour_array, "array"):
60+
contour_array = np.array(contour_array.array)
6361
else:
64-
contour_array = np.array(self.contour_array.array)
62+
contour_array = np.array(contour_array)
6563

6664
contour_indices_list = measure.find_contours(contour_array, 0)
6765

0 commit comments

Comments
 (0)