From a6925d96198fba6ebe68c1e2ea5d1196066b3b49 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 24 Nov 2025 13:38:58 +0000 Subject: [PATCH 1/4] black --- autoarray/abstract_ndarray.py | 2 ++ autoarray/dataset/imaging/dataset.py | 4 +++- autoarray/dataset/interferometer/dataset.py | 6 +++++- autoarray/inversion/pixelization/mesh/rectangular.py | 9 +++++++-- autoarray/operators/over_sampling/over_sampler.py | 8 ++++++-- autoarray/operators/transformer.py | 2 +- autoarray/operators/transformer_util.py | 5 ++++- autoarray/preloads.py | 2 +- autoarray/structures/arrays/uniform_2d.py | 7 ++++++- autoarray/structures/triangles/coordinate_array_np.py | 2 +- test_autoarray/structures/triangles/test_np.py | 2 -- 11 files changed, 36 insertions(+), 13 deletions(-) diff --git a/autoarray/abstract_ndarray.py b/autoarray/abstract_ndarray.py index 6c8b1d9e8..22f59e712 100644 --- a/autoarray/abstract_ndarray.py +++ b/autoarray/abstract_ndarray.py @@ -338,6 +338,7 @@ def __getitem__(self, item): try: import jax.numpy as jnp + if isinstance(result, jnp.ndarray): result = self.with_new_array(result) except ImportError: @@ -351,6 +352,7 @@ def __setitem__(self, key, value): self._array[key] = value else: import jax.numpy as jnp + self._array = jnp.where(key, value, self._array) def __repr__(self): diff --git a/autoarray/dataset/imaging/dataset.py b/autoarray/dataset/imaging/dataset.py index 9433d5f74..967054a49 100644 --- a/autoarray/dataset/imaging/dataset.py +++ b/autoarray/dataset/imaging/dataset.py @@ -3,6 +3,8 @@ from pathlib import Path from typing import Optional, Union +from autoconf import cached_property + from autoarray.dataset.abstract.dataset import AbstractDataset from autoarray.dataset.grids import GridsDataset from autoarray.dataset.imaging.w_tilde import WTildeImaging @@ -191,7 +193,7 @@ def __init__( psf=self.psf, ) - @property + @cached_property def w_tilde(self): """ The w_tilde formalism of the linear algebra equations precomputes the convolution of every pair of masked diff --git a/autoarray/dataset/interferometer/dataset.py b/autoarray/dataset/interferometer/dataset.py index 5c6ac0235..3e37dc454 100644 --- a/autoarray/dataset/interferometer/dataset.py +++ b/autoarray/dataset/interferometer/dataset.py @@ -2,6 +2,8 @@ import numpy as np from pathlib import Path +from autoconf import cached_property + from autoconf.fitsable import ndarray_via_fits_from, output_to_fits from autoarray.dataset.abstract.dataset import AbstractDataset @@ -14,6 +16,8 @@ from autoarray.inversion.inversion.interferometer import inversion_interferometer_util +from autoarray import exc + logger = logging.getLogger(__name__) @@ -165,7 +169,7 @@ def w_tilde_preprocessing(self): fits.writeto(filename, data=curvature_preload) - @property + @cached_property def w_tilde(self): """ The w_tilde formalism of the linear algebra equations precomputes the Fourier Transform of all the visibilities diff --git a/autoarray/inversion/pixelization/mesh/rectangular.py b/autoarray/inversion/pixelization/mesh/rectangular.py index 6c490869a..392da979b 100644 --- a/autoarray/inversion/pixelization/mesh/rectangular.py +++ b/autoarray/inversion/pixelization/mesh/rectangular.py @@ -158,7 +158,12 @@ def requires_image_mesh(self): class RectangularSource(RectangularMagnification): - def __init__(self, shape: Tuple[int, int] = (3, 3), weight_power: float = 1.0, weight_floor : float = 0.0): + def __init__( + self, + shape: Tuple[int, int] = (3, 3), + weight_power: float = 1.0, + weight_floor: float = 0.0, + ): """ A uniform mesh of rectangular pixels, which without interpolation are paired with a 2D grid of (y,x) coordinates. @@ -205,7 +210,7 @@ def mesh_weight_map_from(self, adapt_data, xp=np) -> np.ndarray: """ mesh_weight_map = xp.asarray(adapt_data.array) mesh_weight_map = xp.clip(mesh_weight_map, 1e-12, None) - mesh_weight_map = mesh_weight_map ** self.weight_power + mesh_weight_map = mesh_weight_map**self.weight_power # Apply floor using xp.where (safe for NumPy and JAX) mesh_weight_map = xp.where( diff --git a/autoarray/operators/over_sampling/over_sampler.py b/autoarray/operators/over_sampling/over_sampler.py index beb75bbbe..e9942547e 100644 --- a/autoarray/operators/over_sampling/over_sampler.py +++ b/autoarray/operators/over_sampling/over_sampler.py @@ -258,10 +258,14 @@ def binned_array_2d_from(self, array: Array2D, xp=np) -> "Array2D": else: # Sum values per segment - sums = np.bincount(self.segment_ids, weights=array, minlength=self.mask.pixels_in_mask) + sums = np.bincount( + self.segment_ids, weights=array, minlength=self.mask.pixels_in_mask + ) # Count number of items per segment - counts = np.bincount(self.segment_ids, minlength=self.mask.pixels_in_mask) + counts = np.bincount( + self.segment_ids, minlength=self.mask.pixels_in_mask + ) # Avoid division by zero counts[counts == 0] = 1 diff --git a/autoarray/operators/transformer.py b/autoarray/operators/transformer.py index aa760c611..d6a8123d3 100644 --- a/autoarray/operators/transformer.py +++ b/autoarray/operators/transformer.py @@ -142,7 +142,7 @@ def visibilities_from(self, image: Array2D, xp=np) -> Visibilities: image_1d=image.slim.array, grid_radians=self.grid.array, uv_wavelengths=self.uv_wavelengths, - xp=xp + xp=xp, ) return Visibilities(visibilities=xp.array(visibilities)) diff --git a/autoarray/operators/transformer_util.py b/autoarray/operators/transformer_util.py index 2beb7e145..d97a36638 100644 --- a/autoarray/operators/transformer_util.py +++ b/autoarray/operators/transformer_util.py @@ -247,7 +247,10 @@ def transformed_mapping_matrix_via_preload_from( def transformed_mapping_matrix_from( - mapping_matrix: np.ndarray, grid_radians: np.ndarray, uv_wavelengths: np.ndarray, xp=np + mapping_matrix: np.ndarray, + grid_radians: np.ndarray, + uv_wavelengths: np.ndarray, + xp=np, ) -> np.ndarray: """ Computes the Fourier-transformed mapping matrix used in radio interferometric imaging. diff --git a/autoarray/preloads.py b/autoarray/preloads.py index 5b258ffc0..607aa6557 100644 --- a/autoarray/preloads.py +++ b/autoarray/preloads.py @@ -67,7 +67,7 @@ def __init__( ids_zeros = np.array(source_pixel_zeroed_indices, dtype=int) - values_to_solve = np.ones(np.max(mapper_indices)+1, dtype=bool) + values_to_solve = np.ones(np.max(mapper_indices) + 1, dtype=bool) values_to_solve[ids_zeros] = False self.source_pixel_zeroed_indices_to_keep = np.where(values_to_solve)[0] diff --git a/autoarray/structures/arrays/uniform_2d.py b/autoarray/structures/arrays/uniform_2d.py index c92a18f3b..f6857bda4 100644 --- a/autoarray/structures/arrays/uniform_2d.py +++ b/autoarray/structures/arrays/uniform_2d.py @@ -378,7 +378,9 @@ def binned_across_columns(self) -> Array1D: return Array1D.no_mask(values=binned_array, pixel_scales=self.pixel_scale) def brightest_coordinate_in_region_from( - self, region: Optional[Tuple[float, float, float, float]] + self, + region: Optional[Tuple[float, float, float, float]], + return_in_pixels: bool = False, ) -> Tuple[float, float]: """ Returns the brightest pixel in the array inside an input region of form (y0, y1, x0, x1) where @@ -420,6 +422,9 @@ def brightest_coordinate_in_region_from( extracted_pixels = np.argwhere(extracted_region == brightest_pixel_value)[0] pixel_coordinates_2d = (y0 + extracted_pixels[0], x0 + extracted_pixels[1]) + if return_in_pixels: + return pixel_coordinates_2d + return self.geometry.scaled_coordinates_2d_from( pixel_coordinates_2d=pixel_coordinates_2d ) diff --git a/autoarray/structures/triangles/coordinate_array_np.py b/autoarray/structures/triangles/coordinate_array_np.py index f37c66f17..107946014 100644 --- a/autoarray/structures/triangles/coordinate_array_np.py +++ b/autoarray/structures/triangles/coordinate_array_np.py @@ -275,7 +275,7 @@ def containing_indices(self, shape: Shape) -> np.ndarray: The indices of triangles that intersect the shape. """ return self.with_vertices(self.vertices).containing_indices(shape) - + @property def means(self): return np.mean(self.triangles, axis=1) diff --git a/test_autoarray/structures/triangles/test_np.py b/test_autoarray/structures/triangles/test_np.py index fac76f350..8a8666373 100644 --- a/test_autoarray/structures/triangles/test_np.py +++ b/test_autoarray/structures/triangles/test_np.py @@ -26,8 +26,6 @@ def triangles(): ) - - @pytest.mark.parametrize( "offset", [-1, 0, 1], From 9e8733e5a82b6980e38d59c6a20bda03d9220e27 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 24 Nov 2025 13:56:00 +0000 Subject: [PATCH 2/4] store tuple in mask, simplify a lot of code --- autoarray/mask/mask_2d.py | 3 + autoarray/structures/arrays/kernel_2d.py | 152 +++-------------------- 2 files changed, 20 insertions(+), 135 deletions(-) diff --git a/autoarray/mask/mask_2d.py b/autoarray/mask/mask_2d.py index bb278d66d..9be77f2e6 100644 --- a/autoarray/mask/mask_2d.py +++ b/autoarray/mask/mask_2d.py @@ -217,6 +217,9 @@ def __init__( xp=xp, ) + slim_to_native = self.derive_indexes.native_for_slim.astype("int32") + self.slim_to_native_tuple = (slim_to_native[:, 0], slim_to_native[:, 1]) + @property def native_for_slim(self): return self.derive_indexes.native_for_slim diff --git a/autoarray/structures/arrays/kernel_2d.py b/autoarray/structures/arrays/kernel_2d.py index d053d98b1..721aed8bc 100644 --- a/autoarray/structures/arrays/kernel_2d.py +++ b/autoarray/structures/arrays/kernel_2d.py @@ -122,25 +122,6 @@ def __init__( self.stored_native = self.native - self.slim_to_native_tuple = None - - if image_mask is not None: - - slim_to_native = image_mask.derive_indexes.native_for_slim.astype("int32") - self.slim_to_native_tuple = (slim_to_native[:, 0], slim_to_native[:, 1]) - - self.slim_to_native_blurring_tuple = None - - if blurring_mask is not None: - - slim_to_native_blurring = ( - blurring_mask.derive_indexes.native_for_slim.astype("int32") - ) - self.slim_to_native_blurring_tuple = ( - slim_to_native_blurring[:, 0], - slim_to_native_blurring[:, 1], - ) - self.fft_shape = fft_shape self.mask_shape = None @@ -585,18 +566,6 @@ def mapping_matrix_native_from( Contains contributions from both the main mapping matrix and, if provided, the blurring mapping matrix. """ - slim_to_native_tuple = self.slim_to_native_tuple - if slim_to_native_tuple is None: - mask_flat = xp.logical_not(mask.array) - - if xp.__name__.startswith("jax"): - slim_to_native_tuple = xp.nonzero( - mask_flat, size=mapping_matrix.shape[0] - ) - else: - slim_to_native = mask.derive_indexes.native_for_slim.astype("int32") - slim_to_native_tuple = (slim_to_native[:, 0], slim_to_native[:, 1]) - n_src = mapping_matrix.shape[1] # Allocate full native grid (ny, nx, n_src) @@ -606,43 +575,22 @@ def mapping_matrix_native_from( # Scatter main mapping matrix into native cube if xp.__name__.startswith("jax"): - mapping_matrix_native = mapping_matrix_native.at[slim_to_native_tuple].set( + mapping_matrix_native = mapping_matrix_native.at[mask.slim_to_native_tuple].set( mapping_matrix ) else: - mapping_matrix_native[slim_to_native_tuple] = mapping_matrix + mapping_matrix_native[mask.slim_to_native_tuple] = mapping_matrix + # Optionally scatter blurring mapping matrix + if blurring_mapping_matrix is not None: - slim_to_native_blurring_tuple = self.slim_to_native_blurring_tuple - - if slim_to_native_blurring_tuple is None: - if blurring_mask is None: - raise ValueError( - "blurring_mask must be provided if blurring_mapping_matrix is given " - "and slim_to_native_blurring_tuple is None." - ) - - if xp.__name__.startswith("jax"): - mask_flat = xp.logical_not(blurring_mask.array) - slim_to_native_blurring_tuple = xp.nonzero( - mask_flat, - size=blurring_mapping_matrix.shape[0], - ) - else: - slim_to_native_blurring = ( - blurring_mask.derive_indexes.native_for_slim.astype("int32") - ) - slim_to_native_blurring_tuple = ( - slim_to_native_blurring[:, 0], - slim_to_native_blurring[:, 1], - ) if xp.__name__.startswith("jax"): mapping_matrix_native = mapping_matrix_native.at[ - slim_to_native_blurring_tuple + blurring_mask.slim_to_native_tuple ].set(blurring_mapping_matrix) else: - mapping_matrix_native[slim_to_native_blurring_tuple] = ( + mapping_matrix_native[blurring_mask.slim_to_native_tuple] = ( blurring_mapping_matrix ) @@ -722,31 +670,17 @@ def convolved_image_from(self, image, blurring_image, jax_method="direct", xp=np mask_shape = self.mask_shape fft_psf = self.fft_psf - slim_to_native_tuple = self.slim_to_native_tuple - slim_to_native_blurring_tuple = self.slim_to_native_blurring_tuple - - if slim_to_native_tuple is None: - - mask_flat = xp.logical_not(image.mask.array) - slim_to_native_tuple = xp.nonzero(mask_flat, size=image.shape[0]) - # start with native image padded with zeros image_both_native = xp.zeros(image.mask.shape, dtype=image.dtype) - image_both_native = image_both_native.at[slim_to_native_tuple].set( + image_both_native = image_both_native.at[image.mask.slim_to_native_tuple].set( xp.asarray(image.array) ) # add blurring contribution if provided if blurring_image is not None: - if slim_to_native_blurring_tuple is None: - - mask_flat = xp.logical_not(blurring_image.mask.array) - slim_to_native_blurring_tuple = xp.nonzero( - mask_flat, size=blurring_image.shape[0] - ) - image_both_native = image_both_native.at[slim_to_native_blurring_tuple].set( + image_both_native = image_both_native.at[blurring_image.mask.slim_to_native_tuple].set( xp.asarray(blurring_image.array) ) @@ -777,7 +711,7 @@ def convolved_image_from(self, image, blurring_image, jax_method="direct", xp=np ) blurred_image = Array2D( - values=blurred_image_native[slim_to_native_tuple], mask=image.mask + values=blurred_image_native[image.mask.slim_to_native_tuple], mask=image.mask ) if self.fft_shape is None: @@ -880,13 +814,6 @@ def convolved_mapping_matrix_from( mask_shape = self.mask_shape fft_psf_mapping = self.fft_psf_mapping - slim_to_native_tuple = self.slim_to_native_tuple - - if slim_to_native_tuple is None: - - mask_flat = xp.logical_not(mask.array) - slim_to_native_tuple = xp.nonzero(mask_flat, size=mapping_matrix.shape[0]) - mapping_matrix_native = self.mapping_matrix_native_from( mapping_matrix=mapping_matrix, mask=mask, @@ -1055,30 +982,18 @@ def convolved_image_via_real_space_from( import jax - slim_to_native_tuple = self.slim_to_native_tuple - slim_to_native_blurring_tuple = self.slim_to_native_blurring_tuple - - if slim_to_native_tuple is None: - mask_flat = xp.logical_not(image.mask.array) - slim_to_native_tuple = xp.nonzero(mask_flat, size=image.shape[0]) - # start with native array padded with zeros image_native = xp.zeros(image.mask.shape, dtype=xp.asarray(image.array).dtype) # set image pixels - image_native = image_native.at[slim_to_native_tuple].set( + image_native = image_native.at[image.mask.slim_to_native_tuple].set( xp.asarray(image.array) ) # add blurring contribution if provided if blurring_image is not None: - if slim_to_native_blurring_tuple is None: - slim_to_native_blurring_tuple = xp.nonzero( - mask_flat, - size=blurring_image.shape[0], - ) - image_native = image_native.at[slim_to_native_blurring_tuple].set( + image_native = image_native.at[blurring_image.mask.slim_to_native_tuple].set( xp.asarray(blurring_image.array) ) else: @@ -1094,7 +1009,7 @@ def convolved_image_via_real_space_from( image_native, kernel, mode="same", method=jax_method ) - convolved_array_1d = convolve_native[slim_to_native_tuple] + convolved_array_1d = convolve_native[image.mask.slim_to_native_tuple] return Array2D(values=convolved_array_1d, mask=image.mask) @@ -1146,16 +1061,6 @@ def convolved_mapping_matrix_via_real_space_from( import jax - slim_to_native_tuple = self.slim_to_native_tuple - - if slim_to_native_tuple is None: - - mask_flat = xp.logical_not(mask.array) - slim_to_native_tuple = xp.nonzero( - mask_flat, - size=mapping_matrix.shape[0], - ) - mapping_matrix_native = self.mapping_matrix_native_from( mapping_matrix=mapping_matrix, mask=mask, @@ -1174,7 +1079,7 @@ def convolved_mapping_matrix_via_real_space_from( ) # return slim form - return blurred_mapping_matrix_native[slim_to_native_tuple] + return blurred_mapping_matrix_native[mask.slim_to_native_tuple] def convolved_image_via_real_space_np_from( self, image: np.ndarray, blurring_image: Optional[np.ndarray] = None, xp=np @@ -1207,32 +1112,16 @@ def convolved_image_via_real_space_np_from( from scipy.signal import convolve as scipy_convolve - slim_to_native_tuple = self.slim_to_native_tuple - slim_to_native_blurring_tuple = self.slim_to_native_blurring_tuple - - if slim_to_native_tuple is None: - slim_to_native = image.mask.derive_indexes.native_for_slim.astype("int32") - slim_to_native_tuple = (slim_to_native[:, 0], slim_to_native[:, 1]) - # start with native array padded with zeros image_native = xp.zeros(image.mask.shape, dtype=xp.asarray(image.array).dtype) # set image pixels - image_native[slim_to_native_tuple] = xp.asarray(image.array) + image_native[image.mask.slim_to_native_tuple] = xp.asarray(image.array) # add blurring contribution if provided if blurring_image is not None: - if slim_to_native_blurring_tuple is None: - - slim_to_native_blurring = ( - blurring_image.mask.derive_indexes.native_for_slim.astype("int32") - ) - slim_to_native_blurring_tuple = ( - slim_to_native_blurring[:, 0], - slim_to_native_blurring[:, 1], - ) - image_native[slim_to_native_blurring_tuple] = xp.asarray( + image_native[blurring_image.mask.slim_to_native_tuple] = xp.asarray( blurring_image.array ) else: @@ -1248,7 +1137,7 @@ def convolved_image_via_real_space_np_from( image_native, kernel, mode="same", method="auto" ) - convolved_array_1d = convolve_native[slim_to_native_tuple] + convolved_array_1d = convolve_native[image.mask.slim_to_native_tuple] return Array2D(values=convolved_array_1d, mask=image.mask) @@ -1290,13 +1179,6 @@ def convolved_mapping_matrix_via_real_space_np_from( from scipy.signal import convolve as scipy_convolve - slim_to_native_tuple = self.slim_to_native_tuple - - if slim_to_native_tuple is None: - - slim_to_native = mask.derive_indexes.native_for_slim.astype("int32") - slim_to_native_tuple = (slim_to_native[:, 0], slim_to_native[:, 1]) - mapping_matrix_native = self.mapping_matrix_native_from( mapping_matrix=mapping_matrix, mask=mask, @@ -1314,4 +1196,4 @@ def convolved_mapping_matrix_via_real_space_np_from( ) # return slim form - return blurred_mapping_matrix_native[slim_to_native_tuple] + return blurred_mapping_matrix_native[mask.slim_to_native_tuple] From 1d8aba19d7e2a1157c68e7d5087bb6c4cd1f60f0 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 24 Nov 2025 16:41:41 +0000 Subject: [PATCH 3/4] all use tuple and removed pointless xp.asarray --- autoarray/structures/arrays/kernel_2d.py | 30 +++++++++--------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/autoarray/structures/arrays/kernel_2d.py b/autoarray/structures/arrays/kernel_2d.py index 721aed8bc..a097a9644 100644 --- a/autoarray/structures/arrays/kernel_2d.py +++ b/autoarray/structures/arrays/kernel_2d.py @@ -673,16 +673,12 @@ def convolved_image_from(self, image, blurring_image, jax_method="direct", xp=np # start with native image padded with zeros image_both_native = xp.zeros(image.mask.shape, dtype=image.dtype) - image_both_native = image_both_native.at[image.mask.slim_to_native_tuple].set( - xp.asarray(image.array) - ) + image_both_native = image_both_native.at[image.mask.slim_to_native_tuple].set(image.array) # add blurring contribution if provided if blurring_image is not None: - image_both_native = image_both_native.at[blurring_image.mask.slim_to_native_tuple].set( - xp.asarray(blurring_image.array) - ) + image_both_native = image_both_native.at[blurring_image.mask.slim_to_native_tuple].set(blurring_image.array) else: warnings.warn( @@ -846,7 +842,7 @@ def convolved_mapping_matrix_from( ) # return slim form - return blurred_mapping_matrix_native[slim_to_native_tuple] + return blurred_mapping_matrix_native[mask.slim_to_native_tuple] def rescaled_with_odd_dimensions_from( self, rescale_factor: float, normalize: bool = False @@ -983,19 +979,16 @@ def convolved_image_via_real_space_from( import jax # start with native array padded with zeros - image_native = xp.zeros(image.mask.shape, dtype=xp.asarray(image.array).dtype) + image_native = xp.zeros(image.mask.shape, dtype=image.array.dtype) # set image pixels - image_native = image_native.at[image.mask.slim_to_native_tuple].set( - xp.asarray(image.array) - ) + image_native = image_native.at[image.mask.slim_to_native_tuple].set(image.array) # add blurring contribution if provided if blurring_image is not None: - image_native = image_native.at[blurring_image.mask.slim_to_native_tuple].set( - xp.asarray(blurring_image.array) - ) + image_native = image_native.at[blurring_image.mask.slim_to_native_tuple].set(blurring_image.array) + else: warnings.warn( "No blurring_image provided. Only the direct image will be convolved. " @@ -1113,17 +1106,16 @@ def convolved_image_via_real_space_np_from( from scipy.signal import convolve as scipy_convolve # start with native array padded with zeros - image_native = xp.zeros(image.mask.shape, dtype=xp.asarray(image.array).dtype) + image_native = xp.zeros(image.mask.shape, dtype=image.array.dtype) # set image pixels - image_native[image.mask.slim_to_native_tuple] = xp.asarray(image.array) + image_native[image.mask.slim_to_native_tuple] = image.array # add blurring contribution if provided if blurring_image is not None: - image_native[blurring_image.mask.slim_to_native_tuple] = xp.asarray( - blurring_image.array - ) + image_native[blurring_image.mask.slim_to_native_tuple] = blurring_image.array + else: warnings.warn( "No blurring_image provided. Only the direct image will be convolved. " From 21ccc39a612786d19b62ba5bfd2dff26a7590af4 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 24 Nov 2025 17:15:27 +0000 Subject: [PATCH 4/4] remove more xp.asarray --- autoarray/fit/fit_util.py | 14 +++++++------- .../inversion/pixelization/mesh/rectangular.py | 2 +- .../inversion/regularization/gaussian_kernel.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/autoarray/fit/fit_util.py b/autoarray/fit/fit_util.py index 3f7363fca..1b126a2d2 100644 --- a/autoarray/fit/fit_util.py +++ b/autoarray/fit/fit_util.py @@ -198,7 +198,7 @@ def residual_map_with_mask_from( model_data The model data used to fit the data. """ - return xp.where(xp.asarray(mask) == 0, xp.subtract(data, model_data), 0) + return xp.where(mask == 0, xp.subtract(data, model_data), 0) @to_new_array @@ -221,7 +221,7 @@ def normalized_residual_map_with_mask_from( mask The mask applied to the residual-map, where `False` entries are included in the calculation. """ - return xp.where(xp.asarray(mask) == 0, xp.divide(residual_map, noise_map), 0) + return xp.where(mask == 0, xp.divide(residual_map, noise_map), 0) @to_new_array @@ -244,7 +244,7 @@ def chi_squared_map_with_mask_from( mask The mask applied to the residual-map, where `False` entries are included in the calculation. """ - return xp.where(xp.asarray(mask) == 0, xp.square(residual_map / noise_map), 0) + return xp.where(mask == 0, xp.square(residual_map / noise_map), 0) def chi_squared_with_mask_from( @@ -263,7 +263,7 @@ def chi_squared_with_mask_from( mask The mask applied to the chi-squared-map, where `False` entries are included in the calculation. """ - return float(xp.sum(chi_squared_map[xp.asarray(mask) == 0])) + return float(xp.sum(chi_squared_map[mask == 0])) def chi_squared_with_mask_fast_from( @@ -301,8 +301,8 @@ def chi_squared_with_mask_fast_from( xp.subtract( data, model_data, - )[xp.asarray(mask) == 0], - noise_map[xp.asarray(mask) == 0], + )[mask == 0], + noise_map[mask == 0], ) ) ) @@ -326,7 +326,7 @@ def noise_normalization_with_mask_from( mask The mask applied to the noise-map, where `False` entries are included in the calculation. """ - return float(xp.sum(xp.log(2 * xp.pi * noise_map[xp.asarray(mask) == 0] ** 2.0))) + return float(xp.sum(xp.log(2 * xp.pi * noise_map[mask == 0] ** 2.0))) def chi_squared_with_noise_covariance_from( diff --git a/autoarray/inversion/pixelization/mesh/rectangular.py b/autoarray/inversion/pixelization/mesh/rectangular.py index 392da979b..4e03268c4 100644 --- a/autoarray/inversion/pixelization/mesh/rectangular.py +++ b/autoarray/inversion/pixelization/mesh/rectangular.py @@ -208,7 +208,7 @@ def mesh_weight_map_from(self, adapt_data, xp=np) -> np.ndarray: xp The array library to use. """ - mesh_weight_map = xp.asarray(adapt_data.array) + mesh_weight_map = adapt_data.array mesh_weight_map = xp.clip(mesh_weight_map, 1e-12, None) mesh_weight_map = mesh_weight_map**self.weight_power diff --git a/autoarray/inversion/regularization/gaussian_kernel.py b/autoarray/inversion/regularization/gaussian_kernel.py index 0e10ae99e..344e24e5b 100644 --- a/autoarray/inversion/regularization/gaussian_kernel.py +++ b/autoarray/inversion/regularization/gaussian_kernel.py @@ -33,7 +33,7 @@ def gauss_cov_matrix_from( The Gaussian covariance matrix. """ # Ensure array: - pts = xp.asarray(pixel_points) # (N, 2) + pts = pixel_points # (N, 2) # Compute squared distances: ||p_i - p_j||^2 diffs = pts[:, None, :] - pts[None, :, :] # (N, N, 2) d2 = xp.sum(diffs**2, axis=-1) # (N, N)