zgebrd_5.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002   Copyright (c) 2010, Intel Corp.
00003   All rights reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice,
00009       this list of conditions and the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright
00011       notice, this list of conditions and the following disclaimer in the
00012       documentation and/or other materials provided with the distribution.
00013     * Neither the name of Intel Corporation nor the names of its contributors
00014       may be used to endorse or promote products derived from this software
00015       without specific prior written permission.
00016 
00017   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027   THE POSSIBILITY OF SUCH DAMAGE.
00028 *****************************************************************************/
00029 /*  Contents: test routine for C interface to LAPACK
00030 *   Author: Intel Corporation
00031 *   Created in March, 2010
00032 *
00033 * Purpose
00034 *
00035 * zgebrd_5 is the test program for the C interface to LAPACK
00036 * routine zgebrd
00037 * The program doesn't require an input, the input data is hardcoded in the
00038 * test program.
00039 * The program tests the C interface in the four combinations:
00040 *   1) column-major layout, middle-level interface
00041 *   2) column-major layout, high-level interface
00042 *   3) row-major layout, middle-level interface
00043 *   4) row-major layout, high-level interface
00044 * The output of the C interface function is compared to those obtained from
00045 * the corresponiding LAPACK routine with the same input data, and the
00046 * comparison diagnostics is then printed on the standard output having PASSED
00047 * keyword if the test is passed, and FAILED keyword if the test isn't passed.
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_zgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_d( lapack_int size, double *d );
00058 static void init_e( lapack_int size, double *e );
00059 static void init_tauq( lapack_int size, lapack_complex_double *tauq );
00060 static void init_taup( lapack_int size, lapack_complex_double *taup );
00061 static void init_work( lapack_int size, lapack_complex_double *work );
00062 static int compare_zgebrd( lapack_complex_double *a, lapack_complex_double *a_i,
00063                            double *d, double *d_i, double *e, double *e_i,
00064                            lapack_complex_double *tauq,
00065                            lapack_complex_double *tauq_i,
00066                            lapack_complex_double *taup,
00067                            lapack_complex_double *taup_i, lapack_int info,
00068                            lapack_int info_i, lapack_int lda, lapack_int m,
00069                            lapack_int n );
00070 
00071 int main(void)
00072 {
00073     /* Local scalars */
00074     lapack_int m, m_i;
00075     lapack_int n, n_i;
00076     lapack_int lda, lda_i;
00077     lapack_int lda_r;
00078     lapack_int lwork, lwork_i;
00079     lapack_int info, info_i;
00080     lapack_int i;
00081     int failed;
00082 
00083     /* Local arrays */
00084     lapack_complex_double *a = NULL, *a_i = NULL;
00085     double *d = NULL, *d_i = NULL;
00086     double *e = NULL, *e_i = NULL;
00087     lapack_complex_double *tauq = NULL, *tauq_i = NULL;
00088     lapack_complex_double *taup = NULL, *taup_i = NULL;
00089     lapack_complex_double *work = NULL, *work_i = NULL;
00090     lapack_complex_double *a_save = NULL;
00091     double *d_save = NULL;
00092     double *e_save = NULL;
00093     lapack_complex_double *tauq_save = NULL;
00094     lapack_complex_double *taup_save = NULL;
00095     lapack_complex_double *a_r = NULL;
00096 
00097     /* Iniitialize the scalar parameters */
00098     init_scalars_zgebrd( &m, &n, &lda, &lwork );
00099     lda_r = n+2;
00100     m_i = m;
00101     n_i = n;
00102     lda_i = lda;
00103     lwork_i = lwork;
00104 
00105     /* Allocate memory for the LAPACK routine arrays */
00106     a = (lapack_complex_double *)
00107         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00108     d = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00109     e = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00110     tauq = (lapack_complex_double *)
00111         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00112     taup = (lapack_complex_double *)
00113         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00114     work = (lapack_complex_double *)
00115         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     a_i = (lapack_complex_double *)
00119         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00120     d_i = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00121     e_i = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00122     tauq_i = (lapack_complex_double *)
00123         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00124     taup_i = (lapack_complex_double *)
00125         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00126     work_i = (lapack_complex_double *)
00127         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00128 
00129     /* Allocate memory for the backup arrays */
00130     a_save = (lapack_complex_double *)
00131         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00132     d_save = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00133     e_save = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00134     tauq_save = (lapack_complex_double *)
00135         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00136     taup_save = (lapack_complex_double *)
00137         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00138 
00139     /* Allocate memory for the row-major arrays */
00140     a_r = (lapack_complex_double *)
00141         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00142 
00143     /* Initialize input arrays */
00144     init_a( lda*n, a );
00145     init_d( (MIN(m,n)), d );
00146     init_e( (MIN(m,n)-1), e );
00147     init_tauq( (MIN(m,n)), tauq );
00148     init_taup( (MIN(m,n)), taup );
00149     init_work( lwork, work );
00150 
00151     /* Backup the ouptut arrays */
00152     for( i = 0; i < lda*n; i++ ) {
00153         a_save[i] = a[i];
00154     }
00155     for( i = 0; i < (MIN(m,n)); i++ ) {
00156         d_save[i] = d[i];
00157     }
00158     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00159         e_save[i] = e[i];
00160     }
00161     for( i = 0; i < (MIN(m,n)); i++ ) {
00162         tauq_save[i] = tauq[i];
00163     }
00164     for( i = 0; i < (MIN(m,n)); i++ ) {
00165         taup_save[i] = taup[i];
00166     }
00167 
00168     /* Call the LAPACK routine */
00169     zgebrd_( &m, &n, a, &lda, d, e, tauq, taup, work, &lwork, &info );
00170 
00171     /* Initialize input data, call the column-major middle-level
00172      * interface to LAPACK routine and check the results */
00173     for( i = 0; i < lda*n; i++ ) {
00174         a_i[i] = a_save[i];
00175     }
00176     for( i = 0; i < (MIN(m,n)); i++ ) {
00177         d_i[i] = d_save[i];
00178     }
00179     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00180         e_i[i] = e_save[i];
00181     }
00182     for( i = 0; i < (MIN(m,n)); i++ ) {
00183         tauq_i[i] = tauq_save[i];
00184     }
00185     for( i = 0; i < (MIN(m,n)); i++ ) {
00186         taup_i[i] = taup_save[i];
00187     }
00188     for( i = 0; i < lwork; i++ ) {
00189         work_i[i] = work[i];
00190     }
00191     info_i = LAPACKE_zgebrd_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i,
00192                                   e_i, tauq_i, taup_i, work_i, lwork_i );
00193 
00194     failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00195                              info, info_i, lda, m, n );
00196     if( failed == 0 ) {
00197         printf( "PASSED: column-major middle-level interface to zgebrd\n" );
00198     } else {
00199         printf( "FAILED: column-major middle-level interface to zgebrd\n" );
00200     }
00201 
00202     /* Initialize input data, call the column-major high-level
00203      * interface to LAPACK routine and check the results */
00204     for( i = 0; i < lda*n; i++ ) {
00205         a_i[i] = a_save[i];
00206     }
00207     for( i = 0; i < (MIN(m,n)); i++ ) {
00208         d_i[i] = d_save[i];
00209     }
00210     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00211         e_i[i] = e_save[i];
00212     }
00213     for( i = 0; i < (MIN(m,n)); i++ ) {
00214         tauq_i[i] = tauq_save[i];
00215     }
00216     for( i = 0; i < (MIN(m,n)); i++ ) {
00217         taup_i[i] = taup_save[i];
00218     }
00219     for( i = 0; i < lwork; i++ ) {
00220         work_i[i] = work[i];
00221     }
00222     info_i = LAPACKE_zgebrd( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i, e_i,
00223                              tauq_i, taup_i );
00224 
00225     failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00226                              info, info_i, lda, m, n );
00227     if( failed == 0 ) {
00228         printf( "PASSED: column-major high-level interface to zgebrd\n" );
00229     } else {
00230         printf( "FAILED: column-major high-level interface to zgebrd\n" );
00231     }
00232 
00233     /* Initialize input data, call the row-major middle-level
00234      * interface to LAPACK routine and check the results */
00235     for( i = 0; i < lda*n; i++ ) {
00236         a_i[i] = a_save[i];
00237     }
00238     for( i = 0; i < (MIN(m,n)); i++ ) {
00239         d_i[i] = d_save[i];
00240     }
00241     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00242         e_i[i] = e_save[i];
00243     }
00244     for( i = 0; i < (MIN(m,n)); i++ ) {
00245         tauq_i[i] = tauq_save[i];
00246     }
00247     for( i = 0; i < (MIN(m,n)); i++ ) {
00248         taup_i[i] = taup_save[i];
00249     }
00250     for( i = 0; i < lwork; i++ ) {
00251         work_i[i] = work[i];
00252     }
00253 
00254     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00255     info_i = LAPACKE_zgebrd_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i,
00256                                   e_i, tauq_i, taup_i, work_i, lwork_i );
00257 
00258     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00259 
00260     failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00261                              info, info_i, lda, m, n );
00262     if( failed == 0 ) {
00263         printf( "PASSED: row-major middle-level interface to zgebrd\n" );
00264     } else {
00265         printf( "FAILED: row-major middle-level interface to zgebrd\n" );
00266     }
00267 
00268     /* Initialize input data, call the row-major high-level
00269      * interface to LAPACK routine and check the results */
00270     for( i = 0; i < lda*n; i++ ) {
00271         a_i[i] = a_save[i];
00272     }
00273     for( i = 0; i < (MIN(m,n)); i++ ) {
00274         d_i[i] = d_save[i];
00275     }
00276     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00277         e_i[i] = e_save[i];
00278     }
00279     for( i = 0; i < (MIN(m,n)); i++ ) {
00280         tauq_i[i] = tauq_save[i];
00281     }
00282     for( i = 0; i < (MIN(m,n)); i++ ) {
00283         taup_i[i] = taup_save[i];
00284     }
00285     for( i = 0; i < lwork; i++ ) {
00286         work_i[i] = work[i];
00287     }
00288 
00289     /* Init row_major arrays */
00290     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00291     info_i = LAPACKE_zgebrd( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i, e_i,
00292                              tauq_i, taup_i );
00293 
00294     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00295 
00296     failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00297                              info, info_i, lda, m, n );
00298     if( failed == 0 ) {
00299         printf( "PASSED: row-major high-level interface to zgebrd\n" );
00300     } else {
00301         printf( "FAILED: row-major high-level interface to zgebrd\n" );
00302     }
00303 
00304     /* Release memory */
00305     if( a != NULL ) {
00306         LAPACKE_free( a );
00307     }
00308     if( a_i != NULL ) {
00309         LAPACKE_free( a_i );
00310     }
00311     if( a_r != NULL ) {
00312         LAPACKE_free( a_r );
00313     }
00314     if( a_save != NULL ) {
00315         LAPACKE_free( a_save );
00316     }
00317     if( d != NULL ) {
00318         LAPACKE_free( d );
00319     }
00320     if( d_i != NULL ) {
00321         LAPACKE_free( d_i );
00322     }
00323     if( d_save != NULL ) {
00324         LAPACKE_free( d_save );
00325     }
00326     if( e != NULL ) {
00327         LAPACKE_free( e );
00328     }
00329     if( e_i != NULL ) {
00330         LAPACKE_free( e_i );
00331     }
00332     if( e_save != NULL ) {
00333         LAPACKE_free( e_save );
00334     }
00335     if( tauq != NULL ) {
00336         LAPACKE_free( tauq );
00337     }
00338     if( tauq_i != NULL ) {
00339         LAPACKE_free( tauq_i );
00340     }
00341     if( tauq_save != NULL ) {
00342         LAPACKE_free( tauq_save );
00343     }
00344     if( taup != NULL ) {
00345         LAPACKE_free( taup );
00346     }
00347     if( taup_i != NULL ) {
00348         LAPACKE_free( taup_i );
00349     }
00350     if( taup_save != NULL ) {
00351         LAPACKE_free( taup_save );
00352     }
00353     if( work != NULL ) {
00354         LAPACKE_free( work );
00355     }
00356     if( work_i != NULL ) {
00357         LAPACKE_free( work_i );
00358     }
00359 
00360     return 0;
00361 }
00362 
00363 /* Auxiliary function: zgebrd scalar parameters initialization */
00364 static void init_scalars_zgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00365                                  lapack_int *lwork )
00366 {
00367     *m = 3;
00368     *n = 3;
00369     *lda = 8;
00370     *lwork = 1024;
00371 
00372     return;
00373 }
00374 
00375 /* Auxiliary functions: zgebrd array parameters initialization */
00376 static void init_a( lapack_int size, lapack_complex_double *a ) {
00377     lapack_int i;
00378     for( i = 0; i < size; i++ ) {
00379         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00380     }
00381     a[0] = lapack_make_complex_double( -2.22551117723546850e+000,
00382                                        0.00000000000000000e+000 );
00383     a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00384                                        0.00000000000000000e+000 );
00385     a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00386                                         0.00000000000000000e+000 );
00387     a[1] = lapack_make_complex_double( 8.20755257796100150e-001,
00388                                        1.23845704671937580e+000 );
00389     a[9] = lapack_make_complex_double( 1.68810098934606920e+000,
00390                                        0.00000000000000000e+000 );
00391     a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00392                                         0.00000000000000000e+000 );
00393     a[2] = lapack_make_complex_double( 1.03347043300727750e-003,
00394                                        -6.82225286276042620e-001 );
00395     a[10] = lapack_make_complex_double( 7.74751330164005660e-001,
00396                                         -6.15472715853114580e-001 );
00397     a[18] = lapack_make_complex_double( -1.59025825045931810e+000,
00398                                         0.00000000000000000e+000 );
00399 }
00400 static void init_d( lapack_int size, double *d ) {
00401     lapack_int i;
00402     for( i = 0; i < size; i++ ) {
00403         d[i] = 0;
00404     }
00405 }
00406 static void init_e( lapack_int size, double *e ) {
00407     lapack_int i;
00408     for( i = 0; i < size; i++ ) {
00409         e[i] = 0;
00410     }
00411 }
00412 static void init_tauq( lapack_int size, lapack_complex_double *tauq ) {
00413     lapack_int i;
00414     for( i = 0; i < size; i++ ) {
00415         tauq[i] = lapack_make_complex_double( 0.0, 0.0 );
00416     }
00417 }
00418 static void init_taup( lapack_int size, lapack_complex_double *taup ) {
00419     lapack_int i;
00420     for( i = 0; i < size; i++ ) {
00421         taup[i] = lapack_make_complex_double( 0.0, 0.0 );
00422     }
00423 }
00424 static void init_work( lapack_int size, lapack_complex_double *work ) {
00425     lapack_int i;
00426     for( i = 0; i < size; i++ ) {
00427         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00428     }
00429 }
00430 
00431 /* Auxiliary function: C interface to zgebrd results check */
00432 /* Return value: 0 - test is passed, non-zero - test is failed */
00433 static int compare_zgebrd( lapack_complex_double *a, lapack_complex_double *a_i,
00434                            double *d, double *d_i, double *e, double *e_i,
00435                            lapack_complex_double *tauq,
00436                            lapack_complex_double *tauq_i,
00437                            lapack_complex_double *taup,
00438                            lapack_complex_double *taup_i, lapack_int info,
00439                            lapack_int info_i, lapack_int lda, lapack_int m,
00440                            lapack_int n )
00441 {
00442     lapack_int i;
00443     int failed = 0;
00444     for( i = 0; i < lda*n; i++ ) {
00445         failed += compare_complex_doubles(a[i],a_i[i]);
00446     }
00447     for( i = 0; i < (MIN(m,n)); i++ ) {
00448         failed += compare_doubles(d[i],d_i[i]);
00449     }
00450     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00451         failed += compare_doubles(e[i],e_i[i]);
00452     }
00453     for( i = 0; i < (MIN(m,n)); i++ ) {
00454         failed += compare_complex_doubles(tauq[i],tauq_i[i]);
00455     }
00456     for( i = 0; i < (MIN(m,n)); i++ ) {
00457         failed += compare_complex_doubles(taup[i],taup_i[i]);
00458     }
00459     failed += (info == info_i) ? 0 : 1;
00460     if( info != 0 || info_i != 0 ) {
00461         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00462     }
00463 
00464     return failed;
00465 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:31