-
Notifications
You must be signed in to change notification settings - Fork 90
Add easy_rule for BigFloat division #2934
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
Conversation
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/internal_rules/bigfloat.jl b/src/internal_rules/bigfloat.jl
index 84d4478a..59bda768 100644
--- a/src/internal_rules/bigfloat.jl
+++ b/src/internal_rules/bigfloat.jl
@@ -67,19 +67,19 @@ function EnzymeRules.reverse(
return ()
end
-EnzymeRules.@easy_rule(+(a::BigFloat, b::Number), (1,1))
-EnzymeRules.@easy_rule(+(a::Number, b::BigFloat), (1,1))
+EnzymeRules.@easy_rule(+(a::BigFloat, b::Number), (1, 1))
+EnzymeRules.@easy_rule(+(a::Number, b::BigFloat), (1, 1))
EnzymeRules.@easy_rule(+(a::BigFloat, b::BigFloat), (1,1))
-EnzymeRules.@easy_rule(-(a::BigFloat, b::Number), (1,-1))
-EnzymeRules.@easy_rule(-(a::Number, b::BigFloat), (1,-1))
+EnzymeRules.@easy_rule(-(a::BigFloat, b::Number), (1, -1))
+EnzymeRules.@easy_rule(-(a::Number, b::BigFloat), (1, -1))
EnzymeRules.@easy_rule(-(a::BigFloat, b::BigFloat), (1,-1))
EnzymeRules.@easy_rule(*(a::BigFloat, b::BigFloat), (b, a))
EnzymeRules.@easy_rule(*(a::BigFloat, b::Number), (b, a))
EnzymeRules.@easy_rule(*(a::Number, b::BigFloat), (b, a))
-EnzymeRules.@easy_rule(/(a::BigFloat, b::Number), (one(a)/b, -(a/b^2)))
-EnzymeRules.@easy_rule(/(a::Number, b::BigFloat), (one(a)/b, -(a/b^2)))
-EnzymeRules.@easy_rule(/(a::BigFloat, b::BigFloat), (one(a)/b, -(a/b^2)))
-EnzymeRules.@easy_rule(Base.inv(a::BigFloat), (-(one(a)/a^2),))
+EnzymeRules.@easy_rule(/(a::BigFloat, b::Number), (one(a) / b, -(a / b^2)))
+EnzymeRules.@easy_rule(/(a::Number, b::BigFloat), (one(a) / b, -(a / b^2)))
+EnzymeRules.@easy_rule(/(a::BigFloat, b::BigFloat), (one(a) / b, -(a / b^2)))
+EnzymeRules.@easy_rule(Base.inv(a::BigFloat), (-(one(a) / a^2),))
EnzymeRules.@easy_rule(Base.sin(a::BigFloat), (cos(a),))
EnzymeRules.@easy_rule(Base.cos(a::BigFloat), (-sin(a),))
EnzymeRules.@easy_rule(Base.tan(a::BigFloat), (one(a) + Ω^2,))
diff --git a/test/rules/internal_rules/bigfloat.jl b/test/rules/internal_rules/bigfloat.jl
index c1818477..65a3bee2 100644
--- a/test/rules/internal_rules/bigfloat.jl
+++ b/test/rules/internal_rules/bigfloat.jl
@@ -13,17 +13,17 @@ using Test
bf64 = 0.56 # for testing mixed methods
dbf64 = 0.27 # for testing mixed methods
- @test autodiff(Enzyme.Forward, +, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da+db
- @test autodiff(Enzyme.Forward, +, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da+dbf64
- @test autodiff(Enzyme.Forward, -, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da-db
- @test autodiff(Enzyme.Forward, -, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da-dbf64
- @test autodiff(Enzyme.Forward, *, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ b*da + a*db
- @test autodiff(Enzyme.Forward, *, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ bf64*da + a*dbf64
- @test autodiff(Enzyme.Forward, /, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da/b - db * a/b^2
- @test autodiff(Enzyme.Forward, /, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da/bf64 - dbf64 * a/bf64^2
+ @test autodiff(Enzyme.Forward, +, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da + db
+ @test autodiff(Enzyme.Forward, +, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da + dbf64
+ @test autodiff(Enzyme.Forward, -, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da - db
+ @test autodiff(Enzyme.Forward, -, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da - dbf64
+ @test autodiff(Enzyme.Forward, *, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ b * da + a * db
+ @test autodiff(Enzyme.Forward, *, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ bf64 * da + a * dbf64
+ @test autodiff(Enzyme.Forward, /, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da / b - db * a / b^2
+ @test autodiff(Enzyme.Forward, /, Duplicated, Duplicated(a, da), Duplicated(bf64, dbf64))[:1] ≈ da / bf64 - dbf64 * a / bf64^2
- @test autodiff(Enzyme.Forward, inv, Duplicated, Duplicated(a, da))[:1] ≈ -(one(BigFloat)/a^2) * da
+ @test autodiff(Enzyme.Forward, inv, Duplicated, Duplicated(a, da))[:1] ≈ -(one(BigFloat) / a^2) * da
@test autodiff(Enzyme.Forward, sin, Duplicated, Duplicated(a, da))[:1] ≈ cos(a) * da
- @test autodiff(Enzyme.Forward, cos, Duplicated, Duplicated(a, da))[:1] ≈ -sin(a) * da
+ @test autodiff(Enzyme.Forward, cos, Duplicated, Duplicated(a, da))[:1] ≈ -sin(a) * da
@test autodiff(Enzyme.Forward, tan, Duplicated, Duplicated(a, da))[:1] ≈ autodiff(Enzyme.Forward, tan, Duplicated, Duplicated(af64, daf64))[1]
end |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #2934 +/- ##
===========================================
- Coverage 66.76% 50.87% -15.89%
===========================================
Files 65 13 -52
Lines 21522 1256 -20266
===========================================
- Hits 14369 639 -13730
+ Misses 7153 617 -6536 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Benchmark Results
Benchmark PlotsA plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/21907830982/artifacts/5466672695. |
|
Added some more arithmetic as a lark. The easy rule formulae match what Symbolics gives (thank you @vchuravy for checking) so I am very confused by why |
|
I think the CUDA stuff is unrelated, the windows fail might be pertinent though |
No description provided.