pub struct Matrix { /* private fields */ }Expand description
A matrix structure.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn new(row_count: usize, col_count: usize) -> Self
pub fn new(row_count: usize, col_count: usize) -> Self
Creates a matrix with the number of rows and the number of columns.
Sourcepub fn new_with_elems(row_count: usize, col_count: usize, elems: &[f32]) -> Self
pub fn new_with_elems(row_count: usize, col_count: usize, elems: &[f32]) -> Self
Creates a matrix with the number of rows, the number of columns, and the elements.
Examples found in repository?
More examples
13fn create_matrix(n: usize, m: usize, is_scalar: bool) -> Matrix
14{
15 let mut elems: Vec<f32> = vec![0.0f32; n * m];
16 let scalar = if is_scalar {
17 (n * m) as f32
18 } else {
19 1.0f32
20 };
21 for i in 0..n {
22 for j in 0..m {
23 elems[m * i + j] = ((m * i + j) as f32) * scalar;
24 }
25 }
26 Matrix::new_with_elems(n, m, elems.as_slice())
27}Sourcepub fn new_with_elem_vecs(elem_vecs: &[Vec<f32>]) -> Self
pub fn new_with_elem_vecs(elem_vecs: &[Vec<f32>]) -> Self
Creates a matrix with the vector of rows.
Sourcepub fn row_count(&self) -> usize
pub fn row_count(&self) -> usize
Returns the number of matrix rows.
Examples found in repository?
10fn main()
11{
12 let a = matrix![
13 [1.0, 2.0, 3.0],
14 [4.0, 5.0, 6.0],
15 [7.0, 8.0, 9.0]
16 ];
17 let b = matrix![
18 [1.0, 4.0, 7.0],
19 [2.0, 5.0, 8.0],
20 [3.0, 6.0, 9.0]
21 ];
22 let c = a * b;
23 let elems = c.elems();
24 for i in 0..c.row_count() {
25 for j in 0..c.col_count() {
26 print!("\t{}", elems[i * c.col_count() + j]);
27 }
28 println!("");
29 }
30}Sourcepub fn col_count(&self) -> usize
pub fn col_count(&self) -> usize
Returns the number of matrix columns.
Examples found in repository?
10fn main()
11{
12 let a = matrix![
13 [1.0, 2.0, 3.0],
14 [4.0, 5.0, 6.0],
15 [7.0, 8.0, 9.0]
16 ];
17 let b = matrix![
18 [1.0, 4.0, 7.0],
19 [2.0, 5.0, 8.0],
20 [3.0, 6.0, 9.0]
21 ];
22 let c = a * b;
23 let elems = c.elems();
24 for i in 0..c.row_count() {
25 for j in 0..c.col_count() {
26 print!("\t{}", elems[i * c.col_count() + j]);
27 }
28 println!("");
29 }
30}Sourcepub fn is_transposed(&self) -> bool
pub fn is_transposed(&self) -> bool
Returns true if the matrix is transposed, otherwise false.
This method indeed returns the transpose flag of matrix that is changed by
transpose.
Sourcepub fn elems(&self) -> Vec<f32>
pub fn elems(&self) -> Vec<f32>
Returns the matrix elements.
Examples found in repository?
10fn main()
11{
12 let a = matrix![
13 [1.0, 2.0, 3.0],
14 [4.0, 5.0, 6.0],
15 [7.0, 8.0, 9.0]
16 ];
17 let b = matrix![
18 [1.0, 4.0, 7.0],
19 [2.0, 5.0, 8.0],
20 [3.0, 6.0, 9.0]
21 ];
22 let c = a * b;
23 let elems = c.elems();
24 for i in 0..c.row_count() {
25 for j in 0..c.col_count() {
26 print!("\t{}", elems[i * c.col_count() + j]);
27 }
28 println!("");
29 }
30}More examples
24fn main()
25{
26 let args: Vec<String> = env::args().collect();
27 let n: usize = match args.get(1) {
28 Some(s) => {
29 match s.parse::<usize>() {
30 Ok(tmp_n) => tmp_n,
31 Err(err) => {
32 eprintln!("{}", err);
33 exit(1);
34 },
35 }
36 },
37 None => 100,
38 };
39 let m: usize = match args.get(2) {
40 Some(s) => {
41 match s.parse::<usize>() {
42 Ok(tmp_m) => tmp_m,
43 Err(err) => {
44 eprintln!("{}", err);
45 exit(1);
46 },
47 }
48 },
49 None => 100,
50 };
51 let l: usize = match args.get(3) {
52 Some(s) => {
53 match s.parse::<usize>() {
54 Ok(tmp_l) => tmp_l,
55 Err(err) => {
56 eprintln!("{}", err);
57 exit(1);
58 },
59 }
60 },
61 None => 100,
62 };
63 let frontend = match Frontend::new() {
64 Ok(tmp_frontend) => tmp_frontend,
65 Err(err) => {
66 eprintln!("{}", err);
67 exit(1);
68 },
69 };
70 println!("backend: {}", frontend.backend().name());
71 let a = create_matrix(n, l);
72 let b = create_matrix(l, m);
73 let now = Instant::now();
74 let c = a * b;
75 let duration = now.elapsed();
76 let elems = c.elems();
77 let sum = elems.iter().fold(0.0f32, |x, y| x + y);
78 println!("sum: {}", sum);
79 println!("time: {}.{:06}", duration.as_secs(), duration.as_micros() % 1000000);
80 match finalize_default_backend() {
81 Ok(()) => (),
82 Err(err) => {
83 eprintln!("{}", err);
84 exit(1);
85 },
86 }
87}24fn main()
25{
26 let args: Vec<String> = env::args().collect();
27 let n: usize = match args.get(1) {
28 Some(s) => {
29 match s.parse::<usize>() {
30 Ok(tmp_n) => tmp_n,
31 Err(err) => {
32 eprintln!("{}", err);
33 exit(1);
34 },
35 }
36 },
37 None => 100,
38 };
39 let m: usize = match args.get(2) {
40 Some(s) => {
41 match s.parse::<usize>() {
42 Ok(tmp_m) => tmp_m,
43 Err(err) => {
44 eprintln!("{}", err);
45 exit(1);
46 },
47 }
48 },
49 None => 100,
50 };
51 let l: usize = match args.get(3) {
52 Some(s) => {
53 match s.parse::<usize>() {
54 Ok(tmp_l) => tmp_l,
55 Err(err) => {
56 eprintln!("{}", err);
57 exit(1);
58 },
59 }
60 },
61 None => 100,
62 };
63 let frontend = match Frontend::new() {
64 Ok(tmp_frontend) => tmp_frontend,
65 Err(err) => {
66 eprintln!("{}", err);
67 exit(1);
68 },
69 };
70 println!("backend: {}", frontend.backend().name());
71 let a = create_matrix(n, l);
72 let b = create_matrix(m, l);
73 let now = Instant::now();
74 let c = a * b.transpose();
75 let duration = now.elapsed();
76 let elems = c.elems();
77 let sum = elems.iter().fold(0.0f32, |x, y| x + y);
78 println!("sum: {}", sum);
79 println!("time: {}.{:06}", duration.as_secs(), duration.as_micros() % 1000000);
80 match finalize_default_backend() {
81 Ok(()) => (),
82 Err(err) => {
83 eprintln!("{}", err);
84 exit(1);
85 },
86 }
87}29fn main()
30{
31 let args: Vec<String> = env::args().collect();
32 let n: usize = match args.get(1) {
33 Some(s) => {
34 match s.parse::<usize>() {
35 Ok(tmp_n) => tmp_n,
36 Err(err) => {
37 eprintln!("{}", err);
38 exit(1);
39 },
40 }
41 },
42 None => 100,
43 };
44 let m: usize = match args.get(2) {
45 Some(s) => {
46 match s.parse::<usize>() {
47 Ok(tmp_m) => tmp_m,
48 Err(err) => {
49 eprintln!("{}", err);
50 exit(1);
51 },
52 }
53 },
54 None => 100,
55 };
56 let l: usize = match args.get(3) {
57 Some(s) => {
58 match s.parse::<usize>() {
59 Ok(tmp_l) => tmp_l,
60 Err(err) => {
61 eprintln!("{}", err);
62 exit(1);
63 },
64 }
65 },
66 None => 100,
67 };
68 let frontend = match Frontend::new() {
69 Ok(tmp_frontend) => tmp_frontend,
70 Err(err) => {
71 eprintln!("{}", err);
72 exit(1);
73 },
74 };
75 println!("backend: {}", frontend.backend().name());
76 let a = create_matrix(n, l, false);
77 let b = create_matrix(l, m, false);
78 let c = create_matrix(n, m, true);
79 let now = Instant::now();
80 let d = a * b + c;
81 let duration = now.elapsed();
82 let elems = d.elems();
83 let sum = elems.iter().fold(0.0f32, |x, y| x + y);
84 println!("sum: {}", sum);
85 println!("time: {}.{:06}", duration.as_secs(), duration.as_micros() % 1000000);
86 match finalize_default_backend() {
87 Ok(()) => (),
88 Err(err) => {
89 eprintln!("{}", err);
90 exit(1);
91 },
92 }
93}Sourcepub fn copy(&self) -> Self
pub fn copy(&self) -> Self
Creates a matrix copy.
This method indeed copies the matrix array to a new matrix array.
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Transposes the matrix ().
This method doesn’t indeed transpose the matrix but changes the transpose flag and exchanges the number of matrix rows with the number of matrix columns.
§Examples
let a = matrix![
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
];
let b = a.transpose();
assert_eq!(3, b.row_count());
assert_eq!(2, b.col_count());
assert_eq!(true, b.is_transposed());
assert_eq!(a.elems(), b.elems());
let c = b.transpose();
assert_eq!(2, c.row_count());
assert_eq!(3, c.col_count());
assert_eq!(false, c.is_transposed());
assert_eq!(a.elems(), c.elems());Examples found in repository?
24fn main()
25{
26 let args: Vec<String> = env::args().collect();
27 let n: usize = match args.get(1) {
28 Some(s) => {
29 match s.parse::<usize>() {
30 Ok(tmp_n) => tmp_n,
31 Err(err) => {
32 eprintln!("{}", err);
33 exit(1);
34 },
35 }
36 },
37 None => 100,
38 };
39 let m: usize = match args.get(2) {
40 Some(s) => {
41 match s.parse::<usize>() {
42 Ok(tmp_m) => tmp_m,
43 Err(err) => {
44 eprintln!("{}", err);
45 exit(1);
46 },
47 }
48 },
49 None => 100,
50 };
51 let l: usize = match args.get(3) {
52 Some(s) => {
53 match s.parse::<usize>() {
54 Ok(tmp_l) => tmp_l,
55 Err(err) => {
56 eprintln!("{}", err);
57 exit(1);
58 },
59 }
60 },
61 None => 100,
62 };
63 let frontend = match Frontend::new() {
64 Ok(tmp_frontend) => tmp_frontend,
65 Err(err) => {
66 eprintln!("{}", err);
67 exit(1);
68 },
69 };
70 println!("backend: {}", frontend.backend().name());
71 let a = create_matrix(n, l);
72 let b = create_matrix(m, l);
73 let now = Instant::now();
74 let c = a * b.transpose();
75 let duration = now.elapsed();
76 let elems = c.elems();
77 let sum = elems.iter().fold(0.0f32, |x, y| x + y);
78 println!("sum: {}", sum);
79 println!("time: {}.{:06}", duration.as_secs(), duration.as_micros() % 1000000);
80 match finalize_default_backend() {
81 Ok(()) => (),
82 Err(err) => {
83 eprintln!("{}", err);
84 exit(1);
85 },
86 }
87}Sourcepub fn really_transpose(&self) -> Self
pub fn really_transpose(&self) -> Self
Indeed transposes the matrix ().
This method indeed transposes the matrix without changing the transpose flag.
§Examples
let a = matrix![
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
];
let b = a.really_transpose();
assert_eq!(3, b.row_count());
assert_eq!(2, b.col_count());
assert_eq!(false, b.is_transposed());
assert_eq!(vec![1.0, 4.0, 2.0, 5.0, 3.0, 6.0], b.elems());Sourcepub fn rt(&self) -> Self
pub fn rt(&self) -> Self
See really_transpose.
Sourcepub fn mul_elems(&self, b: &Self) -> Self
pub fn mul_elems(&self, b: &Self) -> Self
Multiplies the matrix elements by the b matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = matrix![
[5.0, 6.0],
[7.0, 8.0]
];
let c = a.mul_elems(&b);
assert_eq!(vec![1.0 * 5.0, 2.0 * 6.0, 3.0 * 7.0, 4.0 * 8.0], c.elems());Sourcepub fn div_elems(&self, b: &Self) -> Self
pub fn div_elems(&self, b: &Self) -> Self
Divides the matrix elements by the b matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = matrix![
[5.0, 6.0],
[7.0, 8.0]
];
let c = a.div_elems(&b);
let elems = c.elems();
assert!((1.0 / 5.0 - elems[0]).abs() < 0.001);
assert!((2.0 / 6.0 - elems[1]).abs() < 0.001);
assert!((3.0 / 7.0 - elems[2]).abs() < 0.001);
assert!((4.0 / 8.0 - elems[3]).abs() < 0.001);Sourcepub fn rsub(&self, b: f32) -> Self
pub fn rsub(&self, b: f32) -> Self
Subtracts the matrix from the b scalar
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.rsub(10.5);
assert_eq!(vec![10.5 - 1.0, 10.5 - 2.0, 10.5 - 3.0, 10.5 - 4.0], b.elems());Sourcepub fn rdiv(&self, b: f32) -> Self
pub fn rdiv(&self, b: f32) -> Self
Divides the b scalar by the matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.rdiv(10.5);
let elems = b.elems();
assert!((10.5 / 1.0 - elems[0]).abs() < 0.001);
assert!((10.5 / 2.0 - elems[1]).abs() < 0.001);
assert!((10.5 / 3.0 - elems[2]).abs() < 0.001);
assert!((10.5 / 4.0 - elems[3]).abs() < 0.001);Sourcepub fn sigmoid(&self) -> Self
pub fn sigmoid(&self) -> Self
Calculates sigmoid function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.sigmoid();
let elems = b.elems();
assert!((1.0 / (1.0 + (-1.0f32).exp()) - elems[0]).abs() < 0.001);
assert!((1.0 / (1.0 + (-2.0f32).exp()) - elems[1]).abs() < 0.001);
assert!((1.0 / (1.0 + (-3.0f32).exp()) - elems[2]).abs() < 0.001);
assert!((1.0 / (1.0 + (-4.0f32).exp()) - elems[3]).abs() < 0.001);Sourcepub fn tanh(&self) -> Self
pub fn tanh(&self) -> Self
Calculates hyperbolic tangent function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.tanh();
let elems = b.elems();
assert!((1.0f32.tanh() - elems[0]).abs() < 0.001);
assert!((2.0f32.tanh() - elems[1]).abs() < 0.001);
assert!((3.0f32.tanh() - elems[2]).abs() < 0.001);
assert!((4.0f32.tanh() - elems[3]).abs() < 0.001);Sourcepub fn swish(&self) -> Self
pub fn swish(&self) -> Self
Calculates swish function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.swish();
let elems = b.elems();
assert!((1.0 / (1.0 + (-1.0f32).exp()) - elems[0]).abs() < 0.001);
assert!((2.0 / (1.0 + (-2.0f32).exp()) - elems[1]).abs() < 0.001);
assert!((3.0 / (1.0 + (-3.0f32).exp()) - elems[2]).abs() < 0.001);
assert!((4.0 / (1.0 + (-4.0f32).exp()) - elems[3]).abs() < 0.001);Sourcepub fn softmax(&self) -> Self
pub fn softmax(&self) -> Self
Calculates softmax function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.softmax();
let elems = b.elems();
let sum1 = 1.0f32.exp() + 3.0f32.exp();
let sum2 = 2.0f32.exp() + 4.0f32.exp();
assert!((1.0f32.exp() / sum1 - elems[0]).abs() < 0.001);
assert!((2.0f32.exp() / sum2 - elems[1]).abs() < 0.001);
assert!((3.0f32.exp() / sum1 - elems[2]).abs() < 0.001);
assert!((4.0f32.exp() / sum2 - elems[3]).abs() < 0.001);Sourcepub fn sqrt(&self) -> Self
pub fn sqrt(&self) -> Self
Calculates square roots of the matrix elements ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.sqrt();
let elems = b.elems();
assert!((1.0f32.sqrt() - elems[0]).abs() < 0.001);
assert!((2.0f32.sqrt() - elems[1]).abs() < 0.001);
assert!((3.0f32.sqrt() - elems[2]).abs() < 0.001);
assert!((4.0f32.sqrt() - elems[3]).abs() < 0.001);Sourcepub fn repeat(&self, n: usize) -> Self
pub fn repeat(&self, n: usize) -> Self
Repeats the vector as column or a row.
§Examples
let a = matrix![
[1.0],
[2.0]
];
let b = a.repeat(3);
assert_eq!(vec![1.0, 1.0, 1.0, 2.0, 2.0, 2.0], b.elems());
let c = matrix![[1.0, 2.0, 3.0]];
let d = c.repeat(2);
assert_eq!(vec![1.0, 2.0, 3.0, 1.0, 2.0, 3.0], d.elems());Sourcepub fn abs(&self) -> Self
pub fn abs(&self) -> Self
Calculates absolute values of the matrix elements ().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = a.abs();
assert_eq!(vec![2.0, 1.0, 1.0, 2.0], b.elems());Sourcepub fn powm(&self, b: &Self) -> Self
pub fn powm(&self, b: &Self) -> Self
Raises the matrix elements to the power of the b matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = matrix![
[3.0, 4.0],
[5.0, 6.0]
];
let c = a.powm(&b);
let elems = c.elems();
assert!((1.0f32.powf(3.0) - elems[0]).abs() < 0.001);
assert!((2.0f32.powf(4.0) - elems[1]).abs() < 0.001);
assert!((3.0f32.powf(5.0) - elems[2]).abs() < 0.001);
assert!((4.0f32.powf(6.0) - elems[3]).abs() < 0.001);Sourcepub fn powf(&self, b: f32) -> Self
pub fn powf(&self, b: f32) -> Self
Raises the matrix elements to the power of the b scalar
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.powf(2.5);
let elems = b.elems();
assert!((1.0f32.powf(2.5) - elems[0]).abs() < 0.001);
assert!((2.0f32.powf(2.5) - elems[1]).abs() < 0.001);
assert!((3.0f32.powf(2.5) - elems[2]).abs() < 0.001);
assert!((4.0f32.powf(2.5) - elems[3]).abs() < 0.001);Sourcepub fn rpowf(&self, b: f32) -> Self
pub fn rpowf(&self, b: f32) -> Self
Raises the b scalar to the power of the matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.rpowf(10.5);
let elems = b.elems();
assert!((10.5f32.powf(1.0) - elems[0]).abs() < 0.001);
assert!((10.5f32.powf(2.0) - elems[1]).abs() < 0.001);
assert!((10.5f32.powf(3.0) - elems[2]).abs() < 0.001);
assert!((10.5f32.powf(4.0) - elems[3]).abs() < 0.001);Sourcepub fn exp(&self) -> Self
pub fn exp(&self) -> Self
Calculates exponential function for the matrix elements ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.exp();
let elems = b.elems();
assert!((1.0f32.exp() - elems[0]).abs() < 0.001);
assert!((2.0f32.exp() - elems[1]).abs() < 0.001);
assert!((3.0f32.exp() - elems[2]).abs() < 0.001);
assert!((4.0f32.exp() - elems[3]).abs() < 0.001);Sourcepub fn ln(&self) -> Self
pub fn ln(&self) -> Self
Calculates natural logarithm of the matrix elements ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.ln();
let elems = b.elems();
assert!((1.0f32.ln() - elems[0]).abs() < 0.001);
assert!((2.0f32.ln() - elems[1]).abs() < 0.001);
assert!((3.0f32.ln() - elems[2]).abs() < 0.001);
assert!((4.0f32.ln() - elems[3]).abs() < 0.001);Sourcepub fn log2(&self) -> Self
pub fn log2(&self) -> Self
Calculates base 2 logarithm of the matrix elements ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.log2();
let elems = b.elems();
assert!((1.0f32.log2() - elems[0]).abs() < 0.001);
assert!((2.0f32.log2() - elems[1]).abs() < 0.001);
assert!((3.0f32.log2() - elems[2]).abs() < 0.001);
assert!((4.0f32.log2() - elems[3]).abs() < 0.001);Sourcepub fn log10(&self) -> Self
pub fn log10(&self) -> Self
Calculates base 10 logarithm of the matrix elements ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.log10();
let elems = b.elems();
assert!((1.0f32.log10() - elems[0]).abs() < 0.001);
assert!((2.0f32.log10() - elems[1]).abs() < 0.001);
assert!((3.0f32.log10() - elems[2]).abs() < 0.001);
assert!((4.0f32.log10() - elems[3]).abs() < 0.001);Sourcepub fn sin(&self) -> Self
pub fn sin(&self) -> Self
Calculates sine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.sin();
let elems = b.elems();
assert!((1.0f32.sin() - elems[0]).abs() < 0.001);
assert!((2.0f32.sin() - elems[1]).abs() < 0.001);
assert!((3.0f32.sin() - elems[2]).abs() < 0.001);
assert!((4.0f32.sin() - elems[3]).abs() < 0.001);Sourcepub fn cos(&self) -> Self
pub fn cos(&self) -> Self
Calculates cosine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.cos();
let elems = b.elems();
assert!((1.0f32.cos() - elems[0]).abs() < 0.001);
assert!((2.0f32.cos() - elems[1]).abs() < 0.001);
assert!((3.0f32.cos() - elems[2]).abs() < 0.001);
assert!((4.0f32.cos() - elems[3]).abs() < 0.001);Sourcepub fn tan(&self) -> Self
pub fn tan(&self) -> Self
Calculates tangent function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.tan();
let elems = b.elems();
assert!((1.0f32.tan() - elems[0]).abs() < 0.001);
assert!((2.0f32.tan() - elems[1]).abs() < 0.001);
assert!((3.0f32.tan() - elems[2]).abs() < 0.001);
assert!((4.0f32.tan() - elems[3]).abs() < 0.001);Sourcepub fn asin(&self) -> Self
pub fn asin(&self) -> Self
Calculates arcsine function for the matrix ().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = a.asin();
let elems = b.elems();
assert!((0.25f32.asin() - elems[0]).abs() < 0.001);
assert!((0.5f32.asin() - elems[1]).abs() < 0.001);
assert!((0.75f32.asin() - elems[2]).abs() < 0.001);
assert!((1.0f32.asin() - elems[3]).abs() < 0.001);Sourcepub fn acos(&self) -> Self
pub fn acos(&self) -> Self
Calculates arccosine function for the matrix ().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = a.acos();
let elems = b.elems();
assert!((0.25f32.acos() - elems[0]).abs() < 0.001);
assert!((0.5f32.acos() - elems[1]).abs() < 0.001);
assert!((0.75f32.acos() - elems[2]).abs() < 0.001);
assert!((1.0f32.acos() - elems[3]).abs() < 0.001);Sourcepub fn atan(&self) -> Self
pub fn atan(&self) -> Self
Calculates arctangent function for the a matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.atan();
let elems = b.elems();
assert!((1.0f32.atan() - elems[0]).abs() < 0.001);
assert!((2.0f32.atan() - elems[1]).abs() < 0.001);
assert!((3.0f32.atan() - elems[2]).abs() < 0.001);
assert!((4.0f32.atan() - elems[3]).abs() < 0.001);Sourcepub fn atan2(&self, b: &Self) -> Self
pub fn atan2(&self, b: &Self) -> Self
Calculates arctangent function for the matrix elements and the b matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = matrix![
[5.0, 6.0],
[7.0, 8.0]
];
let c = a.atan2(&b);
let elems = c.elems();
assert!((1.0f32.atan2(5.0) - elems[0]).abs() < 0.001);
assert!((2.0f32.atan2(6.0) - elems[1]).abs() < 0.001);
assert!((3.0f32.atan2(7.0) - elems[2]).abs() < 0.001);
assert!((4.0f32.atan2(8.0) - elems[3]).abs() < 0.001);Sourcepub fn atan2f(&self, b: f32) -> Self
pub fn atan2f(&self, b: f32) -> Self
Calculates arctangent function for the matrix elements and the b scalar
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.atan2f(10.5);
let elems = b.elems();
assert!((1.0f32.atan2(10.5) - elems[0]).abs() < 0.001);
assert!((2.0f32.atan2(10.5) - elems[1]).abs() < 0.001);
assert!((3.0f32.atan2(10.5) - elems[2]).abs() < 0.001);
assert!((4.0f32.atan2(10.5) - elems[3]).abs() < 0.001);Sourcepub fn ratan2f(&self, b: f32) -> Self
pub fn ratan2f(&self, b: f32) -> Self
Calculates arctangent function for the b scalar and the matrix elements
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.ratan2f(10.5);
let elems = b.elems();
assert!((10.5f32.atan2(1.0) - elems[0]).abs() < 0.001);
assert!((10.5f32.atan2(2.0) - elems[1]).abs() < 0.001);
assert!((10.5f32.atan2(3.0) - elems[2]).abs() < 0.001);
assert!((10.5f32.atan2(4.0) - elems[3]).abs() < 0.001);Sourcepub fn sinh(&self) -> Self
pub fn sinh(&self) -> Self
Calculates hyperbolic sine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.sinh();
let elems = b.elems();
assert!((1.0f32.sinh() - elems[0]).abs() < 0.001);
assert!((2.0f32.sinh() - elems[1]).abs() < 0.001);
assert!((3.0f32.sinh() - elems[2]).abs() < 0.001);
assert!((4.0f32.sinh() - elems[3]).abs() < 0.001);Sourcepub fn cosh(&self) -> Self
pub fn cosh(&self) -> Self
Calculates hyperbolic cosine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.cosh();
let elems = b.elems();
assert!((1.0f32.cosh() - elems[0]).abs() < 0.001);
assert!((2.0f32.cosh() - elems[1]).abs() < 0.001);
assert!((3.0f32.cosh() - elems[2]).abs() < 0.001);
assert!((4.0f32.cosh() - elems[3]).abs() < 0.001);Sourcepub fn asinh(&self) -> Self
pub fn asinh(&self) -> Self
Calculates inverse hyperbolic sine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.asinh();
let elems = b.elems();
assert!((1.0f32.asinh() - elems[0]).abs() < 0.001);
assert!((2.0f32.asinh() - elems[1]).abs() < 0.001);
assert!((3.0f32.asinh() - elems[2]).abs() < 0.001);
assert!((4.0f32.asinh() - elems[3]).abs() < 0.001);Sourcepub fn acosh(&self) -> Self
pub fn acosh(&self) -> Self
Calculates inverse hyperbolic cosine function for the matrix ().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = a.acosh();
let elems = b.elems();
assert!((1.0f32.acosh() - elems[0]).abs() < 0.001);
assert!((2.0f32.acosh() - elems[1]).abs() < 0.001);
assert!((3.0f32.acosh() - elems[2]).abs() < 0.001);
assert!((4.0f32.acosh() - elems[3]).abs() < 0.001);Sourcepub fn atanh(&self) -> Self
pub fn atanh(&self) -> Self
Calculates inverse hyperbolic tangent function for the matrix ().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = a.atanh();
let elems = b.elems();
assert!((0.25f32.atanh() - elems[0]).abs() < 0.001);
assert!((0.5f32.atanh() - elems[1]).abs() < 0.001);
assert!((0.75f32.atanh() - elems[2]).abs() < 0.001);
assert_eq!(f32::INFINITY, elems[3]);Sourcepub fn signum(&self) -> Self
pub fn signum(&self) -> Self
Calculates signum function for the matrix ().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = a.signum();
assert_eq!(vec![-1.0, -1.0, 1.0, 1.0], b.elems());Sourcepub fn ceil(&self) -> Self
pub fn ceil(&self) -> Self
Calculates ceil function for the matrix ().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = a.ceil();
assert_eq!(vec![-2.0, -1.0, 2.0, 3.0], b.elems());Sourcepub fn floor(&self) -> Self
pub fn floor(&self) -> Self
Calculates floor function for the matrix ().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = a.floor();
assert_eq!(vec![-3.0, -2.0, 1.0, 2.0], b.elems());Sourcepub fn round(&self) -> Self
pub fn round(&self) -> Self
Calculates round function for the matrix ().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = a.round();
assert_eq!(vec![-3.0, -1.0, 1.0, 3.0], b.elems());Sourcepub fn trunc(&self) -> Self
pub fn trunc(&self) -> Self
Calculates trunc function for the matrix ().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = a.trunc();
assert_eq!(vec![-2.0, -1.0, 1.0, 2.0], b.elems());Sourcepub fn max(&self, b: &Self) -> Self
pub fn max(&self, b: &Self) -> Self
Finds maximum values between the matrix elements and the b matrix elements
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = matrix![
[4.0, 2.0],
[-2.0, -4.0]
];
let c = a.max(&b);
assert_eq!(vec![4.0, 2.0, 1.0, 2.0], c.elems());Sourcepub fn maxf(&self, b: f32) -> Self
pub fn maxf(&self, b: f32) -> Self
Finds maximum values between the matrix elements and the b scalar
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = a.maxf(0.0);
assert_eq!(vec![0.0, 0.0, 1.0, 2.0], b.elems());Trait Implementations§
Source§impl AddAssign<&Matrix> for Matrix
impl AddAssign<&Matrix> for Matrix
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moreSource§impl AddAssign<&f32> for Matrix
impl AddAssign<&f32> for Matrix
Source§fn add_assign(&mut self, rhs: &f32)
fn add_assign(&mut self, rhs: &f32)
+= operation. Read moreSource§impl AddAssign<f32> for Matrix
impl AddAssign<f32> for Matrix
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moreSource§impl AddAssign for Matrix
impl AddAssign for Matrix
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl DivAssign<&f32> for Matrix
impl DivAssign<&f32> for Matrix
Source§fn div_assign(&mut self, rhs: &f32)
fn div_assign(&mut self, rhs: &f32)
/= operation. Read moreSource§impl DivAssign<f32> for Matrix
impl DivAssign<f32> for Matrix
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl MulAssign<&Matrix> for Matrix
impl MulAssign<&Matrix> for Matrix
Source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
*= operation. Read moreSource§impl MulAssign<&f32> for Matrix
impl MulAssign<&f32> for Matrix
Source§fn mul_assign(&mut self, rhs: &f32)
fn mul_assign(&mut self, rhs: &f32)
*= operation. Read moreSource§impl MulAssign<f32> for Matrix
impl MulAssign<f32> for Matrix
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl MulAssign for Matrix
impl MulAssign for Matrix
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl SubAssign<&Matrix> for Matrix
impl SubAssign<&Matrix> for Matrix
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moreSource§impl SubAssign<&f32> for Matrix
impl SubAssign<&f32> for Matrix
Source§fn sub_assign(&mut self, rhs: &f32)
fn sub_assign(&mut self, rhs: &f32)
-= operation. Read more