diff --git a/CHANGELOG.md b/CHANGELOG.md index 758f884f..2fe62236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). and to types of the [mint](https://crates.io/crates/mint) crate. * The `::repeat(...)` constructor that is an alternative name to `::from_element(...)`. + * The `.iamin()` methods that returns the index of the vector entry with + smallest absolute value. diff --git a/src/core/blas.rs b/src/core/blas.rs index 517e7793..65dbe7e8 100644 --- a/src/core/blas.rs +++ b/src/core/blas.rs @@ -31,6 +31,26 @@ impl> Vector the_i } + + /// Computes the index of the vector component with the smallest absolute value. + #[inline] + pub fn iamin(&self) -> usize { + assert!(!self.is_empty(), "The input vector must not be empty."); + + let mut the_max = unsafe { self.vget_unchecked(0).abs() }; + let mut the_i = 0; + + for i in 1 .. self.nrows() { + let val = unsafe { self.vget_unchecked(i).abs() }; + + if val < the_max { + the_max = val; + the_i = i; + } + } + + the_i + } } impl> Matrix {