Skip to content

Commit 10acc34

Browse files
authored
Merge pull request #42 from fgnt/numpy2
Fixes for recent numpy and scipy versions
2 parents 99eb6c8 + 6390b47 commit 10acc34

File tree

14 files changed

+45
-49
lines changed

14 files changed

+45
-49
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
1313
strategy:
1414
matrix:
15-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
16-
15+
python-version: ['3.9', '3.10', '3.11', '3.12']
16+
os: ['ubuntu-latest']
17+
include:
18+
- python-version: '3.12'
19+
os: 'macos-latest'
1720
steps:
1821
- uses: actions/checkout@v3
1922
- name: Set up Python ${{ matrix.python-version }}
@@ -26,6 +29,7 @@ jobs:
2629
trap 'echo -e "$ $BASH_COMMAND"' DEBUG
2730
sudo apt-get update
2831
sudo apt-get install libsndfile1 sox
32+
if: matrix.os != 'macos-latest'
2933

3034
- name: Install python dependencies
3135
run: |
@@ -36,6 +40,7 @@ jobs:
3640
python -m pip install wheel
3741
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3842
pip install --editable .[all]
43+
pip install https://github.com/ludlows/python-pesq/archive/master.zip
3944
4045
- name: Lint with flake8
4146
run: |
@@ -50,3 +55,4 @@ jobs:
5055
- name: Codecov
5156
run: |
5257
codecov
58+
if: matrix.os != 'macos-latest'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Blind Source Separation (BSS) algorithms
22

