Skip to content

Commit 069640b

Browse files
committed
style: cargo fmt the W1a/W2 additions (rustfmt 1.95.0)
Formatting-only; fixes the format/stable CI on #203. No logic change. https://claude.ai/code/session_017GFLBnDy23AWBqvkbHHC41
1 parent 6f267ae commit 069640b

5 files changed

Lines changed: 46 additions & 38 deletions

File tree

src/hpc/activations.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,8 @@ fn log_softmax_f32_scalar(x: ArrayView1<f32>, mut out: ArrayViewMut1<f32>) {
388388
/// assert!((out[[1, 0]] - 1.0 / 3.0).abs() < 1e-5);
389389
/// ```
390390
pub fn softmax_axis_f32(x: ArrayView2<f32>, mut out: ArrayViewMut2<f32>, axis: Axis) {
391-
assert!(
392-
axis.index() < 2,
393-
"softmax_axis_f32: axis {} is out of bounds for a 2-D array",
394-
axis.index()
395-
);
396-
assert_eq!(
397-
x.shape(),
398-
out.shape(),
399-
"softmax_axis_f32: shape mismatch (x={:?} out={:?})",
400-
x.shape(),
401-
out.shape()
402-
);
391+
assert!(axis.index() < 2, "softmax_axis_f32: axis {} is out of bounds for a 2-D array", axis.index());
392+
assert_eq!(x.shape(), out.shape(), "softmax_axis_f32: shape mismatch (x={:?} out={:?})", x.shape(), out.shape());
403393
// `lanes(axis)` yields 1-D views ALONG `axis`; `lanes_mut(axis)` yields
404394
// the corresponding mutable 1-D views of `out`. Zipping them visits every
405395
// lane exactly once.
@@ -450,11 +440,7 @@ pub fn softmax_axis_f32(x: ArrayView2<f32>, mut out: ArrayViewMut2<f32>, axis: A
450440
/// assert!((out[[1, 2]] - expected).abs() < 1e-5);
451441
/// ```
452442
pub fn log_softmax_axis_f32(x: ArrayView2<f32>, mut out: ArrayViewMut2<f32>, axis: Axis) {
453-
assert!(
454-
axis.index() < 2,
455-
"log_softmax_axis_f32: axis {} is out of bounds for a 2-D array",
456-
axis.index()
457-
);
443+
assert!(axis.index() < 2, "log_softmax_axis_f32: axis {} is out of bounds for a 2-D array", axis.index());
458444
assert_eq!(
459445
x.shape(),
460446
out.shape(),
@@ -776,7 +762,13 @@ mod tests {
776762
softmax_f32(row.view(), out_1d.view_mut());
777763

778764
for j in 0..4 {
779-
assert!((out_axis[[0, j]] - out_1d[j]).abs() < 1e-6, "j={}: axis={} vs 1d={}", j, out_axis[[0, j]], out_1d[j]);
765+
assert!(
766+
(out_axis[[0, j]] - out_1d[j]).abs() < 1e-6,
767+
"j={}: axis={} vs 1d={}",
768+
j,
769+
out_axis[[0, j]],
770+
out_1d[j]
771+
);
780772
}
781773
}
782774

@@ -850,7 +842,10 @@ mod tests {
850842
assert!(
851843
(out_axis[[i, j]] - out_1d[j]).abs() < 1e-5,
852844
"row={} j={}: axis={} vs 1d={}",
853-
i, j, out_axis[[i, j]], out_1d[j]
845+
i,
846+
j,
847+
out_axis[[i, j]],
848+
out_1d[j]
854849
);
855850
}
856851
}

src/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ pub use crate::simd_avx512::{
252252
u32x8,
253253
u64x4,
254254
u64x8,
255-
u8x8,
256255
u8x64,
256+
u8x8,
257257
F32Mask16,
258258
// 512-bit (native AVX-512, __m512/__m512d/__m512i)
259259
F32x16,

src/simd_avx512.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,12 @@ impl U16x8 {
25292529
// Bounds validation: debug panics, release falls back to safe get()
25302530
#[cfg(debug_assertions)]
25312531
for &i in &idx {
2532-
assert!((i as usize) < table.len(), "gather_u16: index {} out of bounds (table.len() = {})", i, table.len());
2532+
assert!(
2533+
(i as usize) < table.len(),
2534+
"gather_u16: index {} out of bounds (table.len() = {})",
2535+
i,
2536+
table.len()
2537+
);
25332538
}
25342539
let mut out = [0u16; 8];
25352540
for k in 0..8 {
@@ -2623,10 +2628,8 @@ impl I8x32 {
26232628
let raw_abs = core::arch::x86_64::_mm256_abs_epi8(self.0);
26242629
// VPMINUB: unsigned-byte minimum. 0x80 unsigned = 128 > 0x7f = 127
26252630
// so min(0x80, 0x7f) = 0x7f. All values < 0x80 pass through.
2626-
let clamped = core::arch::x86_64::_mm256_min_epu8(
2627-
raw_abs,
2628-
core::arch::x86_64::_mm256_set1_epi8(0x7f_u8 as i8),
2629-
);
2631+
let clamped =
2632+
core::arch::x86_64::_mm256_min_epu8(raw_abs, core::arch::x86_64::_mm256_set1_epi8(0x7f_u8 as i8));
26302633
I8x32(clamped)
26312634
}
26322635
#[cfg(not(target_arch = "x86_64"))]
@@ -2688,15 +2691,19 @@ impl U64x8 {
26882691
{
26892692
let arr = self.to_array();
26902693
let mut out = [0u64; 8];
2691-
for i in 0..8 { out[i] = arr[i].count_ones() as u64; }
2694+
for i in 0..8 {
2695+
out[i] = arr[i].count_ones() as u64;
2696+
}
26922697
U64x8::from_array(out)
26932698
}
26942699
#[cfg(not(target_arch = "x86_64"))]
26952700
{
26962701
// Scalar fallback (unreachable in practice for this backend file).
26972702
let arr = self.to_array();
26982703
let mut out = [0u64; 8];
2699-
for i in 0..8 { out[i] = arr[i].count_ones() as u64; }
2704+
for i in 0..8 {
2705+
out[i] = arr[i].count_ones() as u64;
2706+
}
27002707
U64x8::from_array(out)
27012708
}
27022709
}
@@ -2731,7 +2738,9 @@ impl U64x8 {
27312738
let a = self.to_array();
27322739
let b = other.to_array();
27332740
let mut sum = 0u64;
2734-
for i in 0..8 { sum += (a[i] ^ b[i]).count_ones() as u64; }
2741+
for i in 0..8 {
2742+
sum += (a[i] ^ b[i]).count_ones() as u64;
2743+
}
27352744
sum
27362745
}
27372746
}

src/simd_int_ops.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,18 +905,14 @@ mod tests {
905905
let packed = vec![0u64; 4];
906906
let aux = vec![0i8; 4];
907907
let mut out = vec![0i8; 4];
908-
batch_packed_i4_16(&packed, &aux, &mut out, |lanes, a| {
909-
lanes.lane_i8::<0>().wrapping_add(a)
910-
});
908+
batch_packed_i4_16(&packed, &aux, &mut out, |lanes, a| lanes.lane_i8::<0>().wrapping_add(a));
911909
assert!(out.iter().all(|&v| v == 0), "batch_packed_i4_16 all-zero");
912910

913911
// Non-zero nibbles
914912
let packed2 = vec![0x1111_1111_1111_1111u64; 2];
915913
let aux2 = vec![10i8; 2];
916914
let mut out2 = vec![0i8; 2];
917-
batch_packed_i4_16(&packed2, &aux2, &mut out2, |lanes, a| {
918-
lanes.lane_i8::<0>().wrapping_add(a)
919-
});
915+
batch_packed_i4_16(&packed2, &aux2, &mut out2, |lanes, a| lanes.lane_i8::<0>().wrapping_add(a));
920916
// nibble 0x1 → lane 0 = +1; +10 = 11
921917
assert!(out2.iter().all(|&v| v == 11), "batch_packed_i4_16 nibble=1+aux=10");
922918
}

src/simd_scalar.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,9 @@ impl I8x32 {
13951395
#[inline(always)]
13961396
pub fn saturating_abs(self) -> Self {
13971397
let mut o = [0i8; 32];
1398-
for i in 0..32 { o[i] = self.0[i].saturating_abs(); }
1398+
for i in 0..32 {
1399+
o[i] = self.0[i].saturating_abs();
1400+
}
13991401
Self(o)
14001402
}
14011403
}
@@ -1572,7 +1574,9 @@ impl U64x8 {
15721574
#[inline(always)]
15731575
pub fn popcnt(self) -> Self {
15741576
let mut out = [0u64; 8];
1575-
for i in 0..8 { out[i] = self.0[i].count_ones() as u64; }
1577+
for i in 0..8 {
1578+
out[i] = self.0[i].count_ones() as u64;
1579+
}
15761580
Self(out)
15771581
}
15781582

@@ -1588,7 +1592,9 @@ impl U64x8 {
15881592
#[inline(always)]
15891593
pub fn xor_popcount(self, other: Self) -> u64 {
15901594
let mut sum = 0u64;
1591-
for i in 0..8 { sum += (self.0[i] ^ other.0[i]).count_ones() as u64; }
1595+
for i in 0..8 {
1596+
sum += (self.0[i] ^ other.0[i]).count_ones() as u64;
1597+
}
15921598
sum
15931599
}
15941600
}
@@ -1604,7 +1610,9 @@ impl U64x4 {
16041610
#[inline(always)]
16051611
pub fn popcnt(self) -> Self {
16061612
let mut out = [0u64; 4];
1607-
for i in 0..4 { out[i] = self.0[i].count_ones() as u64; }
1613+
for i in 0..4 {
1614+
out[i] = self.0[i].count_ones() as u64;
1615+
}
16081616
Self(out)
16091617
}
16101618
}

0 commit comments

Comments
 (0)