@@ -16,7 +16,7 @@ function sum_dim1(A::CuSparseMatrixCSR{T}) where {T}
16
16
m, n = size (A)
17
17
rowsum = CuVector {Float64} (undef, m)
18
18
kernel_f = @cuda launch= false kernel (T, rowsum, A)
19
-
19
+
20
20
config = launch_configuration (kernel_f. fun)
21
21
threads = min (n, config. threads)
22
22
blocks = cld (n, threads)
@@ -40,7 +40,7 @@ function sum_dim2(A::CuSparseMatrixCSR{T}) where {T}
40
40
m, n = size (A)
41
41
colsum = CuVector {Float64} (undef, n)
42
42
kernel_f = @cuda launch= false kernel (T, colsum, A)
43
-
43
+
44
44
config = launch_configuration (kernel_f. fun)
45
45
threads = min (m, config. threads)
46
46
blocks = cld (m, threads)
@@ -97,7 +97,7 @@ function SparseArrays.droptol!(A::CuSparseMatrixCOO, tol::Real)
97
97
copyto! (A, B)
98
98
end
99
99
100
- function Base. reshape (A:: CuSparseMatrixCOO , dims:: NTuple{N,Int} ) where {N}
100
+ function Base. reshape (A:: CuSparseMatrixCOO , dims:: Dims )
101
101
nrows, ncols = size (A)
102
102
flat_indices = nrows .* (A. colInd .- 1 ) .+ A. rowInd .- 1
103
103
new_col, new_row = div .(flat_indices, dims[1 ]) .+ 1 , rem .(flat_indices, dims[1 ]) .+ 1
@@ -125,7 +125,7 @@ function LinearAlgebra.kron(A::CuSparseMatrixCOO{T}, B::CuSparseMatrixCOO{T}) wh
125
125
col .+ = repeat (B. colInd .- 1 , outer = Annz) .+ 1
126
126
127
127
data .*= repeat (B. nzVal, outer = Annz)
128
-
128
+
129
129
sparse (row, col, data, out_shape... , fmt = :coo )
130
130
end
131
131
@@ -150,7 +150,7 @@ function LinearAlgebra.kron(A::CuSparseMatrixCOO{T}, B::Diagonal) where {T}
150
150
col .+ = CuVector (repeat (0 : nB- 1 , outer = Annz)) .+ 1
151
151
152
152
data .*= repeat (CUDA. ones (T, nB), outer = Annz)
153
-
153
+
154
154
sparse (row, col, data, out_shape... , fmt = :coo )
155
155
end
156
156
@@ -175,62 +175,62 @@ function LinearAlgebra.kron(A::Diagonal, B::CuSparseMatrixCOO{T}) where {T}
175
175
col .+ = repeat (B. colInd .- 1 , outer = Annz) .+ 1
176
176
177
177
data .*= repeat (B. nzVal, outer = Annz)
178
-
178
+
179
179
sparse (row, col, data, out_shape... , fmt = :coo )
180
180
end
181
181
182
182
for SparseMatrixType in [:CuSparseMatrixCSC , :CuSparseMatrixCSR ]
183
183
@eval begin
184
- LinearAlgebra. triu (A:: $SparseMatrixType{T,M } , k:: Integer ) where {T,M } =
184
+ LinearAlgebra. triu (A:: $SparseMatrixType{T} , k:: Integer ) where {T} =
185
185
$ SparseMatrixType ( triu (CuSparseMatrixCOO (A), k) )
186
- LinearAlgebra. triu (A:: Transpose{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
186
+ LinearAlgebra. triu (A:: Transpose{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
187
187
$ SparseMatrixType ( triu (CuSparseMatrixCOO (_sptranspose (parent (A))), k) )
188
- LinearAlgebra. triu (A:: Adjoint{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
188
+ LinearAlgebra. triu (A:: Adjoint{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
189
189
$ SparseMatrixType ( triu (CuSparseMatrixCOO (_spadjoint (parent (A))), k) )
190
-
191
- LinearAlgebra. tril (A:: $SparseMatrixType{T,M } , k:: Integer ) where {T,M } =
190
+
191
+ LinearAlgebra. tril (A:: $SparseMatrixType{T} , k:: Integer ) where {T} =
192
192
$ SparseMatrixType ( tril (CuSparseMatrixCOO (A), k) )
193
- LinearAlgebra. tril (A:: Transpose{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
193
+ LinearAlgebra. tril (A:: Transpose{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
194
194
$ SparseMatrixType ( tril (CuSparseMatrixCOO (_sptranspose (parent (A))), k) )
195
- LinearAlgebra. tril (A:: Adjoint{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
195
+ LinearAlgebra. tril (A:: Adjoint{T,<:$SparseMatrixType} , k:: Integer ) where {T} =
196
196
$ SparseMatrixType ( tril (CuSparseMatrixCOO (_spadjoint (parent (A))), k) )
197
-
198
- LinearAlgebra. triu (A:: Union{$SparseMatrixType{T,M }, Transpose{T,<:$SparseMatrixType}, Adjoint{T,<:$SparseMatrixType}} ) where {T,M } =
197
+
198
+ LinearAlgebra. triu (A:: Union{$SparseMatrixType{T}, Transpose{T,<:$SparseMatrixType}, Adjoint{T,<:$SparseMatrixType}} ) where {T} =
199
199
$ SparseMatrixType ( triu (CuSparseMatrixCOO (A), 0 ) )
200
- LinearAlgebra. tril (A:: Union{$SparseMatrixType{T,M}, Transpose{T,<:$SparseMatrixType}, Adjoint{T,<:$SparseMatrixType}} ) where {T,M } =
200
+ LinearAlgebra. tril (A:: Union{$SparseMatrixType{T}, Transpose{T,<:$SparseMatrixType}, Adjoint{T,<:$SparseMatrixType}} ) where {T} =
201
201
$ SparseMatrixType ( tril (CuSparseMatrixCOO (A), 0 ) )
202
202
203
- LinearAlgebra. kron (A:: $SparseMatrixType{T,M } , B:: $SparseMatrixType{T,M } ) where {T,M } =
203
+ LinearAlgebra. kron (A:: $SparseMatrixType{T} , B:: $SparseMatrixType{T} ) where {T} =
204
204
$ SparseMatrixType ( kron (CuSparseMatrixCOO (A), CuSparseMatrixCOO (B)) )
205
- LinearAlgebra. kron (A:: $SparseMatrixType{T,M } , B:: Diagonal ) where {T,M } =
205
+ LinearAlgebra. kron (A:: $SparseMatrixType{T} , B:: Diagonal ) where {T} =
206
206
$ SparseMatrixType ( kron (CuSparseMatrixCOO (A), B) )
207
- LinearAlgebra. kron (A:: Diagonal , B:: $SparseMatrixType{T,M } ) where {T,M } =
207
+ LinearAlgebra. kron (A:: Diagonal , B:: $SparseMatrixType{T} ) where {T} =
208
208
$ SparseMatrixType ( kron (A, CuSparseMatrixCOO (B)) )
209
-
210
- LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: $SparseMatrixType{T,M } ) where {T,M } =
209
+
210
+ LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: $SparseMatrixType{T} ) where {T} =
211
211
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_sptranspose (parent (A))), CuSparseMatrixCOO (B)) )
212
- LinearAlgebra. kron (A:: $SparseMatrixType{T,M } , B:: Transpose{T,<:$SparseMatrixType} ) where {T,M } =
212
+ LinearAlgebra. kron (A:: $SparseMatrixType{T} , B:: Transpose{T,<:$SparseMatrixType} ) where {T} =
213
213
$ SparseMatrixType ( kron (CuSparseMatrixCOO (A), CuSparseMatrixCOO (_sptranspose (parent (B)))) )
214
- LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: Transpose{T,<:$SparseMatrixType} ) where {T} =
214
+ LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: Transpose{T,<:$SparseMatrixType} ) where {T} =
215
215
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_sptranspose (parent (A))), CuSparseMatrixCOO (_sptranspose (parent (B)))) )
216
- LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: Diagonal ) where {T} =
216
+ LinearAlgebra. kron (A:: Transpose{T,<:$SparseMatrixType} , B:: Diagonal ) where {T} =
217
217
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_sptranspose (parent (A))), B) )
218
- LinearAlgebra. kron (A:: Diagonal , B:: Transpose{T,<:$SparseMatrixType} ) where {T} =
218
+ LinearAlgebra. kron (A:: Diagonal , B:: Transpose{T,<:$SparseMatrixType} ) where {T} =
219
219
$ SparseMatrixType ( kron (A, CuSparseMatrixCOO (_sptranspose (parent (B)))) )
220
220
221
- LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: $SparseMatrixType{T,M } ) where {T,M } =
221
+ LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: $SparseMatrixType{T} ) where {T} =
222
222
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_spadjoint (parent (A))), CuSparseMatrixCOO (B)) )
223
- LinearAlgebra. kron (A:: $SparseMatrixType{T,M } , B:: Adjoint{T,<:$SparseMatrixType} ) where {T,M } =
223
+ LinearAlgebra. kron (A:: $SparseMatrixType{T} , B:: Adjoint{T,<:$SparseMatrixType} ) where {T} =
224
224
$ SparseMatrixType ( kron (CuSparseMatrixCOO (A), CuSparseMatrixCOO (_spadjoint (parent (B)))) )
225
- LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: Adjoint{T,<:$SparseMatrixType} ) where {T} =
225
+ LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: Adjoint{T,<:$SparseMatrixType} ) where {T} =
226
226
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_spadjoint (parent (A))), CuSparseMatrixCOO (_spadjoint (parent (B)))) )
227
- LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: Diagonal ) where {T} =
227
+ LinearAlgebra. kron (A:: Adjoint{T,<:$SparseMatrixType} , B:: Diagonal ) where {T} =
228
228
$ SparseMatrixType ( kron (CuSparseMatrixCOO (_spadjoint (parent (A))), B) )
229
- LinearAlgebra. kron (A:: Diagonal , B:: Adjoint{T,<:$SparseMatrixType} ) where {T} =
229
+ LinearAlgebra. kron (A:: Diagonal , B:: Adjoint{T,<:$SparseMatrixType} ) where {T} =
230
230
$ SparseMatrixType ( kron (A, CuSparseMatrixCOO (_spadjoint (parent (B)))) )
231
231
232
232
233
- function Base. reshape (A:: $SparseMatrixType , dims:: NTuple{N,Int} ) where {N}
233
+ function Base. reshape (A:: $SparseMatrixType , dims:: Dims )
234
234
B = CuSparseMatrixCOO (A)
235
235
$ SparseMatrixType (reshape (B, dims))
236
236
end
@@ -244,16 +244,16 @@ for SparseMatrixType in [:CuSparseMatrixCSC, :CuSparseMatrixCSR]
244
244
function LinearAlgebra. exp (A:: $SparseMatrixType ; threshold = 1e-7 , nonzero_tol = 1e-14 )
245
245
rows = LinearAlgebra. checksquare (A) # Throws exception if not square
246
246
typeA = eltype (A)
247
-
247
+
248
248
mat_norm = norm (A, Inf )
249
249
scaling_factor = nextpow (2 , mat_norm) # Native routine, faster
250
250
A = A ./ scaling_factor
251
251
delta = 1
252
-
252
+
253
253
P = $ SparseMatrixType (spdiagm (0 => ones (eltype (A), rows)))
254
254
next_term = P
255
255
n = 1
256
-
256
+
257
257
while delta > threshold
258
258
next_term = typeA (1 / n) * A * next_term
259
259
droptol! (next_term, nonzero_tol)
0 commit comments