@@ -55,6 +55,20 @@ function SparseMatrixCSR(a::Transpose{Tv,<:SparseMatrixCSC} where Tv)
55
55
SparseMatrixCSR {1} (size (a,1 ),size (a,2 ),at. colptr,rowvals (at),nonzeros (at))
56
56
end
57
57
58
+ """
59
+ SparseMatrixCSR(a::SparseMatrixCSC}
60
+
61
+ Build a 1-based `SparseMatrixCSR` from a `SparseMatrixCSC`.
62
+ """
63
+ SparseMatrixCSR (a:: SparseMatrixCSC ) = SparseMatrixCSR (transpose (sparse (transpose (a))))
64
+
65
+ """
66
+ SparseMatrixCSR(a::AbstractMatrix}
67
+
68
+ Build a 1-based `SparseMatrixCSR` from an `AbstractMatrix`.
69
+ """
70
+ SparseMatrixCSR (a:: AbstractMatrix ) = SparseMatrixCSR (sparse (a))
71
+
58
72
"""
59
73
SparseMatrixCSR{Bi}(a::Transpose{Tv,<:SparseMatrixCSC} where Tv) where Bi
60
74
@@ -77,7 +91,7 @@ SparseMatrixCSR{1}(a::Transpose{Tv,<:SparseMatrixCSC} where Tv) = SparseMatrixCS
77
91
78
92
Create a `SparseMatrixCSR` with `Bi`-based indexing (1 by default)
79
93
from the same `args...` as one constructs a `SparseMatrixCSC`
80
- with the [`sparse`](@ref ) function.
94
+ with the [`SparseArrays. sparse`](@extref ) function.
81
95
"""
82
96
sparsecsr (I,J,V) = SparseMatrixCSR (transpose (sparse (J,I,V,dimlub (J),dimlub (I))))
83
97
sparsecsr (I,J,V,m,n) = SparseMatrixCSR (transpose (sparse (J,I,V,n,m)))
@@ -133,27 +147,31 @@ end
133
147
function LinearAlgebra. lu (a:: SparseMatrixCSR{0} )
134
148
rowptr = _copy_and_increment (a. rowptr)
135
149
colval = _copy_and_increment (a. colval)
136
- Transpose (lu (SparseMatrixCSC (a. m,a. n,rowptr,colval,a. nzval)))
150
+ transpose (lu (SparseMatrixCSC (a. m,a. n,rowptr,colval,a. nzval)))
137
151
end
138
152
139
153
function LinearAlgebra. lu (a:: SparseMatrixCSR{1} )
140
- Transpose (lu (SparseMatrixCSC (a. m,a. n,a. rowptr,a. colval,a. nzval)))
154
+ transpose (lu (SparseMatrixCSC (a. m,a. n,a. rowptr,a. colval,a. nzval)))
141
155
end
142
156
143
157
if Base. USE_GPL_LIBS
144
158
159
+ const TransposeFact = isdefined (LinearAlgebra, :TransposeFactorization ) ?
160
+ LinearAlgebra. TransposeFactorization :
161
+ Transpose
162
+
145
163
function LinearAlgebra. lu! (
146
- translu:: Transpose {T,<:SuiteSparse.UMFPACK.UmfpackLU{T}} ,
164
+ translu:: TransposeFact {T,<:SuiteSparse.UMFPACK.UmfpackLU{T}} ,
147
165
a:: SparseMatrixCSR{1} ) where {T}
148
- Transpose (lu! (translu. parent,SparseMatrixCSC (a. m,a. n,a. rowptr,a. colval,a. nzval)))
166
+ transpose (lu! (translu. parent,SparseMatrixCSC (a. m,a. n,a. rowptr,a. colval,a. nzval)))
149
167
end
150
168
151
169
function LinearAlgebra. lu! (
152
- translu:: Transpose {T,<:SuiteSparse.UMFPACK.UmfpackLU{T}} ,
170
+ translu:: TransposeFact {T,<:SuiteSparse.UMFPACK.UmfpackLU{T}} ,
153
171
a:: SparseMatrixCSR{0} ) where {T}
154
172
rowptr = _copy_and_increment (a. rowptr)
155
173
colval = _copy_and_increment (a. colval)
156
- Transpose (lu! (translu. parent,SparseMatrixCSC (a. m,a. n,rowptr,colval,a. nzval)))
174
+ transpose (lu! (translu. parent,SparseMatrixCSC (a. m,a. n,rowptr,colval,a. nzval)))
157
175
end
158
176
159
177
end # Base.USE_GPL_LIBS
@@ -223,7 +241,7 @@ issparse(S::SparseMatrixCSR) = true
223
241
224
242
Returns the number of stored (filled) elements in a sparse array.
225
243
"""
226
- nnz (S:: SparseMatrixCSR ) = length ( nonzeros (S) )
244
+ nnz (S:: SparseMatrixCSR{Bi} ) where Bi = Int (S . rowptr[ size (S, 1 ) + 1 ] - Bi )
227
245
228
246
"""
229
247
nonzeros(S::SparseMatrixCSR)
@@ -235,6 +253,8 @@ and any modifications to the returned vector will mutate S as well.
235
253
"""
236
254
nonzeros (S:: SparseMatrixCSR ) = S. nzval
237
255
256
+ nzvalview (S:: SparseMatrixCSR ) = view (nonzeros (S), 1 : nnz (S))
257
+
238
258
"""
239
259
colvals(S::SparseMatrixCSR{Bi}) where {Bi}
240
260
289
309
Count the number of elements in `nonzeros(S)` for which predicate `pred` returns `true`.
290
310
If `pred` not given, it counts the number of `true` values.
291
311
"""
292
- count (pred, S:: SparseMatrixCSR ) = count (pred, nonzeros (S))
293
- count (S:: SparseMatrixCSR ) = count (i-> true , nonzeros (S))
312
+ count (pred, S:: SparseMatrixCSR ) = count (pred, nzvalview (S))
313
+ count (S:: SparseMatrixCSR ) = count (i-> true , nzvalview (S))
294
314
295
315
function mul! (y:: AbstractVector ,A:: SparseMatrixCSR ,v:: AbstractVector , α:: Number , β:: Number )
296
316
A. n == size (v, 1 ) || throw (DimensionMismatch ())
0 commit comments