zungtr_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 * zungtr_1 is the test program for the C interface to LAPACK
00036 * routine zungtr
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_zungtr( char *uplo, 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_tau( lapack_int size, lapack_complex_double *tau );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zungtr( lapack_complex_double *a, lapack_complex_double *a_i,
00060                            lapack_int info, lapack_int info_i, lapack_int lda,
00061                            lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_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     /* Local arrays */
00076     lapack_complex_double *a = NULL, *a_i = NULL;
00077     lapack_complex_double *tau = NULL, *tau_i = NULL;
00078     lapack_complex_double *work = NULL, *work_i = NULL;
00079     lapack_complex_double *a_save = NULL;
00080     lapack_complex_double *a_r = NULL;
00081 
00082     /* Iniitialize the scalar parameters */
00083     init_scalars_zungtr( &uplo, &n, &lda, &lwork );
00084     lda_r = n+2;
00085     uplo_i = uplo;
00086     n_i = n;
00087     lda_i = lda;
00088     lwork_i = lwork;
00089 
00090     /* Allocate memory for the LAPACK routine arrays */
00091     a = (lapack_complex_double *)
00092         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00093     tau = (lapack_complex_double *)
00094         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00095     work = (lapack_complex_double *)
00096         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00097 
00098     /* Allocate memory for the C interface function arrays */
00099     a_i = (lapack_complex_double *)
00100         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00101     tau_i = (lapack_complex_double *)
00102         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00103     work_i = (lapack_complex_double *)
00104         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     a_save = (lapack_complex_double *)
00108         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00109 
00110     /* Allocate memory for the row-major arrays */
00111     a_r = (lapack_complex_double *)
00112         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00113 
00114     /* Initialize input arrays */
00115     init_a( lda*n, a );
00116     init_tau( (n-1), tau );
00117     init_work( lwork, work );
00118 
00119     /* Backup the ouptut arrays */
00120     for( i = 0; i < lda*n; i++ ) {
00121         a_save[i] = a[i];
00122     }
00123 
00124     /* Call the LAPACK routine */
00125     zungtr_( &uplo, &n, a, &lda, tau, work, &lwork, &info );
00126 
00127     /* Initialize input data, call the column-major middle-level
00128      * interface to LAPACK routine and check the results */
00129     for( i = 0; i < lda*n; i++ ) {
00130         a_i[i] = a_save[i];
00131     }
00132     for( i = 0; i < (n-1); i++ ) {
00133         tau_i[i] = tau[i];
00134     }
00135     for( i = 0; i < lwork; i++ ) {
00136         work_i[i] = work[i];
00137     }
00138     info_i = LAPACKE_zungtr_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00139                                   tau_i, work_i, lwork_i );
00140 
00141     failed = compare_zungtr( a, a_i, info, info_i, lda, n );
00142     if( failed == 0 ) {
00143         printf( "PASSED: column-major middle-level interface to zungtr\n" );
00144     } else {
00145         printf( "FAILED: column-major middle-level interface to zungtr\n" );
00146     }
00147 
00148     /* Initialize input data, call the column-major high-level
00149      * interface to LAPACK routine and check the results */
00150     for( i = 0; i < lda*n; i++ ) {
00151         a_i[i] = a_save[i];
00152     }
00153     for( i = 0; i < (n-1); i++ ) {
00154         tau_i[i] = tau[i];
00155     }
00156     for( i = 0; i < lwork; i++ ) {
00157         work_i[i] = work[i];
00158     }
00159     info_i = LAPACKE_zungtr( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i, tau_i );
00160 
00161     failed = compare_zungtr( a, a_i, info, info_i, lda, n );
00162     if( failed == 0 ) {
00163         printf( "PASSED: column-major high-level interface to zungtr\n" );
00164     } else {
00165         printf( "FAILED: column-major high-level interface to zungtr\n" );
00166     }
00167 
00168     /* Initialize input data, call the row-major middle-level
00169      * interface to LAPACK routine and check the results */
00170     for( i = 0; i < lda*n; i++ ) {
00171         a_i[i] = a_save[i];
00172     }
00173     for( i = 0; i < (n-1); i++ ) {
00174         tau_i[i] = tau[i];
00175     }
00176     for( i = 0; i < lwork; i++ ) {
00177         work_i[i] = work[i];
00178     }
00179 
00180     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00181     info_i = LAPACKE_zungtr_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00182                                   tau_i, work_i, lwork_i );
00183 
00184     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00185 
00186     failed = compare_zungtr( a, a_i, info, info_i, lda, n );
00187     if( failed == 0 ) {
00188         printf( "PASSED: row-major middle-level interface to zungtr\n" );
00189     } else {
00190         printf( "FAILED: row-major middle-level interface to zungtr\n" );
00191     }
00192 
00193     /* Initialize input data, call the row-major high-level
00194      * interface to LAPACK routine and check the results */
00195     for( i = 0; i < lda*n; i++ ) {
00196         a_i[i] = a_save[i];
00197     }
00198     for( i = 0; i < (n-1); i++ ) {
00199         tau_i[i] = tau[i];
00200     }
00201     for( i = 0; i < lwork; i++ ) {
00202         work_i[i] = work[i];
00203     }
00204 
00205     /* Init row_major arrays */
00206     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00207     info_i = LAPACKE_zungtr( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r, tau_i );
00208 
00209     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00210 
00211     failed = compare_zungtr( a, a_i, info, info_i, lda, n );
00212     if( failed == 0 ) {
00213         printf( "PASSED: row-major high-level interface to zungtr\n" );
00214     } else {
00215         printf( "FAILED: row-major high-level interface to zungtr\n" );
00216     }
00217 
00218     /* Release memory */
00219     if( a != NULL ) {
00220         LAPACKE_free( a );
00221     }
00222     if( a_i != NULL ) {
00223         LAPACKE_free( a_i );
00224     }
00225     if( a_r != NULL ) {
00226         LAPACKE_free( a_r );
00227     }
00228     if( a_save != NULL ) {
00229         LAPACKE_free( a_save );
00230     }
00231     if( tau != NULL ) {
00232         LAPACKE_free( tau );
00233     }
00234     if( tau_i != NULL ) {
00235         LAPACKE_free( tau_i );
00236     }
00237     if( work != NULL ) {
00238         LAPACKE_free( work );
00239     }
00240     if( work_i != NULL ) {
00241         LAPACKE_free( work_i );
00242     }
00243 
00244     return 0;
00245 }
00246 
00247 /* Auxiliary function: zungtr scalar parameters initialization */
00248 static void init_scalars_zungtr( char *uplo, lapack_int *n, lapack_int *lda,
00249                                  lapack_int *lwork )
00250 {
00251     *uplo = 'L';
00252     *n = 4;
00253     *lda = 8;
00254     *lwork = 512;
00255 
00256     return;
00257 }
00258 
00259 /* Auxiliary functions: zungtr array parameters initialization */
00260 static void init_a( lapack_int size, lapack_complex_double *a ) {
00261     lapack_int i;
00262     for( i = 0; i < size; i++ ) {
00263         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00264     }
00265     a[0] = lapack_make_complex_double( 6.01999999999999960e+000,
00266                                        0.00000000000000000e+000 );
00267     a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00268                                        0.00000000000000000e+000 );
00269     a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00270                                         0.00000000000000000e+000 );
00271     a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00272                                         0.00000000000000000e+000 );
00273     a[1] = lapack_make_complex_double( 2.74238946905796020e+000,
00274                                        0.00000000000000000e+000 );
00275     a[9] = lapack_make_complex_double( 2.73884478838405960e+000,
00276                                        0.00000000000000000e+000 );
00277     a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00278                                         0.00000000000000000e+000 );
00279     a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00280                                         0.00000000000000000e+000 );
00281     a[2] = lapack_make_complex_double( 4.47159464619637070e-001,
00282                                        5.10028663365299840e-001 );
00283     a[10] = lapack_make_complex_double( 1.83596199507003280e+000,
00284                                         0.00000000000000000e+000 );
00285     a[18] = lapack_make_complex_double( 5.17355680416448840e+000,
00286                                         0.00000000000000000e+000 );
00287     a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00288                                         0.00000000000000000e+000 );
00289     a[3] = lapack_make_complex_double( -4.67528244124222340e-001,
00290                                        -1.70128972117306430e-001 );
00291     a[11] = lapack_make_complex_double( 2.04211388385163510e-001,
00292                                         -3.61711899882242730e-001 );
00293     a[19] = lapack_make_complex_double( 1.69521155377209640e+000,
00294                                         0.00000000000000000e+000 );
00295     a[27] = lapack_make_complex_double( 2.46759840745145450e+000,
00296                                         0.00000000000000000e+000 );
00297 }
00298 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00299     lapack_int i;
00300     for( i = 0; i < size; i++ ) {
00301         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00302     }
00303     tau[0] = lapack_make_complex_double( 1.16409047842303020e+000,
00304                                          9.11613769016833550e-002 );
00305     tau[1] = lapack_make_complex_double( 1.52841731363511960e+000,
00306                                          -5.20542904209260300e-001 );
00307     tau[2] = lapack_make_complex_double( 1.73263408741633640e+000,
00308                                          6.80622725124302660e-001 );
00309 }
00310 static void init_work( lapack_int size, lapack_complex_double *work ) {
00311     lapack_int i;
00312     for( i = 0; i < size; i++ ) {
00313         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00314     }
00315 }
00316 
00317 /* Auxiliary function: C interface to zungtr results check */
00318 /* Return value: 0 - test is passed, non-zero - test is failed */
00319 static int compare_zungtr( lapack_complex_double *a, lapack_complex_double *a_i,
00320                            lapack_int info, lapack_int info_i, lapack_int lda,
00321                            lapack_int n )
00322 {
00323     lapack_int i;
00324     int failed = 0;
00325     for( i = 0; i < lda*n; i++ ) {
00326         failed += compare_complex_doubles(a[i],a_i[i]);
00327     }
00328     failed += (info == info_i) ? 0 : 1;
00329     if( info != 0 || info_i != 0 ) {
00330         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00331     }
00332 
00333     return failed;
00334 }


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