forked from dimforge/nalgebra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CsMatrix: axpy_cs, transpose, Add and Mul.
- Loading branch information
Showing
9 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub use self::cs_matrix::CsMatrix; | ||
pub use self::cs_matrix::{CsMatrix, CsVector}; | ||
|
||
mod cs_matrix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
||
use na::{Matrix4x5, CsMatrix}; | ||
|
||
#[test] | ||
fn cs_from_to_matrix() { | ||
let m = Matrix4x5::new( | ||
5.0, 6.0, 0.0, 8.0, 15.0, | ||
9.0, 10.0, 11.0, 12.0, 0.0, | ||
0.0, 0.0, 13.0, 0.0, 0.0, | ||
0.0, 1.0, 4.0, 0.0, 14.0, | ||
); | ||
|
||
let cs: CsMatrix<_, _, _> = m.into(); | ||
let m2: Matrix4x5<_> = cs.into(); | ||
|
||
assert_eq!(m2, m); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
||
use na::{Matrix4x5, Matrix5x4, CsMatrix}; | ||
|
||
#[test] | ||
fn cs_transpose() { | ||
let m = Matrix4x5::new( | ||
4.0, 1.0, 4.0, 0.0, 9.0, | ||
5.0, 6.0, 0.0, 8.0, 10.0, | ||
9.0, 10.0, 11.0, 12.0, 0.0, | ||
0.0, 0.0, 1.0, 0.0, 10.0 | ||
); | ||
|
||
let cs: CsMatrix<_, _, _> = m.into(); | ||
let cs_transposed: Matrix5x4<_> = cs.transpose().into(); | ||
|
||
assert_eq!(cs_transposed, m.transpose()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
||
|
||
use na::{Matrix3x4, Matrix4x5, Matrix3x5, CsMatrix, Vector5, CsVector}; | ||
|
||
#[test] | ||
fn axpy_cs() { | ||
let mut v1 = Vector5::new(1.0, 2.0, 3.0, 4.0, 5.0); | ||
let v2 = Vector5::new(10.0, 0.0, 30.0, 0.0, 50.0); | ||
let expected = 5.0 * v2 + 10.0 * v1; | ||
|
||
let cs: CsVector<_, _> = v2.into(); | ||
v1.axpy_cs(5.0, &cs, 10.0); | ||
|
||
assert_eq!(v1, expected) | ||
} | ||
|
||
|
||
#[test] | ||
fn cs_mat_mul() { | ||
let m1 = Matrix3x4::new( | ||
0.0, 1.0, 4.0, 0.0, | ||
5.0, 6.0, 0.0, 8.0, | ||
9.0, 10.0, 11.0, 12.0, | ||
); | ||
|
||
let m2 = Matrix4x5::new( | ||
5.0, 6.0, 0.0, 8.0, 15.0, | ||
9.0, 10.0, 11.0, 12.0, 0.0, | ||
0.0, 0.0, 13.0, 0.0, 0.0, | ||
0.0, 1.0, 4.0, 0.0, 14.0, | ||
); | ||
|
||
let sm1: CsMatrix<_, _, _> = m1.into(); | ||
let sm2: CsMatrix<_, _, _> = m2.into(); | ||
|
||
let mul = &sm1 * &sm2; | ||
|
||
assert_eq!(Matrix3x5::from(mul), m1 * m2); | ||
} | ||
|
||
|
||
#[test] | ||
fn cs_mat_add() { | ||
let m1 = Matrix4x5::new( | ||
4.0, 1.0, 4.0, 0.0, 9.0, | ||
5.0, 6.0, 0.0, 8.0, 10.0, | ||
9.0, 10.0, 11.0, 12.0, 0.0, | ||
0.0, 0.0, 1.0, 0.0, 10.0 | ||
); | ||
|
||
let m2 = Matrix4x5::new( | ||
0.0, 1.0, 4.0, 0.0, 14.0, | ||
5.0, 6.0, 0.0, 8.0, 15.0, | ||
9.0, 10.0, 11.0, 12.0, 0.0, | ||
0.0, 0.0, 13.0, 0.0, 0.0, | ||
); | ||
|
||
let sm1: CsMatrix<_, _, _> = m1.into(); | ||
let sm2: CsMatrix<_, _, _> = m2.into(); | ||
|
||
let mul = &sm1 + &sm2; | ||
|
||
assert_eq!(Matrix4x5::from(mul), m1 + m2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod cs_construction; | ||
mod cs_conversion; | ||
mod cs_matrix; | ||
mod cs_ops; |