sparse icon indicating copy to clipboard operation
sparse copied to clipboard

Fix leading duplicates in COO.

Open MaxvdKolk opened this issue 5 years ago • 1 comments

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.

MaxvdKolk avatar Jun 10 '20 14:06 MaxvdKolk

Codecov Report

Merging #19 into master will increase coverage by 0.02%. The diff coverage is 100.00%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update ae25042...d6ed124. Read the comment docs.

codecov[bot] avatar Jun 10 '20 14:06 codecov[bot]