-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathblas_test.rs
67 lines (55 loc) · 1.59 KB
/
blas_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
extern crate peroxide;
#[allow(unused_imports)]
use peroxide::fuga::*;
#[test]
#[cfg(feature = "O3")]
fn daxpy_test() {
let a = ml_matrix("1 2; 3 4");
let b = matrix(vec![1, 3, 2, 4], 2, 2, Col);
let c = ml_matrix("2 4;6 8");
assert_eq!(&a + &b, c.clone());
assert_eq!(a + b, c);
}
#[test]
#[cfg(feature = "O3")]
fn dgemv_test() {
let a = ml_matrix("1 2;3 4");
let b = c![1, 2];
let c = ml_matrix("5; 11");
assert_eq!(&a * &b, c.clone());
assert_eq!(&(a.change_shape()) * &b, c);
}
#[test]
#[cfg(feature = "O3")]
fn dgemm_test() {
// 2x2
let a = ml_matrix("1 2;3 4");
let b = ml_matrix("1 2;3 4");
let rr = &a * &b;
let rc = &a * &(b.change_shape());
let cr = &(a.change_shape()) * &b;
let cc = &(a.change_shape()) * &(b.change_shape());
assert_eq!(rc.clone(), cr.clone());
assert_eq!(rr, rc);
assert_eq!(cr, cc);
// 3x3
let a2 = ml_matrix("1 2 3;4 5 6;7 8 9");
let b2 = ml_matrix("1 2 3;4 5 6;7 8 9");
let rr2 = &a2 * &b2;
let rc2 = &a2 * &(b2.change_shape());
let cr2 = &(a2.change_shape()) * &b2;
let cc2 = &(a2.change_shape()) * &(b2.change_shape());
assert_eq!(rc2.clone(), cr2.clone());
assert_eq!(rr2, rc2);
assert_eq!(cr2, cc2);
// 3x2, 2x3
let a3 = ml_matrix("1 2;3 4;5 6");
let b3 = ml_matrix("1 2 3;4 5 6");
let rr3 = &a3 * &b3;
let rc3 = &a3 * &(b3.change_shape());
let cr3 = &(a3.change_shape()) * &b3;
let cc3 = &(a3.change_shape()) * &(b3.change_shape());
assert_eq!(rc3.clone(), cr3.clone());
assert_eq!(rr3, rc3);
assert_eq!(cr3, cc3);
}