• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python anno.setanno函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.contrib.autograph.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')
      else:
        target_fqn = None
      if self._function_is_compilable(target_entity):
        node = self._rename_compilable_function(node)
      elif target_fqn and 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, KNOWN_NUMPY_FUNCTIONS[target_fqn].dtype)
      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:syed-ahmed,项目名称:tensorflow,代码行数:35,代码来源:call_trees.py


示例2: _track_symbol

  def _track_symbol(self,
                    node,
                    composite_writes_alter_parent=False,
                    writes_create_symbol=False):
    # A QN may be missing when we have an attribute (or subscript) on a function
    # call. Example: a().b
    if not anno.hasanno(node, anno.Basic.QN):
      return
    qn = anno.getanno(node, anno.Basic.QN)

    if isinstance(node.ctx, gast.Store):
      self.scope.mark_write(qn)
      if qn.is_composite and composite_writes_alter_parent:
        self.scope.mark_write(qn.parent)
      if writes_create_symbol:
        self.scope.mark_creation(qn, writes_create_symbol=True)
      if self._in_aug_assign:
        self.scope.mark_read(qn)
    elif isinstance(node.ctx, gast.Load):
      self.scope.mark_read(qn)
    elif isinstance(node.ctx, gast.Param):
      # Param contexts appear in function defs, so they have the meaning of
      # defining a variable.
      self.scope.mark_write(qn)
      self.scope.mark_param(qn, self.enclosing_entities[-1])
    else:
      raise ValueError('Unknown context %s for node %s.' % (type(node.ctx), qn))

    anno.setanno(node, NodeAnno.IS_LOCAL, self.scope.has(qn))

    if self._in_return_statement:
      self.scope.mark_returned(qn)
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:32,代码来源:activity.py


示例3: visit_Print

 def visit_Print(self, node):
   self._enter_scope(False)
   node.values = self.visit_block(node.values)
   anno.setanno(node, anno.Static.SCOPE, self.scope)
   anno.setanno(node, NodeAnno.ARGS_SCOPE, self.scope)
   self._exit_scope()
   return node
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:7,代码来源:activity.py


示例4: visit_For

  def visit_For(self, node):
    scope = anno.getanno(node, NodeAnno.BODY_SCOPE)
    break_var = self.context.namer.new_symbol('break__', scope.referenced)

    node.target = self.visit(node.target)
    node.iter = self.visit(node.iter)
    node.body, break_used = self._track_body(node.body, break_var)
    # A break in the else clause applies to the containing scope.
    node.orelse = self.visit_block(node.orelse)

    if break_used:
      node.orelse = self._guard_if_present(node.orelse, break_var)
      template = """
        var_name = False
        for_stmt
      """
      # Python's else clause only triggers if the loop exited cleanly (e.g.
      # break did not trigger).
      node = templates.replace(
          template,
          var_name=break_var,
          for_stmt=node)
      extra_test = templates.replace_as_expression(
          'not var_name', var_name=break_var)
      anno.setanno(node[1], 'extra_test', extra_test)

    return node
开发者ID:Jackiefan,项目名称:tensorflow,代码行数:27,代码来源:break_statements.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:bikong2,项目名称:tensorflow,代码行数:27,代码来源:type_info.py


示例6: visit_With

 def visit_With(self, node):
   self.generic_visit(node)
   incoming = anno.getanno(node.body[0], self.in_label)
   for item in node.items:
     incoming |= anno.getanno(item, self.in_label)
   outgoing = anno.getanno(node.body[-1], self.out_label)
   anno.setanno(node, self.in_label, incoming)
   anno.setanno(node, self.out_label, outgoing)
开发者ID:Eagle732,项目名称:tensorflow,代码行数:8,代码来源:cfg.py


示例7: 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:syed-ahmed,项目名称:tensorflow,代码行数:8,代码来源:activity.py


示例8: _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:BhaskarNallani,项目名称:tensorflow,代码行数:8,代码来源:logical_expressions.py


示例9: _aggregate_successors_live_in

 def _aggregate_successors_live_in(self, node):
   successors = self.current_analyzer.graph.stmt_next[node]
   node_live_out = set()
   for s in successors:
     node_live_out.update(self.current_analyzer.in_[s])
   anno.setanno(node, anno.Static.LIVE_VARS_OUT, frozenset(node_live_out))
   node = self.generic_visit(node)
   return node
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:8,代码来源:liveness.py


示例10: 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, NodeAnno.ARGS_SCOPE, args_scope)
   self.scope = current_scope
   return node
开发者ID:syed-ahmed,项目名称:tensorflow,代码行数:9,代码来源:activity.py


