JWS C Library
C language utility library
lapack.c File Reference

Definitions for functions from LAPACK. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <assert.h>
#include "jwsc/math/lapack.h"
Include dependency graph for lapack.c:

Go to the source code of this file.

Functions

static void trans_d (double **A_out, const double *A, int M, int N)
 Double precision matrix transpose.
static void trans_f (float **A_out, const float *A, int M, int N)
 Single precision matrix transpose.
void lapack_sgetrf (int M, int N, float *A, int lda, int *ipiv, int *info)
 Computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.
void lapack_dgetrf (int M, int N, double *A, int lda, int *ipiv, int *info)
 Computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.
void lapack_sgetri (int N, float *A, int lda, int *ipiv, float *work, int lwork, int *info)
 computes the inverse of a matrix using the LU factorization computed by SGETRF.
void lapack_dgetri (int N, double *A, int lda, int *ipiv, double *work, int lwork, int *info)
 computes the inverse of a matrix using the LU factorization computed by DGETRF.
void lapack_sgesdd (char JOBZ, int M, int N, float *A, int LDA, float *S, float *U, int LDU, float *VT, int LDVT, float *WORK, int LWORK, int *IWORK, int *INFO)
 computes the SVD of a matrix using a divide and conquer algorithm implemented by SGESDD.
void lapack_dgesdd (char JOBZ, int M, int N, double *A, int LDA, double *S, double *U, int LDU, double *VT, int LDVT, double *WORK, int LWORK, int *IWORK, int *INFO)
 computes the SVD of a matrix using a divide and conquer algorithm implemented by DGESDD.
void lapack_ssyev (char JOBZ, char UPLO, int N, float *A, int LDA, float *W, float *WORK, int LWORK, int *INFO)
 Computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.
void lapack_dsyev (char JOBZ, char UPLO, int N, double *A, int LDA, double *W, double *WORK, int LWORK, int *INFO)
 Computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.

Detailed Description

Definitions for functions from LAPACK.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Wraps the LAPACK library from netlib.

Input matrices are expected to be in row-major order; they are transposed before and after calling the wrapped Fortran routine.

Definition in file lapack.c.


Function Documentation

static void trans_d ( double **  A_out,
const double *  A,
int  M,
int  N 
) [static]

Double precision matrix transpose.

Definition at line 77 of file lapack.c.

static void trans_f ( float **  A_out,
const float *  A,
int  M,
int  N 
) [static]

Single precision matrix transpose.

Definition at line 99 of file lapack.c.

void lapack_sgetrf ( int  M,
int  N,
float *  A,
int  lda,
int *  ipiv,
int *  info 
)

Computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.

The factorization has the form

     A = P * L * U

where P is a permutation matrix, L is lower triangular with unit diagonal elements (lower trapezoidal if M > N), and U is upper triangular (upper trapezoidal if M < N).

Parameters:
MNumber of rows in A.
NNumber of columns in A.
AOn entry, the M-by-N matrix to be factored. On exit, the factors L and U from the factorization A = P*L*U; the unit diagonal elements of L are not stored.
ldaNumber of rows in A. Referred to as the leading dimension of A.
ipivThe pivot indices; for 1 <= i <= min(M,N), row i of the matrix was interchanged with row IPIV(i).
info= 0 successful exit; < 0 if INFO = -i, the i-th argument had an illegal value; > 0 if INFO = i, U(i,i) is exactly zero. The factorization has been completed, but the factor U is exactly singular, and division by zero will occur if it is used to solve a system of equations.

Definition at line 148 of file lapack.c.

void lapack_dgetrf ( int  M,
int  N,
double *  A,
int  lda,
int *  ipiv,
int *  info 
)

Computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.

The factorization has the form

     A = P * L * U

where P is a permutation matrix, L is lower triangular with unit diagonal elements (lower trapezoidal if M > N), and U is upper triangular (upper trapezoidal if M < N).

Parameters:
MNumber of rows in A.
NNumber of columns in A.
AOn entry, the M-by-N matrix to be factored. On exit, the factors L and U from the factorization A = P*L*U; the unit diagonal elements of L are not stored.
ldaNumber of rows in A. Referred to as the leading dimension of A.
ipivThe pivot indices; for 1 <= i <= min(M,N), row i of the matrix was interchanged with row IPIV(i).
info= 0 successful exit; < 0 if INFO = -i, the i-th argument had an illegal value; > 0 if INFO = i, U(i,i) is exactly zero. The factorization has been completed, but the factor U is exactly singular, and division by zero will occur if it is used to solve a system of equations.

