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 max, min, and abs. #11

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
@define_diffrule Base.lgamma(x) = :( digamma($x) )
@define_diffrule Base.Math.JuliaLibm.log1p(x) = :( inv($x + 1) )
@define_diffrule Base.transpose(x) = :( 1 )
@define_diffrule Base.abs(x) = :( $x > 0 ? one($x) : -one($x) )
Copy link
Member

Choose a reason for hiding this comment

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

Should we use signbit instead here (since, e.g. !(-0.0 < 0.0))? At least, this is what ForwardDiff's manual definition currently uses, though IIRC that decision was made fairly arbitrarily at the time...

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. Will make the change.


# binary #
#--------#
Expand All @@ -76,6 +77,8 @@
@define_diffrule Base.mod(x, y) = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :( z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -floor(z)), NaN)) )
@define_diffrule Base.rem(x, y) = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :( z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -trunc(z)), NaN)) )
@define_diffrule Base.rem2pi(x, r) = :( 1 ), :NaN
@define_diffrule Base.max(x, y) = :( $x > $y ? one($x) : zero($x) ), :( $x > $y ? zero($y) : one($y) )
@define_diffrule Base.min(x, y) = :( $x > $y ? zero($x) : one($x) ), :( $x > $y ? one($y) : zero($y) )

####################
# SpecialFunctions #
Expand Down