ArgMinMax
Efficient argmin & argmax (in 1 function) with SIMD (SSE, AVX(2), AVX512, NEON) for
f16
,f32
,f64
,i8
,i16
,i32
,i64
,u8
,u16
,u32
,u64
.
&[T]
or Vec<T>
where T
can be f16
1, f32
, f64
, i8
, i16
, i32
, i64
, u8
, u16
, u32
, u64
.
slice
, Vec
, 1D ndarray::ArrayBase
2, and apache arrow::PrimitiveArray
3.
1 for
f16
you should enable the"half"
feature.
2 forndarray::ArrayBase
you should enable the"ndarray"
feature.
3 forarrow::PrimitiveArray
you should enable the"arrow"
feature.
Installing
Add the following to your Cargo.toml
:
[dependencies]
argminmax = "0.4"
Example usage
use argminmax::ArgMinMax; // import trait
let arr: Vec<i32> = (0..200_000).collect(); // create a vector
let (min, max) = arr.argminmax(); // apply extension
println!("min: {}, max: {}", min, max);
println!("arr[min]: {}, arr[max]: {}", arr[min], arr[max]);
Features
- "half": support
f16
argminmax (through using thehalf
crate). - "ndarray": add
ArgMinMax
trait tondarray
itsArray1
&ArrayView1
.
Benchmarks
Benchmarks on my laptop (AMD Ryzen 7 4800U, 1.8 GHz, 16GB RAM) using criterion show that the function is 3-20x faster than the scalar implementation (depending of data type).
See /benches/results
.
Run the benchmarks yourself with the following command:
cargo bench --quiet --message-format=short --features half | grep "time:"
Tests
To run the tests use the following command:
cargo test --message-format=short --all-features
Limitations
Acknowledgements
Some parts of this library are inspired by the great work of minimalrust's argmm project.