def make_stateless(self, declaration):
declaration['name'] = 'THPTensor_stateless_({})'.format(declaration['name'])
new_options = []
for option in declaration['options']:
option['cname'] = 'THTensor_({})'.format(option['cname'])
allocated = []
for i, arg in enumerate(option['arguments']):
if 'allocate' in arg and arg['allocate']:
arg['ignore_check'] = True
allocated.append(i)
if arg['name'] == 'self':
arg['name'] = 'source'
for permutation in product((True, False), repeat=len(allocated)):
option_copy = deepcopy(option)
for i, bit in zip(allocated, permutation):
arg = option_copy['arguments'][i]
# By default everything is allocated, so we don't have to do anything
if not bit:
del arg['allocate']
del arg['ignore_check']
new_options.append(option_copy)
declaration['options'] = self.filter_unique_options(declaration['options'] + new_options)
return declaration
评论列表
文章目录