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

Method copyfrom

python/dgl/_ffi/ndarray.py:271–316  ·  view source on GitHub ↗

Perform a synchronized copy from the array. Parameters ---------- source_array : array_like The data source we should like to copy from. Returns ------- arr : NDArray Reference to self.

(self, source_array)

Source from the content-addressed store, hash-verified

269 raise TypeError("type %s not supported" % str(type(value)))
270
271 def copyfrom(self, source_array):
272 """Perform a synchronized copy from the array.
273
274 Parameters
275 ----------
276 source_array : array_like
277 The data source we should like to copy from.
278
279 Returns
280 -------
281 arr : NDArray
282 Reference to self.
283 """
284 if isinstance(source_array, NDArrayBase):
285 source_array.copyto(self)
286 return self
287
288 if not isinstance(source_array, np.ndarray):
289 try:
290 source_array = np.asarray(source_array, dtype=self.dtype)
291 except:
292 raise TypeError(
293 "array must be an array_like data,"
294 + "type %s is not supported" % str(type(source_array))
295 )
296 t = DGLDataType(self.dtype)
297 shape, dtype = self.shape, self.dtype
298 if t.lanes > 1:
299 shape = shape + (t.lanes,)
300 t.lanes = 1
301 dtype = str(t)
302
303 if source_array.shape != shape:
304 raise ValueError(
305 "array shape do not match the shape of NDArray {0} vs {1}".format(
306 source_array.shape, shape
307 )
308 )
309 source_array = np.ascontiguousarray(source_array, dtype=dtype)
310 assert source_array.flags["C_CONTIGUOUS"]
311 data = source_array.ctypes.data_as(ctypes.c_void_p)
312 nbytes = ctypes.c_size_t(
313 source_array.size * source_array.dtype.itemsize
314 )
315 check_call(_LIB.DGLArrayCopyFromBytes(self.handle, data, nbytes))
316 return self
317
318 def __repr__(self):
319 res = "dgl.{0}@{1}".format(self.asnumpy().__repr__(), self.context)

Callers 5

__setitem__Method · 0.95
shared_memoryMethod · 0.80
arrayFunction · 0.80
perform_copyFunction · 0.80

Calls 4

DGLDataTypeClass · 0.85
check_callFunction · 0.85
copytoMethod · 0.80
formatMethod · 0.80

Tested by 1

perform_copyFunction · 0.64