Skip to content

Commit 7a33584

Browse files
committed
fix allocations in lnk+csc, type annotate op
1 parent 4de82ce commit 7a33584

6 files changed

Lines changed: 18 additions & 17 deletions

src/genericextendablesparsematrixcsc.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ end
137137
"""
138138
function rawupdateindex!(
139139
ext::GenericExtendableSparseMatrixCSC,
140-
op,
140+
op::Op,
141141
v,
142142
i,
143143
j,
144144
part = 1
145-
)
145+
) where {Op}
146146
k = findindex(ext.cscmatrix, i, j)
147147
return if k > 0
148148
ext.cscmatrix.nzval[k] = op(ext.cscmatrix.nzval[k], v)
@@ -151,16 +151,17 @@ function rawupdateindex!(
151151
end
152152
end
153153

154+
154155
"""
155156
$(TYPEDSIGNATURES)
156157
"""
157158
function updateindex!(
158159
ext::GenericExtendableSparseMatrixCSC,
159-
op,
160+
op::Op,
160161
v,
161162
i,
162163
j
163-
)
164+
) where {Op}
164165
k = findindex(ext.cscmatrix, i, j)
165166
return if k > 0
166167
ext.cscmatrix.nzval[k] = op(ext.cscmatrix.nzval[k], v)

src/genericmtextendablesparsematrixcsc.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ nnznew(ext::GenericMTExtendableSparseMatrixCSC) = sum(nnz, ext.xmatrices)
148148
"""
149149
function rawupdateindex!(
150150
ext::GenericMTExtendableSparseMatrixCSC,
151-
op,
151+
op::Op,
152152
v,
153153
i,
154154
j,
155155
tid = 1
156-
)
156+
) where {Op}
157157
k = findindex(ext.cscmatrix, i, j)
158158
return if k > 0
159159
ext.cscmatrix.nzval[k] = op(ext.cscmatrix.nzval[k], v)
@@ -168,12 +168,12 @@ end
168168
"""
169169
function updateindex!(
170170
ext::GenericMTExtendableSparseMatrixCSC,
171-
op,
171+
op::Op,
172172
v,
173173
i,
174174
j,
175175
tid = 1
176-
)
176+
) where {Op}
177177
k = findindex(ext.cscmatrix, i, j)
178178
return if k > 0
179179
ext.cscmatrix.nzval[k] = op(ext.cscmatrix.nzval[k], v)

src/sparsematrixcsc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ A
4848
```
4949
5050
"""
51-
function updateindex!(csc::SparseMatrixCSC{Tv, Ti}, op, v, i, j) where {Tv, Ti <: Integer}
51+
function updateindex!(csc::SparseMatrixCSC{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti <: Integer, Op}
5252
k = findindex(csc, i, j)
5353
if k > 0 # update existing value
5454
csc.nzval[k] = op(csc.nzval[k], v)

src/sparsematrixdict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ end
8585
"""
8686
$(TYPEDSIGNATURES)
8787
"""
88-
function rawupdateindex!(m::SparseMatrixDict{Tv, Ti}, op, v, i, j) where {Tv, Ti}
88+
function rawupdateindex!(m::SparseMatrixDict{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
8989
p = Pair(i, j)
9090
return m.values[p] = op(get(m.values, p, zero(Tv)), v)
9191
end
@@ -94,7 +94,7 @@ end
9494
"""
9595
$(TYPEDSIGNATURES)
9696
"""
97-
function updateindex!(m::SparseMatrixDict{Tv, Ti}, op, v, i, j) where {Tv, Ti}
97+
function updateindex!(m::SparseMatrixDict{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
9898
p = Pair(i, j)
9999
v1 = op(get(m.values, p, zero(Tv)), v)
100100
if !iszero(v1)

src/sparsematrixdilnkc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Update element of the matrix with operation `op`.
218218
It assumes that `op(0,0)==0`. If `v` is zero, no new
219219
entry is created.
220220
"""
221-
function updateindex!(lnk::SparseMatrixDILNKC{Tv, Ti}, op, v, i, j) where {Tv, Ti}
221+
function updateindex!(lnk::SparseMatrixDILNKC{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
222222
k, k0 = findindex(lnk, i, j)
223223
if k > 0
224224
lnk.nzval[k] = op(lnk.nzval[k], v)
@@ -238,7 +238,7 @@ Update element of the matrix with operation `op`.
238238
It assumes that `op(0,0)==0`. If `v` is zero a new entry
239239
is created nevertheless.
240240
"""
241-
function rawupdateindex!(lnk::SparseMatrixDILNKC{Tv, Ti}, op, v, i, j) where {Tv, Ti}
241+
function rawupdateindex!(lnk::SparseMatrixDILNKC{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
242242
k, k0 = findindex(lnk, i, j)
243243
if k > 0
244244
lnk.nzval[k] = op(lnk.nzval[k], v)

src/sparsematrixlnk.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Update element of the matrix with operation `op`.
216216
It assumes that `op(0,0)==0`. If `v` is zero, no new
217217
entry is created.
218218
"""
219-
function updateindex!(lnk::SparseMatrixLNK{Tv, Ti}, op, v, i, j) where {Tv, Ti}
219+
function updateindex!(lnk::SparseMatrixLNK{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
220220
# Set the first column entry if it was not yet set.
221221
if lnk.rowval[j] == 0 && !iszero(v)
222222
lnk.rowval[j] = i
@@ -243,7 +243,7 @@ Update element of the matrix with operation `op`.
243243
It assumes that `op(0,0)==0`. If `v` is zero a new entry
244244
is created nevertheless.
245245
"""
246-
function rawupdateindex!(lnk::SparseMatrixLNK{Tv, Ti}, op, v, i, j) where {Tv, Ti}
246+
function rawupdateindex!(lnk::SparseMatrixLNK{Tv, Ti}, op::Op, v, i, j) where {Tv, Ti, Op}
247247
# Set the first column entry if it was not yet set.
248248
if lnk.rowval[j] == 0
249249
lnk.rowval[j] = i
@@ -278,13 +278,13 @@ SparseArrays.nnz(lnk::SparseMatrixLNK) = lnk.nnz
278278

279279
# Struct holding pair of value and row
280280
# number, for sorting
281-
mutable struct ColEntry{Tv, Ti <: Integer}
281+
struct ColEntry{Tv, Ti <: Integer}
282282
rowval::Ti
283283
nzval::Tv
284284
end
285285

286286
# Comparison method for sorting
287-
Base.isless(x::ColEntry, y::ColEntry) = (x.rowval < y.rowval)
287+
Base.isless(x::ColEntry{Tv, Ti}, y::ColEntry{Tv, Ti}) where {Tv, Ti} = (x.rowval < y.rowval)
288288

289289
"""
290290
$(TYPEDSIGNATURES)

0 commit comments

Comments
 (0)