Skip to content

Commit

Permalink
(f77) fix added f77 interfaces for a few Lapack QR RQ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
14NGiestas committed Dec 7, 2024
1 parent 38f3c7c commit 2c00961
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 14 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,24 @@ Most of BLAS level 1 routines can be replaced by intrinsincs and other features
| :+1: | potrf | Computes the Cholesky factorization of a symmetric (Hermitian) positive-definite matrix. |
| :+1: | potri | Computes the inverse of a Cholesky-factored symmetric (Hermitian) positive-definite matrix. |
| :+1: | potrs | Solves a system of linear equations with a Cholesky-factored symmetric (Hermitian) positive-definite coefficient matrix, with multiple right-hand sides. |
| | orgqr | Generates the real orthogonal matrix Q of the QR factorization formed by geqrf. |
| | ormqr | Multiplies a real matrix by the orthogonal matrix Q of the QR factorization formed by geqrf. |
| | ormrq | Multiplies a real matrix by the orthogonal matrix Q of the RQ factorization formed by gerqf. |
| | sytrf | Computes the Bunch-Kaufman factorization of a symmetric matrix. |
| | trtrs | Solves a system of linear equations with a triangular coefficient matrix, with multiple right-hand sides. |
| | ungqr | Generates the complex unitary matrix Q of the QR factorization formed by geqrf. |
| | unmqr | Multiplies a complex matrix by the unitary matrix Q of the QR factorization formed by geqrf. |
| | unmrq | Multiplies a complex matrix by the unitary matrix Q of the RQ factorization formed by gerqf. |
| f77 | orgqr | Generates the real orthogonal matrix Q of the QR factorization formed by geqrf. |
| f77 | orgrq | Generates the real orthogonal matrix Q of the RQ factorization formed by gerqf. |
| f77 | ormqr | Multiplies a real matrix by the orthogonal matrix Q of the QR factorization formed by geqrf. |
| f77 | ormrq | Multiplies a real matrix by the orthogonal matrix Q of the RQ factorization formed by gerqf. |
| | sytrf | Computes the Bunch-Kaufman factorization of a symmetric matrix. |
| | trtrs | Solves a system of linear equations with a triangular coefficient matrix, with multiple right-hand sides. |
| f77 | ungqr | Generates the complex unitary matrix Q of the QR factorization formed by geqrf. |
| f77 | ungrq | Generates the complex unitary matrix Q of the RQ factorization formed by gerqf. |
| f77 | unmqr | Multiplies a complex matrix by the unitary matrix Q of the QR factorization formed by geqrf. |
| f77 | unmrq | Multiplies a complex matrix by the unitary matrix Q of the RQ factorization formed by gerqf. |
| f77 | org2r | |
| f77 | orm2r | |
| f77 | ung2r | |
| f77 | unm2r | |
| f77 | orgr2 | |
| f77 | ormr2 | |
| f77 | ungr2 | |
| f77 | unmr2 | |

#### Singular Value and Eigenvalue Problem Routines
| done?| name | description |
Expand Down
1 change: 1 addition & 0 deletions ford.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ display: public
source: true
graph: true
search: true
sort: type
license: by-nc
max_frontpage_items: 4
extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html
Expand Down
23 changes: 21 additions & 2 deletions src/f77/lapack.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#:include "src/f77/lapack/gelsy.fypp"
#:include "src/f77/lapack/gglse.fypp"
#:include "src/f77/lapack/gglsm.fypp"
#:include "src/f77/lapack/org2r_orgr2_ung2r_ungr2.fypp"
#:include "src/f77/lapack/orgqr_orgrq_ungqr_ungrq.fypp"
#:include "src/f77/lapack/orm2r_ormr2_unm2r_unmr2.fypp"
#:include "src/f77/lapack/ormqr_ormrq_unmqr_unmrq.fypp"
#:set COLLECT = [ &
('?geqrf', DEFAULT_TYPES, geqrf_gerqf), &
('?gerqf', DEFAULT_TYPES, geqrf_gerqf), &
Expand All @@ -44,15 +48,30 @@
('?gelsy', DEFAULT_TYPES, gelsy), &
('?gglse', DEFAULT_TYPES, gglse), &
('?gglsm', DEFAULT_TYPES, gglsm), &
('?org2r', REAL_TYPES, org2r_orgr2_ung2r_ungr2), &
('?orgr2', REAL_TYPES, org2r_orgr2_ung2r_ungr2), &
('?orm2r', REAL_TYPES, orm2r_ormr2_unm2r_unmr2), &
('?ormr2', REAL_TYPES, orm2r_ormr2_unm2r_unmr2), &
('?ormqr', REAL_TYPES, ormqr_ormrq_unmqr_unmrq), &
('?ormrq', REAL_TYPES, ormqr_ormrq_unmqr_unmrq), &
('?orgqr', REAL_TYPES, orgqr_orgrq_ungqr_ungrq), &
('?orgrq', REAL_TYPES, orgqr_orgrq_ungqr_ungrq), &
('?ung2r', COMPLEX_TYPES, org2r_orgr2_ung2r_ungr2), &
('?ungr2', COMPLEX_TYPES, org2r_orgr2_ung2r_ungr2), &
('?unm2r', COMPLEX_TYPES, orm2r_ormr2_unm2r_unmr2), &
('?unmr2', COMPLEX_TYPES, orm2r_ormr2_unm2r_unmr2), &
('?unmqr', COMPLEX_TYPES, ormqr_ormrq_unmqr_unmrq), &
('?unmrq', COMPLEX_TYPES, ormqr_ormrq_unmqr_unmrq), &
('?ungqr', COMPLEX_TYPES, orgqr_orgrq_ungqr_ungrq), &
('?ungrq', COMPLEX_TYPES, orgqr_orgrq_ungqr_ungrq), &
('?lartg', DEFAULT_TYPES, lartg), &
]
#:endmute
#:endmute
!> Improved and original F77 interfaces for LAPACK
module f77_lapack
use iso_fortran_env
implicit none


