start on inverse DCT, transforming to iterative
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 28 Jul 2021 18:04:52 +0000 (19:04 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 28 Jul 2021 18:04:52 +0000 (19:04 +0100)
src/openpower/decoder/isa/fastdct-test.py
src/openpower/decoder/isa/fastdctlee.py

index 14214b2b8f5bd54ffe4465765f5db1d3718594b1..033df0ffd546619828008e13cfddf2055eb22285 100644 (file)
@@ -27,8 +27,8 @@ import fastdctlee, naivedct, remap_dct_yield
 
 class FastDctTest(unittest.TestCase):
 
-    def tst_fast_dct_lee_vs_naive(self):
-        for i in range(3, 10):
+    def test_fast_dct_lee_vs_naive(self):
+        for i in range(3, 4):
             n = 2**i
             vector = FastDctTest.nonrandom_vector(n)
             expect = naivedct.transform(vector)
@@ -36,10 +36,10 @@ class FastDctTest(unittest.TestCase):
             actual = fastdctlee.transform2(vector)
             self.assertListAlmostEqual(actual, expect)
             expect = naivedct.inverse_transform(vector)
-            actual = fastdctlee.inverse_transform(vector)
+            actual = fastdctlee.inverse_transform2(vector)
             self.assertListAlmostEqual(actual, expect)
 
-    def test_yield_dct_lee_vs_naive(self):
+    def tst_yield_dct_lee_vs_naive(self):
         for i in range(3, 4):
             n = 2**i
             vector = FastDctTest.nonrandom_vector(n)
index 68678ab947725abc1a19eb8bfdfe0f702fa9b39c..1fefc39bed93eafedabb8dcdef746afa616fe7dc 100644 (file)
@@ -310,37 +310,44 @@ def inverse_transform(vector, root=True, indent=0):
         inverse_transform(alpha, False, indent+1)
         inverse_transform(beta , False, indent+1)
         for i in range(half):
-            x = alpha[i]
-            y = beta[i] / (math.cos((i + 0.5) * math.pi / n) * 2)
+            x, y = alpha[i], beta[i]
+            coeff = (math.cos((i + 0.5) * math.pi / n) * 2)
+            y /= coeff
             vector[i] = x + y
-            vector[-(i + 1)] = x - y
+            vector[n-(i+1)] = x - y
             print (idt, " v[%d] = alpha[%d]+beta[%d]" % (i, i, i))
             print (idt, " v[%d] = alpha[%d]-beta[%d]" % (n-i-1, i, i))
         return vector
 
 
-def inverse_transform2(vector, root=True):
+def inverse_transform2(vector, root=True, indent=0):
+    idt = "   " * indent
     n = len(vector)
     if root:
         vector = list(vector)
+        vector[0] /= 2
     if n == 1:
         return vector
     elif n == 0 or n % 2 != 0:
         raise ValueError()
     else:
         half = n // 2
-        alpha = [0]
-        beta  = [1]
+        alpha = [vector[0]]
+        beta  = [vector[1]]
         for i in range(2, n, 2):
-            alpha.append(i)
-            beta.append(("add", i - 1, i + 1))
-        inverse_transform2(alpha, False)
-        inverse_transform2(beta , False)
+            alpha.append(vector[i])
+            beta.append(vector[i - 1] + vector[i + 1])
+        inverse_transform2(alpha, False, indent+1)
+        inverse_transform2(beta , False, indent+1)
         for i in range(half):
+            x, y = alpha[i], beta[i]
+            coeff = (math.cos((i + 0.5) * math.pi / n) * 2)
+            y /= coeff
+            vector[i] = x + y
+            vector[n-(i+1)] = x - y
+            print (idt, " v[%d] = alpha[%d]+beta[%d]" % (i, i, i))
+            print (idt, " v[%d] = alpha[%d]-beta[%d]" % (n-i-1, i, i))
             x = alpha[i]
-            y = ("cos", beta[i], i)
-            vector[i] = ("add", x, y)
-            vector[-(i + 1)] = ("sub", x, y)
         return vector