willow-ahrens / Finch.jl

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

Error for `SingleList` and `SingleRLE` in 2D Tensor creation #447

Closed mtsokol closed 6 months ago

mtsokol commented 6 months ago

Hi @willow-ahrens,

I wanted to adjust similar tests for SingleList and SingleRLE but I noticed that these levels can't be used in 2-dim tensors:

using Finch

arr = [0.0, 0.0, 2.0, 0.0, 0.0, 0.0]
dropdefaults!(Tensor(SingleList(Element(zero(eltype(arr))))), arr)  # passes

# restart interpreter
using Finch

mt = Matrix(reshape(1:25, (5, 5)))
dropdefaults!(Tensor(Dense(SingleList(Element(zero(eltype(mt)))))), mt) # fails
ERROR: Finch.FinchProtocolError("SingleListLevels can only be updated once")
Stacktrace:
  [1] macro expansion
    @ ~/JuliaProjects/Finch.jl/src/tensors/levels/singlelistlevels.jl:346 [inlined]
  [2] macro expansion
    @ ~/JuliaProjects/Finch.jl/src/looplets/lookups.jl:344 [inlined]
  [3] macro expansion
    @ ~/JuliaProjects/Finch.jl/src/environment.jl:50 [inlined]
willow-ahrens commented 6 months ago

I don't think this is a bug. The SingleListLevel is only capable of representing a single nonzero, but Matrix(reshape(1:25, (5, 5))) has 25 nonzeros

mtsokol commented 6 months ago

Ah, I missed that - thank you for an explanation!