Skip to content

Commit 93c8f2a

Browse files
authored
Enforce strides to be not null when ndim is nonzero (#178)
* Enforce strides to be not null when ndim is nonzero This PR updates the spec to enforce the strides to be not null when the ndim is nonzero. This is going to help consumers to handle cases more uniformly. * Add more comments on the null rationale * Remove mention of framework handling * Update NULL note, bump minor
1 parent 1117366 commit 93c8f2a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

include/dlpack/dlpack.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define DLPACK_MAJOR_VERSION 1
2020

2121
/*! \brief The current minor version of dlpack */
22-
#define DLPACK_MINOR_VERSION 1
22+
#define DLPACK_MINOR_VERSION 2
2323

2424
/*! \brief DLPACK_DLL prefix for windows */
2525
#ifdef _WIN32
@@ -254,11 +254,23 @@ typedef struct {
254254
int32_t ndim;
255255
/*! \brief The data type of the pointer*/
256256
DLDataType dtype;
257-
/*! \brief The shape of the tensor */
257+
/*!
258+
* \brief The shape of the tensor
259+
*
260+
* When ndim == 0, shape can be set to NULL.
261+
*/
258262
int64_t* shape;
259263
/*!
260-
* \brief strides of the tensor (in number of elements, not bytes)
261-
* can be NULL, indicating tensor is compact and row-majored.
264+
* \brief strides of the tensor (in number of elements, not bytes),
265+
* can not be NULL if ndim != 0, must points to
266+
* an array of ndim elements that specifies the strides,
267+
* so consumer can always rely on strides[dim] being valid for 0 <= dim < ndim.
268+
*
269+
* When ndim == 0, strides can be set to NULL.
270+
*
271+
* \note Before DLPack v1.2, strides can be NULL to indicate contiguous data.
272+
* This is not allowed in DLPack v1.2 and later. The rationale
273+
* is to simplify the consumer handling.
262274
*/
263275
int64_t* strides;
264276
/*! \brief The offset in bytes to the beginning pointer to data */

0 commit comments

Comments
 (0)