Compare commits
2 Commits
9b61d89fc4
...
725ca99712
| Author | SHA1 | Date | |
|---|---|---|---|
| 725ca99712 | |||
| 2494c237d7 |
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -2,12 +2,6 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "fractions"
|
||||
version = "0.1.0"
|
||||
@@ -18,14 +12,4 @@ name = "matrix"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fractions",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
@@ -4,5 +4,4 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
num-traits = "0.2.19"
|
||||
fractions = {git = "https://laentropia-homelab.tail7368da.ts.net/laentropia/Rusty-Fractions.git", branch= "main" }
|
||||
|
||||
42
src/lib.rs
42
src/lib.rs
@@ -1,6 +1,7 @@
|
||||
use fractions::{Fraction, FractionError};
|
||||
use std::cmp::min;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::error::Error;
|
||||
use std::fmt::{self, Debug, Display};
|
||||
use std::ops::Add;
|
||||
use std::ops::Mul;
|
||||
use std::ops::Sub;
|
||||
@@ -27,6 +28,45 @@ impl From<FractionError> for MatrixError {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MatrixError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MatrixError::IndexOutOfRange => write!(f, "Index out of range"),
|
||||
MatrixError::RowOutOfRange => write!(f, "Row index out of range"),
|
||||
MatrixError::ColumnOutOfRange => write!(f, "Column index out of range"),
|
||||
MatrixError::NotSquared => write!(f, "Matrix must be square"),
|
||||
MatrixError::InvalidDataSize => write!(f, "Invalid data size for matrix"),
|
||||
MatrixError::InvalidSizeForAdd => {
|
||||
write!(f, "Matrices must have same dimensions for addition")
|
||||
}
|
||||
MatrixError::InvalidSizeForSub => {
|
||||
write!(f, "Matrices must have same dimensions for subtraction")
|
||||
}
|
||||
MatrixError::InvalidSizeForMul => {
|
||||
write!(f, "Invalid matrix dimensions for multiplication")
|
||||
}
|
||||
MatrixError::ZeroSize => write!(f, "Matrix cannot have zero rows or columns"),
|
||||
MatrixError::FailedGauss => {
|
||||
write!(f, "Gaussian elimination failed (possibly singular matrix)")
|
||||
}
|
||||
MatrixError::FailedGaussJordan => write!(
|
||||
f,
|
||||
"Gauss-Jordan elimination failed (possibly singular matrix)"
|
||||
),
|
||||
MatrixError::FractionError(err) => write!(f, "Fraction error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for MatrixError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
match self {
|
||||
MatrixError::FractionError(err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct Matrix {
|
||||
rows: usize,
|
||||
|
||||
Reference in New Issue
Block a user