@@ -32,7 +32,7 @@ using CUDA.CUSPARSE, SparseArrays
32
32
dz = dx .* dy .* elty (2 )
33
33
@test dz isa typ{elty}
34
34
@test z == SparseMatrixCSC (dz)
35
-
35
+
36
36
# multiple inputs
37
37
w = sprand (elty, m, n, p)
38
38
dw = typ (w)
@@ -42,34 +42,34 @@ using CUDA.CUSPARSE, SparseArrays
42
42
@test z == SparseMatrixCSC (dz)
43
43
end
44
44
@testset " $typ ($elty )" for typ in [CuSparseVector,]
45
- m = 64
45
+ m = 64
46
46
p = 0.5
47
47
x = sprand (elty, m, p)
48
48
dx = typ (x)
49
-
49
+
50
50
# zero-preserving
51
51
y = x .* elty (1 )
52
52
dy = dx .* elty (1 )
53
53
@test dy isa typ{elty}
54
- @test collect (dy. iPtr) == collect (dx. iPtr)
54
+ @test collect (dy. iPtr) == collect (dx. iPtr)
55
55
@test collect (dy. iPtr) == y. nzind
56
56
@test collect (dy. nzVal) == y. nzval
57
57
@test y == SparseVector (dy)
58
-
58
+
59
59
# not zero-preserving
60
60
y = x .+ elty (1 )
61
61
dy = dx .+ elty (1 )
62
62
@test dy isa CuArray{elty}
63
63
hy = Array (dy)
64
- @test Array (y) == hy
64
+ @test Array (y) == hy
65
65
66
66
# involving something dense
67
67
y = x .+ ones (elty, m)
68
68
dy = dx .+ CUDA. ones (elty, m)
69
69
@test dy isa CuArray{elty}
70
70
@test y == Array (dy)
71
-
72
- # sparse to sparse
71
+
72
+ # sparse to sparse
73
73
dx = typ (x)
74
74
y = sprand (elty, m, p)
75
75
dy = typ (y)
@@ -88,25 +88,41 @@ using CUDA.CUSPARSE, SparseArrays
88
88
dz = @. dx * dy * dw
89
89
@test dz isa typ{elty}
90
90
@test z == SparseVector (dz)
91
-
91
+
92
92
y = sprand (elty, m, p)
93
93
w = sprand (elty, m, p)
94
94
dense_arr = rand (elty, m)
95
- d_dense_arr = CuArray (dense_arr)
95
+ d_dense_arr = CuArray (dense_arr)
96
96
dy = typ (y)
97
97
dw = typ (w)
98
- z = @. x * y * w * dense_arr
99
- dz = @. dx * dy * dw * d_dense_arr
98
+ z = @. x * y * w * dense_arr
99
+ dz = @. dx * dy * dw * d_dense_arr
100
100
@test dz isa CuArray{elty}
101
101
@test z == Array (dz)
102
-
102
+
103
103
y = sprand (elty, m, p)
104
104
dy = typ (y)
105
105
dx = typ (x)
106
106
z = x .* y .* elty (2 )
107
107
dz = dx .* dy .* elty (2 )
108
108
@test dz isa typ{elty}
109
109
@test z == SparseVector (dz)
110
+
111
+ # type-mismatching
112
+ # # non-zero-preserving
113
+ dx = typ (x)
114
+ dy = dx .+ 1
115
+ y = x .+ 1
116
+ @test dy isa CuArray{promote_type (elty, Int)}
117
+ @test y == Array (dy)
118
+ # # zero-preserving
119
+ dy = dx .* 1
120
+ y = x .* 1
121
+ @test dy isa typ{promote_type (elty, Int)}
122
+ @test collect (dy. iPtr) == collect (dx. iPtr)
123
+ @test collect (dy. iPtr) == y. nzind
124
+ @test collect (dy. nzVal) == y. nzval
125
+ @test y == SparseVector (dy)
110
126
end
111
127
end
112
128
0 commit comments