mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
2.5 KiB
2.5 KiB
name, slug, sourceRef, category, subCategory, similarHelpers, position, signatures
| name | slug | sourceRef | category | subCategory | similarHelpers | position | signatures | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mean | mean | exp/simd/math_avx.go#L352 | exp | simd |
|
10 |
|
Calculates the arithmetic mean of a collection using SIMD instructions. The suffix (x2, x4, x8, x16, x32, x64) indicates the number of lanes processed simultaneously.
Note
: Choose the variant matching your CPU's capabilities. Higher lane counts provide better performance but require newer CPU support.
// Using AVX2 variant (32 lanes at once) - Intel Haswell+ / AMD Excavator+
mean := simd.MeanInt8x32([]int8{1, 2, 3, 4, 5})
// 3
// Using AVX-512 variant (16 lanes at once) - Intel Skylake-X+
mean := simd.MeanFloat32x16([]float32{1.0, 2.0, 3.0, 4.0})
// 2.5
// Using AVX variant (8 lanes at once) - works on all amd64
mean := simd.MeanInt16x8([]int16{10, 20, 30, 40})
// 25
// Empty collection returns 0
mean := simd.MeanUint32x4([]uint32{})
// 0