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

Method tousertensor

python/dgl/utils/internal.py:127–145  ·  view source on GitHub ↗

Convert to user tensor (defined in `backend`).

(self, ctx=None)

Source from the content-addressed store, hash-verified

125 return self._pydata
126
127 def tousertensor(self, ctx=None):
128 """Convert to user tensor (defined in `backend`)."""
129 if ctx is None:
130 ctx = F.cpu()
131 if len(self._user_tensor_data) == 0:
132 if self._dgl_tensor_data is not None:
133 # zero copy from dgl tensor
134 dlpack = self._dgl_tensor_data.to_dlpack()
135 self._user_tensor_data[F.cpu()] = F.zerocopy_from_dlpack(dlpack)
136 else:
137 # zero copy from numpy array
138 self._user_tensor_data[F.cpu()] = F.zerocopy_from_numpy(
139 self.tonumpy()
140 )
141 if ctx not in self._user_tensor_data:
142 # copy from cpu to another device
143 data = next(iter(self._user_tensor_data.values()))
144 self._user_tensor_data[ctx] = F.copy_to(data, ctx)
145 return self._user_tensor_data[ctx]
146
147 def todgltensor(self):
148 """Convert to dgl.NDArray."""

Callers 15

tonumpyMethod · 0.95
todgltensorMethod · 0.95
__getstate__Method · 0.95
get_itemsMethod · 0.95
set_itemsMethod · 0.95
append_zerosMethod · 0.95
nonzeroMethod · 0.95
has_nonzeroMethod · 0.95
adjacency_matrixMethod · 0.80
incidence_matrixMethod · 0.80
reorder_nodesFunction · 0.80

Calls 5

tonumpyMethod · 0.95
to_dlpackMethod · 0.80
cpuMethod · 0.45
valuesMethod · 0.45
copy_toMethod · 0.45

Tested by 3

test_pickling_indexFunction · 0.64