diff --git a/Project.toml b/Project.toml index 5ec4a34c..20764dd5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,18 +1,21 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.7.0" +version = "1.8.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" 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" @@ -20,6 +23,7 @@ FillArraysStatisticsExt = "Statistics" Aqua = "0.8" Base64 = "1.6" LinearAlgebra = "1.6" +PDMats = "0.11.17" Random = "1.6" ReverseDiff = "1" SparseArrays = "1.6" @@ -31,6 +35,7 @@ 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" @@ -38,4 +43,4 @@ 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"] diff --git a/ext/FillArraysPDMatsExt.jl b/ext/FillArraysPDMatsExt.jl new file mode 100644 index 00000000..d5a0892d --- /dev/null +++ b/ext/FillArraysPDMatsExt.jl @@ -0,0 +1,12 @@ +module FillArraysPDMatsExt + +import FillArrays +import FillArrays.LinearAlgebra +import PDMats + +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 diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 7ca7b78e..d6d21f67 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -669,7 +669,8 @@ include("fillalgebra.jl") include("fillbroadcast.jl") include("trues.jl") -@static if !isdefined(Base, :get_extension) +if !isdefined(Base, :get_extension) + include("../ext/FillArraysPDMatsExt.jl") include("../ext/FillArraysSparseArraysExt.jl") include("../ext/FillArraysStatisticsExt.jl") end diff --git a/test/runtests.jl b/test/runtests.jl index aee883da..ef9f463c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -2193,3 +2193,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 +