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


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