Struct rerun::sdk::prelude::TensorData
source · pub struct TensorData {
pub shape: ArrowBuffer<u64>,
pub names: Option<Vec<ArrowString>>,
pub buffer: TensorBuffer,
}
Expand description
Datatype: An N-dimensional array of numbers.
The number of dimensions and their respective lengths is specified by the shape
field.
The dimensions are ordered from outermost to innermost. For example, in the common case of
a 2D RGB Image, the shape would be [height, width, channel]
.
These dimensions are combined with an index to look up values from the buffer
field,
which stores a contiguous array of typed values.
Fields§
§shape: ArrowBuffer<u64>
The shape of the tensor, i.e. the length of each dimension.
names: Option<Vec<ArrowString>>
The names of the dimensions of the tensor (optional).
If set, should be the same length as datatypes::TensorData::shape
.
If it has a different length your names may show up improperly,
and some constructors may produce a warning or even an error.
Example: ["height", "width", "channel", "batch"]
.
buffer: TensorBuffer
The content/data.
Implementations§
source§impl TensorData
impl TensorData
sourcepub fn new(
shape: impl Into<ArrowBuffer<u64>>,
buffer: TensorBuffer,
) -> TensorData
pub fn new( shape: impl Into<ArrowBuffer<u64>>, buffer: TensorBuffer, ) -> TensorData
Create a new tensor.
sourcepub fn with_dim_names(
self,
names: impl IntoIterator<Item = impl Into<ArrowString>>,
) -> TensorData
pub fn with_dim_names( self, names: impl IntoIterator<Item = impl Into<ArrowString>>, ) -> TensorData
Set the names of the dimensions to the provided names.
Any existing names will be overwritten.
If the wrong number of names are given, a warning will be logged, and the names might not show up correctly.
sourcepub fn dim_name(&self, dim: usize) -> Option<&ArrowString>
pub fn dim_name(&self, dim: usize) -> Option<&ArrowString>
Get the name of a specific dimension.
Returns None
if the dimension does not have a name.
sourcepub fn shape_short(&self) -> &[u64]
pub fn shape_short(&self) -> &[u64]
Returns the shape of the tensor with all leading & trailing dimensions of size 1 ignored.
If all dimension sizes are one, this returns only the first dimension.
sourcepub fn num_dim(&self) -> usize
pub fn num_dim(&self) -> usize
The number of dimensions of the tensor.
An image tensor will usually have two (height, width) or three (height, width, channels) dimensions.
sourcepub fn is_vector(&self) -> bool
pub fn is_vector(&self) -> bool
Returns true if either all dimensions have size 1 or only a single dimension has a size larger than 1.
Empty tensors return false.
sourcepub fn get(&self, index: &[u64]) -> Option<TensorElement>
pub fn get(&self, index: &[u64]) -> Option<TensorElement>
Get the value of the element at the given index.
Return None
if out-of-bounds.
sourcepub fn dtype(&self) -> TensorDataType
pub fn dtype(&self) -> TensorDataType
The datatype of the tensor.
sourcepub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
The size of the tensor data, in bytes.
source§impl TensorData
impl TensorData
sourcepub fn from_image_file(path: &Path) -> Result<TensorData, TensorImageLoadError>
pub fn from_image_file(path: &Path) -> Result<TensorData, TensorImageLoadError>
Construct a tensor from the contents of an image file on disk.
This will spend CPU cycles reading the file and decoding the image.
To save CPU time and storage, we recommend you instead use
EncodedImage::from_file
.
Requires the image
feature.
sourcepub fn from_image_bytes(
bytes: &[u8],
format: ImageFormat,
) -> Result<TensorData, TensorImageLoadError>
pub fn from_image_bytes( bytes: &[u8], format: ImageFormat, ) -> Result<TensorData, TensorImageLoadError>
Construct a tensor from the contents of an image file.
This will spend CPU cycles decoding the image.
To save CPU time and storage, we recommend you instead use
EncodedImage::from_file_contents
.
Requires the image
feature.
sourcepub fn from_image(
image: impl Into<DynamicImage>,
) -> Result<TensorData, TensorImageLoadError>
pub fn from_image( image: impl Into<DynamicImage>, ) -> Result<TensorData, TensorImageLoadError>
Construct a tensor from something that can be turned into a image::DynamicImage
.
Requires the image
feature.
sourcepub fn from_dynamic_image(
image: DynamicImage,
) -> Result<TensorData, TensorImageLoadError>
pub fn from_dynamic_image( image: DynamicImage, ) -> Result<TensorData, TensorImageLoadError>
Construct a tensor from image::DynamicImage
.
Requires the image
feature.
Trait Implementations§
source§impl Borrow<TensorData> for TensorData
impl Borrow<TensorData> for TensorData
source§fn borrow(&self) -> &TensorData
fn borrow(&self) -> &TensorData
source§impl Clone for TensorData
impl Clone for TensorData
source§fn clone(&self) -> TensorData
fn clone(&self) -> TensorData
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TensorData
impl Debug for TensorData
source§impl Default for TensorData
impl Default for TensorData
source§fn default() -> TensorData
fn default() -> TensorData
source§impl From<&[f16]> for TensorData
impl From<&[f16]> for TensorData
source§fn from(slice: &[f16]) -> TensorData
fn from(slice: &[f16]) -> TensorData
source§impl From<&[f32]> for TensorData
impl From<&[f32]> for TensorData
source§fn from(slice: &[f32]) -> TensorData
fn from(slice: &[f32]) -> TensorData
source§impl From<&[f64]> for TensorData
impl From<&[f64]> for TensorData
source§fn from(slice: &[f64]) -> TensorData
fn from(slice: &[f64]) -> TensorData
source§impl From<&[i16]> for TensorData
impl From<&[i16]> for TensorData
source§fn from(slice: &[i16]) -> TensorData
fn from(slice: &[i16]) -> TensorData
source§impl From<&[i32]> for TensorData
impl From<&[i32]> for TensorData
source§fn from(slice: &[i32]) -> TensorData
fn from(slice: &[i32]) -> TensorData
source§impl From<&[i64]> for TensorData
impl From<&[i64]> for TensorData
source§fn from(slice: &[i64]) -> TensorData
fn from(slice: &[i64]) -> TensorData
source§impl From<&[i8]> for TensorData
impl From<&[i8]> for TensorData
source§fn from(slice: &[i8]) -> TensorData
fn from(slice: &[i8]) -> TensorData
source§impl From<&[u16]> for TensorData
impl From<&[u16]> for TensorData
source§fn from(slice: &[u16]) -> TensorData
fn from(slice: &[u16]) -> TensorData
source§impl From<&[u32]> for TensorData
impl From<&[u32]> for TensorData
source§fn from(slice: &[u32]) -> TensorData
fn from(slice: &[u32]) -> TensorData
source§impl From<&[u64]> for TensorData
impl From<&[u64]> for TensorData
source§fn from(slice: &[u64]) -> TensorData
fn from(slice: &[u64]) -> TensorData
source§impl From<&[u8]> for TensorData
impl From<&[u8]> for TensorData
source§fn from(slice: &[u8]) -> TensorData
fn from(slice: &[u8]) -> TensorData
source§impl Loggable for TensorData
impl Loggable for TensorData
source§fn arrow_datatype() -> DataType
fn arrow_datatype() -> DataType
arrow::datatypes::DataType
, excluding datatype extensions.source§fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, TensorData>>>>,
) -> Result<Arc<dyn Array>, SerializationError>where
TensorData: Clone + 'a,
fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, TensorData>>>>,
) -> Result<Arc<dyn Array>, SerializationError>where
TensorData: Clone + 'a,
source§fn from_arrow_opt(
arrow_data: &dyn Array,
) -> Result<Vec<Option<TensorData>>, DeserializationError>where
TensorData: Sized,
fn from_arrow_opt(
arrow_data: &dyn Array,
) -> Result<Vec<Option<TensorData>>, DeserializationError>where
TensorData: Sized,
Loggable
s.fn arrow_empty() -> Arc<dyn Array>
source§fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
) -> Result<Arc<dyn Array>, SerializationError>where
Self: 'a,
fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
) -> Result<Arc<dyn Array>, SerializationError>where
Self: 'a,
source§fn from_arrow(data: &dyn Array) -> Result<Vec<Self>, DeserializationError>
fn from_arrow(data: &dyn Array) -> Result<Vec<Self>, DeserializationError>
Loggable
s.source§impl PartialEq for TensorData
impl PartialEq for TensorData
source§fn eq(&self, other: &TensorData) -> bool
fn eq(&self, other: &TensorData) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl SizeBytes for TensorData
impl SizeBytes for TensorData
source§fn heap_size_bytes(&self) -> u64
fn heap_size_bytes(&self) -> u64
self
uses on the heap. Read moresource§fn total_size_bytes(&self) -> u64
fn total_size_bytes(&self) -> u64
self
in bytes, accounting for both stack and heap space.source§fn stack_size_bytes(&self) -> u64
fn stack_size_bytes(&self) -> u64
self
on the stack, in bytes. Read moresource§impl TryFrom<DynamicImage> for TensorData
impl TryFrom<DynamicImage> for TensorData
§type Error = TensorImageLoadError
type Error = TensorImageLoadError
source§fn try_from(
value: DynamicImage,
) -> Result<TensorData, <TensorData as TryFrom<DynamicImage>>::Error>
fn try_from( value: DynamicImage, ) -> Result<TensorData, <TensorData as TryFrom<DynamicImage>>::Error>
source§impl<P, S> TryFrom<ImageBuffer<P, S>> for TensorData
impl<P, S> TryFrom<ImageBuffer<P, S>> for TensorData
§type Error = TensorImageLoadError
type Error = TensorImageLoadError
source§fn try_from(
value: ImageBuffer<P, S>,
) -> Result<TensorData, <TensorData as TryFrom<ImageBuffer<P, S>>>::Error>
fn try_from( value: ImageBuffer<P, S>, ) -> Result<TensorData, <TensorData as TryFrom<ImageBuffer<P, S>>>::Error>
impl StructuralPartialEq for TensorData
Auto Trait Implementations§
impl Freeze for TensorData
impl RefUnwindSafe for TensorData
impl Send for TensorData
impl Sync for TensorData
impl Unpin for TensorData
impl UnwindSafe for TensorData
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<L> LoggableBatch for L
impl<L> LoggableBatch for L
source§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.