Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

muladd Doesn't propagate Zeros.Zero()s #9

Open
favba opened this issue Dec 30, 2023 · 0 comments · May be fixed by #10
Open

muladd Doesn't propagate Zeros.Zero()s #9

favba opened this issue Dec 30, 2023 · 0 comments · May be fixed by #10

Comments

@favba
Copy link

favba commented Dec 30, 2023

Hi there!
I'm using this package in a local package of mine and I noticed that Zeros.Zero() isn't propagating in the muladd function:

julia> muladd(Zeros.Zero(),2.0,Zeros.Zero())
0.0

I see in the source code some definitions for muladd but they are commented out. Why is that?
In my package I'm using the following method definitions to get my desired behavior:

for op in [:fma :muladd]
    @eval $op(::Zero, ::Zero, ::Zero) = Zero()
    @eval $op(::Zero,::Number,::Zero) = Zero()
    @eval $op(::Number,::Zero,::Zero) = Zero()
    @eval $op(x::Number, y::Number, ::Zero) = x*y
    @eval $op(::One, x::Number, y::Number) = x+y
    @eval $op(x::Number, ::One, y::Number) = x+y
    for T in (Real, Complex)  # Special definitions for Real and Complex to avoid method ambiguities.
        @eval $op(::Zero,::$T,::Zero) = Zero()
        @eval $op(::$T,::Zero,::Zero) = Zero()
        for T2 in (Real, Complex)
            @eval $op(x::$T, y::$T2, ::Zero) = x*y
            @eval $op(::One, x::$T, y::$T2) = x+y
            @eval $op(x::$T, ::One, y::$T2) = x+y
        end
    end
end

And it works as expected:

julia> muladd(𝟎,2.0,𝟎)
𝟎

Wouldn't having this method's definition in Zeros.jl be desirable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant