Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Remove TensorTrait #1819

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
with:
mode: minimum
count: 1
labels: "📊 analytics, 🪳 bug, 🧑‍💻 dev experience, 📖 documentation, 💬 discussion, examples, 📉 performance, 🐍 python API, ⛃ re_datastore, 📺 re_viewer, 🔺 re_renderer, ⛴ release, 🦀 rust SDK, 🔨 testing, ui, 🕸️ web"
labels: "📊 analytics, 🪳 bug, 🧑‍💻 dev experience, 📖 documentation, 💬 discussion, examples, 📉 performance, 🐍 python API, ⛃ re_datastore, 📺 re_viewer, 🔺 re_renderer, 🚜 refactor, ⛴ release, 🦀 rust SDK, 🔨 testing, ui, 🕸️ web"
2 changes: 1 addition & 1 deletion crates/re_log_types/src/component_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub use size::Size3D;
#[cfg(feature = "image")]
pub use tensor::TensorImageError;
pub use tensor::{
Tensor, TensorCastError, TensorData, TensorDataMeaning, TensorDimension, TensorId, TensorTrait,
Tensor, TensorCastError, TensorData, TensorDataMeaning, TensorDimension, TensorId,
};
pub use text_entry::TextEntry;
pub use transform::{Pinhole, Rigid3, Transform};
Expand Down
32 changes: 10 additions & 22 deletions crates/re_log_types/src/component_types/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ use crate::{TensorDataType, TensorElement};

use super::arrow_convert_shims::BinaryBuffer;

pub trait TensorTrait {
fn id(&self) -> TensorId;
fn shape(&self) -> &[TensorDimension];
fn num_dim(&self) -> usize;
fn is_shaped_like_an_image(&self) -> bool;
fn is_vector(&self) -> bool;
fn meaning(&self) -> TensorDataMeaning;
fn get(&self, index: &[u64]) -> Option<TensorElement>;
fn dtype(&self) -> TensorDataType;
fn size_in_bytes(&self) -> usize;
}

// ----------------------------------------------------------------------------

/// A unique id per [`Tensor`].
Expand Down Expand Up @@ -365,23 +353,23 @@ pub struct Tensor {
pub meter: Option<f32>,
}

