willow-ahrens / Finch.jl

Sparse tensors in Julia and more! Datastructure-driven array programing language.
http://willowahrens.io/Finch.jl/
MIT License
159 stars 15 forks source link

Segfault when converting COO to Dense #511

Closed mtsokol closed 5 months ago

mtsokol commented 5 months ago

Hi @willow-ahrens,

I'm trying to convert empty COO tensor to a dense one but I get a segfault. Should I write it differently or is it a bug?

using Finch

tns_coo = Tensor(SparseCOO{2}(Element(0), (3,3)))  # empty coo
# with Tensor(SparseCOO{2}(Element(0), (3,3)), zeros(3,3)) it works

Tensor(Dense(Dense(Element(0))), tns_coo)  # segfault instead of dense 3x3
mtsokol commented 5 months ago

It looks like ptr field in uninitialized one is:

1-element Vector{Int64}:
 1

and for initialized it's:

2-element Vector{Int64}:
 1
 1
willow-ahrens commented 5 months ago

That syntax isn't supposed to initialize a tensor. Instead, pass the dimensions to the Tensor function. It looks like the relevant docs in https://github.com/willow-ahrens/Finch.jl/blob/c9588e252e5fb50b0b217fa73b0fae522d7817f0/src/tensors/fibers.jl#L24-L31 somehow didn't make it into the website, so I made a PR to do that.

mtsokol commented 5 months ago

Ah, then I used incorrect semantics, thank you!