Skip to content

ForwardDiff.gradient(x->log(1/max(1f-20,x[1])), zeros(Float32,1))) returns [NaN32] #287

Closed

Description

@micklat

Hi and thanks for ForwardDiff!

I've ran into what seems like a bug:

import ForwardDiff

println("This should be 0: ",
    ForwardDiff.gradient(x->log(1/max(1f-10,x[1])), zeros(Float32,1)))

println("This should be 0 too: ",
    ForwardDiff.gradient(x->log(1/max(1f-20,x[1])), zeros(Float32,1)))

output is:

This should be 0: Float32[-0.0]
This should be 0 too: Float32[NaN32]

I guess this looks like some kind of overflow problem, but the number isn't that big, so I wouldn't expect overflow here.

ForwardDiff version is 0.7
julia version is 0.6.2 (2017-12-13 18:08 UTC) x86_64-linux-gnu.

HTH.

Activity

  1. fredrikekre commented on Jan 5, 2018

    @fredrikekre
    Contributor

    You can set

    const NANSAFE_MODE_ENABLED = false
    to true, see #179 and linked issues

  2. micklat commented on Jan 5, 2018

    @micklat
    Author

    Thanks, that worked around it! I wonder how nans got into this in the first place.

  3. micklat commented on Jan 5, 2018

    @micklat
    Author

    Oh I see, the drivative of 1/x overflows when x=1f-20.

  4. jrevels commented on Jan 18, 2018

    @jrevels
    Member

    Closing since this seems resolved, but feel to reopen if there's still an issue here!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions