Skip to content

Commit faa6a6e

Browse files
voidstackloopclaude
andcommitted
dtype: U64 (exact 64-bit paths without f64, wrapping arithmetic, npy/safetensors/torch I/O, numpy conversion)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 566d771 commit faa6a6e

8 files changed

Lines changed: 136 additions & 11 deletions

File tree

‎crates/oxideon-core/src/backend/cpu.rs‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum CpuStorage {
1818
I16(Vec<i16>),
1919
U16(Vec<u16>),
2020
U32(Vec<u32>),
21+
U64(Vec<u64>),
2122
I32(Vec<i32>),
2223
I64(Vec<i64>),
2324
F16(Vec<f16>),
@@ -89,6 +90,7 @@ impl CpuStorage {
8990
Self::I16(_) => DType::I16,
9091
Self::U16(_) => DType::U16,
9192
Self::U32(_) => DType::U32,
93+
Self::U64(_) => DType::U64,
9294
Self::I32(_) => DType::I32,
9395
Self::I64(_) => DType::I64,
9496
Self::F16(_) => DType::F16,
@@ -106,6 +108,7 @@ impl CpuStorage {
106108
Self::I16(v) => v.len(),
107109
Self::U16(v) => v.len(),
108110
Self::U32(v) => v.len(),
111+
Self::U64(v) => v.len(),
109112
Self::I32(v) => v.len(),
110113
Self::I64(v) => v.len(),
111114
Self::F16(v) => v.len(),
@@ -170,6 +173,7 @@ impl CpuStorage {
170173
DType::I16 => Self::I16(data.iter().map(|x| x.to_f64() as i16).collect()),
171174
DType::U16 => Self::U16(data.iter().map(|x| x.to_f64() as u16).collect()),
172175
DType::U32 => Self::U32(data.iter().map(|x| x.to_f64() as u32).collect()),
176+
DType::U64 => Self::U64(data.iter().map(|x| x.to_u64()).collect()),
173177
DType::I32 => Self::I32(data.iter().map(|x| x.to_f64() as i32).collect()),
174178
DType::I64 => Self::I64(data.iter().map(|x| x.to_i64()).collect()),
175179
DType::F16 => Self::F16(data.iter().map(|x| f16::from_f32(x.to_f32())).collect()),
@@ -188,6 +192,7 @@ impl CpuStorage {
188192
DType::I16 => Self::I16(vec![val as i16; numel]),
189193
DType::U16 => Self::U16(vec![val as u16; numel]),
190194
DType::U32 => Self::U32(vec![val as u32; numel]),
195+
DType::U64 => Self::U64(vec![val as u64; numel]),
191196
DType::I32 => Self::I32(vec![val as i32; numel]),
192197
DType::I64 => Self::I64(vec![val as i64; numel]),
193198
DType::F16 => Self::F16(vec![f16::from_f32(val as f32); numel]),
@@ -247,6 +252,7 @@ impl CpuStorage {
247252
Self::I16(v) => extract!(v, |&x: &i16| T::from_f64(x as f64)),
248253
Self::U16(v) => extract!(v, |&x: &u16| T::from_f64(x as f64)),
249254
Self::U32(v) => extract!(v, |&x: &u32| T::from_f64(x as f64)),
255+
Self::U64(v) => extract!(v, |&x: &u64| T::from_u64(x)),
250256
Self::I32(v) => extract!(v, |&x: &i32| T::from_f64(x as f64)),
251257
Self::I64(v) => extract!(v, |&x: &i64| T::from_i64(x)),
252258
Self::F16(v) => extract!(v, |&x: &f16| T::from_f32(x.to_f32())),
@@ -322,6 +328,7 @@ impl CpuStorage {
322328
Self::I16(v) => copy_typed!(I16, v),
323329
Self::U16(v) => copy_typed!(U16, v),
324330
Self::U32(v) => copy_typed!(U32, v),
331+
Self::U64(v) => copy_typed!(U64, v),
325332
Self::I32(v) => copy_typed!(I32, v),
326333
Self::I64(v) => copy_typed!(I64, v),
327334
Self::F16(v) => copy_typed!(F16, v),
@@ -342,6 +349,7 @@ impl CpuStorage {
342349
DType::I16 => Ok(Self::I16(self.to_vec::<i16>(layout))),
343350
DType::U16 => Ok(Self::U16(self.to_vec::<u16>(layout))),
344351
DType::U32 => Ok(Self::U32(self.to_vec::<u32>(layout))),
352+
DType::U64 => Ok(Self::U64(self.to_vec::<u64>(layout))),
345353
DType::I32 => Ok(Self::I32(self.to_vec::<i32>(layout))),
346354
DType::I64 => Ok(Self::I64(self.to_vec::<i64>(layout))),
347355
DType::F16 => Ok(Self::F16(self.to_vec::<f16>(layout))),
@@ -386,6 +394,7 @@ impl CpuStorage {
386394
Self::I16(v) => scatter_typed!(I16, v, 0i16, |a: &mut i16, b: i16| *a = a.wrapping_add(b)),
387395
Self::U16(v) => scatter_typed!(U16, v, 0u16, |a: &mut u16, b: u16| *a = a.wrapping_add(b)),
388396
Self::U32(v) => scatter_typed!(U32, v, 0u32, |a: &mut u32, b: u32| *a = a.wrapping_add(b)),
397+
Self::U64(v) => scatter_typed!(U64, v, 0u64, |a: &mut u64, b: u64| *a = a.wrapping_add(b)),
389398
Self::I32(v) => {
390399
scatter_typed!(I32, v, 0i32, |a: &mut i32, b: i32| *a = a.wrapping_add(b))
391400
}
@@ -476,6 +485,7 @@ impl CpuStorage {
476485
Self::I16(v) => run_unary!(I16, v, |x: i16| eval_unary_f64(x as f64, op) as i64 as i16),
477486
Self::U16(v) => run_unary!(U16, v, |x: u16| eval_unary_f64(x as f64, op) as i64 as u16),
478487
Self::U32(v) => run_unary!(U32, v, |x: u32| eval_unary_f64(x as f64, op) as i64 as u32),
488+
Self::U64(v) => run_unary!(U64, v, |x: u64| eval_unary_f64(x as f64, op) as i64 as u64),
479489
Self::Bool(_) => Err(Error::UnsupportedDType {
480490
op: "unary_op",
481491
dtype: DType::Bool,
@@ -514,7 +524,7 @@ impl CpuStorage {
514524
// Integer division by zero is an error, not a panic. Only denominators
515525
// inside the (pre-broadcast) view count. MIN/-1 keeps wrapping
516526
// semantics via wrapping_div below (the wrapped quotient is MIN).
517-
if matches!(op, BinaryOp::Div | BinaryOp::Fmod | BinaryOp::Remainder | BinaryOp::FloorDiv) && matches!(self, Self::I32(_) | Self::I64(_) | Self::U8(_) | Self::I8(_) | Self::I16(_) | Self::U16(_) | Self::U32(_))
527+
if matches!(op, BinaryOp::Div | BinaryOp::Fmod | BinaryOp::Remainder | BinaryOp::FloorDiv) && matches!(self, Self::I32(_) | Self::I64(_) | Self::U8(_) | Self::I8(_) | Self::I16(_) | Self::U16(_) | Self::U32(_) | Self::U64(_))
518528
{
519529
let denoms = rhs.to_vec::<i64>(rhs_l);
520530
if denoms.contains(&0) {
@@ -523,7 +533,7 @@ impl CpuStorage {
523533
}
524534
// Integer pow is exact: negative exponents have no integer value and
525535
// silently saturated/wrapped huge powers hid bugs, so both are errors.
526-
if matches!(op, BinaryOp::Pow) && matches!(self, Self::I32(_) | Self::I64(_) | Self::U8(_) | Self::I8(_) | Self::I16(_) | Self::U16(_) | Self::U32(_))
536+
if matches!(op, BinaryOp::Pow) && matches!(self, Self::I32(_) | Self::I64(_) | Self::U8(_) | Self::I8(_) | Self::I16(_) | Self::U16(_) | Self::U32(_) | Self::U64(_))
527537
{
528538
let bases = self.to_vec::<i64>(lhs_l);
529539
let exps = rhs.to_vec::<i64>(rhs_l);
@@ -535,6 +545,7 @@ impl CpuStorage {
535545
Self::I16(_) => (i16::MIN as i128, i16::MAX as i128),
536546
Self::U16(_) => (0, u16::MAX as i128),
537547
Self::U32(_) => (0, u32::MAX as i128),
548+
Self::U64(_) => (0, u64::MAX as i128),
538549
_ => unreachable!("guarded by the outer matches"),
539550
};
540551
for (&b, &e) in bases.iter().zip(exps.iter()) {
@@ -855,6 +866,17 @@ impl CpuStorage {
855866
BinaryOp::Fmod | BinaryOp::Remainder => x % y,
856867
BinaryOp::FloorDiv => x / y,
857868
}),
869+
(Self::U64(a), Self::U64(b)) => run_bin!(U64, a, b, |x: u64, y: u64| match op {
870+
BinaryOp::Add => x.wrapping_add(y),
871+
BinaryOp::Sub => x.wrapping_sub(y),
872+
BinaryOp::Mul => x.wrapping_mul(y),
873+
BinaryOp::Div => x.wrapping_div(y),
874+
BinaryOp::Maximum => x.max(y),
875+
BinaryOp::Minimum => x.min(y),
876+
BinaryOp::Pow => int_pow_kernel(x as i64, y as i64) as u64,
877+
BinaryOp::Fmod | BinaryOp::Remainder => x % y,
878+
BinaryOp::FloorDiv => x / y,
879+
}),
858880
(Self::Bool(a), Self::Bool(b)) => run_bin!(Bool, a, b, |x: bool, y: bool| match op {
859881
BinaryOp::Add | BinaryOp::Maximum => x || y,
860882
BinaryOp::Mul | BinaryOp::Minimum => x && y,
@@ -1119,6 +1141,9 @@ impl CpuStorage {
11191141
(Self::U32(a), Self::U32(b)) => {
11201142
run_cmp!(a, b, |x: u32, y: u32| eval_cmp(x, y, op))
11211143
}
1144+
(Self::U64(a), Self::U64(b)) => {
1145+
run_cmp!(a, b, |x: u64, y: u64| eval_cmp(x, y, op))
1146+
}
11221147
(Self::Bool(a), Self::Bool(b)) => {
11231148
run_cmp!(a, b, |x: bool, y: bool| eval_cmp(x, y, op))
11241149
}
@@ -1181,6 +1206,7 @@ impl CpuStorage {
11811206
(Self::I16(a), Self::I16(b)) => bit_typed!(I16, a, b),
11821207
(Self::U16(a), Self::U16(b)) => bit_typed!(U16, a, b),
11831208
(Self::U32(a), Self::U32(b)) => bit_typed!(U32, a, b),
1209+
(Self::U64(a), Self::U64(b)) => bit_typed!(U64, a, b),
11841210
(Self::I32(a), Self::I32(b)) => bit_typed!(I32, a, b),
11851211
(Self::I64(a), Self::I64(b)) => bit_typed!(I64, a, b),
11861212
_ => Err(Error::UnsupportedDType {
@@ -1260,6 +1286,7 @@ impl CpuStorage {
12601286
Self::I16(v) => not_typed!(I16, v),
12611287
Self::U16(v) => not_typed!(U16, v),
12621288
Self::U32(v) => not_typed!(U32, v),
1289+
Self::U64(v) => not_typed!(U64, v),
12631290
Self::I32(v) => not_typed!(I32, v),
12641291
Self::I64(v) => not_typed!(I64, v),
12651292
_ => Err(Error::UnsupportedDType {
@@ -1316,6 +1343,7 @@ impl CpuStorage {
13161343
Self::I16(_) => select_typed!(I16, i16),
13171344
Self::U16(_) => select_typed!(U16, u16),
13181345
Self::U32(_) => select_typed!(U32, u32),
1346+
Self::U64(_) => select_typed!(U64, u64),
13191347
Self::I32(_) => select_typed!(I32, i32),
13201348
Self::I64(_) => select_typed!(I64, i64),
13211349
Self::F16(_) => select_typed!(F16, f16),
@@ -1386,6 +1414,9 @@ impl CpuStorage {
13861414
(Self::U32(_), Self::U32(_)) => {
13871415
add_typed!(U32, u32, |a: &mut u32, b: u32| *a = a.wrapping_add(b))
13881416
}
1417+
(Self::U64(_), Self::U64(_)) => {
1418+
add_typed!(U64, u64, |a: &mut u64, b: u64| *a = a.wrapping_add(b))
1419+
}
13891420
(Self::I32(_), Self::I32(_)) => {
13901421
add_typed!(I32, i32, |a: &mut i32, b: i32| *a = a.wrapping_add(b))
13911422
}
@@ -1461,6 +1492,7 @@ impl CpuStorage {
14611492
Self::I16(_) => gather_typed!(I16, i16),
14621493
Self::U16(_) => gather_typed!(U16, u16),
14631494
Self::U32(_) => gather_typed!(U32, u32),
1495+
Self::U64(_) => gather_typed!(U64, u64),
14641496
Self::I32(_) => gather_typed!(I32, i32),
14651497
Self::I64(_) => gather_typed!(I64, i64),
14661498
Self::F16(_) => gather_typed!(F16, f16),
@@ -1539,6 +1571,9 @@ impl CpuStorage {
15391571
(Self::U32(_), Self::U32(_)) => {
15401572
scatter_typed!(U32, u32, |a: &mut u32, b: u32| *a = a.wrapping_add(b))
15411573
}
1574+
(Self::U64(_), Self::U64(_)) => {
1575+
scatter_typed!(U64, u64, |a: &mut u64, b: u64| *a = a.wrapping_add(b))
1576+
}
15421577
(Self::I32(_), Self::I32(_)) => {
15431578
scatter_typed!(I32, i32, |a: &mut i32, b: i32| *a = a.wrapping_add(b))
15441579
}
@@ -1626,6 +1661,7 @@ impl CpuStorage {
16261661
(Self::I16(_), Self::I16(_)) => scatter_write!(I16, i16),
16271662
(Self::U16(_), Self::U16(_)) => scatter_write!(U16, u16),
16281663
(Self::U32(_), Self::U32(_)) => scatter_write!(U32, u32),
1664+
(Self::U64(_), Self::U64(_)) => scatter_write!(U64, u64),
16291665
(Self::I32(_), Self::I32(_)) => scatter_write!(I32, i32),
16301666
(Self::I64(_), Self::I64(_)) => scatter_write!(I64, i64),
16311667
(Self::F16(_), Self::F16(_)) => scatter_write!(F16, f16),
@@ -1681,6 +1717,7 @@ impl CpuStorage {
16811717
(Self::I16(tv), Self::I16(fv)) => select_typed!(I16, tv, fv),
16821718
(Self::U16(tv), Self::U16(fv)) => select_typed!(U16, tv, fv),
16831719
(Self::U32(tv), Self::U32(fv)) => select_typed!(U32, tv, fv),
1720+
(Self::U64(tv), Self::U64(fv)) => select_typed!(U64, tv, fv),
16841721
(Self::I32(tv), Self::I32(fv)) => select_typed!(I32, tv, fv),
16851722
(Self::I64(tv), Self::I64(fv)) => select_typed!(I64, tv, fv),
16861723
(Self::F16(tv), Self::F16(fv)) => select_typed!(F16, tv, fv),

‎crates/oxideon-core/src/dtype.rs‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum DType {
1414
U16,
1515
I32,
1616
U32,
17+
U64,
1718
I64,
1819
F16,
1920
BF16,
@@ -28,7 +29,7 @@ impl DType {
2829
Self::Bool | Self::U8 | Self::I8 => 1,
2930
Self::F16 | Self::BF16 | Self::I16 | Self::U16 => 2,
3031
Self::I32 | Self::U32 | Self::F32 => 4,
31-
Self::I64 | Self::F64 => 8,
32+
Self::I64 | Self::U64 | Self::F64 => 8,
3233
}
3334
}
3435

@@ -41,7 +42,7 @@ impl DType {
4142
}
4243

4344
pub const fn is_int(self) -> bool {
44-
matches!(self, Self::U8 | Self::I8 | Self::I16 | Self::U16 | Self::I32 | Self::U32 | Self::I64)
45+
matches!(self, Self::U8 | Self::I8 | Self::I16 | Self::U16 | Self::I32 | Self::U32 | Self::U64 | Self::I64)
4546
}
4647

4748
/// Standard safetensors dtype string.
@@ -53,6 +54,7 @@ impl DType {
5354
Self::I16 => "I16",
5455
Self::U16 => "U16",
5556
Self::U32 => "U32",
57+
Self::U64 => "U64",
5658
Self::I32 => "I32",
5759
Self::I64 => "I64",
5860
Self::F16 => "F16",
@@ -70,6 +72,7 @@ impl DType {
7072
"I16" => Ok(Self::I16),
7173
"U16" => Ok(Self::U16),
7274
"U32" => Ok(Self::U32),
75+
"U64" => Ok(Self::U64),
7376
"I32" => Ok(Self::I32),
7477
"I64" => Ok(Self::I64),
7578
"F16" => Ok(Self::F16),
@@ -92,6 +95,7 @@ impl fmt::Display for DType {
9295
Self::I16 => "i16",
9396
Self::U16 => "u16",
9497
Self::U32 => "u32",
98+
Self::U64 => "u64",
9599
Self::I32 => "i32",
96100
Self::I64 => "i64",
97101
Self::F16 => "f16",
@@ -318,6 +322,14 @@ pub trait Element: Copy + Default + Send + Sync + 'static + fmt::Debug + fmt::Di
318322
fn to_i64(self) -> i64 {
319323
self.to_f64() as i64
320324
}
325+
/// Conversion from `u64`; the default goes through `f64`, which is exact only up to 2^53.
326+
fn from_u64(v: u64) -> Self {
327+
Self::from_f64(v as f64)
328+
}
329+
/// Conversion to `u64`; the default goes through `f64`, which is exact only up to 2^53.
330+
fn to_u64(self) -> u64 {
331+
self.to_f64() as u64
332+
}
321333
}
322334

323335
impl Element for bool {
@@ -417,6 +429,34 @@ impl Element for u32 {
417429
v as u32
418430
}
419431
}
432+
impl Element for u64 {
433+
const DTYPE: DType = DType::U64;
434+
#[inline]
435+
fn from_f64(v: f64) -> Self {
436+
// Torch routes float -> small integer through i64 (truncate, then wrap the low bits).
437+
if v >= 9.223_372_036_854_775_8e18 { v as u64 } else { float_to_i64_torch(v) as u64 }
438+
}
439+
#[inline]
440+
fn to_f64(self) -> f64 {
441+
self as f64
442+
}
443+
#[inline]
444+
fn from_i64(v: i64) -> Self {
445+
v as u64
446+
}
447+
#[inline]
448+
fn to_i64(self) -> i64 {
449+
self as i64
450+
}
451+
#[inline]
452+
fn from_u64(v: u64) -> Self {
453+
v
454+
}
455+
#[inline]
456+
fn to_u64(self) -> u64 {
457+
self
458+
}
459+
}
420460

421461
impl Element for i32 {
422462
const DTYPE: DType = DType::I32;
@@ -454,6 +494,14 @@ impl Element for i64 {
454494
fn to_i64(self) -> i64 {
455495
self
456496
}
497+
#[inline]
498+
fn from_u64(v: u64) -> Self {
499+
v as i64
500+
}
501+
#[inline]
502+
fn to_u64(self) -> u64 {
503+
self as u64
504+
}
457505
}
458506

459507
impl Element for f16 {

‎crates/oxideon-core/src/ops.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ impl Tensor {
22582258
DType::I16 => stitch!(I16, i16),
22592259
DType::U16 => stitch!(U16, u16),
22602260
DType::U32 => stitch!(U32, u32),
2261+
DType::U64 => stitch!(U64, u64),
22612262
DType::I32 => stitch!(I32, i32),
22622263
DType::I64 => stitch!(I64, i64),
22632264
DType::F16 => stitch!(F16, f16),

‎crates/oxideon-core/src/serialize/npy.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn descr_of(dtype: DType) -> Result<&'static str> {
3434
DType::I16 => "<i2",
3535
DType::U16 => "<u2",
3636
DType::U32 => "<u4",
37+
DType::U64 => "<u8",
3738
DType::Bool => "|b1",
3839
DType::BF16 => return Err(err("bfloat16 has no NumPy dtype; cast to f32 before saving")),
3940
})
@@ -68,6 +69,7 @@ pub fn npy_bytes(t: &Tensor) -> Result<Vec<u8>> {
6869
DType::I16 => t.to_vec::<i16>()?.iter().for_each(|v| out.extend_from_slice(&v.to_le_bytes())),
6970
DType::U16 => t.to_vec::<u16>()?.iter().for_each(|v| out.extend_from_slice(&v.to_le_bytes())),
7071
DType::U32 => t.to_vec::<u32>()?.iter().for_each(|v| out.extend_from_slice(&v.to_le_bytes())),
72+
DType::U64 => t.to_vec::<u64>()?.iter().for_each(|v| out.extend_from_slice(&v.to_le_bytes())),
7173
DType::Bool => out.extend(t.to_vec::<bool>()?.into_iter().map(u8::from)),
7274
DType::BF16 => unreachable!("rejected above"),
7375
}
@@ -203,7 +205,7 @@ pub fn from_npy_bytes(bytes: &[u8]) -> Result<Tensor> {
203205
(b'u', 1) => Tensor::from_slice(&data[..count], &h.shape)?,
204206
(b'u', 2) => Tensor::from_slice(&(0..count).map(|i| { let c = chunk(i); u16::from_le_bytes([c[0], c[1]]) }).collect::<Vec<_>>(), &h.shape)?,
205207
(b'u', 4) => Tensor::from_slice(&(0..count).map(|i| u32::from_le_bytes(chunk(i).try_into().unwrap())).collect::<Vec<_>>(), &h.shape)?,
206-
(b'u', 8) => Tensor::from_slice(&(0..count).map(|i| u64::from_le_bytes(chunk(i).try_into().unwrap()) as i64).collect::<Vec<_>>(), &h.shape)?,
208+
(b'u', 8) => Tensor::from_slice(&(0..count).map(|i| u64::from_le_bytes(chunk(i).try_into().unwrap())).collect::<Vec<_>>(), &h.shape)?,
207209
(b'b', 1) => Tensor::from_slice(&data[..count].iter().map(|&b| b != 0).collect::<Vec<_>>(), &h.shape)?,
208210
_ => return Err(err(format!("unsupported npy dtype '{}'", h.descr))),
209211
};

‎crates/oxideon-core/src/serialize/safetensors.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ fn tensor_to_le_bytes(t: &Tensor) -> Result<Vec<u8>> {
174174
CpuStorage::I16(v) => v.into_iter().for_each(|x| out.extend_from_slice(&x.to_le_bytes())),
175175
CpuStorage::U16(v) => v.into_iter().for_each(|x| out.extend_from_slice(&x.to_le_bytes())),
176176
CpuStorage::U32(v) => v.into_iter().for_each(|x| out.extend_from_slice(&x.to_le_bytes())),
177+
CpuStorage::U64(v) => v.into_iter().for_each(|x| out.extend_from_slice(&x.to_le_bytes())),
177178
CpuStorage::I32(v) => {
178179
if cfg!(target_endian = "little") {
179180
out.extend_from_slice(as_le_bytes(&v));
@@ -251,6 +252,7 @@ fn tensor_from_le_bytes(dtype: DType, shape: Vec<usize>, raw: &[u8]) -> Result<T
251252
DType::I16 => CpuStorage::I16(raw.chunks_exact(2).map(|c| i16::from_le_bytes(c.try_into().unwrap())).collect()),
252253
DType::U16 => CpuStorage::U16(raw.chunks_exact(2).map(|c| u16::from_le_bytes(c.try_into().unwrap())).collect()),
253254
DType::U32 => CpuStorage::U32(raw.chunks_exact(4).map(|c| u32::from_le_bytes(c.try_into().unwrap())).collect()),
255+
DType::U64 => CpuStorage::U64(raw.chunks_exact(8).map(|c| u64::from_le_bytes(c.try_into().unwrap())).collect()),
254256
DType::I32 => CpuStorage::I32(vec_from_le_bytes(raw)),
255257
DType::I64 => CpuStorage::I64(vec_from_le_bytes(raw)),
256258
DType::F16 => CpuStorage::F16(vec_from_le_bytes(raw)),
@@ -271,6 +273,7 @@ fn tensor_from_le_bytes(dtype: DType, shape: Vec<usize>, raw: &[u8]) -> Result<T
271273
DType::I16 => CpuStorage::I16(raw.chunks_exact(2).map(|c| i16::from_le_bytes(c.try_into().unwrap())).collect()),
272274
DType::U16 => CpuStorage::U16(raw.chunks_exact(2).map(|c| u16::from_le_bytes(c.try_into().unwrap())).collect()),
273275
DType::U32 => CpuStorage::U32(raw.chunks_exact(4).map(|c| u32::from_le_bytes(c.try_into().unwrap())).collect()),
276+
DType::U64 => CpuStorage::U64(raw.chunks_exact(8).map(|c| u64::from_le_bytes(c.try_into().unwrap())).collect()),
274277
DType::I32 => CpuStorage::I32(
275278
raw.chunks_exact(4)
276279
.map(|c| i32::from_le_bytes(c.try_into().unwrap()))

0 commit comments

Comments
 (0)