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 7908413
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 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,17 @@ 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 {
self.shape
.iter()
.enumerate()
.rev()
.find(|(_, dim)| dim.size != 1)
.map_or(&self.shape[0..1], |(i, _)| &self.shape[..(i + 1)])
let first_not_one = self.shape.iter().position(|dim| dim.size != 1);
let last_not_one = self.shape.iter().rev().position(|dim| dim.size != 1);
&self.shape[first_not_one.unwrap_or(0)..self.shape.len() - last_not_one.unwrap_or(0)]
}
}

Expand Down

0 comments on commit 7908413

Please sign in to comment.