tqchen commented on code in PR #167:
URL: https://github.com/apache/tvm-ffi/pull/167#discussion_r2441408989
##########
include/tvm/ffi/container/tensor.h:
##########
@@ -306,18 +304,26 @@ class Tensor : public ObjectRef {
}
/*!
- * \brief Get the size of the idx-th dimension.
+ * \brief Get the size of the idx-th dimension. If the idx is negative,
+ * it gets the size of last idx-th dimension.
* \param idx The index of the size.
* \return The size of the idx-th dimension.
*/
- int64_t size(size_t idx) const { return get()->shape[idx]; }
+ int64_t size(int64_t idx) const {
+ if (idx < 0) return get()->shape[get()->ndim - idx];
+ return get()->shape[idx];
+ }
/*!
- * \brief Get the stride of the idx-th dimension.
+ * \brief Get the stride of the idx-th dimension. If the idx is negative,
+ * it gets the stride of last idx-th dimension.
* \param idx The index of the stride.
* \return The stride of the idx-th dimension.
*/
- int64_t stride(size_t idx) const { return get()->strides[idx]; }
+ int64_t stride(int64_t idx) const {
+ if (idx < 0) return get()->strides[get()->ndim - idx];
Review Comment:
```c++
const TensorObj* ptr = get();
return ptr->strides[idx >=0 ? idx : (ptr->ndim - idx)] :
ptr->strides[ptr->ndim - idx];
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]