Skip to content

Commit 616e8b4

Browse files
authored
Merge pull request #414 from PyAutoLabs/feature/point-source-chi-squared-variants
feat: thread xp through Grid2DIrregular.grid_2d_via_deflection_grid_from
2 parents 5c7a5e0 + 9428a2a commit 616e8b4

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

autoarray/structures/grids/irregular_2d.py

Lines changed: 15 additions & 3 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
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
@@ -181,8 +181,20 @@ def grid_2d_via_deflection_grid_from(
181181
----------
182182
deflection_grid
183183
The grid of (y,x) coordinates which is subtracted from this grid.
184-
"""
185-
return Grid2DIrregular(values=self - deflection_grid, xp=self._xp)
184+
xp
185+
The array module (``numpy`` or ``jax.numpy``) used to construct the returned grid, mirroring
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)
186198

187199
def squared_distances_to_coordinate_from(
188200
self, coordinate: Tuple[float, float] = (0.0, 0.0)

0 commit comments

Comments
 (0)