Skip to content

Commit 99b6d70

Browse files
authored
Merge pull request #141 from dkazanc/defrag-radway-79
Optimize `calc_filter` (LPRec)
2 parents 7f5559a + 92605b0 commit 99b6d70

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

tests/test_fourier.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from tomobar.fourier import calc_filter
2+
from numpy.testing import assert_allclose
3+
import pytest
4+
5+
6+
@pytest.mark.parametrize(
7+
"test_case",
8+
[
9+
("none", 100),
10+
("ramp", 0.496701),
11+
("shepp", 0.447188),
12+
("cosine", 0.25168),
13+
("cosine2", 0.164889),
14+
("hamming", 0.185245),
15+
("hann", 0.164889),
16+
("parzen", 0.042508),
17+
],
18+
)
19+
def test_calc_filter(test_case):
20+
filter_name, expected_median = test_case
21+
length = 100
22+
f = calc_filter(length, filter_name, 1.0)
23+
assert f.size == length / 2 + 1
24+
f = f.get()
25+
f.sort()
26+
assert_allclose(f[f.size // 2], expected_median, rtol=1e-5)

tomobar/fourier.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def _wint(n, t):
100100
for j in range(N - n + 1):
101101
# Change coordinates, and constant and linear parts
102102
W = ((t[j + n - 1] - t[j]) ** 2) * W1 + (t[j + n - 1] - t[j]) * t[j] * W2
103-
104-
for k in range(n - 1):
105-
w[j : j + n] = w[j : j + n] + p[j + k] * W[:, k]
103+
w[j : j + n] += W @ p[j : j + n - 1]
106104

107105
wn = w
108106
wn[-40:] = (w[-40]) / (N - 40) * np.arange(N - 40, N)

0 commit comments

Comments
 (0)