chbtrd_1.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 * chbtrd_1 is the test program for the C interface to LAPACK
00036 * routine chbtrd
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_chbtrd( char *vect, char *uplo, lapack_int *n,
00055                                  lapack_int *kd, lapack_int *ldab,
00056                                  lapack_int *ldq );
00057 static void init_ab( lapack_int size, lapack_complex_float *ab );
00058 static void init_d( lapack_int size, float *d );
00059 static void init_e( lapack_int size, float *e );
00060 static void init_q( lapack_int size, lapack_complex_float *q );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_chbtrd( lapack_complex_float *ab, lapack_complex_float *ab_i,
00063                            float *d, float *d_i, float *e, float *e_i,
00064                            lapack_complex_float *q, lapack_complex_float *q_i,
00065                            lapack_int info, lapack_int info_i, lapack_int ldab,
00066                            lapack_int ldq, lapack_int n, char vect );
00067 
00068 int main(void)
00069 {
00070     /* Local scalars */
00071     char vect, vect_i;
00072     char uplo, uplo_i;
00073     lapack_int n, n_i;
00074     lapack_int kd, kd_i;
00075     lapack_int ldab, ldab_i;
00076     lapack_int ldab_r;
00077     lapack_int ldq, ldq_i;
00078     lapack_int ldq_r;
00079     lapack_int info, info_i;
00080     lapack_int i;
00081     int failed;
00082 
00083     /* Local arrays */
00084     lapack_complex_float *ab = NULL, *ab_i = NULL;
00085     float *d = NULL, *d_i = NULL;
00086     float *e = NULL, *e_i = NULL;
00087     lapack_complex_float *q = NULL, *q_i = NULL;
00088     lapack_complex_float *work = NULL, *work_i = NULL;
00089     lapack_complex_float *ab_save = NULL;
00090     float *d_save = NULL;
00091     float *e_save = NULL;
00092     lapack_complex_float *q_save = NULL;
00093     lapack_complex_float *ab_r = NULL;
00094     lapack_complex_float *q_r = NULL;
00095 
00096     /* Iniitialize the scalar parameters */
00097     init_scalars_chbtrd( &vect, &uplo, &n, &kd, &ldab, &ldq );
00098     ldab_r = n+2;
00099     ldq_r = n+2;
00100     vect_i = vect;
00101     uplo_i = uplo;
00102     n_i = n;
00103     kd_i = kd;
00104     ldab_i = ldab;
00105     ldq_i = ldq;
00106 
00107     /* Allocate memory for the LAPACK routine arrays */
00108     ab = (lapack_complex_float *)
00109         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00110     d = (float *)LAPACKE_malloc( n * sizeof(float) );
00111     e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00112     q = (lapack_complex_float *)
00113         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00114     work = (lapack_complex_float *)
00115         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     ab_i = (lapack_complex_float *)
00119         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00120     d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00121     e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00122     q_i = (lapack_complex_float *)
00123         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00124     work_i = (lapack_complex_float *)
00125         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00126 
00127     /* Allocate memory for the backup arrays */
00128     ab_save = (lapack_complex_float *)
00129         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00130     d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00131     e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00132     q_save = (lapack_complex_float *)
00133         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00134 
00135     /* Allocate memory for the row-major arrays */
00136     ab_r = (lapack_complex_float *)
00137         LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_float) );
00138     q_r = (lapack_complex_float *)
00139         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00140 
00141     /* Initialize input arrays */
00142     init_ab( ldab*n, ab );
00143     init_d( n, d );
00144     init_e( (n-1), e );
00145     init_q( ldq*n, q );
00146     init_work( n, work );
00147 
00148     /* Backup the ouptut arrays */
00149     for( i = 0; i < ldab*n; i++ ) {
00150         ab_save[i] = ab[i];
00151     }
00152     for( i = 0; i < n; i++ ) {
00153         d_save[i] = d[i];
00154     }
00155     for( i = 0; i < (n-1); i++ ) {
00156         e_save[i] = e[i];
00157     }
00158     for( i = 0; i < ldq*n; i++ ) {
00159         q_save[i] = q[i];
00160     }
00161 
00162     /* Call the LAPACK routine */
00163     chbtrd_( &vect, &uplo, &n, &kd, ab, &ldab, d, e, q, &ldq, work, &info );
00164 
00165     /* Initialize input data, call the column-major middle-level
00166      * interface to LAPACK routine and check the results */
00167     for( i = 0; i < ldab*n; i++ ) {
00168         ab_i[i] = ab_save[i];
00169     }
00170     for( i = 0; i < n; i++ ) {
00171         d_i[i] = d_save[i];
00172     }
00173     for( i = 0; i < (n-1); i++ ) {
00174         e_i[i] = e_save[i];
00175     }
00176     for( i = 0; i < ldq*n; i++ ) {
00177         q_i[i] = q_save[i];
00178     }
00179     for( i = 0; i < n; i++ ) {
00180         work_i[i] = work[i];
00181     }
00182     info_i = LAPACKE_chbtrd_work( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i,
00183                                   ab_i, ldab_i, d_i, e_i, q_i, ldq_i, work_i );
00184 
00185     failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00186                              ldab, ldq, n, vect );
00187     if( failed == 0 ) {
00188         printf( "PASSED: column-major middle-level interface to chbtrd\n" );
00189     } else {
00190         printf( "FAILED: column-major middle-level interface to chbtrd\n" );
00191     }
00192 
00193     /* Initialize input data, call the column-major high-level
00194      * interface to LAPACK routine and check the results */
00195     for( i = 0; i < ldab*n; i++ ) {
00196         ab_i[i] = ab_save[i];
00197     }
00198     for( i = 0; i < n; i++ ) {
00199         d_i[i] = d_save[i];
00200     }
00201     for( i = 0; i < (n-1); i++ ) {
00202         e_i[i] = e_save[i];
00203     }
00204     for( i = 0; i < ldq*n; i++ ) {
00205         q_i[i] = q_save[i];
00206     }
00207     for( i = 0; i < n; i++ ) {
00208         work_i[i] = work[i];
00209     }
00210     info_i = LAPACKE_chbtrd( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_i,
00211                              ldab_i, d_i, e_i, q_i, ldq_i );
00212 
00213     failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00214                              ldab, ldq, n, vect );
00215     if( failed == 0 ) {
00216         printf( "PASSED: column-major high-level interface to chbtrd\n" );
00217     } else {
00218         printf( "FAILED: column-major high-level interface to chbtrd\n" );
00219     }
00220 
00221     /* Initialize input data, call the row-major middle-level
00222      * interface to LAPACK routine and check the results */
00223     for( i = 0; i < ldab*n; i++ ) {
00224         ab_i[i] = ab_save[i];
00225     }
00226     for( i = 0; i < n; i++ ) {
00227         d_i[i] = d_save[i];
00228     }
00229     for( i = 0; i < (n-1); i++ ) {
00230         e_i[i] = e_save[i];
00231     }
00232     for( i = 0; i < ldq*n; i++ ) {
00233         q_i[i] = q_save[i];
00234     }
00235     for( i = 0; i < n; i++ ) {
00236         work_i[i] = work[i];
00237     }
00238 
00239     LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00240     if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00241         LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00242     }
00243     info_i = LAPACKE_chbtrd_work( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i,
00244                                   ab_r, ldab_r, d_i, e_i, q_r, ldq_r, work_i );
00245 
00246     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
00247     if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00248         LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00249     }
00250 
00251     failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00252                              ldab, ldq, n, vect );
00253     if( failed == 0 ) {
00254         printf( "PASSED: row-major middle-level interface to chbtrd\n" );
00255     } else {
00256         printf( "FAILED: row-major middle-level interface to chbtrd\n" );
00257     }
00258 
00259     /* Initialize input data, call the row-major high-level
00260      * interface to LAPACK routine and check the results */
00261     for( i = 0; i < ldab*n; i++ ) {
00262         ab_i[i] = ab_save[i];
00263     }
00264     for( i = 0; i < n; i++ ) {
00265         d_i[i] = d_save[i];
00266     }
00267     for( i = 0; i < (n-1); i++ ) {
00268         e_i[i] = e_save[i];
00269     }
00270     for( i = 0; i < ldq*n; i++ ) {
00271         q_i[i] = q_save[i];
00272     }
00273     for( i = 0; i < n; i++ ) {
00274         work_i[i] = work[i];
00275     }
00276 
00277     /* Init row_major arrays */
00278     LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00279     if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00280         LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00281     }
00282     info_i = LAPACKE_chbtrd( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_r,
00283                              ldab_r, d_i, e_i, q_r, ldq_r );
00284 
00285     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
00286     if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00287         LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00288     }
00289 
00290     failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00291                              ldab, ldq, n, vect );
00292     if( failed == 0 ) {
00293         printf( "PASSED: row-major high-level interface to chbtrd\n" );
00294     } else {
00295         printf( "FAILED: row-major high-level interface to chbtrd\n" );
00296     }
00297 
00298     /* Release memory */
00299     if( ab != NULL ) {
00300         LAPACKE_free( ab );
00301     }
00302     if( ab_i != NULL ) {
00303         LAPACKE_free( ab_i );
00304     }
00305     if( ab_r != NULL ) {
00306         LAPACKE_free( ab_r );
00307     }
00308     if( ab_save != NULL ) {
00309         LAPACKE_free( ab_save );
00310     }
00311     if( d != NULL ) {
00312         LAPACKE_free( d );
00313     }
00314     if( d_i != NULL ) {
00315         LAPACKE_free( d_i );
00316     }
00317     if( d_save != NULL ) {
00318         LAPACKE_free( d_save );
00319     }
00320     if( e != NULL ) {
00321         LAPACKE_free( e );
00322     }
00323     if( e_i != NULL ) {
00324         LAPACKE_free( e_i );
00325     }
00326     if( e_save != NULL ) {
00327         LAPACKE_free( e_save );
00328     }
00329     if( q != NULL ) {
00330         LAPACKE_free( q );
00331     }
00332     if( q_i != NULL ) {
00333         LAPACKE_free( q_i );
00334     }
00335     if( q_r != NULL ) {
00336         LAPACKE_free( q_r );
00337     }
00338     if( q_save != NULL ) {
00339         LAPACKE_free( q_save );
00340     }
00341     if( work != NULL ) {
00342         LAPACKE_free( work );
00343     }
00344     if( work_i != NULL ) {
00345         LAPACKE_free( work_i );
00346     }
00347 
00348     return 0;
00349 }
00350 
00351 /* Auxiliary function: chbtrd scalar parameters initialization */
00352 static void init_scalars_chbtrd( char *vect, char *uplo, lapack_int *n,
00353                                  lapack_int *kd, lapack_int *ldab,
00354                                  lapack_int *ldq )
00355 {
00356     *vect = 'V';
00357     *uplo = 'L';
00358     *n = 4;
00359     *kd = 2;
00360     *ldab = 9;
00361     *ldq = 8;
00362 
00363     return;
00364 }
00365 
00366 /* Auxiliary functions: chbtrd array parameters initialization */
00367 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00368     lapack_int i;
00369     for( i = 0; i < size; i++ ) {
00370         ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00371     }
00372     ab[0] = lapack_make_complex_float( -3.130000114e+000, 0.000000000e+000 );
00373     ab[9] = lapack_make_complex_float( -1.909999967e+000, 0.000000000e+000 );
00374     ab[18] = lapack_make_complex_float( -2.869999886e+000, 0.000000000e+000 );
00375     ab[27] = lapack_make_complex_float( 5.000000000e-001, 0.000000000e+000 );
00376     ab[1] = lapack_make_complex_float( 1.940000057e+000, 2.099999905e+000 );
00377     ab[10] = lapack_make_complex_float( -8.199999928e-001, 8.899999857e-001 );
00378     ab[19] = lapack_make_complex_float( -2.099999905e+000, 1.599999964e-001 );
00379     ab[28] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00380     ab[2] = lapack_make_complex_float( -3.400000095e+000, -2.500000000e-001 );
00381     ab[11] = lapack_make_complex_float( -6.700000167e-001, -3.400000036e-001 );
00382     ab[20] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00383     ab[29] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00384 }
00385 static void init_d( lapack_int size, float *d ) {
00386     lapack_int i;
00387     for( i = 0; i < size; i++ ) {
00388         d[i] = 0;
00389     }
00390 }
00391 static void init_e( lapack_int size, float *e ) {
00392     lapack_int i;
00393     for( i = 0; i < size; i++ ) {
00394         e[i] = 0;
00395     }
00396 }
00397 static void init_q( lapack_int size, lapack_complex_float *q ) {
00398     lapack_int i;
00399     for( i = 0; i < size; i++ ) {
00400         q[i] = lapack_make_complex_float( 0.0f, 0.0f );
00401     }
00402     q[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00403     q[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00404     q[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00405     q[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00406     q[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00407     q[9] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00408     q[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00409     q[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00410     q[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00411     q[10] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00412     q[18] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00413     q[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00414     q[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00415     q[11] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00416     q[19] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00417     q[27] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00418 }
00419 static void init_work( lapack_int size, lapack_complex_float *work ) {
00420     lapack_int i;
00421     for( i = 0; i < size; i++ ) {
00422         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00423     }
00424 }
00425 
00426 /* Auxiliary function: C interface to chbtrd results check */
00427 /* Return value: 0 - test is passed, non-zero - test is failed */
00428 static int compare_chbtrd( lapack_complex_float *ab, lapack_complex_float *ab_i,
00429                            float *d, float *d_i, float *e, float *e_i,
00430                            lapack_complex_float *q, lapack_complex_float *q_i,
00431                            lapack_int info, lapack_int info_i, lapack_int ldab,
00432                            lapack_int ldq, lapack_int n, char vect )
00433 {
00434     lapack_int i;
00435     int failed = 0;
00436     for( i = 0; i < ldab*n; i++ ) {
00437         failed += compare_complex_floats(ab[i],ab_i[i]);
00438     }
00439     for( i = 0; i < n; i++ ) {
00440         failed += compare_floats(d[i],d_i[i]);
00441     }
00442     for( i = 0; i < (n-1); i++ ) {
00443         failed += compare_floats(e[i],e_i[i]);
00444     }
00445     if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00446         for( i = 0; i < ldq*n; i++ ) {
00447             failed += compare_complex_floats(q[i],q_i[i]);
00448         }
00449     }
00450     failed += (info == info_i) ? 0 : 1;
00451     if( info != 0 || info_i != 0 ) {
00452         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00453     }
00454 
00455     return failed;
00456 }


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