unit test for PartitionedSignal.__Cat__
[ieee754fpu.git] / src / ieee754 / part_mul_add / partpoints.py
index 887372af62cef7bb7b213cd63e98dbb10aae85ce..8ae238103e32b3d7b7f176d6c2a838a517a372f4 100644 (file)
@@ -28,23 +28,29 @@ def make_partition(mask, width):
 
 def make_partition2(mask, width):
     """ from a mask and a bitwidth, create partition points.
-        note that the assumption is that the mask indicates the
-        breakpoints in regular intervals, and that the last bit (MSB)
-        of the mask is therefore *ignored*.
-        mask len = 4, width == 16 will return:
+        note that the mask represents the actual partition points
+        and therefore must be ONE LESS than the number of required
+        partitions
+
+        mask len = 3, width == 16 will return:
             {4: mask[0], 8: mask[1], 12: mask[2]}
-        mask len = 8, width == 64 will return:
+        mask len = 7, width == 64 will return:
             {8: mask[0], 16: mask[1], 24: mask[2], .... 56: mask[6]}
     """
-    mlen = len(mask)
+    mlen = len(mask) + 1     # ONE MORE partitions than break-points
     jumpsize = width // mlen # amount to jump by (size of each partition)
     ppoints = {}
     ppos = jumpsize
     midx = 0
+    if isinstance(mask, dict): # convert dict/partpoints to sequential list
+        mask = list(mask.values())
+    print ("make_partition2", width, mask, mlen, jumpsize)
     while ppos < width and midx < mlen: # -1, ignore last bit
+        print ("    make_partition2", ppos, width, midx, mlen)
         ppoints[ppos] = mask[midx]
         ppos += jumpsize
         midx += 1
+    print ("    make_partition2", mask, width, ppoints)
     return ppoints