MCPcopy
hub / github.com/dmlc/dgl / get_items

Method get_items

python/dgl/utils/internal.py:189–230  ·  view source on GitHub ↗

Return values at given positions of an Index Parameters ---------- index: utils.Index Returns ------- utils.Index The values at the given position.

(self, index)

Source from the content-addressed store, hash-verified

187 self._initialize_data(state)
188
189 def get_items(self, index):
190 """Return values at given positions of an Index
191
192 Parameters
193 ----------
194 index: utils.Index
195
196 Returns
197 -------
198 utils.Index
199 The values at the given position.
200 """
201 if self._slice_data is not None and self._slice_data.start == 0:
202 # short-cut for identical mapping
203 # NOTE: we don't check for out-of-bound error
204 return index
205 elif index._slice_data is None:
206 # the provided index is not a slice
207 tensor = self.tousertensor()
208 index = index.tousertensor()
209 # TODO(Allen): Change F.gather_row to dgl operation
210 return Index(F.gather_row(tensor, index), self.dtype)
211 elif self._slice_data is None:
212 # the current index is not a slice but the provided is a slice
213 tensor = self.tousertensor()
214 index = index._slice_data
215 # TODO(Allen): Change F.narrow_row to dgl operation
216 return Index(
217 F.astype(
218 F.narrow_row(tensor, index.start, index.stop),
219 F.data_type_dict[self.dtype],
220 ),
221 self.dtype,
222 )
223 else:
224 # both self and index wrap a slice object, then return another
225 # Index wrapping a slice
226 start = self._slice_data.start
227 index = index._slice_data
228 return Index(
229 slice(start + index.start, start + index.stop), self.dtype
230 )
231
232 def set_items(self, index, value):
233 """Set values at given positions of an Index. Set is not done in place,

Callers

nothing calls this directly

Calls 3

tousertensorMethod · 0.95
IndexClass · 0.85
astypeMethod · 0.45

Tested by

no test coverage detected