Developer Reference for Intel® oneAPI Math Kernel Library for C
?gelsd
Computes the minimum-norm solution to a linear least squares problem using the singular value decomposition of A and a divide and conquer method.
Syntax
lapack_int LAPACKE_sgelsd ( intmatrix_layout , lapack_intm , lapack_intn , lapack_intnrhs , float*a , lapack_intlda , float*b , lapack_intldb , float*s , floatrcond , lapack_int*rank );
lapack_int LAPACKE_dgelsd ( intmatrix_layout , lapack_intm , lapack_intn , lapack_intnrhs , double*a , lapack_intlda , double*b , lapack_intldb , double*s , doublercond , lapack_int*rank );
lapack_int LAPACKE_cgelsd ( intmatrix_layout , lapack_intm , lapack_intn , lapack_intnrhs , lapack_complex_float*a , lapack_intlda , lapack_complex_float*b , lapack_intldb , float*s , floatrcond , lapack_int*rank );
lapack_int LAPACKE_zgelsd ( intmatrix_layout , lapack_intm , lapack_intn , lapack_intnrhs , lapack_complex_double*a , lapack_intlda , lapack_complex_double*b , lapack_intldb , double*s , doublercond , lapack_int*rank );
Include Files
mkl.h
Description
sgelsd dgelsd cgelsd zgelsd gelsd
The routine computes the minimum-norm solution to a real linear least squares problem:
minimize ||b - A*x||_{2}
using the singular value decomposition (SVD) of A . A is an m -by- n matrix which may be rank-deficient.
Several right hand side vectors b and solution vectors x can be handled in a single call; they are stored as the columns of the m -by- nrhs right hand side matrix B and the n -by- nrhs solution matrix X .
The problem is solved in three steps:
Reduce the coefficient matrix A to bidiagonal form with Householder transformations, reducing the original problem into a “bidiagonal least squares problem” (BLS).
Solve the BLS using a divide and conquer approach.
Apply back all the Householder transformations to solve the original least squares problem.
The effective rank of A is determined by treating as zero those singular values which are less than rcond times the largest singular value.
The routine uses auxiliary routines lals0 and lalsa .
Input Parameters
- matrix_layout
-
Specifies whether matrix storage layout is row major ( LAPACK_ROW_MAJOR ) or column major ( LAPACK_COL_MAJOR ).
m
The number of rows of the matrix A ( m≥ 0 ).
n
The number of columns of the matrix A
( n≥ 0 ).
nrhs
The number of right-hand sides; the number of columns in B ( nrhs≥ 0 ).
- a , b , work
-
REAL for sgelsd DOUBLE PRECISION for dgelsd COMPLEX for cgelsd DOUBLE COMPLEX for zgelsd . Arrays:
a (size max(1, lda * n ) for column major layout and max(1, lda * m ) for row major layout) contains the m -by- n matrix A .
The second dimension of a must be at least max(1, n ).
b (size max(1, ldb * nrhs ) for column major layout and max(1, ldb *max( m , n )) for row major layout) contains the m -by- nrhs right hand side matrix B .
The second dimension of b must be at least max(1, nrhs ). work is a workspace array, its dimension max(1, lwork) .
lda
The leading dimension of a ; at least max(1, m ) for column major layout and max(1, n ) for row major layout .
ldb
The leading dimension of b ; must be at least max(1, m , n ) for column major layout and at least max(1, nrhs ) for row major layout .
- rcond
-
REAL for single-precision flavors DOUBLE PRECISION for double-precision flavors. rcond is used to determine the effective rank of A . Singular values s(i) ≤rcond *s(1) are treated as zero. If rcond≤ 0 , machine precision is used instead.
lwork
The size of the work array; lwork≥ 1 .
If lwork = -1 , then a workspace query is assumed; the routine only calculates the optimal size of the array work and the minimum sizes of the arrays rwork and iwork , and returns these values as the first entries of the work , rwork and iwork arrays, and no error message related to lwork is issued by xerbla . See Application Notes for the suggested value of lwork .
iwork
Workspace array. See Application Notes for the suggested dimension of iwork .
- rwork
-
REAL for cgelsd DOUBLE PRECISION for zgelsd . Workspace array, used in complex flavors only. See Application Notes for the suggested dimension of rwork .
Output Parameters
- a
-
On exit, A has been overwritten.
- b
-
Overwritten by the n -by- nrhs solution matrix X . If m≥n and rank = n , the residual sum-of-squares for the solution in the i -th column is given by the sum of squares of modulus of elements n +1: m in that column.
- s
-
REAL for single precision flavors DOUBLE PRECISION for double precision flavors. Array, size at least max(1, min( m , n )). The singular values of A in decreasing order. The condition number of A in the 2-norm is k_{2}(A) = s(1)/ s(min(m, n)) .
rank
The effective rank of A , that is, the number of singular values which are greater than rcond *s(1) .
- work(1)
-
If info = 0 , on exit, work(1) contains the minimum value of lwork required for optimum performance. Use this lwork for subsequent runs.
- rwork(1)
-
If info = 0 , on exit, rwork(1) returns the minimum size of the workspace array iwork required for optimum performance.
- iwork(1)
-
If info = 0 , on exit, iwork(1) returns the minimum size of the workspace array iwork required for optimum performance.
Return Values
This function returns a value info .
If info=0 , the execution is successful.
If info = -i , the i -th parameter had an illegal value.
If info = i , then the algorithm for computing the SVD failed to converge; i indicates the number of off-diagonal elements of an intermediate bidiagonal form that did not converge to zero.
LAPACK 95 Interface Notes
There exist FORTRAN 77 and FORTRAN 95 interfaces for this routine. See the Intel® oneMKL Fortran Developer Reference for details.
Application Notes
The divide and conquer algorithm makes very mild assumptions about floating point arithmetic. It will work on machines with a guard digit in add/subtract. It could conceivably fail on hexadecimal or decimal machines without guard digits, but we know of none.
The exact minimum amount of workspace needed depends on m , n and nrhs . The size lwork of the workspace array work must be as given below.
For real flavors :
If m≥n ,
\(lwork\geq 12n + 2n smlsiz + 8n nlvl + n nrhs + (smlsiz+1)^{2}\) ;
If m < n ,
\(lwork\geq 12m + 2m smlsiz + 8m nlvl + m nrhs + (smlsiz+1)^{2}\) ;
For complex flavors :
If m≥n ,
lwork< 2n + n*nrhs ;
If m < n ,
lwork≥ 2m + m*nrhs ;
where smlsiz is returned by ilaenv and is equal to the maximum size of the subproblems at the bottom of the computation tree (usually about 25), and
\(nlvl = INT( log_{2}( min( m, n )/(smlsiz+1)) ) + 1\) .
For good performance, lwork should generally be larger.
If you are in doubt how much workspace to supply, use a generous value of lwork for the first run or set lwork = -1 .
If you choose the first option and set any of admissible lwork sizes, which is no less than the minimal value described, the routine completes the task, though probably not so fast as with a recommended workspace, and provides the recommended workspace in the first element of the corresponding array work on exit. Use this value ( work(1) ) for subsequent runs.
If you set lwork = -1 , the routine returns immediately and provides the recommended workspace in the first element of the corresponding array ( work ). This operation is called a workspace query.
Note that if you set lwork to less than the minimal required value and not -1, the routine returns immediately with an error exit and does not provide any information on the recommended workspace.
The dimension of the workspace array iwork must be at least
3*min( m, n )*nlvl + 11*min( m, n ) .
The dimension of the workspace array iwork (for complex flavors) must be at least max(1, lrwork) .
\(lrwork\geq 10n + 2n smlsiz + 8n nlvl + 3 smlsiz nrhs + (smlsiz+1)^{2}\) if m≥n , and
\(lrwork\geq 10m + 2m smlsiz + 8m nlvl + 3 smlsiz nrhs + (smlsiz+1)^{2}\) if m < n .