示例11: visit_Call

 def visit_Call(self, node):
   self._enter_scope(False)
   node.args = self.visit_block(node.args)
   node.keywords = self.visit_block(node.keywords)
   # TODO(mdan): Account starargs, kwargs
   anno.setanno(node, NodeAnno.ARGS_SCOPE, self.scope)
   self._exit_scope()
   node.func = self.visit(node.func)
   return node
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:9,代码来源:activity.py


示例12: _process_statement_directive

 def _process_statement_directive(self, call_node, directive):
   if self.local_scope_level < 1:
     raise ValueError(
         '"%s" must be used inside a statement' % directive.__name__)
   target = self.get_local(ENCLOSING_LOOP)
   node_anno = anno.getanno(target, converter.AgAnno.DIRECTIVES, {})
   node_anno[directive] = _map_args(call_node, directive)
   anno.setanno(target, converter.AgAnno.DIRECTIVES, node_anno)
   return call_node
开发者ID:ZhangXinNan,项目名称:tensorflow,代码行数:9,代码来源:directives.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, scope_name, block_scope)
   self.scope = current_scope
   return node
开发者ID:syed-ahmed,项目名称:tensorflow,代码行数:9,代码来源:activity.py


示例14: test_rename_symbols_annotations

  def test_rename_symbols_annotations(self):
    node = parser.parse_str('a[i]')
    node = qual_names.resolve(node)
    anno.setanno(node, 'foo', 'bar')
    orig_anno = anno.getanno(node, 'foo')

    node = ast_util.rename_symbols(node,
                                   {qual_names.QN('a'): qual_names.QN('b')})

    self.assertIs(anno.getanno(node, 'foo'), orig_anno)
开发者ID:StephenOman,项目名称:tensorflow,代码行数:10,代码来源:ast_util_test.py


示例15: test_copy

  def test_copy(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:ChristinaEricka,项目名称:tensorflow,代码行数:10,代码来源:anno_test.py


示例16: visit_While

 def visit_While(self, node):
   self._enter_scope(False)
   node.test = self.visit(node.test)
   anno.setanno(node, NodeAnno.COND_SCOPE, self.scope)
   anno.setanno(node.test, anno.Static.SCOPE, self.scope)
   self._exit_scope()
   node = self._process_parallel_blocks(node,
                                        ((node.body, NodeAnno.BODY_SCOPE),
                                         (node.orelse, NodeAnno.ORELSE_SCOPE)))
   return node
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:10,代码来源:activity.py


示例17: _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:bikong2,项目名称:tensorflow,代码行数:10,代码来源:type_info.py


示例18: visit_For

 def visit_For(self, node):
   self.generic_visit(node)
   incoming = set(anno.getanno(node.body[0], self.in_label))
   incoming -= set((anno.getanno(node.target, anno.Basic.QN),))
   outgoing = anno.getanno(node.body[-1], self.out_label)
   if node.orelse:
     orelse_outgoing = anno.getanno(node.orelse[-1], self.out_label)
     outgoing = self.transfer_fn(outgoing, orelse_outgoing)
   anno.setanno(node, self.in_label, frozenset(incoming))
   anno.setanno(node, self.out_label, outgoing)
开发者ID:Eagle732,项目名称:tensorflow,代码行数:10,代码来源:cfg.py


示例19: visit_While

 def visit_While(self, node):
   self.generic_visit(node)
   incoming = anno.getanno(node.body[0], self.in_label)
   incoming |= anno.getanno(node.test, self.in_label)
   outgoing = anno.getanno(node.body[-1], self.out_label)
   if node.orelse:
     orelse_outgoing = anno.getanno(node.orelse[-1], self.out_label)
     outgoing = self.transfer_fn(outgoing, orelse_outgoing)
   anno.setanno(node, self.in_label, incoming)
   anno.setanno(node, self.out_label, outgoing)
开发者ID:Eagle732,项目名称:tensorflow,代码行数:10,代码来源:cfg.py


示例20: visit_For

 def visit_For(self, node):
   self._enter_scope(False)
   node.target = self.visit(node.target)
   node.iter = self.visit(node.iter)
   anno.setanno(node.iter, anno.Static.SCOPE, self.scope)
   self._exit_scope()
   node = self._process_parallel_blocks(node,
                                        ((node.body, NodeAnno.BODY_SCOPE),
                                         (node.orelse, NodeAnno.ORELSE_SCOPE)))
   return node
开发者ID:ChristinaEricka,项目名称:tensorflow,代码行数:10,代码来源:activity.py



注:本文中的tensorflow.contrib.autograph.pyct.anno.setanno函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python parser.parse_entity函数代码示例发布时间:2022-05-27
下一篇:
Python anno.hasanno函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap