Skip to content

Commit

Permalink
Added imax/imin() as variations of iamax/iamin()
Browse files Browse the repository at this point in the history
  • Loading branch information
lovesegfault committed Jul 9, 2018
1 parent 3eaa65c commit 70d3de0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/base/blas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ use base::storage::{Storage, StorageMut};
use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector};

impl<N: Scalar + PartialOrd + Signed, D: Dim, S: Storage<N, D>> Vector<N, D, S> {

/// 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 {
Expand All @@ -34,6 +55,26 @@ impl<N: Scalar + PartialOrd + Signed, D: Dim, S: Storage<N, D>> Vector<N, D, S>
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 {
Expand Down

0 comments on commit 70d3de0

Please sign in to comment.