Skip to content

Commit

Permalink
Add FillArrays extension
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Oct 17, 2023
1 parent 187f741 commit 1a1f8e4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ jobs:
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- name: Downgrade FillArrays on Julia 1.0 to fix compat conflicts with BandedMatrices
if: ${{ matrix.version }} == '1.0'
run: |
import Pkg
Pkg.instantiate()
Pkg.add(Pkg.PackageSpec(; name="FillArrays", uuid="1a297f60-69ca-5386-bcde-b61e274b549b", version="0.10"))
shell: julia --project=. --color=yes {0}
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
Expand Down
11 changes: 10 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.27"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[compat]
FillArrays = "0.10, 0.11, 0.12, 1"
julia = "1"

[extensions]
PDMatsFillArraysExt = "FillArrays"

[extras]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["BandedMatrices", "StaticArrays", "Test"]
test = ["BandedMatrices", "FillArrays", "StaticArrays", "Test"]

[weakdeps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
11 changes: 11 additions & 0 deletions ext/PDMatsFillArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module PDMatsFillArraysExt

using PDMats: PDMats, LinearAlgebra
using FillArrays: FillArrays

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
4 changes: 4 additions & 0 deletions src/PDMats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ module PDMats

include("deprecates.jl")

# FillArrays support on Julia < 1.9
if !isdefined(Base, :get_extension)
include("../ext/PDMatsFillArraysExt.jl")
end
end # module
10 changes: 10 additions & 0 deletions test/ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using FillArrays

@testset "PDMatsFillArraysExt" 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 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include("testutils.jl")
tests = ["pdmtypes", "abstracttypes", "addition", "generics", "kron", "chol", "specialarrays", "sqrt"]
tests = ["pdmtypes", "abstracttypes", "addition", "generics", "kron", "chol", "specialarrays", "sqrt", "ext"]
println("Running tests ...")

for t in tests
Expand Down

0 comments on commit 1a1f8e4

Please sign in to comment.