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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <stdio.h>
00050 #include "lapacke.h"
00051 #include "lapacke_utils.h"
00052 #include "test_utils.h"
00053
00054 static void init_scalars_dorgqr( lapack_int *m, lapack_int *n, lapack_int *k,
00055 lapack_int *lda, lapack_int *lwork );
00056 static void init_a( lapack_int size, double *a );
00057 static void init_tau( lapack_int size, double *tau );
00058 static void init_work( lapack_int size, double *work );
00059 static int compare_dorgqr( double *a, double *a_i, lapack_int info,
00060 lapack_int info_i, lapack_int lda, lapack_int n );
00061
00062 int main(void)
00063 {
00064
00065 lapack_int m, m_i;
00066 lapack_int n, n_i;
00067 lapack_int k, k_i;
00068 lapack_int lda, lda_i;
00069 lapack_int lda_r;
00070 lapack_int lwork, lwork_i;
00071 lapack_int info, info_i;
00072 lapack_int i;
00073 int failed;
00074
00075
00076 double *a = NULL, *a_i = NULL;
00077 double *tau = NULL, *tau_i = NULL;
00078 double *work = NULL, *work_i = NULL;
00079 double *a_save = NULL;
00080 double *a_r = NULL;
00081
00082
00083 init_scalars_dorgqr( &m, &n, &k, &lda, &lwork );
00084 lda_r = n+2;
00085 m_i = m;
00086 n_i = n;
00087 k_i = k;
00088 lda_i = lda;
00089 lwork_i = lwork;
00090
00091
00092 a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00093 tau = (double *)LAPACKE_malloc( k * sizeof(double) );
00094 work = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00095
00096
00097 a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00098 tau_i = (double *)LAPACKE_malloc( k * sizeof(double) );
00099 work_i = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00100
00101
00102 a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00103
00104
00105 a_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00106
00107
00108 init_a( lda*n, a );
00109 init_tau( k, tau );
00110 init_work( lwork, work );
00111
00112
00113 for( i = 0; i < lda*n; i++ ) {
00114 a_save[i] = a[i];
00115 }
00116
00117
00118 dorgqr_( &m, &n, &k, a, &lda, tau, work, &lwork, &info );
00119
00120
00121
00122 for( i = 0; i < lda*n; i++ ) {
00123 a_i[i] = a_save[i];
00124 }
00125 for( i = 0; i < k; i++ ) {
00126 tau_i[i] = tau[i];
00127 }
00128 for( i = 0; i < lwork; i++ ) {
00129 work_i[i] = work[i];
00130 }
00131 info_i = LAPACKE_dorgqr_work( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00132 tau_i, work_i, lwork_i );
00133
00134 failed = compare_dorgqr( a, a_i, info, info_i, lda, n );
00135 if( failed == 0 ) {
00136 printf( "PASSED: column-major middle-level interface to dorgqr\n" );
00137 } else {
00138 printf( "FAILED: column-major middle-level interface to dorgqr\n" );
00139 }
00140
00141
00142
00143 for( i = 0; i < lda*n; i++ ) {
00144 a_i[i] = a_save[i];
00145 }
00146 for( i = 0; i < k; i++ ) {
00147 tau_i[i] = tau[i];
00148 }
00149 for( i = 0; i < lwork; i++ ) {
00150 work_i[i] = work[i];
00151 }
00152 info_i = LAPACKE_dorgqr( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00153 tau_i );
00154
00155 failed = compare_dorgqr( a, a_i, info, info_i, lda, n );
00156 if( failed == 0 ) {
00157 printf( "PASSED: column-major high-level interface to dorgqr\n" );
00158 } else {
00159 printf( "FAILED: column-major high-level interface to dorgqr\n" );
00160 }
00161
00162
00163
00164 for( i = 0; i < lda*n; i++ ) {
00165 a_i[i] = a_save[i];
00166 }
00167 for( i = 0; i < k; i++ ) {
00168 tau_i[i] = tau[i];
00169 }
00170 for( i = 0; i < lwork; i++ ) {
00171 work_i[i] = work[i];
00172 }
00173
00174 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00175 info_i = LAPACKE_dorgqr_work( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00176 tau_i, work_i, lwork_i );
00177
00178 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00179
00180 failed = compare_dorgqr( a, a_i, info, info_i, lda, n );
00181 if( failed == 0 ) {
00182 printf( "PASSED: row-major middle-level interface to dorgqr\n" );
00183 } else {
00184 printf( "FAILED: row-major middle-level interface to dorgqr\n" );
00185 }
00186
00187
00188
00189 for( i = 0; i < lda*n; i++ ) {
00190 a_i[i] = a_save[i];
00191 }
00192 for( i = 0; i < k; i++ ) {
00193 tau_i[i] = tau[i];
00194 }
00195 for( i = 0; i < lwork; i++ ) {
00196 work_i[i] = work[i];
00197 }
00198
00199
00200 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00201 info_i = LAPACKE_dorgqr( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00202 tau_i );
00203
00204 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00205
00206 failed = compare_dorgqr( a, a_i, info, info_i, lda, n );
00207 if( failed == 0 ) {
00208 printf( "PASSED: row-major high-level interface to dorgqr\n" );
00209 } else {
00210 printf( "FAILED: row-major high-level interface to dorgqr\n" );
00211 }
00212
00213
00214 if( a != NULL ) {
00215 LAPACKE_free( a );
00216 }
00217 if( a_i != NULL ) {
00218 LAPACKE_free( a_i );
00219 }
00220 if( a_r != NULL ) {
00221 LAPACKE_free( a_r );
00222 }
00223 if( a_save != NULL ) {
00224 LAPACKE_free( a_save );
00225 }
00226 if( tau != NULL ) {
00227 LAPACKE_free( tau );
00228 }
00229 if( tau_i != NULL ) {
00230 LAPACKE_free( tau_i );
00231 }
00232 if( work != NULL ) {
00233 LAPACKE_free( work );
00234 }
00235 if( work_i != NULL ) {
00236 LAPACKE_free( work_i );
00237 }
00238
00239 return 0;
00240 }
00241
00242
00243 static void init_scalars_dorgqr( lapack_int *m, lapack_int *n, lapack_int *k,
00244 lapack_int *lda, lapack_int *lwork )
00245 {
00246 *m = 6;
00247 *n = 6;
00248 *k = 4;
00249 *lda = 8;
00250 *lwork = 1024;
00251
00252 return;
00253 }
00254
00255
00256 static void init_a( lapack_int size, double *a ) {
00257 lapack_int i;
00258 for( i = 0; i < size; i++ ) {
00259 a[i] = 0;
00260 }
00261 a[0] = 3.61767881382524030e+000;
00262 a[8] = 0.00000000000000000e+000;
00263 a[16] = 0.00000000000000000e+000;
00264 a[24] = 0.00000000000000000e+000;
00265 a[32] = 0.00000000000000000e+000;
00266 a[40] = 0.00000000000000000e+000;
00267 a[1] = 4.60875842155869410e-001;
00268 a[9] = -2.02807703220235600e+000;
00269 a[17] = 0.00000000000000000e+000;
00270 a[25] = 0.00000000000000000e+000;
00271 a[33] = 0.00000000000000000e+000;
00272 a[41] = 0.00000000000000000e+000;
00273 a[2] = -5.49230278216839230e-001;
00274 a[10] = -4.57109828928023500e-002;
00275 a[18] = 1.37446064122229530e+000;
00276 a[26] = 0.00000000000000000e+000;
00277 a[34] = 0.00000000000000000e+000;
00278 a[42] = 0.00000000000000000e+000;
00279 a[3] = 4.60875842155869410e-001;
00280 a[11] = 2.82843169061735180e-001;
00281 a[19] = 4.43081480436171260e-003;
00282 a[27] = -2.37552731958861860e+000;
00283 a[35] = 0.00000000000000000e+000;
00284 a[43] = 0.00000000000000000e+000;
00285 a[4] = -3.58193659706634230e-002;
00286 a[12] = 7.96426824688575980e-002;
00287 a[20] = -7.72856175744114360e-002;
00288 a[28] = -5.21374484743236330e-001;
00289 a[36] = 0.00000000000000000e+000;
00290 a[44] = 0.00000000000000000e+000;
00291 a[5] = 4.77591546275512370e-003;
00292 a[13] = 3.00294208560961730e-001;
00293 a[21] = 8.01665355572227840e-001;
00294 a[29] = 2.55811387218232210e-001;
00295 a[37] = 0.00000000000000000e+000;
00296 a[45] = 0.00000000000000000e+000;
00297 }
00298 static void init_tau( lapack_int size, double *tau ) {
00299 lapack_int i;
00300 for( i = 0; i < size; i++ ) {
00301 tau[i] = 0;
00302 }
00303 tau[0] = 1.15755959258232120e+000;
00304 tau[1] = 1.69691513947038100e+000;
00305 tau[2] = 1.21310637129962080e+000;
00306 tau[3] = 1.49558337124162670e+000;
00307 }
00308 static void init_work( lapack_int size, double *work ) {
00309 lapack_int i;
00310 for( i = 0; i < size; i++ ) {
00311 work[i] = 0;
00312 }
00313 }
00314
00315
00316
00317 static int compare_dorgqr( double *a, double *a_i, lapack_int info,
00318 lapack_int info_i, lapack_int lda, lapack_int n )
00319 {
00320 lapack_int i;
00321 int failed = 0;
00322 for( i = 0; i < lda*n; i++ ) {
00323 failed += compare_doubles(a[i],a_i[i]);
00324 }
00325 failed += (info == info_i) ? 0 : 1;
00326 if( info != 0 || info_i != 0 ) {
00327 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00328 }
00329
00330 return failed;
00331 }