|
16 | 16 |
|
17 | 17 | SymTridiagonal{T}(dv::Vector{T}, ev::Vector{T}) = SymTridiagonal{T}(dv, ev)
|
18 | 18 |
|
19 |
| -function SymTridiagonal{Td,Te}(dv::Vector{Td}, ev::Vector{Te}) |
| 19 | +function SymTridiagonal{Td,Te}(dv::AbstractVector{Td}, ev::AbstractVector{Te}) |
20 | 20 | T = promote_type(Td,Te)
|
21 | 21 | SymTridiagonal(convert(Vector{T}, dv), convert(Vector{T}, ev))
|
22 | 22 | end
|
@@ -271,17 +271,32 @@ immutable Tridiagonal{T} <: AbstractMatrix{T}
|
271 | 271 | du::Vector{T} # sup-diagonal
|
272 | 272 | du2::Vector{T} # supsup-diagonal for pivoting
|
273 | 273 | end
|
| 274 | + |
| 275 | +# Basic constructor takes in three dense vectors of same type |
274 | 276 | function Tridiagonal{T}(dl::Vector{T}, d::Vector{T}, du::Vector{T})
|
275 | 277 | n = length(d)
|
276 | 278 | if (length(dl) != n-1 || length(du) != n-1)
|
277 | 279 | throw(ArgumentError("Cannot make Tridiagonal from incompatible lengths of subdiagonal, diagonal and superdiagonal: ($(length(dl)), $(length(d)), $(length(du))"))
|
278 | 280 | end
|
279 | 281 | Tridiagonal(dl, d, du, zeros(T,n-2))
|
280 | 282 | end
|
281 |
| -function Tridiagonal{Tl, Td, Tu}(dl::Vector{Tl}, d::Vector{Td}, du::Vector{Tu}) |
| 283 | + |
| 284 | +# Construct from diagonals of any abstract vector, any eltype |
| 285 | +function Tridiagonal{Tl, Td, Tu}(dl::AbstractVector{Tl}, d::AbstractVector{Td}, du::AbstractVector{Tu}) |
282 | 286 | Tridiagonal(map(v->convert(Vector{promote_type(Tl,Td,Tu)}, v), (dl, d, du))...)
|
283 | 287 | end
|
284 | 288 |
|
| 289 | +# Provide a constructor Tridiagonal(A) similar to the triangulars, diagonal, symmetric |
| 290 | +""" |
| 291 | + Tridiagonal(A) |
| 292 | +
|
| 293 | +returns a `Tridiagonal` array based on (abstract) matrix `A`, using its lower diagonal, |
| 294 | +diagonal, and upper diagonal. |
| 295 | +""" |
| 296 | +function Tridiagonal(A::AbstractMatrix) |
| 297 | + return Tridiagonal(diag(A,-1), diag(A), diag(A,+1)) |
| 298 | +end |
| 299 | + |
285 | 300 | size(M::Tridiagonal) = (length(M.d), length(M.d))
|
286 | 301 | function size(M::Tridiagonal, d::Integer)
|
287 | 302 | if d < 1
|
|
0 commit comments