Skip to content

Commit

Permalink
Clarify what happens if the number of names is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 17, 2024
1 parent 7f6c1f0 commit eeb8585
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ table TensorData (
/// The names of the dimensions of the tensor (optional).
///
/// If set, should be the same length as [datatypes.TensorData.shape].
/// If it has a different length your names may show up improperly,
/// and some constructors may produce a warning or even an error.
///
/// Example: `["height", "width", "channel", "batch"]`.
names: [string] (order: 250, nullable);
Expand Down
3 changes: 2 additions & 1 deletion crates/store/re_types/src/archetypes/tensor_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl Tensor {
///
/// Any existing names will be overwritten.
///
/// If too few or too many names are provided, this function will warn and return.
/// If the wrong number of names are given, a warning will be logged,
/// and the names might not show up correctly.
pub fn with_dim_names(
mut self,
names: impl IntoIterator<Item = impl Into<ArrowString>>,
Expand Down
2 changes: 2 additions & 0 deletions crates/store/re_types/src/datatypes/tensor_data.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions crates/store/re_types/src/datatypes/tensor_data_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ impl TensorData {
///
/// Any existing names will be overwritten.
///
/// If too few or too many names are provided, this function will warn and return.
/// If the wrong number of names are given, a warning will be logged,
/// and the names might not show up correctly.
pub fn with_dim_names(
mut self,
names: impl IntoIterator<Item = impl Into<ArrowString>>,
) -> Self {
let names: Vec<ArrowString> = names.into_iter().map(|x| x.into()).collect();
if names.len() == self.shape.len() {
self.names = Some(names);
} else {

if names.len() != self.shape.len() {
re_log::warn_once!(
"Wrong number of names provided for tensor dimension. {} provided but {} expected.",
"Wrong number of names provided for tensor dimension. {} provided but {} expected. The names will be ignored.",
names.len(),
self.shape.len(),
);
}

self.names = Some(names);

self
}

Expand Down
2 changes: 2 additions & 0 deletions docs/content/reference/types/datatypes/tensor_data.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rerun_cpp/src/rerun/datatypes/tensor_data.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rerun_py/rerun_sdk/rerun/datatypes/tensor_data.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eeb8585

Please sign in to comment.