Skip to content

Commit 0ba5dc5

Browse files
authored
Remove size(::StructuredMatrix, d) specializations (#51083)
1 parent 9ce30f2 commit 0ba5dc5

File tree

12 files changed

+16
-51
lines changed

12 files changed

+16
-51
lines changed

src/bidiag.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,7 @@ function show(io::IO, M::Bidiagonal)
271271
print_matrix(io, (M.ev)')
272272
end
273273

274-
size(M::Bidiagonal) = (length(M.dv), length(M.dv))
275-
function size(M::Bidiagonal, d::Integer)
276-
if d < 1
277-
throw(ArgumentError("dimension must be ≥ 1, got $d"))
278-
elseif d <= 2
279-
return length(M.dv)
280-
else
281-
return 1
282-
end
283-
end
274+
size(M::Bidiagonal) = (n = length(M.dv); (n, n))
284275

285276
#Elementary operations
286277
for func in (:conj, :copy, :real, :imag)

src/diagonal.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ copyto!(D1::Diagonal, D2::Diagonal) = (copyto!(D1.diag, D2.diag); D1)
133133

134134
size(D::Diagonal) = (n = length(D.diag); (n,n))
135135

136-
function size(D::Diagonal,d::Integer)
137-
if d<1
138-
throw(ArgumentError("dimension must be ≥ 1, got $d"))
139-
end
140-
return d<=2 ? length(D.diag) : 1
141-
end
136+
axes(D::Diagonal) = (ax = axes(D.diag, 1); (ax, ax))
142137

143138
@inline function Base.isassigned(D::Diagonal, i::Int, j::Int)
144139
@boundscheck checkbounds(Bool, D, i, j) || return false
@@ -150,8 +145,6 @@ end
150145
r
151146
end
152147

153-
axes(D::Diagonal) = (ax = axes(D.diag, 1); (ax, ax))
154-
155148
@inline function Base.isstored(D::Diagonal, i::Int, j::Int)
156149
@boundscheck checkbounds(D, i, j)
157150
if i == j

src/hessenberg.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ UpperHessenberg{T}(H::UpperHessenberg) where {T} = UpperHessenberg{T}(H.data)
5555
UpperHessenberg(A::AbstractMatrix) = UpperHessenberg{eltype(A),typeof(A)}(A)
5656
Matrix(H::UpperHessenberg{T}) where {T} = Matrix{T}(H)
5757
Array(H::UpperHessenberg) = Matrix(H)
58-
size(H::UpperHessenberg, d) = size(H.data, d)
5958
size(H::UpperHessenberg) = size(H.data)
6059
parent(H::UpperHessenberg) = H.data
6160

src/symmetric.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ const RealHermSym{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}}
222222
const RealHermSymComplexHerm{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}, Hermitian{Complex{T},S}}
223223
const RealHermSymComplexSym{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}, Symmetric{Complex{T},S}}
224224

225-
size(A::HermOrSym, d) = size(A.data, d)
226225
size(A::HermOrSym) = size(A.data)
227226
@inline function Base.isassigned(A::HermOrSym, i::Int, j::Int)
228227
@boundscheck checkbounds(Bool, A, i, j) || return false

src/triangular.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, :UnitUpperTr
3434

3535
AbstractMatrix{T}(A::$t) where {T} = $t{T}(A)
3636

37-
size(A::$t, d) = size(A.data, d)
3837
size(A::$t) = size(A.data)
3938

4039
# For A<:AbstractTriangular, similar(A[, neweltype]) should yield a matrix with the same

src/tridiag.jl

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,7 @@ end
138138
Matrix(M::SymTridiagonal{T}) where {T} = Matrix{promote_type(T, typeof(zero(T)))}(M)
139139
Array(M::SymTridiagonal) = Matrix(M)
140140

141-
size(A::SymTridiagonal) = (length(A.dv), length(A.dv))
142-
function size(A::SymTridiagonal, d::Integer)
143-
if d < 1
144-
throw(ArgumentError("dimension must be ≥ 1, got $d"))
145-
elseif d<=2
146-
return length(A.dv)
147-
else
148-
return 1
149-
end
150-
end
141+
size(A::SymTridiagonal) = (n = length(A.dv); (n, n))
151142

152143
similar(S::SymTridiagonal, ::Type{T}) where {T} = SymTridiagonal(similar(S.dv, T), similar(S.ev, T))
153144
similar(S::SymTridiagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = similar(S.dv, T, dims)
@@ -558,16 +549,7 @@ function Tridiagonal{T}(A::Tridiagonal) where {T}
558549
end
559550
end
560551

561-
size(M::Tridiagonal) = (length(M.d), length(M.d))
562-
function size(M::Tridiagonal, d::Integer)
563-
if d < 1
564-
throw(ArgumentError("dimension d must be ≥ 1, got $d"))
565-
elseif d <= 2
566-
return length(M.d)
567-
else
568-
return 1
569-
end
570-
end
552+
size(M::Tridiagonal) = (n = length(M.d); (n, n))
571553

572554
function Matrix{T}(M::Tridiagonal) where {T}
573555
A = Matrix{T}(undef, size(M))

test/bidiag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Random.seed!(1)
102102
@test_throws BoundsError ubd[1, n + 1] = 1
103103
@test ((cubd[2, 2] = 10) == 10; cubd[2, 2] == 10)
104104
# bidiagonal size
105-
@test_throws ArgumentError size(ubd, 0)
105+
@test_throws BoundsError size(ubd, 0)
106106
@test size(ubd, 1) == size(ubd, 2) == n
107107
@test size(ubd, 3) == 1
108108
# bidiagonal similar

test/diagonal.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Random.seed!(1)
5454
end
5555

5656
@testset "Basic properties" begin
57-
@test_throws ArgumentError size(D,0)
57+
@test_throws BoundsError size(D,0)
58+
@test size(D,1) == size(D,2) == length(dd)
59+
@test size(D,3) == 1
5860
@test typeof(convert(Diagonal{ComplexF32},D)) <: Diagonal{ComplexF32}
5961
@test typeof(convert(AbstractMatrix{ComplexF32},D)) <: Diagonal{ComplexF32}
6062

test/lq.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ end
206206
show(bf, "text/plain", lq(Matrix(I, 4, 4)))
207207
seekstart(bf)
208208
@test String(take!(bf)) == """
209-
LinearAlgebra.LQ{Float64, Matrix{Float64}, Vector{Float64}}
209+
$(LinearAlgebra.LQ){Float64, Matrix{Float64}, Vector{Float64}}
210210
L factor:
211211
4×4 Matrix{Float64}:
212212
1.0 0.0 0.0 0.0
213213
0.0 1.0 0.0 0.0
214214
0.0 0.0 1.0 0.0
215215
0.0 0.0 0.0 1.0
216-
Q factor: 4×4 LinearAlgebra.LQPackedQ{Float64, Matrix{Float64}, Vector{Float64}}"""
216+
Q factor: 4×4 $(LinearAlgebra.LQPackedQ){Float64, Matrix{Float64}, Vector{Float64}}"""
217217
end
218218

219219
@testset "adjoint of LQ" begin

test/lu.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ end
301301
show(bf, "text/plain", lu(Matrix(I, 4, 4)))
302302
seekstart(bf)
303303
@test String(take!(bf)) == """
304-
LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{$Int}}
304+
$(LinearAlgebra.LU){Float64, Matrix{Float64}, Vector{$Int}}
305305
L factor:
306306
4×4 Matrix{Float64}:
307307
1.0 0.0 0.0 0.0

0 commit comments

Comments
 (0)