Skip to content

Commit 0d15abb

Browse files
Merge pull request #400 from JuliaLinearAlgebra/complex-bidiagonalization
add complex bidiagonalization methods from LAPACK
2 parents 19474cf + acebbf1 commit 0d15abb

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "0.17.37"
3+
version = "0.17.38"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/banded/BandedMatrix.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,20 @@ function _bidiagonalize!(A::AbstractMatrix{T}, M::BandedColumnMajor) where T
798798
Bidiagonal(d, e, :U)
799799
end
800800

801+
function _bidiagonalize!(A::AbstractMatrix{T}, M::BandedColumnMajor) where T <: Complex
802+
m, n = size(A)
803+
mn = min(m, n)
804+
d = Vector{real(T)}(undef, mn)
805+
e = Vector{real(T)}(undef, mn-1)
806+
Q = Matrix{T}(undef, 0, 0)
807+
Pt = Matrix{T}(undef, 0, 0)
808+
C = Matrix{T}(undef, 0, 0)
809+
work = Vector{T}(undef, 2*max(m, n))
810+
rwork = Vector{real(T)}(undef, 2*max(m, n))
811+
gbbrd!('N', m, n, 0, bandwidth(A, 1), bandwidth(A, 2), bandeddata(A), d, e, Q, Pt, C, work, rwork)
812+
Bidiagonal(d, e, :U)
813+
end
814+
801815
bidiagonalize!(A::AbstractMatrix) = _bidiagonalize!(A, MemoryLayout(typeof(A)))
802816
bidiagonalize(A::AbstractMatrix) = bidiagonalize!(copy(A))
803817

src/lapack.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,31 @@ for (fname, elty) in ((:dgbbrd_,:Float64),
190190
end
191191
end
192192

193+
for (fname, elty) in ((:zgbbrd_,:ComplexF64),
194+
(:cgbbrd_,:ComplexF32))
195+
@eval begin
196+
local Relty = real($elty)
197+
function gbbrd!(vect::Char, m::Int, n::Int, ncc::Int,
198+
kl::Int, ku::Int, ab::AbstractMatrix{$elty},
199+
d::AbstractVector{Relty}, e::AbstractVector{Relty}, Q::AbstractMatrix{$elty},
200+
Pt::AbstractMatrix{$elty}, C::AbstractMatrix{$elty}, work::AbstractVector{$elty},
201+
rwork::AbstractVector{Relty})
202+
info = Ref{BlasInt}()
203+
ccall((@blasfunc($fname), liblapack), Nothing,
204+
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt},
205+
Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt},
206+
Ptr{Relty}, Ptr{Relty}, Ptr{$elty}, Ref{BlasInt},
207+
Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{$elty}, Ptr{Relty}, Ptr{BlasInt}),
208+
vect, m, n, ncc,
209+
kl, ku, ab, max(1,stride(ab,2)),
210+
d, e, Q, max(1,stride(Q,2)),
211+
Pt, max(1,stride(Pt,2)), C, max(1,stride(C,2)), work, rwork, info)
212+
LAPACK.chklapackerror(info[])
213+
d, e, Q, Pt, C
214+
end
215+
end
216+
end
217+
193218
# All the eigenvalues and, optionally, eigenvectors of a real symmetric band matrix A.
194219
for (fname, elty) in ((:dsbev_,:Float64),
195220
(:ssbev_,:Float32))

test/test_banded.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,12 @@ Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef,
451451
end
452452

453453
@testset "induced norm" begin
454-
A = brand(Float64, 12, 10, 2, 3)
455-
B = Matrix(A)
456-
@test opnorm(A) opnorm(B)
457-
@test cond(A) cond(B)
454+
for T in (Float32, Float64, Complex{Float32}, Complex{Float64})
455+
A = brand(T, 12, 10, 2, 3)
456+
B = Matrix(A)
457+
@test opnorm(A) opnorm(B)
458+
@test cond(A) cond(B)
459+
end
458460
end
459461

460462
@testset "triu/tril" begin

0 commit comments

Comments
 (0)