Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/yalapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
#! format: on
@eval begin
# Flexible QR / LQ
function geqr!(A::AbstractMatrix{$elty})
#=function geqr!(A::AbstractMatrix{$elty})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should actually start using this one if no explicit block size is given. It lowers to two different implementations depending on the m versus n ratio, and chooses an optimal block size.

require_one_based_indexing(A)
chkstride1(A)
m, n = size(A)
Expand Down Expand Up @@ -162,7 +162,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
end
end
return A, t
end
end=#

# Classic QR / LQ / QL / RQ
function geqrf!(
Expand Down Expand Up @@ -231,7 +231,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
end
return A, tau
end
function geqlf!(
#=function geqlf!(
A::AbstractMatrix{$elty},
tau::AbstractVector{$elty} = similar(A, $elty, min(size(A)...))
)
Expand Down Expand Up @@ -296,7 +296,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
end
end
return A, tau
end
end=#

# QR and LQ with block reflectors
#! format: off
Expand Down Expand Up @@ -441,7 +441,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
#! format: on
@eval begin
# multiply with Q factor of flexible QR / LQ
function gemqr!(
#=function gemqr!(
side::AbstractChar, trans::AbstractChar, A::AbstractMatrix{$elty},
T::AbstractVector{$elty}, C::AbstractVecOrMat{$elty}
)
Expand Down Expand Up @@ -544,7 +544,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
end
end
return C
end
end=#

# Build Q factor of classic QR / LQ / QL / RQ in the space of `A`
function ungqr!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
Expand Down Expand Up @@ -615,7 +615,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
end
return A
end
function ungql!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
#=function ungql!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
require_one_based_indexing(A, tau)
chkstride1(A, tau)
m, n = size(A)
Expand Down Expand Up @@ -682,7 +682,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
end
end
return A
end
end=#

# multiply with Q factor of classic QR / LQ / QL / RQ
function unmqr!(
Expand Down Expand Up @@ -781,7 +781,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
end
return C
end
function unmql!(
#=function unmql!(
side::AbstractChar, trans::AbstractChar,
A::AbstractMatrix{$elty}, tau::AbstractVector{$elty},
C::AbstractVecOrMat{$elty}
Expand Down Expand Up @@ -876,7 +876,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
end
end
return C
end
end=#

# Multiply with blocked Q factor from QR / LQ
function gemqrt!(
Expand Down
4 changes: 4 additions & 0 deletions test/schur.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ for T in (BLASFloats..., GenericFloats...)
end
if !is_buildkite
TestSuite.test_schur(T, (m, m))
if T ∈ BLASFloats
LAPACK_SCHUR_ALGS = (LAPACK_Simple(), LAPACK_Expert())
TestSuite.test_schur_algs(T, (m, m), LAPACK_SCHUR_ALGS)
end
#AT = Diagonal{T, Vector{T}}
#TestSuite.test_schur(AT, m) # not supported yet
end
Expand Down
3 changes: 3 additions & 0 deletions test/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ for T in (BLASFloats..., GenericFloats...), m in (0, 54), n in (0, 37, m, 63)
)
TestSuite.test_svd(T, (m, n))
TestSuite.test_svd_algs(T, (m, n), LAPACK_SVD_ALGS)
@static if VERSION > v"1.11-" # Jacobi broken on 1.10
m ≥ n && TestSuite.test_svd_algs(T, (m, n), (LAPACK_Jacobi(),); test_full = false, test_vals = false)
end
elseif T ∈ GenericFloats
TestSuite.test_svd(T, (m, n))
TestSuite.test_svd_algs(T, (m, n), (GLA_QRIteration(),))
Expand Down
55 changes: 55 additions & 0 deletions test/testsuite/decompositions/schur.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ function test_schur(T::Type, sz; kwargs...)
end
end

function test_schur_algs(T::Type, sz, algs; kwargs...)
summary_str = testargs_summary(T, sz)
return @testset "schur algorithms $summary_str" begin
test_schur_full_algs(T, sz, algs; kwargs...)
test_schur_vals_algs(T, sz, algs; kwargs...)
end
end

function test_schur_full(
T::Type, sz;
atol::Real = 0, rtol::Real = precision(T),
Expand All @@ -34,6 +42,31 @@ function test_schur_full(
end
end

function test_schur_full_algs(
T::Type, sz, algs;
atol::Real = 0, rtol::Real = precision(T),
kwargs...
)
summary_str = testargs_summary(T, sz)
return @testset "schur_full! algorithm $alg $summary_str" for alg in algs
A = instantiate_matrix(T, sz)
Ac = deepcopy(A)
Tc = isa(A, Diagonal) ? eltype(T) : complex(eltype(T))

TA, Z, vals = @testinferred schur_full(A; alg)
@test eltype(TA) == eltype(Z) == eltype(T)
@test eltype(vals) == Tc
@test isisometric(Z)
@test A * Z ≈ Z * TA

TA2, Z2, vals2 = @testinferred schur_full!(Ac, (TA, Z, vals); alg)
@test TA2 === TA
@test Z2 === Z
@test vals2 === vals
@test A * Z ≈ Z * TA
end
end

function test_schur_vals(
T::Type, sz;
atol::Real = 0, rtol::Real = precision(T),
Expand All @@ -55,3 +88,25 @@ function test_schur_vals(
@test valsc ≈ eig_vals(A)
end
end

function test_schur_vals_algs(
T::Type, sz, algs;
atol::Real = 0, rtol::Real = precision(T),
kwargs...
)
summary_str = testargs_summary(T, sz)
return @testset "schur_vals! algorithm $alg $summary_str" for alg in algs
A = instantiate_matrix(T, sz)
Ac = deepcopy(A)
Tc = isa(A, Diagonal) ? eltype(T) : complex(eltype(T))

valsc = @testinferred schur_vals(A; alg)
@test eltype(valsc) == Tc
@test valsc ≈ eig_vals(A)

valsc = similar(A, Tc, size(A, 1))
valsc = @testinferred schur_vals!(Ac, valsc; alg)
@test eltype(valsc) == Tc
@test valsc ≈ eig_vals(A)
end
end
32 changes: 18 additions & 14 deletions test/testsuite/decompositions/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ using TestExtras
using GenericLinearAlgebra
using LinearAlgebra: opnorm

function test_svd(T::Type, sz; kwargs...)
function test_svd(T::Type, sz; test_compact::Bool = true, test_full::Bool = true, test_trunc::Bool = true, kwargs...)
summary_str = testargs_summary(T, sz)
return @testset "svd $summary_str" begin
test_svd_compact(T, sz; kwargs...)
test_svd_full(T, sz; kwargs...)
test_svd_trunc(T, sz; kwargs...)
test_compact && test_svd_compact(T, sz; kwargs...)
test_full && test_svd_full(T, sz; kwargs...)
test_trunc && test_svd_trunc(T, sz; kwargs...)
end
end

function test_svd_algs(T::Type, sz, algs; kwargs...)
function test_svd_algs(T::Type, sz, algs; test_compact::Bool = true, test_full::Bool = true, test_trunc::Bool = true, kwargs...)
summary_str = testargs_summary(T, sz)
return @testset "svd algorithms $summary_str" begin
test_svd_compact_algs(T, sz, algs; kwargs...)
test_svd_full_algs(T, sz, algs; kwargs...)
test_svd_trunc_algs(T, sz, algs; kwargs...)
test_compact && test_svd_compact_algs(T, sz, algs; kwargs...)
test_full && test_svd_full_algs(T, sz, algs; kwargs...)
test_trunc && test_svd_trunc_algs(T, sz, algs; kwargs...)
end
end

function test_svd_compact(
T::Type, sz;
atol::Real = 0, rtol::Real = precision(eltype(T)),
kwargs...
test_vals::Bool = true, kwargs...
)
summary_str = testargs_summary(T, sz)
return @testset "svd_compact! $summary_str" begin
Expand All @@ -47,15 +47,17 @@ function test_svd_compact(
@test isisometric(V2ᴴ; side = :right)
@test isposdef(S2)

Sd = @testinferred svd_vals(A)
@test S ≈ Diagonal(Sd)
if test_vals
Sd = @testinferred svd_vals(A)
@test S ≈ Diagonal(Sd)
end
end
end

function test_svd_compact_algs(
T::Type, sz, algs;
atol::Real = 0, rtol::Real = precision(eltype(T)),
kwargs...
test_vals::Bool = true, kwargs...
)
summary_str = testargs_summary(T, sz)
return @testset "svd_compact! algorithm $alg $summary_str" for alg in algs
Expand All @@ -78,8 +80,10 @@ function test_svd_compact_algs(
@test isisometric(V2ᴴ; side = :right)
@test isposdef(S2)

Sd = @testinferred svd_vals(A; alg)
@test S ≈ Diagonal(Sd)
if test_vals
Sd = @testinferred svd_vals(A; alg)
@test S ≈ Diagonal(Sd)
end
end
end

Expand Down
Loading