Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "1.7.0"
version = "1.8.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[extensions]
FillArraysPDMatsExt = "PDMats"
FillArraysSparseArraysExt = "SparseArrays"
FillArraysStatisticsExt = "Statistics"

[compat]
Aqua = "0.5, 0.6, 0.7"
PDMats = "0.11.17"
Requires = "1"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "Base64", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics"]
test = ["Aqua", "Test", "Base64", "PDMats", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics"]
18 changes: 18 additions & 0 deletions ext/FillArraysPDMatsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module FillArraysPDMatsExt

if isdefined(Base, :get_extension)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style seems a bit unusual to me. Would it not be possible to import the packages directly, or is the namespace specification necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch is necessary, Requires needs relative imports (as shown also in the docs: https://github.com/JuliaPackaging/Requires.jl and https://pkgdocs.julialang.org/v1/creating-packages/#Requires.jl).

Moreover, in an extension one should import only the package itself and its weak dependency, and even stdlibs should be loaded indirectly: JuliaStats/LogExpFunctions.jl#63

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting, I had no idea about this transitive loading issue. Looks fine to me then

import FillArrays
import FillArrays.LinearAlgebra
import PDMats
else
import ..FillArrays
import ..FillArrays.LinearAlgebra
import ..PDMats
end

function PDMats.AbstractPDMat(a::LinearAlgebra.Diagonal{T,<:FillArrays.AbstractFill{T,1}}) where {T<:Real}
dim = size(a, 1)
return PDMats.ScalMat(dim, FillArrays.getindex_value(a.diag))
end

end # module
10 changes: 9 additions & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,18 @@ include("fillalgebra.jl")
include("fillbroadcast.jl")
include("trues.jl")

@static if !isdefined(Base, :get_extension)
if !isdefined(Base, :get_extension)
import Requires
include("../ext/FillArraysSparseArraysExt.jl")
include("../ext/FillArraysStatisticsExt.jl")
end
@static if !isdefined(Base, :get_extension)
function __init__()
Requires.@require PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" begin
include("../ext/FillArraysPDMatsExt.jl")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This codecov annotation is wrong - the line is hit since otherwise tests on Julia 1.6 would fail.

end
end
end

##
# print
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FillArrays, LinearAlgebra, SparseArrays, StaticArrays, ReverseDiff, Random, Base64, Test, Statistics
using FillArrays, LinearAlgebra, PDMats, SparseArrays, StaticArrays, ReverseDiff, Random, Base64, Test, Statistics
import FillArrays: AbstractFill, RectDiagonal, SquareEye

using Aqua
Expand All @@ -7,6 +7,8 @@ using Aqua
# only test formatting on VERSION >= v1.7
# https://github.com/JuliaTesting/Aqua.jl/issues/105#issuecomment-1551405866
project_toml_formatting = VERSION >= v"1.7",
# Requires is only loaded on Julia < 1.9
stale_deps = (ignore = VERSION < v"1.9-" ? Symbol[] : [:Requires],),
)
end

Expand Down Expand Up @@ -2194,3 +2196,13 @@ end
@test ReverseDiff.gradient(x -> sum(abs2.((Zeros{eltype(x)}(5) .+ zeros(5)) ./ x)), rand(5)) == zeros(5)
@test ReverseDiff.gradient(x -> sum(abs2.((zeros(5) .+ Zeros{eltype(x)}(5)) ./ x)), rand(5)) == zeros(5)
end

@testset "FillArraysPDMatsExt" begin
for diag in (Ones(5), Fill(4.1, 8))
a = @inferred(AbstractPDMat(Diagonal(diag)))
@test a isa ScalMat
@test a.dim == length(diag)
@test a.value == first(diag)
end
end