Skip to content

Commit c91bd79

Browse files
committed
Update doctest output for Numpy 2.x
See astropy/astropy#15095.
1 parent e2dd84e commit c91bd79

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

‎m4opt/models/math.py‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
from scipy.integrate import quad_vec
2020

2121

22-
def _unwrap_scalar(array):
23-
if isinstance(array, np.generic) and np.isscalar(array):
24-
array = array.item()
25-
return array
26-
27-
2822
def _map_interval(func):
2923
"""Apply a function to the bounds of an interval."""
3024

@@ -100,7 +94,7 @@ def _get_intervals(model: Model) -> portion.Interval:
10094
For a simple, bounded model, `_get_intervals` returns a single interval:
10195
10296
>>> _get_intervals(models.Box1D(width=3))
103-
(-1.5,1.5)
97+
(np.float64(-1.5),np.float64(1.5))
10498
10599
This also works with models that have dimensionful input:
106100
@@ -127,11 +121,11 @@ def _get_intervals(model: Model) -> portion.Interval:
127121
>>> model1 = models.Box1D(x_0=-0.5, width=3)
128122
>>> model2 = models.Box1D(x_0=0.5, width=3)
129123
>>> _get_intervals(model1)
130-
(-2.0,1.0)
124+
(np.float64(-2.0),np.float64(1.0))
131125
>>> _get_intervals(model2)
132-
(-1.0,2.0)
126+
(np.float64(-1.0),np.float64(2.0))
133127
>>> _get_intervals(model1 * model2)
134-
(-1.0,1.0)
128+
(np.float64(-1.0),np.float64(1.0))
135129
>>> model1 = models.Box1D(x_0=-0.5*u.m, width=3*u.m)
136130
>>> model2 = models.Box1D(x_0=0.5*u.m, width=3*u.m)
137131
>>> _get_intervals(model1 * model2)
@@ -142,9 +136,9 @@ def _get_intervals(model: Model) -> portion.Interval:
142136
>>> model1 = models.Box1D(x_0=-0.5, width=3)
143137
>>> model2 = models.Box1D(x_0=0.5, width=3)
144138
>>> _get_intervals(model1 + model2)
145-
(-2.0,-1.0) | (-1.0,2.0)
139+
(np.float64(-2.0),np.float64(-1.0)) | (np.float64(-1.0),np.float64(2.0))
146140
>>> _get_intervals(model1 - model2)
147-
(-2.0,-1.0) | (-1.0,2.0)
141+
(np.float64(-2.0),np.float64(-1.0)) | (np.float64(-1.0),np.float64(2.0))
148142
>>> model1 = models.Box1D(x_0=-0.5*u.m, width=3*u.m)
149143
>>> model2 = models.Box1D(x_0=0.5*u.m, width=3*u.m)
150144
>>> _get_intervals(model1 + model2)
@@ -174,7 +168,7 @@ def _get_intervals(model: Model) -> portion.Interval:
174168
return portion.open(-np.inf * unit, np.inf * unit)
175169
else:
176170
((lo, hi),) = bbox
177-
return portion.open(_unwrap_scalar(lo), _unwrap_scalar(hi))
171+
return portion.open(lo, hi)
178172

179173

180174
def integrate(
@@ -221,12 +215,12 @@ def integrate(
221215
>>> integrate(model)
222216
3.0
223217
>>> integrate(model, quick_and_dirty_npts=10000)
224-
3.0
218+
np.float64(3.0)
225219
>>> model = models.Gaussian1D() * models.Const1D(1 / np.sqrt(2 * np.pi))
226220
>>> integrate(model, epsrel=1e-7)
227221
0.9999999648585338
228222
>>> integrate(model, quick_and_dirty_npts=10000)
229-
0.9999999620207557
223+
np.float64(0.9999999620207557)
230224
231225
Or models with dimensions:
232226
@@ -259,7 +253,7 @@ def func(x):
259253

260254
if quick_and_dirty_npts is not None:
261255
x = np.linspace(a, b, quick_and_dirty_npts)
262-
yint = _unwrap_scalar(trapezoid(func(x), x))
256+
yint = trapezoid(func(x), x)
263257
else:
264258
yint, _ = quad_vec(func, a, b, points=points, quadrature="trapezoid", **kwargs)
265259

0 commit comments

Comments
 (0)