Skip to content

Commit edad337

Browse files
committed
fix: simpler
1 parent 19fa527 commit edad337

4 files changed

Lines changed: 20 additions & 33 deletions

File tree

jax_galsim/bounds.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from jax_galsim.core.utils import (
88
cast_to_float,
99
cast_to_int,
10-
cast_to_static_numeric_scalar,
1110
check_is_int_then_cast,
1211
ensure_hashable,
1312
has_tracers,
@@ -509,12 +508,8 @@ def __init__(self, *args, **kwargs):
509508

510509
self._parse_args(*args, **kwargs)
511510

512-
msg = (
513-
"Jax-GalSim BoundsI instances must have a fixed, static width! "
514-
f"Got deltax,deltay = {self.deltax!r},{self.deltay!r}."
515-
)
516-
self.deltax = cast_to_float(cast_to_static_numeric_scalar(self.deltax, msg=msg))
517-
self.deltay = cast_to_float(cast_to_static_numeric_scalar(self.deltay, msg=msg))
511+
self.deltax = cast_to_float(self.deltax)
512+
self.deltay = cast_to_float(self.deltay)
518513
if (self.deltax != int(self.deltax)) or (self.deltay != int(self.deltay)):
519514
raise TypeError("BoundsI must be initialized with integer values")
520515
self.deltax = cast_to_int(self.deltax)

jax_galsim/core/utils.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@ def has_tracers(x):
5151
return False
5252

5353

54-
def cast_to_static_numeric_scalar(x, msg=None):
55-
if isinstance(x, (int, float, np.integer, np.floating)):
56-
return x
57-
58-
if isinstance(x, (np.ndarray, jax.Array, jnp.ndarray)):
59-
if x.ndim == 0:
60-
return x.item()
61-
62-
if all(sv for sv in x.shape == 1):
63-
return x.ravel()[0].item()
64-
65-
msg = msg or f"Cannot convert input {x!r} to a static, numeric scalar."
66-
raise RuntimeError(msg)
67-
68-
6954
def _cast_to_type(x, typ, accept_strings=False):
7055
if isinstance(x, (int, float, np.integer, np.floating)) or (
7156
accept_strings and isinstance(x, str)

jax_galsim/photon_array.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from jax_galsim.core.utils import (
1010
cast_numpy_array_to_native_byte_order,
1111
cast_to_int,
12-
cast_to_static_numeric_scalar,
1312
implements,
1413
)
1514
from jax_galsim.errors import (
@@ -92,14 +91,7 @@ def __init__(
9291
_nokeep=None,
9392
):
9493
self._Ntot = _JAX_GALSIM_PHOTON_ARRAY_SIZE or N
95-
self._Ntot = cast_to_int(
96-
cast_to_static_numeric_scalar(
97-
self._Ntot,
98-
msg=(
99-
f"JAX_GalSim photon arrays must have static sizes., Got {self._Ntot!r}."
100-
),
101-
)
102-
)
94+
self._Ntot = cast_to_int(self._Ntot)
10395

10496
if _JAX_GALSIM_PHOTON_ARRAY_SIZE is not None and (
10597
self._Ntot > _JAX_GALSIM_PHOTON_ARRAY_SIZE

jax_galsim/wcs.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import galsim as _galsim
2+
import jax
23
import jax.numpy as jnp
34
import numpy as np
45
from jax.tree_util import register_pytree_node_class
@@ -7,7 +8,6 @@
78
from jax_galsim.celestial import CelestialCoord
89
from jax_galsim.core.utils import (
910
cast_to_float,
10-
cast_to_static_numeric_scalar,
1111
ensure_hashable,
1212
implements,
1313
)
@@ -18,8 +18,23 @@
1818
from jax_galsim.transform import _Transform
1919

2020

21+
def _cast_to_static_numeric_scalar(x, msg=None):
22+
if isinstance(x, (int, float, np.integer, np.floating)):
23+
return x
24+
25+
if isinstance(x, (np.ndarray, jax.Array, jnp.ndarray)):
26+
if x.ndim == 0:
27+
return x.item()
28+
29+
if all(sv for sv in x.shape == 1):
30+
return x.ravel()[0].item()
31+
32+
msg = msg or f"Cannot convert input {x!r} to a static, numeric scalar."
33+
raise RuntimeError(msg)
34+
35+
2136
def _cast_to_python_float(x):
22-
return cast_to_float(cast_to_static_numeric_scalar(x))
37+
return cast_to_float(_cast_to_static_numeric_scalar(x))
2338

2439

2540
# We inherit from the reference BaseWCS and only redefine the methods that

0 commit comments

Comments
 (0)