sparse
sparse copied to clipboard
Fix leading duplicates in COO.
When leading duplicates are present in a COO matrix, the conversion towards CSR becomes invalid and not identical to the original COO representation. This changes the dedupe function, such that leading duplicates are treated correctly by starting the counter at -1 compared to 0.
The following illustrates the problem:
// create identity matrix with a duplicate at (0,0) that should drop out
coo := NewCOO(2, 2, make([]int, 0), make([]int, 0), make([]float64, 0))
coo.Set(0, 0, 100)
coo.Set(0, 0, -100)
coo.Set(0, 0, 1)
coo.Set(1, 1, 1)
csr := coo.ToCSR()
// compare matrices after conversion to CSR, expect equal matrices.
if !mat.Equal(coo, csr) {
fmt.Printf("Expected:\n%v\n but created:\n%v\n", mat.Formatted(coo), mat.Formatted(csr))
}
When evaluated, we observe the output, showing the influence of the leading duplicates.
⎡1 0⎤
⎣0 1⎦
but created:
⎡100 0⎤
⎣ 0 1⎦
The committed change should resolve this.
Codecov Report
Merging #19 into master will increase coverage by
0.02%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #19 +/- ##
==========================================
+ Coverage 76.08% 76.10% +0.02%
==========================================
Files 15 15
Lines 2354 2356 +2
==========================================
+ Hits 1791 1793 +2
Misses 385 385
Partials 178 178
| Impacted Files | Coverage Δ | |
|---|---|---|
| coordinate.go | 89.02% <100.00%> (+0.13%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update ae25042...d6ed124. Read the comment docs.