Skip to content

Commit

Permalink
add seminormal keyword argument for qrm_min_norm and qrm_least_square
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxenceGollier committed Dec 19, 2024
1 parent ab9b7a5 commit aa934fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/wrapper/qr_mumps_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/test_qrm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aa934fc

Please sign in to comment.