Skip to content
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

simplify package extension for post Julia 1.10 #161

Open
wants to merge 4 commits into
base: yebai-patch-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[weakdeps]
Expand Down Expand Up @@ -45,7 +44,6 @@ LogDensityProblems = "2"
Optimisers = "0.2.16, 0.3, 0.4"
ProgressMeter = "1.6"
Random = "1"
Requires = "1.0"
StatsBase = "0.32, 0.33, 0.34"
julia = "1.10, 1.11.2"

Expand Down
19 changes: 6 additions & 13 deletions ext/AdvancedVIBijectorsExt.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@

module AdvancedVIBijectorsExt

if isdefined(Base, :get_extension)
using AdvancedVI
using Bijectors
using LinearAlgebra
using Optimisers
using Random
else
using ..AdvancedVI
using ..Bijectors
using ..LinearAlgebra
using ..Optimisers
using ..Random
end
using AdvancedVI
using Bijectors
using LinearAlgebra
using Optimisers
using Random

function AdvancedVI.apply(
op::ClipScale,
Expand Down Expand Up @@ -82,4 +74,5 @@ function AdvancedVI.reparam_with_entropy(
entropy = unconst_entropy + logjac
return samples, entropy
end

end
12 changes: 3 additions & 9 deletions ext/AdvancedVIEnzymeExt.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
module AdvancedVIEnzymeExt

if isdefined(Base, :get_extension)
using Enzyme
using AdvancedVI
using AdvancedVI: ADTypes, DiffResults
else
using ..Enzyme
using ..AdvancedVI
using ..AdvancedVI: ADTypes, DiffResults
end
using Enzyme
using AdvancedVI
using AdvancedVI: ADTypes, DiffResults

function AdvancedVI.restructure_ad_forward(::ADTypes.AutoEnzyme, restructure, params)
return restructure(params)::typeof(restructure.model)
Expand Down
16 changes: 0 additions & 16 deletions src/AdvancedVI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,4 @@ export optimize
include("utils.jl")
include("optimize.jl")

# optional dependencies
if !isdefined(Base, :get_extension) # check whether :get_extension is defined in Base
using Requires
end

@static if !isdefined(Base, :get_extension)
function __init__()
@require Bijectors = "76274a88-744f-5084-9051-94815aaf08c4" begin
include("../ext/AdvancedVIBijectorsExt.jl")
end
@require Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" begin
include("../ext/AdvancedVIEnzymeExt.jl")
end
end
end

end
Loading