當前位置: 首頁>>代碼示例>>Python>>正文


Python containers.RepeatedScalarFieldContainer方法代碼示例

本文整理匯總了Python中google.protobuf.internal.containers.RepeatedScalarFieldContainer方法的典型用法代碼示例。如果您正苦於以下問題:Python containers.RepeatedScalarFieldContainer方法的具體用法?Python containers.RepeatedScalarFieldContainer怎麽用?Python containers.RepeatedScalarFieldContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.protobuf.internal.containers的用法示例。


在下文中一共展示了containers.RepeatedScalarFieldContainer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def set(prop, val):
    if val is None:
        return
    if type(prop) is RepeatedScalarFieldContainer:
        if type(val) is list:
            for i in val:
                prop.append(i)
        else:
            prop.append(val)
    elif type(prop) is RepeatedCompositeFieldContainer:
        x = prop.add()
        # x.phase= val
        x = val
    else:
        prop = val
    return prop  # use for immutable fields 
開發者ID:marakeby,項目名稱:udl,代碼行數:18,代碼來源:layer.py

示例2: create_clusters_meta

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def create_clusters_meta(cluster_ids: RepeatedScalarFieldContainer) -> Tuple[List[Cluster], Dict[str, int]]:
        try:
            unannotated_ids = set((int(c) for c in cluster_ids))
            clusters_list = [str(c) for c in sorted(unannotated_ids)]
            annotated = False
        except ValueError:
            clusters_list = sorted(set((c for c in cluster_ids)))
            annotated = True

        clusters: List[Cluster] = []
        cluster_mapping = {}
        for cluster_id, cluster_name in enumerate(clusters_list):
            clusters.append(
                {"id": cluster_id, "description": cluster_name if annotated else f"Unannotated Cluster {cluster_name}"}
            )
            cluster_mapping[str(cluster_name)] = cluster_id

        return clusters, cluster_mapping 
開發者ID:aertslab,項目名稱:SCope,代碼行數:20,代碼來源:loom.py

示例3: parse_kernel

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def parse_kernel(lparam):
        # pasre the kernel size from the caffe config parameters
        # easiest to do this case by case to cover the different caffe protobuf defs
        key = 'kernel_size'
        if hasattr(lparam, key):
            ks = getattr(lparam, key)
            if type(ks) is int and ks > 0:
                return [ks]*2
            
            if type(ks) is list or type(ks) is RepeatedScalarFieldContainer:
                ks = list(ks)
                if len(ks) > 3:
                    raise NotImplementedError()
                if len(ks) > 0 and all([x > 0 for x in ks]):
                    return [ks[0], ks[-1]]
                # ks is [] or has an element that is <= 0

        # try to parse from kernel_h and _w
        key = 'kernel'
        if not (hasattr(lparam, key+'_h') and hasattr(lparam, key+'_w')):
            raise ValueError('Can not parse kernel size')

        k_h = getattr(lparam, key+'_h')
        k_w = getattr(lparam, key+'_w')
        if k_h == 0 and k_w == 0:
            import ipdb; ipdb.set_trace()
            raise ValueError('Can not parse kernel size')
        return [k_h, k_w] 
開發者ID:NervanaSystems,項目名稱:caffe2neon,代碼行數:30,代碼來源:decaffeinate.py

示例4: generate_solver_proto

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def generate_solver_proto(**kwargs):
    sp = caffe_pb2.SolverParameter()
    for k,v in kwargs.iteritems():
        if not hasattr(sp, k):
            raise ValueError('The argument \'%s\' is not part of the Caffe solver parameters!')
        elif v is not None:
            elem = getattr(sp, k)
            if type(elem) == RepeatedScalarFieldContainer:
                elem.append(v)
            elif k == 'solver_mode':
                setattr(sp, k, sp.SolverMode.DESCRIPTOR.values_by_name[v].number)
            else:
                setattr(sp, k, v)
    return sp 
開發者ID:ssudholt,項目名稱:phocnet,代碼行數:16,代碼來源:solver_proto_generator.py

示例5: _assign_to_field

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def _assign_to_field(obj, name, val):
    'Helper to assign an arbitrary value to a protobuf field'
    target = getattr(obj, name)

    if isinstance(target, containers.RepeatedScalarFieldContainer):
        target.append(val)
    elif isinstance(target, containers.RepeatedCompositeFieldContainer):
        target = target.add()
        target.CopyFrom(val)
    elif isinstance(target, (int, float, bool, str, bytes)):
        setattr(obj, name, val)
    elif isinstance(target, message.Message):
        target.CopyFrom(val)
    else:
        raise RuntimeError("Unsupported type: {}".format(type(target))) 
開發者ID:trailofbits,項目名稱:protofuzz,代碼行數:17,代碼來源:protofuzz.py

