Skip to content

Commit

Permalink
Fix remaining numpy2 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Jun 18, 2024
1 parent 2ccd994 commit 94ab451
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
48 changes: 24 additions & 24 deletions audmath/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def db(
Examples:
>>> db(1)
0.0
np.float64(0.0)
>>> db(0)
-120.0
np.float64(-120.0)
>>> db(2)
6.020599913279624
np.float64(6.020599913279624)
>>> db([0, 1])
array([-120., 0.])
Expand Down Expand Up @@ -171,23 +171,23 @@ def duration_in_seconds(
Examples:
>>> duration_in_seconds(2)
2.0
np.float64(2.0)
>>> duration_in_seconds(2.0)
2.0
np.float64(2.0)
>>> duration_in_seconds("2")
2.0
np.float64(2.0)
>>> duration_in_seconds("2ms")
0.002
np.float64(0.002)
>>> duration_in_seconds("2 ms")
0.002
np.float64(0.002)
>>> duration_in_seconds("ms")
0.001
np.float64(0.001)
>>> duration_in_seconds(2000, sampling_rate=1000)
2.0
np.float64(2.0)
>>> duration_in_seconds(np.timedelta64(2, "s"))
2.0
np.float64(2.0)
>>> duration_in_seconds(pd.to_timedelta(2, "s"))
2.0
np.float64(2.0)
>>> duration_in_seconds("Inf")
inf
>>> duration_in_seconds(None)
Expand Down Expand Up @@ -368,16 +368,16 @@ def inverse_db(
Examples:
>>> inverse_db(0)
1.0
np.float64(1.0)
>>> inverse_db(-120)
0.0
np.float64(0.0)
>>> inverse_db(-3)
0.7079457843841379
np.float64(0.7079457843841379)
>>> inverse_db([-120, 0])
array([0., 1.])
"""
min_value = 0.0
min_value = np.float64(0.0)
if bottom is None:
bottom = -np.inf

Expand Down Expand Up @@ -477,7 +477,7 @@ def inverse_normal_distribution(

# Return if no other values are left
if non_valid.sum() == len(x):
return np.float64(x)
return x.astype(np.float64)

switch_sign[non_valid] = 0

Expand Down Expand Up @@ -584,7 +584,7 @@ def inverse_normal_distribution(

x = np.where(switch_sign == 1, -1 * x, x)

return np.float64(x)
return x.astype(np.float64)


def rms(
Expand Down Expand Up @@ -626,11 +626,11 @@ def rms(
Examples:
>>> rms([])
0.0
np.float64(0.0)
>>> rms([0, 1])
0.7071067811865476
np.float64(0.7071067811865476)
>>> rms([[0, 1], [0, 1]])
0.7071067811865476
np.float64(0.7071067811865476)
>>> rms([[0, 1], [0, 1]], keepdims=True)
array([[0.70710678]])
>>> rms([[0, 1], [0, 1]], axis=1)
Expand Down Expand Up @@ -706,11 +706,11 @@ def similarity(
Example:
>>> similarity([1, 0], [1, 0])
1.0
np.float64(1.0)
>>> similarity([1, 0], [0, 1])
0.0
np.float64(0.0)
>>> similarity([1, 0], [-1, 0])
-1.0
np.float64(-1.0)
>>> similarity([[1, 0]], [1, 0])
array([1.])
>>> similarity([1, 0], [[1, 0], [0, 1]])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
0,
False,
3.0,
marks=pytest.mark.xfail(raises=np.AxisError),
marks=pytest.mark.xfail(raises=np.exceptions.AxisError),
),
pytest.param( # array with dim=0 has no axis
3,
0,
True,
3.0,
marks=pytest.mark.xfail(raises=np.AxisError),
marks=pytest.mark.xfail(raises=np.exceptions.AxisError),
),
],
)
Expand Down

0 comments on commit 94ab451

Please sign in to comment.