def match_sig(self, signature): (name, params) = common.parse_signature(signature) if len(params) != len(self.params): return False for p1, p2 in zip(params, self.params): if p1 != p2: return False return True
def __init__(self): BenchOperator.__init__(self) (self.name, void) = common.parse_signature(self.signature)
def __init__(self): (self.name, self.params) = common.parse_signature(self.signature) super(Operator, self).__init__()
def __new__(cls, name, bases, dct): def member_is_defined(member): if member in dct: return True for bc in range(len(bases)): if member in bases[bc].__dict__: return True return False def get_member_value(member): if member in dct: return dct[member] for bc in range(len(bases)): if member in bases[bc].__dict__: return bases[bc].__dict__[member] raise Exception('Member does not exists in class {}'.format(name)) # We don't care about the parent class if name == 'Operator' or name == 'SrcOperator': return type.__new__(cls, name, bases, dct) # Mandatory members mm = ['categories', 'signature'] for m in mm: if m not in dct: raise Exception('Mandatory member "{}" not given in "{}"'. \ format(m, name)) # Check that all items in categories exists for c in dct['categories']: if type(c) == str: raise Exception( \ 'Category "{}" must not be a string for operator "{}"'. \ format(c, name)) if not hasattr(c, 'name'): raise Exception( \ 'Category "{}" does not exist for operator "{}"'. \ format(c.__class__.__name__, name)) if c.name not in categories: raise Exception( \ 'Category "{}" does not exist for operator "{}"'. \ format(c.__class__.__name__, name)) # Some defaults, that are fixed by the implementation (dct['name'], dct['params']) = common.parse_signature(dct['signature']) if 'output_to' in dct: if dct['output_to'] == common.OUTPUT_TO_SAME_TYPE: dct['closed'] = True else: dct['closed'] = False else: dct['closed'] = True dct['output_to'] = common.OUTPUT_TO_SAME_TYPE # If the operator takes as inputs vectors and returns a scalar, then # by default we cannot autogenerate the C++ advanced API because we # cannot guess how to combine pieces of a unrolled pack if 'autogen_cxx_adv' not in dct: if dct['params'][0] in ['p', 's']: dct['autogen_cxx_adv'] = False else: dct['autogen_cxx_adv'] = True # Fill domain, default is R if 'domain' not in dct: dct['domain'] = Domain('R') # Check that params is not empty if len(dct['params']) == 0: raise Exception('"params" is empty for operator "{}"'. \ format(name)) # Fill full_name, default is same as name if 'full_name' not in dct: dct['full_name'] = name # Fill desc, default is a basic sentence using full_name if 'desc' not in dct: arg = 'arguments' if len(dct['params']) > 2 else 'argument' if dct['params'][0] == '_': dct['desc'] = \ '{} the {}. Defined over {}.'. \ format(dct['full_name'].capitalize(), arg, dct['domain']) else: dct['desc'] = \ 'Returns the {} of the {}. Defined over {}.'.\ format(dct['full_name'], arg, dct['domain']) # Fill src, default is operator is in header not in source if not member_is_defined('src'): dct['src'] = False # Fill load_store, default is operator is not for loading/storing if 'load_store' not in dct: dct['load_store'] = False # Fill has_scalar_impl, default is based on several properties if 'has_scalar_impl' not in dct: if DocShuffle in dct['categories'] or \ DocMisc in dct['categories'] or \ 'vx2' in dct['params'] or \ 'vx3' in dct['params'] or \ 'vx4' in dct['params'] or \ dct['output_to'] in [common.OUTPUT_TO_UP_TYPES, common.OUTPUT_TO_DOWN_TYPES] or \ dct['load_store'] or get_member_value('src'): dct['has_scalar_impl'] = False else: dct['has_scalar_impl'] = True ret = type.__new__(cls, name, bases, dct) operators[dct['name']] = ret() return ret
def __new__(cls, name, bases, dct): # We don't care about the parent class if name == 'Operator' or name == 'SrcOperator': return type.__new__(cls, name, bases, dct) # Mandatory members mm = ['categories', 'signature'] for m in mm: if m not in dct: raise Exception('Mandatory member "{}" not given in "{}"'. \ format(m, name)) # Check that all items in categories exists for c in dct['categories']: if type(c) == str: raise Exception( \ 'Category "{}" must not be a string for operator "{}"'. \ format(c, name)) if not hasattr(c, 'name'): raise Exception( \ 'Category "{}" does not exist for operator "{}"'. \ format(c.__class__.__name__, name)) if c.name not in categories: raise Exception( \ 'Category "{}" does not exist for operator "{}"'. \ format(c.__class__.__name__, name)) # Some defaults, that are fixed by the implementation (dct['name'], dct['params']) = common.parse_signature(dct['signature']) if 'output_to' in dct: if dct['output_to'] == common.OUTPUT_TO_SAME_TYPE: dct['closed'] = True else: dct['closed'] = False else: dct['closed'] = True dct['output_to'] = common.OUTPUT_TO_SAME_TYPE # If the operator takes as inputs vectors and returns a scalar, then # by default we cannot autogenerate the C++ advanced API because we # cannot guess how to combine pieces of a unrolled pack if 'autogen_cxx_adv' not in dct: if dct['params'][0] in ['p', 's']: dct['autogen_cxx_adv'] = False else: dct['autogen_cxx_adv'] = True # Fill domain, default is R if 'domain' not in dct: dct['domain'] = Domain('R') # Check that params is not empty if len(dct['params']) == 0: raise Exception('"params" is empty for operator "{}"'. \ format(name)) # Fill full_name, default is same as name if 'full_name' not in dct: dct['full_name'] = name # Fill desc, default is a basic sentence using full_name if 'desc' not in dct: arg = 'arguments' if len(dct['params']) > 2 else 'argument' if dct['params'][0] == '_': dct['desc'] = \ '{} the {}. Defined over {}.'. \ format(dct['full_name'].capitalize(), arg, dct['domain']) else: dct['desc'] = \ 'Returns the {} of the {}. Defined over {}.'.\ format(dct['full_name'], arg, dct['domain']) ret = type.__new__(cls, name, bases, dct) operators[dct['name']] = ret() return ret