# python "yield" can be iterated. use this to make it clear how
# the indices are generated by using natural-looking nested loops
def iterate_indices(SVSHAPE):
+ # establish if this is triangular mode
+ triangle = SVSHAPE.mode == 0b11 and SVSHAPE.submode == 0b00
# get indices to iterate over, in the required order
xd = SVSHAPE.lims[0]
yd = SVSHAPE.lims[1]
zd = SVSHAPE.lims[2]
# create lists of indices to iterate over in each dimension
- x_r = list(range(xd))
- y_r = list(range(yd))
+ _x_r = list(range(xd))
+ _y_r = list(range(yd))
z_r = list(range(zd))
# invert the indices if needed
if SVSHAPE.invxyz[0]: x_r.reverse()
# start an infinite (wrapping) loop
step = 0 # track src/dst step
while True:
- for z in z_r: # loop over 1st order dimension
+ for zi, z in enumerate(z_r): # loop over 1st order dimension
z_end = z == z_r[-1]
- for y in y_r: # loop over 2nd order dimension
+ # triangle uses a truncated copy
+ y_r = list(_y_r[:zi+1] if triangle else _y_r)
+ y_end = True # if list is empty
+ for yi, y in enumerate(y_r): # loop over 2nd order dimension
y_end = y == y_r[-1]
- for x in x_r: # loop over 3rd order dimension
+ x_r = list(_x_r[:yi+1] if triangle else _x_r)
+ x_end = True # if list is empty
+ for xi, x in enumerate(x_r): # loop over 3rd order dimension
x_end = x == x_r[-1]
# ok work out which order to construct things in.
# start by creating a list of tuples of the dimension
# was actually selected above on all 3 dimensions,
# e.g. [z][x][y] or [y][z][x]. "skip" allows one of
# those to be knocked out
- if SVSHAPE.skip == i+1: continue
#print ("select %d %s" % (i, dbg))
- if SVSHAPE.mode == 0b00:
+ if SVSHAPE.mode == 0b00: # Matrix Mode
+ if SVSHAPE.skip == i+1: continue
idx *= mult # shifts up by previous dimension(s)
result += idx # adds on this dimension
- if SVSHAPE.mode == 0b00:
+ if SVSHAPE.mode == 0b00: # Matrix Mode
mult *= lim # for the next dimension
loopends = (x_end |
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:
+ print()
break
+ triangle = SVSHAPE0.mode == 0b11 and SVSHAPE0.submode == 0b00
+ if triangle:
+ if SVSHAPE0.lims[0] == 1: end &= ~0b001
+ if triangle:
+ if SVSHAPE0.lims[1] == 1: end &= ~0b010
+ if end != 0:
+ print()
def demo():
dump_shape(SVSHAPE0)
# rhombus - see https://bugs.libre-soc.org/show_bug.cgi?id=1155#c17
- print("\ntriangular, skip-x", xdim, ydim, zdim)
+ xdim, ydim, zdim = 3, 4, 1 # set the dimension sizes here
+ print("\nrhombus", xdim, ydim, zdim)
+ SVSHAPE0 = SVSHAPE()
+ SVSHAPE0.lims = [xdim, ydim, zdim]
+ SVSHAPE0.order = [0,1,2] # experiment with different permutations, here
+ SVSHAPE0.mode = 0b11
+ SVSHAPE0.submode = 0b01 # rhombus mode
+ SVSHAPE0.offset = 0 # experiment with different offset, here
+ SVSHAPE0.invxyz = [0,0,0] # inversion if desired
+
+ dump_shape(SVSHAPE0)
+
+ # triangle
+ print("\ntriangle", xdim, ydim, zdim)
+ xdim, ydim, zdim = 1, 5, 5 # set the dimension sizes here
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.submode = 0b00 # triangle mode
SVSHAPE0.offset = 0 # experiment with different offset, here
SVSHAPE0.invxyz = [0,0,0] # inversion if desired