bsc-quantic / Tensors.jl

Tensors and Einstein Summation in Julia
https://bsc-quantic.github.io/Tensors.jl/
Apache License 2.0
0 stars 1 forks source link

Incorrect array typevar inference on `+(::Tensor{T,0}, ::Tensor{T,0}` #28

Closed mofeing closed 1 year ago

mofeing commented 1 year ago

When summing two scalar Tensors (Tensors that return 0 on ndims), the result is doubly-wrapped in a Tensor:

julia> a = Tensor(fill(rand()), ())
0-dimensional Tensor{Float64, 0, Array{Float64, 0}}:
0.6996548996696567

julia> b = Tensor(fill(rand()), ())
0-dimensional Tensor{Float64, 0, Array{Float64, 0}}:
0.8928731288094572

julia> a + b
0-dimensional Tensor{Tensor{Float64, 0, Array{Float64, 0}}, 0, Array{Tensor{Float64, 0, Array{Float64, 0}}, 0}}:
fill(1.592528028479114)

Although the value is correct, Tensors.parenttype on a+b returns Array{Tensor{Float64, 0, Array{Float64, 0}}, 0} instead of Array{Float64, 0}.

This probably is an automatic dispatch because Tensor <: AbstractArray.

mofeing commented 1 year ago

Fixed in https://github.com/bsc-quantic/Tensors.jl/commit/9690013eabae439a0cf905d71e3f2e39caf11d66

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/43

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/48

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/50

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/53

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/58

mofeing commented 1 year ago

Triggering TagBot for merged registry pull request: https://github.com/bsc-quantic/Registry/pull/59