Struct re_types::archetypes::Tensor
source · pub struct Tensor {
pub data: Option<SerializedComponentBatch>,
pub value_range: Option<SerializedComponentBatch>,
}
Expand description
Archetype: An N-dimensional array of numbers.
§Example
§Simple tensor
use ndarray::{Array, ShapeBuilder};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_tensor").spawn()?;
let mut data = Array::<u8, _>::default((8, 6, 3, 5).f());
data.map_inplace(|x| *x = rand::random());
let tensor =
rerun::Tensor::try_from(data)?.with_dim_names(["width", "height", "channel", "batch"]);
rec.log("tensor", &tensor)?;
Ok(())
}

Fields§
§data: Option<SerializedComponentBatch>
The tensor data
value_range: Option<SerializedComponentBatch>
The expected range of values.
This is typically the expected range of valid values. Everything outside of the range is clamped to the range for the purpose of colormpaping. Any colormap applied for display, will map this range.
If not specified, the range will be automatically estimated from the data. Note that the Viewer may try to guess a wider range than the minimum/maximum of values in the contents of the tensor. E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0, the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
Implementations§
source§impl Tensor
impl Tensor
sourcepub fn descriptor_data() -> ComponentDescriptor
pub fn descriptor_data() -> ComponentDescriptor
Returns the ComponentDescriptor
for Self::data
.
sourcepub fn descriptor_value_range() -> ComponentDescriptor
pub fn descriptor_value_range() -> ComponentDescriptor
Returns the ComponentDescriptor
for Self::value_range
.
sourcepub fn descriptor_indicator() -> ComponentDescriptor
pub fn descriptor_indicator() -> ComponentDescriptor
Returns the ComponentDescriptor
for the associated indicator component.
source§impl Tensor
impl Tensor
sourcepub const NUM_COMPONENTS: usize = 3usize
pub const NUM_COMPONENTS: usize = 3usize
The total number of components in the archetype: 1 required, 1 recommended, 1 optional
source§impl Tensor
impl Tensor
sourcepub fn new(data: impl Into<TensorData>) -> Self
pub fn new(data: impl Into<TensorData>) -> Self
Create a new Tensor
.
sourcepub fn update_fields() -> Self
pub fn update_fields() -> Self
Update only some specific fields of a Tensor
.
sourcepub fn clear_fields() -> Self
pub fn clear_fields() -> Self
Clear all the fields of a Tensor
.
sourcepub fn columns<I>(
self,
_lengths: I,
) -> SerializationResult<impl Iterator<Item = SerializedComponentColumn>>
pub fn columns<I>( self, _lengths: I, ) -> SerializationResult<impl Iterator<Item = SerializedComponentColumn>>
Partitions the component data into multiple sub-batches.
Specifically, this transforms the existing SerializedComponentBatch
es data into SerializedComponentColumn
s
instead, via SerializedComponentBatch::partitioned
.
This makes it possible to use RecordingStream::send_columns
to send columnar data directly into Rerun.
The specified lengths
must sum to the total length of the component batch.
sourcepub fn columns_of_unit_batches(
self,
) -> SerializationResult<impl Iterator<Item = SerializedComponentColumn>>
pub fn columns_of_unit_batches( self, ) -> SerializationResult<impl Iterator<Item = SerializedComponentColumn>>
Helper to partition the component data into unit-length sub-batches.
This is semantically similar to calling Self::columns
with std::iter::take(1).repeat(n)
,
where n
is automatically guessed.
sourcepub fn with_data(self, data: impl Into<TensorData>) -> Self
pub fn with_data(self, data: impl Into<TensorData>) -> Self
The tensor data
sourcepub fn with_many_data(
self,
data: impl IntoIterator<Item = impl Into<TensorData>>,
) -> Self
pub fn with_many_data( self, data: impl IntoIterator<Item = impl Into<TensorData>>, ) -> Self
This method makes it possible to pack multiple crate::components::TensorData
in a single component batch.
This only makes sense when used in conjunction with Self::columns
. Self::with_data
should
be used when logging a single row’s worth of data.
sourcepub fn with_value_range(self, value_range: impl Into<ValueRange>) -> Self
pub fn with_value_range(self, value_range: impl Into<ValueRange>) -> Self
The expected range of values.
This is typically the expected range of valid values. Everything outside of the range is clamped to the range for the purpose of colormpaping. Any colormap applied for display, will map this range.
If not specified, the range will be automatically estimated from the data. Note that the Viewer may try to guess a wider range than the minimum/maximum of values in the contents of the tensor. E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0, the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
sourcepub fn with_many_value_range(
self,
value_range: impl IntoIterator<Item = impl Into<ValueRange>>,
) -> Self
pub fn with_many_value_range( self, value_range: impl IntoIterator<Item = impl Into<ValueRange>>, ) -> Self
This method makes it possible to pack multiple crate::components::ValueRange
in a single component batch.
This only makes sense when used in conjunction with Self::columns
. Self::with_value_range
should
be used when logging a single row’s worth of data.
source§impl Tensor
impl Tensor
sourcepub fn try_from<T: TryInto<TensorData>>(data: T) -> Result<Self, T::Error>
pub fn try_from<T: TryInto<TensorData>>(data: T) -> Result<Self, T::Error>
Try to construct a Tensor
from anything that can be converted into TensorData
This is useful for constructing a tensor from an ndarray.
sourcepub fn with_dim_names(
self,
names: impl IntoIterator<Item = impl Into<ArrowString>>,
) -> Self
pub fn with_dim_names( self, names: impl IntoIterator<Item = impl Into<ArrowString>>, ) -> Self
Update the names
of the contained TensorData
dimensions.
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.
source§impl Tensor
impl Tensor
sourcepub fn from_image(
image: impl Into<DynamicImage>,
) -> Result<Self, TensorImageLoadError>
pub fn from_image( image: impl Into<DynamicImage>, ) -> Result<Self, 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<Self, TensorImageLoadError>
pub fn from_dynamic_image( image: DynamicImage, ) -> Result<Self, TensorImageLoadError>
Construct a tensor from [image::DynamicImage
].
Requires the image
feature.
Trait Implementations§
source§impl Archetype for Tensor
impl Archetype for Tensor
§type Indicator = GenericIndicatorComponent<Tensor>
type Indicator = GenericIndicatorComponent<Tensor>
source§fn name() -> ArchetypeName
fn name() -> ArchetypeName
rerun.archetypes.Points2D
.source§fn display_name() -> &'static str
fn display_name() -> &'static str
source§fn required_components() -> Cow<'static, [ComponentDescriptor]>
fn required_components() -> Cow<'static, [ComponentDescriptor]>
source§fn recommended_components() -> Cow<'static, [ComponentDescriptor]>
fn recommended_components() -> Cow<'static, [ComponentDescriptor]>
source§fn optional_components() -> Cow<'static, [ComponentDescriptor]>
fn optional_components() -> Cow<'static, [ComponentDescriptor]>
source§fn all_components() -> Cow<'static, [ComponentDescriptor]>
fn all_components() -> Cow<'static, [ComponentDescriptor]>
source§fn from_arrow_components(
arrow_data: impl IntoIterator<Item = (ComponentDescriptor, ArrayRef)>,
) -> DeserializationResult<Self>
fn from_arrow_components( arrow_data: impl IntoIterator<Item = (ComponentDescriptor, ArrayRef)>, ) -> DeserializationResult<Self>
ComponentNames
, deserializes them
into this archetype. Read moresource§fn from_arrow(
data: impl IntoIterator<Item = (Field, Arc<dyn Array>)>,
) -> Result<Self, DeserializationError>where
Self: Sized,
fn from_arrow(
data: impl IntoIterator<Item = (Field, Arc<dyn Array>)>,
) -> Result<Self, DeserializationError>where
Self: Sized,
source§impl AsComponents for Tensor
impl AsComponents for Tensor
source§fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch>
fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch>
SerializedComponentBatch
es. Read moresource§impl PartialEq for Tensor
impl PartialEq for Tensor
source§impl SizeBytes for Tensor
impl SizeBytes for Tensor
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 moreimpl ArchetypeReflectionMarker for Tensor
impl StructuralPartialEq for Tensor
Auto Trait Implementations§
impl Freeze for Tensor
impl !RefUnwindSafe for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl !UnwindSafe for Tensor
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> 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 more