00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "lapacke.h"
00035 #include "lapacke_utils.h"
00036
00037 lapack_int LAPACKE_dgelsd( int matrix_order, lapack_int m, lapack_int n,
00038 lapack_int nrhs, double* a, lapack_int lda,
00039 double* b, lapack_int ldb, double* s, double rcond,
00040 lapack_int* rank )
00041 {
00042 lapack_int info = 0;
00043 lapack_int lwork = -1;
00044
00045 lapack_int liwork;
00046 lapack_int* iwork = NULL;
00047 double* work = NULL;
00048 lapack_int iwork_query;
00049 double work_query;
00050 if( matrix_order != LAPACK_COL_MAJOR && matrix_order != LAPACK_ROW_MAJOR ) {
00051 LAPACKE_xerbla( "LAPACKE_dgelsd", -1 );
00052 return -1;
00053 }
00054 #ifndef LAPACK_DISABLE_NAN_CHECK
00055
00056 if( LAPACKE_dge_nancheck( matrix_order, m, n, a, lda ) ) {
00057 return -5;
00058 }
00059 if( LAPACKE_dge_nancheck( matrix_order, MAX(m,n), nrhs, b, ldb ) ) {
00060 return -7;
00061 }
00062 if( LAPACKE_d_nancheck( 1, &rcond, 1 ) ) {
00063 return -10;
00064 }
00065 #endif
00066
00067 info = LAPACKE_dgelsd_work( matrix_order, m, n, nrhs, a, lda, b, ldb, s,
00068 rcond, rank, &work_query, lwork, &iwork_query );
00069 if( info != 0 ) {
00070 goto exit_level_0;
00071 }
00072 liwork = (lapack_int)iwork_query;
00073 lwork = (lapack_int)work_query;
00074
00075 iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * liwork );
00076 if( iwork == NULL ) {
00077 info = LAPACK_WORK_MEMORY_ERROR;
00078 goto exit_level_0;
00079 }
00080 work = (double*)LAPACKE_malloc( sizeof(double) * lwork );
00081 if( work == NULL ) {
00082 info = LAPACK_WORK_MEMORY_ERROR;
00083 goto exit_level_1;
00084 }
00085
00086 info = LAPACKE_dgelsd_work( matrix_order, m, n, nrhs, a, lda, b, ldb, s,
00087 rcond, rank, work, lwork, iwork );
00088
00089 LAPACKE_free( work );
00090 exit_level_1:
00091 LAPACKE_free( iwork );
00092 exit_level_0:
00093 if( info == LAPACK_WORK_MEMORY_ERROR ) {
00094 LAPACKE_xerbla( "LAPACKE_dgelsd", info );
00095 }
00096 return info;
00097 }