Skip to content

Commit 42467d4

Browse files
committed
fix regression in memory allocation
1 parent c075d00 commit 42467d4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/SparseArrays/src/higherorderfns.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ _maxnnzfrom(shape::NTuple{2}, A::AbstractSparseMatrixCSC) = nnz(A) * div(shape[1
229229
@inline _unchecked_maxnnzbcres(shape, As...) = _unchecked_maxnnzbcres(shape, As)
230230
@inline _checked_maxnnzbcres(shape::NTuple{1}, As...) = shape[1] != 0 ? _unchecked_maxnnzbcres(shape, As) : 0
231231
@inline _checked_maxnnzbcres(shape::NTuple{2}, As...) = shape[1] != 0 && shape[2] != 0 ? _unchecked_maxnnzbcres(shape, As) : 0
232-
@inline _allocres(shape::NTuple{1}, indextype, entrytype, maxnnz) = sizehint!(SparseVector(shape[1], indextype[], entrytype[]), maxnnz)
233-
@inline _allocres(shape::NTuple{2}, indextype, entrytype, maxnnz) = sizehint!(SparseMatrixCSC(shape..., fill(indextype(1), shape[2]+1), indextype[], entrytype[]), maxnnz)
232+
@inline function _allocres(shape::Union{NTuple{1},NTuple{2}}, indextype, entrytype, maxnnz)
233+
X = spzeros(entrytype, indextype, shape)
234+
resize!(storedinds(X), maxnnz)
235+
resize!(storedvals(X), maxnnz)
236+
return X
237+
end
234238

235239
# (4) _map_zeropres!/_map_notzeropres! specialized for a single sparse vector/matrix
236240
"Stores only the nonzero entries of `map(f, Array(A))` in `C`."

0 commit comments

Comments
 (0)