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

Disappearing value in one-element 1-D Tensors #554

Closed mtsokol closed 4 months ago

mtsokol commented 4 months ago

Hi @willow-ahrens,

While implementing Array API standard I noticed that one-element 1-D tensors drop their values for some broadcasted operations:

julia> using Finch

julia> Tensor(ones(1))
Dense [1:1]
└─ [1]: 1.0

julia> broadcast(trunc, swizzle(Tensor(ones(1)), 1))  # <-- here 1.0 disappears
Dense [1:0]

julia> Tensor(ones(2))
Dense [1:2]
├─ [1]: 1.0
└─ [2]: 1.0

julia> broadcast(trunc, swizzle(Tensor(ones(2)), 1))
Dense [1:2]
├─ [1]: 1.0
└─ [2]: 1.0
willow-ahrens commented 4 months ago

I think this is a dup of https://github.com/willow-ahrens/Finch.jl/issues/533, and I'm currently working on a fix. I'll add these tests too and close this issue only if that resolves it