You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `partition::Symbol`: either `:row` or `:column`.
16
25
- `matrix_template::AbstractMatrix`: matrix for which the vector of colors was precomputed (the algorithm will only accept matrices of the exact same size).
17
26
- `color::Vector{<:Integer}`: vector of integer colors, one for each row or column (depending on `partition`).
27
+
- `allow_denser::Bool`: whether or not to allow decompression into a `SparseMatrixCSC` which has more nonzeros than the original sparsity pattern (see [`decompress!`](@ref) to know when this is implemented).
18
28
19
29
!!! warning
20
30
The second constructor (based on keyword arguments) is type-unstable.
Copy file name to clipboardExpand all lines: src/decompression.jl
+58-15Lines changed: 58 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -189,15 +189,25 @@ The out-of-place alternative is [`decompress`](@ref).
189
189
190
190
!!! note
191
191
In-place decompression is faster when `A isa SparseMatrixCSC`.
192
-
- In general, this case requires the sparsity pattern of `A` to match the sparsity pattern `S` from which the coloring result was computed.
193
-
- For a coloring result with `decompression=:direct`, we also allow _full_ decompression into an `A` whose sparsity pattern is a strict superset of `S`.
194
192
195
193
Compression means summing either the columns or the rows of `A` which share the same color.
196
194
It is done by calling [`compress`](@ref).
197
195
196
+
# Details
197
+
198
198
For `:symmetric` coloring results (and for those only), an optional positional argument `uplo in (:U, :L, :F)` can be passed to specify which part of the matrix `A` should be updated: the Upper triangle, the Lower triangle, or the Full matrix.
199
199
When `A isa SparseMatrixCSC`, using the `uplo` argument requires a target matrix which only stores the relevant triangle(s).
200
200
201
+
Some coloring algorithms ([`GreedyColoringAlgorithm`](@ref) and [`ConstantColoringAlgorithm`](@ref)) have an option called `allow_denser`, which enables in-place decompression into a `SparseMatrixCSC` containing more structural nonzeros than the sparsity pattern used for coloring.
202
+
203
+
!!! warning
204
+
Decompression into a denser `SparseMatrixCSC` is only implemented when all the conditions below are satisfied simultaneously:
205
+
- the partition is `:row` or `:column` (not `:bidirectional`)
206
+
- the decompression is `:direct` (not `:substitution`)
207
+
- the decompression is full (so [`decompress_single_color!`](@ref) will not work)
208
+
209
+
Outside of these cases, it is up to the user to make sure that the sparsity pattern of the decompression target is an exact match.
210
+
201
211
# Example
202
212
203
213
```jldoctest
@@ -212,6 +222,8 @@ julia> A = sparse([
212
222
213
223
julia> result = coloring(A, ColoringProblem(), GreedyColoringAlgorithm());
4×6 SparseMatrixCSC{Int64, Int64} with 11 stored entries:
256
+
0 ⋅ 4 6 ⋅ 9
257
+
1 ⋅ ⋅ ⋅ 7 ⋅
258
+
⋅ 2 ⋅ ⋅ 8 ⋅
259
+
⋅ 3 5 ⋅ ⋅ 0
260
+
261
+
julia> A3 == A
262
+
true
239
263
```
240
264
241
265
# See also
@@ -260,6 +284,8 @@ Decompress the vector `b` corresponding to color `c` in-place into `A`, given a
260
284
!!! warning
261
285
This function will only update some coefficients of `A`, without resetting the rest to zero.
262
286
287
+
# Details
288
+
263
289
For `:symmetric` coloring results (and for those only), an optional positional argument `uplo in (:U, :L, :F)` can be passed to specify which part of the matrix `A` should be updated: the Upper triangle, the Lower triangle, or the Full matrix.
264
290
When `A isa SparseMatrixCSC`, using the `uplo` argument requires a target matrix which only stores the relevant triangle(s).
265
291
@@ -356,27 +382,28 @@ function decompress_single_color!(
356
382
end
357
383
358
384
function decompress!(A::SparseMatrixCSC, B::AbstractMatrix, result::ColumnColoringResult)
359
-
(; compressed_indices) = result
385
+
(; compressed_indices, allow_denser) = result
360
386
S = result.bg.S2
361
-
check_same_pattern(A, S; allow_superset=true)
387
+
check_same_pattern(A, S; allow_denser)
362
388
nzA = nonzeros(A)
363
389
if nnz(A) == nnz(S)
364
390
for k in eachindex(compressed_indices)
365
391
nzA[k] = B[compressed_indices[k]]
366
392
end
367
-
else # nnz(A) > nnz(Z)
368
-
fill!(nonzeros(A), zero(eltype(A)))
393
+
else # nnz(A) > nnz(S)
369
394
rvA, rvS = rowvals(A), rowvals(S)
370
395
shift = 0
371
396
for j in axes(S, 2)
372
397
for k in nzrange(S, j)
373
398
i = rvS[k]
374
399
while (k + shift) < A.colptr[j] || rvA[k + shift] < i
400
+
nzA[k + shift] = zero(eltype(A))
375
401
shift += 1
376
402
end
377
403
nzA[k + shift] = B[compressed_indices[k]]
378
404
end
379
405
end
406
+
nzA[(nnz(S) + shift + 1):end] .= zero(eltype(A))
380
407
end
381
408
return A
382
409
end
@@ -433,27 +460,28 @@ function decompress_single_color!(
433
460
end
434
461
435
462
function decompress!(A::SparseMatrixCSC, B::AbstractMatrix, result::RowColoringResult)
436
-
(; compressed_indices) = result
463
+
(; compressed_indices, allow_denser) = result
437
464
S = result.bg.S2
438
-
check_same_pattern(A, S; allow_superset=true)
465
+
check_same_pattern(A, S; allow_denser)
439
466
nzA = nonzeros(A)
440
467
if nnz(A) == nnz(S)
441
468
for k in eachindex(nzA, compressed_indices)
442
469
nzA[k] = B[compressed_indices[k]]
443
470
end
444
471
else # nnz(A) > nnz(S)
445
-
fill!(nonzeros(A), zero(eltype(A)))
446
472
rvA, rvS = rowvals(A), rowvals(S)
447
473
shift = 0
448
474
for j in axes(S, 2)
449
475
for k in nzrange(S, j)
450
476
i = rvS[k]
451
477
while (k + shift) < A.colptr[j] || rvA[k + shift] < i
0 commit comments