SF_LINALG
Description
SciFortran module for linear algebra
Quick access
- Routines:
build_tridiag(),check_tridiag(),cross_product(),det(),deye(),deye_tridiag(),diag(),diagonal(),eig(),eigh(),eigh_jacobi(),eigvals(),eigvalsh(),eye(),get_tridiag(),inv(),inv_gj(),inv_her(),inv_sym(),inv_triang(),inv_tridiag(),kron(),kronecker_product(),lstsq(),mat_product(),ones(),operator(.kx.)(),operator(.px.)(),operator(.x.)(),outerprod(),p_eigh(),p_inv(),p_mat_product(),s3_product(),solve(),svd(),svdvals(),trace(),zeros(),zeye(),zeye_tridiag()
Used modules
sf_blacs: SciFortran BLACS module (used bySF_LINALG)
Subroutines and functions
- interface sf_linalg/eig(a, eval, evec[, jobvl, jobvr])
This subroutine computes the eigenvalues and the right eigenvectors of a general (non-symmetric real or non-hermitian complex) square matrix
A, \(A v_j = \lambda_j v_j\), using the LAPACK routinesdgeev(real,deig) andzgeev(complex,zeig).The input matrix is not modified. The eigenvalues
Evalare complex and are returned in the order given by LAPACK. The eigenvectors are stored column-wise inEvec,Evec(:,j)being the eigenvector associated toEval(j). The right eigenvectors are computed unlessjobvr='N'. The left eigenvectors are not available: the program stops ifjobvl='V', ifAis not square, or ifEvecdoes not have shape[n,n].- Parameters:
a (•, •) [real/complex, in] – real matrix [n,n], not modified
eval (•) [complex, out] – eigenvalues, size n
evec (•, •) [complex, out] – right eigenvectors, [n,n]; Evec(:,j) <-> Eval(j)
- Options:
jobvl [character(len=1)] – optional, ‘N’ (default); ‘V’ is not supported
jobvr [character(len=1)] – optional, ‘V’ (default) computes the right eigenvectors, ‘N’ does not
- interface sf_linalg/eigh(am, bm, lam, c, a, e, d, u[, method, jobz, uplo, vl, vu, il, iu, tol, ev, irange, vrange])
This subroutine solves the eigenvalue problem of real symmetric or complex hermitian matrices. The eigenvalues are real and are returned in ascending order. The specific procedures cover
the generalized problem \(A c = \lambda B c\), with
Amsymmetric/hermitian andBmpositive definite (dsygvd,zhegvd), returning the eigenvalueslamand the eigenvectorsc, stored column-wise and normalized as \(c^H B c = 1\). Only the lower triangles ofAmandBmare referenced and the matrices are not modifiedthe simple problem \(A v = E v\), solved in place with the LAPACK driver chosen by
method:dsyevd(default),dsyevr,dsyevordsyevx, and thezhe...counterparts for hermitian matrices. Ifjobz='V'(default) the eigenvectors overwrite the columns ofA, otherwiseAis destroyed. The triangleuplo(default'U') is used. A subset of the spectrum can be selected, with therandxdrivers only, by value (vl,vu) or by index (il,iu)a real symmetric tridiagonal matrix, given by its main diagonal
Dand off-diagonalUand diagonalized withdstevr.DandUare overwritten, andDcontains the eigenvalues on output. The eigenvectors are computed only ifEvis present, and a subset of the spectrum can be selected by index withIrangeor by value withVrange
The program stops if the shapes of the arguments are inconsistent, or if the LAPACK routine returns an error code.
- Parameters:
am (•, •) [real/complex, in] – LHS matrix of Am c = lam Bm c, [n,n]
bm (•, •) [real/complex, in] – Bmt temporaries overwritten by dsygvd
lam (•) [real, out] – eigenvalues, ascending, size n
c (•, •) [real/complex, out] – eigenvectors, c(i,j) = i-th component of j-th vector, [n,n]
a (•, •) [real/complex, inout/in,required] – in: symmetric matrix; out: eigenvectors (columns) if jobz=V
e (size(a, 2)) [real, inout] – eigenvalues, ascending, size n (zero beyond the mE found)
d (•) [real, in,required] – in: main diagonal, size n; out: eigenvalues (first m valid)
u (max(1, -1 + size(d))) [real] – off-diagonal, size n-1; destroyed on exit
- Options:
method [character(len=*)] – optional: ‘dsyevd’ (default), ‘dsyevr’, ‘dsyev’, ‘dsyevx’
jobz [character(len=1)] – optional: ‘V’ (default) eigenvectors too, ‘N’ eigenvalues only
uplo [character(len=1)] – optional: ‘U’ (default) or ‘L’, triangle of A to be used
vl [real] – optional: lower bound of the eigenvalue interval (vl,vu]
vu [real] – optional: upper bound of the eigenvalue interval (vl,vu]
il [integer] – optional: index of the first eigenvalue wanted
iu [integer] – optional: index of the last eigenvalue wanted
tol [real] – optional: absolute eigenvalue tolerance (dsyevr/dsyevx), default 0
ev (•, •) [real] – optional out: eigenvectors, [n,m]
irange (2) [integer] – optional: [il,iu] indices of the first and last eigenvalue wanted
vrange (2) [integer] – optional: [vl,vu] eigenvalue interval (vl,vu]
- interface sf_linalg/p_eigh(a, w, nblock[, method, jobz, uplo, vl, vu, il, iu, tol])
This subroutine is the distributed-memory counterpart of
eighfor the simple problem, for real symmetric (p_deigh_simple) and complex hermitian (p_zeigh_simple) matrices, using ScaLAPACK. It is available only when compiling with_SCALAPACK.The matrix
A, a full copy of which is expected on every process, is distributed on the BLACS process grid of the module in a block-cyclic layout with square blocks of sizeNblock, and diagonalized with the driver chosen bymethod:PDSYEVR(default),PDSYEV,PDSYEVDorPDSYEVX. The eigenvalues are returned in ascending order inW, and ifjobz='V'the eigenvectors are gathered back intoA, column-wise.- Parameters:
a (•, •) [real/complex, inout/in,required] – in: symmetric matrix; out: eigenvectors (columns) if jobz=V
w (size(a, 2)) [real, inout] – eigenvalues, ascending, size n
nblock [integer] – block size of the block-cyclic distribution
- Options:
method [character(len=*)] – optional: ‘dsyevr’ (default), ‘dsyev’, ‘dsyevd’, ‘dsyevx’
jobz [character(len=1)] – optional: ‘V’ (default) eigenvectors too, ‘N’ eigenvalues only
uplo [character(len=1)] – optional: ‘L’ (default) or ‘U’, triangle of A to be used
vl [real] – optional: lower bound of the eigenvalue interval (vl,vu]
vu [real] – optional: upper bound of the eigenvalue interval (vl,vu]
il [integer] – optional: index of the first eigenvalue wanted
iu [integer] – optional: index of the last eigenvalue wanted
tol [real] – optional: accepted but currently not used
- interface sf_linalg/eigh_jacobi(a, d, v, nrot, u, sweep)
This subroutine computes all the eigenvalues and eigenvectors of a real symmetric (
d_jacobi) or complex hermitian (c_jacobi) matrix with the Jacobi method of plane rotations. Only the upper triangle of the input matrix is referenced and the matrix is destroyed. The eigenvalues are NOT sorted.real case: the eigenvectors are stored column-wise in
v,v(:,j)being associated tod(j). The number of rotations performed is returned innrotcomplex case: the eigenvectors are stored in the ROWS of
U, conjugated, so that \(A = U^\dagger \mathrm{diag}(D) U\). The sweep at which convergence was detected is returned insweep
The program stops if the matrix is not square or if convergence is not reached within 50 sweeps.
- Parameters:
a (•, •) [real/complex, inout] – in: symmetric matrix (upper triangle used); destroyed on exit
d (size(a, 1)) [real, out] – eigenvalues, NOT sorted, size n
v (size(a, 1), size(a, 2)) [real, out] – eigenvectors, v(:,j) <-> d(j), [n,n]
nrot [integer, out] – number of Jacobi rotations performed
u (size(a, 1), size(a, 2)) [complex, out] – eigenvectors: conjg(U(j,:)) <-> D(j), [n,n]
sweep [integer] – sweep at which convergence was detected
- interface sf_linalg/eigvals(a)
This function returns the eigenvalues of a general real or complex square matrix
A, computed with the LAPACK routinesdgeev(deigvals) andzgeev(zeigvals) without computing the eigenvectors. The input matrix is not modified. The result is a complex array of sizen, in the order given by LAPACK (not sorted). The program stops ifAis not square or if the LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex, in] – eigenvalues of A, A c = lam c, size n
- Result:
lam (size(a, 1)) [complex]
- interface sf_linalg/eigvalsh(a)
This function returns the eigenvalues of a real symmetric (
deigvalsh) or complex hermitian (zeigvalsh) matrixA, computed with the LAPACK routinesdsyevdandzheevdwithout computing the eigenvectors. Only the upper triangle ofAis referenced and the input matrix is not modified. The result is a real array, in ascending order. The program stops ifAis not square or if the LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex, in] – eigenvalues of A, ascending, size n
- Result:
lam (size(a, 1)) [real]
- interface sf_linalg/svdvals(a)
This function returns the singular values of a real (
dsvdvals) or complex (zsvdvals) \(m\times n\) matrixA, in descending order, computed with the LAPACK routinedgesvd(zgesvd) without computing the singular vectors. The input matrix is not modified. The result is a real array allocated with sizemin(m,n). The program stops if the LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex, in] – real matrix [m,n], not modified
- Result:
s (•) [real, allocatable] – = lda
- interface sf_linalg/svd(a, s, u, vtransp)
This subroutine computes the singular value decomposition \(A = U \Sigma V^T\) of a real (
dsvd) or \(A = U \Sigma V^H\) of a complex (zsvd) \(m\times n\) matrixA, with the LAPACK routinesdgesvdandzgesvd. The input matrix is not modified.The singular values
sare in descending order, and \(\Sigma\) is the \(m\times n\) matrix with \(\Sigma_{ii} = s_i\). The matricesUandVtranspare full, with shapes[m,m]and[n,n]. Note that the routine returns the transpose (conjugate transpose in the complex case) of \(V\), not \(V\). The program stops ifUorVtranspdo not have these shapes, or if the LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex, in] – real matrix [m,n], not modified
s (•) [real, out] – = lda
u (•, •) [real/complex, out] – left singular vectors (columns), [m,m]
vtransp (•, •) [real/complex, out] – V^T (V^H in the complex case), [n,n]
- interface sf_linalg/inv(am)
This subroutine inverts in place a general real (
dinv) or complex (zinv) square matrixAmusing the LU factorization with partial pivoting,dgetrf+dgetri(zgetrf+zgetri). On outputAmis replaced by its inverse. The program stops ifAmis not square, if it is singular, or if the LAPACK routines return an error code.- Parameters:
am (•, •) [real/complex, inout] – in: square matrix to be inverted; out: its inverse
- interface sf_linalg/p_inv(a, nblock)
This subroutine is the distributed-memory counterpart of
inv, for real (p_dinv) and complex (p_zinv) square matrices, using ScaLAPACK. It is available only when compiling with_SCALAPACK.The matrix
A, a full copy of which is expected on every process, is distributed on the BLACS process grid of the module in a block-cyclic layout with square blocks of sizeNblock, and inverted in place with the LU factorization,PDGETRF+PDGETRI(PZGETRF+PZGETRI). The inverse is gathered back intoA. The program stops ifAis not square or if a ScaLAPACK routine fails.- Parameters:
a (•, •) [real/complex, inout] – in: square matrix to be inverted; out: its inverse
nblock [integer] – block size of the block-cyclic distribution
- interface sf_linalg/inv_sym(a[, uplo])
This subroutine inverts in place a real symmetric (
dinv_sym) or complex symmetric (zinv_sym, NOT hermitian, seeinv_her) matrixAusing the Bunch-Kaufman factorization,dsytrf+dsytri(zsytrf+zsytri). Only the triangle selected byuplo(default'U') is referenced on input. On outputAcontains the full inverse, the computed triangle being mirrored onto the other one. The program stops if a LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex] – in: symmetric matrix; out: its inverse (full matrix)
- Options:
uplo [character(len=*)] – optional: ‘U’ (default) or ‘L’, triangle of A referenced
- interface sf_linalg/inv_her(a[, uplo])
This subroutine inverts in place a complex hermitian matrix
Ausing the Bunch-Kaufman factorization,zhetrf+zhetri. The hermiticity ofAis tested first. Only the triangle selected byuplo(default'U') is referenced by LAPACK, and on outputAcontains the full inverse, the other triangle being the complex conjugate of the computed one. The program stops ifAis not hermitian or if a LAPACK routine returns an error code.- Parameters:
a (•, •) [complex] – in: hermitian matrix; out: its inverse (full matrix)
- Options:
uplo [character(len=*)] – optional: ‘U’ (default) or ‘L’, triangle of A referenced
- interface sf_linalg/inv_triang(a[, uplo, diag])
This subroutine inverts in place a real (
dinv_triang) or complex (zinv_triang) triangular matrixAusing the LAPACK routinedtrtri(ztrtri). On output the triangle selected byuplo(default'U') contains the triangle of the inverse, the other one is not referenced. Ifdiag='U'the matrix is assumed unit triangular and its diagonal is not referenced, the default being'N'. The program stops if the LAPACK routine returns an error code, e.g. for a singular matrix.- Parameters:
a (•, •) [real/complex] – in: triangular matrix [n,n]; out: its inverse (same triangle)
- Options:
uplo [character(len=1)] – optional: ‘U’ (default) upper, ‘L’ lower triangular
diag [character(len=1)] – optional: ‘N’ (default) non-unit, ‘U’ unit triangular
- interface sf_linalg/inv_gj(a)
This subroutine inverts in place a real (
dinv_gj) or complex (zinv_gj) square matrixawith the Gauss-Jordan elimination with full pivoting. On outputais replaced by its inverse. The program stops if the matrix is singular.- Parameters:
a (•, •) [real/complex, inout] – in: square matrix [n,n]; out: its inverse
- interface sf_linalg/solve(a, b[, trans])
This subroutine solves the real or complex linear system \(A x = b\) using the LU factorization,
dgetrf+dgetrs(zgetrf+zgetrs). The specific procedures cover a single right-hand side (dsolve_1rhs,zsolve_1rhs) and several right-hand sides stored as the columns ofb(dsolve_mrhs,zsolve_mrhs).The solution overwrites
b. Note thatAis factorized in place: despite theintent(in)it contains the LU factors on exit, so a copy must be passed if the original matrix is needed afterwards. Iftransis'T'or'C'the transposed system \(A^T x = b\) is solved instead, the default being'N'. The program stops if a LAPACK routine returns an error code, e.g. for a singular matrix.- Parameters:
a (•, •) [real/complex, in] – square matrix [n,n]; overwritten by its LU factors
b (various shapes) [real/complex, inout] – in: right-hand side, size n; out: solution x
- Options:
trans [character(len=1)] – optional: ‘N’ (default) solve A x = b, ‘T’/’C’ solve A^T x = b
- interface sf_linalg/lstsq(a, b)
This function returns the least-squares solution \(x = \mathrm{argmin}_x \| A x - b \|_2\) of the real (
dlstsq) or complex (zlstsq) linear system \(A x = b\), with \(A\) an \(m\times n\) matrix of possibly non-square shape. It uses the LAPACK routinedgelsy(zgelsy), a complete orthogonal factorization with column pivoting, which is suitable also for rank-deficient matrices. The input arrays are not modified, and the solution is allocated with sizen. The program stops if the LAPACK routine returns an error code.- Parameters:
a (•, •) [real/complex, in] – real matrix [m,n], not modified
b (•) [real/complex, in] – right-hand side, size m, not modified
- Result:
x (•) [real/complex, allocatable] – least-squares solution, size n
- interface sf_linalg/inv_tridiag(sub_, diag_, over_, inv, ainv, amat, nb, n[, n, nb])
This subroutine returns the diagonal elements, or the diagonal blocks, of the inverse of a real or complex (block) tridiagonal matrix, without building the full inverse, using a downward and an upward recursion. The specific procedures cover
a tridiagonal matrix given by its sub-diagonal
sub_, main diagonaldiag_and over-diagonalover_, of sizeN: theNdiagonal elements of the inverse are returned inInva block tridiagonal matrix given by its block diagonals, made of
Nbblocks of size \(N\times N\): theNbdiagonal blocks of the inverse are returned inAinva full tridiagonal matrix
Amat, or a full block tridiagonal matrixAmatmade ofNbblocks of size \(N\times N\), treated in place: the diagonals are extracted withget_tridiagand on outputAmatis a diagonal (block diagonal) matrix containing the diagonal elements (blocks) of the inverse
The tridiagonal structure of the input is not checked, see
check_tridiag. The program stops if a zero pivot is found, i.e. if the matrix is ill-conditioned, or ifAmatis not square.- Options:
n [integer, optional,default=1 + shape(sub, 0)] – size of the matrix
nb [integer, optional,default=1 + shape(sub, 0)] – number of blocks
- Parameters:
sub_ (various shapes) [real/complex] – sub-diagonal, A(i+1,i), size N-1
diag_ (various shapes) [real/complex] – main diagonal, size N
over_ (various shapes) [real/complex] – over-diagonal, A(i,i+1), size N-1
inv (n) [real/complex] – diagonal elements of the inverse matrix, size N
ainv (nb, n, n) [real/complex] – diagonal blocks of the inverse matrix, [Nb,N,N]
amat (various shapes) [real/complex, inout] – in: tridiagonal [N,N]; out: diag. matrix of inverse diagonal
- interface sf_linalg/check_tridiag(amat, nblock, nsize)
This function checks whether a real or complex matrix
Amatis tridiagonal, i.e. whether all the elements outside the main, sub- and over-diagonals are exactly zero. The specific procedures cover a plain matrix and a matrix made ofNblockblocks of size \(N_{size}\times N_{size}\), to be checked for block tridiagonal structure. The result is.true.for a (block) tridiagonal matrix. The program stops if a plain matrix is not square.- Parameters:
amat (various shapes) [real/complex] – square matrix [N,N] to be checked
nblock [integer, in,required] – number of blocks
nsize [integer, in,required] – size of each block
- Result:
mcheck [logical] – .true. if Amat is tridiagonal
- interface sf_linalg/get_tridiag(amat, sub, diag, nblock, nsize[, over])
This subroutine extracts the three diagonals of a real or complex tridiagonal matrix
Amat: the sub-diagonalsub(i) = A(i+1,i), the main diagonaldiag(i) = A(i,i)and, optionally, the over-diagonalover(i) = A(i,i+1). The block version, for a matrix made ofNblockblocks of size \(N_{size}\times N_{size}\), extracts the block diagonalssub(i,:,:) = A(i+1,i),diag(i,:,:) = A(i,i)andover(i,:,:) = A(i,i+1). The input matrix is not modified and its structure is not checked, seecheck_tridiag. The inverse operation isbuild_tridiag.- Parameters:
amat (various shapes) [real/complex, in,required] – tridiagonal matrix [N,N]
sub (various shapes) [real/complex] – sub-diagonal, A(i+1,i), size N-1
diag (various shapes) [real/complex] – main diagonal, size N
nblock [integer, in,required,default=1 + shape(sub, 0)] – number of blocks
nsize [integer, in,required] – size of each block
- Options:
over (various shapes) [real/complex] – optional out: over-diagonal, A(i,i+1), size N-1
- interface sf_linalg/build_tridiag(sub, diag[, over, nblock, nsize])
This function builds a real or complex tridiagonal matrix from its three diagonals: the sub-diagonal
A(i+1,i) = sub(i), the main diagonalA(i,i) = diag(i)and the over-diagonalA(i,i+1) = over(i). Ifoveris not present the matrix is symmetric,over = sub. The block version, withNblockblocks of size \(N_{size}\times N_{size}\), builds a block tridiagonal matrix from the block diagonalssub(i,:,:),diag(i,:,:)andover(i,:,:). The inverse operation isget_tridiag.- Parameters:
sub (various shapes) [real/complex] – sub-diagonal, size N-1
diag (various shapes) [real/complex, in,required] – main diagonal, size N
- Options:
over (various shapes) [real/complex] – optional: over-diagonal, size N-1 (default: over = sub)
nblock [integer, optional,default=1 + shape(sub, 0)] – number of blocks
nsize [integer] – size of each block
- Result:
amat (various shapes) [real/complex] – tridiagonal matrix, [N,N]
- interface sf_linalg/det(a)
This function returns the determinant of a real (
ddet) or complex (zdet) square matrixA, computed from its LU factorization (dgetrf,zgetrf) as the product of the diagonal elements of \(U\) with the sign changes due to the row permutations. The input matrix is not modified. The program stops ifAis not square, or if the LAPACK routine returns an error code, which includes the case of an exactly singular matrix.- Parameters:
a (•, •) [real/complex, in] – square matrix [n,n], not modified
- Result:
x [real/complex] – determinant of A
- interface sf_linalg/deye(n, i, j)
This function returns real identity matrices or matrix elements: if one integer input variable is provided, it returns the the \(n\times n\) identity matrix
deye(n)(deye_matrix). If instead two integer input variables are provided, it returns the Kronecker delta \(\delta_{ij}\), 1 ifi==jand 0 otherwise (deye_indices). It is the same aseye, and the complex version iszeye.- Parameters:
n [integer, in] – size of the matrix
i [integer, in] – first index
j [integer, in] – second index
- Result:
a (various shapes) [real] – identity matrix [n,n] or matrix element (scalar)
- interface sf_linalg/zeye(n, i, j)
This function returns complex identity matrices or matrix elements: if one integer input variable is provided, it returns the the \(n\times n\) identity matrix
zeye(n)(zeye_matrix). If instead two integer input variables are provided, it returns the Kronecker delta \(\delta_{ij}\), 1 ifi==jand 0 otherwise (zeye_indices).- Parameters:
n [integer, in] – size of the matrix
i [integer, in] – first index
j [integer, in] – second index
- Result:
a (various shapes) [complex] – identity matrix [n,n] or matrix element (scalar)
- interface sf_linalg/eye(n, i, j)
This function returns real identity matrices or matrix elements: if one integer input variable is provided, it returns the the \(n\times n\) identity matrix
deye(n)(deye_matrix). If instead two integer input variables are provided, it returns the Kronecker delta \(\delta_{ij}\), 1 ifi==jand 0 otherwise (deye_indices). It is the same asdeye, and the complex version iszeye.- Parameters:
n [integer, in] – size of the matrix
i [integer, in] – first index
j [integer, in] – second index
- Result:
a (various shapes) [real] – identity matrix [n,n] or matrix element (scalar)
- interface sf_linalg/diag(x)
This function builds a real (
ddiag) or complex (zdiag) square matrix with the elements of the arrayxon the main diagonal and zeros elsewhere. The inverse operation isdiagonal.- Parameters:
x (•) [real/complex, in] – diagonal elements, size n
- Result:
a (•, •) [real/complex, allocatable] – diagonal matrix, A(i,i) = x(i), [n,n]
- interface sf_linalg/diagonal(a)
This function returns the main diagonal of a real (
d_diagonal) or complex (z_diagonal) matrixA, expected to be square: the size of the result issize(A,1). The inverse operation isdiag.- Parameters:
a (•, •) [real/complex, in] – square matrix [n,n]
- Result:
dd (size(a, 1)) [real/complex] – diagonal elements, dd(i) = A(i,i), size n
- interface sf_linalg/trace(a)
This function returns the trace of a real (
dtrace) or complex (ztrace) matrixA, i.e. the sum of the elements along the main diagonal. For a non-square matrix the sum runs up tomin(m,n).- Parameters:
a (•, •) [real/complex, in] – real matrix [m,n]
- Result:
t [real/complex] – trace of A
- interface sf_linalg/zeros(n, n1, n2, n3, n4, n5, n6, n7)
This function returns a complex(8) array with all the elements set to 0. The shape is given by one integer extent for each dimension,
zeros(n1,...,nk), and the ranks from 1 to 7 are covered.- Parameters:
n [integer, in] – extent of dimension 1
n1 [integer, in] – extent of dimension 1
n2 [integer, in] – extent of dimension 2
n3 [integer, in] – extent of dimension 3
n4 [integer, in] – extent of dimension 4
n5 [integer, in] – extent of dimension 5
n6 [integer, in] – extent of dimension 6
n7 [integer, in] – extent of dimension 7
- Result:
a (various shapes) [complex] – complex array, [n]
- interface sf_linalg/ones(n, n1, n2, n3, n4, n5, n6, n7)
This function returns a complex(8) array with all the elements set to 1. The shape is given by one integer extent for each dimension,
ones(n1,...,nk), and the ranks from 1 to 7 are covered.- Parameters:
n [integer, in] – extent of dimension 1
n1 [integer, in] – extent of dimension 1
n2 [integer, in] – extent of dimension 2
n3 [integer, in] – extent of dimension 3
n4 [integer, in] – extent of dimension 4
n5 [integer, in] – extent of dimension 5
n6 [integer, in] – extent of dimension 6
n7 [integer, in] – extent of dimension 7
- Result:
a (various shapes) [complex] – complex array, [n]
- interface sf_linalg/kron(a, b)
This function returns the Kronecker (tensor) product \(A \otimes B\) of two matrices
AandB, i.e. the block matrix whose \((i,j)\) block is \(A_{ij} B\). The result has shape[size(A,1)*size(B,1),size(A,2)*size(B,2)]. The specific procedures cover integer, real, real \(\otimes\) complex, complex \(\otimes\) real and complex matrices, the result being complex if any of the two is complex. It is the same askronecker_productand as the operator.kx..- Parameters:
a (•, •) [integer/real/complex, in] – first factor, [rowA,colA]
b (•, •) [integer/real/complex, in] – Kronecker product, [rowA*rowB,colA*colB]
- Result:
axb (size(a, 1) · size(b, 1), size(a, 2) · size(b, 2)) [integer/real/complex]
- interface sf_linalg/kronecker_product(a, b)
This function returns the Kronecker (tensor) product \(A \otimes B\) of two matrices
AandB, i.e. the block matrix whose \((i,j)\) block is \(A_{ij} B\). The result has shape[size(A,1)*size(B,1),size(A,2)*size(B,2)]. The specific procedures cover integer, real, real \(\otimes\) complex, complex \(\otimes\) real and complex matrices, the result being complex if any of the two is complex. It is the same askronand as the operator.kx..- Parameters:
a (•, •) [integer/real/complex, in] – first factor, [rowA,colA]
b (•, •) [integer/real/complex, in] – Kronecker product, [rowA*rowB,colA*colB]
- Result:
axb (size(a, 1) · size(b, 1), size(a, 2) · size(b, 2)) [integer/real/complex]
- interface sf_linalg/operator(.kx.)(a, b)
This operator returns the Kronecker (tensor) product \(A \otimes B\) of two matrices
AandB, i.e. the block matrix whose \((i,j)\) block is \(A_{ij} B\). The result has shape[size(A,1)*size(B,1),size(A,2)*size(B,2)]. The specific procedures cover integer, real, real \(\otimes\) complex, complex \(\otimes\) real and complex matrices, the result being complex if any of the two is complex. It is used asAxB = A .kx. B, and it is the same askron.- Parameters:
a (•, •) [integer/real/complex, in] – first factor, [rowA,colA]
b (•, •) [integer/real/complex, in] – Kronecker product, [rowA*rowB,colA*colB]
- Result:
axb (size(a, 1) · size(b, 1), size(a, 2) · size(b, 2)) [integer/real/complex]
- interface sf_linalg/outerprod(a, b)
This function returns the outer product of two real or complex one-dimensional arrays
aandb, i.e. the matrix \(A_{ij} = a_i b_j\), of shape[size(a),size(b)]. No complex conjugation is applied.- Parameters:
a (•) [real/complex, in]
b (•) [real/complex, in]
- Result:
outerprod (size(a), size(b)) [real/complex]
- interface sf_linalg/cross_product(a, b)
This function returns the cross (vector) product \(c = a \times b\) of two real or complex vectors
aandbwith 3 components, \(c_1 = a_2 b_3 - a_3 b_2\), \(c_2 = a_3 b_1 - a_1 b_3\), \(c_3 = a_1 b_2 - a_2 b_1\). Only the 3-dimensional version is available through this interface.- Parameters:
a (3) [real/complex]
b (3) [real/complex]
- Result:
c (3) [real/complex]
- interface sf_linalg/s3_product(a, b, c)
This function returns the triple product \(a \cdot (b \times c)\) of three real or complex vectors
a,bandcwith 3 components, evaluated asdot_product(a,cross_product(b,c)). The result is a real number: in the complex caseais conjugated bydot_productand the imaginary part of the result is discarded.- Parameters:
a (3) [real/complex, in]
b (3) [real/complex, in]
c (3) [real/complex, in]
- Result:
s3 [real]
- interface sf_linalg/mat_product(a, b, c[, alfa, beta])
This subroutine computes the real (
d_matmul) or complex (z_matmul) matrix-matrix product \(C = \alpha A B + \beta C\) with the BLAS routinedgemm(zgemm), \(A\) being \(N\times K\), \(B\) \(K\times M\) and \(C\) \(N\times M\). By default \(\alpha=1\) and \(\beta=0\), so thatCcontains the plain product \(A B\) on output.AandBare not modified. The program stops ifBorCdo not have the shapes[K,M]and[N,M]. The function form is the operator.x..- Parameters:
a (•, •) [real/complex, inout] – matrix [N,K], not modified
b (•, •) [real/complex, inout] – matrix [K,M], not modified
c (•, •) [real/complex, inout] – in/out: C = alfa*A*B + beta*C, [N,M]
- Options:
alfa [real/complex] – optional scalar, default 1
beta [real/complex] – optional scalar, default 0
- interface sf_linalg/operator(.x.)(a, b)
This operator returns the real or complex matrix-matrix product \(C = A B\), computed with the BLAS routine
dgemm(zgemm), \(A\) being \(N\times K\) and \(B\) \(K\times M\). It is used asC = A .x. B, through the functionsd_matmul_andz_matmul_. The program stops ifBdoes not have the shape[K,M]. The subroutine form ismat_product.- Parameters:
a (•, •) [real/complex, in] – matrix [N,K]
b (•, •) [real/complex, in] – matrix [K,M]
- Result:
c (size(a, 1), size(b, 2)) [real/complex] – product A*B, [N,M]
- interface sf_linalg/p_mat_product(a, b, c, nblock[, alfa, beta])
This subroutine is the distributed-memory counterpart of
mat_product: it computes the real (p_d_matmul) or complex (p_z_matmul) matrix-matrix product \(C = \alpha A B + \beta C\) with the ScaLAPACK routinePDGEMM(PZGEMM). It is available only when compiling with_SCALAPACK.The matrices
AandB, full copies of which are expected on every process, are distributed on the BLACS process grid of the module in a block-cyclic layout with square blocks of sizeNblock, and the product is gathered back intoC. By default \(\alpha=1\) and \(\beta=0\). The program stops ifBorCdo not have the shapes[K,M]and[N,M]. The function form is the operator.Px..- Parameters:
a (•, •) [real/complex, inout] – matrix [N,K]
b (•, •) [real/complex, inout] – matrix [K,M]
c (various shapes) [real/complex, inout] – out: product alfa*A*B, [N,M]
nblock [integer] – block size of the block-cyclic distribution
- Options:
alfa [real] – optional scalar, default 1
beta [real] – optional scalar, default 0
- interface sf_linalg/operator(.px.)(a, b)
This operator returns the real or complex matrix-matrix product \(C = A B\), computed in parallel with the ScaLAPACK routine
PDGEMM(PZGEMM), \(A\) being \(N\times K\) and \(B\) \(K\times M\). It is used asC = A .Px. B, through the functionsp_d_matmul_fandp_z_matmul_f, and it is available only when compiling with_SCALAPACK. The block size of the block-cyclic distribution is chosen automatically, as the largest power of 2 smaller thanmin(N,K,M), up to 64. The program stops ifBdoes not have the shape[K,M]. The subroutine form isp_mat_product.- Parameters:
a (•, •) [real/complex, in] – matrix [N,K]
b (•, •) [real/complex, in] – matrix [K,M]
- Result:
c (size(a, 1), size(b, 2)) [real/complex] – product A*B, [N,M]
- function sf_linalg/deye_tridiag(nblock, n)
This function returns
Nblockreal \(N\times N\) identity matrices stacked in a rank-3 array, i.e. the blocks of a block identity matrix. It can be used to build block tridiagonal matrices, seebuild_tridiag.- Parameters:
nblock [integer] – number of blocks
n [integer] – size of each block
- Result:
eye_block (nblock, n, n) [real] – identity blocks, eye_block(i,:,:) = 1, [Nblock,N,N]
- function sf_linalg/zeye_tridiag(nblock, n)
This function is the complex counterpart of
deye_tridiag: it returnsNblockcomplex \(N\times N\) identity matrices stacked in a rank-3 array.- Parameters:
nblock [integer] – number of blocks
n [integer] – size of each block
- Result:
eye_block (nblock, n, n) [complex] – identity blocks, eye_block(i,:,:) = 1, [Nblock,N,N]