3+
[![pytest](https://github.com/fgnt/pb_bss/actions/workflows/tests.yml/badge.svg)](https://github.com/fgnt/pb_bss/actions)
34
[![Build Status](https://dev.azure.com/fgnt/fgnt/_apis/build/status/fgnt.pb_bss?branchName=master)](https://dev.azure.com/fgnt/fgnt/_build/latest?definitionId=1&branchName=master)
45
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/fgnt/fgnt/1)](https://dev.azure.com/fgnt/fgnt/_build/latest?definitionId=1&branchName=master)
56
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/fgnt/fgnt/1)](https://dev.azure.com/fgnt/fgnt/_build/latest?definitionId=1&branchName=master)

azure-pipelines.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,9 @@ jobs:
33
- job: test
44
strategy:
55
matrix:
6-
Linux py37:
7-
IMAGE_NAME: 'ubuntu-latest'
8-
PYTHON_VERSION: '3.7'
9-
OSX py37:
10-
IMAGE_NAME: 'macos-latest'
11-
PYTHON_VERSION: '3.7'
12-
Linux py38:
13-
IMAGE_NAME: 'ubuntu-latest'
14-
PYTHON_VERSION: '3.8'
156
Linux py39:
167
IMAGE_NAME: 'ubuntu-latest'
17-
PYTHON_VERSION: '3.9'
8+
PYTHON_VERSION: '3.12'
189
pool:
1910
vmImage: $(IMAGE_NAME)
2011
steps:

pb_bss/evaluation/module_pesq.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ def pesq(reference, estimation, sample_rate, mode=None):
1414
>>> np.random.seed(0)
1515
>>> a = np.random.normal(size=16_000)
1616
>>> b = a + np.random.normal(size=16_000)
17-
>>> pesq(a, b, sample_rate=16000)
18-
2.2297563552856445
17+
>>> pesq(a, b, sample_rate=16000) # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
18+
2.22975...
1919
>>> pesq(a, b, sample_rate=8000)
2020
1.0334522724151611
21-
>>> pesq(a, b, sample_rate=16000, mode='nb')
22-
3.200247049331665
21+
>>> pesq(a, b, sample_rate=16000, mode='nb') # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
22+
3.20024...
2323
24-
>>> pesq([a, a], [b, b], sample_rate=16000)
25-
array([2.22975636, 2.22975636])
26-
>>> pesq([[a, a], [b, a]], [[b, b], [b, b]], sample_rate=16000)
27-
array([[2.22975636, 2.22975636],
28-
[4.64388847, 2.22975636]])
24+
>>> pesq([a, a], [b, b], sample_rate=16000) # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
25+
array([2.22975..., 2.22975...])
26+
>>> pesq([[a, a], [b, a]], [[b, b], [b, b]], sample_rate=16000) # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
27+
array([[2.22975..., 2.22975...],
28+
[4.64388847, 2.22975...]])
2929
3030
>>> pesq(a, b, sample_rate=8000, mode='wb')
3131
Traceback (most recent call last):

pb_bss/evaluation/module_si_sdr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ def si_sdr(reference, estimation):
1717
1818
>>> np.random.seed(0)
1919
>>> reference = np.random.randn(100)
20-
>>> si_sdr(reference, reference)
20+
>>> print(si_sdr(reference, reference))
2121
inf
22-
>>> si_sdr(reference, reference * 2)
22+
>>> print(si_sdr(reference, reference * 2))
2323
inf
24-
>>> si_sdr(reference, np.flip(reference))
24+
>>> print(si_sdr(reference, np.flip(reference)))
2525
-25.127672346460717
26-
>>> si_sdr(reference, reference + np.flip(reference))
26+
>>> print(si_sdr(reference, reference + np.flip(reference)))
2727
0.481070445785553
28-
>>> si_sdr(reference, reference + 0.5)
28+
>>> print(si_sdr(reference, reference + 0.5))
2929
6.3704606032577304
30-
>>> si_sdr(reference, reference * 2 + 1)
30+
>>> print(si_sdr(reference, reference * 2 + 1))
3131
6.3704606032577304
32-
>>> si_sdr([1., 0], [0., 0]) # never predict only zeros
32+
>>> print(si_sdr([1., 0], [0., 0])) # never predict only zeros
3333
nan
3434
>>> si_sdr([reference, reference], [reference * 2 + 1, reference * 1 + 0.5])
3535
array([6.3704606, 6.3704606])

pb_bss/evaluation/module_srmr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def srmr(signal, sample_rate: int = 16000, n_cochlear_filters: int = 23, low_fre
1717
>>> import paderbox as pb
1818
>>> a = pb.testing.testfile_fetcher.get_file_path('speech_bab_0dB.wav')
1919
>>> a = pb.io.load_audio(a)
20-
>>> srmr(a, 16000) # doctest: +ELLIPSIS
20+
>>> print(srmr(a, 16000)) # doctest: +ELLIPSIS
2121
1.8561615800...
2222
>>> srmr([a, a], 16000)
2323
array([1.85616158, 1.85616158])
@@ -96,7 +96,7 @@ def SRMR(signal: np.ndarray, sample_rate: int = 16000, n: int = 23, low_freq: in
9696
temp = segment_axis(E[j][k], int(sample_rate/1000)*256, int(sample_rate/1000)*64)
9797

9898
#Multiplication of a hamming window with each segment and summation of the result
99-
hamm_window = sp.signal.hamming(int(sample_rate/1000)*256, sym=True)
99+
hamm_window = sp.signal.windows.hamming(int(sample_rate/1000)*256, sym=True)
100100
for window in temp:
101101
energy[j][k].append(np.sum(np.square(hamm_window*window)))
102102

pb_bss/evaluation/sxr_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_snr(X, N, *, axis=None, keepdims=False):
4040
Returns:
4141
SNR of time signals or STFT signals in dB.
4242
43-
>>> get_snr([1, 2, 3], [1, 2, 3])
43+
>>> print(get_snr([1, 2, 3], [1, 2, 3]))
4444
0.0
4545
"""
4646
power_X = get_variance_for_zero_mean_signal(X, axis=axis, keepdims=keepdims)

pb_bss/evaluation/wrapper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ def __init__(
290290
... )
291291
292292
# Obtain all metrics (recommended)
293-
>>> with np.printoptions(precision=4):
293+
>>> with np.printoptions(precision=4): # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
294294
... pprint(metrics.as_dict())
295-
{'pesq': array([1.2235, 1.225 ]),
295+
{'pesq': array([1.22..., 1.225 ]),
296296
'stoi': array([0.0503, 0.0638]),
297297
'mir_eval_sdr': array([7.2565, 7.3303]),
298298
'mir_eval_sir': array([25.6896, 46.638 ]),
@@ -301,12 +301,12 @@ def __init__(
301301
'srmr': array([203.3988, 203.3988])}
302302
303303
# Obtain particular metric (e.g. pesq)
304-
>>> metrics.pesq
305-
array([1.22345543, 1.2250005 ])
304+
>>> metrics.pesq # doctest: +ELLIPSIS # macOS doesn't yield the same as Ubuntu
305+
array([1.22..., 1.225000...])
306306
307307
# Obtain multiple metrics (e.g. pesq and stoi)
308308
>>> pprint({m: metrics[m] for m in ['pesq', 'stoi']})
309-
{'pesq': array([1.22345543, 1.2250005 ]),
309+
{'pesq': array([1.22..., 1.225000...]),
310310
'stoi': array([0.05026565, 0.06377457])}
311311
"""
312312
self.speech_prediction = speech_prediction

pb_bss/extraction/beamformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def get_mvdr_vector(atf_vector, noise_psd_matrix):
247247
noise_psd_matrix + np.conj(noise_psd_matrix.swapaxes(-1, -2))
248248
)
249249
try:
250-
numerator = solve(noise_psd_matrix, atf_vector)
250+
numerator = np.squeeze(solve(noise_psd_matrix, atf_vector[..., None]), axis=-1)
251251
except np.linalg.LinAlgError:
252252
bins = noise_psd_matrix.shape[0]
253253
numerator = np.empty_like(atf_vector)

pb_bss/testing/dummy_data.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def read_audio(example):
5757
def low_reverberation_data():
5858
"""
5959
>>> import numpy as np
60-
>>> np.set_string_function(lambda a: f'array(shape={a.shape}, dtype={a.dtype})')
61-
>>> from IPython.lib.pretty import pprint
60+
>>> from paderbox.utils.pretty import pprint
6261
>>> pprint(low_reverberation_data()) # doctest: +ELLIPSIS
6362
{'audio_path': ...,
6463
'gender': ['m', 'm'],
@@ -86,7 +85,6 @@ def low_reverberation_data():
8685
'speech_reverberation_early': array(shape=(2, 6, 38520), dtype=float64),
8786
'speech_reverberation_tail': array(shape=(2, 6, 38520), dtype=float64),
8887
'speech_source': array(shape=(2, 38520), dtype=float64)}}
89-
>>> np.set_string_function(None) # needed for pytest. np.set_string_function is not properly reseted.
9088
"""
9189
return _get_data()['low_reverberation']
9290

@@ -95,8 +93,7 @@ def reverberation_data():
9593
"""
9694
9795
>>> import numpy as np
98-
>>> np.set_string_function(lambda a: f'array(shape={a.shape}, dtype={a.dtype})')
99-
>>> from IPython.lib.pretty import pprint
96+
>>> from paderbox.utils.pretty import pprint
10097
>>> pprint(reverberation_data()) # doctest: +ELLIPSIS
10198
{'audio_path': ...,
10299
'gender': ['m', 'm'],
@@ -116,7 +113,6 @@ def reverberation_data():
116113
'example_id': 'reverberation',
117114
'dataset': 'test',
118115
'audio_data': ...
119-
>>> np.set_string_function(None) # needed for pytest. np.set_string_function is not properly reseted.
120116
121117
"""
122118
return _get_data()['reverberation']

0 commit comments

Comments
 (0)