Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import sys
- import itertools
- # routines
- PREFIX_NAME='tile_repart'
- TEST= os.path.join('testcases', 't', 'checkin', 'other')
- RESULT= os.path.join('testcases', 'r', 'checkin', 'other')
- DATA= os.path.join('testcases', 'data')
- DATA_LOAD= os.path.join('..', 'tests', 'harness', DATA)
- def getter(prefix, suffix):
- def result(*setting):
- return os.path.join(prefix, '%s_%s.%s' % (PREFIX_NAME, "_".join(setting), suffix))
- return result
- PATH_LIST= [ TEST, RESULT, DATA, DATA_LOAD ]
- SUFFIX_LIST= [ 'test', 'result', 'txt', 'txt' ]
- GET_PATH_LIST= [ getter(prefix, suffix) for (prefix, suffix) in zip(PATH_LIST, SUFFIX_LIST) ]
- # constant
- SOURCE='source'
- RESULT='result'
- NAME='name'
- SIZE='size'
- COUNT='count'
- TYPE='type'
- MULTIPLIER='multiplier'
- # chunks sizes
- SAME='same'
- ALIGNED_INCREASE='aligned_increase'
- ALIGNED_DECREASE='aligned_decrease'
- NOT_ALIGNED='not_aligned'
- PARTIALLY_ALIGNED='partially_aligned'
- CHUNK_SIZES_LIST=[SAME, ALIGNED_INCREASE, ALIGNED_DECREASE, NOT_ALIGNED, PARTIALLY_ALIGNED]
- # overlap
- OVERLAP_SAME='overlap_same'
- OVERLAP_NONE='overlap_none'
- OVERLAP_ADD='overlap_add'
- OVERLAP_REMOVE='overlap_remove'
- OVERLAP_INCREASE='overlap_increase'
- OVERLAP_DECREASE='overlap_decrease'
- OVERLAP_LIST=[OVERLAP_ADD, OVERLAP_REMOVE, OVERLAP_INCREASE, OVERLAP_DECREASE]
- # algorithm
- DENSE='dense'
- SPARSE='sparse'
- ALGORITHM_LIST=[DENSE, SPARSE]
- # all available settings
- SETTING_LIST= [CHUNK_SIZES_LIST, OVERLAP_LIST, ALGORITHM_LIST]
- # combination which should included
- def include_setting(chunk_sizes, overlap, algorithm):
- return not ((chunk_sizes == SAME) and overlap in set([OVERLAP_SAME, OVERLAP_NONE]))
- # generate permutations list
- PERMUTATIONS_LIST= itertools.ifilter(lambda setting: include_setting(*setting), itertools.product(*SETTING_LIST))
- def iterate_permutations(function):
- def result():
- for setting in PERMUTATIONS_LIST:
- function(*setting)
- return result
- # print single setting
- def print_setting(function):
- def result(*setting):
- print "TEST [Chunk sizes: '%s' Overlap: '%s' Algorithm: '%s']" % tuple(setting)
- function(*setting)
- return result
- # setting
- DIMENSION_LIST=[ {NAME: 'x', MULTIPLIER: 1} ] # {NAME: 'y', MULTIPLIER: 3}
- ATTRIBUTE_LIST=[ {NAME: 'a', TYPE: 'int32'} ] # {NAME: 'b', TYPE: 'int64'}
- O_ZERO= 0
- O_VALUE= 1
- O_LESSER= 2
- O_GREATER= 3
- OVERLAP_DICT= {
- OVERLAP_NONE: { SOURCE: O_ZERO, RESULT: O_ZERO },
- OVERLAP_SAME: { SOURCE: O_VALUE, RESULT: O_VALUE },
- OVERLAP_ADD: { SOURCE: O_ZERO, RESULT: O_VALUE },
- OVERLAP_REMOVE: { SOURCE: O_VALUE, RESULT: O_ZERO },
- OVERLAP_INCREASE: { SOURCE: O_LESSER, RESULT: O_GREATER },
- OVERLAP_DECREASE: { SOURCE: O_GREATER, RESULT: O_LESSER }
- }
- CS_ZERO= 0
- CS_VALUE= 2
- CS_LESSER= 2
- CS_GREATER= 3
- CS_COPRIME_FIRST= 2
- CS_COPRIME_SECOND= 3
- CHUNK_SIZES_DICT= {
- SAME: { SOURCE: { SIZE: CS_VALUE, COUNT: CS_VALUE },
- RESULT: { SIZE: CS_VALUE, COUNT: CS_VALUE } },
- ALIGNED_INCREASE: { SOURCE: { SIZE: CS_LESSER, COUNT: CS_GREATER },
- RESULT: { SIZE: CS_GREATER, COUNT: CS_LESSER } },
- ALIGNED_DECREASE: { SOURCE: { SIZE: CS_GREATER, COUNT: CS_LESSER },
- RESULT: { SIZE: CS_LESSER, COUNT: CS_GREATER } },
- NOT_ALIGNED: { SOURCE: { SIZE: CS_COPRIME_FIRST, COUNT: CS_COPRIME_SECOND },
- RESULT: { SIZE: CS_COPRIME_SECOND, COUNT: CS_COPRIME_FIRST } },
- PARTIALLY_ALIGNED: { SOURCE: { SIZE: CS_COPRIME_FIRST*2, COUNT: CS_COPRIME_SECOND*2 },
- RESULT: { SIZE: CS_COPRIME_SECOND*2, COUNT: CS_COPRIME_FIRST*2 } }
- }
- # dimensions
- def dimension(chunk, overlap):
- def generate(setting):
- size= chunk[SIZE]
- maximum= chunk[SIZE] * chunk[COUNT]
- return '%s=0:%s,%s,%s' % tuple([ setting[NAME] ] + [ str(item * setting[MULTIPLIER]) for item in [maximum, size, overlap] ])
- return ','.join([ generate(setting) for setting in DIMENSION_LIST ])
- # attributes
- def attribute():
- def generate(attribute):
- return '%s: %s' % (attribute[NAME], attribute[TYPE])
- return ','.join(map(generate, ATTRIBUTE_LIST))
- # array
- def create_array(name, chunk, overlap):
- return 'create array %s [%s] <%s>' % (name, attribute(), dimension(chunk, overlap))
- def remove_array(name):
- return 'remove(%s)' % name
- # generate tests, expected results, data for tests
- @iterate_permutations
- @print_setting
- def generate(*setting):
- (chunk_sizes, overlap, algorithm)= tuple(setting)
- def data():
- return 'data'
- def test():
- def setup():
- chunk_d= CHUNK_SIZES_DICT[chunk_sizes]
- overlap_d= OVERLAP_DICT[overlap]
- source= create_array(SOURCE, chunk_d[SOURCE], overlap_d[SOURCE])
- result= create_array(RESULT, chunk_d[RESULT], overlap_d[RESULT])
- data_load_index= PATH_LIST.index(DATA_LOAD)
- get_data_load_path= GET_PATH_LIST[data_load_index]
- data_load_path= get_data_load_path(chunk_sizes, overlap, algorithm)
- data_load= "load(%s, '%s')" % (SOURCE, data_load_path)
- return [source, result, data_load]
- def test():
- return ['scan(source)', 'repart(source, result)', 'store(repart(source, result), result)', 'scan(result)']
- def cleanup():
- return [ remove_array(name) for name in [SOURCE, RESULT] ]
- header= [ ['--' + header] for header in ['setup', 'test', 'cleanup'] ]
- queries= [ [query + ';' for query in generator()] for generator in [setup, test, cleanup] ]
- lines= reduce(lambda result, line: result + line, [ header + queries for (header, queries) in zip(header, queries) ])
- return os.linesep.join(lines)
- def result():
- return 'result'
- def write_file(name, data):
- f= open(name, 'w')
- f.write(data)
- f.close()
- print "Wrote: '%s'" % name
- ACTION_LIST= [test, result, data]
- [ write_file(get_path(*setting), action()) for (get_path, action) in zip(GET_PATH_LIST, ACTION_LIST) ]
- @iterate_permutations
- @print_setting
- def clean(*setting):
- def remove_file(name):
- os.remove(name)
- print "Removed: '%s'" % name
- [ remove_file(get_path(*setting)) for get_path in GET_PATH_LIST[:-1] ]
- def unknown():
- sys.stderr.write('Error: unknown acion "%s"%s' % (sys.argv[1], os.linesep))
- exit(-1)
- if __name__ == "__main__":
- if len(sys.argv) != 2:
- sys.stderr.write('Error: specify action (generate or clean)%s' % os.linesep)
- exit(-1)
- { 'generate': generate, 'clean': clean }.get(sys.argv[1], unknown)()
Advertisement
Add Comment
Please, Sign In to add comment