-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[FFI] Construct NDArray.strides by default #18272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| */ | ||
| inline Shape InferStrideFromShape(Shape shape) { | ||
| size_t ndim = shape.size(); | ||
| Array<int64_t> strides(ndim, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not use array, instead, use https://github.com/apache/tvm/blob/main/ffi/include/tvm/ffi/container/shape.h#L71
details::MakeEmptyShape, then fill in the strides.
do something like
int64_t stride = 1;
for () {
assign
}
We can also move this function to shape.h details::
| explicit NDArrayObjFromDLPack(TDLPackManagedTensor* tensor) : tensor_(tensor) { | ||
| *static_cast<DLTensor*>(this) = tensor_->dl_tensor; | ||
| // set strides to nullptr if the tensor is contiguous. | ||
| if (IsContiguous(tensor->dl_tensor)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also need to check tensor->dl_tensor->strides == nullptr and act accordingly if needed
| * \return The check result. | ||
| */ | ||
| inline bool IsContiguous(const DLTensor& arr) { | ||
| if (arr.strides == nullptr) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep this for now as this function is defined per DLTensor
| return p; | ||
| } | ||
|
|
||
| TVM_FFI_INLINE ObjectPtr<ShapeObj> InferStrideFromShape(int64_t ndim, int64_t* shape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: MakeStridesFromShape
This PR updates NDArray.strides to construct strides by default
This PR updates NDArray.strides to construct strides by default
This PR updates NDArray.strides to construct strides by default
This PR updates the NDArray construction that the strides will be constructed by default.