tp-nan commented on issue #325:
URL: https://github.com/apache/tvm-ffi/issues/325#issuecomment-3639956796

   I would provide another example: converting a contiguous `cv::Mat` into a 
`Tensor` seems to be simple with:
   
   ```cpp
   struct CPUNDAlloc {
       CPUNDAlloc(cv::Mat data) : data_(data) {}
       void AllocData(DLTensor* tensor) { tensor->data = data_.data; }
       void FreeData(DLTensor* tensor) { std::swap(data_, cv::Mat()); }
       cv::Mat data_;
   };
   
   inline Tensor mat2tensor(cv::Mat mat) {
       DLDataType dtype = ...;
       DLDevice device = ...;
       assert(mat.isContinuous());
   
       return Tensor::FromNDAlloc(CPUNDAlloc(mat), shape, dtype, device);
   }
   ```
   
   However, non-contiguous `cv::Mat` objects cannot be converted to `Tensor` 
using this approach directly.


-- 
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]

Reply via email to