Skip to content

Commit 3e50fd8

Browse files
authored
Replace AbstractTriangular by union (#1146)
* Replace AbstractTriangular by union * test on v1.6 & v1 * Keep testing on Julia v1.0 * adjust tests * fix core test
1 parent 6bbf550 commit 3e50fd8

File tree

17 files changed

+88
-65
lines changed

17 files changed

+88
-65
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ jobs:
1414
matrix:
1515
version:
1616
- '1.0'
17-
- '1.1'
18-
- '1.2'
19-
- '1.3'
20-
- '1.4'
17+
- '1.6'
18+
- '1'
2119
- 'nightly'
2220
os:
2321
- ubuntu-latest
@@ -31,13 +29,6 @@ jobs:
3129
# See https://github.com/marketplace/actions/setup-julia-environment
3230
# MacOS not available on x86
3331
- {os: 'macOS-latest', arch: 'x86'}
34-
# Don't test on all versions
35-
- {os: 'macOS-latest', version: '1.1'}
36-
- {os: 'macOS-latest', version: '1.2'}
37-
- {os: 'macOS-latest', version: '1.3'}
38-
- {os: 'windows-latest', version: '1.1'}
39-
- {os: 'windows-latest', version: '1.2'}
40-
- {os: 'windows-latest', version: '1.3'}
4132
steps:
4233
- uses: actions/checkout@v1
4334
- uses: julia-actions/setup-julia@latest
@@ -56,7 +47,7 @@ jobs:
5647
- uses: actions/checkout@v1
5748
- uses: julia-actions/setup-julia@latest
5849
with:
59-
version: '1.4'
50+
version: '1'
6051
- run: julia --project=docs -e '
6152
using Pkg;
6253
Pkg.develop(PackageSpec(; path=pwd()));

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "0.12.5"
3+
version = "0.12.6"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/lu.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ function _first_zero_on_diagonal(A::StaticMatrix{M,N,T}) where {M,N,T}
5858
end
5959
end
6060

61-
function _first_zero_on_diagonal(A::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix})
62-
_first_zero_on_diagonal(A.data)
63-
end
64-
6561
issuccess(F::LU) = _first_zero_on_diagonal(F.U) == 0
6662

6763
@generated function _lu(A::StaticMatrix{M,N,T}, pivot, check) where {M,N,T}

