zamotivator

Untitled

May 7th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. SOURCE='source'
  4. RESULT='result'
  5.  
  6. NAME='name'
  7. SIZE='size'
  8. COUNT='count'
  9. TYPE='type'
  10. MULTIPLIER='multiplier'
  11.  
  12. # chunks sizes
  13. SAME='same'
  14. ALIGNED_INCREASE='aligned_increase'
  15. ALIGNED_DECREASE='aligned_decrease'
  16. NOT_ALIGNED='not_aligned'
  17. PARTIALLY_ALIGNED='partially_aligned'
  18.  
  19. CHUNK_SIZES_LIST=[SAME, ALIGNED_INCREASE, ALIGNED_DECREASE, NOT_ALIGNED, PARTIALLY_ALIGNED]
  20.  
  21. # overlap
  22. OVERLAP_SAME='overlap_same'
  23. OVERLAP_NONE='overlap_none'
  24. OVERLAP_ADD='overlap_add'
  25. OVERLAP_REMOVE='overlap_remove'
  26. OVERLAP_INCREASE='overlap_increase'
  27. OVERLAP_DECREASE='overlap_decrease'
  28.  
  29. OVERLAP_LIST=[OVERLAP_ADD, OVERLAP_REMOVE, OVERLAP_INCREASE, OVERLAP_DECREASE]
  30.  
  31. # algorithm
  32. DENSE='dense'
  33. SPARSE='sparse'
  34.  
  35. ALGORITHM_LIST=[DENSE, SPARSE]
  36.  
  37. SETTING_LIST= [CHUNK_SIZES_LIST, OVERLAP_LIST, ALGORITHM_LIST]
  38. def include_setting(chunk_sizes, overlap, algorithm):
  39. return not ((chunk_sizes == SAME) and overlap in set([OVERLAP_SAME, OVERLAP_NONE]))
  40. import itertools
  41. PERMUTATIONS_LIST= itertools.ifilter(lambda setting: include_setting(*setting), itertools.product(*SETTING_LIST))
  42.  
  43. def print_setting(*setting):
  44. print "TEST [Chunk sizes: '%s' Overlap: '%s' Algorithm: '%s']" % tuple(setting)
  45.  
  46. import os
  47.  
  48. # defaults
  49. prefix_path='testcases'
  50. test= os.path.join('t', 'checkin', 'other')
  51. result= os.path.join('r', 'checkin', 'other')
  52. data= 'data'
  53. path_list= [ test, result, data ]
  54. suffix_list= [ 'test', 'result', 'data' ]
  55.  
  56. prefix_name='tile_repart'
  57.  
  58. def getter(prefix, suffix):
  59. def result(*setting):
  60. return os.path.join('testcases', '%s_%s.%s' % (prefix, "_".join(setting), suffix))
  61. return result
  62. GET_PATH_LIST= [ getter(prefix, suffix) for (prefix, suffix) in zip(path_list, suffix_list) ]
  63.  
  64. # setting
  65.  
  66. def get_overlap_setting(overlap):
  67. value= 1
  68. lesser= value * 2
  69. greater= value * 3
  70. d= {
  71. OVERLAP_NONE: { SOURCE: 0, RESULT: 0 },
  72. OVERLAP_SAME: { SOURCE: value, RESULT: value },
  73. OVERLAP_ADD: { SOURCE: 0, RESULT: value },
  74. OVERLAP_REMOVE: { SOURCE: value, RESULT: 0 },
  75. OVERLAP_INCREASE: { SOURCE: lesser, RESULT: greater },
  76. OVERLAP_DECREASE: { SOURCE: greater, RESULT: lesser }
  77. }
  78. return d[overlap]
  79.  
  80. def get_chunk_setting(chunk_sizes):
  81. value= 2
  82. lesser= value
  83. greater= value * 2
  84. coprime_first= 2
  85. coprime_second= 3
  86. d= {
  87. SAME: { SIZE: { SOURCE: value, RESULT: value },
  88. COUNT: { SOURCE: value, RESULT: value } },
  89. ALIGNED_INCREASE: { SIZE: { SOURCE: lesser, RESULT: greater },
  90. COUNT: { SOURCE: greater, RESULT: lesser } },
  91. ALIGNED_DECREASE: { SIZE: { SOURCE: greater, RESULT: lesser },
  92. COUNT: { SOURCE: lesser, RESULT: greater } },
  93. NOT_ALIGNED: { SIZE: { SOURCE: coprime_first, RESULT: coprime_second },
  94. COUNT: { SOURCE: coprime_second, RESULT: coprime_first } },
  95. PARTIALLY_ALIGNED: { SIZE: { SOURCE: coprime_first*2, RESULT: coprime_second*2 },
  96. COUNT: { SOURCE: coprime_second*2, RESULT: coprime_first*2 } }
  97. }
  98. r= {}
  99. for key in d:
  100. value= d[key]
  101. r[key]= { SOURCE: { SIZE: value[SIZE][SOURCE], COUNT: value[COUNT][SOURCE] },
  102. RESULT: { SIZE: value[SIZE][RESULT], COUNT: value[COUNT][RESULT] } }
  103. return r[chunk_sizes]
  104.  
  105. def dimension(chunk, overlap):
  106. def generate(setting):
  107. maximum= chunk[SIZE] * chunk[COUNT]
  108. size= chunk[SIZE]
  109. multiply= lambda value: value * setting[MULTIPLIER]
  110. data= [maximum, size, overlap]
  111. data= tuple([ setting[NAME] ] + map(str, map(multiply, data)))
  112. return '%s=0:%s,%s,%s' % data
  113. return ','.join([ generate(setting) for setting in [ {NAME: 'x', MULTIPLIER: 1} ] ])
  114.  
  115. def attribute():
  116. def generate(attribute):
  117. return '%s: %s' % (attribute[NAME], attribute[TYPE])
  118. attribute= [ {NAME: 'a', TYPE: 'int32'} ]
  119. return ','.join(map(generate, attribute))
  120.  
  121. def generate_array(name, chunk, overlap):
  122. return 'create array %s [%s] <%s>' % (name, attribute(), dimension(chunk, overlap))
  123.  
  124. def remove_array(name):
  125. return 'remove(%s)' % name
  126.  
  127. def generate():
  128. for setting in PERMUTATIONS_LIST:
  129. print_setting(*setting)
  130.  
  131. def data(*setting):
  132. return 'data'
  133.  
  134. def test(chunk_sizes, overlap, algorithm):
  135. def setup():
  136. chunk_s= get_chunk_setting(chunk_sizes)
  137. overlap_s= get_overlap_setting(overlap)
  138. source= generate_array(SOURCE, chunk_s[SOURCE], overlap_s[SOURCE])
  139. result= generate_array(RESULT, chunk_s[RESULT], overlap_s[RESULT])
  140. return [source, result]
  141. def test():
  142. return ['scan(source)', 'repart(source, result)', 'store(repart(source, result), result)', 'scan(result)']
  143. def cleanup():
  144. return map(remove_array, [SOURCE, RESULT])
  145. header= [ ['--' + header] for header in ['setup', 'test', 'cleanup'] ]
  146. queries= [ [query + ';' for query in generator()] for generator in [setup, test, cleanup] ]
  147. lines= reduce(lambda result, line: result + line, [ header + queries for (header, queries) in zip(header, queries) ])
  148. return os.linesep.join(lines)
  149.  
  150. def result(*setting):
  151. return 'result'
  152.  
  153. def write_file(name, data):
  154. print "Write file: '%s'" % name
  155. f= open(name, 'w')
  156. f.write(data)
  157. f.close()
  158. ACTION_LIST= [test, result, data]
  159. [ write_file(get_path(*setting), action(*setting)) for (get_path, action) in zip(GET_PATH_LIST, ACTION_LIST) ]
  160.  
  161. if __name__ == "__main__":
  162. generate()
Advertisement
Add Comment
Please, Sign In to add comment