Add iamin.
This commit is contained in:
parent
fcfcc391b5
commit
dc41b55e5a
|
@ -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.
|
and to types of the [mint](https://crates.io/crates/mint) crate.
|
||||||
* The `::repeat(...)` constructor that is an alternative name to
|
* The `::repeat(...)` constructor that is an alternative name to
|
||||||
`::from_element(...)`.
|
`::from_element(...)`.
|
||||||
|
* The `.iamin()` methods that returns the index of the vector entry with
|
||||||
|
smallest absolute value.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,26 @@ impl<N: Scalar + PartialOrd + Signed, D: Dim, S: Storage<N, D>> Vector<N, D, S>
|
||||||
|
|
||||||
the_i
|
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<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||||
|
|
Loading…
Reference in New Issue