Used cargo fmt
This commit is contained in:
95
src/lib.rs
95
src/lib.rs
@@ -1,19 +1,39 @@
|
||||
use num_traits::{Num, NumAssign, Signed, Float};
|
||||
use core::panic;
|
||||
use num_traits::{Float, Num, NumAssign, Signed};
|
||||
use std::fmt::{self, Debug};
|
||||
use std::ops::Add;
|
||||
use std::ops::Sub;
|
||||
use std::ops::Mul;
|
||||
|
||||
use std::ops::Sub;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct Matrix<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> {
|
||||
pub struct Matrix<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> {
|
||||
rows: usize,
|
||||
columns: usize,
|
||||
data: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> Matrix<T> {
|
||||
impl<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> Matrix<T>
|
||||
{
|
||||
pub fn new(rows: usize, columns: usize, default: T) -> Self {
|
||||
Self {
|
||||
rows,
|
||||
@@ -40,7 +60,6 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
let mut index = 0;
|
||||
let mut data = Vec::new();
|
||||
|
||||
|
||||
index += self.columns * row;
|
||||
for i in 0..self.columns {
|
||||
data.push(self.data[index + i]);
|
||||
@@ -145,7 +164,6 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
self.data[column2 + (i * self.columns)] = self.data[column1 + (i * self.columns)];
|
||||
self.data[column1 + (i * self.columns)] = temp[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn get_determinant(&self) -> T {
|
||||
@@ -197,7 +215,12 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
while x < trig_matrix.rows {
|
||||
let m = *trig_matrix.get(x, i) / pivot;
|
||||
println!("m = {m}");
|
||||
let new_row = trig_matrix.get_row(x).iter().zip(trig_matrix.get_row(i).iter()).map(|(a, b)| *a - m * *b).collect::<Vec<T>>();
|
||||
let new_row = trig_matrix
|
||||
.get_row(x)
|
||||
.iter()
|
||||
.zip(trig_matrix.get_row(i).iter())
|
||||
.map(|(a, b)| *a - m * *b)
|
||||
.collect::<Vec<T>>();
|
||||
trig_matrix.set_row(x, new_row);
|
||||
x += 1;
|
||||
}
|
||||
@@ -213,7 +236,18 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> Add for Matrix<T> {
|
||||
impl<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> Add for Matrix<T>
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: Self) -> Self::Output {
|
||||
@@ -234,7 +268,18 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> Sub for Matrix<T> {
|
||||
impl<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> Sub for Matrix<T>
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, other: Self) -> Self::Output {
|
||||
@@ -255,7 +300,18 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> Mul for Matrix<T> {
|
||||
impl<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> Mul for Matrix<T>
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, other: Self) -> Self::Output {
|
||||
@@ -285,7 +341,18 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug + std::iter::Product<T>> fmt::Display for Matrix<T> {
|
||||
impl<
|
||||
T: Num
|
||||
+ NumAssign
|
||||
+ Signed
|
||||
+ Float
|
||||
+ fmt::Display
|
||||
+ Copy
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ std::iter::Product<T>,
|
||||
> fmt::Display for Matrix<T>
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut display = String::new();
|
||||
let mut index = 0;
|
||||
@@ -379,7 +446,7 @@ mod tests {
|
||||
matrix1.set(0, 2, 9.0);
|
||||
matrix1.set(0, 3, 6.0);
|
||||
|
||||
let data = vec![8.0, 7.0 , 9.0, 6.0];
|
||||
let data = vec![8.0, 7.0, 9.0, 6.0];
|
||||
|
||||
assert_eq!(matrix1.get_row(0), data);
|
||||
}
|
||||
@@ -414,7 +481,7 @@ mod tests {
|
||||
matrix1.set(2, 0, 9.0);
|
||||
matrix1.set(3, 0, 6.0);
|
||||
|
||||
let data = vec![8.0, 7.0 , 9.0, 6.0];
|
||||
let data = vec![8.0, 7.0, 9.0, 6.0];
|
||||
|
||||
assert_eq!(matrix1.get_column(0), data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user