From: Corey Lowman Date: Mon, 21 Aug 2023 07:14:25 +0000 (-0400) Subject: impl `View` for `TensorView` (#329) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=34a2a0a29014faa342ebfb1a0cc22b9574da96d6;p=safetensors.git 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. --- 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(