src/traits.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ Size(::Type{Transpose{T, A}}) where {T, A <: AbstractVecOrMat{T}} = Size(Size(A)
9393
Size(::Type{Symmetric{T, A}}) where {T, A <: AbstractMatrix{T}} = Size(A)
9494
Size(::Type{Hermitian{T, A}}) where {T, A <: AbstractMatrix{T}} = Size(A)
9595
Size(::Type{Diagonal{T, A}}) where {T, A <: AbstractVector{T}} = Size(Size(A)[1], Size(A)[1])
96-
Size(::Type{<:LinearAlgebra.AbstractTriangular{T, A}}) where {T,A} = Size(A)
96+
Size(::Type{UpperTriangular{T, A}}) where {T,A} = Size(A)
97+
Size(::Type{UnitUpperTriangular{T, A}}) where {T,A} = Size(A)
98+
Size(::Type{LowerTriangular{T, A}}) where {T,A} = Size(A)
99+
Size(::Type{UnitLowerTriangular{T, A}}) where {T,A} = Size(A)
97100

98101
@pure Size(::Type{<:AbstractArray{<:Any, N}}) where {N} = Size(ntuple(_ -> Dynamic(), N))
99102

src/triangular.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const StaticULT = Union{UpperTriangular{<:Any,<:StaticMatrix},LowerTriangular{<:Any,<:StaticMatrix}}
2+
const StaticUULT = Union{StaticULT,UnitUpperTriangular{<:Any,<:StaticMatrix},UnitLowerTriangular{<:Any,<:StaticMatrix}}
3+
14
@inline transpose(A::LinearAlgebra.LowerTriangular{<:Any,<:StaticMatrix}) =
25
LinearAlgebra.UpperTriangular(transpose(A.data))
36
@inline adjoint(A::LinearAlgebra.LowerTriangular{<:Any,<:StaticMatrix}) =
@@ -6,22 +9,23 @@
69
LinearAlgebra.LowerTriangular(transpose(A.data))
710
@inline adjoint(A::LinearAlgebra.UpperTriangular{<:Any,<:StaticMatrix}) =
811
LinearAlgebra.LowerTriangular(adjoint(A.data))
9-
@inline Base.:*(A::Adjoint{<:Any,<:StaticVecOrMat}, B::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}) =
12+
@inline Base.:*(A::Adjoint{<:Any,<:StaticVecOrMat}, B::StaticUULT) =
1013
adjoint(adjoint(B) * adjoint(A))
11-
@inline Base.:*(A::Transpose{<:Any,<:StaticVecOrMat}, B::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}) =
14+
@inline Base.:*(A::Transpose{<:Any,<:StaticVecOrMat}, B::StaticUULT) =
1215
transpose(transpose(B) * transpose(A))
13-
@inline Base.:*(A::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}, B::Adjoint{<:Any,<:StaticVecOrMat}) =
16+
@inline Base.:*(A::StaticUULT, B::Adjoint{<:Any,<:StaticVecOrMat}) =
1417
adjoint(adjoint(B) * adjoint(A))
15-
@inline Base.:*(A::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}, B::Transpose{<:Any,<:StaticVecOrMat}) =
18+
@inline Base.:*(A::StaticUULT, B::Transpose{<:Any,<:StaticVecOrMat}) =
1619
transpose(transpose(B) * transpose(A))
1720

18-
const StaticULT = Union{UpperTriangular{<:Any,<:StaticMatrix},LowerTriangular{<:Any,<:StaticMatrix}}
19-
20-
@inline Base.:*(A::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}, B::StaticVecOrMat) = _A_mul_B(Size(A), Size(B), A, B)
21-
@inline Base.:*(A::StaticVecOrMat, B::LinearAlgebra.AbstractTriangular{<:Any,<:StaticMatrix}) = _A_mul_B(Size(A), Size(B), A, B)
21+
@inline Base.:*(A::StaticUULT, B::StaticVecOrMat) = _A_mul_B(Size(A), Size(B), A, B)
22+
@inline Base.:*(A::StaticVecOrMat, B::StaticUULT) = _A_mul_B(Size(A), Size(B), A, B)
2223
@inline Base.:*(A::StaticULT, B::StaticULT) = _A_mul_B(Size(A), Size(B), A, B)
2324
@inline Base.:\(A::StaticULT, B::StaticVecOrMat) = _A_ldiv_B(Size(A), Size(B), A, B)
2425

26+
function _first_zero_on_diagonal(A::StaticUULT)
27+
_first_zero_on_diagonal(A.data)
28+
end
2529

2630
@generated function _A_mul_B(::Size{sa}, ::Size{sb}, A::UpperTriangular{TA,<:StaticMatrix}, B::StaticVecOrMat{TB}) where {sa,sb,TA,TB}
2731
m = sb[1]

