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

Method append_zeros

python/dgl/utils/internal.py:257–273  ·  view source on GitHub ↗

Append zeros to an Index Parameters ---------- num: int number of zeros to append

(self, num)

Source from the content-addressed store, hash-verified

255 return Index(F.scatter_row(tensor, index, value), self.dtype)
256
257 def append_zeros(self, num):
258 """Append zeros to an Index
259
260 Parameters
261 ----------
262 num: int
263 number of zeros to append
264 """
265 if num == 0:
266 return self
267 new_items = F.zeros((num,), dtype=F.int64, ctx=F.cpu())
268 if len(self) == 0:
269 return Index(new_items, self.dtype)
270 else:
271 tensor = self.tousertensor()
272 tensor = F.cat((tensor, new_items), dim=0)
273 return Index(tensor, self.dtype)
274
275 def nonzero(self):
276 """Return the nonzero positions"""

Callers

nothing calls this directly

Calls 3

tousertensorMethod · 0.95
IndexClass · 0.85
cpuMethod · 0.45

Tested by

no test coverage detected