From ff781e597c6ce124552b29272bf7784b1a07f536 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 10 Jul 2017 18:15:14 +0200 Subject: [PATCH] Use Symbol for uplo in Bidiagonal constructors (#22703) - Consistent with Symmetric/Hermitian wrappers - It is clearer to use :U/:L instead of true/false - The Char constructor was originally for internal use only; remove and remove docstring --- NEWS.md | 3 + base/deprecated.jl | 5 + base/linalg/bidiag.jl | 187 +++++++++++++--------------------- base/linalg/dense.jl | 6 +- base/linalg/lu.jl | 4 +- base/linalg/special.jl | 16 +-- base/sparse/sparsematrix.jl | 2 +- test/linalg/bidiag.jl | 127 ++++++++++------------- test/linalg/cholesky.jl | 2 +- test/linalg/dense.jl | 4 +- test/linalg/generic.jl | 2 +- test/linalg/lapack.jl | 2 +- test/linalg/matmul.jl | 8 +- test/linalg/rowvector.jl | 2 +- test/linalg/special.jl | 8 +- test/show.jl | 4 +- test/sparse/higherorderfns.jl | 10 +- test/sparse/sparse.jl | 4 +- 18 files changed, 171 insertions(+), 225 deletions(-) diff --git a/NEWS.md b/NEWS.md index d60b4a547404d..1575fd962bdeb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -148,6 +148,9 @@ Deprecated or removed * `read(::IO, ::Ref)` is now a method of `read!`, since it mutates its `Ref` argument ([#21592]). + * `Bidiagonal` constructors now use a `Symbol` (`:U` or `:L`) for the upper/lower + argument, instead of a `Bool` or a `Char` ([#22703]). + Julia v0.6.0 Release Notes ========================== diff --git a/base/deprecated.jl b/base/deprecated.jl index cba0c240ca1c4..8d9285cffda43 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1555,6 +1555,11 @@ function CartesianRange{N}(start::CartesianIndex{N}, stop::CartesianIndex{N}) CartesianRange(inds) end +# PR #22703 +@deprecate Bidiagonal(dv::AbstractVector, ev::AbstractVector, isupper::Bool) Bidiagonal(dv, ev, ifelse(isupper, :U, :L)) +@deprecate Bidiagonal(dv::AbstractVector, ev::AbstractVector, uplo::Char) Bidiagonal(dv, ev, ifelse(uplo == 'U', :U, :L)) +@deprecate Bidiagonal(A::AbstractMatrix, isupper::Bool) Bidiagonal(A, ifelse(isupper, :U, :L)) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index b54dce69018f2..2ef755eeec228 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -4,47 +4,50 @@ mutable struct Bidiagonal{T} <: AbstractMatrix{T} dv::Vector{T} # diagonal ev::Vector{T} # sub/super diagonal - isupper::Bool # is upper bidiagonal (true) or lower (false) - function Bidiagonal{T}(dv::Vector{T}, ev::Vector{T}, isupper::Bool) where T + uplo::Char # upper bidiagonal ('U') or lower ('L') + function Bidiagonal{T}(dv::Vector{T}, ev::Vector{T}, uplo::Char) where T if length(ev) != length(dv)-1 throw(DimensionMismatch("length of diagonal vector is $(length(dv)), length of off-diagonal vector is $(length(ev))")) end - new(dv, ev, isupper) + new(dv, ev, uplo) + end + function Bidiagonal(dv::Vector{T}, ev::Vector{T}, uplo::Char) where T + Bidiagonal{T}(dv, ev, uplo) end end + """ - Bidiagonal(dv, ev, isupper::Bool) + Bidiagonal(dv, ev, uplo::Symbol) -Constructs an upper (`isupper=true`) or lower (`isupper=false`) bidiagonal matrix using the -given diagonal (`dv`) and off-diagonal (`ev`) vectors. The result is of type `Bidiagonal` +Constructs an upper (`uplo=:U`) or lower (`uplo=:L`) bidiagonal matrix using the +given diagonal (`dv`) and off-diagonal (`ev`) vectors. The result is of type `Bidiagonal` and provides efficient specialized linear solvers, but may be converted into a regular -matrix with [`convert(Array, _)`](@ref) (or `Array(_)` for short). `ev`'s length +matrix with [`convert(Array, _)`](@ref) (or `Array(_)` for short). The length of `ev` must be one less than the length of `dv`. -# Example - +# Examples ```jldoctest -julia> dv = [1; 2; 3; 4] +julia> dv = [1, 2, 3, 4] 4-element Array{Int64,1}: 1 2 3 4 -julia> ev = [7; 8; 9] +julia> ev = [7, 8, 9] 3-element Array{Int64,1}: 7 8 9 -julia> Bu = Bidiagonal(dv, ev, true) # ev is on the first superdiagonal +julia> Bu = Bidiagonal(dv, ev, :U) # ev is on the first superdiagonal 4×4 Bidiagonal{Int64}: 1 7 ⋅ ⋅ ⋅ 2 8 ⋅ ⋅ ⋅ 3 9 ⋅ ⋅ ⋅ 4 -julia> Bl = Bidiagonal(dv, ev, false) # ev is on the first subdiagonal +julia> Bl = Bidiagonal(dv, ev, :L) # ev is on the first subdiagonal 4×4 Bidiagonal{Int64}: 1 ⋅ ⋅ ⋅ 7 2 ⋅ ⋅ @@ -52,73 +55,23 @@ julia> Bl = Bidiagonal(dv, ev, false) # ev is on the first subdiagonal ⋅ ⋅ 9 4 ``` """ -Bidiagonal(dv::AbstractVector{T}, ev::AbstractVector{T}, isupper::Bool) where {T} = Bidiagonal{T}(collect(dv), collect(ev), isupper) +function Bidiagonal(dv::AbstractVector{T}, ev::AbstractVector{T}, uplo::Symbol) where T + Bidiagonal{T}(collect(dv), collect(ev), char_uplo(uplo)) +end Bidiagonal(dv::AbstractVector, ev::AbstractVector) = throw(ArgumentError("did you want an upper or lower Bidiagonal? Try again with an additional true (upper) or false (lower) argument.")) -""" - Bidiagonal(dv, ev, uplo::Char) - -Constructs an upper (`uplo='U'`) or lower (`uplo='L'`) bidiagonal matrix using the -given diagonal (`dv`) and off-diagonal (`ev`) vectors. The result is of type `Bidiagonal` -and provides efficient specialized linear solvers, but may be converted into a regular -matrix with [`convert(Array, _)`](@ref) (or `Array(_)` for short). `ev`'s -length must be one less than the length of `dv`. - -# Example - -```jldoctest -julia> dv = [1; 2; 3; 4] -4-element Array{Int64,1}: - 1 - 2 - 3 - 4 - -julia> ev = [7; 8; 9] -3-element Array{Int64,1}: - 7 - 8 - 9 - -julia> Bu = Bidiagonal(dv, ev, 'U') #e is on the first superdiagonal -4×4 Bidiagonal{Int64}: - 1 7 ⋅ ⋅ - ⋅ 2 8 ⋅ - ⋅ ⋅ 3 9 - ⋅ ⋅ ⋅ 4 - -julia> Bl = Bidiagonal(dv, ev, 'L') #e is on the first subdiagonal -4×4 Bidiagonal{Int64}: - 1 ⋅ ⋅ ⋅ - 7 2 ⋅ ⋅ - ⋅ 8 3 ⋅ - ⋅ ⋅ 9 4 -``` -""" -#Convert from BLAS uplo flag to boolean internal -function Bidiagonal(dv::AbstractVector, ev::AbstractVector, uplo::Char) - if uplo === 'U' - isupper = true - elseif uplo === 'L' - isupper = false - else - throw(ArgumentError("Bidiagonal uplo argument must be upper 'U' or lower 'L', got $(repr(uplo))")) - end - Bidiagonal(collect(dv), collect(ev), isupper) -end -function Bidiagonal(dv::AbstractVector{Td}, ev::AbstractVector{Te}, isupper::Bool) where {Td,Te} +function Bidiagonal(dv::AbstractVector{Td}, ev::AbstractVector{Te}, uplo::Symbol) where {Td,Te} T = promote_type(Td,Te) - Bidiagonal(convert(Vector{T}, dv), convert(Vector{T}, ev), isupper) + Bidiagonal(convert(Vector{T}, dv), convert(Vector{T}, ev), uplo) end """ - Bidiagonal(A, isupper::Bool) + Bidiagonal(A, uplo::Symbol) Construct a `Bidiagonal` matrix from the main diagonal of `A` and -its first super- (if `isupper=true`) or sub-diagonal (if `isupper=false`). - -# Example +its first super- (if `uplo=:U`) or sub-diagonal (if `uplo=:L`). +# Examples ```jldoctest julia> A = [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4] 4×4 Array{Int64,2}: @@ -127,14 +80,14 @@ julia> A = [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4] 3 3 3 3 4 4 4 4 -julia> Bidiagonal(A, true) #contains the main diagonal and first superdiagonal of A +julia> Bidiagonal(A, :U) #contains the main diagonal and first superdiagonal of A 4×4 Bidiagonal{Int64}: 1 1 ⋅ ⋅ ⋅ 2 2 ⋅ ⋅ ⋅ 3 3 ⋅ ⋅ ⋅ 4 -julia> Bidiagonal(A, false) #contains the main diagonal and first subdiagonal of A +julia> Bidiagonal(A, :L) #contains the main diagonal and first subdiagonal of A 4×4 Bidiagonal{Int64}: 1 ⋅ ⋅ ⋅ 2 2 ⋅ ⋅ @@ -142,7 +95,7 @@ julia> Bidiagonal(A, false) #contains the main diagonal and first subdiagonal of ⋅ ⋅ 4 4 ``` """ -Bidiagonal(A::AbstractMatrix, isupper::Bool)=Bidiagonal(diag(A), diag(A, isupper ? 1 : -1), isupper) +Bidiagonal(A::AbstractMatrix, uplo::Symbol) = Bidiagonal(diag(A), diag(A, uplo == :U ? 1 : -1), uplo) function getindex(A::Bidiagonal{T}, i::Integer, j::Integer) where T if !((1 <= i <= size(A,2)) && (1 <= j <= size(A,2))) @@ -174,7 +127,7 @@ end ## structured matrix methods ## function Base.replace_in_print_matrix(A::Bidiagonal,i::Integer,j::Integer,s::AbstractString) - if A.isupper + if A.uplo == 'U' i==j || i==j-1 ? s : Base.replace_with_centered_mark(s) else i==j || i==j+1 ? s : Base.replace_with_centered_mark(s) @@ -187,7 +140,7 @@ function convert(::Type{Matrix{T}}, A::Bidiagonal) where T B = zeros(T, n, n) for i = 1:n - 1 B[i,i] = A.dv[i] - if A.isupper + if A.uplo == 'U' B[i, i + 1] = A.ev[i] else B[i + 1, i] = A.ev[i] @@ -205,29 +158,29 @@ promote_rule(::Type{Matrix{T}}, ::Type{Bidiagonal{S}}) where {T,S} = Matrix{prom Tridiagonal(M::Bidiagonal{T}) where {T} = convert(Tridiagonal{T}, M) function convert(::Type{Tridiagonal{T}}, A::Bidiagonal) where T z = zeros(T, size(A)[1]-1) - A.isupper ? Tridiagonal(z, convert(Vector{T},A.dv), convert(Vector{T},A.ev)) : Tridiagonal(convert(Vector{T},A.ev), convert(Vector{T},A.dv), z) + A.uplo == 'U' ? Tridiagonal(z, convert(Vector{T},A.dv), convert(Vector{T},A.ev)) : Tridiagonal(convert(Vector{T},A.ev), convert(Vector{T},A.dv), z) end promote_rule(::Type{Tridiagonal{T}}, ::Type{Bidiagonal{S}}) where {T,S} = Tridiagonal{promote_type(T,S)} # No-op for trivial conversion Bidiagonal{T} -> Bidiagonal{T} convert(::Type{Bidiagonal{T}}, A::Bidiagonal{T}) where {T} = A # Convert Bidiagonal to Bidiagonal{T} by constructing a new instance with converted elements -convert(::Type{Bidiagonal{T}}, A::Bidiagonal) where {T} = Bidiagonal(convert(Vector{T}, A.dv), convert(Vector{T}, A.ev), A.isupper) +convert(::Type{Bidiagonal{T}}, A::Bidiagonal) where {T} = Bidiagonal(convert(Vector{T}, A.dv), convert(Vector{T}, A.ev), A.uplo) # When asked to convert Bidiagonal to AbstractMatrix{T}, preserve structure by converting to Bidiagonal{T} <: AbstractMatrix{T} convert(::Type{AbstractMatrix{T}}, A::Bidiagonal) where {T} = convert(Bidiagonal{T}, A) -broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.isupper) +broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.uplo) -similar(B::Bidiagonal, ::Type{T}) where {T} = Bidiagonal{T}(similar(B.dv, T), similar(B.ev, T), B.isupper) +similar(B::Bidiagonal, ::Type{T}) where {T} = Bidiagonal{T}(similar(B.dv, T), similar(B.ev, T), B.uplo) ################### # LAPACK routines # ################### #Singular values -svdvals!(M::Bidiagonal{<:BlasReal}) = LAPACK.bdsdc!(M.isupper ? 'U' : 'L', 'N', M.dv, M.ev)[1] +svdvals!(M::Bidiagonal{<:BlasReal}) = LAPACK.bdsdc!(M.uplo, 'N', M.dv, M.ev)[1] function svdfact!(M::Bidiagonal{<:BlasReal}; thin::Bool=true) - d, e, U, Vt, Q, iQ = LAPACK.bdsdc!(M.isupper ? 'U' : 'L', 'I', M.dv, M.ev) + d, e, U, Vt, Q, iQ = LAPACK.bdsdc!(M.uplo, 'I', M.dv, M.ev) SVD(U, d, Vt) end svdfact(M::Bidiagonal; thin::Bool=true) = svdfact!(copy(M),thin=thin) @@ -241,7 +194,7 @@ function show(io::IO, M::Bidiagonal) println(io, summary(M), ":") print(io, " diag:") print_matrix(io, (M.dv)') - print(io, M.isupper ? "\n super:" : "\n sub:") + print(io, M.uplo == 'U' ? "\n super:" : "\n sub:") print_matrix(io, (M.ev)') end @@ -257,38 +210,38 @@ function size(M::Bidiagonal, d::Integer) end #Elementary operations -broadcast(::typeof(abs), M::Bidiagonal) = Bidiagonal(abs.(M.dv), abs.(M.ev), abs.(M.isupper)) -broadcast(::typeof(round), M::Bidiagonal) = Bidiagonal(round.(M.dv), round.(M.ev), M.isupper) -broadcast(::typeof(trunc), M::Bidiagonal) = Bidiagonal(trunc.(M.dv), trunc.(M.ev), M.isupper) -broadcast(::typeof(floor), M::Bidiagonal) = Bidiagonal(floor.(M.dv), floor.(M.ev), M.isupper) -broadcast(::typeof(ceil), M::Bidiagonal) = Bidiagonal(ceil.(M.dv), ceil.(M.ev), M.isupper) +broadcast(::typeof(abs), M::Bidiagonal) = Bidiagonal(abs.(M.dv), abs.(M.ev), M.uplo) +broadcast(::typeof(round), M::Bidiagonal) = Bidiagonal(round.(M.dv), round.(M.ev), M.uplo) +broadcast(::typeof(trunc), M::Bidiagonal) = Bidiagonal(trunc.(M.dv), trunc.(M.ev), M.uplo) +broadcast(::typeof(floor), M::Bidiagonal) = Bidiagonal(floor.(M.dv), floor.(M.ev), M.uplo) +broadcast(::typeof(ceil), M::Bidiagonal) = Bidiagonal(ceil.(M.dv), ceil.(M.ev), M.uplo) for func in (:conj, :copy, :real, :imag) - @eval ($func)(M::Bidiagonal) = Bidiagonal(($func)(M.dv), ($func)(M.ev), M.isupper) + @eval ($func)(M::Bidiagonal) = Bidiagonal(($func)(M.dv), ($func)(M.ev), M.uplo) end -broadcast(::typeof(round), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(round.(T, M.dv), round.(T, M.ev), M.isupper) -broadcast(::typeof(trunc), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(trunc.(T, M.dv), trunc.(T, M.ev), M.isupper) -broadcast(::typeof(floor), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(floor.(T, M.dv), floor.(T, M.ev), M.isupper) -broadcast(::typeof(ceil), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(ceil.(T, M.dv), ceil.(T, M.ev), M.isupper) +broadcast(::typeof(round), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(round.(T, M.dv), round.(T, M.ev), M.uplo) +broadcast(::typeof(trunc), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(trunc.(T, M.dv), trunc.(T, M.ev), M.uplo) +broadcast(::typeof(floor), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(floor.(T, M.dv), floor.(T, M.ev), M.uplo) +broadcast(::typeof(ceil), ::Type{T}, M::Bidiagonal) where {T<:Integer} = Bidiagonal(ceil.(T, M.dv), ceil.(T, M.ev), M.uplo) -transpose(M::Bidiagonal) = Bidiagonal(M.dv, M.ev, !M.isupper) -ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), !M.isupper) +transpose(M::Bidiagonal) = Bidiagonal(M.dv, M.ev, M.uplo == 'U' ? :L : :U) +ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), M.uplo == 'U' ? :L : :U) -istriu(M::Bidiagonal) = M.isupper || iszero(M.ev) -istril(M::Bidiagonal) = !M.isupper || iszero(M.ev) +istriu(M::Bidiagonal) = M.uplo == 'U' || iszero(M.ev) +istril(M::Bidiagonal) = M.uplo == 'L' || iszero(M.ev) function tril!(M::Bidiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) - elseif M.isupper && k < 0 + elseif M.uplo == 'U' && k < 0 fill!(M.dv,0) fill!(M.ev,0) elseif k < -1 fill!(M.dv,0) fill!(M.ev,0) - elseif M.isupper && k == 0 + elseif M.uplo == 'U' && k == 0 fill!(M.ev,0) - elseif !M.isupper && k == -1 + elseif M.uplo == 'L' && k == -1 fill!(M.dv,0) end return M @@ -298,15 +251,15 @@ function triu!(M::Bidiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) - elseif !M.isupper && k > 0 + elseif M.uplo == 'L' && k > 0 fill!(M.dv,0) fill!(M.ev,0) elseif k > 1 fill!(M.dv,0) fill!(M.ev,0) - elseif !M.isupper && k == 0 + elseif M.uplo == 'L' && k == 0 fill!(M.ev,0) - elseif M.isupper && k == 1 + elseif M.uplo == 'U' && k == 1 fill!(M.dv,0) end return M @@ -316,9 +269,9 @@ function diag(M::Bidiagonal{T}, n::Integer=0) where T if n == 0 return M.dv elseif n == 1 - return M.isupper ? M.ev : zeros(T, size(M,1)-1) + return M.uplo == 'U' ? M.ev : zeros(T, size(M,1)-1) elseif n == -1 - return M.isupper ? zeros(T, size(M,1)-1) : M.ev + return M.uplo == 'L' ? M.ev : zeros(T, size(M,1)-1) elseif -size(M,1) < n < size(M,1) return zeros(T, size(M,1)-abs(n)) else @@ -327,26 +280,26 @@ function diag(M::Bidiagonal{T}, n::Integer=0) where T end function +(A::Bidiagonal, B::Bidiagonal) - if A.isupper == B.isupper - Bidiagonal(A.dv+B.dv, A.ev+B.ev, A.isupper) + if A.uplo == B.uplo + Bidiagonal(A.dv+B.dv, A.ev+B.ev, A.uplo) else - Tridiagonal((A.isupper ? (B.ev,A.dv+B.dv,A.ev) : (A.ev,A.dv+B.dv,B.ev))...) + Tridiagonal((A.uplo == 'U' ? (B.ev,A.dv+B.dv,A.ev) : (A.ev,A.dv+B.dv,B.ev))...) end end function -(A::Bidiagonal, B::Bidiagonal) - if A.isupper == B.isupper - Bidiagonal(A.dv-B.dv, A.ev-B.ev, A.isupper) + if A.uplo == B.uplo + Bidiagonal(A.dv-B.dv, A.ev-B.ev, A.uplo) else - Tridiagonal((A.isupper ? (-B.ev,A.dv-B.dv,A.ev) : (A.ev,A.dv-B.dv,-B.ev))...) + Tridiagonal((A.uplo == 'U' ? (-B.ev,A.dv-B.dv,A.ev) : (A.ev,A.dv-B.dv,-B.ev))...) end end --(A::Bidiagonal)=Bidiagonal(-A.dv,-A.ev,A.isupper) -*(A::Bidiagonal, B::Number) = Bidiagonal(A.dv*B, A.ev*B, A.isupper) +-(A::Bidiagonal)=Bidiagonal(-A.dv,-A.ev,A.uplo) +*(A::Bidiagonal, B::Number) = Bidiagonal(A.dv*B, A.ev*B, A.uplo) *(B::Number, A::Bidiagonal) = A*B -/(A::Bidiagonal, B::Number) = Bidiagonal(A.dv/B, A.ev/B, A.isupper) -==(A::Bidiagonal, B::Bidiagonal) = (A.dv==B.dv) && (A.ev==B.ev) && (A.isupper==B.isupper) +/(A::Bidiagonal, B::Number) = Bidiagonal(A.dv/B, A.ev/B, A.uplo) +==(A::Bidiagonal, B::Bidiagonal) = (A.uplo==B.uplo) && (A.dv==B.dv) && (A.ev==B.ev) const BiTriSym = Union{Bidiagonal,Tridiagonal,SymTridiagonal} const BiTri = Union{Bidiagonal,Tridiagonal} @@ -543,7 +496,7 @@ function naivesub!(A::Bidiagonal{T}, b::AbstractVector, x::AbstractVector = b) w if N != length(b) || N != length(x) throw(DimensionMismatch("second dimension of A, $N, does not match one of the lengths of x, $(length(x)), or b, $(length(b))")) end - if !A.isupper #do forward substitution + if A.uplo == 'L' #do forward substitution for j = 1:N x[j] = b[j] j > 1 && (x[j] -= A.ev[j-1] * x[j-1]) @@ -579,7 +532,7 @@ function eigvecs(M::Bidiagonal{T}) where T Q = Matrix{T}(n,n) blks = [0; find(x -> x == 0, M.ev); n] v = zeros(T, n) - if M.isupper + if M.uplo == 'U' for idx_block = 1:length(blks) - 1, i = blks[idx_block] + 1:blks[idx_block + 1] #index of eigenvector fill!(v, zero(T)) v[blks[idx_block] + 1] = one(T) diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 7ed1c8f9a027e..46d78399e2061 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -688,7 +688,7 @@ will return a Cholesky factorization. # Example ```jldoctest -julia> A = Array(Bidiagonal(ones(5, 5), true)) +julia> A = Array(Bidiagonal(ones(5, 5), :U)) 5×5 Array{Float64,2}: 1.0 1.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 @@ -748,12 +748,12 @@ function factorize(A::StridedMatrix{T}) where T return Diagonal(A) end if utri1 - return Bidiagonal(diag(A), diag(A, -1), false) + return Bidiagonal(diag(A), diag(A, -1), :L) end return LowerTriangular(A) end if utri - return Bidiagonal(diag(A), diag(A, 1), true) + return Bidiagonal(diag(A), diag(A, 1), :U) end if utri1 if (herm & (T <: Complex)) | sym diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index a0c85a8a9a96b..192900f92c69a 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -396,7 +396,7 @@ factorize(A::Tridiagonal) = lufact(A) function getindex(F::Base.LinAlg.LU{T,Tridiagonal{T}}, d::Symbol) where T m, n = size(F) if d == :L - L = Array(Bidiagonal(ones(T, n), F.factors.dl, false)) + L = Array(Bidiagonal(ones(T, n), F.factors.dl, d)) for i = 2:n tmp = L[F.ipiv[i], 1:i - 1] L[F.ipiv[i], 1:i - 1] = L[i, 1:i - 1] @@ -404,7 +404,7 @@ function getindex(F::Base.LinAlg.LU{T,Tridiagonal{T}}, d::Symbol) where T end return L elseif d == :U - U = Array(Bidiagonal(F.factors.d, F.factors.du, true)) + U = Array(Bidiagonal(F.factors.d, F.factors.du, d)) for i = 1:n - 2 U[i,i + 2] = F.factors.du2[i] end diff --git a/base/linalg/special.jl b/base/linalg/special.jl index d278d953514a5..d57ff0f23520a 100644 --- a/base/linalg/special.jl +++ b/base/linalg/special.jl @@ -4,7 +4,7 @@ # Interconversion between special matrix types convert(::Type{Bidiagonal}, A::Diagonal{T}) where {T} = - Bidiagonal(A.diag, zeros(T, size(A.diag,1)-1), true) + Bidiagonal(A.diag, zeros(T, size(A.diag,1)-1), :U) convert(::Type{SymTridiagonal}, A::Diagonal{T}) where {T} = SymTridiagonal(A.diag, zeros(T, size(A.diag,1)-1)) convert(::Type{Tridiagonal}, A::Diagonal{T}) where {T} = @@ -25,14 +25,14 @@ function convert(::Type{SymTridiagonal}, A::Bidiagonal) end convert(::Type{Tridiagonal}, A::Bidiagonal{T}) where {T} = - Tridiagonal(A.isupper ? zeros(T, size(A.dv,1)-1) : A.ev, A.dv, - A.isupper ? A.ev:zeros(T, size(A.dv,1)-1)) + Tridiagonal(A.uplo == 'U' ? zeros(T, size(A.dv,1)-1) : A.ev, A.dv, + A.uplo == 'U' ? A.ev:zeros(T, size(A.dv,1)-1)) function convert(::Type{Bidiagonal}, A::SymTridiagonal) if !iszero(A.ev) throw(ArgumentError("matrix cannot be represented as Bidiagonal")) end - Bidiagonal(A.dv, A.ev, true) + Bidiagonal(A.dv, A.ev, :U) end function convert(::Type{Diagonal}, A::Tridiagonal) @@ -44,9 +44,9 @@ end function convert(::Type{Bidiagonal}, A::Tridiagonal) if iszero(A.dl) - return Bidiagonal(A.d, A.du, true) + return Bidiagonal(A.d, A.du, :U) elseif iszero(A.du) - return Bidiagonal(A.d, A.dl, false) + return Bidiagonal(A.d, A.dl, :L) else throw(ArgumentError("matrix cannot be represented as Bidiagonal")) end @@ -73,9 +73,9 @@ end function convert(::Type{Bidiagonal}, A::AbstractTriangular) fA = full(A) if fA == diagm(diag(A)) + diagm(diag(fA, 1), 1) - return Bidiagonal(diag(A), diag(fA,1), true) + return Bidiagonal(diag(A), diag(fA,1), :U) elseif fA == diagm(diag(A)) + diagm(diag(fA, -1), -1) - return Bidiagonal(diag(A), diag(fA,-1), false) + return Bidiagonal(diag(A), diag(fA,-1), :L) else throw(ArgumentError("matrix cannot be represented as Bidiagonal")) end diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index c474c7006f1f2..4cdcba0523252 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -760,7 +760,7 @@ end function sparse(B::Bidiagonal) m = length(B.dv) - B.isupper || return sparse([1:m;2:m],[1:m;1:m-1],[B.dv;B.ev], Int(m), Int(m)) # lower bidiagonal + B.uplo == 'U' || return sparse([1:m;2:m],[1:m;1:m-1],[B.dv;B.ev], Int(m), Int(m)) # lower bidiagonal return sparse([1:m;1:m-1],[1:m;2:m],[B.dv;B.ev], Int(m), Int(m)) # upper bidiagonal end diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index 515a175b26f4c..948d5fd7df764 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -24,15 +24,15 @@ srand(1) end @testset "Constructors" begin - @test Bidiagonal(dv,ev,'U') == Bidiagonal(dv,ev,true) - @test_throws ArgumentError Bidiagonal(dv,ev,'R') - @test_throws DimensionMismatch Bidiagonal(dv,ones(elty,n),true) + @test Bidiagonal(dv,ev,:U) != Bidiagonal(dv,ev,:L) + @test_throws ArgumentError Bidiagonal(dv,ev,:R) + @test_throws DimensionMismatch Bidiagonal(dv,ones(elty,n),:U) @test_throws ArgumentError Bidiagonal(dv,ev) end @testset "getindex, setindex!, size, and similar" begin - ubd = Bidiagonal(dv, ev, true) - lbd = Bidiagonal(dv, ev, false) + ubd = Bidiagonal(dv, ev, :U) + lbd = Bidiagonal(dv, ev, :L) # bidiagonal getindex / upper & lower @test_throws BoundsError ubd[n + 1, 1] @test_throws BoundsError ubd[1, n + 1] @@ -69,58 +69,57 @@ srand(1) @test isa(similar(ubd, Int, (3, 2)), Matrix{Int}) end - BD = Bidiagonal(dv, ev, true) @testset "show" begin + BD = Bidiagonal(dv, ev, :U) dstring = sprint(Base.print_matrix,BD.dv') estring = sprint(Base.print_matrix,BD.ev') @test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n super:$estring" - BD = Bidiagonal(dv,ev,false) + BD = Bidiagonal(dv,ev,:L) @test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n sub:$estring" end - @testset for isupper in (true, false) - T = Bidiagonal(dv, ev, isupper) + @testset for uplo in (:U, :L) + T = Bidiagonal(dv, ev, uplo) @testset "Constructor and basic properties" begin @test size(T, 1) == size(T, 2) == n @test size(T) == (n, n) - @test Array(T) == diagm(dv) + diagm(ev, isupper ? 1 : -1) - @test Bidiagonal(Array(T), isupper) == T + @test Array(T) == diagm(dv) + diagm(ev, uplo == :U ? 1 : -1) + @test Bidiagonal(Array(T), uplo) == T @test big.(T) == T - @test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper ? 1 : -1)) - @test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper ? 1 : -1)) - @test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper ? 1 : -1)) + @test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, uplo == :U ? 1 : -1)) + @test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, uplo == :U ? 1 : -1)) + @test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, uplo == :U ? 1 : -1)) end - z = zeros(elty, n) @testset for func in (conj, transpose, ctranspose) @test func(func(T)) == T end @testset "triu and tril" begin - @test istril(Bidiagonal(dv,ev,'L')) - @test !istril(Bidiagonal(dv,ev,'U')) - @test tril!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test tril!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(zeros(dv),ev,'L') - @test tril!(Bidiagonal(dv,ev,'U'),-2) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test tril!(Bidiagonal(dv,ev,'L'),-2) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test tril!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(dv,ev,'U') - @test tril!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(dv,ev,'L') - @test tril!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,zeros(ev),'U') - @test tril!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,ev,'L') - @test_throws ArgumentError tril!(Bidiagonal(dv,ev,'U'),n+1) + @test istril(Bidiagonal(dv,ev,:L)) + @test !istril(Bidiagonal(dv,ev,:U)) + @test tril!(Bidiagonal(dv,ev,:U),-1) == Bidiagonal(zeros(dv),zeros(ev),:U) + @test tril!(Bidiagonal(dv,ev,:L),-1) == Bidiagonal(zeros(dv),ev,:L) + @test tril!(Bidiagonal(dv,ev,:U),-2) == Bidiagonal(zeros(dv),zeros(ev),:U) + @test tril!(Bidiagonal(dv,ev,:L),-2) == Bidiagonal(zeros(dv),zeros(ev),:L) + @test tril!(Bidiagonal(dv,ev,:U),1) == Bidiagonal(dv,ev,:U) + @test tril!(Bidiagonal(dv,ev,:L),1) == Bidiagonal(dv,ev,:L) + @test tril!(Bidiagonal(dv,ev,:U)) == Bidiagonal(dv,zeros(ev),:U) + @test tril!(Bidiagonal(dv,ev,:L)) == Bidiagonal(dv,ev,:L) + @test_throws ArgumentError tril!(Bidiagonal(dv,ev,:U),n+1) - @test istriu(Bidiagonal(dv,ev,'U')) - @test !istriu(Bidiagonal(dv,ev,'L')) - @test triu!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test triu!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(zeros(dv),ev,'U') - @test triu!(Bidiagonal(dv,ev,'U'),2) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test triu!(Bidiagonal(dv,ev,'L'),2) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test triu!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(dv,ev,'U') - @test triu!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(dv,ev,'L') - @test triu!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,zeros(ev),'L') - @test triu!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,ev,'U') - @test_throws ArgumentError triu!(Bidiagonal(dv,ev,'U'),n+1) + @test istriu(Bidiagonal(dv,ev,:U)) + @test !istriu(Bidiagonal(dv,ev,:L)) + @test triu!(Bidiagonal(dv,ev,:L),1) == Bidiagonal(zeros(dv),zeros(ev),:L) + @test triu!(Bidiagonal(dv,ev,:U),1) == Bidiagonal(zeros(dv),ev,:U) + @test triu!(Bidiagonal(dv,ev,:U),2) == Bidiagonal(zeros(dv),zeros(ev),:U) + @test triu!(Bidiagonal(dv,ev,:L),2) == Bidiagonal(zeros(dv),zeros(ev),:L) + @test triu!(Bidiagonal(dv,ev,:U),-1) == Bidiagonal(dv,ev,:U) + @test triu!(Bidiagonal(dv,ev,:L),-1) == Bidiagonal(dv,ev,:L) + @test triu!(Bidiagonal(dv,ev,:L)) == Bidiagonal(dv,zeros(ev),:L) + @test triu!(Bidiagonal(dv,ev,:U)) == Bidiagonal(dv,ev,:U) + @test_throws ArgumentError triu!(Bidiagonal(dv,ev,:U),n+1) end Tfull = Array(T) @@ -187,24 +186,10 @@ srand(1) end end - @testset "Round,float,trunc,ceil" begin - if elty <: BlasReal - @test floor.(Int, T) == Bidiagonal(floor.(Int, T.dv), floor.(Int, T.ev), T.isupper) - @test isa(floor.(Int, T), Bidiagonal) - @test trunc.(Int,T) == Bidiagonal(trunc.(Int, T.dv), trunc.(Int, T.ev), T.isupper) - @test isa(trunc.(Int,T), Bidiagonal) - @test round.(Int, T) == Bidiagonal(round.(Int, T.dv), round.(Int, T.ev), T.isupper) - @test isa(round.(Int, T), Bidiagonal) - @test ceil.(Int,T) == Bidiagonal(ceil.(Int,T.dv), ceil.(Int,T.ev), T.isupper) - @test isa(ceil.(Int,T), Bidiagonal) - @test floor.(T) == Bidiagonal(floor.(T.dv), floor.(T.ev), T.isupper) - @test isa(floor.(T), Bidiagonal) - @test trunc.(T) == Bidiagonal(trunc.(T.dv), trunc.(T.ev), T.isupper) - @test isa(trunc.(T), Bidiagonal) - @test round.(T) == Bidiagonal(round.(T.dv), round.(T.ev), T.isupper) - @test isa(round.(T), Bidiagonal) - @test ceil.(T) == Bidiagonal(ceil.(T.dv), ceil.(T.ev), T.isupper) - @test isa(ceil.(T), Bidiagonal) + if elty <: BlasReal + @testset "$f" for f in (floor, trunc, round, ceil) + @test (f.(Int, T))::Bidiagonal == Bidiagonal(f.(Int, T.dv), f.(Int, T.ev), T.uplo) + @test (f.(T))::Bidiagonal == Bidiagonal(f.(T.dv), f.(T.ev), T.uplo) end end @@ -217,9 +202,9 @@ srand(1) if relty <: AbstractFloat d1, v1 = eig(T) d2, v2 = eig(map(elty<:Complex ? Complex128 : Float64,Tfull)) - @test (isupper ? d1 : reverse(d1)) ≈ d2 + @test (uplo == :U ? d1 : reverse(d1)) ≈ d2 if elty <: Real - Test.test_approx_eq_modphase(v1, isupper ? v2 : v2[:,n:-1:1]) + Test.test_approx_eq_modphase(v1, uplo == :U ? v2 : v2[:,n:-1:1]) end end end @@ -242,13 +227,13 @@ srand(1) end @testset "Binary operations" begin - @test -T == Bidiagonal(-T.dv,-T.ev,T.isupper) - @test convert(elty,-1.0) * T == Bidiagonal(-T.dv,-T.ev,T.isupper) - @test T * convert(elty,-1.0) == Bidiagonal(-T.dv,-T.ev,T.isupper) - @testset for isupper2 in (true, false) + @test -T == Bidiagonal(-T.dv,-T.ev,T.uplo) + @test convert(elty,-1.0) * T == Bidiagonal(-T.dv,-T.ev,T.uplo) + @test T * convert(elty,-1.0) == Bidiagonal(-T.dv,-T.ev,T.uplo) + @testset for uplo2 in (:U, :L) dv = convert(Vector{elty}, relty <: AbstractFloat ? randn(n) : rand(1:10, n)) ev = convert(Vector{elty}, relty <: AbstractFloat ? randn(n-1) : rand(1:10, n-1)) - T2 = Bidiagonal(dv, ev, isupper2) + T2 = Bidiagonal(dv, ev, uplo2) Tfull2 = Array(T2) for op in (+, -, *) @test Array(op(T, T2)) ≈ op(Tfull, Tfull2) @@ -258,22 +243,22 @@ srand(1) @test inv(T)*Tfull ≈ eye(elty,n) end - + BD = Bidiagonal(dv, ev, :U) @test Matrix{Complex{Float64}}(BD) == BD end # Issue 10742 and similar -let A = Bidiagonal([1,2,3], [0,0], true) +let A = Bidiagonal([1,2,3], [0,0], :U) @test istril(A) @test isdiag(A) end # test construct from range -@test Bidiagonal(1:3, 1:2, true) == [1 1 0; 0 2 2; 0 0 3] +@test Bidiagonal(1:3, 1:2, :U) == [1 1 0; 0 2 2; 0 0 3] @testset "promote_rule" begin - A = Bidiagonal(ones(Float32,10),ones(Float32,9),true) + A = Bidiagonal(ones(Float32,10),ones(Float32,9),:U) B = rand(Float64,10,10) C = Tridiagonal(rand(Float64,9),rand(Float64,10),rand(Float64,9)) @test promote_rule(Matrix{Float64}, Bidiagonal{Float64}) == Matrix{Float64} @@ -287,8 +272,8 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular let # fillslots! A = Tridiagonal(randn(2), randn(3), randn(2)) @test fillslots!(A, 3) == Tridiagonal([3, 3.], [3, 3, 3.], [3, 3.]) - B = Bidiagonal(randn(3), randn(2), true) - @test fillslots!(B, 2) == Bidiagonal([2.,2,2], [2,2.], true) + B = Bidiagonal(randn(3), randn(2), :U) + @test fillslots!(B, 2) == Bidiagonal([2.,2,2], [2,2.], :U) S = SymTridiagonal(randn(3), randn(2)) @test fillslots!(S, 1) == SymTridiagonal([1,1,1.], [1,1.]) Ult = UnitLowerTriangular(randn(3,3)) @@ -296,7 +281,7 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular end let # fill!(exotic, 0) exotic_arrays = Any[Tridiagonal(randn(3), randn(4), randn(3)), - Bidiagonal(randn(3), randn(2), rand(Bool)), + Bidiagonal(randn(3), randn(2), rand([:U,:L])), SymTridiagonal(randn(3), randn(2)), sparse(randn(3,4)), Diagonal(randn(5)), @@ -313,12 +298,12 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular end let # fill!(small, x) val = randn() - b = Bidiagonal(randn(1,1), true) + b = Bidiagonal(randn(1,1), :U) st = SymTridiagonal(randn(1,1)) for x in (b, st) @test Array(fill!(x, val)) == fill!(Array(x), val) end - b = Bidiagonal(randn(2,2), true) + b = Bidiagonal(randn(2,2), :U) st = SymTridiagonal(randn(3), randn(2)) t = Tridiagonal(randn(3,3)) for x in (b, t, st) diff --git a/test/linalg/cholesky.jl b/test/linalg/cholesky.jl index a90fe73b80e88..3174541a43d46 100644 --- a/test/linalg/cholesky.jl +++ b/test/linalg/cholesky.jl @@ -101,7 +101,7 @@ using Base.LinAlg: BlasComplex, BlasFloat, BlasReal, QRPivoted, PosDefException # test chol of 2x2 Strang matrix S = convert(AbstractMatrix{eltya},full(SymTridiagonal([2,2],[-1]))) - U = Bidiagonal([2,sqrt(eltya(3))],[-1],true) / sqrt(eltya(2)) + U = Bidiagonal([2,sqrt(eltya(3))],[-1],:U) / sqrt(eltya(2)) @test full(chol(S)) ≈ full(U) # test extraction of factor and re-creating original matrix diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index 501acb6f9d2b2..4b142dfc9891e 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -150,11 +150,11 @@ bimg = randn(n,2)/2 A = diagm(d) @test factorize(A) == Diagonal(d) A += diagm(e,-1) - @test factorize(A) == Bidiagonal(d,e,false) + @test factorize(A) == Bidiagonal(d,e,:L) A += diagm(f,-2) @test factorize(A) == LowerTriangular(A) A = diagm(d) + diagm(e,1) - @test factorize(A) == Bidiagonal(d,e,true) + @test factorize(A) == Bidiagonal(d,e,:U) if eltya <: Real A = diagm(d) + diagm(e,1) + diagm(e,-1) @test full(factorize(A)) ≈ full(factorize(SymTridiagonal(d,e))) diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index 4c7648548f04c..d41df65481fa7 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -142,7 +142,7 @@ y = ['a','b','c','d','e'] @test !ishermitian(ones(5,3)) @test cross(ones(3),ones(3)) == zeros(3) -@test trace(Bidiagonal(ones(5),zeros(4),true)) == 5 +@test trace(Bidiagonal(ones(5),zeros(4),:U)) == 5 # array and subarray tests diff --git a/test/linalg/lapack.jl b/test/linalg/lapack.jl index 4bc46b9e8a9aa..ab62c6a4f7048 100644 --- a/test/linalg/lapack.jl +++ b/test/linalg/lapack.jl @@ -52,7 +52,7 @@ end d, e = convert(Vector{elty}, randn(n)), convert(Vector{elty}, randn(n - 1)) U, Vt, C = eye(elty, n), eye(elty, n), eye(elty, n) s, _ = LAPACK.bdsqr!('U', copy(d), copy(e), Vt, U, C) - @test Array(Bidiagonal(d, e, true)) ≈ U*Diagonal(s)*Vt + @test Array(Bidiagonal(d, e, :U)) ≈ U*Diagonal(s)*Vt @test_throws ArgumentError LAPACK.bdsqr!('A', d, e, Vt, U, C) @test_throws DimensionMismatch LAPACK.bdsqr!('U', d, [e; 1], Vt, U, C) diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index ea9a81820f0b7..333e16a8ce604 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -349,8 +349,8 @@ let eltypes = [Float32, Float64, Int64] for k in [3, 4, 10] T = rand(eltypes) - bi1 = Bidiagonal(rand(T, k), rand(T, k-1), rand(Bool)) - bi2 = Bidiagonal(rand(T, k), rand(T, k-1), rand(Bool)) + bi1 = Bidiagonal(rand(T, k), rand(T, k-1), rand([:U, :L])) + bi2 = Bidiagonal(rand(T, k), rand(T, k-1), rand([:U, :L])) tri1 = Tridiagonal(rand(T,k-1), rand(T, k), rand(T, k-1)) tri2 = Tridiagonal(rand(T,k-1), rand(T, k), rand(T, k-1)) stri1 = SymTridiagonal(rand(T, k), rand(T, k-1)) @@ -372,8 +372,8 @@ let end end for T in eltypes - A = Bidiagonal(rand(T, 2), rand(T, 1), rand(Bool)) - B = Bidiagonal(rand(T, 2), rand(T, 1), rand(Bool)) + A = Bidiagonal(rand(T, 2), rand(T, 1), rand([:U, :L])) + B = Bidiagonal(rand(T, 2), rand(T, 1), rand([:U, :L])) C = randn(2,2) test_mul(C, A, B) B = randn(2, 9) diff --git a/test/linalg/rowvector.jl b/test/linalg/rowvector.jl index 6e40f94332de4..832510c243ba1 100644 --- a/test/linalg/rowvector.jl +++ b/test/linalg/rowvector.jl @@ -73,7 +73,7 @@ end end @testset "Bidiagonal ambiguity methods" begin - bd = Bidiagonal([1,2,3], [0,0], true) + bd = Bidiagonal([1,2,3], [0,0], :U) v = [2,3,4] rv = v.' diff --git a/test/linalg/special.jl b/test/linalg/special.jl index fb7896a6c2dd0..e65a7c14309b8 100644 --- a/test/linalg/special.jl +++ b/test/linalg/special.jl @@ -16,7 +16,7 @@ let a=[1.0:n;] for isupper in (true, false) debug && println("isupper is $(isupper)") - A=Bidiagonal(a, [1.0:n-1;], isupper) + A=Bidiagonal(a, [1.0:n-1;], ifelse(isupper, :U, :L)) for newtype in [Bidiagonal, Tridiagonal, Matrix] debug && println("newtype is $(newtype)") @test full(convert(newtype, A)) == full(A) @@ -26,7 +26,7 @@ let a=[1.0:n;] tritype = isupper ? UpperTriangular : LowerTriangular @test full(tritype(A)) == full(A) - A=Bidiagonal(a, zeros(n-1), isupper) #morally Diagonal + A=Bidiagonal(a, zeros(n-1), ifelse(isupper, :U, :L)) #morally Diagonal for newtype in [Diagonal, Bidiagonal, SymTridiagonal, Tridiagonal, Matrix] debug && println("newtype is $(newtype)") @test full(convert(newtype, A)) == full(A) @@ -129,7 +129,7 @@ end let N = 4 # Test concatenating pairwise combinations of special matrices diagmat = Diagonal(ones(N)) - bidiagmat = Bidiagonal(ones(N), ones(N-1), true) + bidiagmat = Bidiagonal(ones(N), ones(N-1), :U) tridiagmat = Tridiagonal(ones(N-1), ones(N), ones(N-1)) symtridiagmat = SymTridiagonal(ones(N), ones(N-1)) specialmats = (diagmat, bidiagmat, tridiagmat, symtridiagmat) @@ -182,7 +182,7 @@ let spvec = spzeros(N) spmat = speye(N) diagmat = Diagonal(ones(N)) - bidiagmat = Bidiagonal(ones(N), ones(N-1), true) + bidiagmat = Bidiagonal(ones(N), ones(N-1), :U) tridiagmat = Tridiagonal(ones(N-1), ones(N), ones(N-1)) symtridiagmat = SymTridiagonal(ones(N), ones(N-1)) sparseconcatmats = testfull ? (spmat, diagmat, bidiagmat, tridiagmat, symtridiagmat) : (spmat, diagmat) diff --git a/test/show.jl b/test/show.jl index 1bda43af49de9..02def842dd9fd 100644 --- a/test/show.jl +++ b/test/show.jl @@ -548,8 +548,8 @@ end # test structured zero matrix printing for select structured types A = reshape(1:16,4,4) @test replstr(Diagonal(A)) == "4×4 Diagonal{$Int}:\n 1 ⋅ ⋅ ⋅\n ⋅ 6 ⋅ ⋅\n ⋅ ⋅ 11 ⋅\n ⋅ ⋅ ⋅ 16" -@test replstr(Bidiagonal(A,true)) == "4×4 Bidiagonal{$Int}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" -@test replstr(Bidiagonal(A,false)) == "4×4 Bidiagonal{$Int}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16" +@test replstr(Bidiagonal(A,:U)) == "4×4 Bidiagonal{$Int}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" +@test replstr(Bidiagonal(A,:L)) == "4×4 Bidiagonal{$Int}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16" @test replstr(SymTridiagonal(A+A')) == "4×4 SymTridiagonal{$Int}:\n 2 7 ⋅ ⋅\n 7 12 17 ⋅\n ⋅ 17 22 27\n ⋅ ⋅ 27 32" @test replstr(Tridiagonal(diag(A,-1),diag(A),diag(A,+1))) == "4×4 Tridiagonal{$Int}:\n 1 5 ⋅ ⋅\n 2 6 10 ⋅\n ⋅ 7 11 15\n ⋅ ⋅ 12 16" @test replstr(UpperTriangular(copy(A))) == "4×4 UpperTriangular{$Int,Array{$Int,2}}:\n 1 5 9 13\n ⋅ 6 10 14\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" diff --git a/test/sparse/higherorderfns.jl b/test/sparse/higherorderfns.jl index 4b9e0a711af7a..e0d613ffdfb72 100644 --- a/test/sparse/higherorderfns.jl +++ b/test/sparse/higherorderfns.jl @@ -375,7 +375,7 @@ end sparsearrays = (V, A) fV, fA = map(Array, sparsearrays) D = Diagonal(rand(N)) - B = Bidiagonal(rand(N), rand(N - 1), true) + B = Bidiagonal(rand(N), rand(N - 1), :U) T = Tridiagonal(rand(N - 1), rand(N), rand(N - 1)) S = SymTridiagonal(rand(N), rand(N - 1)) structuredarrays = (D, B, T, S) @@ -426,13 +426,13 @@ end A = sprand(N, N, p) sA = A + transpose(A) D = Diagonal(rand(N)) - B = Bidiagonal(rand(N), rand(N - 1), true) + B = Bidiagonal(rand(N), rand(N - 1), :U) T = Tridiagonal(rand(N - 1), rand(N), rand(N - 1)) @test broadcast!(sin, copy(D), D) == Diagonal(sin.(D)) - @test broadcast!(sin, copy(B), B) == Bidiagonal(sin.(B), true) + @test broadcast!(sin, copy(B), B) == Bidiagonal(sin.(B), :U) @test broadcast!(sin, copy(T), T) == Tridiagonal(sin.(T)) @test broadcast!(*, copy(D), D, A) == Diagonal(broadcast(*, D, A)) - @test broadcast!(*, copy(B), B, A) == Bidiagonal(broadcast(*, B, A), true) + @test broadcast!(*, copy(B), B, A) == Bidiagonal(broadcast(*, B, A), :U) @test broadcast!(*, copy(T), T, A) == Tridiagonal(broadcast(*, T, A)) # SymTridiagonal (and similar symmetric matrix types) do not support setindex! # off the diagonal, and so cannot serve as a destination for broadcast! @@ -443,7 +443,7 @@ end A = sprand(N, N, p) Z, fA = copy(A), Array(A) D = Diagonal(rand(N)) - B = Bidiagonal(rand(N), rand(N - 1), true) + B = Bidiagonal(rand(N), rand(N - 1), :U) T = Tridiagonal(rand(N - 1), rand(N), rand(N - 1)) S = SymTridiagonal(rand(N), rand(N - 1)) structuredarrays = (D, B, T, S) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index 0c5f3ce9ba4ca..27c964f6c845c 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -1192,10 +1192,10 @@ end T = SymTridiagonal(randn(5),rand(4)) S = sparse(T) @test norm(Array(T) - Array(S)) == 0.0 - B = Bidiagonal(randn(5),randn(4),true) + B = Bidiagonal(randn(5),randn(4),:U) S = sparse(B) @test norm(Array(B) - Array(S)) == 0.0 - B = Bidiagonal(randn(5),randn(4),false) + B = Bidiagonal(randn(5),randn(4),:L) S = sparse(B) @test norm(Array(B) - Array(S)) == 0.0 end