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_cggsvd_work( int matrix_order, char jobu, char jobv,
00038 char jobq, lapack_int m, lapack_int n,
00039 lapack_int p, lapack_int* k, lapack_int* l,
00040 lapack_complex_float* a, lapack_int lda,
00041 lapack_complex_float* b, lapack_int ldb,
00042 float* alpha, float* beta,
00043 lapack_complex_float* u, lapack_int ldu,
00044 lapack_complex_float* v, lapack_int ldv,
00045 lapack_complex_float* q, lapack_int ldq,
00046 lapack_complex_float* work, float* rwork,
00047 lapack_int* iwork )
00048 {
00049 lapack_int info = 0;
00050 if( matrix_order == LAPACK_COL_MAJOR ) {
00051
00052 LAPACK_cggsvd( &jobu, &jobv, &jobq, &m, &n, &p, k, l, a, &lda, b, &ldb,
00053 alpha, beta, u, &ldu, v, &ldv, q, &ldq, work, rwork,
00054 iwork, &info );
00055 if( info < 0 ) {
00056 info = info - 1;
00057 }
00058 } else if( matrix_order == LAPACK_ROW_MAJOR ) {
00059 lapack_int lda_t = MAX(1,m);
00060 lapack_int ldb_t = MAX(1,p);
00061 lapack_int ldq_t = MAX(1,n);
00062 lapack_int ldu_t = MAX(1,m);
00063 lapack_int ldv_t = MAX(1,p);
00064 lapack_complex_float* a_t = NULL;
00065 lapack_complex_float* b_t = NULL;
00066 lapack_complex_float* u_t = NULL;
00067 lapack_complex_float* v_t = NULL;
00068 lapack_complex_float* q_t = NULL;
00069
00070 if( lda < n ) {
00071 info = -11;
00072 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00073 return info;
00074 }
00075 if( ldb < n ) {
00076 info = -13;
00077 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00078 return info;
00079 }
00080 if( ldq < n ) {
00081 info = -21;
00082 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00083 return info;
00084 }
00085 if( ldu < m ) {
00086 info = -17;
00087 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00088 return info;
00089 }
00090 if( ldv < p ) {
00091 info = -19;
00092 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00093 return info;
00094 }
00095
00096 a_t = (lapack_complex_float*)
00097 LAPACKE_malloc( sizeof(lapack_complex_float) * lda_t * MAX(1,n) );
00098 if( a_t == NULL ) {
00099 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00100 goto exit_level_0;
00101 }
00102 b_t = (lapack_complex_float*)
00103 LAPACKE_malloc( sizeof(lapack_complex_float) * ldb_t * MAX(1,n) );
00104 if( b_t == NULL ) {
00105 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00106 goto exit_level_1;
00107 }
00108 if( LAPACKE_lsame( jobu, 'u' ) ) {
00109 u_t = (lapack_complex_float*)
00110 LAPACKE_malloc( sizeof(lapack_complex_float) *
00111 ldu_t * MAX(1,m) );
00112 if( u_t == NULL ) {
00113 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00114 goto exit_level_2;
00115 }
00116 }
00117 if( LAPACKE_lsame( jobv, 'v' ) ) {
00118 v_t = (lapack_complex_float*)
00119 LAPACKE_malloc( sizeof(lapack_complex_float) *
00120 ldv_t * MAX(1,p) );
00121 if( v_t == NULL ) {
00122 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00123 goto exit_level_3;
00124 }
00125 }
00126 if( LAPACKE_lsame( jobq, 'q' ) ) {
00127 q_t = (lapack_complex_float*)
00128 LAPACKE_malloc( sizeof(lapack_complex_float) *
00129 ldq_t * MAX(1,n) );
00130 if( q_t == NULL ) {
00131 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00132 goto exit_level_4;
00133 }
00134 }
00135
00136 LAPACKE_cge_trans( matrix_order, m, n, a, lda, a_t, lda_t );
00137 LAPACKE_cge_trans( matrix_order, p, n, b, ldb, b_t, ldb_t );
00138
00139 LAPACK_cggsvd( &jobu, &jobv, &jobq, &m, &n, &p, k, l, a_t, &lda_t, b_t,
00140 &ldb_t, alpha, beta, u_t, &ldu_t, v_t, &ldv_t, q_t,
00141 &ldq_t, work, rwork, iwork, &info );
00142 if( info < 0 ) {
00143 info = info - 1;
00144 }
00145
00146 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_t, lda_t, a, lda );
00147 LAPACKE_cge_trans( LAPACK_COL_MAJOR, p, n, b_t, ldb_t, b, ldb );
00148 if( LAPACKE_lsame( jobu, 'u' ) ) {
00149 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, m, u_t, ldu_t, u, ldu );
00150 }
00151 if( LAPACKE_lsame( jobv, 'v' ) ) {
00152 LAPACKE_cge_trans( LAPACK_COL_MAJOR, p, p, v_t, ldv_t, v, ldv );
00153 }
00154 if( LAPACKE_lsame( jobq, 'q' ) ) {
00155 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
00156 }
00157
00158 if( LAPACKE_lsame( jobq, 'q' ) ) {
00159 LAPACKE_free( q_t );
00160 }
00161 exit_level_4:
00162 if( LAPACKE_lsame( jobv, 'v' ) ) {
00163 LAPACKE_free( v_t );
00164 }
00165 exit_level_3:
00166 if( LAPACKE_lsame( jobu, 'u' ) ) {
00167 LAPACKE_free( u_t );
00168 }
00169 exit_level_2:
00170 LAPACKE_free( b_t );
00171 exit_level_1:
00172 LAPACKE_free( a_t );
00173 exit_level_0:
00174 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
00175 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00176 }
00177 } else {
00178 info = -1;
00179 LAPACKE_xerbla( "LAPACKE_cggsvd_work", info );
00180 }
00181 return info;
00182 }