willow-ahrens / Finch.jl

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

Incorrect eltype in `tensordot` for `Complex` inputs #576

Closed mtsokol closed 3 weeks ago

mtsokol commented 1 month ago

Hi @willow-ahrens,

While adapting tensordot to the Array API standard I noticed that for complex inputs it returns a union type of float and complex, instead of just complex:

using Finch

a = zeros(ComplexF64, 2, 1)
a[1, 1] = 1.8 + 1.8im
a[2, 1] = 4.8 + 4.8im

b = [1 + 1im, 2 + 2im]

a_tns = Tensor(a)
b_tns = Tensor(b)

res = Finch.tensordot(a_tns, b_tns, ((1,), (1,)))

eltype(res)  # Union{Float64, ComplexF64} but should be ComplexF64