test/abstractarray.jl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,33 @@ using StaticArrays, Test, LinearAlgebra
165165
@test convert(AbstractArray{Float64}, diag) == diag
166166
# The following cases currently convert the SMatrix into an MMatrix, because
167167
# the constructor in Base invokes `similar`, rather than `convert`, on the static array
168-
trans = Transpose(SVector(1,2))
169-
@test_broken @inferred(convert(AbstractArray{Float64}, trans)) isa Transpose{Float64,SVector{2,Float64}}
170-
adj = Adjoint(SVector(1,2))
171-
@test_broken @inferred(convert(AbstractArray{Float64}, adj)) isa Adjoint{Float64,SVector{2,Float64}}
172-
uptri = UpperTriangular(SA[1 2; 0 3])
173-
@test_broken @inferred(convert(AbstractArray{Float64}, uptri)) isa UpperTriangular{Float64,SMatrix{2,2,Float64,4}}
174-
lotri = LowerTriangular(SA[1 0; 2 3])
175-
@test_broken @inferred(convert(AbstractArray{Float64}, lotri)) isa LowerTriangular{Float64,SMatrix{2,2,Float64,4}}
176-
unituptri = UnitUpperTriangular(SA[1 2; 0 1])
177-
@test_broken @inferred(convert(AbstractArray{Float64}, unituptri)) isa UnitUpperTriangular{Float64,SMatrix{2,2,Float64,4}}
178-
unitlotri = UnitLowerTriangular(SA[1 0; 2 1])
179-
@test_broken @inferred(convert(AbstractArray{Float64}, unitlotri)) isa UnitLowerTriangular{Float64,SMatrix{2,2,Float64,4}}
168+
if VERSION < v"1.8-"
169+
trans = Transpose(SVector(1,2))
170+
@test_broken @inferred(convert(AbstractArray{Float64}, trans)) isa Transpose{Float64,SVector{2,Float64}}
171+
adj = Adjoint(SVector(1,2))
172+
@test_broken @inferred(convert(AbstractArray{Float64}, adj)) isa Adjoint{Float64,SVector{2,Float64}}
173+
uptri = UpperTriangular(SA[1 2; 0 3])
174+
@test_broken @inferred(convert(AbstractArray{Float64}, uptri)) isa UpperTriangular{Float64,SMatrix{2,2,Float64,4}}
175+
lotri = LowerTriangular(SA[1 0; 2 3])
176+
@test_broken @inferred(convert(AbstractArray{Float64}, lotri)) isa LowerTriangular{Float64,SMatrix{2,2,Float64,4}}
177+
unituptri = UnitUpperTriangular(SA[1 2; 0 1])
178+
@test_broken @inferred(convert(AbstractArray{Float64}, unituptri)) isa UnitUpperTriangular{Float64,SMatrix{2,2,Float64,4}}
179+
unitlotri = UnitLowerTriangular(SA[1 0; 2 1])
180+
@test_broken @inferred(convert(AbstractArray{Float64}, unitlotri)) isa UnitLowerTriangular{Float64,SMatrix{2,2,Float64,4}}
181+
else
182+
trans = Transpose(SVector(1,2))
183+
@test @inferred(convert(AbstractArray{Float64}, trans)) isa Transpose{Float64,SVector{2,Float64}}
184+
adj = Adjoint(SVector(1,2))
185+
@test @inferred(convert(AbstractArray{Float64}, adj)) isa Adjoint{Float64,SVector{2,Float64}}
186+
uptri = UpperTriangular(SA[1 2; 0 3])
187+
@test @inferred(convert(AbstractArray{Float64}, uptri)) isa UpperTriangular{Float64,SMatrix{2,2,Float64,4}}
188+
lotri = LowerTriangular(SA[1 0; 2 3])
189+
@test @inferred(convert(AbstractArray{Float64}, lotri)) isa LowerTriangular{Float64,SMatrix{2,2,Float64,4}}
190+
unituptri = UnitUpperTriangular(SA[1 2; 0 1])
191+
@test @inferred(convert(AbstractArray{Float64}, unituptri)) isa UnitUpperTriangular{Float64,SMatrix{2,2,Float64,4}}
192+
unitlotri = UnitLowerTriangular(SA[1 0; 2 1])
193+
@test @inferred(convert(AbstractArray{Float64}, unitlotri)) isa UnitLowerTriangular{Float64,SMatrix{2,2,Float64,4}}
194+
end
180195
end
181196
end
182197

