Skip to content

Commit ed3461c

Browse files
Jammy2211Jammy2211
authored andcommitted
jnp revmoed from vectors
1 parent 1def232 commit ed3461c

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

autoarray/structures/grids/grid_1d_util.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
import numpy as np
3-
import jax.numpy as jnp
3+
44
from typing import TYPE_CHECKING, List, Union, Tuple
55

66
if TYPE_CHECKING:
@@ -40,30 +40,27 @@ def convert_grid_1d(
4040

4141
grid_1d = grid_2d_util.convert_grid(grid=grid_1d)
4242

43-
is_numpy = True if isinstance(grid_1d, np.ndarray) else False
44-
4543
is_native = grid_1d.shape[0] == mask_1d.shape_native[0]
4644

4745
if is_native == store_native:
48-
grid_1d = grid_1d
46+
return grid_1d
4947
elif not store_native:
50-
grid_1d = grid_1d_slim_from(
48+
return grid_1d_slim_from(
5149
grid_1d_native=grid_1d,
5250
mask_1d=mask_1d,
5351
)
54-
else:
55-
grid_1d = grid_1d_native_from(
56-
grid_1d_slim=grid_1d,
57-
mask_1d=mask_1d,
58-
xp=xp
59-
)
60-
return np.array(grid_1d) if is_numpy else jnp.array(grid_1d)
52+
return grid_1d_native_from(
53+
grid_1d_slim=grid_1d,
54+
mask_1d=mask_1d,
55+
xp=xp
56+
)
6157

6258

6359
def grid_1d_slim_via_shape_slim_from(
6460
shape_slim: Tuple[int],
6561
pixel_scales: ty.PixelScales,
6662
origin: Tuple[float] = (0.0,),
63+
xp=np
6764
) -> np.ndarray:
6865
"""
6966
This routine computes the (x) scaled coordinates at the centre of every pixel defined by a 1D shape of the
@@ -96,13 +93,15 @@ def grid_1d_slim_via_shape_slim_from(
9693
mask_1d=np.full(fill_value=False, shape=shape_slim),
9794
pixel_scales=pixel_scales,
9895
origin=origin,
96+
xp=xp
9997
)
10098

10199

102100
def grid_1d_slim_via_mask_from(
103101
mask_1d: np.ndarray,
104102
pixel_scales: ty.PixelScales,
105103
origin: Tuple[float] = (0.0,),
104+
xp=np
106105
) -> np.ndarray:
107106
"""
108107
For a grid, every unmasked pixel of its 1D mask with shape (total_pixels,) is divided into a finer uniform
@@ -137,8 +136,8 @@ def grid_1d_slim_via_mask_from(
137136
centres_scaled = geometry_util.central_scaled_coordinate_1d_from(
138137
shape_slim=mask_1d.shape, pixel_scales=pixel_scales, origin=origin
139138
)
140-
indices = jnp.arange(mask_1d.shape[0])
141-
unmasked = jnp.logical_not(mask_1d)
139+
indices = xp.arange(mask_1d.shape[0])
140+
unmasked = xp.logical_not(mask_1d)
142141
coords = (indices - centres_scaled[0]) * pixel_scales[0]
143142
return coords[unmasked]
144143

autoarray/structures/grids/uniform_2d.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import List, Optional, Tuple, Union
66

77
from autoconf import conf
8-
from autoconf import cached_property
98
from autoconf.fitsable import ndarray_via_fits_from
109

1110
from autoarray.mask.mask_2d import Mask2D

autoarray/structures/vectors/irregular.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import numpy as np
3-
import jax.numpy as jnp
43
from typing import List, Tuple, Union
54

65
from autoarray.structures.vectors.abstract import AbstractVectorYX2D
@@ -120,13 +119,13 @@ def vectors_within_radius(
120119
squared_distances = self.grid.distances_to_coordinate_from(coordinate=centre)
121120
mask = squared_distances < radius
122121

123-
if jnp.all(mask == False):
122+
if np.all(mask == False):
124123
raise exc.VectorYXException(
125124
"The input radius removed all vectors / points on the grid."
126125
)
127126

128127
return VectorYX2DIrregular(
129-
values=jnp.array(self.array)[mask], grid=Grid2DIrregular(self.grid[mask])
128+
values=np.array(self.array)[mask], grid=Grid2DIrregular(self.grid[mask])
130129
)
131130

132131
def vectors_within_annulus(

autoarray/structures/vectors/uniform.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
import numpy as np
4-
import jax.numpy as jnp
54
from typing import List, Optional, Tuple, Union
65

76
from autoarray.structures.arrays.uniform_2d import Array2D
@@ -394,7 +393,7 @@ def magnitudes(self) -> Array2D:
394393
Returns the magnitude of every vector which are computed as sqrt(y**2 + x**2).
395394
"""
396395
return Array2D(
397-
values=jnp.sqrt(self.array[:, 0] ** 2.0 + self.array[:, 1] ** 2.0),
396+
values=np.sqrt(self.array[:, 0] ** 2.0 + self.array[:, 1] ** 2.0),
398397
mask=self.mask,
399398
)
400399

0 commit comments

Comments
 (0)