Issue 107477
Summary [mlir][sparse] Adding two COO tensors and returning result fails with Python bindings
Labels mlir
Assignees
Reporter mtsokol
    Hi!

I've been writing a short program with MLIR and Python bindings and I noticed that adding two COO tensors and returning COO result throws an error:
```
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_fill_insert
Aborted (core dumped)
```

**I'm using LLVM** `19.1.0-rc3`

---

My setup is:
1. I create NumPy arrays `pos` (of dtype `int64`), `index` (of dtype `int64`), and `data` (of dtype `float64`) and pass them to MLIR module that assembles them and returns a pointer to the COO tensor
2. Then I pass that pointer to another MLIR module that adds COO tensors element-wise `add(a, a)` and returns the result as a pointer to the resulting COO.

It fails with an error pasted above. Here's a full python script that reproduces it (less than 100 lines): https://gist.github.com/mtsokol/a1b83817c02353242ae6be4fae10eb95

---

I did spend some time investigating it and I think the culprit is with returning the result COO tensor after addition. If I convert the COO tensor to a dense one before returning (so step 3. let's say) the program works: https://gist.github.com/mtsokol/06e0f5421b190aaa4eed0dcf560dd3bb

Also, it shouldn't be the problem with the way I return the COO tensor. To prove it here's one more gist (mostly copied from previous ones) where I assemble a COO tensor, return a pointer to it and pass it to another module call "disassemble" and return constituent NumPy arrays and successfully compare them with original ones: https://gist.github.com/mtsokol/d4b4c16a440de03f700601e91cd7f745

My suspicion the issue is with the returning COO tensor that is the result of addition directly from the call, which I would classify it as a bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to