Skip to content

Commit 9428a2a

Browse files
Jammy2211claude
authored andcommitted
fix: codex-review — restore self._xp default, unwrap wrapper before subtraction
xp=None now defaults to self._xp (pre-existing behaviour preserved for JAX-backed callers not passing xp); deflection_grid unwrapped via .array so traced values never hit __array__/asarray (verified: the source-plane vmap+jit regression now passes where it raised TracerArrayConversionError). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 35d9505 commit 9428a2a

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

autoarray/structures/grids/irregular_2d.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def extent_with_buffer_from(self, buffer: float = 1.0e-8) -> List[float]:
168168
]
169169

170170
def grid_2d_via_deflection_grid_from(
171-
self, deflection_grid: np.ndarray, xp=np
171+
self, deflection_grid: np.ndarray, xp=None
172172
) -> "Grid2DIrregular":
173173
"""
174174
Returns a new Grid2DIrregular from this grid coordinates, where the (y,x) coordinates of this grid have a
@@ -183,11 +183,18 @@ def grid_2d_via_deflection_grid_from(
183183
The grid of (y,x) coordinates which is subtracted from this grid.
184184
xp
185185
The array module (``numpy`` or ``jax.numpy``) used to construct the returned grid, mirroring
186-
``subtracted_from`` / ``subtracted_and_rotated_from``. Passed through explicitly by the caller rather
187-
than inferred from ``self._xp``, so JIT-traced call sites (where ``self`` may not carry a reliable
188-
``use_jax`` flag) do not silently fall back to NumPy.
189-
"""
190-
return Grid2DIrregular(values=self.array - xp.asarray(deflection_grid), xp=xp)
186+
``subtracted_from`` / ``subtracted_and_rotated_from``. Defaults to ``self._xp`` (the pre-existing
187+
behaviour); JIT-traced call sites (where ``self`` may not carry a reliable ``use_jax`` flag) should
188+
pass it explicitly so they do not silently fall back to NumPy.
189+
"""
190+
if xp is None:
191+
xp = self._xp
192+
deflections = (
193+
deflection_grid.array
194+
if hasattr(deflection_grid, "array")
195+
else deflection_grid
196+
)
197+
return Grid2DIrregular(values=self.array - deflections, xp=xp)
191198

192199
def squared_distances_to_coordinate_from(
193200
self, coordinate: Tuple[float, float] = (0.0, 0.0)

0 commit comments

Comments
 (0)