Add is_zero() to trait WeightNum
This commit is contained in:
parent
ed7c417013
commit
ba128c0c93
22
src/lib.rs
22
src/lib.rs
@ -27,16 +27,32 @@ use std::num::Zero;
|
|||||||
use coverage::Coverage;
|
use coverage::Coverage;
|
||||||
use mark_matrix::MarkMatrix;
|
use mark_matrix::MarkMatrix;
|
||||||
pub use weight_matrix::WeightMatrix;
|
pub use weight_matrix::WeightMatrix;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
pub mod square_matrix;
|
pub mod square_matrix;
|
||||||
mod coverage;
|
mod coverage;
|
||||||
mod mark_matrix;
|
mod mark_matrix;
|
||||||
pub mod weight_matrix;
|
pub mod weight_matrix;
|
||||||
|
|
||||||
pub trait WeightNum: PartialOrd + Copy + Sub<Output=Self> + Add<Output=Self> + Zero { }
|
pub trait WeightNum: PartialOrd + Copy + Sub<Output=Self> + Add<Output=Self> + Zero {
|
||||||
|
#[inline(always)]
|
||||||
|
fn is_zero(&self) -> bool {
|
||||||
|
self.partial_cmp(&Self::zero()) == Some(Ordering::Equal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> WeightNum for T
|
impl WeightNum for usize { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
where T: PartialOrd + Copy + Sub<Output=T> + Add<Output=T> + Zero { }
|
impl WeightNum for isize { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for u64 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for i64 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for u32 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for i32 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for u16 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for i16 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for u8 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for i8 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0 } }
|
||||||
|
impl WeightNum for f64 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0.0 } }
|
||||||
|
impl WeightNum for f32 { #[inline(always)] fn is_zero(&self) -> bool { *self == 0.0 } }
|
||||||
|
|
||||||
pub trait Weights {
|
pub trait Weights {
|
||||||
type T: WeightNum;
|
type T: WeightNum;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use std::cmp::Ordering;
|
|
||||||
use super::{WeightNum, Weights};
|
use super::{WeightNum, Weights};
|
||||||
use super::square_matrix::SquareMatrix;
|
use super::square_matrix::SquareMatrix;
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ impl<T: WeightNum> Weights for WeightMatrix<T> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_element_zero(&self, pos: (usize, usize)) -> bool {
|
fn is_element_zero(&self, pos: (usize, usize)) -> bool {
|
||||||
self.c[pos].partial_cmp(&T::zero()) == Some(Ordering::Equal)
|
self.c[pos].is_zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each row, subtracts the minimum of that row from each other value in the
|
// for each row, subtracts the minimum of that row from each other value in the
|
||||||
|
Loading…
Reference in New Issue
Block a user