pub struct Frontend { /* private fields */ }Expand description
A frontend structure.
The frontend contains methods which operate on matrices or calculate functions for the
matrices. Backend methods are called by the frontend to operate the matrices. The frontend is
high-level layer that can be directly used by programmer or a Matrix structure.
Implementations§
Source§impl Frontend
impl Frontend
Sourcepub fn new() -> Result<Frontend>
pub fn new() -> Result<Frontend>
Creates a frontend with a default backend.
This method also automatically initializes a default backend if the default backend is uninitialized.
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(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}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(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 new_with_backend(backend: Arc<dyn Backend + Send + Sync>) -> Frontend
pub fn new_with_backend(backend: Arc<dyn Backend + Send + Sync>) -> Frontend
Creates a frotend with the backend.
Sourcepub fn backend(&self) -> Arc<dyn Backend + Send + Sync>
pub fn backend(&self) -> Arc<dyn Backend + Send + Sync>
Returns the backend.
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(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}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(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 unsafe fn create_matrix(
&self,
row_count: usize,
col_count: usize,
) -> Result<Matrix>
pub unsafe fn create_matrix( &self, row_count: usize, col_count: usize, ) -> Result<Matrix>
Creates a matrix with unset elements.
Sourcepub fn create_matrix_and_set_zeros(
&self,
row_count: usize,
col_count: usize,
) -> Result<Matrix>
pub fn create_matrix_and_set_zeros( &self, row_count: usize, col_count: usize, ) -> Result<Matrix>
Creates a matrix and sets the matrix elements on zeros.
Sourcepub fn create_matrix_and_set_elems(
&self,
row_count: usize,
col_count: usize,
elems: &[f32],
) -> Result<Matrix>
pub fn create_matrix_and_set_elems( &self, row_count: usize, col_count: usize, elems: &[f32], ) -> Result<Matrix>
Creates a matrix and sets the matrix elements.
Sourcepub fn copy(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn copy(&self, a: &Matrix, b: &Matrix) -> Result<()>
Copies the a matrix to the b matrix.
This method indeed copies the a matrix array to the b matrix array.
Sourcepub fn get_elems_and_transpose_flag(
&self,
a: &Matrix,
elems: &mut [f32],
is_transposed: &mut bool,
) -> Result<()>
pub fn get_elems_and_transpose_flag( &self, a: &Matrix, elems: &mut [f32], is_transposed: &mut bool, ) -> Result<()>
Copies the matrix elements to the mutable slice and the transpose flag to the object that is referred by the reference.
Sourcepub fn elems_and_transpose_flag(&self, a: &Matrix) -> Result<(Vec<f32>, bool)>
pub fn elems_and_transpose_flag(&self, a: &Matrix) -> Result<(Vec<f32>, bool)>
Returns the elements and the transpose flag of matrix.
Sourcepub fn add(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn add(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Adds the b matrix to the a matrix and then the result is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.add(&a, &b, &c).unwrap();
assert_eq!(vec![1.0 + 5.0, 2.0 + 6.0, 3.0 + 7.0, 4.0 + 8.0], c.elems());Sourcepub fn sub(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn sub(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Subtracts the b matrix from the a matrix and then the result is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sub(&a, &b, &c).unwrap();
assert_eq!(vec![1.0 - 5.0, 2.0 - 6.0, 3.0 - 7.0, 4.0 - 8.0], c.elems());Sourcepub fn mul(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn mul(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Multiplies the a matrix by the b matrix and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
];
let b = matrix![
[7.0, 8.0],
[9.0, 10.0],
[11.0, 12.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.mul(&a, &b, &c).unwrap();
let c11: f32 = 1.0 * 7.0 + 2.0 * 9.0 + 3.0 * 11.0;
let c12: f32 = 1.0 * 8.0 + 2.0 * 10.0 + 3.0 * 12.0;
let c21: f32 = 4.0 * 7.0 + 5.0 * 9.0 + 6.0 * 11.0;
let c22: f32 = 4.0 * 8.0 + 5.0 * 10.0 + 6.0 * 12.0;
assert_eq!(vec![c11, c12, c21, c22], c.elems());Sourcepub fn mul_elems(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn mul_elems(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Multiplies the a matrix elements by the b matrix elements and then the result is in
the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.mul_elems(&a, &b, &c).unwrap();
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, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn div_elems(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Divides the a matrix elements by the b matrix elements and then the result is in the
c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.div_elems(&a, &b, &c).unwrap();
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 add_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn add_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Adds the b scalar to the a matrix and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.add_for_scalar(&a, 10.5, &c).unwrap();
assert_eq!(vec![1.0 + 10.5, 2.0 + 10.5, 3.0 + 10.5, 4.0 + 10.5], c.elems());Sourcepub fn sub_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn sub_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Subtracts the b scalar from the a matrix and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sub_for_scalar(&a, 10.5, &c).unwrap();
assert_eq!(vec![1.0 - 10.5, 2.0 - 10.5, 3.0 - 10.5, 4.0 - 10.5], c.elems());Sourcepub fn rsub_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn rsub_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Subtracts the a matrix from the b scalar and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.rsub_for_scalar(&a, 10.5, &c).unwrap();
assert_eq!(vec![10.5 - 1.0, 10.5 - 2.0, 10.5 - 3.0, 10.5 - 4.0], c.elems());Sourcepub fn mul_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn mul_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Multiplies the a matrix by the b scalar and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.mul_for_scalar(&a, 10.5, &c).unwrap();
assert_eq!(vec![1.0 * 10.5, 2.0 * 10.5, 3.0 * 10.5, 4.0 * 10.5], c.elems());Sourcepub fn div_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn div_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Divides the a matrix by the b scalar and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.div_for_scalar(&a, 10.5, &c).unwrap();
let elems = c.elems();
assert!((1.0 / 10.5 - elems[0]).abs() < 0.001);
assert!((2.0 / 10.5 - elems[1]).abs() < 0.001);
assert!((3.0 / 10.5 - elems[2]).abs() < 0.001);
assert!((4.0 / 10.5 - elems[3]).abs() < 0.001);Sourcepub fn rdiv_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn rdiv_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Divides the b scalar by the a matrix elements and then the result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.rdiv_for_scalar(&a, 10.5, &c).unwrap();
let elems = c.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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn sigmoid(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates sigmoid function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sigmoid(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn tanh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates hyperbolic tangent function for the a matrix and then the result is in the
b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.tanh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn swish(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates swish function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.swish(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn softmax(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates softmax function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.softmax(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn sqrt(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates square roots of the a matrix elements and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sqrt(&a, &b).unwrap();
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 really_transpose(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn really_transpose(&self, a: &Matrix, b: &Matrix) -> Result<()>
Indeed transposes the a matrix and then the result is in the b matrix
().
This method indeed transposes the a matrix without changing the transpose flag.
§Examples
let a = matrix![
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
];
let b = Matrix::new(3, 2);
let frontend = Frontend::new().unwrap();
frontend.really_transpose(&a, &b).unwrap();
assert_eq!(vec![1.0, 4.0, 2.0, 5.0, 3.0, 6.0], b.elems());Sourcepub fn repeat(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn repeat(&self, a: &Matrix, b: &Matrix) -> Result<()>
Repeats the a vector as column or a row
( or
).
§Examples
let a = matrix![
[1.0],
[2.0]
];
let b = Matrix::new(2, 3);
let frontend = Frontend::new().unwrap();
frontend.repeat(&a, &b).unwrap();
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 = Matrix::new(2, 3);
let frontend = Frontend::new().unwrap();
frontend.repeat(&c, &d).unwrap();
assert_eq!(vec![1.0, 2.0, 3.0, 1.0, 2.0, 3.0], d.elems());Sourcepub fn abs(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn abs(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates absolute values of the a matrix elements and then the result is in the b
matrix
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.abs(&a, &b).unwrap();
assert_eq!(vec![2.0, 1.0, 1.0, 2.0], b.elems());Sourcepub fn pow(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn pow(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Raises the a matrix elements to the power of the b matrix elements and then the result
is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.pow(&a, &b, &c).unwrap();
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 pow_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn pow_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Raises the a matrix elements to the power of the b scalar and then the result is in
the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.pow_for_scalar(&a, 2.5, &c).unwrap();
let elems = c.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 rpow_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn rpow_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Raises the b scalar to the power of the a matrix elements and then the result is in
the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.rpow_for_scalar(&a, 10.5, &c).unwrap();
let elems = c.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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn exp(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates exponential function for the a matrix elements and then the result is in the
b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.exp(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn ln(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates natural logarithm of the a matrix elements and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.ln(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn log2(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates base 2 logarithm of the a matrix elements and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.log2(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn log10(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates base 10 logarithm of the a matrix elements and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.log10(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn sin(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates sine function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sin(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn cos(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates cosine function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.cos(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn tan(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates tangent function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.tan(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn asin(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates arcsine function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.asin(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn acos(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates arccosine function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.acos(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn atan(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates arctangent function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.atan(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn atan2(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Calculates arctangent function for the a matrix elements and the b matrix elements and
then the result is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.atan2(&a, &b, &c).unwrap();
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 atan2_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn atan2_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Calculates arctangent function for the a matrix elements and the b scalar and then the
result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.atan2_for_scalar(&a, 10.5, &c).unwrap();
let elems = c.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 ratan2_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn ratan2_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Calculates arctangent function for the b scalar and the a matrix elements and then the
result is in the c matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.ratan2_for_scalar(&a, 10.5, &c).unwrap();
let elems = c.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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn sinh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates hyperbolic sine function for the a matrix and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.sinh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn cosh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates hyperbolic cosine function for the a matrix and then the result is in the b
matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.cosh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn asinh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates inverse hyperbolic sine function for the a matrix and then the result is in
the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.asinh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn acosh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates inverse hyperbolic cosine function for the a matrix and then the result is in
the b matrix
().
§Examples
let a = matrix![
[1.0, 2.0],
[3.0, 4.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.acosh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn atanh(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates inverse hyperbolic tangent function for the a matrix and then the result is
in the b matrix
().
§Examples
let a = matrix![
[0.25, 0.5],
[0.75, 1.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.atanh(&a, &b).unwrap();
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, a: &Matrix, b: &Matrix) -> Result<()>
pub fn signum(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates signum function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.signum(&a, &b).unwrap();
assert_eq!(vec![-1.0, -1.0, 1.0, 1.0], b.elems());Sourcepub fn ceil(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn ceil(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates ceil function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.ceil(&a, &b).unwrap();
assert_eq!(vec![-2.0, -1.0, 2.0, 3.0], b.elems());Sourcepub fn floor(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn floor(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates floor function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.floor(&a, &b).unwrap();
assert_eq!(vec![-3.0, -2.0, 1.0, 2.0], b.elems());Sourcepub fn round(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn round(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates round function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.round(&a, &b).unwrap();
assert_eq!(vec![-3.0, -1.0, 1.0, 3.0], b.elems());Sourcepub fn trunc(&self, a: &Matrix, b: &Matrix) -> Result<()>
pub fn trunc(&self, a: &Matrix, b: &Matrix) -> Result<()>
Calculates trunc function for the a matrix and then the result is in the b matrix
().
§Examples
let a = matrix![
[-2.6, -1.3],
[1.3, 2.6]
];
let b = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.trunc(&a, &b).unwrap();
assert_eq!(vec![-2.0, -1.0, 1.0, 2.0], b.elems());Sourcepub fn max(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn max(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Finds maximum values between the a matrix elements and the b matrix elements and then
the result is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.max(&a, &b, &c).unwrap();
assert_eq!(vec![4.0, 2.0, 1.0, 2.0], c.elems());Sourcepub fn max_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn max_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Finds maximum values between the a matrix elements and the b scalar and then the
result is in the c matrix
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.max_for_scalar(&a, 0.0, &c).unwrap();
assert_eq!(vec![0.0, 0.0, 1.0, 2.0], c.elems());Sourcepub fn min(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
pub fn min(&self, a: &Matrix, b: &Matrix, c: &Matrix) -> Result<()>
Finds minimum values between the a matrix elements and the b matrix elements and then
the result is in the c matrix
().
§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 = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.min(&a, &b, &c).unwrap();
assert_eq!(vec![-2.0, -1.0, -2.0, -4.0], c.elems());Sourcepub fn min_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
pub fn min_for_scalar(&self, a: &Matrix, b: f32, c: &Matrix) -> Result<()>
Finds minimum values between the a matrix elements and the b scalar and then the
result is in the c matrix
().
§Examples
let a = matrix![
[-2.0, -1.0],
[1.0, 2.0]
];
let c = Matrix::new(2, 2);
let frontend = Frontend::new().unwrap();
frontend.min_for_scalar(&a, 0.0, &c).unwrap();
assert_eq!(vec![-2.0, -1.0, 0.0, 0.0], c.elems());