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_zgesdd( int matrix_order, char jobz, lapack_int m,
00038 lapack_int n, lapack_complex_double* a,
00039 lapack_int lda, double* s, lapack_complex_double* u,
00040 lapack_int ldu, lapack_complex_double* vt,
00041 lapack_int ldvt )
00042 {
00043 lapack_int info = 0;
00044 lapack_int lwork = -1;
00045
00046 size_t lrwork;
00047 lapack_int* iwork = NULL;
00048 double* rwork = NULL;
00049 lapack_complex_double* work = NULL;
00050 lapack_complex_double work_query;
00051 if( matrix_order != LAPACK_COL_MAJOR && matrix_order != LAPACK_ROW_MAJOR ) {
00052 LAPACKE_xerbla( "LAPACKE_zgesdd", -1 );
00053 return -1;
00054 }
00055 #ifndef LAPACK_DISABLE_NAN_CHECK
00056
00057 if( LAPACKE_zge_nancheck( matrix_order, m, n, a, lda ) ) {
00058 return -5;
00059 }
00060 #endif
00061
00062 if( LAPACKE_lsame( jobz, 'n' ) ) {
00063 lrwork = MAX(1,5*MIN(m,n));
00064 } else {
00065 lrwork = (size_t)5*MAX(1,MIN(m,n))*MAX(1,MIN(m,n))+7*MIN(m,n);
00066 }
00067
00068 iwork = (lapack_int*)
00069 LAPACKE_malloc( sizeof(lapack_int) * MAX(1,8*MIN(m,n)) );
00070 if( iwork == NULL ) {
00071 info = LAPACK_WORK_MEMORY_ERROR;
00072 goto exit_level_0;
00073 }
00074 rwork = (double*)LAPACKE_malloc( sizeof(double) * lrwork );
00075 if( rwork == NULL ) {
00076 info = LAPACK_WORK_MEMORY_ERROR;
00077 goto exit_level_1;
00078 }
00079
00080 info = LAPACKE_zgesdd_work( matrix_order, jobz, m, n, a, lda, s, u, ldu, vt,
00081 ldvt, &work_query, lwork, rwork, iwork );
00082 if( info != 0 ) {
00083 goto exit_level_2;
00084 }
00085 lwork = LAPACK_Z2INT( work_query );
00086
00087 work = (lapack_complex_double*)
00088 LAPACKE_malloc( sizeof(lapack_complex_double) * lwork );
00089 if( work == NULL ) {
00090 info = LAPACK_WORK_MEMORY_ERROR;
00091 goto exit_level_2;
00092 }
00093
00094 info = LAPACKE_zgesdd_work( matrix_order, jobz, m, n, a, lda, s, u, ldu, vt,
00095 ldvt, work, lwork, rwork, iwork );
00096
00097 LAPACKE_free( work );
00098 exit_level_2:
00099 LAPACKE_free( rwork );
00100 exit_level_1:
00101 LAPACKE_free( iwork );
00102 exit_level_0:
00103 if( info == LAPACK_WORK_MEMORY_ERROR ) {
00104 LAPACKE_xerbla( "LAPACKE_zgesdd", info );
00105 }
00106 return info;
00107 }