Skip to content

Commit 157b6c5

Browse files
authored
Merge branch 'master' into patch-1
2 parents 0abb814 + 21bd031 commit 157b6c5

13 files changed

+1630
-393
lines changed

.github/workflows/Invalidations.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
- uses: julia-actions/setup-julia@v1
2020
with:
2121
version: '1'
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- uses: julia-actions/julia-buildpkg@v1
2424
- uses: julia-actions/julia-invalidations@v1
2525
id: invs_pr
2626

27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
with:
2929
ref: ${{ github.event.repository.default_branch }}
3030
- uses: julia-actions/julia-buildpkg@v1

.github/workflows/ci.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@ on:
44
branches:
55
- master
66
pull_request:
7+
8+
concurrency:
9+
group: build-${{ github.event.pull_request.number || github.ref }}-${{ github.workflow }}
10+
cancel-in-progress: true
11+
712
jobs:
13+
pre_job:
14+
# continue-on-error: true # Uncomment once integration is finished
15+
runs-on: ubuntu-latest
16+
# Map a step output to a job output
17+
outputs:
18+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
19+
steps:
20+
- id: skip_check
21+
uses: fkirc/skip-duplicate-actions@v5
822
test:
23+
needs: pre_job
24+
if: needs.pre_job.outputs.should_skip != 'true'
925
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
1026
runs-on: ${{ matrix.os }}
1127
strategy:
@@ -14,15 +30,15 @@ jobs:
1430
version:
1531
- '1.6'
1632
- '1'
17-
- '~1.9.0-0'
33+
- '~1.10.0-0'
1834
os:
1935
- ubuntu-latest
2036
- macOS-latest
2137
- windows-latest
2238
arch:
2339
- x64
2440
steps:
25-
- uses: actions/checkout@v3
41+
- uses: actions/checkout@v4
2642
- uses: julia-actions/setup-julia@v1
2743
with:
2844
version: ${{ matrix.version }}

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
julia-version: [1]
1919
os: [ubuntu-latest]
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
- uses: julia-actions/setup-julia@latest
2323
with:
2424
version: ${{ matrix.julia-version }}

