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

Method set_items

python/dgl/utils/internal.py:232–255  ·  view source on GitHub ↗

Set values at given positions of an Index. Set is not done in place, instead, a new Index object will be returned. Parameters ---------- index: utils.Index Positions to set values value: int or utils.Index Values to set. If value is an

(self, index, value)

Source from the content-addressed store, hash-verified

230 )
231
232 def set_items(self, index, value):
233 """Set values at given positions of an Index. Set is not done in place,
234 instead, a new Index object will be returned.
235
236 Parameters
237 ----------
238 index: utils.Index
239 Positions to set values
240 value: int or utils.Index
241 Values to set. If value is an integer, then all positions are set
242 to the same value
243
244 Returns
245 -------
246 utils.Index
247 The new values.
248 """
249 tensor = self.tousertensor()
250 index = index.tousertensor()
251 if isinstance(value, int):
252 value = F.full_1d(len(index), value, dtype=F.int64, ctx=F.cpu())
253 else:
254 value = value.tousertensor()
255 return Index(F.scatter_row(tensor, index, value), self.dtype)
256
257 def append_zeros(self, num):
258 """Append zeros to an Index

Callers

nothing calls this directly

Calls 3

tousertensorMethod · 0.95
IndexClass · 0.85
cpuMethod · 0.45

Tested by

no test coverage detected