Struct rerun::archetypes::Tensor
source · pub struct Tensor {
pub data: TensorData,
pub value_range: Option<ValueRange>,
}
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: TensorData
The tensor data
value_range: Option<ValueRange>
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 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>) -> Tensor
pub fn new(data: impl Into<TensorData>) -> Tensor
Create a new Tensor
.
sourcepub fn with_value_range(self, value_range: impl Into<ValueRange>) -> Tensor
pub fn with_value_range(self, value_range: impl Into<ValueRange>) -> Tensor
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.
source§impl Tensor
impl Tensor
sourcepub fn data(&self) -> &TensorData
pub fn data(&self) -> &TensorData
Accessor to the underlying TensorData
.
sourcepub fn try_from<T>(data: T) -> Result<Tensor, <T as TryInto<TensorData>>::Error>where
T: TryInto<TensorData>,
pub fn try_from<T>(data: T) -> Result<Tensor, <T as TryInto<TensorData>>::Error>where
T: TryInto<TensorData>,
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>>
) -> Tensor
pub fn with_dim_names( self, names: impl IntoIterator<Item = impl Into<ArrowString>> ) -> Tensor
Update the names
of the contained TensorData
dimensions.
Any existing Dimension names will be overwritten.
If too many, or too few names are provided, this function will warn and only update the subset of names that it can.
source§impl Tensor
impl Tensor
sourcepub fn from_image(
image: impl Into<DynamicImage>
) -> Result<Tensor, TensorImageLoadError>
pub fn from_image( image: impl Into<DynamicImage> ) -> Result<Tensor, 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<Tensor, TensorImageLoadError>
pub fn from_dynamic_image( image: DynamicImage ) -> Result<Tensor, TensorImageLoadError>
Construct a tensor from image::DynamicImage
.
Requires the image
feature.
Methods from Deref<Target = TensorData>§
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 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.
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 indicator() -> MaybeOwnedComponentBatch<'static>
fn indicator() -> MaybeOwnedComponentBatch<'static>
source§fn required_components() -> Cow<'static, [ComponentName]>
fn required_components() -> Cow<'static, [ComponentName]>
source§fn recommended_components() -> Cow<'static, [ComponentName]>
fn recommended_components() -> Cow<'static, [ComponentName]>
source§fn optional_components() -> Cow<'static, [ComponentName]>
fn optional_components() -> Cow<'static, [ComponentName]>
source§fn all_components() -> Cow<'static, [ComponentName]>
fn all_components() -> Cow<'static, [ComponentName]>
source§fn from_arrow_components(
arrow_data: impl IntoIterator<Item = (ComponentName, Box<dyn Array>)>
) -> Result<Tensor, DeserializationError>
fn from_arrow_components( arrow_data: impl IntoIterator<Item = (ComponentName, Box<dyn Array>)> ) -> Result<Tensor, DeserializationError>
ComponentNames
, deserializes them
into this archetype. Read moresource§fn from_arrow(
data: impl IntoIterator<Item = (Field, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
fn from_arrow(
data: impl IntoIterator<Item = (Field, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
source§impl AsComponents for Tensor
impl AsComponents for Tensor
source§fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>>
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>>
ComponentBatch
s. Read moresource§impl AsRef<TensorData> for Tensor
impl AsRef<TensorData> for Tensor
source§fn as_ref(&self) -> &TensorData
fn as_ref(&self) -> &TensorData
source§impl Borrow<TensorData> for Tensor
impl Borrow<TensorData> for Tensor
source§fn borrow(&self) -> &TensorData
fn borrow(&self) -> &TensorData
source§impl Deref for Tensor
impl Deref for Tensor
§type Target = TensorData
type Target = TensorData
source§fn deref(&self) -> &TensorData
fn deref(&self) -> &TensorData
source§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
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 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>
§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