Skip to content

Commit

Permalink
Add Type(dims) constructors for Bidiagonal, Tridiagonal, and
Browse files Browse the repository at this point in the history
SymTridiagonal

For Type in Bidiagonal, Tridiagonal, SymTridiagonal, support the
following:
Type(::Dims{2})
Type(::Integer, ::Integer)
Type{T}(::Dims{2})
Type{T}(::Integer, ::Integer)
  • Loading branch information
martinholters committed Jun 13, 2016
1 parent 304bfce commit bb16a82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ type Bidiagonal{T} <: AbstractMatrix{T}
end
new(dv, ev, isupper)
end
function Bidiagonal(m::Integer, n::Integer)
check_array_size(m, n)
checksquaredims(m, n, Bidiagonal{T})
new(Vector{T}(n), Vector{T}(n-1))
end
Bidiagonal(dims::Dims{2}) = Bidiagonal{T}(dims...)
end
Bidiagonal{T}(dv::AbstractVector{T}, ev::AbstractVector{T}, isupper::Bool) = Bidiagonal{T}(collect(dv), collect(ev), isupper)
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(m::Integer, n::Integer) = Bidiagonal{Float64}(m, n)
Bidiagonal(dims::Dims{2}) = Bidiagonal(dims...)

#Convert from BLAS uplo flag to boolean internal
Bidiagonal(dv::AbstractVector, ev::AbstractVector, uplo::Char) = begin
Expand Down
19 changes: 19 additions & 0 deletions base/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ immutable SymTridiagonal{T} <: AbstractMatrix{T}
end
new(dv,ev)
end
function SymTridiagonal(m::Integer, n::Integer)
check_array_size(m, n)
checksquaredims(m, n, SymTridiagonal{T})
new(Vector{T}(n), Vector{T}(n-1))
end
SymTridiagonal(dims::Dims{2}) = SymTridiagonal{T}(dims...)
end

SymTridiagonal{T}(dv::Vector{T}, ev::Vector{T}) = SymTridiagonal{T}(dv, ev)
SymTridiagonal(m::Integer, n::Integer) = SymTridiagonal{Float64}(m, n)
SymTridiagonal(dims::Dims{2}) = SymTridiagonal(dims...)

function SymTridiagonal{Td,Te}(dv::AbstractVector{Td}, ev::AbstractVector{Te})
T = promote_type(Td,Te)
Expand Down Expand Up @@ -312,7 +320,18 @@ immutable Tridiagonal{T} <: AbstractMatrix{T}
d::Vector{T} # diagonal
du::Vector{T} # sup-diagonal
du2::Vector{T} # supsup-diagonal for pivoting

Tridiagonal(dl::Vector{T}, d::Vector{T}, du::Vector{T}, du2::Vector{T}) = new(dl, d, du, du2)
function Tridiagonal(m::Integer, n::Integer)
check_array_size(m, n)
checksquaredims(m, n, Tridiagonal{T})
new(Vector{T}(n-1), Vector{T}(n), Vector{T}(n-1), Vector{T}(n-2))
end
Tridiagonal(dims::Dims{2}) = Tridiagonal{T}(dims...)
end
Tridiagonal{T}(dl::Vector{T}, d::Vector{T}, du::Vector{T}, du2::Vector{T}) = Tridiagonal{T}(dl, d, du, du2)
Tridiagonal(m::Integer, n::Integer) = Tridiagonal{Float64}(m, n)
Tridiagonal(dims::Dims{2}) = Tridiagonal(dims...)

# Basic constructor takes in three dense vectors of same type
function Tridiagonal{T}(dl::Vector{T}, d::Vector{T}, du::Vector{T})
Expand Down

0 comments on commit bb16a82

Please sign in to comment.