MCPcopy Create free account
hub / github.com/pytorch/pytorch / slice

Method slice

caffe2/python/schema.py:152–172  ·  view source on GitHub ↗

Returns a slice representing the range of field ids that belong to this field. This slice can be used to index a list of fields. E.g.: >>> s = Struct( >>> ('a', Scalar()), >>> ('b', Struct( >>> ('b1', Scalar()), >>>

(self)

Source from the content-addressed store, hash-verified

150 self._parent = (parent, relative_id)
151
152 def slice(self):
153 """
154 Returns a slice representing the range of field ids that belong to
155 this field. This slice can be used to index a list of fields.
156
157 E.g.:
158
159 >>> s = Struct(
160 >>> ('a', Scalar()),
161 >>> ('b', Struct(
162 >>> ('b1', Scalar()),
163 >>> ('b2', Scalar()),
164 >>> )),
165 >>> ('c', Scalar()),
166 >>> )
167 >>> field_data = ['da', 'db1', 'db2', 'dc']
168 >>> field_data[s.b.split()]
169 ['db1', 'db2']
170 """
171 base_id = self._child_base_id()
172 return slice(base_id, base_id + len(self.field_names()))
173
174 def _child_base_id(self, child_index=None):
175 """Get the base id of the given child"""

Callers

nothing calls this directly

Calls 3

_child_base_idMethod · 0.95
field_namesMethod · 0.95
sliceFunction · 0.50

Tested by

no test coverage detected