#:for name, supported_types, code in COLLECT
$:f77_original(name, supported_types, code)
#:endfor
Expand Down
6 changes: 3 additions & 3 deletions src/f77/lapack/gesv.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ subroutine {s,d,c,z}gesv (
integer out ipiv(*),
type(wp) inout b(ldb,*),
integer in ldb,
integer out info
integer out info
)

#:def gesv(NAME,pfxs)
Expand Down Expand Up @@ -37,8 +37,8 @@ subroutine dsgesv (
real(dp) work( n, * ),
real(sp) swork( * ),
integer iter,
integer info
)
integer info
)

#:def gesv_mixed(NAME,pfxs)
#:set wp=pfxs[0]
Expand Down
40 changes: 40 additions & 0 deletions src/f77/lapack/org2r_orgr2_ung2r_ungr2.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#:mute
subroutine {s,d}org{2r,r2}(
subroutine {c,z}ung{2r,r2}(
integer m,
integer n,
integer k,
type(wp) a(lda,*),
integer lda,
type(wp) tau(*),
type(wp) work(*),
integer info
)

#:def org2r_orgr2_ung2r_ungr2(NAME,pfxs)
#:set wp=pfxs[0]
#:if NAME.endswith('2r')
!> This routine generates an \(M \times N \) ${type(wp)}$
!> matrix \( Q \) with orthonormal columns,
!> which is defined as the first \( N \) columns of a product of \( K \) elementary
!> reflectors of order \( M \).
!> \( Q = H(1) H(2) . . . H(k) \)
!> as returned by [[f77_geqrf:${wp}$geqrf]].
#:elif NAME.endswith('r2')
!> This routine generates an \(M \times N \) ${type(wp)}$
!> matrix \( Q \) with orthonormal rows,
!> which is defined as the last \( M \) rows of a product of \( K \) elementary
!> reflectors of order \( N \).
!> \( Q = H(1)^\dagger H(2)^\dagger \cdots H(k)^\dagger \)
!> as returned by [[f77_gerqf:${wp}$gerqf]].
#:endif
pure subroutine ${NAME}$(m, n, k, a, lda, tau, work, info)
$:imports(pfxs)
@:args(${type(wp)}$, inout, a(lda,*))
@:args(${type(wp)}$, out, work(*))
@:args(${type(wp)}$, in, tau(*))
@:args(integer, in, m, n, k, lda)
@:args(integer, out, info)
end subroutine
#:enddef
#:endmute
38 changes: 38 additions & 0 deletions src/f77/lapack/orgqr_orgrq_ungqr_ungrq.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#:mute
subroutine {s,d}org{qr,rq}(
subroutine {c,z}ung{qr,rq}(
integer m,
integer n,
integer k,
type(wp) a(lda,*),
integer lda,
type(wp) tau(*),
type(wp) work(*),
integer lwork,
integer info
)

#:def orgqr_orgrq_ungqr_ungrq(NAME,pfxs)
#:set wp=pfxs[0]
!> This routine generates an \(M \times N \) ${type(wp)}$
!> matrix \( Q \) with orthonormal columns,
!> which is defined as the first \( N \) columns of a product of \( K \) elementary
#:if NAME.endswith('qr')
!> reflectors of order \( M \).
!> \( Q = H(1) H(2) . . . H(k) \)
!> as returned by [[f77_geqrf:${wp}$geqrf]].
#:elif NAME.endswith('rq')
!> reflectors of order \( N \).
!> \( Q = H(1)^\dagger H(2)^\dagger . . . H(k)^\dagger \)
!> as returned by [[f77_gerqf:${wp}$gerqf]].
#:endif
pure subroutine ${NAME}$(m, n, k, a, lda, tau, work, lwork, info)
$:imports(pfxs)
@:args(${type(wp)}$, inout, a(lda,*))
@:args(${type(wp)}$, out, work(*))
@:args(${type(wp)}$, in, tau(*))
@:args(integer, in, m, n, k, lda, lwork)
@:args(integer, out, info)
end subroutine
#:enddef
#:endmute
48 changes: 48 additions & 0 deletions src/f77/lapack/orm2r_ormr2_unm2r_unmr2.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#:mute
subroutine {s,d}orm{2r,r2} (
subroutine {c,z}unm{2r,r2} (
character side,
character trans,
integer m,
integer n,
integer k,
type(wp) a(lda,*),
integer lda,
type(wp) tau(*),
type(wp) c(ldc,*),
integer ldc,
type(wp) work(*),
integer info
)

#:def orm2r_ormr2_unm2r_unmr2(NAME,pfxs)
#:set wp=pfxs[0]
!> This routine overwrites the general complex \(M \times N\) matrix \( C \) with
!>```fortran
!> SIDE = 'L' SIDE = 'R'
!> TRANS = 'N': Q * C C * Q
!> TRANS = 'C': Q**H * C C * Q**H
!>```
!> where Q is a complex unitary matrix defined as the product of k
!> elementary reflectors
!>
#:if NAME.endswith('2r')
!> \( Q = H(1) H(2) \cdots H(k) \)
!> as returned by [[f77_geqrf:${wp}$geqrf]].
#:elif NAME.endswith('r2')
!> \( Q = H(1)^\dagger H(2)^\dagger \cdots H(k)^\dagger \)
!> as returned by [[f77_gerqf:${wp}$gerqf]].
#:endif
!> \( Q \) is of order \( M \) if `SIDE = 'L'`
!> and of order \( N \) if `SIDE = 'R'`.
pure subroutine ${NAME}$(side, trans, m, n, k, a, lda, tau, c, ldc, work, info)
$:imports(pfxs)
@:args(character, in, side, trans)
@:args(${type(wp)}$, inout, a(lda,*), c(ldc,*))
@:args(${type(wp)}$, out, work(*))
@:args(${type(wp)}$, in, tau(*))
@:args(integer, in, m, n, k, lda, ldc)
@:args(integer, out, info)
end subroutine
#:enddef
#:endmute
49 changes: 49 additions & 0 deletions src/f77/lapack/ormqr_ormrq_unmqr_unmrq.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#:mute
subroutine {s,d}orm{qr,rq} (
subroutine {c,z}unm{qr,rq} (
character side,
character trans,
integer m,
integer n,
integer k,
type(wp) a(lda,*),
integer lda,
type(wp) tau(*),
type(wp) c(ldc,*),
integer ldc,
type(wp) work(*),
integer lwork,
integer info
)

#:def ormqr_ormrq_unmqr_unmrq(NAME,pfxs)
#:set wp=pfxs[0]
!> This routine overwrites the general complex \(M \times N\) matrix \( C \) with
!>```fortran
!> SIDE = 'L' SIDE = 'R'
!> TRANS = 'N': Q * C C * Q
!> TRANS = 'C': Q**H * C C * Q**H
!>```
!> where Q is a complex unitary matrix defined as the product of k
!> elementary reflectors
!>
#:if NAME.endswith('qr')
!> \( Q = H(1) H(2) \cdots H(k) \)
!> as returned by [[f77_geqrf:${wp}$geqrf]].
#:elif NAME.endswith('rq')
!> \( Q = H(1)^\dagger H(2)^\dagger \cdots H(k)^\dagger \)
!> as returned by [[f77_gerqf:${wp}$gerqf]].
#:endif
!> \( Q \) is of order \( M \) if `SIDE = 'L'`
!> and of order \( N \) if `SIDE = 'R'`.
pure subroutine ${NAME}$(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
$:imports(pfxs)
@:args(character, in, side, trans)
@:args(${type(wp)}$, inout, a(lda,*), c(ldc,*))
@:args(${type(wp)}$, out, work(*))
@:args(${type(wp)}$, in, tau(*))
@:args(integer, in, m, n, k, lda, ldc, lwork)
@:args(integer, out, info)
end subroutine
#:enddef
#:endmute
2 changes: 1 addition & 1 deletion src/mfi/blas/rot.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!> Given two vectors x and y,
!> each vector element of these vectors is replaced as follows:
!>```fortran
#:if type(A) == real(A)
#:if type(A) == real(A)
!> xi = c*xi + s*yi
!> yi = c*yi - s*xi
#:elif type(A) == complex(A)
Expand Down

0 comments on commit 2c00961

Please sign in to comment.