@@ -1270,6 +1270,34 @@ function sparse!(I::AbstractVector{Ti}, J::AbstractVector{Ti},
1270
1270
Vector {Ti} (undef, n+ 1 ), Vector {Ti} (), Vector {Tv} ())
1271
1271
end
1272
1272
1273
+ """
1274
+ SparseArrays.sparse!(I, J, V, [m, n, combine]) -> SparseMatrixCSC
1275
+
1276
+ Variant of `sparse!` that re-uses the input vectors (`I`, `J`, `V`) for the final matrix
1277
+ storage. After construction the input vectors will alias the matrix buffers; `S.colptr ===
1278
+ I`, `S.rowval === J`, and `S.nzval === V` holds, and they will be `resize!`d as necessary.
1279
+
1280
+ Note that some work buffers will still be allocated. Specifically, this method is a
1281
+ convenience wrapper around `sparse!(I, J, V, m, n, combine, klasttouch, csrrowptr,
1282
+ csrcolval, csrnzval, csccolptr, cscrowval, cscnzval)` where this method allocates
1283
+ `klasttouch`, `csrrowptr`, `csrcolval`, and `csrnzval` of appropriate size, but reuses `I`,
1284
+ `J`, and `V` for `csccolptr`, `cscrowval`, and `cscnzval`.
1285
+
1286
+ Arguments `m`, `n`, and `combine` defaults to `maximum(I)`, `maximum(J)`, and `+`,
1287
+ respectively.
1288
+
1289
+ !!! compat "Julia 1.10"
1290
+ This method requires Julia version 1.10 or later.
1291
+ """
1292
+ function sparse! (I:: AbstractVector{Ti} , J:: AbstractVector{Ti} , V:: AbstractVector{Tv} ,
1293
+ m:: Integer = dimlub (I), n:: Integer = dimlub (J), combine:: Function = + ) where {Tv, Ti<: Integer }
1294
+ klasttouch = Vector {Ti} (undef, n)
1295
+ csrrowptr = Vector {Ti} (undef, m + 1 )
1296
+ csrcolval = Vector {Ti} (undef, length (I))
1297
+ csrnzval = Vector {Tv} (undef, length (I))
1298
+ sparse! (I, J, V, Int (m), Int (n), combine, klasttouch, csrrowptr, csrcolval, csrnzval, I, J, V)
1299
+ end
1300
+
1273
1301
dimlub (I) = isempty (I) ? 0 : Int (maximum (I)) # least upper bound on required sparse matrix dimension
1274
1302
1275
1303
sparse (I,J,v:: Number ) = sparse (I, J, fill (v,length (I)))
@@ -2116,6 +2144,31 @@ function spzeros!(::Type{Tv}, I::AbstractVector{Ti}, J::AbstractVector{Ti}, m::I
2116
2144
csrrowptr, csrcolval, cscnzval, csccolptr, cscrowval, cscnzval)
2117
2145
end
2118
2146
2147
+ """
2148
+ SparseArrays.spzeros!(::Type{Tv}, I, J, [m, n]) -> SparseMatrixCSC{Tv}
2149
+
2150
+ Variant of `spzeros!` that re-uses the input vectors `I` and `J` for the final matrix
2151
+ storage. After construction the input vectors will alias the matrix buffers; `S.colptr ===
2152
+ I` and `S.rowval === J` holds, and they will be `resize!`d as necessary.
2153
+
2154
+ Note that some work buffers will still be allocated. Specifically, this method is a
2155
+ convenience wrapper around `spzeros!(Tv, I, J, m, n, klasttouch, csrrowptr, csrcolval,
2156
+ csccolptr, cscrowval)` where this method allocates `klasttouch`, `csrrowptr`, and
2157
+ `csrcolval` of appropriate size, but reuses `I` and `J` for `csccolptr` and `cscrowval`.
2158
+
2159
+ Arguments `m` and `n` defaults to `maximum(I)` and `maximum(J)`.
2160
+
2161
+ !!! compat "Julia 1.10"
2162
+ This method requires Julia version 1.10 or later.
2163
+ """
2164
+ function spzeros! (:: Type{Tv} , I:: AbstractVector{Ti} , J:: AbstractVector{Ti} ,
2165
+ m:: Integer = dimlub (I), n:: Integer = dimlub (J)) where {Tv, Ti <: Integer }
2166
+ klasttouch = Vector {Ti} (undef, n)
2167
+ csrrowptr = Vector {Ti} (undef, m + 1 )
2168
+ csrcolval = Vector {Ti} (undef, length (I))
2169
+ return spzeros! (Tv, I, J, Int (m), Int (n), klasttouch, csrrowptr, csrcolval, I, J)
2170
+ end
2171
+
2119
2172
import Base. _one
2120
2173
function Base. _one (unit:: T , S:: AbstractSparseMatrixCSC ) where T
2121
2174
size (S, 1 ) == size (S, 2 ) || throw (DimensionMismatch (" multiplicative identity only defined for square matrices" ))
0 commit comments