-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_matrix.jl
163 lines (142 loc) · 4.29 KB
/
test_matrix.jl
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
module TestMatrix
include("preamble.jl")
@testset "basic interface" begin
m = 10
n = 3
A0 = sprandn(m, m, 0.3)
A = SparseXXMatrixCSC(A0)
@test A[1, 1] isa Float64
@test A == A0
@test sprint(show, A) isa String
@test sprint(show, "text/plain", A) isa String
end
@testset begin
m = 10
n = 3
A0 = sprandn(m, m, 0.3)
A = SparseXXMatrixCSC(A0)
B = randn(m, n)
C0 = mul!(zeros(m, n), A0, B)
C = mul!(zeros(m, n), A, B)
@test C ≈ C0
C = fmul!(zeros(m, n), A, 1, B)
@test C ≈ C0
C = fmul!(zeros(m, n), A, 3I, B)
@test C ≈ 3C0
D = Diagonal(randn(m))
C = fmul!(zeros(m, n), A, D, B)
@test C ≈ A0 * D * B
C0 = mul!(zeros(m, n), A0', B)
C = mul!(zeros(m, n), A', B)
@test C ≈ C0
C = fmul!(zeros(m, n), 1, A', B)
@test C ≈ C0
C = fmul!(zeros(m, n), 3I, A', B)
@test C ≈ 3C0
D = Diagonal(randn(m))
C = fmul!(zeros(m, n), D, A', B)
@test C ≈ D * C0
end
fmul_shared_test_params = let params = []
m = 10
n = 3
S1 = sprandn(m, m, 0.3)
S2 = spshared(S1)
S3 = spshared(S1)
randn!(nonzeros(S2))
randn!(nonzeros(S3))
push!(params, (
label = "Xn :: Matrix",
D1 = Diagonal(randn(m)),
D2 = Diagonal(randn(m)),
D3 = Diagonal(randn(m)),
S1 = S1,
S2 = S2,
S3 = S3,
X1 = randn(m, n),
X2 = randn(m, n),
X3 = randn(m, n),
))
push!(params, (
label = "Xn :: Vector",
D1 = Diagonal(randn(m)),
D2 = Diagonal(randn(m)),
D3 = Diagonal(randn(m)),
S1 = S1,
S2 = S2,
S3 = S3,
X1 = randn(m),
X2 = randn(m),
X3 = randn(m),
))
S1 = sprandn(m, m, 0.3)
S2 = spshared(S1)
S3 = spshared(S1)
randn!(nonzeros(S2))
randn!(nonzeros(S3))
push!(params, (
label = "mixed D type",
D1 = randn(),
D2 = randn() * I,
D3 = Diagonal(randn(m)),
S1 = S1,
S2 = S2,
S3 = S3,
X1 = randn(m, n),
X2 = randn(m, n),
X3 = randn(m, n),
))
params
end
@testset "is_shared_simd $(p.label)" for p in fmul_shared_test_params[1:2]
@unpack D1, D2, D3, S1, S2, S3, X1, X2, X3 = p
@test SparseXX.is_shared_simd3(((D1, S1', X1), (D2, S2', X2)))
@test SparseXX.is_shared_simd2(((D1, S1'), (D2, S2'), X1))
@test SparseXX.is_shared_simd3(((D1, S1', X1),
(D2, S2', X2),
(D3, S3', X3)))
@test SparseXX.is_shared_simd2(((D1, S1'),
(D2, S2'),
(D3, S3'),
X1))
end
@testset "fmul_shared! $(p.label)" for p in fmul_shared_test_params
@unpack D1, D2, D3, S1, S2, S3, X1, X2, X3 = p
Y = fmul_shared!(zero(X1), (D1, S1', X1), (D2, S2', X2))
@test Y ≈ D1 * S1' * X1 + D2 * S2' * X2
Y1, Y2 = fmul_shared!((zero(X1), zero(X1)), (D1, S1', X1), (D2, S2', X2))
@test Y1 ≈ D1 * S1' * X1
@test Y2 ≈ D2 * S2' * X2
Y = fmul_shared!(zero(X1), (D1, S1'), (D2, S2'), X1)
@test Y ≈ (D1 * S1' + D2 * S2') * X1
Y1, Y2 = fmul_shared!((zero(X1), zero(X1)), (D1, S1'), (D2, S2'), X1)
@test Y1 ≈ D1 * S1' * X1
@test Y2 ≈ D2 * S2' * X1
Y = fmul_shared!(zero(X1),
(D1, S1', X1),
(D2, S2', X2),
(D3, S3', X3))
@test Y ≈ D1 * S1' * X1 + D2 * S2' * X2 + D3 * S3' * X3
Y1, Y2, Y3 = fmul_shared!((zero(X1), zero(X1), zero(X1)),
(D1, S1', X1),
(D2, S2', X2),
(D3, S3', X3))
@test Y1 ≈ D1 * S1' * X1
@test Y2 ≈ D2 * S2' * X2
@test Y3 ≈ D3 * S3' * X3
Y = fmul_shared!(zero(X1),
(D1, S1'),
(D2, S2'),
(D3, S3'),
X1)
@test Y ≈ (D1 * S1' + D2 * S2' + D3 * S3') * X1
Y1, Y2, Y3 = fmul_shared!((zero(X1), zero(X1), zero(X1)),
(D1, S1'),
(D2, S2'),
(D3, S3'),
X1)
@test Y1 ≈ D1 * S1' * X1
@test Y2 ≈ D2 * S2' * X1
@test Y3 ≈ D3 * S3' * X1
end
end # module