pub struct Tensor {
pub tensor_id: TensorId,
pub shape: Vec<TensorDimension>,
pub data: TensorData,
pub meaning: TensorDataMeaning,
pub meter: Option<f32>,
}
Expand description
A Multi-dimensional Tensor.
All clones are shallow.
The Tensor
component is special, as you can only have one instance of it per entity.
This is because each element in a tensor is considered to be a separate instance.
§Examples
assert_eq!(
Tensor::data_type(),
DataType::Struct(vec![
Field::new("tensor_id", DataType::FixedSizeBinary(16), false),
Field::new(
"shape",
DataType::List(Box::new(Field::new(
"item",
TensorDimension::data_type(),
false
)),),
false
),
Field::new("data", TensorData::data_type(), false),
Field::new(
"meaning",
DataType::Union(
vec![
Field::new("Unknown", DataType::Boolean, false),
Field::new("ClassId", DataType::Boolean, false),
Field::new("Depth", DataType::Boolean, false)
],
None,
UnionMode::Dense
),
false
),
Field::new("meter", DataType::Float32, true),
])
);
Fields§
§tensor_id: TensorId
Unique identifier for the tensor
shape: Vec<TensorDimension>
Dimensionality and length
data: TensorData
Data payload
meaning: TensorDataMeaning
The per-element data meaning Used to indicated if the data should be interpreted as color, class_id, etc.
meter: Option<f32>
Reciprocal scale of meter unit for depth images
Implementations§
Source§impl Tensor
impl Tensor
pub fn id(&self) -> TensorId
pub fn shape(&self) -> &[TensorDimension]
Sourcepub fn shape_short(&self) -> &[TensorDimension]
pub fn shape_short(&self) -> &[TensorDimension]
Returns the shape of the tensor with all trailing dimensions of size 1 ignored.
If all dimension sizes are one, this returns only the first dimension.
pub fn num_dim(&self) -> usize
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.
pub fn meaning(&self) -> TensorDataMeaning
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)
pub fn get(&self, index: &[u64]) -> Option<TensorElement>
pub fn dtype(&self) -> TensorDataType
pub fn size_in_bytes(&self) -> usize
Source§impl Tensor
impl Tensor
pub fn new( tensor_id: TensorId, shape: Vec<TensorDimension>, data: TensorData, meaning: TensorDataMeaning, meter: Option<f32>, ) -> Self
Source§impl Tensor
impl Tensor
Sourcepub fn from_image_file(path: &Path) -> Result<Self, TensorImageLoadError>
pub fn from_image_file(path: &Path) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of an image file on disk.
JPEGs will be kept encoded, left to the viewer to decode on-the-fly. Other images types will be decoded directly.
Requires the image
feature.
Sourcepub fn from_jpeg_file(path: &Path) -> Result<Self, TensorImageLoadError>
pub fn from_jpeg_file(path: &Path) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of a JPEG file on disk.
Requires the image
feature.
pub fn tensor_from_jpeg_file( image_path: impl AsRef<Path>, ) -> Result<Self, TensorImageLoadError>
Sourcepub fn from_image_bytes(
bytes: Vec<u8>,
format: ImageFormat,
) -> Result<Self, TensorImageLoadError>
pub fn from_image_bytes( bytes: Vec<u8>, format: ImageFormat, ) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of an image file.
JPEGs will be kept encoded, left to the viewer to decode on-the-fly. Other images types will be decoded directly.
Requires the image
feature.
Sourcepub fn from_jpeg_bytes(
jpeg_bytes: Vec<u8>,
) -> Result<Self, TensorImageLoadError>
pub fn from_jpeg_bytes( jpeg_bytes: Vec<u8>, ) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of a JPEG file, without decoding it now.
Requires the image
feature.
pub fn tensor_from_jpeg_bytes( jpeg_bytes: Vec<u8>, ) -> Result<Self, TensorImageLoadError>
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.
This is a convenience function that calls DecodedTensor::from_image
.
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.
This is a convenience function that calls DecodedTensor::from_dynamic_image
.
Sourcepub fn could_be_dynamic_image(&self) -> bool
pub fn could_be_dynamic_image(&self) -> bool
Predicts if Self::to_dynamic_image
is likely to succeed, without doing anything expensive
Sourcepub fn to_dynamic_image(&self) -> Result<DynamicImage, TensorImageSaveError>
pub fn to_dynamic_image(&self) -> Result<DynamicImage, TensorImageSaveError>
Try to convert an image-like tensor into an image::DynamicImage
.
Trait Implementations§
Source§impl ArrowDeserialize for Tensor
impl ArrowDeserialize for Tensor
Source§impl ArrowField for Tensor
impl ArrowField for Tensor
Source§impl ArrowSerialize for Tensor
impl ArrowSerialize for Tensor
Source§type MutableArrayType = MutableTensorArray
type MutableArrayType = MutableTensorArray
arrow2::array::MutableArray
that holds this valueSource§fn new_array() -> Self::MutableArrayType
fn new_array() -> Self::MutableArrayType
Source§fn arrow_serialize(v: &Self, array: &mut Self::MutableArrayType) -> Result<()>
fn arrow_serialize(v: &Self, array: &mut Self::MutableArrayType) -> Result<()>
Source§impl AsRef<Tensor> for DecodedTensor
impl AsRef<Tensor> for DecodedTensor
Source§impl Borrow<Tensor> for DecodedTensor
impl Borrow<Tensor> for DecodedTensor
Source§impl LegacyComponent for Tensor
impl LegacyComponent for Tensor
Source§fn legacy_name() -> ComponentName
fn legacy_name() -> ComponentName
Source§impl Loggable for Tensor
impl Loggable for Tensor
type Name = ComponentName
type Item<'a> = <&'a <Tensor as ArrowDeserialize>::ArrayType as IntoIterator>::Item
type Iter<'a> = <&'a <Tensor as ArrowDeserialize>::ArrayType as IntoIterator>::IntoIter
Source§fn name() -> Self::Name
fn name() -> Self::Name
rerun.datatypes.Vec2D
.Source§fn to_arrow_datatype() -> DataType
fn to_arrow_datatype() -> DataType
arrow2::datatypes::DataType
.Source§fn try_to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
_extension_wrapper: Option<&str>,
) -> SerializationResult<Box<dyn Array>>where
Self: Clone + 'a,
fn try_to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
_extension_wrapper: Option<&str>,
) -> SerializationResult<Box<dyn Array>>where
Self: Clone + 'a,
Loggable
, serializes them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moreSource§fn try_iter_from_arrow(
data: &dyn Array,
) -> DeserializationResult<Self::Iter<'_>>where
Self: Sized,
fn try_iter_from_arrow(
data: &dyn Array,
) -> DeserializationResult<Self::Iter<'_>>where
Self: Sized,
Loggable::Item
s. Read moreSource§fn convert_item_to_self(item: Self::Item<'_>) -> Option<Self>
fn convert_item_to_self(item: Self::Item<'_>) -> Option<Self>
Source§fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>,
) -> Box<dyn Array>where
Self: Clone + 'a,
fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>,
) -> Box<dyn Array>where
Self: Clone + 'a,
Loggable
, serializes
them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moreSource§fn try_to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>,
) -> Result<Box<dyn Array>, SerializationError>where
Self: Clone + 'a,
fn try_to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>,
) -> Result<Box<dyn Array>, SerializationError>where
Self: Clone + 'a,
Loggable
, serializes
them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moreSource§fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
extension_wrapper: Option<&str>,
) -> Box<dyn Array>where
Self: Clone + 'a,
fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
extension_wrapper: Option<&str>,
) -> Box<dyn Array>where
Self: Clone + 'a,
Loggable
, serializes them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moreSource§fn from_arrow(data: &(dyn Array + 'static)) -> Vec<Self>
fn from_arrow(data: &(dyn Array + 'static)) -> Vec<Self>
Source§fn try_from_arrow(
data: &(dyn Array + 'static),
) -> Result<Vec<Self>, DeserializationError>
fn try_from_arrow( data: &(dyn Array + 'static), ) -> Result<Vec<Self>, DeserializationError>
Source§fn try_from_arrow_opt(
data: &(dyn Array + 'static),
) -> Result<Vec<Option<Self>>, DeserializationError>
fn try_from_arrow_opt( data: &(dyn Array + 'static), ) -> Result<Vec<Option<Self>>, DeserializationError>
Source§impl TryFrom<Tensor> for DecodedTensor
impl TryFrom<Tensor> for DecodedTensor
impl Component 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§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 more