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

bug(?) on round/floor/ceil #112

Open
Moelf opened this issue Oct 14, 2020 · 3 comments
Open

bug(?) on round/floor/ceil #112

Moelf opened this issue Oct 14, 2020 · 3 comments

Comments

@Moelf
Copy link

Moelf commented Oct 14, 2020

this is probably edge case but:

julia> central_fdm(5, 1)(ceil, 0.1)
5.833333333333332

julia> central_fdm(5, 1)(ceil, 0.2)
-0.8333333333333333

JuliaDiff/ChainRules.jl#277

@oxinabox
Copy link
Member

Does this happen on FiniteDifference v0.10?

@oxinabox
Copy link
Member

It does happen in v0.10 also.

Finite differencing near discontinualities is hard.
I would hope we do a bit better that that though.

Probably though the right solution is to do forward_fdm for ciel and backward_fdm for floor
and the appropriate one depending on which side of 0.5 you are on for round
(You can pass the fdm method into the test_X functions from ChainRulesTestUtils as a kwarg)

julia> forward_fdm(5, 1)(ceil, 0.2)  # do this
-2.220446049250313e-15

julia> backward_fdm(5, 1)(ceil, 0.2)  # don't do this
-19.166666666666664

@wesselb
Copy link
Member

wesselb commented Jan 11, 2021

In v0.12, another way of doing this is by setting the max_range keyword appropriately:

julia> central_fdm(5, 1, max_range=9e-1)(ceil, 0.2)
6.085449991639748e-14

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

3 participants