diff --git a/src/wrapper/qr_mumps_api.jl b/src/wrapper/qr_mumps_api.jl index 2e1f12d..b114917 100644 --- a/src/wrapper/qr_mumps_api.jl +++ b/src/wrapper/qr_mumps_api.jl @@ -622,7 +622,9 @@ for (fname, elty) in ((:sqrm_least_squares_c, :Float32 ), return nothing end - function qrm_least_squares(spmat :: qrm_spmat{$elty}, b :: Vector{$elty}; transp :: Char='n') + function qrm_least_squares(spmat :: qrm_spmat{$elty}, b :: Vector{$elty}; transp :: Char='n', seminormal :: Bool = false) + seminormal && return qrm_least_squares_semi_normal(spmat, b, transp = transp) + nrhs = 1 if transp == 'n' x = zeros($elty, spmat.mat.n) @@ -635,7 +637,9 @@ for (fname, elty) in ((:sqrm_least_squares_c, :Float32 ), return x end - function qrm_least_squares(spmat :: qrm_spmat{$elty}, b :: Matrix{$elty}; transp :: Char='n') + function qrm_least_squares(spmat :: qrm_spmat{$elty}, b :: Matrix{$elty}; transp :: Char='n', seminormal :: Bool = false) + seminormal && return qrm_least_squares_semi_normal(spmat, b, transp = transp) + nrhs = size(b, 2) if transp == 'n' x = zeros($elty, spmat.mat.n, nrhs) @@ -651,14 +655,14 @@ for (fname, elty) in ((:sqrm_least_squares_c, :Float32 ), @inline qrm_least_squares!(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}, x :: Vector{$elty}) = qrm_least_squares!(spmat.parent, b, x, transp='t') @inline qrm_least_squares!(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}, x :: Matrix{$elty}) = qrm_least_squares!(spmat.parent, b, x, transp='t') - @inline qrm_least_squares(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}) = qrm_least_squares(spmat.parent, b, transp='t') - @inline qrm_least_squares(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}) = qrm_least_squares(spmat.parent, b, transp='t') + @inline qrm_least_squares(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}; seminormal :: Bool = false) = qrm_least_squares(spmat.parent, b, transp='t', seminormal = false) + @inline qrm_least_squares(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}; seminormal :: Bool = false) = qrm_least_squares(spmat.parent, b, transp='t', seminormal = false) @inline qrm_least_squares!(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}, x :: Vector{$elty}) = qrm_least_squares!(spmat.parent, b, x, transp='c') @inline qrm_least_squares!(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}, x :: Matrix{$elty}) = qrm_least_squares!(spmat.parent, b, x, transp='c') - @inline qrm_least_squares(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}) = qrm_least_squares(spmat.parent, b, transp='c') - @inline qrm_least_squares(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}) = qrm_least_squares(spmat.parent, b, transp='c') + @inline qrm_least_squares(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}; seminormal :: Bool = false) = qrm_least_squares(spmat.parent, b, transp='c', seminormal = false) + @inline qrm_least_squares(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}; seminormal :: Bool = false) = qrm_least_squares(spmat.parent, b, transp='c', seminormal = false) end end @@ -692,7 +696,9 @@ for (fname, elty) in ((:sqrm_min_norm_c, :Float32 ), return nothing end - function qrm_min_norm(spmat :: qrm_spmat{$elty}, b :: Vector{$elty}; transp :: Char='n') + function qrm_min_norm(spmat :: qrm_spmat{$elty}, b :: Vector{$elty}; transp :: Char='n', seminormal :: Bool = false) + seminormal && return qrm_min_norm_semi_normal(spmat, b, transp = transp) + nrhs = 1 if transp == 'n' x = zeros($elty, spmat.mat.n) @@ -704,7 +710,9 @@ for (fname, elty) in ((:sqrm_min_norm_c, :Float32 ), return x end - function qrm_min_norm(spmat :: qrm_spmat{$elty}, b :: Matrix{$elty}; transp :: Char='n') + function qrm_min_norm(spmat :: qrm_spmat{$elty}, b :: Matrix{$elty}; transp :: Char='n', seminormal :: Bool = false) + seminormal && return qrm_min_norm_semi_normal(spmat, b, transp = transp) + nrhs = size(b, 2) if transp == 'n' x = zeros($elty, spmat.mat.n, nrhs) @@ -719,14 +727,14 @@ for (fname, elty) in ((:sqrm_min_norm_c, :Float32 ), @inline qrm_min_norm!(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}, x :: Vector{$elty}) = qrm_min_norm!(spmat.parent, b, x, transp='t') @inline qrm_min_norm!(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}, x :: Matrix{$elty}) = qrm_min_norm!(spmat.parent, b, x, transp='t') - @inline qrm_min_norm(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}) = qrm_min_norm(spmat.parent, b, transp='t') - @inline qrm_min_norm(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}) = qrm_min_norm(spmat.parent, b, transp='t') + @inline qrm_min_norm(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}; seminormal :: Bool = false) = qrm_min_norm(spmat.parent, b, transp='t', seminormal = seminormal) + @inline qrm_min_norm(spmat :: Transpose{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}; seminormal :: Bool = false) = qrm_min_norm(spmat.parent, b, transp='t', seminormal = seminormal) @inline qrm_min_norm!(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}, x :: Vector{$elty}) = qrm_min_norm!(spmat.parent, b, x, transp='c') @inline qrm_min_norm!(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}, x :: Matrix{$elty}) = qrm_min_norm!(spmat.parent, b, x, transp='c') - @inline qrm_min_norm(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}) = qrm_min_norm(spmat.parent, b, transp='c') - @inline qrm_min_norm(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}) = qrm_min_norm(spmat.parent, b, transp='c') + @inline qrm_min_norm(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Vector{$elty}; seminormal :: Bool = false) = qrm_min_norm(spmat.parent, b, transp='c', seminormal = seminormal) + @inline qrm_min_norm(spmat :: Adjoint{$elty,qrm_spmat{$elty}}, b :: Matrix{$elty}; seminormal :: Bool = false) = qrm_min_norm(spmat.parent, b, transp='c', seminormal = seminormal) end end diff --git a/test/test_qrm.jl b/test/test_qrm.jl index e9f74e8..f57ee58 100644 --- a/test/test_qrm.jl +++ b/test/test_qrm.jl @@ -90,6 +90,10 @@ p = 5 r = b - A * x @test norm(A' * r) ≤ tol + x = qrm_least_squares(spmat, b, seminormal = true) + r = b - A * x + @test norm(A' * r) ≤ tol + x = qrm_least_squares_semi_normal(spmat, b) r = b - A * x @test norm(A' * r) ≤ tol @@ -102,6 +106,10 @@ p = 5 R = B - A * X @test norm(A' * R) ≤ tol + X = qrm_least_squares(spmat, B, seminormal = true) + R = B - A * X + @test norm(A' * R) ≤ tol + X = qrm_least_squares_semi_normal(spmat, B) R = B - A * X @test norm(A' * R) ≤ tol @@ -273,6 +281,10 @@ end r = b - A * x @test norm(r) ≤ tol + x = qrm_min_norm(spmat, b, seminormal = true) + r = b - A * x + @test norm(r) ≤ tol + x = qrm_min_norm_semi_normal(spmat, b) r = b - A * x @test norm(r) ≤ tol @@ -284,6 +296,10 @@ end X = qrm_min_norm(spmat, B) R = B - A * X @test norm(R) ≤ tol + + X = qrm_min_norm(spmat, B, seminormal = true) + R = B - A * X + @test norm(R) ≤ tol X = qrm_min_norm_semi_normal(spmat, B) R = B - A * X