Definition at line 195 of file lapack.c.

void lapack_sgetri ( int  N,
float *  A,
int  lda,
int *  ipiv,
float *  work,
int  lwork,
int *  info 
)

computes the inverse of a matrix using the LU factorization computed by SGETRF.

This method inverts U and then computes inv(A) by solving the system

     inv(A)*L = inv(U) for inv(A).
Parameters:
NThe order of the matrix A. N >= 0.
AOn entry, the factors L and U from the factorization A = P*L*U as computed by SGETRF. On exit, if INFO = 0, the inverse of the original matrix A.
ldaNumber of rows in A. Referred to as the leading dimension of A.
ipivThe pivot indices; for 1 <= i <= N, row i of the matrix was interchanged with row IPIV(i).
workOn exit, if INFO=0, then WORK(1) returns the optimal LWORK.
lworkThe dimension of the array WORK. LWORK >= max(1,N). For optimal performance LWORK >= N*NB, where NB is the optimal blocksize returned by ILAENV. If LWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.
info= 0 successful exit; < 0 if INFO = -i, the i-th argument had an illegal value; > 0 if INFO = i, U(i,i) is exactly zero, the matrix is singular and its inverse could not be computed.

Definition at line 243 of file lapack.c.

void lapack_dgetri ( int  N,
double *  A,
int  lda,
int *  ipiv,
double *  work,
int  lwork,
int *  info 
)

computes the inverse of a matrix using the LU factorization computed by DGETRF.

This method inverts U and then computes inv(A) by solving the system

     inv(A)*L = inv(U) for inv(A).
Parameters:
NThe order of the matrix A. N >= 0.
AOn entry, the factors L and U from the factorization A = P*L*U as computed by DGETRF. On exit, if INFO = 0, the inverse of the original matrix A.
ldaNumber of rows in A. Referred to as the leading dimension of A.
ipivThe pivot indices; for 1 <= i <= N, row i of the matrix was interchanged with row IPIV(i).
workOn exit, if INFO=0, then WORK(1) returns the optimal LWORK.
lworkThe dimension of the array WORK. LWORK >= max(1,N). For optimal performance LWORK >= N*NB, where NB is the optimal blocksize returned by ILAENV. If LWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.
info= 0 successful exit; < 0 if INFO = -i, the i-th argument had an illegal value; > 0 if INFO = i, U(i,i) is exactly zero, the matrix is singular and its inverse could not be computed.

Definition at line 292 of file lapack.c.

void lapack_sgesdd ( char  JOBZ,
int  M,
int  N,
float *  A,
int  LDA,
float *  S,
float *  U,
int  LDU,
float *  VT,
int  LDVT,
float *  WORK,
int  LWORK,
int *  IWORK,
int *  INFO 
)

computes the SVD of a matrix using a divide and conquer algorithm implemented by SGESDD.

SGESDD computes the singular value decomposition (SVD) of a real M-by-N matrix A, optionally computing the left and right singular vectors. If singular vectors are desired, it uses a divide-and-conquer algorithm.

The SVD is written

    A = U * SIGMA * transpose(V)

where SIGMA is an M-by-N matrix which is zero except for its min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA are the singular values of A; they are real and non-negative, and are returned in descending order. The first min(m,n) columns of U and V are the left and right singular vectors of A.

Note that the routine returns VT = V**T, not V.