示例6: parse_pad

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def parse_pad(lparam):
        # pasre the padding size from the caffe config parameters
        # easiest to do this case by case to cover the different caffe protobuf defs
        key = 'pad'
        if hasattr(lparam, key):
            ps = getattr(lparam, key)
            if type(ps) is int:
                return [ps]*2
            
            if type(ps) is list or type(ps) is RepeatedScalarFieldContainer:
                ps = list(ps)
                if len(ps) > 3:
                    raise NotImplementedError()
                if len(ps) > 0:
                    return [ps[0], ps[-1]]

        # default to [0, 0]
        ps = [0, 0]

        try:
            k_h = getattr(lparam, key+'_h')
            ps[0] = k_h
            k_w = getattr(lparam, key+'_w')
            ps[1] = k_w
        except:
            pass
        return ps 
開發者ID:NervanaSystems,項目名稱:caffe2neon,代碼行數:29,代碼來源:decaffeinate.py

示例7: parse_stride

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def parse_stride(lparam):
        # pasre the strides from the caffe config parameters
        # easiest to do this case by case to cover the different caffe protobuf defs
        key = 'stride'
        if hasattr(lparam, key):
            ss = getattr(lparam, key)
            if type(ss) is int:
                return [ss]*2
            
            if type(ss) is list or type(ss) is RepeatedScalarFieldContainer:
                ss = list(ss)
                if len(ss) > 3:
                    raise NotImplementedError()
                if len(ss) > 0 and all([x > 0 for x in ss]):
                    return [ss[0], ss[-1]]

        # default to [1, 1]
        ss = [1, 1]

        try:
            k_h = getattr(lparam, key+'_h')
            if k_h > 0:
                ss[0] = k_h
            k_w = getattr(lparam, key+'_w')
            if k_w > 0:
                ss[1] = k_w
        except:
            pass
        return ss 
開發者ID:NervanaSystems,項目名稱:caffe2neon,代碼行數:31,代碼來源:decaffeinate.py

示例8: _DefaultValueConstructorForField

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def _DefaultValueConstructorForField(field):
  """Returns a function which returns a default value for a field.

  Args:
    field: FieldDescriptor object for this field.

  The returned function has one argument:
    message: Message instance containing this field, or a weakref proxy
      of same.

  That function in turn returns a default value for this field.  The default
    value may refer back to |message| via a weak reference.
  """

  if _IsMapField(field):
    return _GetInitializeDefaultForMap(field)

  if field.label == _FieldDescriptor.LABEL_REPEATED:
    if field.has_default_value and field.default_value != []:
      raise ValueError('Repeated field default value not empty list: %s' % (
          field.default_value))
    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
      # We can't look at _concrete_class yet since it might not have
      # been set.  (Depends on order in which we initialize the classes).
      message_type = field.message_type
      def MakeRepeatedMessageDefault(message):
        return containers.RepeatedCompositeFieldContainer(
            message._listener_for_children, field.message_type)
      return MakeRepeatedMessageDefault
    else:
      type_checker = type_checkers.GetTypeChecker(field)
      def MakeRepeatedScalarDefault(message):
        return containers.RepeatedScalarFieldContainer(
            message._listener_for_children, type_checker)
      return MakeRepeatedScalarDefault

  if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
    # _concrete_class may not yet be initialized.
    message_type = field.message_type
    def MakeSubMessageDefault(message):
      result = message_type._concrete_class()
      result._SetListener(
          _OneofListener(message, field)
          if field.containing_oneof is not None
          else message._listener_for_children)
      return result
    return MakeSubMessageDefault

  def MakeScalarDefault(message):
    # TODO(protobuf-team): This may be broken since there may not be
    # default_value.  Combine with has_default_value somehow.
    return field.default_value
  return MakeScalarDefault 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:55,代碼來源:python_message.py

示例9: _DefaultValueConstructorForField

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def _DefaultValueConstructorForField(field):
  """Returns a function which returns a default value for a field.

  Args:
    field: FieldDescriptor object for this field.

  The returned function has one argument:
    message: Message instance containing this field, or a weakref proxy
      of same.

  That function in turn returns a default value for this field.  The default
    value may refer back to |message| via a weak reference.
  """

  if field.label == _FieldDescriptor.LABEL_REPEATED:
    if field.has_default_value and field.default_value != []:
      raise ValueError('Repeated field default value not empty list: %s' % (
          field.default_value))
    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
      # We can't look at _concrete_class yet since it might not have
      # been set.  (Depends on order in which we initialize the classes).
      message_type = field.message_type
      def MakeRepeatedMessageDefault(message):
        return containers.RepeatedCompositeFieldContainer(
            message._listener_for_children, field.message_type)
      return MakeRepeatedMessageDefault
    else:
      type_checker = type_checkers.GetTypeChecker(field)
      def MakeRepeatedScalarDefault(message):
        return containers.RepeatedScalarFieldContainer(
            message._listener_for_children, type_checker)
      return MakeRepeatedScalarDefault

  if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
    # _concrete_class may not yet be initialized.
    message_type = field.message_type
    def MakeSubMessageDefault(message):
      result = message_type._concrete_class()
      result._SetListener(message._listener_for_children)
      return result
    return MakeSubMessageDefault

  def MakeScalarDefault(message):
    # TODO(protobuf-team): This may be broken since there may not be
    # default_value.  Combine with has_default_value somehow.
    return field.default_value
  return MakeScalarDefault 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:49,代碼來源:python_message.py

