`CopyVectorToNDArray` in src/c_api_common.h

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.

You’re right it’s a bug. Would you like to submit a PR for that?

It seems like a legacy change without changing the documentation

PR created: Fix CopyVectorToNDArray in src/c_api_common.h by hirayaku · Pull Request #3597 · dmlc/dgl · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.