.github/workflows/downstream.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: IntegrationTest
2+
on:
3+
push:
4+
branches: [master]
5+
tags: [v*]
6+
pull_request:
7+
paths-ignore:
8+
- 'LICENSE'
9+
- 'README.md'
10+
- '.github/workflows/TagBot.yml'
11+
12+
concurrency:
13+
group: build-${{ github.event.pull_request.number || github.ref }}-${{ github.workflow }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
pre_job:
18+
# continue-on-error: true # Uncomment once integration is finished
19+
runs-on: ubuntu-latest
20+
# Map a step output to a job output
21+
outputs:
22+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
23+
steps:
24+
- id: skip_check
25+
uses: fkirc/skip-duplicate-actions@v5
26+
test:
27+
needs: pre_job
28+
if: needs.pre_job.outputs.should_skip != 'true'
29+
name: ${{ matrix.package.group }}/${{ matrix.package.repo }}/${{ matrix.julia-version }}
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
fail-fast: true
33+
matrix:
34+
julia-version: ['1']
35+
os: [ubuntu-latest]
36+
package:
37+
- {repo: Distributions.jl, group: JuliaStats}
38+
- {repo: BlockArrays.jl, group: JuliaArrays}
39+
- {repo: LazyArrays.jl, group: JuliaArrays}
40+
- {repo: ArrayLayouts.jl, group: JuliaLinearAlgebra}
41+
- {repo: LazyBandedMatrices.jl, group: JuliaLinearAlgebra}
42+
- {repo: BandedMatrices.jl, group: JuliaLinearAlgebra}
43+
- {repo: BlockBandedMatrices.jl, group: JuliaLinearAlgebra}
44+
- {repo: InfiniteLinearAlgebra.jl, group: JuliaLinearAlgebra}
45+
- {repo: Optim.jl, group: JuliaNLSolvers}
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: julia-actions/setup-julia@v1
50+
with:
51+
version: ${{ matrix.julia-version }}
52+
arch: x64
53+
- uses: julia-actions/julia-buildpkg@latest
54+
- name: Clone Downstream
55+
uses: actions/checkout@v4
56+
with:
57+
repository: ${{ matrix.package.group }}/${{ matrix.package.repo }}
58+
path: downstream
59+
- name: Load this and run the downstream tests
60+
shell: julia --color=yes --project=downstream {0}
61+
run: |
62+
using Pkg
63+
try
64+
# force it to use this PR's version of the package
65+
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
66+
Pkg.update()
67+
Pkg.test(; coverage = true) # resolver may fail with test time deps
68+
catch err
69+
err isa Pkg.Resolve.ResolverError || rethrow()
70+
# If we can't resolve that means this is incompatible by SemVer and this is fine
71+
# It means we marked this as a breaking change, so we don't need to worry about
72+
# Mistakenly introducing a breaking change, as we have intentionally made one
73+
@info "Not compatible with this release. No problem." exception=err
74+
exit(0) # Exit immediately, as a success
75+
end
76+
- uses: julia-actions/julia-processcoverage@v1
77+
- uses: codecov/codecov-action@v3
78+
with:
79+
files: lcov.info

Project.toml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "1.0"
3+
version = "1.7.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
88
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
99
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1010

11+
[weakdeps]
12+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
13+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
14+
15+
[extensions]
16+
FillArraysSparseArraysExt = "SparseArrays"
17+
FillArraysStatisticsExt = "Statistics"
18+
1119
[compat]
12-
Aqua = "0.5, 0.6"
20+
Aqua = "0.5, 0.6, 0.7"
21+
LinearAlgebra = "1.6"
22+
Random = "1.6"
23+
SparseArrays = "1.6"
24+
Statistics = "1.6"
1325
julia = "1.6"
1426

1527
[extras]
1628
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1729
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
30+
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
31+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1832
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
33+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1934
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2035

2136
[targets]
22-
test = ["Aqua", "Test", "Base64", "StaticArrays"]
37+
test = ["Aqua", "Test", "Base64", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics"]

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
Julia package to lazily represent matrices filled with a single entry,
1212
as well as identity matrices. This package exports the following types:
13-
`Eye`, `Fill`, `Ones`, `Zeros`, `Trues` and `Falses`.
13+
`Eye`, `Fill`, `Ones`, `Zeros`, `Trues`, `Falses`, and `OneElement`.
1414

1515

1616
The primary purpose of this package is to present a unified way of constructing
@@ -30,6 +30,9 @@ julia> Zeros(5, 6)
3030
julia> Zeros{Int}(2, 3)
3131
2×3 Zeros{Int64}
3232

33+
julia> Zeros(Int, 2, 3) # can also specify the type as an argument
34+
2×3 Zeros{Int64}
35+
3336
julia> Ones{Int}(5)
3437
5-element Ones{Int64}
3538

@@ -49,6 +52,14 @@ julia> Trues(2, 3)
4952

5053
julia> Falses(2)
5154
2-element Zeros{Bool}
55+
56+
julia> OneElement(3.0, (2,1), (5,6))
57+
5×6 OneElement{Float64, 2, Tuple{Int64, Int64}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}:
58+
59+
3.0
60+
61+
62+
5263
```
5364

5465
They support conversion to other matrix types like `Array`, `SparseVector`, `SparseMatrix`, and `Diagonal`:

ext/FillArraysSparseArraysExt.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module FillArraysSparseArraysExt
2+
3+
using SparseArrays
4+
import Base: convert, kron
5+
using FillArrays
6+
using FillArrays: RectDiagonalFill, RectOrDiagonalFill, ZerosVector, ZerosMatrix, getindex_value
7+
using LinearAlgebra
8+
9+
##################
10+
## Sparse arrays
11+
##################
12+
SparseVector{T}(Z::ZerosVector) where T = spzeros(T, length(Z))
13+
SparseVector{Tv,Ti}(Z::ZerosVector) where {Tv,Ti} = spzeros(Tv, Ti, length(Z))
14+
15+
convert(::Type{AbstractSparseVector}, Z::ZerosVector{T}) where T = spzeros(T, length(Z))
16+
convert(::Type{AbstractSparseVector{T}}, Z::ZerosVector) where T= spzeros(T, length(Z))
17+
18+
SparseMatrixCSC{T}(Z::ZerosMatrix) where T = spzeros(T, size(Z)...)
19+
SparseMatrixCSC{Tv,Ti}(Z::Zeros{T,2,Axes}) where {Tv,Ti<:Integer,T,Axes} = spzeros(Tv, Ti, size(Z)...)
20+
21+
convert(::Type{AbstractSparseMatrix}, Z::ZerosMatrix{T}) where T = spzeros(T, size(Z)...)
22+
convert(::Type{AbstractSparseMatrix{T}}, Z::ZerosMatrix) where T = spzeros(T, size(Z)...)
23+
24+
convert(::Type{AbstractSparseArray}, Z::Zeros{T}) where T = spzeros(T, size(Z)...)
25+
convert(::Type{AbstractSparseArray{Tv}}, Z::Zeros{T}) where {T,Tv} = spzeros(Tv, size(Z)...)
26+
convert(::Type{AbstractSparseArray{Tv,Ti}}, Z::Zeros{T}) where {T,Tv,Ti} = spzeros(Tv, Ti, size(Z)...)
27+
convert(::Type{AbstractSparseArray{Tv,Ti,N}}, Z::Zeros{T,N}) where {T,Tv,Ti,N} = spzeros(Tv, Ti, size(Z)...)
28+
29+
SparseMatrixCSC{Tv}(Z::Eye{T}) where {T,Tv} = SparseMatrixCSC{Tv}(I, size(Z)...)
30+
# works around missing `speye`:
31+
SparseMatrixCSC{Tv,Ti}(Z::Eye{T}) where {T,Tv,Ti<:Integer} =
32+
convert(SparseMatrixCSC{Tv,Ti}, SparseMatrixCSC{Tv}(I, size(Z)...))
33+
34+
convert(::Type{AbstractSparseMatrix}, Z::Eye{T}) where {T} = SparseMatrixCSC{T}(I, size(Z)...)
35+
convert(::Type{AbstractSparseMatrix{Tv}}, Z::Eye{T}) where {T,Tv} = SparseMatrixCSC{Tv}(I, size(Z)...)
36+
37+
convert(::Type{AbstractSparseArray}, Z::Eye{T}) where T = SparseMatrixCSC{T}(I, size(Z)...)
38+
convert(::Type{AbstractSparseArray{Tv}}, Z::Eye{T}) where {T,Tv} = SparseMatrixCSC{Tv}(I, size(Z)...)
39+
40+
41+
convert(::Type{AbstractSparseArray{Tv,Ti}}, Z::Eye{T}) where {T,Tv,Ti} =
42+
convert(SparseMatrixCSC{Tv,Ti}, Z)
43+
convert(::Type{AbstractSparseArray{Tv,Ti,2}}, Z::Eye{T}) where {T,Tv,Ti} =
44+
convert(SparseMatrixCSC{Tv,Ti}, Z)
45+
46+
function SparseMatrixCSC{Tv}(R::RectOrDiagonalFill) where {Tv}
47+
SparseMatrixCSC{Tv,eltype(axes(R,1))}(R)
48+
end
49+
function SparseMatrixCSC{Tv,Ti}(R::RectOrDiagonalFill) where {Tv,Ti}
50+
Base.require_one_based_indexing(R)
51+
v = parent(R)
52+
J = getindex_value(v)*I
53+
SparseMatrixCSC{Tv,Ti}(J, size(R))
54+
end
55+
56+
# TODO: remove in v2.0
57+
@deprecate kron(E1::RectDiagonalFill, E2::RectDiagonalFill) kron(sparse(E1), sparse(E2))
58+
59+
end # module

ext/FillArraysStatisticsExt.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module FillArraysStatisticsExt
2+
3+
import Statistics: mean, var, cov, cor
4+
using LinearAlgebra: diagind
5+
6+
using FillArrays
7+
using FillArrays: AbstractFill, AbstractFillVector, AbstractFillMatrix, getindex_value
8+
9+
mean(A::AbstractFill; dims=(:)) = mean(identity, A; dims=dims)
10+
function mean(f::Union{Function, Type}, A::AbstractFill; dims=(:))
11+
val = float(f(getindex_value(A)))
12+
dims isa Colon ? val :
13+
Fill(val, ntuple(d -> d in dims ? 1 : size(A,d), ndims(A))...)
14+
end
15+
16+
17+
function var(A::AbstractFill{T}; corrected::Bool=true, mean=nothing, dims=(:)) where {T<:Number}
18+
dims isa Colon ? zero(float(T)) :
19+
Zeros{float(T)}(ntuple(d -> d in dims ? 1 : size(A,d), ndims(A))...)
20+
end
21+
22+
cov(::AbstractFillVector{T}; corrected::Bool=true) where {T<:Number} = zero(float(T))
23+
cov(A::AbstractFillMatrix{T}; corrected::Bool=true, dims::Integer=1) where {T<:Number} =
24+
Zeros{float(T)}(size(A, 3-dims), size(A, 3-dims))
25+
26+
cor(::AbstractFillVector{T}) where {T<:Number} = one(float(T))
27+
function cor(A::AbstractFillMatrix{T}; dims::Integer=1) where {T<:Number}
28+
out = fill(float(T)(NaN), size(A, 3-dims), size(A, 3-dims))
29+
out[diagind(out)] .= 1
30+
out
31+
end
32+
33+
end # module

0 commit comments

Comments
 (0)