OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
generate_loop_ref.py
Go to the documentation of this file.
1 def generate(mask, cond_mask, upper_bounds):
2  indent_level = 0
3  start_iterator_ch = 'i'
4  cond_idx = 0
5  iterators = []
6  loops = ''
7  for i in xrange(0, len(upper_bounds)):
8  if mask & (1 << i):
9  cond_is_true = (cond_mask & (1 << cond_idx)) != 0
10  slot_lookup_result = 99 if cond_is_true else -1
11  if_cond = indent_level * ' ' + 'if %d >= 0:' % slot_lookup_result
12  cond_idx += 1
13  iterators.append(slot_lookup_result)
14  loops += if_cond + '\n'
15  else:
16  iterator_ch = chr(ord(start_iterator_ch) + i)
17  for_loop = (indent_level * ' ' + 'for %s in xrange(0, %d):' %
18  (iterator_ch, upper_bounds[i]))
19  iterators.append(iterator_ch)
20  loops += for_loop + '\n'
21  indent_level += 1
22  loops += (indent_level * ' ' + "print('" + ', '.join(['%s' for iterator in iterators])
23  + "' % (" + ', '.join([str(iterator) for iterator in iterators]) + '))')
24  return loops
25 
26 if __name__ == '__main__':
27  upper_bounds = [5, 3, 9]
28  for mask in xrange(0, 1 << len(upper_bounds)):
29  mask_bitcount = bin(mask).count("1")
30  for cond_mask in xrange(0, 1 << mask_bitcount):
31  loops = generate(mask, cond_mask, upper_bounds)
32  exec(loops)
std::string join(T const &container, std::string const &delim)