From 883d9c3165e4b232ac7541cded190c94ba76004a Mon Sep 17 00:00:00 2001 From: Vladimir Babin Date: Fri, 16 Oct 2026 12:03:00 +0300 Subject: [PATCH] Fix DType::from rejecting S16, U16 and F16 The upper bound was DType::U64 (9), but the enum extends to F16 (12), so DType::from panicked for the crate's own S16/U16/F16 types -- which Array::get_type() returns for f16 arrays. --- src/core/defines.rs | 9 +++++++++ src/core/util.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/defines.rs b/src/core/defines.rs index b1166279..e3e81e84 100644 --- a/src/core/defines.rs +++ b/src/core/defines.rs @@ -602,6 +602,15 @@ pub enum CublasMathMode { #[cfg(test)] mod tests { + use super::DType; + + #[test] + fn dtype_from_u32_roundtrip() { + for v in (DType::F32 as u32)..=(DType::F16 as u32) { + assert_eq!(DType::from(v) as u32, v); + } + } + #[cfg(feature = "afserde")] mod serde_tests { #[test] diff --git a/src/core/util.rs b/src/core/util.rs index 5a626d52..552caf29 100644 --- a/src/core/util.rs +++ b/src/core/util.rs @@ -75,7 +75,7 @@ impl From for AfError { impl From for DType { fn from(t: u32) -> Self { - assert!(DType::F32 as u32 <= t && t <= DType::U64 as u32); + assert!(DType::F32 as u32 <= t && t <= DType::F16 as u32); unsafe { mem::transmute(t) } } }