Skip to content

Commit 0b0b896

Browse files
author
Kristoffer Carlsson
authored
move MakieCore and ChainRulesCore code to extensions (#479)
1 parent f3669e3 commit 0b0b896

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Project.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
1111
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1212

13+
[weakdeps]
14+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
15+
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
16+
17+
[extensions]
18+
PolynomialsChainRulesCoreExt = "ChainRulesCore"
19+
PolynomialsMakieCoreExt = "MakieCore"
20+
1321
[compat]
1422
ChainRulesCore = "1"
1523
MakieCore = "0.6"
1624
RecipesBase = "0.7, 0.8, 1"
1725
julia = "1.6"
1826

1927
[extras]
28+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
29+
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
2030
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
2131
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
2232
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -26,4 +36,4 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2636
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2737

2838
[targets]
29-
test = ["DualNumbers", "LinearAlgebra", "SparseArrays", "OffsetArrays", "SpecialFunctions", "Test"]
39+
test = ["ChainRulesCore", "DualNumbers", "LinearAlgebra", "SparseArrays", "OffsetArrays", "SpecialFunctions", "Test"]

src/chain_rules.jl renamed to ext/PolynomialsChainRulesCoreExt.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
module PolynomialsChainRulesCoreExt
2+
3+
using Polynomials
14
import ChainRulesCore
25

36
function ChainRulesCore.frule(
@@ -9,8 +12,9 @@ function ChainRulesCore.frule(
912
p(x), derivative(p)(x)*Δx
1013
end
1114

12-
1315
function ChainRulesCore.rrule(p::AbstractPolynomial, x)
1416
_pullback(ΔΩ) = (ChainRulesCore.NoTangent(), derivative(p)(x))
1517
return (p(x), _pullback)
1618
end
19+
20+
end
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
module PolynomialsMakieCoreExt
2+
3+
using Polynomials
14
import MakieCore
25

3-
function MakieCore.convert_arguments(P::Type{<:MakieCore.XYBased}, p::AbstractPolynomial)
4-
xs = poly_interval(p)
6+
function MakieCore.convert_arguments(P::Type{<:MakieCore.XYBased}, p::AbstractPolynomial)
7+
xs = Polynomials.poly_interval(p)
58
return MakieCore.convert_arguments(P, xs, p.(xs))
69
end
710

811
MakieCore.plottype(p::AbstractPolynomial) = MakieCore.Lines
12+
13+
end

src/Polynomials.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Base: evalpoly
77
include("abstract.jl")
88
include("show.jl")
99
include("plots.jl")
10-
include("makie.jl")
1110
include("contrib.jl")
1211

1312
# Interface for all AbstractPolynomials
@@ -35,7 +34,12 @@ include("rational-functions/plot-recipes.jl")
3534

3635
# compat; opt-in with `using Polynomials.PolyCompat`
3736
include("polynomials/Poly.jl")
38-
include("chain_rules.jl")
37+
38+
if !isdefined(Base, :get_extension)
39+
include("../ext/PolynomialsChainRulesCoreExt.jl")
40+
include("../ext/PolynomialsMakieCoreExt.jl")
41+
end
42+
3943
include("precompiles.jl")
4044

4145
end # module

0 commit comments

Comments
 (0)