Parameters:
JOBZ(input) CHARACTER*1 Specifies options for computing all or part of the matrix U: = 'A': all M columns of U and all N rows of V**T are returned in the arrays U and VT; = 'S': the first min(M,N) columns of U and the first min(M,N) rows of V**T are returned in the arrays U and VT; = 'O': If M >= N, the first N columns of U are overwritten on the array A and all rows of V**T are returned in the array VT; otherwise, all columns of U are returned in the array U and the first M rows of V**T are overwritten in the array A; = 'N': no columns of U or rows of V**T are computed.
M(input) INTEGER The number of rows of the input matrix A. M >= 0.
N(input) INTEGER The number of columns of the input matrix A. N >= 0.
A(input/output) REAL array, dimension (LDA,N) On entry, the M-by-N matrix A. On exit, if JOBZ = 'O', A is overwritten with the first N columns of U (the left singular vectors, stored columnwise) if M >= N; A is overwritten with the first M rows of V**T (the right singular vectors, stored rowwise) otherwise. if JOBZ .ne. 'O', the contents of A are destroyed.
LDA(input) INTEGER The leading dimension of the array A. LDA >= max(1,M).
S(output) REAL array, dimension (min(M,N)) The singular values of A, sorted so that S(i) >= S(i+1).
U(output) REAL array, dimension (LDU,UCOL) UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N; UCOL = min(M,N) if JOBZ = 'S'. If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M orthogonal matrix U; if JOBZ = 'S', U contains the first min(M,N) columns of U (the left singular vectors, stored columnwise); if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced.
LDU(input) INTEGER The leading dimension of the array U. LDU >= 1; if JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M.
VT(output) REAL array, dimension (LDVT,N) If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the N-by-N orthogonal matrix V**T; if JOBZ = 'S', VT contains the first min(M,N) rows of V**T (the right singular vectors, stored rowwise); if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced.
LDVT(input) INTEGER The leading dimension of the array VT. LDVT >= 1; if JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N; if JOBZ = 'S', LDVT >= min(M,N).
WORK(workspace/output) REAL array, dimension (MAX(1,LWORK)) On exit, if INFO = 0, WORK(1) returns the optimal LWORK;
LWORK(input) INTEGER The dimension of the array WORK. LWORK >= 1. If JOBZ = 'N', LWORK >= 3*min(M,N) + max(max(M,N),6*min(M,N)). If JOBZ = 'O', LWORK >= 3*min(M,N)*min(M,N) + max(max(M,N),5*min(M,N)*min(M,N)+4*min(M,N)). If JOBZ = 'S' or 'A' LWORK >= 3*min(M,N)*min(M,N) + max(max(M,N),4*min(M,N)*min(M,N)+4*min(M,N)). For good performance, LWORK should generally be larger. If LWORK = -1 but other input arguments are legal, WORK(1) returns the optimal LWORK.
IWORK(workspace) INTEGER array, dimension (8*min(M,N))
INFO(output) INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value. > 0: SBDSDC did not converge, updating process failed.

Definition at line 420 of file lapack.c.

void lapack_dgesdd ( char  JOBZ,
int  M,
int  N,
double *  A,
int  LDA,
double *  S,
double *  U,
int  LDU,
double *  VT,
int  LDVT,
double *  WORK,
int  LWORK,
int *  IWORK,
int *  INFO 
)

computes the SVD of a matrix using a divide and conquer algorithm implemented by DGESDD.

DGESDD computes the singular value decomposition (SVD) of a real M-by-N matrix A, optionally computing the left and right singular vectors. If singular vectors are desired, it uses a divide-and-conquer algorithm.

The SVD is written

    A = U * SIGMA * transpose(V)

where SIGMA is an M-by-N matrix which is zero except for its min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA are the singular values of A; they are real and non-negative, and are returned in descending order. The first min(m,n) columns of U and V are the left and right singular vectors of A.

Note that the routine returns VT = V**T, not V.

Parameters:
JOBZ(input) CHARACTER*1 Specifies options for computing all or part of the matrix U: = 'A': all M columns of U and all N rows of V**T are returned in the arrays U and VT; = 'S': the first min(M,N) columns of U and the first min(M,N) rows of V**T are returned in the arrays U and VT; = 'O': If M >= N, the first N columns of U are overwritten on the array A and all rows of V**T are returned in the array VT; otherwise, all columns of U are returned in the array U and the first M rows of V**T are overwritten in the array A; = 'N': no columns of U or rows of V**T are computed.
M(input) INTEGER The number of rows of the input matrix A. M >= 0.
N(input) INTEGER The number of columns of the input matrix A. N >= 0.
A(input/output) REAL array, dimension (LDA,N) On entry, the M-by-N matrix A. On exit, if JOBZ = 'O', A is overwritten with the first N columns of U (the left singular vectors, stored columnwise) if M >= N; A is overwritten with the first M rows of V**T (the right singular vectors, stored rowwise) otherwise. if JOBZ .ne. 'O', the contents of A are destroyed.
LDA(input) INTEGER The leading dimension of the array A. LDA >= max(1,M).
S(output) REAL array, dimension (min(M,N)) The singular values of A, sorted so that S(i) >= S(i+1).
U(output) REAL array, dimension (LDU,UCOL) UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N; UCOL = min(M,N) if JOBZ = 'S'. If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M orthogonal matrix U; if JOBZ = 'S', U contains the first min(M,N) columns of U (the left singular vectors, stored columnwise); if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced.
LDU(input) INTEGER The leading dimension of the array U. LDU >= 1; if JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M.
VT(output) REAL array, dimension (LDVT,N) If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the N-by-N orthogonal matrix V**T; if JOBZ = 'S', VT contains the first min(M,N) rows of V**T (the right singular vectors, stored rowwise); if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced.
LDVT(input) INTEGER The leading dimension of the array VT. LDVT >= 1; if JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N; if JOBZ = 'S', LDVT >= min(M,N).
WORK(workspace/output) REAL array, dimension (MAX(1,LWORK)) On exit, if INFO = 0, WORK(1) returns the optimal LWORK;
LWORK(input) INTEGER The dimension of the array WORK. LWORK >= 1. If JOBZ = 'N', LWORK >= 3*min(M,N) + max(max(M,N),6*min(M,N)). If JOBZ = 'O', LWORK >= 3*min(M,N)*min(M,N) + max(max(M,N),5*min(M,N)*min(M,N)+4*min(M,N)). If JOBZ = 'S' or 'A' LWORK >= 3*min(M,N)*min(M,N) + max(max(M,N),4*min(M,N)*min(M,N)+4*min(M,N)). For good performance, LWORK should generally be larger. If LWORK = -1 but other input arguments are legal, WORK(1) returns the optimal LWORK.
IWORK(workspace) INTEGER array, dimension (8*min(M,N))
INFO(output) INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value. > 0: SBDSDC did not converge, updating process failed.

