-
Notifications
You must be signed in to change notification settings - Fork 64
Deprecate One()
#357
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
Deprecate One()
#357
Changes from all commits
3037ae2
ecbe953
0449df0
32143e2
61ac743
821ad3a
7de64f4
4ca0f15
08453d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,73 @@ | ||
| # Define some rules to test One on | ||
| dummy_identity(x) = x | ||
| @scalar_rule(dummy_identity(x), One()) | ||
|
|
||
| very_nice(x, y) = x + y | ||
| @scalar_rule(very_nice(x, y), (One(), One())) | ||
|
|
||
| @testset "deprecations" begin | ||
| @test ChainRulesCore.AbstractDifferential === ChainRulesCore.AbstractTangent | ||
| @test Zero === ZeroTangent | ||
| @test DoesNotExist === NoTangent | ||
| @test Composite === Tangent | ||
| @test_deprecated One() | ||
| end | ||
|
|
||
| @testset "One()" begin | ||
|
|
||
| o = One() | ||
| @test extern(o) === true | ||
| @test o + o == 2 | ||
| @test o + 1 == 2 | ||
| @test 1 + o == 2 | ||
| @test o * o == o | ||
| @test o * 17 == 17 | ||
| @test 6 * o == 6 | ||
| @test dot(2 + im, o) == 2 - im | ||
| @test dot(o, 2 + im) == 2 + im | ||
| for x in o | ||
| @test x === o | ||
| end | ||
| @test broadcastable(o) isa Ref{One} | ||
| @test conj(o) == o | ||
|
|
||
| @test reim(o) === (One(), ZeroTangent()) | ||
| @test real(o) === One() | ||
| @test imag(o) === ZeroTangent() | ||
|
|
||
| @test complex(o) === o | ||
| @test complex(o, ZeroTangent()) === o | ||
| @test complex(ZeroTangent(), o) === im | ||
|
|
||
| @test frule((nothing, nothing, 5.0), Core._apply, dummy_identity, 4.0) == (4.0, 5.0) | ||
|
|
||
| @testset "broadcasting One" begin | ||
| sx = @SVector [1, 2] | ||
| sy = @SVector [3, 4] | ||
|
|
||
| # Test that @scalar_rule and `One()` play nice together, w.r.t broadcasting | ||
| @inferred frule((ZeroTangent(), sx, sy), very_nice, 1, 2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this testing? it doesn't appear to be using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is testing that |
||
| end | ||
|
|
||
| @testset "interaction with other types" begin | ||
| c = Tangent{Foo}(y=1.5, x=2.5) | ||
| @test One() * c === c | ||
| @test c * One() === c | ||
|
|
||
| z = ZeroTangent() | ||
| @test zero(One()) === z | ||
| @test zero(One) === z | ||
|
|
||
| ni = ChainRulesCore.NotImplemented( | ||
| @__MODULE__, LineNumberNode(@__LINE__, @__FILE__), "error" | ||
| ) | ||
| @test ni + One() === ni | ||
| @test One() + ni === ni | ||
| E = ChainRulesCore.NotImplementedException | ||
| @test_throws E ni - One() | ||
| @test_throws E One() - ni | ||
| @test_throws E One() * ni | ||
| @test_throws E dot(ni, One()) | ||
| @test_throws E dot(One(), ni) | ||
| end | ||
| end | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,13 @@ cool(x, y) = x + y + 1 | |
|
|
||
| # a rule we define so we can test rules | ||
| dummy_identity(x) = x | ||
| @scalar_rule(dummy_identity(x), One()) | ||
| @scalar_rule(dummy_identity(x), true) | ||
|
|
||
| nice(x) = 1 | ||
| @scalar_rule(nice(x), ZeroTangent()) | ||
|
|
||
| very_nice(x, y) = x + y | ||
| @scalar_rule(very_nice(x, y), (One(), One())) | ||
| sum_two(x, y) = x + y | ||
| @scalar_rule(sum_two(x, y), (true, true)) | ||
|
|
||
| complex_times(x) = (1 + 2im) * x | ||
| @scalar_rule(complex_times(x), 1 + 2im) | ||
|
|
@@ -116,12 +116,12 @@ _second(t) = Base.tuple_type_head(Base.tuple_type_tail(t)) | |
|
|
||
| @test frule((nothing, nothing, 5.0), Core._apply, dummy_identity, 4.0) == (4.0, 5.0) | ||
|
|
||
| @testset "broadcasting One" begin | ||
| @testset "broadcasting true" begin | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this name and comments relate to the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we don't need this test anymore? |
||
| sx = @SVector [1, 2] | ||
| sy = @SVector [3, 4] | ||
|
|
||
| # Test that @scalar_rule and `One()` play nice together, w.r.t broadcasting | ||
| @inferred frule((ZeroTangent(), sx, sy), very_nice, 1, 2) | ||
| # Test that @scalar_rule and `true` play nice together, w.r.t broadcasting | ||
| @inferred frule((ZeroTangent(), sx, sy), sum_two, 1, 2) | ||
| end | ||
|
|
||
| @testset "complex inputs" begin | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.