Skip to content

Commit b866df9

Browse files
authored
Merge pull request #354 from LCAV/bug/issue353
bugfixes
2 parents 40e973c + 79db2b1 commit b866df9

File tree

8 files changed

+52
-8
lines changed

8 files changed

+52
-8
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Bugfix
2626
ticks when called with ``kind="tf"``
2727
- Fixes an issue where the ``visibility`` attribute of the room is not
2828
set if there are no visible source or image source in the room. (#313)
29+
- Fixes issue with cast reflections delays to float32 in room.py (#353)
30+
- Fixes calls to ``numpy.linalg.solve`` with Numpy 2.0 API
2931

3032
`0.7.4`_ - 2024-04-25
3133
---------------------

pyroomacoustics/bss/auxiva.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def demix(Y, X, W):
227227
)
228228

229229
WV = np.matmul(W_hat, V)
230-
W[:, s, :] = np.conj(np.linalg.solve(WV, eyes[:, :, s]))
230+
W[:, s, :] = np.conj(np.linalg.solve(WV, eyes[:, :, [s]]))[..., 0]
231231

232232
# normalize
233233
denom = np.matmul(

pyroomacoustics/bss/fastmnmf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def separate():
175175

176176
try:
177177
tmp_FM = np.linalg.solve(
178-
np.matmul(Q_FMM, V_FMM), np.eye(n_chan)[None, m]
179-
)
178+
np.matmul(Q_FMM, V_FMM), np.eye(n_chan)[None, :, [m]]
179+
)[..., 0]
180180
except np.linalg.LinAlgError:
181181
# If Gaussian elimination fails due to a singlular matrix, we
182182
# switch to the pseudo-inverse solution

pyroomacoustics/bss/fastmnmf2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def separate():
165165
np.einsum("ftij, ft -> fij", XX_FTMM, 1 / Y_FTM[..., m]) / n_frames
166166
)
167167
tmp_FM = np.linalg.solve(
168-
np.matmul(Q_FMM, V_FMM), np.eye(n_chan)[None, m]
169-
)
168+
np.matmul(Q_FMM, V_FMM), np.eye(n_chan)[None, :, [m]]
169+
)[..., 0]
170170
Q_FMM[:, m] = (
171171
tmp_FM
172172
/ np.sqrt(

pyroomacoustics/bss/ilrma.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def demix(Y, X, W):
159159
C = np.matmul((X * iR[s, :, None, :]), np.conj(X.swapaxes(1, 2))) / n_frames
160160

161161
WV = np.matmul(W, C)
162-
W[:, s, :] = np.conj(np.linalg.solve(WV, eyes[:, :, s]))
162+
W[:, s, :] = np.conj(np.linalg.solve(WV, eyes[:, :, [s]]))[..., 0]
163163

164164
# normalize
165165
denom = np.matmul(

pyroomacoustics/bss/sparseauxiva.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def demixsparse(Y, X, S, W):
148148
W_H = np.conj(np.swapaxes(W, 1, 2))
149149
WV = np.matmul(W_H, V[:, s, :, :])
150150
rhs = I[None, :, s][[0] * WV.shape[0], :]
151-
W[:, :, s] = np.linalg.solve(WV, rhs)
151+
W[:, :, s] = np.linalg.solve(WV, rhs[..., None])[..., 0]
152152

153153
# normalize
154154
P1 = np.conj(W[:, :, s])

pyroomacoustics/room.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,8 @@ def compute_rir(self):
22582258

22592259
# compute the distance from image sources
22602260
dist = np.sqrt(np.sum((src.images - mic[:, None]) ** 2, axis=0))
2261-
time = dist / self.c
2261+
# the RIR building routine works in float32, so we cast here
2262+
time = (dist / self.c).astype(np.float32)
22622263
t_max = time.max()
22632264
N = int(math.ceil(t_max * self.fs))
22642265

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
# Test for Issue 353
3+
4+
[issue #353](https://github.com/LCAV/pyroomacoustics/issues/353)
5+
6+
The cause of the issue was that the time of the maximum delay
7+
in the RIR is used to determine the necessary size of the array.
8+
9+
The float64 value of the delay was used to determine the size and construct the array.
10+
However, the `rir_build` routine takes float32.
11+
After conversion, the array size would evaluate to one delay more due to rounding
12+
offset and an array size check would fail.
13+
14+
Converting the delay time array to float32 before creating the rir array
15+
solved the issue.
16+
"""
17+
18+
import numpy as np
19+
20+
import pyroomacoustics as pra
21+
22+
23+
def test_issue_353():
24+
room_dims = np.array([10.0, 10.0, 10.0])
25+
room = pra.ShoeBox(
26+
room_dims, fs=24000, materials=None, max_order=22, use_rand_ism=False
27+
)
28+
29+
source = np.array([[6.35551912], [4.33308523], [3.69586303]])
30+
room.add_source(source)
31+
32+
mic_array_in_room = np.array(
33+
[
34+
[1.5205189, 1.49366285, 1.73302404, 1.67847898],
35+
[4.68430529, 4.76250254, 4.67956424, 4.60702604],
36+
[2.68214263, 2.7980202, 2.55341851, 2.72701718],
37+
]
38+
)
39+
room.add_microphone_array(mic_array_in_room)
40+
41+
room.compute_rir()

0 commit comments

Comments
 (0)