Skip to content

Commit

Permalink
Fix image view not handling images with extra leading dimensions of s…
Browse files Browse the repository at this point in the history
…ize 1
  • Loading branch information
Wumpf committed Mar 19, 2024
1 parent 7cfa13c commit f03d53a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/re_types/src/datatypes/tensor_data_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ impl TensorData {
self.shape.as_slice()
}

/// Returns the shape of the tensor with all trailing dimensions of size 1 ignored.
/// 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.
#[inline]
pub fn shape_short(&self) -> &[TensorDimension] {
if self.shape.is_empty() {
&self.shape
} else {
let first_non_one = self
.shape
.iter()
.enumerate()
.find(|(_, dim)| dim.size != 1)
.map_or(0, |(i, _)| i);
self.shape
.iter()
.enumerate()
.rev()
.find(|(_, dim)| dim.size != 1)
.map_or(&self.shape[0..1], |(i, _)| &self.shape[..(i + 1)])
.map_or(&self.shape[..1], |(i, _)| {
&self.shape[first_non_one..(i + 1)]
})
}
}

Expand Down

0 comments on commit f03d53a

Please sign in to comment.