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_sggev_work( int matrix_order, char jobvl, char jobvr,
00038 lapack_int n, float* a, lapack_int lda, float* b,
00039 lapack_int ldb, float* alphar, float* alphai,
00040 float* beta, float* vl, lapack_int ldvl,
00041 float* vr, lapack_int ldvr, float* work,
00042 lapack_int lwork )
00043 {
00044 lapack_int info = 0;
00045 if( matrix_order == LAPACK_COL_MAJOR ) {
00046
00047 LAPACK_sggev( &jobvl, &jobvr, &n, a, &lda, b, &ldb, alphar, alphai,
00048 beta, vl, &ldvl, vr, &ldvr, work, &lwork, &info );
00049 if( info < 0 ) {
00050 info = info - 1;
00051 }
00052 } else if( matrix_order == LAPACK_ROW_MAJOR ) {
00053 lapack_int nrows_vl = LAPACKE_lsame( jobvl, 'v' ) ? n : 1;
00054 lapack_int ncols_vl = LAPACKE_lsame( jobvl, 'v' ) ? n : 1;
00055 lapack_int nrows_vr = LAPACKE_lsame( jobvr, 'v' ) ? n : 1;
00056 lapack_int ncols_vr = LAPACKE_lsame( jobvr, 'v' ) ? n : 1;
00057 lapack_int lda_t = MAX(1,n);
00058 lapack_int ldb_t = MAX(1,n);
00059 lapack_int ldvl_t = MAX(1,nrows_vl);
00060 lapack_int ldvr_t = MAX(1,nrows_vr);
00061 float* a_t = NULL;
00062 float* b_t = NULL;
00063 float* vl_t = NULL;
00064 float* vr_t = NULL;
00065
00066 if( lda < n ) {
00067 info = -6;
00068 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00069 return info;
00070 }
00071 if( ldb < n ) {
00072 info = -8;
00073 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00074 return info;
00075 }
00076 if( ldvl < ncols_vl ) {
00077 info = -13;
00078 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00079 return info;
00080 }
00081 if( ldvr < ncols_vr ) {
00082 info = -15;
00083 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00084 return info;
00085 }
00086
00087 if( lwork == -1 ) {
00088 LAPACK_sggev( &jobvl, &jobvr, &n, a, &lda_t, b, &ldb_t, alphar,
00089 alphai, beta, vl, &ldvl_t, vr, &ldvr_t, work, &lwork,
00090 &info );
00091 return (info < 0) ? (info - 1) : info;
00092 }
00093
00094 a_t = (float*)LAPACKE_malloc( sizeof(float) * lda_t * MAX(1,n) );
00095 if( a_t == NULL ) {
00096 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00097 goto exit_level_0;
00098 }
00099 b_t = (float*)LAPACKE_malloc( sizeof(float) * ldb_t * MAX(1,n) );
00100 if( b_t == NULL ) {
00101 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00102 goto exit_level_1;
00103 }
00104 if( LAPACKE_lsame( jobvl, 'v' ) ) {
00105 vl_t = (float*)
00106 LAPACKE_malloc( sizeof(float) * ldvl_t * MAX(1,ncols_vl) );
00107 if( vl_t == NULL ) {
00108 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00109 goto exit_level_2;
00110 }
00111 }
00112 if( LAPACKE_lsame( jobvr, 'v' ) ) {
00113 vr_t = (float*)
00114 LAPACKE_malloc( sizeof(float) * ldvr_t * MAX(1,ncols_vr) );
00115 if( vr_t == NULL ) {
00116 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00117 goto exit_level_3;
00118 }
00119 }
00120
00121 LAPACKE_sge_trans( matrix_order, n, n, a, lda, a_t, lda_t );
00122 LAPACKE_sge_trans( matrix_order, n, n, b, ldb, b_t, ldb_t );
00123
00124 LAPACK_sggev( &jobvl, &jobvr, &n, a_t, &lda_t, b_t, &ldb_t, alphar,
00125 alphai, beta, vl_t, &ldvl_t, vr_t, &ldvr_t, work, &lwork,
00126 &info );
00127 if( info < 0 ) {
00128 info = info - 1;
00129 }
00130
00131 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
00132 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
00133 if( LAPACKE_lsame( jobvl, 'v' ) ) {
00134 LAPACKE_sge_trans( LAPACK_COL_MAJOR, nrows_vl, ncols_vl, vl_t,
00135 ldvl_t, vl, ldvl );
00136 }
00137 if( LAPACKE_lsame( jobvr, 'v' ) ) {
00138 LAPACKE_sge_trans( LAPACK_COL_MAJOR, nrows_vr, ncols_vr, vr_t,
00139 ldvr_t, vr, ldvr );
00140 }
00141
00142 if( LAPACKE_lsame( jobvr, 'v' ) ) {
00143 LAPACKE_free( vr_t );
00144 }
00145 exit_level_3:
00146 if( LAPACKE_lsame( jobvl, 'v' ) ) {
00147 LAPACKE_free( vl_t );
00148 }
00149 exit_level_2:
00150 LAPACKE_free( b_t );
00151 exit_level_1:
00152 LAPACKE_free( a_t );
00153 exit_level_0:
00154 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
00155 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00156 }
00157 } else {
00158 info = -1;
00159 LAPACKE_xerbla( "LAPACKE_sggev_work", info );
00160 }
00161 return info;
00162 }