From 525ddb67b22db225c5808724d1fd3d3e528bdfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Targe?= <70773604+clemtarge@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:48:10 +0400 Subject: [PATCH 1/2] Some for loop removed --- modwt.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modwt.py b/modwt.py index bf3de8d..27b2b40 100644 --- a/modwt.py +++ b/modwt.py @@ -1,5 +1,5 @@ import numpy as np -import pdb +# import pdb import pywt @@ -8,8 +8,8 @@ def upArrow_op(li, j): return [1] N = len(li) li_n = np.zeros(2 ** (j - 1) * (N - 1) + 1) - for i in range(N): - li_n[2 ** (j - 1) * i] = li[i] + indexes = np.arange(N) + li_n[2 ** (j - 1) * indexes] = np.array(li)[indexes] return li_n @@ -48,15 +48,15 @@ def circular_convolve_d(h_t, v_j_1, j): ''' N = len(v_j_1) L = len(h_t) - w_j = np.zeros(N) l = np.arange(L) - for t in range(N): - index = np.mod(t - 2 ** (j - 1) * l, N) - v_p = np.array([v_j_1[ind] for ind in index]) - w_j[t] = (np.array(h_t) * v_p).sum() + t = np.arange(N).reshape(-1,1) + indexes = np.mod(t - 2 ** (j - 1) * l, N) + w_j = np.matmul(v_j_1[indexes], h_t) return w_j + + def circular_convolve_s(h_t, g_t, w_j, v_j, j): ''' (j-1)th level synthesis from w_j, w_j @@ -64,17 +64,17 @@ def circular_convolve_s(h_t, g_t, w_j, v_j, j): ''' N = len(v_j) L = len(h_t) - v_j_1 = np.zeros(N) l = np.arange(L) - for t in range(N): - index = np.mod(t + 2 ** (j - 1) * l, N) - w_p = np.array([w_j[ind] for ind in index]) - v_p = np.array([v_j[ind] for ind in index]) - v_j_1[t] = (np.array(h_t) * w_p).sum() - v_j_1[t] = v_j_1[t] + (np.array(g_t) * v_p).sum() + t = np.arange(N).reshape(-1,1) + indexes = np.mod(t + 2 ** (j - 1) * l, N) + v_j_1 = np.matmul(w_j[indexes], h_t) + np.matmul(v_j[indexes], g_t) return v_j_1 + + + + def modwt(x, filters, level): ''' filters: 'db1', 'db2', 'haar', ... @@ -149,4 +149,4 @@ def modwtmra(w, filters): s1 = np.arange(10) ws = modwt(s1, 'db2', 3) s1p = imodwt(ws, 'db2') - mra = modwtmra(ws, 'db2') + mra = modwtmra(ws, 'db2') \ No newline at end of file From c2d653561562604c987fc54844fc6e367c765409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Targe?= <70773604+clemtarge@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:56:46 +0400 Subject: [PATCH 2/2] Update modwt.py --- modwt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modwt.py b/modwt.py index 27b2b40..475ee9b 100644 --- a/modwt.py +++ b/modwt.py @@ -1,5 +1,5 @@ import numpy as np -# import pdb +import pdb import pywt @@ -149,4 +149,4 @@ def modwtmra(w, filters): s1 = np.arange(10) ws = modwt(s1, 'db2', 3) s1p = imodwt(ws, 'db2') - mra = modwtmra(ws, 'db2') \ No newline at end of file + mra = modwtmra(ws, 'db2')