Skip to content

fma and muladd ignore NaN-safe mode #860

Open

Description

@devmotion

With NaN-safe mode enabled (nansafe_mode = true), fma and muladd propagate NaN partials for dual numbers with zero partials, unlike the equivalent x * y + z:

julia> using ForwardDiff: Dual  # nansafe_mode = true

julia> x, y, z = Dual(Inf, 0.0), Dual(2.0, 0.0), Dual(0.0, 0.0);

julia> x * y + z
Dual{Nothing}(Inf,0.0)

julia> muladd(x, y, z)
Dual{Nothing}(Inf,NaN)

julia> fma(x, y, z)
Dual{Nothing}(Inf,NaN)

julia> x, y, z = Dual(1.0, 0.0), Inf, Dual(0.0, 1.0);

julia> x * y + z
Dual{Nothing}(Inf,1.0)

julia> muladd(x, y, z)
Dual{Nothing}(Inf,NaN)

julia> fma(x, y, z)
Dual{Nothing}(Inf,NaN)

The methods for three dual arguments, and for dual-real-dual arguments, compute the partials with fma/muladd directly instead of going through the NaN-safe multiplication. Related: #857, #858.

ForwardDiff master (a3c0f4f), Julia 1.13.1, macOS aarch64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions