summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2025-01-23 19:25:44 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2025-01-23 19:25:44 +0200
commit1fdf5e281b2e5963b6348b5d577a827c191785f9 (patch)
tree8a65f0f604780c66705cda2f7aa614c4358ebd54
parent28fae4141285f590e1baf2cc401186ca05e3c9aa (diff)
downloadmatrix-rs-1fdf5e281b2e5963b6348b5d577a827c191785f9.tar.gz
matrix-rs-1fdf5e281b2e5963b6348b5d577a827c191785f9.tar.bz2
matrix-rs-1fdf5e281b2e5963b6348b5d577a827c191785f9.zip
fix: correct from function
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/matrix.rs16
3 files changed, 11 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 221110f..cb6225c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,4 +4,4 @@ version = 3
[[package]]
name = "matrix"
-version = "0.1.5"
+version = "0.1.7"
diff --git a/Cargo.toml b/Cargo.toml
index 08e0460..288c613 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "matrix"
-version = "0.1.6"
+version = "0.1.7"
edition = "2021"
authors = ["Zhongheng Liu <z.liu@outlook.com.gr>"]
homepage = "https://stvnliu.gitlab.io"
diff --git a/src/matrix.rs b/src/matrix.rs
index 9227917..bd6b38f 100644
--- a/src/matrix.rs
+++ b/src/matrix.rs
@@ -11,17 +11,21 @@
//! ```
//! TODO:: Create matrix multiplication method
-use std::{fmt::Display, ops::{Add, Mul, Sub}, str::FromStr};
+use std::{
+ fmt::Display,
+ ops::{Add, Mul, Sub},
+ str::FromStr,
+};
use crate::error::{MatrixSetValueError, ParseMatrixError};
#[derive(Debug, PartialEq, Eq)]
pub struct Matrix {
/// Number of rows in matrix.
pub nrows: usize,
-
+
/// Number of columns in matrix.
pub ncols: usize,
-
+
/// Data stored in the matrix, you should not access this directly
data: Vec<Vec<i32>>,
}
@@ -121,7 +125,6 @@ impl Matrix {
}
}
}
-
impl FromStr for Matrix {
type Err = ParseMatrixError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -188,7 +191,7 @@ impl<'a, 'b> Sub<&'b Matrix> for &'a Matrix {
fn sub(self, rhs: &'b Matrix) -> Self::Output {
todo!()
}
- }
+}
impl<'a, 'b> Mul<&'b Matrix> for &'a Matrix {
type Output = Matrix;
fn mul(self, rhs: &'b Matrix) -> Self::Output {
@@ -221,8 +224,7 @@ impl From<Vec<i32>> for Matrix {
Matrix {
nrows: value.len(),
ncols: 1,
- data: vec![value],
+ data: value.iter().map(|v| vec![*v]).collect(),
}
}
}
-