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

filtering for isnan can result in NaN gradient #34

Open
jonny-so opened this issue Jun 4, 2019 · 1 comment
Open

filtering for isnan can result in NaN gradient #34

jonny-so opened this issue Jun 4, 2019 · 1 comment

Comments

@jonny-so
Copy link

jonny-so commented Jun 4, 2019

This works as expected

function test(x)
    y = [1.0, NaN, 1.0]
    sum(filter(!isnan, x.-y))
end

julia> Tracker.gradient(test, [1, 2, 3])
([1.0, 0.0, 1.0] (tracked),)

This does not

function test2(x)
    y = [1.0, NaN, 2.0]
    sum(filter(!isnan, (x.-y).^2))
end
julia> Tracker.gradient(test2, [1,2,3])
([0.0, NaN, 2.0] (tracked),)

I wouldn't expect the computation (x[2]-y[2])^2 to be in the graph for the result, so I don't understand why this would return NaN. Have I missed something?

@jonny-so
Copy link
Author

jonny-so commented Jun 4, 2019

Tracker version 0.2.2

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

No branches or pull requests

1 participant