Skip to content

Commit 70752d4

Browse files
migrosserdpo
authored andcommitted
use Requires.jl for julia versions <1.9
1 parent d40dc47 commit 70752d4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
12+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1213

1314
[weakdeps]
1415
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

ext/LinearOperatorsChainRulesCoreExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module LinearOperatorsChainRulesCoreExt
22

33
using LinearOperators
4-
import ChainRulesCore
4+
isdefined(Base, :get_extension) ? (import ChainRulesCore) : (import ..ChainRulesCore)
55

66
function ChainRulesCore.frule((_, Δx, _), ::typeof(*), op::AbstractLinearOperator{T}, x::AbstractVector{S}) where {T, S}
77
y = op*x

src/LinearOperators.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,17 @@ include("TimedOperators.jl")
2828
include("utilities.jl")
2929
include("deprecated.jl")
3030

31+
# lazy loading of chainrules for Julia < 1.9
32+
@static if !isdefined(Base, :get_extension)
33+
import Requires
34+
end
35+
36+
@static if !isdefined(Base, :get_extension)
37+
function __init__()
38+
Requires.@require ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" begin
39+
include("../ext/LinearOperatorsChainRulesCoreExt.jl")
40+
end
41+
end
42+
end
43+
3144
end # module

0 commit comments

Comments
 (0)