wiebecommajonas / libmat Goto Github PK
View Code? Open in Web Editor NEWRust library for matrices.
Rust library for matrices.
Some operations could be implemented more efficiently by first implementing the Assign version of the respective operation and then, depending on that, the original version.
Add<Matrix>
Sub<Matrix>
Mul<T>
Div<T>
impl<...> MulAssign<T> for Matrix {
fn mul_assign(...) {
for i in 0..self.row_count() {
for j in 0..self.col_count() {
self[i][j] = self[i][j] * rhs;
}
}
}
}
impl<...> Mul<T> for Matrix {
type ...
fn mul(...) -> Self::Output {
let mut res = self.clone();
res *= rhs;
res
}
}
The following test fails:
#[test]
fn double_inverse_3() -> Result<(), DimensionError> {
let mat_a = matrix! {{0.0, 1.0, 2.0}, {1.0, 2.0, 3.0}, {3.0, 1.0, 1.0}};
let mat_b = matrix! {{0.5, -0.5, 0.5}, {-4.0, 3.0, -1.0}, {2.5, -1.5, 0.5}};
assert_eq!(mat_a.clone().inv()?, Some(mat_b.clone()));
assert_eq!(mat_b.inv()?, Some(mat_a));
Ok(())
}
The initial inverse of mat_a
fails:
---- double_inverse_3 stdout ----
thread 'double_inverse_3' panicked at 'assertion failed: `(left == right)`
left: `Some(Matrix { dims: Dimensions { rows: 3, cols: 3 }, matrix: [-1.5, 0.5, 2.5, -0.5, 0.5, 0.5, 3.0, -1.0, -4.0] })`,
right: `Some(Matrix { dims: Dimensions { rows: 3, cols: 3 }, matrix: [0.5, -0.5, 0.5, -4.0, 3.0, -1.0, 2.5, -1.5, 0.5] })`', tests/complex_tests.rs:17:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The follow test fails:
let mat_d = matrix!{{1.0,2.0},{3.0,4.0}};
assert_eq!(mat_d.clone().inv()?.unwrap().inv()?, Some(mat_d));
Result:
left: `Some(Matrix { dims: Dimensions { rows: 2, cols: 2 }, matrix: [4.0, 3.0, 2.0, 1.0] })`,
right: `Some(Matrix { dims: Dimensions { rows: 2, cols: 2 }, matrix: [1.0, 2.0, 3.0, 4.0] })`'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.