Skip to content

Commit d7de3ea

Browse files
committed
fix: replace unwrap() with safe handling in tensor Display impl
- Use unwrap_or(0) for empty iterator in max() to avoid panic on empty tensors - Use ok_or(std::fmt::Error)? for split_once('e') to propagate errors properly Fixes #801
1 parent 230fe11 commit d7de3ea

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/kornia-tensor/src/tensor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ where
10271027
.iter()
10281028
.map(|v| format!("{v:.4}").len())
10291029
.max()
1030-
.unwrap();
1030+
.unwrap_or(0);
10311031

10321032
let scientific = width > 8;
10331033

@@ -1074,7 +1074,7 @@ where
10741074
if value.is_empty() {
10751075
value = if scientific {
10761076
let num = format!("{v:.4e}");
1077-
let (before, after) = num.split_once('e').unwrap();
1077+
let (before, after) = num.split_once('e').ok_or(std::fmt::Error)?;
10781078
let after = if let Some(stripped) = after.strip_prefix('-') {
10791079
format!("-{:0>2}", &stripped)
10801080
} else {

0 commit comments

Comments
 (0)