ztrexc_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 * ztrexc_1 is the test program for the C interface to LAPACK
00036 * routine ztrexc
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_ztrexc( char *compq, lapack_int *n, lapack_int *ldt,
00055                                  lapack_int *ldq, lapack_int *ifst,
00056                                  lapack_int *ilst );
00057 static void init_t( lapack_int size, lapack_complex_double *t );
00058 static void init_q( lapack_int size, lapack_complex_double *q );
00059 static int compare_ztrexc( lapack_complex_double *t, lapack_complex_double *t_i,
00060                            lapack_complex_double *q, lapack_complex_double *q_i,
00061                            lapack_int info, lapack_int info_i, char compq,
00062                            lapack_int ldq, lapack_int ldt, lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char compq, compq_i;
00068     lapack_int n, n_i;
00069     lapack_int ldt, ldt_i;
00070     lapack_int ldt_r;
00071     lapack_int ldq, ldq_i;
00072     lapack_int ldq_r;
00073     lapack_int ifst, ifst_i;
00074     lapack_int ilst, ilst_i;
00075     lapack_int info, info_i;
00076     lapack_int i;
00077     int failed;
00078 
00079     /* Local arrays */
00080     lapack_complex_double *t = NULL, *t_i = NULL;
00081     lapack_complex_double *q = NULL, *q_i = NULL;
00082     lapack_complex_double *t_save = NULL;
00083     lapack_complex_double *q_save = NULL;
00084     lapack_complex_double *t_r = NULL;
00085     lapack_complex_double *q_r = NULL;
00086 
00087     /* Iniitialize the scalar parameters */
00088     init_scalars_ztrexc( &compq, &n, &ldt, &ldq, &ifst, &ilst );
00089     ldt_r = n+2;
00090     ldq_r = n+2;
00091     compq_i = compq;
00092     n_i = n;
00093     ldt_i = ldt;
00094     ldq_i = ldq;
00095     ifst_i = ifst;
00096     ilst_i = ilst;
00097 
00098     /* Allocate memory for the LAPACK routine arrays */
00099     t = (lapack_complex_double *)
00100         LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
00101     q = (lapack_complex_double *)
00102         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00103 
00104     /* Allocate memory for the C interface function arrays */
00105     t_i = (lapack_complex_double *)
00106         LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
00107     q_i = (lapack_complex_double *)
00108         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00109 
00110     /* Allocate memory for the backup arrays */
00111     t_save = (lapack_complex_double *)
00112         LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
00113     q_save = (lapack_complex_double *)
00114         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00115 
00116     /* Allocate memory for the row-major arrays */
00117     t_r = (lapack_complex_double *)
00118         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00119     q_r = (lapack_complex_double *)
00120         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00121 
00122     /* Initialize input arrays */
00123     init_t( ldt*n, t );
00124     init_q( ldq*n, q );
00125 
00126     /* Backup the ouptut arrays */
00127     for( i = 0; i < ldt*n; i++ ) {
00128         t_save[i] = t[i];
00129     }
00130     for( i = 0; i < ldq*n; i++ ) {
00131         q_save[i] = q[i];
00132     }
00133 
00134     /* Call the LAPACK routine */
00135     ztrexc_( &compq, &n, t, &ldt, q, &ldq, &ifst, &ilst, &info );
00136 
00137     /* Initialize input data, call the column-major middle-level
00138      * interface to LAPACK routine and check the results */
00139     for( i = 0; i < ldt*n; i++ ) {
00140         t_i[i] = t_save[i];
00141     }
00142     for( i = 0; i < ldq*n; i++ ) {
00143         q_i[i] = q_save[i];
00144     }
00145     info_i = LAPACKE_ztrexc_work( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i,
00146                                   q_i, ldq_i, ifst_i, ilst_i );
00147 
00148     failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
00149     if( failed == 0 ) {
00150         printf( "PASSED: column-major middle-level interface to ztrexc\n" );
00151     } else {
00152         printf( "FAILED: column-major middle-level interface to ztrexc\n" );
00153     }
00154 
00155     /* Initialize input data, call the column-major high-level
00156      * interface to LAPACK routine and check the results */
00157     for( i = 0; i < ldt*n; i++ ) {
00158         t_i[i] = t_save[i];
00159     }
00160     for( i = 0; i < ldq*n; i++ ) {
00161         q_i[i] = q_save[i];
00162     }
00163     info_i = LAPACKE_ztrexc( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i, q_i,
00164                              ldq_i, ifst_i, ilst_i );
00165 
00166     failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
00167     if( failed == 0 ) {
00168         printf( "PASSED: column-major high-level interface to ztrexc\n" );
00169     } else {
00170         printf( "FAILED: column-major high-level interface to ztrexc\n" );
00171     }
00172 
00173     /* Initialize input data, call the row-major middle-level
00174      * interface to LAPACK routine and check the results */
00175     for( i = 0; i < ldt*n; i++ ) {
00176         t_i[i] = t_save[i];
00177     }
00178     for( i = 0; i < ldq*n; i++ ) {
00179         q_i[i] = q_save[i];
00180     }
00181 
00182     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
00183     if( LAPACKE_lsame( compq, 'v' ) ) {
00184         LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00185     }
00186     info_i = LAPACKE_ztrexc_work( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r,
00187                                   q_r, ldq_r, ifst_i, ilst_i );
00188 
00189     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
00190     if( LAPACKE_lsame( compq, 'v' ) ) {
00191         LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00192     }
00193 
00194     failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: row-major middle-level interface to ztrexc\n" );
00197     } else {
00198         printf( "FAILED: row-major middle-level interface to ztrexc\n" );
00199     }
00200 
00201     /* Initialize input data, call the row-major high-level
00202      * interface to LAPACK routine and check the results */
00203     for( i = 0; i < ldt*n; i++ ) {
00204         t_i[i] = t_save[i];
00205     }
00206     for( i = 0; i < ldq*n; i++ ) {
00207         q_i[i] = q_save[i];
00208     }
00209 
00210     /* Init row_major arrays */
00211     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
00212     if( LAPACKE_lsame( compq, 'v' ) ) {
00213         LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00214     }
00215     info_i = LAPACKE_ztrexc( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r, q_r,
00216                              ldq_r, ifst_i, ilst_i );
00217 
00218     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
00219     if( LAPACKE_lsame( compq, 'v' ) ) {
00220         LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00221     }
00222 
00223     failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
00224     if( failed == 0 ) {
00225         printf( "PASSED: row-major high-level interface to ztrexc\n" );
00226     } else {
00227         printf( "FAILED: row-major high-level interface to ztrexc\n" );
00228     }
00229 
00230     /* Release memory */
00231     if( t != NULL ) {
00232         LAPACKE_free( t );
00233     }
00234     if( t_i != NULL ) {
00235         LAPACKE_free( t_i );
00236     }
00237     if( t_r != NULL ) {
00238         LAPACKE_free( t_r );
00239     }
00240     if( t_save != NULL ) {
00241         LAPACKE_free( t_save );
00242     }
00243     if( q != NULL ) {
00244         LAPACKE_free( q );
00245     }
00246     if( q_i != NULL ) {
00247         LAPACKE_free( q_i );
00248     }
00249     if( q_r != NULL ) {
00250         LAPACKE_free( q_r );
00251     }
00252     if( q_save != NULL ) {
00253         LAPACKE_free( q_save );
00254     }
00255 
00256     return 0;
00257 }
00258 
00259 /* Auxiliary function: ztrexc scalar parameters initialization */
00260 static void init_scalars_ztrexc( char *compq, lapack_int *n, lapack_int *ldt,
00261                                  lapack_int *ldq, lapack_int *ifst,
00262                                  lapack_int *ilst )
00263 {
00264     *compq = 'N';
00265     *n = 4;
00266     *ldt = 8;
00267     *ldq = 1;
00268     *ifst = 1;
00269     *ilst = 4;
00270 
00271     return;
00272 }
00273 
00274 /* Auxiliary functions: ztrexc array parameters initialization */
00275 static void init_t( lapack_int size, lapack_complex_double *t ) {
00276     lapack_int i;
00277     for( i = 0; i < size; i++ ) {
00278         t[i] = lapack_make_complex_double( 0.0, 0.0 );
00279     }
00280     t[0] = lapack_make_complex_double( -6.00000000000000000e+000,
00281                                        -7.00000000000000000e+000 );
00282     t[8] = lapack_make_complex_double( 3.59999999999999990e-001,
00283                                        -3.59999999999999990e-001 );
00284     t[16] = lapack_make_complex_double( -1.90000000000000000e-001,
00285                                         4.79999999999999980e-001 );
00286     t[24] = lapack_make_complex_double( 8.80000000000000000e-001,
00287                                         -2.50000000000000000e-001 );
00288     t[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00289                                        0.00000000000000000e+000 );
00290     t[9] = lapack_make_complex_double( -5.00000000000000000e+000,
00291                                        2.00000000000000000e+000 );
00292     t[17] = lapack_make_complex_double( -2.99999999999999990e-002,
00293                                         -7.19999999999999970e-001 );
00294     t[25] = lapack_make_complex_double( -2.30000000000000010e-001,
00295                                         1.30000000000000000e-001 );
00296     t[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00297                                        0.00000000000000000e+000 );
00298     t[10] = lapack_make_complex_double( 0.00000000000000000e+000,
00299                                         0.00000000000000000e+000 );
00300     t[18] = lapack_make_complex_double( 8.00000000000000000e+000,
00301                                         -1.00000000000000000e+000 );
00302     t[26] = lapack_make_complex_double( 9.39999999999999950e-001,
00303                                         5.30000000000000030e-001 );
00304     t[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00305                                        0.00000000000000000e+000 );
00306     t[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00307                                         0.00000000000000000e+000 );
00308     t[19] = lapack_make_complex_double( 0.00000000000000000e+000,
00309                                         0.00000000000000000e+000 );
00310     t[27] = lapack_make_complex_double( 3.00000000000000000e+000,
00311                                         -4.00000000000000000e+000 );
00312 }
00313 static void init_q( lapack_int size, lapack_complex_double *q ) {
00314     lapack_int i;
00315     for( i = 0; i < size; i++ ) {
00316         q[i] = lapack_make_complex_double( 0.0, 0.0 );
00317     }
00318     q[0] = lapack_make_complex_double( 0.00000000000000000e+000,
00319                                        0.00000000000000000e+000 );
00320     q[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00321                                        0.00000000000000000e+000 );
00322     q[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00323                                        0.00000000000000000e+000 );
00324     q[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00325                                        0.00000000000000000e+000 );
00326     q[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00327                                        0.00000000000000000e+000 );
00328     q[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00329                                        0.00000000000000000e+000 );
00330     q[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00331                                        0.00000000000000000e+000 );
00332     q[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00333                                        0.00000000000000000e+000 );
00334     q[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00335                                        0.00000000000000000e+000 );
00336     q[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00337                                        0.00000000000000000e+000 );
00338 }
00339 
00340 /* Auxiliary function: C interface to ztrexc results check */
00341 /* Return value: 0 - test is passed, non-zero - test is failed */
00342 static int compare_ztrexc( lapack_complex_double *t, lapack_complex_double *t_i,
00343                            lapack_complex_double *q, lapack_complex_double *q_i,
00344                            lapack_int info, lapack_int info_i, char compq,
00345                            lapack_int ldq, lapack_int ldt, lapack_int n )
00346 {
00347     lapack_int i;
00348     int failed = 0;
00349     for( i = 0; i < ldt*n; i++ ) {
00350         failed += compare_complex_doubles(t[i],t_i[i]);
00351     }
00352     if( LAPACKE_lsame( compq, 'v' ) ) {
00353         for( i = 0; i < ldq*n; i++ ) {
00354             failed += compare_complex_doubles(q[i],q_i[i]);
00355         }
00356     }
00357     failed += (info == info_i) ? 0 : 1;
00358     if( info != 0 || info_i != 0 ) {
00359         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00360     }
00361 
00362     return failed;
00363 }


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