cgebrd_4.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 * cgebrd_4 is the test program for the C interface to LAPACK
00036 * routine cgebrd
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_cgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_d( lapack_int size, float *d );
00058 static void init_e( lapack_int size, float *e );
00059 static void init_tauq( lapack_int size, lapack_complex_float *tauq );
00060 static void init_taup( lapack_int size, lapack_complex_float *taup );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_cgebrd( lapack_complex_float *a, lapack_complex_float *a_i,
00063                            float *d, float *d_i, float *e, float *e_i,
00064                            lapack_complex_float *tauq,
00065                            lapack_complex_float *tauq_i,
00066                            lapack_complex_float *taup,
00067                            lapack_complex_float *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_float *a = NULL, *a_i = NULL;
00085     float *d = NULL, *d_i = NULL;
00086     float *e = NULL, *e_i = NULL;
00087     lapack_complex_float *tauq = NULL, *tauq_i = NULL;
00088     lapack_complex_float *taup = NULL, *taup_i = NULL;
00089     lapack_complex_float *work = NULL, *work_i = NULL;
00090     lapack_complex_float *a_save = NULL;
00091     float *d_save = NULL;
00092     float *e_save = NULL;
00093     lapack_complex_float *tauq_save = NULL;
00094     lapack_complex_float *taup_save = NULL;
00095     lapack_complex_float *a_r = NULL;
00096 
00097     /* Iniitialize the scalar parameters */
00098     init_scalars_cgebrd( &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_float *)
00107         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00108     d = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00109     e = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00110     tauq = (lapack_complex_float *)
00111         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00112     taup = (lapack_complex_float *)
00113         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00114     work = (lapack_complex_float *)
00115         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     a_i = (lapack_complex_float *)
00119         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00120     d_i = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00121     e_i = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00122     tauq_i = (lapack_complex_float *)
00123         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00124     taup_i = (lapack_complex_float *)
00125         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00126     work_i = (lapack_complex_float *)
00127         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00128 
00129     /* Allocate memory for the backup arrays */
00130     a_save = (lapack_complex_float *)
00131         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00132     d_save = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00133     e_save = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00134     tauq_save = (lapack_complex_float *)
00135         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00136     taup_save = (lapack_complex_float *)
00137         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00138 
00139     /* Allocate memory for the row-major arrays */
00140     a_r = (lapack_complex_float *)
00141         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
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     cgebrd_( &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_cgebrd_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_cgebrd( 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 cgebrd\n" );
00198     } else {
00199         printf( "FAILED: column-major middle-level interface to cgebrd\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_cgebrd( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i, e_i,
00223                              tauq_i, taup_i );
00224 
00225     failed = compare_cgebrd( 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 cgebrd\n" );
00229     } else {
00230         printf( "FAILED: column-major high-level interface to cgebrd\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00255     info_i = LAPACKE_cgebrd_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_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00259 
00260     failed = compare_cgebrd( 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 cgebrd\n" );
00264     } else {
00265         printf( "FAILED: row-major middle-level interface to cgebrd\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00291     info_i = LAPACKE_cgebrd( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i, e_i,
00292                              tauq_i, taup_i );
00293 
00294     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00295 
00296     failed = compare_cgebrd( 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 cgebrd\n" );
00300     } else {
00301         printf( "FAILED: row-major high-level interface to cgebrd\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: cgebrd scalar parameters initialization */
00364 static void init_scalars_cgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00365                                  lapack_int *lwork )
00366 {
00367     *m = 4;
00368     *n = 4;
00369     *lda = 8;
00370     *lwork = 1024;
00371 
00372     return;
00373 }
00374 
00375 /* Auxiliary functions: cgebrd array parameters initialization */
00376 static void init_a( lapack_int size, lapack_complex_float *a ) {
00377     lapack_int i;
00378     for( i = 0; i < size; i++ ) {
00379         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00380     }
00381     a[0] = lapack_make_complex_float( -3.087005138e+000, 0.000000000e+000 );
00382     a[8] = lapack_make_complex_float( -4.884994030e-001, -1.141689062e+000 );
00383     a[16] = lapack_make_complex_float( 3.773559928e-001, -1.243729830e+000 );
00384     a[24] = lapack_make_complex_float( -8.551653028e-001, -7.073198557e-001 );
00385     a[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00386     a[9] = lapack_make_complex_float( 1.516316056e+000, 0.000000000e+000 );
00387     a[17] = lapack_make_complex_float( 1.373054981e+000, -8.176293373e-001 );
00388     a[25] = lapack_make_complex_float( -2.508625686e-001, 8.203486204e-001 );
00389     a[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00390     a[10] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00391     a[18] = lapack_make_complex_float( -2.171345234e+000, 0.000000000e+000 );
00392     a[26] = lapack_make_complex_float( -2.272676229e-001, -2.957314849e-001 );
00393     a[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00394     a[11] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00395     a[19] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00396     a[27] = lapack_make_complex_float( -2.353376150e+000, 0.000000000e+000 );
00397 }
00398 static void init_d( lapack_int size, float *d ) {
00399     lapack_int i;
00400     for( i = 0; i < size; i++ ) {
00401         d[i] = 0;
00402     }
00403 }
00404 static void init_e( lapack_int size, float *e ) {
00405     lapack_int i;
00406     for( i = 0; i < size; i++ ) {
00407         e[i] = 0;
00408     }
00409 }
00410 static void init_tauq( lapack_int size, lapack_complex_float *tauq ) {
00411     lapack_int i;
00412     for( i = 0; i < size; i++ ) {
00413         tauq[i] = lapack_make_complex_float( 0.0f, 0.0f );
00414     }
00415 }
00416 static void init_taup( lapack_int size, lapack_complex_float *taup ) {
00417     lapack_int i;
00418     for( i = 0; i < size; i++ ) {
00419         taup[i] = lapack_make_complex_float( 0.0f, 0.0f );
00420     }
00421 }
00422 static void init_work( lapack_int size, lapack_complex_float *work ) {
00423     lapack_int i;
00424     for( i = 0; i < size; i++ ) {
00425         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00426     }
00427 }
00428 
00429 /* Auxiliary function: C interface to cgebrd results check */
00430 /* Return value: 0 - test is passed, non-zero - test is failed */
00431 static int compare_cgebrd( lapack_complex_float *a, lapack_complex_float *a_i,
00432                            float *d, float *d_i, float *e, float *e_i,
00433                            lapack_complex_float *tauq,
00434                            lapack_complex_float *tauq_i,
00435                            lapack_complex_float *taup,
00436                            lapack_complex_float *taup_i, lapack_int info,
00437                            lapack_int info_i, lapack_int lda, lapack_int m,
00438                            lapack_int n )
00439 {
00440     lapack_int i;
00441     int failed = 0;
00442     for( i = 0; i < lda*n; i++ ) {
00443         failed += compare_complex_floats(a[i],a_i[i]);
00444     }
00445     for( i = 0; i < (MIN(m,n)); i++ ) {
00446         failed += compare_floats(d[i],d_i[i]);
00447     }
00448     for( i = 0; i < (MIN(m,n)-1); i++ ) {
00449         failed += compare_floats(e[i],e_i[i]);
00450     }
00451     for( i = 0; i < (MIN(m,n)); i++ ) {
00452         failed += compare_complex_floats(tauq[i],tauq_i[i]);
00453     }
00454     for( i = 0; i < (MIN(m,n)); i++ ) {
00455         failed += compare_complex_floats(taup[i],taup_i[i]);
00456     }
00457     failed += (info == info_i) ? 0 : 1;
00458     if( info != 0 || info_i != 0 ) {
00459         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00460     }
00461 
00462     return failed;
00463 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:26