impl TensorTrait for Tensor {
impl Tensor {
#[inline]
fn id(&self) -> TensorId {
pub fn id(&self) -> TensorId {
self.tensor_id
}

#[inline]
fn shape(&self) -> &[TensorDimension] {
pub fn shape(&self) -> &[TensorDimension] {
self.shape.as_slice()
}

#[inline]
fn num_dim(&self) -> usize {
pub fn num_dim(&self) -> usize {
self.shape.len()
}

fn is_shaped_like_an_image(&self) -> bool {
pub fn is_shaped_like_an_image(&self) -> bool {
self.num_dim() == 2
|| self.num_dim() == 3 && {
matches!(
Expand All @@ -393,17 +381,17 @@ impl TensorTrait for Tensor {
}

#[inline]
fn is_vector(&self) -> bool {
pub fn is_vector(&self) -> bool {
let shape = &self.shape;
shape.len() == 1 || { shape.len() == 2 && (shape[0].size == 1 || shape[1].size == 1) }
}

#[inline]
fn meaning(&self) -> TensorDataMeaning {
pub fn meaning(&self) -> TensorDataMeaning {
self.meaning
}

fn get(&self, index: &[u64]) -> Option<TensorElement> {
pub fn get(&self, index: &[u64]) -> Option<TensorElement> {
let mut stride: usize = 1;
let mut offset: usize = 0;
for (TensorDimension { size, .. }, index) in self.shape.iter().zip(index).rev() {
Expand All @@ -429,11 +417,11 @@ impl TensorTrait for Tensor {
}
}

fn dtype(&self) -> TensorDataType {
pub fn dtype(&self) -> TensorDataType {
self.data.dtype()
}

fn size_in_bytes(&self) -> usize {
pub fn size_in_bytes(&self) -> usize {
self.data.size_in_bytes()
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ pub mod components {
EncodedMesh3D, InstanceKey, KeypointId, Label, LineStrip2D, LineStrip3D, Mat3x3, Mesh3D,
MeshFormat, MeshId, Pinhole, Point2D, Point3D, Quaternion, Radius, RawMesh3D, Rect2D,
Rigid3, Scalar, ScalarPlotProps, Size3D, Tensor, TensorData, TensorDataMeaning,
TensorDimension, TensorId, TensorTrait, TextEntry, Transform, Vec2D, Vec3D, Vec4D,
ViewCoordinates,
TensorDimension, TensorId, TextEntry, Transform, Vec2D, Vec3D, Vec4D, ViewCoordinates,
};
}

Expand Down
2 changes: 1 addition & 1 deletion crates/re_tensor_ops/tests/tensor_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use re_log_types::component_types::{
Tensor, TensorCastError, TensorData, TensorDataMeaning, TensorDimension, TensorId, TensorTrait,
Tensor, TensorCastError, TensorData, TensorDataMeaning, TensorDimension, TensorId,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/misc/caches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod mesh_cache;
mod tensor_decode_cache;
mod tensor_image_cache;

use re_log_types::component_types::{self, TensorTrait};
use re_log_types::component_types::{self};
pub use tensor_image_cache::ColoredTensorView;

/// Does memoization of different things for the immediate mode UI.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/misc/caches/tensor_decode_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use re_log_types::component_types::{Tensor, TensorDimension, TensorId, TensorTrait};
use re_log_types::component_types::{Tensor, TensorDimension, TensorId};

#[derive(thiserror::Error, Clone, Debug)]
pub enum TensorDecodeError {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/misc/caches/tensor_image_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use egui::{Color32, ColorImage};
use egui_extras::RetainedImage;
use image::DynamicImage;
use re_log_types::{
component_types::{self, ClassId, Tensor, TensorData, TensorDataMeaning, TensorTrait},
component_types::{self, ClassId, Tensor, TensorData, TensorDataMeaning},
MsgId,
};
use re_renderer::{
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/data_ui/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use egui::{ColorImage, Vec2};
use itertools::Itertools as _;

use re_log_types::{
component_types::{ClassId, Tensor, TensorDataMeaning, TensorTrait},
component_types::{ClassId, Tensor, TensorDataMeaning},
TensorElement,
};

Expand Down
5 changes: 1 addition & 4 deletions crates/re_viewer/src/ui/space_view_heuristics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use itertools::Itertools;
use nohash_hasher::IntSet;
use re_arrow_store::{DataStore, LatestAtQuery, Timeline};
use re_data_store::{log_db::EntityDb, query_latest_single, ComponentName, EntityPath};
use re_log_types::{
component_types::{Tensor, TensorTrait},
Component,
};
use re_log_types::{component_types::Tensor, Component};

use crate::{
misc::{space_info::SpaceInfoCollection, ViewerContext},
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_bar_chart/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use re_arrow_store::LatestAtQuery;
use re_data_store::EntityPath;
use re_log::warn_once;
use re_log_types::component_types::{self, InstanceKey, Tensor, TensorTrait as _};
use re_log_types::component_types::{self, InstanceKey, Tensor};
use re_query::query_entity_with_primary;

use crate::{misc::ViewerContext, ui::scene::SceneQuery};
Expand Down
3 changes: 1 addition & 2 deletions crates/re_viewer/src/ui/view_category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use re_arrow_store::{LatestAtQuery, TimeInt};
use re_data_store::{EntityPath, LogDb, Timeline};
use re_log_types::{
component_types::{
Box3D, LineStrip2D, LineStrip3D, Point2D, Point3D, Rect2D, Scalar, Tensor, TensorTrait,
TextEntry,
Box3D, LineStrip2D, LineStrip3D, Point2D, Point3D, Rect2D, Scalar, Tensor, TextEntry,
},
Arrow3D, Component, Mesh3D, Transform,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;

use re_data_store::{query_latest_single, EntityPath, EntityProperties, InstancePathHash};
use re_log_types::{
component_types::{ColorRGBA, InstanceKey, Tensor, TensorData, TensorDataMeaning, TensorTrait},
component_types::{ColorRGBA, InstanceKey, Tensor, TensorData, TensorDataMeaning},
Component, Transform,
};
use re_query::{query_primary_with_history, EntityView, QueryError};
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ impl ViewSpatialState {
if tensor.meaning == TensorDataMeaning::Depth {
if properties.depth_from_world_scale.is_auto() {
let auto = tensor.meter.unwrap_or_else(|| {
use re_log_types::component_types::TensorTrait as _;
if tensor.dtype().is_integer() {
1000.0
} else {
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use egui::{
};
use macaw::IsoTransform;
use re_data_store::EntityPath;
use re_log_types::component_types::TensorTrait;
use re_renderer::view_builder::{TargetConfiguration, ViewBuilder};

use super::{
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_tensor/scene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use re_arrow_store::LatestAtQuery;
use re_data_store::{EntityPath, EntityProperties, InstancePath};
use re_log_types::component_types::{InstanceKey, Tensor, TensorTrait};
use re_log_types::component_types::{InstanceKey, Tensor};
use re_query::{query_entity_with_primary, EntityView, QueryError};

use crate::{misc::ViewerContext, ui::SceneQuery};
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_tensor/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use egui::{epaint::TextShape, Color32, ColorImage, NumExt as _, Vec2};
use ndarray::{Axis, Ix2};

use re_log_types::{
component_types::{self, Tensor, TensorTrait},
component_types::{self, Tensor},
TensorDataType,
};
use re_tensor_ops::dimension_mapping::{DimensionMapping, DimensionSelector};
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use rerun::{
EncodedMesh3D, InstanceKey, KeypointId, Label, LineStrip2D, LineStrip3D, Mat3x3, Mesh3D,
MeshFormat, MeshId, Pinhole, Point2D, Point3D, Quaternion, Radius, RawMesh3D, Rect2D,
Rigid3, Scalar, ScalarPlotProps, Size3D, Tensor, TensorData, TensorDimension, TensorId,
TensorTrait, TextEntry, Transform, Vec2D, Vec3D, Vec4D, ViewCoordinates,
TextEntry, Transform, Vec2D, Vec3D, Vec4D, ViewCoordinates,
},
coordinates::{Axis3, Handedness, Sign, SignedAxis3},
};
Expand Down