tch-rs
tch-rs copied to clipboard
Get `&[MaybeUninit<f32>]` from `Tensor` for zero copy
I need to export images from graphicsmagick, which can be quite large and I'd like to avoid copying and unnecessary allocation.
The API I use accepts &'a mut [MaybeUninit<T>]
, so I wonder is it possible for tch
to expose such API?
There's a function called Tensor::data_ptr
that can be used to construct &[MaybeUninit<f32>]
, but I'm not sure whether it returns pointer to a continuous allocation of f32
.
Is calling f_contiguous
enough to make sure its internal memory is contiguous?