tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

Get `&[MaybeUninit<f32>]` from `Tensor` for zero copy

Open NobodyXu opened this issue 1 year ago • 2 comments

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?

NobodyXu avatar Sep 04 '22 06:09 NobodyXu

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.

NobodyXu avatar Sep 05 '22 04:09 NobodyXu

Is calling f_contiguous enough to make sure its internal memory is contiguous?

NobodyXu avatar Sep 07 '22 09:09 NobodyXu