Skip to content

Commit

Permalink
Merge c82796f into 7f8af88
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Aug 21, 2019
2 parents 7f8af88 + c82796f commit 2b37970
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@scalar_rule(one(x), Zero())
@scalar_rule(zero(x), Zero())
@scalar_rule(abs2(x), Wirtinger(x', x))
@scalar_rule(log(x), inv(x))
@scalar_rule(log10(x), inv(x) / log(oftype(x, 10)))
Expand Down
17 changes: 17 additions & 0 deletions test/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,22 @@ end
rrule_test(identity, randn(rng), (randn(rng), randn(rng)))
rrule_test(identity, randn(rng, 4), (randn(rng, 4), randn(rng, 4)))
end

@testset "Constants" begin
function test_constant(f, x, expected)
y, rule = frule(f, x)
@test y == expected
@test extern(rule(1)) == 0.0

y, rule = rrule(f, x)
@test y == expected
@test extern(rule(1)) == 0.0
end
test_constant(one, 5, 1)
test_constant(one, -4.1, 1)

test_constant(zero, 5, 0)
test_constant(zero, -4.1, 0)
end
end
# TODO: Non-trig stuff

0 comments on commit 2b37970

Please sign in to comment.