Skip to content

Conversation

@cyx-6
Copy link
Contributor

@cyx-6 cyx-6 commented Sep 6, 2025

This PR updates the NDArray construction that the strides will be constructed by default.

*/
inline Shape InferStrideFromShape(Shape shape) {
size_t ndim = shape.size();
Array<int64_t> strides(ndim, 1);
Copy link
Member

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)) {
Copy link
Member

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;
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: MakeStridesFromShape

@tqchen tqchen merged commit 5c1707d into apache:main Sep 6, 2025
13 checks passed
tqchen pushed a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
This PR updates NDArray.strides to construct strides by default
tqchen pushed a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
This PR updates NDArray.strides to construct strides by default
tqchen pushed a commit to tqchen/tvm that referenced this pull request Sep 13, 2025
This PR updates NDArray.strides to construct strides by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants