Skip to content

Commit

Permalink
Automatically upcast for to_u64 (huggingface#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler authored Jun 4, 2024
1 parent 3f13ad3 commit 9182c82
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion candle-core/src/quantized/gguf_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,16 @@ impl Value {
}
}

/// This will also automatically upcast any integral types which will not truncate.
pub fn to_u64(&self) -> Result<u64> {
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:?}"),
}
}

Expand Down

0 comments on commit 9182c82

Please sign in to comment.