I am trying to use this function with a std::vector<int>
to return a NDArray with int32 datatype, but get some runtime error:
.../dgl/src/runtime/ndarray.c:35: Check failed: dtype.bits % 8 == 0 (4 vs. 0)
I could see that the error is sourced from DLDataType{kDLInt, sizeof(IdType), 1}
when creating the empty NDArray in CopyVectorToNDArray
. The 2nd field in DLDataType means the number of bits of the datatype and have to be a multiple of 8. By using sizeof
rather than sizeof(...) * 8
it requires IdType
to be 8*N bytes. Int32 isn’t so here’s the error.
Is this a bug or intentional? The specification says “The element type of the vector must be convertible to int64_t”, but I think it’s unnecessary - this function works as long as DType is convertible to Idtype.