Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions autogalaxy/abstract_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@


class AbstractFitInversion:
def __init__(
self,
model_obj,
settings_inversion: aa.SettingsInversion,
xp=np
):
def __init__(self, model_obj, settings_inversion: aa.SettingsInversion, xp=np):
"""
An abstract fit object which fits to datasets (e.g. imaging, interferometer) inherit from.

Expand Down Expand Up @@ -131,7 +126,9 @@ def linear_light_profile_intensity_dict(

for i, light_profile in enumerate(linear_obj_func.light_profile_list):
if self.use_jax:
linear_light_profile_intensity_dict[light_profile] = reconstruction[i]
linear_light_profile_intensity_dict[light_profile] = reconstruction[
i
]
else:
linear_light_profile_intensity_dict[light_profile] = float(
reconstruction[i]
Expand Down
5 changes: 4 additions & 1 deletion autogalaxy/galaxy/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def image_2d_from(
)

def galaxy_image_2d_dict_from(
self, grid: aa.type.Grid2DLike, xp=np, operated_only: Optional[bool] = None
self,
grid: aa.type.Grid2DLike,
xp=np,
operated_only: Optional[bool] = None,
) -> {Galaxy: np.ndarray}:
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation -> {Galaxy: np.ndarray} is a dict literal, not a typing annotation, and it doesn’t match the actual returned values (which are aa.Array2D instances from image_2d_list_from). Replace it with an appropriate typing type (e.g. Dict[Galaxy, aa.Array2D]) to avoid confusing/incorrect type information.

Suggested change
) -> {Galaxy: np.ndarray}:
) -> Dict[Galaxy, aa.Array2D]:

Copilot uses AI. Check for mistakes.
"""
Returns a dictionary associating every `Galaxy` object with its corresponding 2D image, using the instance
Expand Down
5 changes: 3 additions & 2 deletions autogalaxy/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
self=self,
model_obj=self.galaxies,
settings_inversion=settings_inversion,
xp=xp
xp=xp,
)

self.adapt_images = adapt_images
Expand Down Expand Up @@ -184,7 +184,7 @@ def galaxy_image_dict(self) -> Dict[Galaxy, np.ndarray]:
"""

galaxy_image_2d_dict = self.galaxies.galaxy_image_2d_dict_from(
grid=self.grids.lp,
grid=self.grids.lp, xp=self._xp
)

galaxy_linear_obj_image_dict = self.galaxy_linear_obj_data_dict_from(
Expand Down Expand Up @@ -212,6 +212,7 @@ def galaxy_model_image_dict(self) -> Dict[Galaxy, np.ndarray]:
grid=self.grids.lp,
psf=self.dataset.psf,
blurring_grid=self.grids.blurring,
xp=self._xp,
)

galaxy_linear_obj_image_dict = self.galaxy_linear_obj_data_dict_from(
Expand Down
8 changes: 5 additions & 3 deletions autogalaxy/interferometer/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
self=self,
model_obj=self.galaxies,
settings_inversion=settings_inversion,
xp=xp
xp=xp,
)

self.adapt_images = adapt_images
Expand Down Expand Up @@ -161,7 +161,9 @@ def galaxy_image_dict(self) -> Dict[Galaxy, np.ndarray]:
For modeling, this dictionary is used to set up the `adapt_images` that adapt certain pixelizations to the
data being fitted.
"""
galaxy_image_dict = self.galaxies.galaxy_image_2d_dict_from(grid=self.grids.lp)
galaxy_image_dict = self.galaxies.galaxy_image_2d_dict_from(
grid=self.grids.lp, xp=self._xp
)

galaxy_linear_obj_image_dict = self.galaxy_linear_obj_data_dict_from(
use_operated=False
Expand All @@ -184,7 +186,7 @@ def galaxy_model_visibilities_dict(self) -> Dict[Galaxy, np.ndarray]:
data being fitted.
"""
galaxy_model_visibilities_dict = self.galaxies.galaxy_visibilities_dict_from(
grid=self.grids.lp, transformer=self.dataset.transformer
grid=self.grids.lp, transformer=self.dataset.transformer, xp=self._xp
)

galaxy_linear_obj_data_dict = self.galaxy_linear_obj_data_dict_from(
Expand Down
13 changes: 7 additions & 6 deletions autogalaxy/operate/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ class OperateImageGalaxies(OperateImageList):
"""

def galaxy_image_2d_dict_from(
self, grid: aa.Grid2D, operated_only: Optional[bool] = None
self, grid: aa.Grid2D, xp=np, operated_only: Optional[bool] = None
) -> Dict[Galaxy, aa.Array2D]:
raise NotImplementedError

def galaxy_blurred_image_2d_dict_from(
self, grid, psf, blurring_grid
self, grid, psf, blurring_grid, xp=np
) -> Dict[Galaxy, aa.Array2D]:
"""
Evaluate the light object's dictionary mapping galaixes to their corresponding 2D images and convolve each
Expand All @@ -392,15 +392,15 @@ def galaxy_blurred_image_2d_dict_from(
"""

galaxy_image_2d_not_operated_dict = self.galaxy_image_2d_dict_from(
grid=grid, operated_only=False
grid=grid, operated_only=False, xp=xp
)

galaxy_blurring_image_2d_not_operated_dict = self.galaxy_image_2d_dict_from(
grid=blurring_grid, operated_only=False
grid=blurring_grid, operated_only=False, xp=xp
Comment on lines +395 to +399
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new xp propagation in the galaxy-dict helpers isn’t covered by tests for a non-numpy backend. Consider extending the existing test_autogalaxy/operate/test_image.py coverage to call these methods with xp=jax.numpy (or self._xp) and assert the outputs match the corresponding *_list_from(..., xp=...) results / are computed via the same backend.

Copilot uses AI. Check for mistakes.
)

galaxy_image_2d_operated_dict = self.galaxy_image_2d_dict_from(
grid=grid, operated_only=True
grid=grid, operated_only=True, xp=xp
)

galaxy_blurred_image_2d_dict = {}
Expand All @@ -414,6 +414,7 @@ def galaxy_blurred_image_2d_dict_from(
blurred_image_2d = psf.convolved_image_from(
image=image_2d_not_operated,
blurring_image=blurring_image_2d_not_operated,
xp=xp,
)

image_2d_operated = galaxy_image_2d_operated_dict[galaxy_key]
Expand Down Expand Up @@ -451,7 +452,7 @@ def galaxy_visibilities_dict_from(
in the uv-plane.
"""

galaxy_image_2d_dict = self.galaxy_image_2d_dict_from(grid=grid)
galaxy_image_2d_dict = self.galaxy_image_2d_dict_from(grid=grid, xp=xp)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

galaxy_visibilities_dict_from now correctly forwards xp into galaxy_image_2d_dict_from, but the subsequent call to transformer.visibilities_from(...) still omits xp. This will break JAX / non-numpy backends (and is inconsistent with visibilities_list_from / visibilities_from above). Pass xp=xp into transformer.visibilities_from here as well.

Copilot uses AI. Check for mistakes.

galaxy_visibilities_dict = {}

Expand Down
Loading