From 34a2a0a29014faa342ebfb1a0cc22b9574da96d6 Mon Sep 17 00:00:00 2001 From: Corey Lowman Date: Mon, 21 Aug 2023 03:14:25 -0400 Subject: [PATCH] impl `View` for `TensorView` (#329) The existing impl only exists for `&TensorView`, which means you cannot pass a `Vec<(String, TensorView)>` into `serialize_to_file`. With this new impl, you can. --- safetensors/src/tensor.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/safetensors/src/tensor.rs b/safetensors/src/tensor.rs index a05f49a..e740bcb 100644 --- a/safetensors/src/tensor.rs +++ b/safetensors/src/tensor.rs @@ -554,6 +554,24 @@ impl<'data> View for &TensorView<'data> { } } +impl<'data> View for TensorView<'data> { + fn dtype(&self) -> Dtype { + self.dtype + } + + fn shape(&self) -> &[usize] { + &self.shape + } + + fn data(&self) -> Cow<[u8]> { + self.data.into() + } + + fn data_len(&self) -> usize { + self.data.len() + } +} + impl<'data> TensorView<'data> { /// Create new tensor view pub fn new( -- 2.43.0