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


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