Struct re_types::datatypes::TensorData
source · pub struct TensorData {
pub shape: Vec<TensorDimension>,
pub buffer: TensorBuffer,
}
Expand description
Datatype: A multi-dimensional Tensor
of data.
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.
Note that the buffer may be encoded in a compressed format such as jpeg
or
in a format with downsampled chroma, such as NV12 or YUY2.
For file formats, the shape is used as a hint, for chroma downsampled format
the shape has to be the shape of the decoded image.
Fields§
§shape: Vec<TensorDimension>
The shape of the tensor, including optional names for each dimension.
buffer: TensorBuffer
The content/data.
Implementations§
source§impl TensorData
impl TensorData
sourcepub fn new(shape: Vec<TensorDimension>, buffer: TensorBuffer) -> Self
pub fn new(shape: Vec<TensorDimension>, buffer: TensorBuffer) -> Self
Create a new tensor.
sourcepub fn shape(&self) -> &[TensorDimension]
pub fn shape(&self) -> &[TensorDimension]
The shape of the tensor, including optional dimension names.
sourcepub fn shape_short(&self) -> &[TensorDimension]
pub fn shape_short(&self) -> &[TensorDimension]
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 image_height_width_channels(&self) -> Option<[u64; 3]>
pub fn image_height_width_channels(&self) -> Option<[u64; 3]>
If the tensor can be interpreted as an image, return the height, width, and channels/depth of it.
sourcepub fn is_shaped_like_an_image(&self) -> bool
pub fn is_shaped_like_an_image(&self) -> bool
Returns true if the tensor can be interpreted as an image.
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_with_image_coords(
&self,
x: u64,
y: u64,
channel: u64
) -> Option<TensorElement>
pub fn get_with_image_coords( &self, x: u64, y: u64, channel: u64 ) -> Option<TensorElement>
Query with x, y, channel indices.
Allows to query values for any image-like tensor even if it has more or less dimensions than 3.
(useful for sampling e.g. N x M x C x 1
tensor which is a valid image)
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, or if the tensor is encoded (e.g. TensorBuffer::Jpeg
).
sourcepub fn get_nv12_pixel(&self, x: u64, y: u64) -> Option<[u8; 3]>
pub fn get_nv12_pixel(&self, x: u64, y: u64) -> Option<[u8; 3]>
Returns decoded RGB8 value at the given image coordinates if this tensor is a NV12 image.
If the tensor is not TensorBuffer::Nv12
, None
is returned.
It is undefined what happens if the coordinate is out-of-bounds.
sourcepub fn get_yuy2_pixel(&self, x: u64, y: u64) -> Option<[u8; 3]>
pub fn get_yuy2_pixel(&self, x: u64, y: u64) -> Option<[u8; 3]>
Returns decoded RGB8 value at the given image coordinates if this tensor is a YUY2 image.
If the tensor is not TensorBuffer::Yuy2
, None
is returned.
It is undefined what happens if the coordinate is 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.
Trait Implementations§
source§impl AsRef<TensorData> for DecodedTensor
impl AsRef<TensorData> for DecodedTensor
source§fn as_ref(&self) -> &TensorData
fn as_ref(&self) -> &TensorData
source§impl Borrow<TensorData> for DecodedTensor
impl Borrow<TensorData> for DecodedTensor
source§fn borrow(&self) -> &TensorData
fn borrow(&self) -> &TensorData
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 From<&[f16]> for TensorData
impl From<&[f16]> for TensorData
source§impl From<&[f32]> for TensorData
impl From<&[f32]> for TensorData
source§impl From<&[f64]> for TensorData
impl From<&[f64]> for TensorData
source§impl From<&[i16]> for TensorData
impl From<&[i16]> for TensorData
source§impl From<&[i32]> for TensorData
impl From<&[i32]> for TensorData
source§impl From<&[i64]> for TensorData
impl From<&[i64]> for TensorData
source§impl From<&[i8]> for TensorData
impl From<&[i8]> for TensorData
source§impl From<&[u16]> for TensorData
impl From<&[u16]> for TensorData
source§impl From<&[u32]> for TensorData
impl From<&[u32]> for TensorData
source§impl From<&[u64]> for TensorData
impl From<&[u64]> for TensorData
source§impl From<&[u8]> for TensorData
impl From<&[u8]> for TensorData
source§impl<'a> From<&'a TensorData> for Cow<'a, TensorData>
impl<'a> From<&'a TensorData> for Cow<'a, TensorData>
source§fn from(value: &'a TensorData) -> Self
fn from(value: &'a TensorData) -> Self
source§impl<'a> From<TensorData> for Cow<'a, TensorData>
impl<'a> From<TensorData> for Cow<'a, TensorData>
source§fn from(value: TensorData) -> Self
fn from(value: TensorData) -> Self
source§impl Loggable for TensorData
impl Loggable for TensorData
type Name = DatatypeName
source§fn name() -> Self::Name
fn name() -> Self::Name
rerun.datatypes.Vec2D
.source§fn arrow_datatype() -> DataType
fn arrow_datatype() -> DataType
arrow2::datatypes::DataType
, excluding datatype extensions.source§fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>
) -> SerializationResult<Box<dyn Array>>where
Self: Clone + 'a,
fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>
) -> SerializationResult<Box<dyn Array>>where
Self: Clone + 'a,
Loggable
, serializes them into an Arrow array.
The Arrow array’s datatype will match Loggable::arrow_field
. Read moresource§fn from_arrow_opt(
arrow_data: &dyn Array
) -> DeserializationResult<Vec<Option<Self>>>where
Self: Sized,
fn from_arrow_opt(
arrow_data: &dyn Array
) -> DeserializationResult<Vec<Option<Self>>>where
Self: Sized,
source§fn extended_arrow_datatype() -> DataType
fn extended_arrow_datatype() -> DataType
arrow2::datatypes::DataType
, including datatype extensions. Read moresource§fn arrow_field() -> Field
fn arrow_field() -> Field
arrow2::datatypes::Field
, including datatype extensions. Read moresource§fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>
) -> Result<Box<dyn Array>, SerializationError>where
Self: 'a,
fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>
) -> Result<Box<dyn Array>, SerializationError>where
Self: 'a,
Loggable
, serializes
them into an Arrow array.
The Arrow array’s datatype will match Loggable::arrow_field
. Read moresource§fn from_arrow(
data: &(dyn Array + 'static)
) -> Result<Vec<Self>, DeserializationError>
fn from_arrow( data: &(dyn Array + 'static) ) -> Result<Vec<Self>, DeserializationError>
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
on the heap, in bytes.source§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<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f16>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f16>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f16>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f16>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f32>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f32>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f64>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, f64>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i16>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i16>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i32>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i32>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i64>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i64>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i8>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, i8>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u16>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u16>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u32>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u32>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u64>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u64>
§type Error = TensorCastError
type Error = TensorCastError
source§impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u8>
impl<'a> TryFrom<&'a TensorData> for ArrayViewD<'a, u8>
§type Error = TensorCastError
type Error = TensorCastError
source§impl TryFrom<TensorData> for DecodedTensor
impl TryFrom<TensorData> for DecodedTensor
§type Error = TensorData
type Error = TensorData
source§fn try_from(tensor: TensorData) -> Result<Self, TensorData>
fn try_from(tensor: TensorData) -> Result<Self, TensorData>
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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<L> LoggableBatch for L
impl<L> LoggableBatch for L
type Name = <L as Loggable>::Name
source§fn name(&self) -> <L as LoggableBatch>::Name
fn name(&self) -> <L as LoggableBatch>::Name
rerun.datatypes.Vec2D
.source§fn num_instances(&self) -> usize
fn num_instances(&self) -> usize
source§fn arrow_field(&self) -> Field
fn arrow_field(&self) -> Field
arrow2::datatypes::Field
, including datatype extensions.