mirror of
https://github.com/huggingface/candle.git
synced 2025-06-15 18:28:24 +00:00
Automatically upcast for to_u64 (#2244)
This commit is contained in:
@ -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> {
|
pub fn to_u64(&self) -> Result<u64> {
|
||||||
match self {
|
match self {
|
||||||
Self::U64(v) => Ok(*v),
|
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:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user