simplify DCT code
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 19 Jul 2021 14:53:17 +0000 (15:53 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 19 Jul 2021 14:53:17 +0000 (15:53 +0100)
src/openpower/decoder/isa/fastdct-test.py
src/openpower/decoder/isa/fastdctlee.py

index 872cfb5c1de14bc781e3d7f1f7104ef6a166cf53..25a16f3dc42a17e562a5f8ef3bf95282dd23b62a 100644 (file)
@@ -28,7 +28,7 @@ import fastdctlee, naivedct
 class FastDctTest(unittest.TestCase):
 
     def test_fast_dct_lee_vs_naive(self):
-        for i in range(3, 4):
+        for i in range(3, 10):
             n = 2**i
             vector = FastDctTest.nonrandom_vector(n)
             expect = naivedct.transform(vector)
index 97b953632772dc2c293c14372bc8b5e9eed51022..425c5e334a70d05991dcfec8a7363ec9d63eec50 100644 (file)
@@ -164,10 +164,9 @@ def transform2(vec):
         for i in ir:
             k = 0
             j = list(range(i, i + halfsize))
-            jr = list(range(i+halfsize, i + size))
-            jr.reverse()
-            print ("  xform jr", j, jr)
-            for ci, (jl, jh) in enumerate(zip(j, jr)):
+            print ("  xform j", j)
+            for ci, jl in enumerate(j):
+                jh = i+size-jl-1
                 t1, t2 = vec[ri[jl]], vec[ri[jh]]
                 # normally DCT would use jl+halfsize not jh, here.
                 # to be able to work in-place, the idea is to perform a
@@ -186,7 +185,8 @@ def transform2(vec):
             # incredibly... bizarrely... this works *without* having
             # to do anything else.
             hz2 = halfsize // 2 # can be zero which stops reversing 1-item lists
-            for ci, (jl, jh) in enumerate(zip(j[:hz2], jr[:hz2])):
+            for jl in j[:hz2]:
+                jh = i+size-jl-1
                 tmp = ri[jl+halfsize]
                 ri[jl+halfsize] = ri[jh]
                 ri[jh] = tmp