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

Add Fastmath operators #388

Merged
merged 3 commits into from
Nov 4, 2019
Merged

Add Fastmath operators #388

merged 3 commits into from
Nov 4, 2019

Conversation

Satya758
Copy link

@Satya758 Satya758 commented Nov 1, 2019

Fixes issue #90

  1. Basic idea is to apply @adjoint macro to all defined fastmath operators.
  2. This is done by looping over fastmath operators and then retrieving defined differentiation expression for each from DiffRules.
  3. Using differentiation expression create adjoint function simillar to https://github.com/FluxML/Zygote.jl/blob/master/src/lib/number.jl#L7

I have added bunch of test cases covering unary and binary operators treating normal operators as a expected value.


fastf = fast_op[f]

if unarydx != nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a strange way to write it. Why not just test hasdiffrule directly here?


DiffRules._abs_deriv(x::Complex) = x/abs(x)
fastmath()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why split this out rather than using a top-level loop as above?

@MikeInnes
Copy link
Member

This is very useful, thanks!

There are quite a few whitespace changes unrelated to the main issue being fixed. While many are useful it would be better to have them as a separate PR, to make review easier.

@Satya758
Copy link
Author

Satya758 commented Nov 4, 2019

I have updated the code with given suggestions


# Function add adjoint for Fastmath operations
# DiffRules is used to find derivatives for each operation
for f in keys(fast_op)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for f in keys(fast_op)
for (f, fastf) in fast_op

@MikeInnes
Copy link
Member

👍 Thanks!

bors r+

bors bot added a commit that referenced this pull request Nov 4, 2019
388: Add Fastmath operators r=MikeInnes a=Satya758

Fixes issue #90 

1. Basic idea is to apply @adjoint macro to all defined fastmath operators.
2. This is done by looping over fastmath [operators](https://github.com/JuliaLang/julia/blob/master/base/fastmath.jl#L31) and then retrieving defined differentiation expression for each from [DiffRules](https://github.com/JuliaDiff/DiffRules.jl/blob/master/src/rules.jl).
3. Using differentiation expression create adjoint function simillar to https://github.com/FluxML/Zygote.jl/blob/master/src/lib/number.jl#L7

I have added bunch of test cases covering unary and binary operators treating normal operators as a expected value.
 


Co-authored-by: Satya <satyap.kommaraju@gmail.com>
@bors
Copy link
Contributor

bors bot commented Nov 4, 2019

Build succeeded

@bors bors bot merged commit 61eedf4 into FluxML:master Nov 4, 2019
@Satya758 Satya758 deleted the fastmath branch November 4, 2019 16:24
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

Successfully merging this pull request may close these issues.

2 participants