diff --git a/src/base/blas.rs b/src/base/blas.rs index 982bbdbf..3c04b8e0 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -14,6 +14,27 @@ use base::storage::{Storage, StorageMut}; use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector}; impl> Vector { + + /// Computes the index of the vector component with the largest value. + #[inline] + pub fn imax(&self) -> usize { + assert!(!self.is_empty(), "The input vector must not be empty."); + + let mut the_max = unsafe { self.vget_unchecked(0) }; + let mut the_i = 0; + + for i in 1..self.nrows() { + let val = unsafe { self.vget_unchecked(i) }; + + if val > the_max { + the_max = val; + the_i = i; + } + } + + the_i + } + /// Computes the index of the vector component with the largest absolute value. #[inline] pub fn iamax(&self) -> usize { @@ -34,6 +55,26 @@ impl> Vector the_i } + /// Computes the index of the vector component with the smallest value. + #[inline] + pub fn imin(&self) -> usize { + assert!(!self.is_empty(), "The input vector must not be empty."); + + let mut the_max = unsafe { self.vget_unchecked(0) }; + let mut the_i = 0; + + for i in 1..self.nrows() { + let val = unsafe { self.vget_unchecked(i) }; + + if val < the_max { + the_max = val; + the_i = i; + } + } + + the_i + } + /// Computes the index of the vector component with the smallest absolute value. #[inline] pub fn iamin(&self) -> usize {