本文整理汇总了Python中tensorflow.contrib.py2tf.pyct.anno.setanno函数的典型用法代码示例。如果您正苦于以下问题:Python setanno函数的具体用法?Python setanno怎么用?Python setanno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setanno函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: visit_Call
def visit_Call(self, node):
# If the function is wrapped by one of the marker decorators,
# consider it graph ready.
if anno.hasanno(node.func, 'live_val'):
target_entity = anno.getanno(node.func, 'live_val')
if target_entity in self.nocompile_decorators:
if len(node.args) < 1:
raise ValueError(
'Found call to decorator function "%s", but it had no arguments. '
'A decorator needs at least an argument.')
anno.setanno(node.args[0], 'graph_ready', True)
self.generic_visit(node)
if anno.hasanno(node.func, 'live_val'):
target_entity = anno.getanno(node.func, 'live_val')
if anno.hasanno(node.func, 'fqn'):
target_fqn = anno.getanno(node.func, 'fqn')
if self._function_is_compilable(target_entity):
node = self._rename_compilable_function(node)
elif target_fqn in KNOWN_NUMPY_FUNCTIONS:
# TODO(mdan): Should we replace these with equivalent TF ops instead?
node = self._wrap_to_py_func_single_return(node, target_fqn)
else:
raise NotImplementedError(
'py_func with return values (unknown function)')
else:
if self.context.recursive:
node = self._insert_dynamic_conversion(node)
else:
# Unresolved functions are allowed in non-recursive mode.
pass
return node
开发者ID:houhaichao830,项目名称:tensorflow,代码行数:32,代码来源:call_trees.py
示例2: visit_Call
def visit_Call(self, node):
# If the function is wrapped by one of the marker decorators,
# consider it graph ready.
if anno.hasanno(node.func, 'live_val'):
target_entity = anno.getanno(node.func, 'live_val')
if target_entity in self.nocompile_decorators:
if len(node.args) < 1:
raise ValueError(
'Found call to decorator function "%s", but it had no arguments. '
'A decorator needs at least an argument.')
anno.setanno(node.args[0], 'graph_ready', True)
self.generic_visit(node)
if anno.hasanno(node.func, 'live_val'):
target_entity = anno.getanno(node.func, 'live_val')
if self._function_is_compilable(target_entity):
node = self._rename_compilable_function(node)
else:
raise NotImplementedError('py_func with return values')
else:
if self.context.recursive:
raise NotImplementedError('Could not resolve target function.')
else:
# TODO(mdan): Double check. Is this reachable code?
pass
return node
开发者ID:dananjayamahesh,项目名称:tensorflow,代码行数:26,代码来源:call_trees.py
示例3: visit_Name
def visit_Name(self, node):
self.generic_visit(node)
if isinstance(node.ctx, gast.Load):
assert anno.hasanno(node, 'is_local'), node
symbol_is_local = anno.getanno(node, 'is_local')
assert anno.hasanno(node, 'is_modified_since_entry'), node
symbol_is_modified = anno.getanno(node, 'is_modified_since_entry')
assert anno.hasanno(node, 'is_param'), node
symbol_is_param = anno.getanno(node, 'is_param')
if not symbol_is_local and not symbol_is_param:
if node.id in self.literals:
anno.setanno(node, 'live_val', self.literals[node.id])
# TODO(mdan): Could live values have FQNs? i.e. 'a'.join()
elif node.id in self.context.namespace:
obj = self.context.namespace[node.id]
anno.setanno(node, 'live_val', obj)
anno.setanno(node, 'fqn', (obj.__name__,))
else:
raise ValueError('Could not resolve symbol "%s".' % node.id)
else:
pass
# TODO(mdan): Attempt to trace its value through the local chain.
# TODO(mdan): Use type annotations as fallback.
if not symbol_is_modified:
if node.id in self.context.arg_values:
obj = self.context.arg_values[node.id]
anno.setanno(node, 'live_val', obj)
anno.setanno(node, 'fqn', (obj.__class__.__name__,))
return node
开发者ID:ClowJ,项目名称:tensorflow,代码行数:31,代码来源:live_values.py
示例4: visit_Name
def visit_Name(self, node):
self.generic_visit(node)
if isinstance(node.ctx, gast.Load):
assert anno.hasanno(node, NodeAnno.IS_LOCAL), node
symbol_is_local = anno.getanno(node, NodeAnno.IS_LOCAL)
assert anno.hasanno(node, NodeAnno.IS_MODIFIED_SINCE_ENTRY), node
symbol_is_modified = anno.getanno(node, NodeAnno.IS_MODIFIED_SINCE_ENTRY)
assert anno.hasanno(node, NodeAnno.IS_PARAM), node
symbol_is_param = anno.getanno(node, NodeAnno.IS_PARAM)
if not symbol_is_local and not symbol_is_param:
if node.id in self.literals:
anno.setanno(node, 'live_val', self.literals[node.id])
# TODO(mdan): Could live values have FQNs? i.e. 'a'.join()
elif node.id in self.context.namespace:
obj = self.context.namespace[node.id]
anno.setanno(node, 'live_val', obj)
anno.setanno(node, 'fqn', (obj.__name__,))
else:
pass
# TODO(mdan): Should we raise an error here?
# Can encounter this when:
# * a symbol truly lacks reference
# * a symbol is new, like the new name of a function we just renamed.
else:
pass
# TODO(mdan): Attempt to trace its value through the local chain.
# TODO(mdan): Use type annotations as fallback.
if not symbol_is_modified:
if node.id in self.context.arg_values:
obj = self.context.arg_values[node.id]
anno.setanno(node, 'live_val', obj)
anno.setanno(node, 'fqn', (obj.__class__.__name__,))
return node
开发者ID:DILASSS,项目名称:tensorflow,代码行数:35,代码来源:live_values.py
示例5: visit_Call
def visit_Call(self, node):
if anno.hasanno(node.func, 'live_val'):
# Symbols targeted by the "set_type" marker function are assigned the data
# type that it specified.
if (anno.getanno(node.func, 'live_val') is
self.context.type_annotation_func):
# Expecting the actual type to be the second argument.
if len(node.args) != 2:
raise ValueError('"%s" must have exactly two parameters'
% self.context.type_annotation_func)
if not anno.hasanno(node.args[0], anno.Basic.QN):
raise ValueError('the first argument of "%s" must by a symbol'
% self.context.type_annotation_func)
if not anno.hasanno(node.args[1], 'live_val'):
raise ValueError(
'the second argument of "%s" must be statically resolvable' %
self.context.type_annotation_func)
target_symbol = anno.getanno(node.args[0], anno.Basic.QN)
element_type = anno.getanno(node.args[1], 'live_val')
# Find the definition of this symbol and annotate it with the given
# data type. That in turn will cause future uses of the symbol
# to receive the same type annotation.
definition = self.scope.getval(target_symbol)
anno.setanno(node, 'element_type', element_type)
anno.setanno(definition, 'element_type', element_type)
# TODO(mdan): Should we update references between definition and here?
return self.generic_visit(node)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:27,代码来源:type_info.py
示例6: visit_Call
def visit_Call(self, node):
target = node.func
if not anno.hasanno(target, 'live_val'):
if not isinstance(target, gast.Attribute):
# Suspecting this pattern would reach here:
# foo = bar
# foo()
raise ValueError('Dont know how to handle dynamic functions.')
if not isinstance(target.value, gast.Name):
# Possible example of this kind:
# foo = module.Foo()
# foo.bar.baz()
# TODO(mdan): This should be doable by using the FQN.
raise ValueError('Dont know how to handle object properties yet.')
# In the example below, object_source is 'tr.train.Optimizer()':
# opt = tf.train.Optimizer()
# opt.foo()
if self.scope.hasval(target.value.id):
object_source = self.scope.getval(target.value.id)
if not anno.hasanno(object_source, 'type'):
raise ValueError('Could not determine type of "%s". Is it dynamic?' %
(target.value.id))
anno.setanno(target, 'type', anno.getanno(object_source, 'type'))
anno.setanno(target, 'type_fqn', anno.getanno(object_source,
'type_fqn'))
else:
# TODO(mdan): Figure out what could the user do to get past this.
raise ValueError('No info on "%s". Is it dynamically built?' %
(target.value.id))
self.generic_visit(node)
return node
开发者ID:craffel,项目名称:tensorflow,代码行数:31,代码来源:type_info.py
示例7: _wrap_to_py_func_no_return
def _wrap_to_py_func_no_return(self, node):
args_scope = anno.getanno(node, 'args_scope')
# TODO(mdan): Properly handle varargs, kwargs, etc.
args = tuple(gast.Name(n, gast.Load(), None) for n in args_scope.used)
# pylint:disable=undefined-variable,unused-argument,function-redefined
def template(call, wrapper, args):
def wrapper(args):
call(args)
return 1
tf.py_func(wrapper, [args], [tf.int64])
# pylint:enable=undefined-variable,unused-argument,function-redefined
wrapper_name = self.namer.compiled_function_name(node.func.id)
wrapper_def, call_expr = templates.replace(
template,
call=node.func,
wrapper=gast.Name(wrapper_name, gast.Load(), None),
args=args)
anno.setanno(call_expr.value, 'args_scope', args_scope)
anno.setanno(wrapper_def, 'skip_processing', True)
return (wrapper_def, call_expr)
开发者ID:andrewharp,项目名称:tensorflow,代码行数:27,代码来源:call_trees.py
示例8: visit_Call
def visit_Call(self, node):
# If the function is wrapped by one of the marker decorators,
# consider it graph ready.
if anno.hasanno(node.func, 'live_val'):
target_obj = anno.getanno(node.func, 'live_val')
if target_obj in self.nocompile_decorators:
if len(node.args) < 1:
raise ValueError(
'Found call to decorator function "%s", but it had no arguments. '
'A decorator needs at least an argument.')
anno.setanno(node.args[0], 'graph_ready', True)
self.generic_visit(node)
if anno.hasanno(node.func, 'live_val'):
target_obj = anno.getanno(node.func, 'live_val')
if self._function_is_compilable(target_obj):
node = self._rename_compilable_function(node)
else:
raise NotImplementedError('py_func with return values')
elif anno.hasanno(node.func, 'type_fqn'):
node = self._rename_member_function_of_known_type(node)
else:
raise NotImplementedError(
'Member function call (of unknown type): %s.' % node.func.id)
return node
开发者ID:craffel,项目名称:tensorflow,代码行数:25,代码来源:call_trees.py
示例9: _wrap_to_py_func_no_return
def _wrap_to_py_func_no_return(self, node):
func_qn = anno.getanno(node.func, anno.Basic.QN)
args_scope = anno.getanno(node, NodeAnno.ARGS_SCOPE)
wrapper_name = self.context.namer.new_symbol(func_qn.ssf(),
args_scope.referenced)
wrapper_args = []
for arg in node.args:
if anno.hasanno(arg, anno.Basic.QN):
arg_qn = anno.getanno(arg, anno.Basic.QN)
else:
arg_qn = qual_names.QN('arg')
wrapper_args.append(
self.context.namer.new_symbol(arg_qn.ssf(), args_scope.referenced))
# TODO(mdan): Properly handle varargs, kwargs, etc.
# TODO(mdan): This is best handled as a dynamic dispatch.
# That way we can separate tensors from non-tensor args.
template = """
def wrapper(wrapper_args):
call(wrapper_args)
return 1
tf.py_func(wrapper, original_args, [tf.int64])
"""
wrapper_def, call_expr = templates.replace(
template,
call=node.func,
wrapper=wrapper_name,
original_args=gast.List(elts=node.args, ctx=None),
wrapper_args=wrapper_args)
anno.setanno(wrapper_def, anno.Basic.SKIP_PROCESSING, True)
return (wrapper_def, call_expr)
开发者ID:japrogramer,项目名称:tensorflow,代码行数:31,代码来源:call_trees.py
示例10: visit_With
def visit_With(self, node):
current_scope = self.scope
with_scope = Scope(current_scope, isolated=False)
self.scope = with_scope
self.generic_visit(node)
anno.setanno(node, NodeAnno.BODY_SCOPE, with_scope)
self.scope = current_scope
return node
开发者ID:DILASSS,项目名称:tensorflow,代码行数:8,代码来源:activity.py
示例11: _as_function
def _as_function(self, func_name, args):
template = """
func_name(args)
"""
replacement = templates.replace_as_expression(
template, func_name=parser.parse_expression(func_name), args=args)
anno.setanno(replacement, SAFE_BOOLEAN_OPERAND, True)
return replacement
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:logical_expressions.py
示例12: _inline_tf_op
def _inline_tf_op(self, op_name, args):
template = """
tf.op_name(args)
"""
replacement = templates.replace(template, op_name=op_name, args=args)
# It's a body with a single expression, we want its value.
n = replacement[0].value
anno.setanno(n, SAFE_BOOLEAN_OPERAND, True)
return n
开发者ID:DILASSS,项目名称:tensorflow,代码行数:9,代码来源:logical_expressions.py
示例13: _process_block_node
def _process_block_node(self, node, block, scope_name):
current_scope = self.scope
block_scope = Scope(current_scope, isolated=False)
self.scope = block_scope
for n in block:
self.visit(n)
anno.setanno(node, '%s_scope' % scope_name, block_scope)
self.scope = current_scope
return node
开发者ID:andrewharp,项目名称:tensorflow,代码行数:9,代码来源:access.py
示例14: visit_Print
def visit_Print(self, node):
current_scope = self.scope
args_scope = Scope(current_scope)
self.scope = args_scope
for n in node.values:
self.visit(n)
anno.setanno(node, 'args_scope', args_scope)
self.scope = current_scope
return node
开发者ID:andrewharp,项目名称:tensorflow,代码行数:9,代码来源:access.py
示例15: test_basic
def test_basic(self):
node = ast.Name()
self.assertFalse(anno.hasanno(node, 'foo'))
with self.assertRaises(AttributeError):
anno.getanno(node, 'foo')
anno.setanno(node, 'foo', 3)
self.assertTrue(anno.hasanno(node, 'foo'))
self.assertEqual(3, anno.getanno(node, 'foo'))
开发者ID:ClowJ,项目名称:tensorflow,代码行数:10,代码来源:anno_test.py
示例16: _process_function_arg
def _process_function_arg(self, arg_name):
str_name = str(arg_name)
if self.function_level == 1 and str_name in self.context.arg_types:
# Forge a node to hold the type information, so that method calls on
# it can resolve the type.
type_holder = arg_name.ast()
type_string, type_obj = self.context.arg_types[str_name]
anno.setanno(type_holder, 'type', type_obj)
anno.setanno(type_holder, 'type_fqn', tuple(type_string.split('.')))
self.scope.setval(arg_name, type_holder)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:10,代码来源:type_info.py
示例17: test_copyanno
def test_copyanno(self):
node_1 = ast.Name()
anno.setanno(node_1, 'foo', 3)
node_2 = ast.Name()
anno.copyanno(node_1, node_2, 'foo')
anno.copyanno(node_1, node_2, 'bar')
self.assertTrue(anno.hasanno(node_2, 'foo'))
self.assertFalse(anno.hasanno(node_2, 'bar'))
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:10,代码来源:anno_test.py
示例18: visit_FunctionDef
def visit_FunctionDef(self, node):
if self.scope:
qn = QN(node.name)
self.scope.mark_write(qn)
current_scope = self.scope
fndef_scope = Scope(current_scope, isolated=True)
self.scope = fndef_scope
self.generic_visit(node)
anno.setanno(node, NodeAnno.BODY_SCOPE, fndef_scope)
self.scope = current_scope
return node
开发者ID:DILASSS,项目名称:tensorflow,代码行数:11,代码来源:activity.py
示例19: visit_Call
def visit_Call(self, node):
current_scope = self.scope
args_scope = Scope(current_scope)
self.scope = args_scope
for n in node.args:
self.visit(n)
# TODO(mdan): Account starargs, kwargs
for n in node.keywords:
self.visit(n)
anno.setanno(node, 'args_scope', args_scope)
self.scope = current_scope
self.visit(node.func)
return node
开发者ID:andrewharp,项目名称:tensorflow,代码行数:13,代码来源:access.py
示例20: visit_Call
def visit_Call(self, node):
current_scope = self.scope
args_scope = Scope(current_scope, isolated=False)
self.scope = args_scope
for n in node.args:
self.visit(n)
# TODO(mdan): Account starargs, kwargs
for n in node.keywords:
self.visit(n)
anno.setanno(node, NodeAnno.ARGS_SCOPE, args_scope)
self.scope = current_scope
self.visit(node.func)
return node
开发者ID:DILASSS,项目名称:tensorflow,代码行数:13,代码来源:activity.py
注:本文中的tensorflow.contrib.py2tf.pyct.anno.setanno函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论