Return a DGLArray representation of a numpy array.
(np_data)
| 86 | |
| 87 | |
| 88 | def numpyasarray(np_data): |
| 89 | """Return a DGLArray representation of a numpy array.""" |
| 90 | data = np_data |
| 91 | assert data.flags["C_CONTIGUOUS"] |
| 92 | arr = DGLArray() |
| 93 | shape = c_array(dgl_shape_index_t, data.shape) |
| 94 | arr.data = data.ctypes.data_as(ctypes.c_void_p) |
| 95 | arr.shape = shape |
| 96 | arr.strides = None |
| 97 | arr.dtype = DGLDataType(np.dtype(data.dtype).name) |
| 98 | arr.ndim = data.ndim |
| 99 | # CPU device |
| 100 | arr.ctx = context(1, 0) |
| 101 | return arr, shape |
| 102 | |
| 103 | |
| 104 | def empty(shape, dtype="float32", ctx=context(1, 0)): |
no test coverage detected