# those to be knocked out
if SVSHAPE.skip == i+1: continue
#print ("select %d %s" % (i, dbg))
- idx *= mult # shifts up by previous dimension(s)
+ if SVSHAPE.mode == 0b00:
+ idx *= mult # shifts up by previous dimension(s)
result += idx # adds on this dimension
- mult *= lim # for the next dimension
+ if SVSHAPE.mode == 0b00:
+ mult *= lim # for the next dimension
loopends = (x_end |
((y_end and x_end)<<1) |
yield result + SVSHAPE.offset, loopends
step += 1
+def dump_shape(SVSHAPE0):
+ # enumerate over the iterator function, getting new indices
+ for idx, (new_idx, end) in enumerate(iterate_indices(SVSHAPE0)):
+ estring = bin(end)[2:] if end else ''
+ print ("%2d->%-2d" % (idx, new_idx), "%2s" % estring, end=' ')
+ if end != 0:
+ print()
+ if end == 0b111:
+ break
+
+
def demo():
- # set the dimension sizes here
- xdim = 3
- ydim = 2
- zdim = 4
+ xdim, ydim, zdim = 3, 2, 4 # set the dimension sizes here
+ VL = xdim * ydim * zdim # set total (can repeat, e.g. VL=x*y*z*4)
- # set total (can repeat, e.g. VL=x*y*z*4)
- VL = xdim * ydim * zdim
+ class SVSHAPE: pass # dummy class
- # set up an SVSHAPE
- class SVSHAPE:
- pass
+ # set up an SVSHAPE with matrix mode
+ print("matrix", xdim, ydim, zdim)
SVSHAPE0 = SVSHAPE()
SVSHAPE0.lims = [xdim, ydim, zdim]
SVSHAPE0.order = [1,0,2] # experiment with different permutations, here
SVSHAPE0.offset = 0 # experiment with different offset, here
SVSHAPE0.invxyz = [0,0,0] # inversion if desired
- # enumerate over the iterator function, getting new indices
- for idx, (new_idx, end) in enumerate(iterate_indices(SVSHAPE0)):
- if idx >= VL:
- break
- print ("%d->%d" % (idx, new_idx), "end", bin(end)[2:])
+ dump_shape(SVSHAPE0)
+
+ # rhombus - see https://bugs.libre-soc.org/show_bug.cgi?id=1155#c17
+ print("\ntriangular, skip-x", xdim, ydim, zdim)
+ SVSHAPE0 = SVSHAPE()
+ SVSHAPE0.lims = [xdim, ydim, zdim]
+ SVSHAPE0.order = [0,1,2] # experiment with different permutations, here
+ SVSHAPE0.mode = 0b11
+ SVSHAPE0.skip = 0b01 # try skipping x-dimension (for fun)
+ SVSHAPE0.offset = 0 # experiment with different offset, here
+ SVSHAPE0.invxyz = [0,0,0] # inversion if desired
+
+ dump_shape(SVSHAPE0)
# run the demo
if __name__ == '__main__':