Skip to content

Commit dd82ce3

Browse files
Jammy2211Jammy2211
authored andcommitted
remove infinities from point solver solution
1 parent a0fc12c commit dd82ce3

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

autolens/point/fit/positions/image/abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ def model_data(self) -> aa.Grid2DIrregular:
104104
tracer=self.tracer,
105105
source_plane_coordinate=self.source_plane_coordinate,
106106
plane_redshift=self.plane_redshift,
107+
remove_infinities=False
107108
)

autolens/point/mock/mock_solver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ def solve(
1010
tracer,
1111
source_plane_coordinate,
1212
plane_redshift: Optional[float] = None,
13+
remove_infinities : bool = True
1314
):
1415
return self.model_positions

autolens/point/solver/point_solver.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def solve(
1818
tracer: OperateDeflections,
1919
source_plane_coordinate: Tuple[float, float],
2020
plane_redshift: Optional[float] = None,
21+
remove_infinities: bool = True,
2122
) -> aa.Grid2DIrregular:
2223
"""
2324
Solve for the image plane coordinates that are traced to the source plane coordinate.
@@ -26,9 +27,15 @@ def solve(
2627
within the triangle. The triangles are sub-sampled to increase the resolution with only the triangles that
2728
contain the source plane coordinate and their neighbours being kept.
2829
29-
The means of the triangles are then filtered to keep only those with an absolute magnification above the
30+
The means of the triangles are then filtered to keep only those with an absolute magnification above the
3031
threshold.
3132
33+
The positions are stored on an array of fixed shape defined by `MAX_CONTAINING_SIZE`. This ensures the
34+
array is static, which is important for JAX compatibility. This array typically has many entries
35+
which use the sentinel value of `inf`, subsequent JAX calculations incorporated. By default, these
36+
sentinel values are removed from the output, for example general use outside of JAX when simulating
37+
strong lenses.
38+
3239
Parameters
3340
----------
3441
source_plane_coordinate
@@ -59,4 +66,8 @@ def solve(
5966
sentinel = self._xp.full_like(solution[0], fill_value=self._xp.inf)
6067
solution = self._xp.where(is_nan[:, None], sentinel, solution)
6168

69+
if remove_infinities:
70+
71+
solution = solution[~self._xp.isinf(solution).any(axis=1)]
72+
6273
return aa.Grid2DIrregular(solution)

test_autolens/point/triangles/test_solver.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def test_real_example_jax(grid, tracer):
8080
result = jax_solver.solve(
8181
tracer=tracer,
8282
source_plane_coordinate=(0.07, 0.07),
83+
remove_infinities=True
84+
)
85+
86+
assert len(result) == 5
87+
88+
89+
result = jax_solver.solve(
90+
tracer=tracer,
91+
source_plane_coordinate=(0.07, 0.07),
92+
remove_infinities=False
8393
)
8494

8595
assert len(result) == 15

0 commit comments

Comments
 (0)