test/ambiguities.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const allowable_ambiguities =
66
4
77
elseif VERSION < v"1.2"
88
2
9+
elseif VERSION == v"1.6-"
10+
53
911
else
10-
1
12+
63
1113
end
1214

1315
@test length(detect_ambiguities(Base, LinearAlgebra, StaticArrays)) <= allowable_ambiguities

test/core.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@testset "Type parameter errors" begin
2020
# (not sure what type of exception these should be?)
2121
@test_throws Exception SVector{1.0,Int}((1,))
22-
@test_throws DimensionMismatch("No precise constructor for SArray{Tuple{2},$Int,1,2} found. Length of input was 1.") SVector{2,Int}((1,))
22+
@test_throws DimensionMismatch SVector{2,Int}((1,))
2323
@test_throws Exception SVector{1,3}((1,))
2424

2525
@test_throws Exception SMatrix{1.0,1,Int,1}((1,))

test/det.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using StaticArrays, Test, LinearAlgebra
1616
@test det(@SMatrix [1 2; 0 3]) == 3
1717
@test det(@SMatrix [1 2 3 4; 0 5 6 7; 0 0 8 9; 0 0 0 10]) == 400.0
1818
@test logdet(@SMatrix [1 2 3 4; 0 5 6 7; 0 0 8 9; 0 0 0 10]) log(400.0)
19-
@test @inferred(det(ones(SMatrix{10,10,Complex{Float64}}))) == 0
19+
VERSION < v"1.7-" && @test @inferred(det(ones(SMatrix{10,10,Complex{Float64}}))) == 0
2020

2121
# Unsigned specializations , compare to Base
2222
M = @SMatrix [1 2 3 4; 200 5 6 7; 0 0 8 9; 0 0 0 10]
@@ -29,17 +29,19 @@ using StaticArrays, Test, LinearAlgebra
2929
for sz in (5, 8, 15), typ in (Float64, Complex{Float64})
3030
A = rand(typ, sz, sz)
3131
SA = SMatrix{sz,sz,typ}(A)
32-
@test det(A) det(SA) == det(lu(SA))
32+
VERSION < v"1.7-" && @test det(A) det(SA) == det(lu(SA))
3333
if typ == Float64 && det(A) < 0
3434
A[:,1], A[:,2] = A[:,2], A[:,1]
3535
SA = SMatrix{sz,sz,typ}(A)
3636
end
37-
@test logdet(A) logdet(SA) == logdet(lu(SA))
37+
VERSION < v"1.7-" && @test logdet(A) logdet(SA) == logdet(lu(SA))
3838
dA, sA = logabsdet(A)
39-
dSA, sSA = logabsdet(SA)
40-
dLU, sLU = logabsdet(lu(SA))
41-
@test dA dSA == dLU
42-
@test sA sSA == sLU
39+
if VERSION < v"1.7-"
40+
dSA, sSA = logabsdet(SA)
41+
dLU, sLU = logabsdet(lu(SA))
42+
@test dA dSA == dLU
43+
@test sA sSA == sLU
44+
end
4345
end
4446

4547
@test_throws DimensionMismatch det(@SMatrix [0; 1])

test/expm.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using StaticArrays, Test, LinearAlgebra
1212
@test exp(@SMatrix zeros(Complex{Float64}, 2, 2))::SMatrix Complex{Float64}[1 0; 0 1]
1313
@test exp(@SMatrix [1 2 0; 2 1 0; 0 0 1]) exp([1 2 0; 2 1 0; 0 0 1])
1414

15+
if VERSION < v"1.7-"
1516
for sz in (3,4), typ in (Float64, Complex{Float64})
1617
A = rand(typ, sz, sz)
1718
nA = norm(A, 1)
@@ -21,4 +22,5 @@ using StaticArrays, Test, LinearAlgebra
2122
@test exp(B) exp(SB)
2223
end
2324
end
25+
end
2426
end

0 commit comments

Comments
 (0)