Issue 116012
Summary [MLIR][sparse] Incorrect result when converting COO tensor
Labels mlir
Assignees
Reporter mtsokol
    Hi!

I noticed that converting COO to another format, like CSR, returns an incorrect result. Here's a script where COO is converted to CSR - it reproduces the issue: https://gist.github.com/mtsokol/2824f8f37c108fe51740fc6df4e5771f

```mlir
sparse_tensor.print %input : tensor<10x10xf64, #COO>
%res = sparse_tensor.convert %input : tensor<10x10xf64, #COO> to tensor<10x10xf64, #CSR>
sparse_tensor.print %res : tensor<10x10xf64, #CSR>
```

It looks like after calling `convert`, `crd[1]` in CSR is missing a bunch of elements. It's length should match `values` length but it's shorter:
```
---- Sparse Tensor ----
nse = 70
dim = ( 10, 10 )
lvl = ( 10, 10 )
pos[0] : ( 0, 70 )
crd[0] : ( 4, 3, 3, 7, 4, 8, 5, 2, 1, 9, 2, 4, 9, 9, 0, 5, 5, 1, 7, 6, 6, 0, 3, 0, 3, 1, 4, 2, 2, 8, 8, 8, 2, 2, 1, 4, 3, 5, 0, 8, 1, 2, 9, 8, 4, 1, 6, 6, 2, 9, 8, 9, 4, 7, 7, 9, 9, 0, 7, 8, 5, 0, 6, 3, 2, 6, 5, 9, 7, 4 )
crd[1] : ( 3, 3, 7, 4, 8, 5, 2, 1, 9, 2, 4, 9, 9, 0, 5, 5, 1, 7, 6, 6, 0, 3, 0, 3, 1, 4, 2, 2, 8, 8, 8, 2, 2, 1, 4, 3, 5, 0, 8, 1, 2, 9, 8, 4, 1, 6, 6, 2, 9, 8, 9, 4, 7, 7, 9, 9, 0, 7, 8, 5, 0, 6, 3, 2, 6, 5, 9, 7, 4, 8 )
values : ( 0.214585, 0.408529, 0.853403, 0.233939, 0.0583027, 0.281384, 0.293594, 0.661917, 0.557032, 0.783898, 0.664314, 0.406387, 0.81402, 0.166973, 0.0227121, 0.0900479, 0.722359, 0.461877, 0.161272, 0.501045, 0.152312, 0.69632, 0.446156, 0.381021, 0.301512, 0.630283, 0.361813, 0.0876499, 0.118006, 0.961898, 0.908581, 0.699707, 0.26587, 0.969176, 0.778751, 0.71689, 0.449362, 0.272242, 0.096391, 0.902602, 0.455776, 0.202363, 0.305957, 0.57922, 0.176773, 0.856614, 0.75852, 0.719463, 0.432093, 0.627309, 0.584098, 0.649847, 0.0844443, 0.415807, 0.0416142, 0.493991, 0.329861, 0.144524, 0.103403, 0.587645, 0.170593, 0.92512, 0.581061, 0.34687, 0.590915, 0.0228039, 0.958559, 0.482303, 0.782735, 0.08273 )
----
---- Sparse Tensor ----
nse = 70
dim = ( 10, 10 )
lvl = ( 10, 10 )
pos[1] : ( 0, 5, 10, 16, 22, 28, 33, 38, 43, 49, 55 )
crd[1] : ( 3, 5, 6, 7, 8, 2, 4, 6, 7, 9, 1, 2, 4, 6, 8, 9, 0, 1, 2, 3, 5, 7, 1, 2, 3, 7, 8, 9, 0, 1, 2, 5, 9, 0, 2, 3, 5, 6, 4, 6, 7, 8, 9, 1, 2, 4, 5, 8, 9, 0, 2, 4, 7, 8, 9 )
values : ( 0.69632, 0.381021, 0.0227121, 0.92512, 0.144524, 0.096391, 0.455776, 0.778751, 0.630283, 0.856614, 0.461877, 0.557032, 0.661917, 0.969176, 0.0876499, 0.26587, 0.664314, 0.590915, 0.118006, 0.432093, 0.202363, 0.446156, 0.301512, 0.34687, 0.408529, 0.449362, 0.853403, 0.176773, 0.361813, 0.71689, 0.214585, 0.0844443, 0.08273, 0.0583027, 0.406387, 0.272242, 0.170593, 0.722359, 0.293594, 0.0900479, 0.958559, 0.152312, 0.719463, 0.581061, 0.0228039, 0.501045, 0.75852, 0.782735, 0.233939, 0.161272, 0.415807, 0.103403, 0.0416142, 0.902602, 0.699707, 0.57922, 0.281384, 0.587645, 0.961898, 0.908581, 0.584098, 0.329861, 0.166973, 0.783898, 0.649847, 0.482303, 0.627309, 0.305957, 0.493991, 0.81402 )
----
```

I think it's a bug in conversion. I can try troubleshooting it, but I would need more details where to search for it.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to