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

Fix warnings #143

Merged
merged 6 commits into from
Dec 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "0.2.4"
version = "0.2.5"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
2 changes: 0 additions & 2 deletions src/ChainRules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ include("rulesets/LinearAlgebra/factorization.jl")
function __init__()
@require NaNMath="77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" begin
include("rulesets/packages/NaNMath.jl")
using .NaNMathGlue
end

@require SpecialFunctions="276daf66-3868-5448-9aa4-cd146d93841b" begin
include("rulesets/packages/SpecialFunctions.jl")
using .SpecialFunctionsGlue
end
end

Expand Down
9 changes: 1 addition & 8 deletions src/rulesets/Base/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ function frule(::typeof(sum), x)
return sum(x), sum_pushforward
end

function rrule(::typeof(sum), x::AbstractArray{<:Real})
mattBrzezinski marked this conversation as resolved.
Show resolved Hide resolved
function sum_pullback(ȳ)
return (NO_FIELDS, @thunk(fill(ȳ, size(x))))
end
return sum(x), sum_pullback
end

function rrule(::typeof(sum), f, x::AbstractArray{<:Real}; dims=:)
y, mr_pullback = rrule(mapreduce, f, Base.add_sum, x; dims=dims)
function sum_pullback(ȳ)
Expand All @@ -73,7 +66,7 @@ function rrule(::typeof(sum), f, x::AbstractArray{<:Real}; dims=:)
end

function rrule(::typeof(sum), x::AbstractArray{<:Real}; dims=:)
y, inner_pullback = rrule(sum, identity, x; dims=dims)
y, inner_pullback = rrule(sum, identity, x; dims=dims)
function sum_pullback(ȳ)
return NO_FIELDS, last(inner_pullback(ȳ))
end
Expand Down
6 changes: 1 addition & 5 deletions src/rulesets/packages/NaNMath.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module NaNMathGlue
using ChainRulesCore
using ..NaNMath
using ..SpecialFunctions

@scalar_rule(NaNMath.sin(x), NaNMath.cos(x))
@scalar_rule(NaNMath.cos(x), -NaNMath.sin(x))
@scalar_rule(NaNMath.asin(x), inv(NaNMath.sqrt(1 - NaNMath.pow(x, 2))))
@scalar_rule(NaNMath.acos(x), -inv(NaNMath.sqrt(1 - NaNMath.pow(x, 2))))
@scalar_rule(NaNMath.acosh(x), inv(NaNMath.sqrt(NaNMath.pow(x, 2) - 1)))
@scalar_rule(NaNMath.tan(x), 1 + Ω^2)
@scalar_rule(NaNMath.atanh(x), inv(1 - NaNMath.pow(x, 2)))
@scalar_rule(NaNMath.log(x), inv(x))
@scalar_rule(NaNMath.log2(x), inv(x) / NaNMath.log(oftype(x, 2)))
Expand All @@ -22,5 +20,3 @@ using ..SpecialFunctions
@scalar_rule(NaNMath.min(x, y),
(ifelse((y < x) | (signbit(y) > signbit(x)), ifelse(isnan(y), One(), Zero()), ifelse(isnan(x), Zero(), One())),
ifelse((y < x) | (signbit(y) > signbit(x)), ifelse(isnan(y), Zero(), One()), ifelse(isnan(x), One(), Zero()))))

end #module
5 changes: 0 additions & 5 deletions src/rulesets/packages/SpecialFunctions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module SpecialFunctionsGlue
using ChainRulesCore
using ..SpecialFunctions


@scalar_rule(SpecialFunctions.erf(x), (2 / sqrt(π)) * exp(-x * x))
@scalar_rule(SpecialFunctions.erfc(x), -(2 / sqrt(π)) * exp(-x * x))
Expand Down Expand Up @@ -78,5 +75,3 @@ end
if isdefined(SpecialFunctions, :loggamma)
@scalar_rule(SpecialFunctions.loggamma(x), SpecialFunctions.digamma(x))
end

end #module