Skip to content

Commit

Permalink
Reformat the reshaping example.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Oct 25, 2020
1 parent 5b3da9e commit 7af509e
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions examples/reshaping.rs
@@ -1,11 +1,20 @@
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate nalgebra as na;

use na::{DMatrix, Dynamic, Matrix2x3, Matrix3x2, U2, U3};

fn main() {
// Matrices can be reshaped in-place without moving or copying values.
let m1 = Matrix2x3::new(1.1, 1.2, 1.3, 2.1, 2.2, 2.3);
let m2 = Matrix3x2::new(1.1, 2.2, 2.1, 1.3, 1.2, 2.3);
let m1 = Matrix2x3::new(
1.1, 1.2, 1.3,
2.1, 2.2, 2.3
);
let m2 = Matrix3x2::new(
1.1, 2.2,
2.1, 1.3,
1.2, 2.3
);

let m3 = m1.reshape_generic(U3, U2);
assert_eq!(m3, m2);
Expand All @@ -14,15 +23,23 @@ fn main() {
//let m4 = m3.reshape_generic(U3, U3);

// If dynamically sized matrices are used, the reshaping is checked at run-time.
let dm1 = DMatrix::from_vec(
let dm1 = DMatrix::from_row_slice(
4,
3,
vec![1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
&[
1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
],
);
let dm2 = DMatrix::from_vec(
let dm2 = DMatrix::from_row_slice(
6,
2,
vec![1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
&[
1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0
],
);

let dm3 = dm1.reshape_generic(Dynamic::new(6), Dynamic::new(2));
Expand Down

0 comments on commit 7af509e

Please sign in to comment.