dtrsyl_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 * dtrsyl_1 is the test program for the C interface to LAPACK
00036 * routine dtrsyl
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_dtrsyl( char *trana, char *tranb, lapack_int *isgn,
00055                                  lapack_int *m, lapack_int *n, lapack_int *lda,
00056                                  lapack_int *ldb, lapack_int *ldc );
00057 static void init_a( lapack_int size, double *a );
00058 static void init_b( lapack_int size, double *b );
00059 static void init_c( lapack_int size, double *c );
00060 static int compare_dtrsyl( double *c, double *c_i, double scale, double scale_i,
00061                            lapack_int info, lapack_int info_i, lapack_int ldc,
00062                            lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char trana, trana_i;
00068     char tranb, tranb_i;
00069     lapack_int isgn, isgn_i;
00070     lapack_int m, m_i;
00071     lapack_int n, n_i;
00072     lapack_int lda, lda_i;
00073     lapack_int lda_r;
00074     lapack_int ldb, ldb_i;
00075     lapack_int ldb_r;
00076     lapack_int ldc, ldc_i;
00077     lapack_int ldc_r;
00078     double scale, scale_i;
00079     lapack_int info, info_i;
00080     lapack_int i;
00081     int failed;
00082 
00083     /* Local arrays */
00084     double *a = NULL, *a_i = NULL;
00085     double *b = NULL, *b_i = NULL;
00086     double *c = NULL, *c_i = NULL;
00087     double *c_save = NULL;
00088     double *a_r = NULL;
00089     double *b_r = NULL;
00090     double *c_r = NULL;
00091 
00092     /* Iniitialize the scalar parameters */
00093     init_scalars_dtrsyl( &trana, &tranb, &isgn, &m, &n, &lda, &ldb, &ldc );
00094     lda_r = m+2;
00095     ldb_r = n+2;
00096     ldc_r = n+2;
00097     trana_i = trana;
00098     tranb_i = tranb;
00099     isgn_i = isgn;
00100     m_i = m;
00101     n_i = n;
00102     lda_i = lda;
00103     ldb_i = ldb;
00104     ldc_i = ldc;
00105 
00106     /* Allocate memory for the LAPACK routine arrays */
00107     a = (double *)LAPACKE_malloc( lda*m * sizeof(double) );
00108     b = (double *)LAPACKE_malloc( ldb*n * sizeof(double) );
00109     c = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00110 
00111     /* Allocate memory for the C interface function arrays */
00112     a_i = (double *)LAPACKE_malloc( lda*m * sizeof(double) );
00113     b_i = (double *)LAPACKE_malloc( ldb*n * sizeof(double) );
00114     c_i = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00115 
00116     /* Allocate memory for the backup arrays */
00117     c_save = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00118 
00119     /* Allocate memory for the row-major arrays */
00120     a_r = (double *)LAPACKE_malloc( m*(m+2) * sizeof(double) );
00121     b_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00122     c_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00123 
00124     /* Initialize input arrays */
00125     init_a( lda*m, a );
00126     init_b( ldb*n, b );
00127     init_c( ldc*n, c );
00128 
00129     /* Backup the ouptut arrays */
00130     for( i = 0; i < ldc*n; i++ ) {
00131         c_save[i] = c[i];
00132     }
00133 
00134     /* Call the LAPACK routine */
00135     dtrsyl_( &trana, &tranb, &isgn, &m, &n, a, &lda, b, &ldb, c, &ldc, &scale,
00136              &info );
00137 
00138     /* Initialize input data, call the column-major middle-level
00139      * interface to LAPACK routine and check the results */
00140     for( i = 0; i < lda*m; i++ ) {
00141         a_i[i] = a[i];
00142     }
00143     for( i = 0; i < ldb*n; i++ ) {
00144         b_i[i] = b[i];
00145     }
00146     for( i = 0; i < ldc*n; i++ ) {
00147         c_i[i] = c_save[i];
00148     }
00149     info_i = LAPACKE_dtrsyl_work( LAPACK_COL_MAJOR, trana_i, tranb_i, isgn_i,
00150                                   m_i, n_i, a_i, lda_i, b_i, ldb_i, c_i, ldc_i,
00151                                   &scale_i );
00152 
00153     failed = compare_dtrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00154     if( failed == 0 ) {
00155         printf( "PASSED: column-major middle-level interface to dtrsyl\n" );
00156     } else {
00157         printf( "FAILED: column-major middle-level interface to dtrsyl\n" );
00158     }
00159 
00160     /* Initialize input data, call the column-major high-level
00161      * interface to LAPACK routine and check the results */
00162     for( i = 0; i < lda*m; i++ ) {
00163         a_i[i] = a[i];
00164     }
00165     for( i = 0; i < ldb*n; i++ ) {
00166         b_i[i] = b[i];
00167     }
00168     for( i = 0; i < ldc*n; i++ ) {
00169         c_i[i] = c_save[i];
00170     }
00171     info_i = LAPACKE_dtrsyl( LAPACK_COL_MAJOR, trana_i, tranb_i, isgn_i, m_i,
00172                              n_i, a_i, lda_i, b_i, ldb_i, c_i, ldc_i,
00173                              &scale_i );
00174 
00175     failed = compare_dtrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major high-level interface to dtrsyl\n" );
00178     } else {
00179         printf( "FAILED: column-major high-level interface to dtrsyl\n" );
00180     }
00181 
00182     /* Initialize input data, call the row-major middle-level
00183      * interface to LAPACK routine and check the results */
00184     for( i = 0; i < lda*m; i++ ) {
00185         a_i[i] = a[i];
00186     }
00187     for( i = 0; i < ldb*n; i++ ) {
00188         b_i[i] = b[i];
00189     }
00190     for( i = 0; i < ldc*n; i++ ) {
00191         c_i[i] = c_save[i];
00192     }
00193 
00194     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, m, a_i, lda, a_r, m+2 );
00195     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00196     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00197     info_i = LAPACKE_dtrsyl_work( LAPACK_ROW_MAJOR, trana_i, tranb_i, isgn_i,
00198                                   m_i, n_i, a_r, lda_r, b_r, ldb_r, c_r, ldc_r,
00199                                   &scale_i );
00200 
00201     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00202 
00203     failed = compare_dtrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00204     if( failed == 0 ) {
00205         printf( "PASSED: row-major middle-level interface to dtrsyl\n" );
00206     } else {
00207         printf( "FAILED: row-major middle-level interface to dtrsyl\n" );
00208     }
00209 
00210     /* Initialize input data, call the row-major high-level
00211      * interface to LAPACK routine and check the results */
00212     for( i = 0; i < lda*m; i++ ) {
00213         a_i[i] = a[i];
00214     }
00215     for( i = 0; i < ldb*n; i++ ) {
00216         b_i[i] = b[i];
00217     }
00218     for( i = 0; i < ldc*n; i++ ) {
00219         c_i[i] = c_save[i];
00220     }
00221 
00222     /* Init row_major arrays */
00223     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, m, a_i, lda, a_r, m+2 );
00224     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00225     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00226     info_i = LAPACKE_dtrsyl( LAPACK_ROW_MAJOR, trana_i, tranb_i, isgn_i, m_i,
00227                              n_i, a_r, lda_r, b_r, ldb_r, c_r, ldc_r,
00228                              &scale_i );
00229 
00230     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00231 
00232     failed = compare_dtrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00233     if( failed == 0 ) {
00234         printf( "PASSED: row-major high-level interface to dtrsyl\n" );
00235     } else {
00236         printf( "FAILED: row-major high-level interface to dtrsyl\n" );
00237     }
00238 
00239     /* Release memory */
00240     if( a != NULL ) {
00241         LAPACKE_free( a );
00242     }
00243     if( a_i != NULL ) {
00244         LAPACKE_free( a_i );
00245     }
00246     if( a_r != NULL ) {
00247         LAPACKE_free( a_r );
00248     }
00249     if( b != NULL ) {
00250         LAPACKE_free( b );
00251     }
00252     if( b_i != NULL ) {
00253         LAPACKE_free( b_i );
00254     }
00255     if( b_r != NULL ) {
00256         LAPACKE_free( b_r );
00257     }
00258     if( c != NULL ) {
00259         LAPACKE_free( c );
00260     }
00261     if( c_i != NULL ) {
00262         LAPACKE_free( c_i );
00263     }
00264     if( c_r != NULL ) {
00265         LAPACKE_free( c_r );
00266     }
00267     if( c_save != NULL ) {
00268         LAPACKE_free( c_save );
00269     }
00270 
00271     return 0;
00272 }
00273 
00274 /* Auxiliary function: dtrsyl scalar parameters initialization */
00275 static void init_scalars_dtrsyl( char *trana, char *tranb, lapack_int *isgn,
00276                                  lapack_int *m, lapack_int *n, lapack_int *lda,
00277                                  lapack_int *ldb, lapack_int *ldc )
00278 {
00279     *trana = 'N';
00280     *tranb = 'N';
00281     *isgn = 1;
00282     *m = 4;
00283     *n = 4;
00284     *lda = 8;
00285     *ldb = 8;
00286     *ldc = 8;
00287 
00288     return;
00289 }
00290 
00291 /* Auxiliary functions: dtrsyl array parameters initialization */
00292 static void init_a( lapack_int size, double *a ) {
00293     lapack_int i;
00294     for( i = 0; i < size; i++ ) {
00295         a[i] = 0;
00296     }
00297     a[0] = 1.00000000000000010e-001;  /* a[0,0] */
00298     a[8] = 5.00000000000000000e-001;  /* a[0,1] */
00299     a[16] = 6.80000000000000050e-001;  /* a[0,2] */
00300     a[24] = -2.09999999999999990e-001;  /* a[0,3] */
00301     a[1] = -5.00000000000000000e-001;  /* a[1,0] */
00302     a[9] = 1.00000000000000010e-001;  /* a[1,1] */
00303     a[17] = -2.39999999999999990e-001;  /* a[1,2] */
00304     a[25] = 6.70000000000000040e-001;  /* a[1,3] */
00305     a[2] = 0.00000000000000000e+000;  /* a[2,0] */
00306     a[10] = 0.00000000000000000e+000;  /* a[2,1] */
00307     a[18] = 1.90000000000000000e-001;  /* a[2,2] */
00308     a[26] = -3.49999999999999980e-001;  /* a[2,3] */
00309     a[3] = 0.00000000000000000e+000;  /* a[3,0] */
00310     a[11] = 0.00000000000000000e+000;  /* a[3,1] */
00311     a[19] = 0.00000000000000000e+000;  /* a[3,2] */
00312     a[27] = -7.19999999999999970e-001;  /* a[3,3] */
00313 }
00314 static void init_b( lapack_int size, double *b ) {
00315     lapack_int i;
00316     for( i = 0; i < size; i++ ) {
00317         b[i] = 0;
00318     }
00319     b[0] = -9.89999999999999990e-001;  /* b[0,0] */
00320     b[8] = -1.70000000000000010e-001;  /* b[0,1] */
00321     b[16] = 3.90000000000000010e-001;  /* b[0,2] */
00322     b[24] = 5.79999999999999960e-001;  /* b[0,3] */
00323     b[1] = 0.00000000000000000e+000;  /* b[1,0] */
00324     b[9] = 4.79999999999999980e-001;  /* b[1,1] */
00325     b[17] = -8.39999999999999970e-001;  /* b[1,2] */
00326     b[25] = -1.49999999999999990e-001;  /* b[1,3] */
00327     b[2] = 0.00000000000000000e+000;  /* b[2,0] */
00328     b[10] = 0.00000000000000000e+000;  /* b[2,1] */
00329     b[18] = 7.50000000000000000e-001;  /* b[2,2] */
00330     b[26] = 2.50000000000000000e-001;  /* b[2,3] */
00331     b[3] = 0.00000000000000000e+000;  /* b[3,0] */
00332     b[11] = 0.00000000000000000e+000;  /* b[3,1] */
00333     b[19] = -2.50000000000000000e-001;  /* b[3,2] */
00334     b[27] = 7.50000000000000000e-001;  /* b[3,3] */
00335 }
00336 static void init_c( lapack_int size, double *c ) {
00337     lapack_int i;
00338     for( i = 0; i < size; i++ ) {
00339         c[i] = 0;
00340     }
00341     c[0] = 6.30000000000000000e-001;  /* c[0,0] */
00342     c[8] = -5.60000000000000050e-001;  /* c[0,1] */
00343     c[16] = 8.00000000000000020e-002;  /* c[0,2] */
00344     c[24] = -2.30000000000000010e-001;  /* c[0,3] */
00345     c[1] = -4.50000000000000010e-001;  /* c[1,0] */
00346     c[9] = -3.10000000000000000e-001;  /* c[1,1] */
00347     c[17] = 2.70000000000000020e-001;  /* c[1,2] */
00348     c[25] = 1.21000000000000000e+000;  /* c[1,3] */
00349     c[2] = 2.00000000000000010e-001;  /* c[2,0] */
00350     c[10] = -3.49999999999999980e-001;  /* c[2,1] */
00351     c[18] = 4.09999999999999980e-001;  /* c[2,2] */
00352     c[26] = 8.39999999999999970e-001;  /* c[2,3] */
00353     c[3] = 4.89999999999999990e-001;  /* c[3,0] */
00354     c[11] = -5.00000000000000030e-002;  /* c[3,1] */
00355     c[19] = -5.20000000000000020e-001;  /* c[3,2] */
00356     c[27] = -8.00000000000000020e-002;  /* c[3,3] */
00357 }
00358 
00359 /* Auxiliary function: C interface to dtrsyl results check */
00360 /* Return value: 0 - test is passed, non-zero - test is failed */
00361 static int compare_dtrsyl( double *c, double *c_i, double scale, double scale_i,
00362                            lapack_int info, lapack_int info_i, lapack_int ldc,
00363                            lapack_int n )
00364 {
00365     lapack_int i;
00366     int failed = 0;
00367     for( i = 0; i < ldc*n; i++ ) {
00368         failed += compare_doubles(c[i],c_i[i]);
00369     }
00370     failed += compare_doubles(scale,scale_i);
00371     failed += (info == info_i) ? 0 : 1;
00372     if( info != 0 || info_i != 0 ) {
00373         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00374     }
00375 
00376     return failed;
00377 }


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