Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various refactorings #1470

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
refactoring
adamnemecek committed Jan 5, 2025
commit 6b569f24cfaadfacefe852f4b5142acf65bf8ba7
49 changes: 16 additions & 33 deletions nalgebra-sparse/src/io/matrix_market.rs
Original file line number Diff line number Diff line change
@@ -237,9 +237,9 @@ pub enum MatrixMarketErrorKind {
}

impl MatrixMarketError {
fn from_kind_and_message(error_type: MatrixMarketErrorKind, message: String) -> Self {
fn from_kind_and_message(error_kind: MatrixMarketErrorKind, message: String) -> Self {
Self {
error_kind: error_type,
error_kind,
message,
}
}
@@ -260,38 +260,21 @@ impl MatrixMarketError {
impl fmt::Display for MatrixMarketError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Matrix Market error: ")?;
match self.kind() {
MatrixMarketErrorKind::ParsingError => {
write!(f, "ParsingError,")?;
write!(
f,
match self.kind() {
MatrixMarketErrorKind::ParsingError => "ParsingError,",
MatrixMarketErrorKind::InvalidHeader => "InvalidHeader,",
MatrixMarketErrorKind::EntryMismatch => "EntryMismatch,",
MatrixMarketErrorKind::TypeMismatch => "TypeMismatch,",
MatrixMarketErrorKind::SparseFormatError(_) => "SparseFormatError,",
MatrixMarketErrorKind::ZeroError => "ZeroError,",
MatrixMarketErrorKind::IOError(_) => "IOError,",
MatrixMarketErrorKind::DiagonalError => "DiagonalError,",
MatrixMarketErrorKind::NotLowerTriangle => "NotLowerTriangle,",
MatrixMarketErrorKind::NonSquare => "NonSquare,",
}
MatrixMarketErrorKind::InvalidHeader => {
write!(f, "InvalidHeader,")?;
}
MatrixMarketErrorKind::EntryMismatch => {
write!(f, "EntryMismatch,")?;
}
MatrixMarketErrorKind::TypeMismatch => {
write!(f, "TypeMismatch,")?;
}
MatrixMarketErrorKind::SparseFormatError(_) => {
write!(f, "SparseFormatError,")?;
}
MatrixMarketErrorKind::ZeroError => {
write!(f, "ZeroError,")?;
}
MatrixMarketErrorKind::IOError(_) => {
write!(f, "IOError,")?;
}
MatrixMarketErrorKind::DiagonalError => {
write!(f, "DiagonalError,")?;
}
MatrixMarketErrorKind::NotLowerTriangle => {
write!(f, "NotLowerTriangle,")?;
}
MatrixMarketErrorKind::NonSquare => {
write!(f, "NonSquare,")?;
}
}
)?;
write!(f, " message: {}", self.message)
}
}
32 changes: 16 additions & 16 deletions src/base/matrix.rs
Original file line number Diff line number Diff line change
@@ -1797,7 +1797,7 @@ where
return None;
}

if self.nrows() == 0 || self.ncols() == 0 {
if self.nrows().is_zero() || self.ncols().is_zero() {
return Some(Ordering::Equal);
}

@@ -1812,24 +1812,24 @@ where
let _ = it.next(); // Drop the first elements (we already tested it).

for (left, right) in it {
if let Some(ord) = left.partial_cmp(right) {
match ord {
Ordering::Equal => { /* Does not change anything. */ }
Ordering::Less => {
if *first_ord == Ordering::Greater {
return None;
}
*first_ord = ord
let Some(ord) = left.partial_cmp(right) else {
return None;
};

match ord {
Ordering::Equal => { /* Does not change anything. */ }
Ordering::Less => {
if first_ord.is_gt() {
return None;
}
Ordering::Greater => {
if *first_ord == Ordering::Less {
return None;
}
*first_ord = ord
*first_ord = ord
}
Ordering::Greater => {
if first_ord.is_lt() {
return None;
}
*first_ord = ord
}
} else {
return None;
}
}
}