Skip to content

Commit

Permalink
Add extension for PDMats (#303)
Browse files Browse the repository at this point in the history
* Add extension for PDMats

* Fix typo

* Make PDMats a dependency on Julia < 1.9

* Revert changes to Aqua tests

* Fix imports
  • Loading branch information
devmotion authored Nov 27, 2023
1 parent 1be2e11 commit b6fa0b4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
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"

[compat]
Aqua = "0.8"
Base64 = "1.6"
LinearAlgebra = "1.6"
PDMats = "0.11.17"
Random = "1.6"
ReverseDiff = "1"
SparseArrays = "1.6"
Expand All @@ -31,11 +35,12 @@ 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"]
12 changes: 12 additions & 0 deletions ext/FillArraysPDMatsExt.jl
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 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 Down Expand Up @@ -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

2 comments on commit b6fa0b4

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/96010

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.8.0 -m "<description of version>" b6fa0b497beae6bf275984b286f0d0da282504d9
git push origin v1.8.0

Please sign in to comment.