Definition at line 608 of file lapack.c.

void lapack_ssyev ( char  JOBZ,
char  UPLO,
int  N,
float *  A,
int  LDA,
float *  W,
float *  WORK,
int  LWORK,
int *  INFO 
)

Computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.

SSYEV computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.

Parameters:
JOBZ(input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors.
UPLO(input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored.
N(input) INTEGER The order of the matrix A. N >= 0.
A(input/output) SINGLE PRECISION array, dimension (LDA, N) On entry, the symmetric matrix A. If UPLO = 'U', the leading N-by-N upper triangular part of A contains the upper triangular part of the matrix A. If UPLO = 'L', the leading N-by-N lower triangular part of A contains the lower triangular part of the matrix A. On exit, if JOBZ = 'V', then if INFO = 0, A contains the orthonormal eigenvectors of the matrix A. If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') or the upper triangle (if UPLO='U') of A, including the diagonal, is destroyed.
LDA(input) INTEGER The leading dimension of the array A. LDA >= max(1,N).
W(output) SINGLE PRECISION array, dimension (N) If INFO = 0, the eigenvalues in ascending order.
WORK(workspace/output) SINGLE PRECISION array, dimension (MAX(1,LWORK)) On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK(input) INTEGER The length of the array WORK. LWORK >= max(1,3*N-1). For optimal efficiency, LWORK >= (NB+2)*N, where NB is the blocksize for DSYTRD returned by ILAENV.

If LWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.

Parameters:
INFO(output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, the algorithm failed to converge; i off-diagonal elements of an intermediate tridiagonal form did not converge to zero.

Definition at line 744 of file lapack.c.

void lapack_dsyev ( char  JOBZ,
char  UPLO,
int  N,
double *  A,
int  LDA,
double *  W,
double *  WORK,
int  LWORK,
int *  INFO 
)

Computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.

DSYEV computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A.

Parameters:
JOBZ(input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors.
UPLO(input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored.
N(input) INTEGER The order of the matrix A. N >= 0.
A(input/output) DOUBLE PRECISION array, dimension (LDA, N) On entry, the symmetric matrix A. If UPLO = 'U', the leading N-by-N upper triangular part of A contains the upper triangular part of the matrix A. If UPLO = 'L', the leading N-by-N lower triangular part of A contains the lower triangular part of the matrix A. On exit, if JOBZ = 'V', then if INFO = 0, A contains the orthonormal eigenvectors of the matrix A. If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') or the upper triangle (if UPLO='U') of A, including the diagonal, is destroyed.
LDA(input) INTEGER The leading dimension of the array A. LDA >= max(1,N).
W(output) DOUBLE PRECISION array, dimension (N) If INFO = 0, the eigenvalues in ascending order.
WORK(workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK(input) INTEGER The length of the array WORK. LWORK >= max(1,3*N-1). For optimal efficiency, LWORK >= (NB+2)*N, where NB is the blocksize for DSYTRD returned by ILAENV.

If LWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.

Parameters:
INFO(output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, the algorithm failed to converge; i off-diagonal elements of an intermediate tridiagonal form did not converge to zero.

Definition at line 828 of file lapack.c.