示例10: _DefaultValueConstructorForField

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def _DefaultValueConstructorForField(field):
  """Returns a function which returns a default value for a field.

  Args:
    field: FieldDescriptor object for this field.

  The returned function has one argument:
    message: Message instance containing this field, or a weakref proxy
      of same.

  That function in turn returns a default value for this field.  The default
    value may refer back to |message| via a weak reference.
  """

  if _IsMapField(field):
    return _GetInitializeDefaultForMap(field)

  if field.label == _FieldDescriptor.LABEL_REPEATED:
    if field.has_default_value and field.default_value != []:
      raise ValueError('Repeated field default value not empty list: %s' % (
          field.default_value))
    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
      # We can't look at _concrete_class yet since it might not have
      # been set.  (Depends on order in which we initialize the classes).
      message_type = field.message_type
      def MakeRepeatedMessageDefault(message):
        return containers.RepeatedCompositeFieldContainer(
            message._listener_for_children, field.message_type)
      return MakeRepeatedMessageDefault
    else:
      type_checker = type_checkers.GetTypeChecker(field)
      def MakeRepeatedScalarDefault(message):
        return containers.RepeatedScalarFieldContainer(
            message._listener_for_children, type_checker)
      return MakeRepeatedScalarDefault

  if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
    # _concrete_class may not yet be initialized.
    message_type = field.message_type
    def MakeSubMessageDefault(message):
      assert getattr(message_type, '_concrete_class', None), (
          'Uninitialized concrete class found for field %r (message type %r)'
          % (field.full_name, message_type.full_name))
      result = message_type._concrete_class()
      result._SetListener(
          _OneofListener(message, field)
          if field.containing_oneof is not None
          else message._listener_for_children)
      return result
    return MakeSubMessageDefault

  def MakeScalarDefault(message):
    # TODO(protobuf-team): This may be broken since there may not be
    # default_value.  Combine with has_default_value somehow.
    return field.default_value
  return MakeScalarDefault 
開發者ID:luci,項目名稱:luci-py,代碼行數:58,代碼來源:python_message.py

示例11: _AddPropertiesForRepeatedField

# 需要導入模塊: from google.protobuf.internal import containers [as 別名]
# 或者: from google.protobuf.internal.containers import RepeatedScalarFieldContainer [as 別名]
def _AddPropertiesForRepeatedField(field, cls):
  """Adds a public property for a "repeated" protocol message field.  Clients
  can use this property to get the value of the field, which will be either a
  RepeatedScalarFieldContainer or RepeatedCompositeFieldContainer (see
  below).

  Note that when clients add values to these containers, we perform
  type-checking in the case of repeated scalar fields, and we also set any
  necessary "has" bits as a side-effect.

  Args:
    field: A FieldDescriptor for this field.
    cls: The class we're constructing.
  """
  proto_field_name = field.name
  property_name = _PropertyName(proto_field_name)

  def getter(self):
    field_value = self._fields.get(field)
    if field_value is None:
      # Construct a new object to represent this field.
      field_value = field._default_constructor(self)

      # Atomically check if another thread has preempted us and, if not, swap
      # in the new object we just created.  If someone has preempted us, we
      # take that object and discard ours.
      # WARNING:  We are relying on setdefault() being atomic.  This is true
      #   in CPython but we haven't investigated others.  This warning appears
      #   in several other locations in this file.
      field_value = self._fields.setdefault(field, field_value)
    return field_value
  getter.__module__ = None
  getter.__doc__ = 'Getter for %s.' % proto_field_name

  # We define a setter just so we can throw an exception with a more
  # helpful error message.
  def setter(self, new_value):
    raise AttributeError('Assignment not allowed to repeated field '
                         '"%s" in protocol message object.' % proto_field_name)

  doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
  setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc)) 
開發者ID:luci,項目名稱:luci-py,代碼行數:44,代碼來源:python_message.py


注:本文中的google.protobuf.internal.containers.RepeatedScalarFieldContainer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。