best way to create libtorch (tch-rs) tensor from polars dataframe

50 Views Asked by At

What would be the most efficient way to create libtorch (tch-rs) tensor from polars dataframe?

I can only make it working with as_slice->from_slice like

Tensor::from_slice(
  series.f64()?
  .to_vec()
  .iter()
  .map(|v| v.unwrap_or_default() as f32)
  .collect::<Vec<f32>>().as_slice()
)

but there are to_arrow/chunks functions in the Series which seem to be giving access to raw memory and also from_blob in Tensor looking like it should be possible to instantiate it without iterating/collecting.

0

There are 0 best solutions below