Rename WeightNum#is_disallowed() to #is_valid()
This commit is contained in:
parent
a870cb4cc7
commit
fe2d4bb8af
@ -31,25 +31,19 @@ impl<T: WeightNum> Weights for WeightMatrix<T> {
|
|||||||
fn add_row(&mut self, row: usize, val: T) {
|
fn add_row(&mut self, row: usize, val: T) {
|
||||||
self.c
|
self.c
|
||||||
.row_mut(row)
|
.row_mut(row)
|
||||||
.mapv_inplace(|cur| if cur.is_disallowed() { cur } else { cur + val });
|
.mapv_inplace(|cur| if cur.is_valid() { cur + val } else { cur });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract `val` from every element in column `col`.
|
// Subtract `val` from every element in column `col`.
|
||||||
fn sub_column(&mut self, col: usize, val: T) {
|
fn sub_column(&mut self, col: usize, val: T) {
|
||||||
self.c.column_mut(col).mapv_inplace(
|
self.c
|
||||||
|cur| {
|
.column_mut(col)
|
||||||
if cur.is_disallowed() {
|
.mapv_inplace(|cur| if cur.is_valid() { cur - val } else { cur });
|
||||||
cur
|
|
||||||
} else {
|
|
||||||
cur - val
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_solvable(&self) -> bool {
|
fn is_solvable(&self) -> bool {
|
||||||
for row in 0..self.n() {
|
for row in 0..self.n() {
|
||||||
if self.c.row(row).iter().all(|c| c.is_disallowed()) {
|
if self.c.row(row).iter().all(|c| !c.is_valid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +70,7 @@ impl<T: WeightNum> WeightMatrix<T> {
|
|||||||
let row_slice = self.c.row(row);
|
let row_slice = self.c.row(row);
|
||||||
let mut min = row_slice[0];
|
let mut min = row_slice[0];
|
||||||
for &val in row_slice.iter().skip(1) {
|
for &val in row_slice.iter().skip(1) {
|
||||||
if !val.is_disallowed() && val < min {
|
if val.is_valid() && val < min {
|
||||||
min = val;
|
min = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +81,7 @@ impl<T: WeightNum> WeightMatrix<T> {
|
|||||||
fn sub_row(&mut self, row: usize, val: T) {
|
fn sub_row(&mut self, row: usize, val: T) {
|
||||||
self.c
|
self.c
|
||||||
.row_mut(row)
|
.row_mut(row)
|
||||||
.mapv_inplace(|cur| if cur.is_disallowed() { cur } else { cur - val });
|
.mapv_inplace(|cur| if cur.is_valid() { cur - val } else { cur });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_slice(&self) -> &[T] {
|
pub fn as_slice(&self) -> &[T] {
|
||||||
|
@ -3,8 +3,8 @@ use std::{f32, f64};
|
|||||||
|
|
||||||
pub trait WeightNum: PartialOrd + Copy + Sub<Output = Self> + Add<Output = Self> {
|
pub trait WeightNum: PartialOrd + Copy + Sub<Output = Self> + Add<Output = Self> {
|
||||||
fn is_zero(&self) -> bool;
|
fn is_zero(&self) -> bool;
|
||||||
fn is_disallowed(&self) -> bool {
|
fn is_valid(&self) -> bool {
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +84,9 @@ impl WeightNum for f64 {
|
|||||||
*self == 0.0
|
*self == 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_disallowed(&self) -> bool {
|
#[inline(always)]
|
||||||
*self == f64::INFINITY
|
fn is_valid(&self) -> bool {
|
||||||
|
self.is_finite()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +96,8 @@ impl WeightNum for f32 {
|
|||||||
*self == 0.0
|
*self == 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_disallowed(&self) -> bool {
|
#[inline(always)]
|
||||||
*self == f32::INFINITY
|
fn is_valid(&self) -> bool {
|
||||||
|
self.is_finite()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user