Skip to content

Commit 932787d

Browse files
committed
verified type changes
1 parent f45b11a commit 932787d

File tree

11 files changed

+39
-33
lines changed

11 files changed

+39
-33
lines changed

aerosandbox/numpy/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,13 +839,13 @@ def full_like(
839839

840840

841841
def assert_equal_shape(
842-
arrays: list[_onp.ndarray] | dict[str, _onp.ndarray],
842+
arrays: list[Array] | dict[str, Array],
843843
) -> None:
844844
"""Assert that all of the given arrays have the same shape.
845845
846846
Parameters
847847
----------
848-
arrays : list of ndarray, or dict of str to ndarray
848+
arrays : list of Array, or dict of str to Array
849849
The arrays to be evaluated. Can be provided as:
850850
851851
- A list, in which case a generic ValueError is thrown on mismatch.

aerosandbox/numpy/finite_difference_operators.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from aerosandbox.numpy.array import array, length
1+
from aerosandbox.numpy.array import array, asarray, length
2+
from aerosandbox.numpy.typing import ArrayLike, Array
23
import numpy as _onp
34

45

56
def finite_difference_coefficients(
6-
x: _onp.ndarray,
7+
x: ArrayLike,
78
x0: float = 0,
89
derivative_degree: int = 1,
9-
) -> _onp.ndarray:
10+
) -> Array:
1011
"""
1112
Computes the weights (coefficients) in compact finite differece formulas for any order of derivative
1213
and to any order of accuracy on one-dimensional grids with arbitrary spacing.
@@ -51,6 +52,8 @@ def finite_difference_coefficients(
5152
grid points `x`.
5253
5354
"""
55+
x = asarray(x)
56+
5457
### Check inputs
5558
if derivative_degree < 1:
5659
raise ValueError("The parameter derivative_degree must be an integer >= 1.")

aerosandbox/numpy/interpolate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from aerosandbox.numpy.array import array, zeros_like
55
from aerosandbox.numpy.conditionals import where
66
from aerosandbox.numpy.logicals import all, any, logical_or
7-
from aerosandbox.numpy.typing import Vectorizable, ConcreteVector, ConcreteArray
7+
from aerosandbox.numpy.typing import Vectorizable, ArrayLike, ConcreteVector, ConcreteArray
88
from typing import Literal, Sequence
99
from scipy import interpolate as _interpolate
1010

@@ -110,11 +110,11 @@ def is_data_structured(
110110

111111

112112
def interpn(
113-
points: Sequence[ConcreteVector],
113+
points: Sequence[ArrayLike],
114114
values: ConcreteArray,
115115
xi: Vectorizable,
116116
method: Literal["linear", "bspline", "nearest"] = "linear",
117-
bounds_error: bool = True,
117+
bounds_error: bool | None = True,
118118
fill_value: float | None = _onp.nan,
119119
) -> Vectorizable:
120120
"""

aerosandbox/numpy/rotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def rotation_matrix_from_euler_angles(
180180
return rot
181181

182182

183-
def is_valid_rotation_matrix(a: _onp.ndarray, tol: float = 1e-9) -> bool:
183+
def is_valid_rotation_matrix(a: Array, tol: float = 1e-9) -> bool:
184184
"""Check whether a matrix satisfies the properties of a rotation matrix.
185185
186186
Tests for:
@@ -191,7 +191,7 @@ def is_valid_rotation_matrix(a: _onp.ndarray, tol: float = 1e-9) -> bool:
191191
192192
Parameters
193193
----------
194-
a : ndarray
194+
a : Array
195195
The matrix to test.
196196
tol : float, optional
197197
Tolerance for floating-point comparisons. Default is 1e-9.

aerosandbox/numpy/surrogate_model_tools.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import aerosandbox.numpy as _np
88
import casadi as _cas
99
from typing import Literal
10+
from aerosandbox.numpy.typing import Vectorizable
1011

1112

1213
def softmax(
13-
*args: float | _np.ndarray,
14+
*args: Vectorizable,
1415
softness: float | None = None,
1516
hardness: float | None = None,
16-
) -> float | _np.ndarray:
17+
) -> Vectorizable:
1718
"""Compute element-wise soft maximum of two or more arrays.
1819
1920
Also known as the log-sum-exp (LSE) function. Useful for optimization
@@ -89,10 +90,10 @@ def softmax(
8990

9091

9192
def softmin(
92-
*args: float | _np.ndarray,
93+
*args: Vectorizable,
9394
softness: float | None = None,
9495
hardness: float | None = None,
95-
) -> float | _np.ndarray:
96+
) -> Vectorizable:
9697
"""Compute element-wise soft minimum of two or more arrays.
9798
9899
Related to the log-sum-exp function. Useful for optimization because
@@ -132,10 +133,10 @@ def softmin(
132133

133134

134135
def softmax_scalefree(
135-
*args: float | _np.ndarray,
136+
*args: Vectorizable,
136137
relative_softness: float | None = None,
137138
relative_hardness: float | None = None,
138-
) -> float | _np.ndarray:
139+
) -> Vectorizable:
139140
"""Compute scale-free soft maximum of two or more arrays.
140141
141142
Like ``softmax``, but the softness is automatically scaled based on
@@ -176,10 +177,10 @@ def softmax_scalefree(
176177

177178

178179
def softmin_scalefree(
179-
*args: float | _np.ndarray,
180+
*args: Vectorizable,
180181
relative_softness: float | None = None,
181182
relative_hardness: float | None = None,
182-
) -> float | _np.ndarray:
183+
) -> Vectorizable:
183184
"""Compute scale-free soft minimum of two or more arrays.
184185
185186
Like ``softmin``, but the softness is automatically scaled based on

aerosandbox/numpy/test_numpy/test_integrate_discrete_intervals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_nonuniform_spacing():
106106

107107
### Compute expected via manual trapezoidal rule
108108
expected = 0.0
109-
for i in range(len(x) - 1):
109+
for i in range(np.length(x) - 1):
110110
expected += (f[i] + f[i + 1]) / 2 * (x[i + 1] - x[i])
111111

112112
assert np.isclose(integral, expected, rtol=1e-10)
@@ -134,7 +134,7 @@ def test_no_x_specified():
134134

135135
result = integrate_discrete_intervals(f, method="trapezoidal")
136136
expected = integrate_discrete_intervals(
137-
f, x=np.arange(len(f)), method="trapezoidal"
137+
f, x=np.arange(np.length(f)), method="trapezoidal"
138138
)
139139

140140
assert np.allclose(result, expected)
@@ -149,7 +149,7 @@ def test_method_endpoints_lower_order():
149149
f, x, method="cubic", method_endpoints="lower_order"
150150
)
151151

152-
assert len(result) == len(x) - 1
152+
assert np.length(result) == np.length(x) - 1
153153
assert not np.any(np.isnan(result))
154154

155155

@@ -174,9 +174,9 @@ def test_method_endpoints_ignore():
174174

175175
### With 'ignore', forward_simpson gives N-2 intervals (missing last interval due to endpoint)
176176
### With 'lower_order', all N-1 intervals are returned
177-
assert len(result_ignore_no_dx) == len(x) - 2
178-
assert len(result_ignore_with_dx) == len(x) - 2
179-
assert len(result_lower) == len(x) - 1
177+
assert np.length(result_ignore_no_dx) == np.length(x) - 2
178+
assert np.length(result_ignore_with_dx) == np.length(x) - 2
179+
assert np.length(result_lower) == np.length(x) - 1
180180

181181
### Verify the bug fix: result_ignore_with_dx should be result_ignore_no_dx * dx
182182
dx = np.diff(x)

aerosandbox/numpy/test_numpy/test_interpolate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def value_func_3d(x, y, z):
5959
value
6060
== pytest.approx(value_func_3d(*[point[:, i] for i in range(point.shape[1])]))
6161
)
62-
assert len(value) == 2
62+
assert np.length(value) == 2
6363

6464
### CasADi test
6565
point = cas.DM(point)
6666
value = np.interpn(points, values, point)
6767
value_actual = value_func_3d(
6868
*[np.array(point[:, i]) for i in range(point.shape[1])]
6969
)
70-
for i in range(len(value)):
70+
for i in range(np.length(value)):
7171
assert value[i] == pytest.approx(float(value_actual[i]))
7272
assert value.shape == (2,)
7373

aerosandbox/numpy/test_numpy/test_logicals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_basic_logicals_numpy():
66
a = np.array([True, True, False, False])
77
b = np.array([True, False, True, False])
88

9-
assert np.all(a & b == np.array([True, False, False, False]))
9+
assert np.all(a & b == np.array([True, False, False, False])) # type: ignore[operator]
1010

1111

1212
if __name__ == "__main__":

aerosandbox/numpy/test_numpy/test_rotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_euler_angles_equivalence_to_general_3D():
1010
rot_euler = np.rotation_matrix_from_euler_angles(phi, theta, psi)
1111
rot_manual = (
1212
np.rotation_matrix_3D(psi, np.array([0, 0, 1]))
13-
@ np.rotation_matrix_3D(theta, np.array([0, 1, 0]))
13+
@ np.rotation_matrix_3D(theta, np.array([0, 1, 0])) # type: ignore[operator]
1414
@ np.rotation_matrix_3D(phi, np.array([1, 0, 0]))
1515
)
1616

aerosandbox/numpy/trig.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as _onp
88
from numpy import pi as _pi
9+
from aerosandbox.numpy.array import asarray
910
from aerosandbox.numpy.typing import Vectorizable, Array
1011

1112
_deg2rad = 180.0 / _pi
@@ -29,7 +30,7 @@ def degrees(x: Vectorizable) -> Array:
2930
--------
3031
numpy.degrees : https://numpy.org/doc/stable/reference/generated/numpy.degrees.html
3132
"""
32-
return x * _deg2rad
33+
return asarray(x * _deg2rad)
3334

3435

3536
def radians(x: Vectorizable) -> Array:
@@ -49,7 +50,7 @@ def radians(x: Vectorizable) -> Array:
4950
--------
5051
numpy.radians : https://numpy.org/doc/stable/reference/generated/numpy.radians.html
5152
"""
52-
return x * _rad2deg
53+
return asarray(x * _rad2deg)
5354

5455

5556
def sind(x: Vectorizable) -> Array:

0 commit comments

Comments
 (0)