Used cargo fmt
This commit is contained in:
91
src/lib.rs
91
src/lib.rs
@@ -1,19 +1,39 @@
|
|||||||
use num_traits::{Num, NumAssign, Signed, Float};
|
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
use num_traits::{Float, Num, NumAssign, Signed};
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::ops::Sub;
|
|
||||||
use std::ops::Mul;
|
use std::ops::Mul;
|
||||||
|
use std::ops::Sub;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[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,
|
rows: usize,
|
||||||
columns: usize,
|
columns: usize,
|
||||||
data: Vec<T>,
|
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 {
|
pub fn new(rows: usize, columns: usize, default: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rows,
|
rows,
|
||||||
@@ -40,7 +60,6 @@ impl<T: Num + NumAssign + Signed + Float + fmt::Display + Copy+PartialEq + Debug
|
|||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
|
|
||||||
|
|
||||||
index += self.columns * row;
|
index += self.columns * row;
|
||||||
for i in 0..self.columns {
|
for i in 0..self.columns {
|
||||||
data.push(self.data[index + i]);
|
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[column2 + (i * self.columns)] = self.data[column1 + (i * self.columns)];
|
||||||
self.data[column1 + (i * self.columns)] = temp[i];
|
self.data[column1 + (i * self.columns)] = temp[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_determinant(&self) -> T {
|
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 {
|
while x < trig_matrix.rows {
|
||||||
let m = *trig_matrix.get(x, i) / pivot;
|
let m = *trig_matrix.get(x, i) / pivot;
|
||||||
println!("m = {m}");
|
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);
|
trig_matrix.set_row(x, new_row);
|
||||||
x += 1;
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn add(self, other: Self) -> Self::Output {
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn sub(self, other: Self) -> Self::Output {
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, other: Self) -> Self::Output {
|
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 {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let mut display = String::new();
|
let mut display = String::new();
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user