From 9182c828e6c727d149075d7cee8dbcb6d5a5f884 Mon Sep 17 00:00:00 2001 From: Eric Buehler <65165915+EricLBuehler@users.noreply.github.com> Date: Tue, 4 Jun 2024 05:32:36 -0400 Subject: [PATCH] Automatically upcast for to_u64 (#2244) --- candle-core/src/quantized/gguf_file.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/candle-core/src/quantized/gguf_file.rs b/candle-core/src/quantized/gguf_file.rs index 1e9a6a9ac5..d3fe4b5852 100644 --- a/candle-core/src/quantized/gguf_file.rs +++ b/candle-core/src/quantized/gguf_file.rs @@ -217,10 +217,16 @@ impl Value { } } + /// This will also automatically upcast any integral types which will not truncate. pub fn to_u64(&self) -> Result { match self { Self::U64(v) => Ok(*v), - v => crate::bail!("not a u64 {v:?}"), + // Autoupcast cases here + Self::U8(v) => Ok(*v as u64), + Self::U16(v) => Ok(*v as u64), + Self::U32(v) => Ok(*v as u64), + Self::Bool(v) => Ok(*v as u64), + v => crate::bail!("not a u64 or upcastable to u64 {v:?}"), } }