annoying: missed out something in the unit test, not working yet
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 19 Jul 2021 14:59:03 +0000 (15:59 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 19 Jul 2021 14:59:03 +0000 (15:59 +0100)
src/openpower/decoder/isa/fastdct-test.py
src/openpower/decoder/isa/fastdctlee.py

index 25a16f3dc42a17e562a5f8ef3bf95282dd23b62a..872cfb5c1de14bc781e3d7f1f7104ef6a166cf53 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, 10):
+        for i in range(3, 4):
             n = 2**i
             vector = FastDctTest.nonrandom_vector(n)
             expect = naivedct.transform(vector)
index 425c5e334a70d05991dcfec8a7363ec9d63eec50..b27caa6ce27e40b340e4ece43d739bc46ed41841 100644 (file)
@@ -149,12 +149,6 @@ def transform2(vec):
     # and pretend we LDed the data in bit-reversed order as well
     vec = [vec[reverse_bits(i, levels)] for i in range(n)]
 
-    # create cos coefficient table
-    coeffs = []
-    for ci in range(n):
-        coeffs.append((math.cos((ci + 0.5) * math.pi / n) * 2.0))
-
-    # start the inner butterfly
     size = n
     while size >= 2:
         halfsize = size // 2
@@ -164,18 +158,18 @@ def transform2(vec):
         for i in ir:
             k = 0
             j = list(range(i, i + halfsize))
-            print ("  xform j", j)
-            for ci, jl in enumerate(j):
-                jh = i+size-jl-1
+            jr = list(range(i+halfsize, i + size))
+            jr.reverse()
+            print ("  xform jr", j, jr)
+            for ci, (jl, jh) in enumerate(zip(j, jr)):
                 t1, t2 = vec[ri[jl]], vec[ri[jh]]
+                coeff = (math.cos((ci + 0.5) * math.pi / size) * 2.0)
                 # normally DCT would use jl+halfsize not jh, here.
                 # to be able to work in-place, the idea is to perform a
-                # high-half reverse/swap afterwards.  however actually
-                # we swap the *indices*
-                coeff = coeffs[k]
+                # swap afterwards.  however actually we swap the *indices*
                 vec[ri[jl]] = t1 + t2
                 vec[ri[jh]] = (t1 - t2) * (1/coeff)
-                print (" ", size, i, k, "ci", ci,
+                print ("coeff", size, i, k, "ci", ci,
                         "jl", ri[jl], "jh", ri[jh],
                        "i/n", (k+0.5)/size, coeff, vec[ri[jl]], vec[ri[jh]])
                 k += tablestep
@@ -185,8 +179,7 @@ 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 jl in j[:hz2]:
-                jh = i+size-jl-1
+            for ci, (jl, jh) in enumerate(zip(j[:hz2], jr[:hz2])):
                 tmp = ri[jl+halfsize]
                 ri[jl+halfsize] = ri[jh]
                 ri[jh] = tmp