Skip to content
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

Add Tensor Format option to DLTensor #35

Closed
ryanolson opened this issue Mar 20, 2019 · 2 comments
Closed

Add Tensor Format option to DLTensor #35

ryanolson opened this issue Mar 20, 2019 · 2 comments

Comments

@ryanolson
Copy link

As a follow-on to Issue #34, I propose the addition of describing the tensor format for the underlying data in the DLTensor struct.

This option would consume a single byte with one of two possible values: kDLRowMajor or kDLColumnMajor.

@ryanolson
Copy link
Author

ryanolson commented Mar 25, 2019

Upon further thought, one can simple infer based on the strides if the underlying format is row/column major.

Unfortunately, that leaves some ambiguity in the reading of the definition of strides which is allowed to be NULL.

  /*!
   * \brief strides of the tensor,
   *  can be NULL, indicating tensor is compact.
   */
  int64_t* strides;

https://github.com/dmlc/dlpack/blob/master/include/dlpack/dlpack.h#L140-L144

It is important to be specific about the definition of a NULL value for strides. I don't have a preference here, but we should explicit state that a NULL value indicates a compact row-major (or column-major) tensor.

>>> c = np.empty((2,3,224,224), dtype=np.float32)
>>> c.shape
(2, 3, 224, 224)
>>> c.strides
(602112, 200704, 896, 4)
>>> f = np.empty((2,3,224,224), dtype=np.float32, order='f')
>>> f.shape
(2, 3, 224, 224)
>>> f.strides
(4, 8, 24, 5376)

@tqchen
Copy link
Member

tqchen commented Mar 25, 2019

It is row-major by default, a PR to clarify things is more than welcomed

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

No branches or pull requests

2 participants