ztrsyl_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 * ztrsyl_1 is the test program for the C interface to LAPACK
00036 * routine ztrsyl
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_ztrsyl( 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, lapack_complex_double *a );
00058 static void init_b( lapack_int size, lapack_complex_double *b );
00059 static void init_c( lapack_int size, lapack_complex_double *c );
00060 static int compare_ztrsyl( lapack_complex_double *c, lapack_complex_double *c_i,
00061                            double scale, double scale_i, lapack_int info,
00062                            lapack_int info_i, lapack_int ldc, 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     lapack_complex_double *a = NULL, *a_i = NULL;
00085     lapack_complex_double *b = NULL, *b_i = NULL;
00086     lapack_complex_double *c = NULL, *c_i = NULL;
00087     lapack_complex_double *c_save = NULL;
00088     lapack_complex_double *a_r = NULL;
00089     lapack_complex_double *b_r = NULL;
00090     lapack_complex_double *c_r = NULL;
00091 
00092     /* Iniitialize the scalar parameters */
00093     init_scalars_ztrsyl( &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 = (lapack_complex_double *)
00108         LAPACKE_malloc( lda*m * sizeof(lapack_complex_double) );
00109     b = (lapack_complex_double *)
00110         LAPACKE_malloc( ldb*n * sizeof(lapack_complex_double) );
00111     c = (lapack_complex_double *)
00112         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00113 
00114     /* Allocate memory for the C interface function arrays */
00115     a_i = (lapack_complex_double *)
00116         LAPACKE_malloc( lda*m * sizeof(lapack_complex_double) );
00117     b_i = (lapack_complex_double *)
00118         LAPACKE_malloc( ldb*n * sizeof(lapack_complex_double) );
00119     c_i = (lapack_complex_double *)
00120         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00121 
00122     /* Allocate memory for the backup arrays */
00123     c_save = (lapack_complex_double *)
00124         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00125 
00126     /* Allocate memory for the row-major arrays */
00127     a_r = (lapack_complex_double *)
00128         LAPACKE_malloc( m*(m+2) * sizeof(lapack_complex_double) );
00129     b_r = (lapack_complex_double *)
00130         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00131     c_r = (lapack_complex_double *)
00132         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00133 
00134     /* Initialize input arrays */
00135     init_a( lda*m, a );
00136     init_b( ldb*n, b );
00137     init_c( ldc*n, c );
00138 
00139     /* Backup the ouptut arrays */
00140     for( i = 0; i < ldc*n; i++ ) {
00141         c_save[i] = c[i];
00142     }
00143 
00144     /* Call the LAPACK routine */
00145     ztrsyl_( &trana, &tranb, &isgn, &m, &n, a, &lda, b, &ldb, c, &ldc, &scale,
00146              &info );
00147 
00148     /* Initialize input data, call the column-major middle-level
00149      * interface to LAPACK routine and check the results */
00150     for( i = 0; i < lda*m; i++ ) {
00151         a_i[i] = a[i];
00152     }
00153     for( i = 0; i < ldb*n; i++ ) {
00154         b_i[i] = b[i];
00155     }
00156     for( i = 0; i < ldc*n; i++ ) {
00157         c_i[i] = c_save[i];
00158     }
00159     info_i = LAPACKE_ztrsyl_work( LAPACK_COL_MAJOR, trana_i, tranb_i, isgn_i,
00160                                   m_i, n_i, a_i, lda_i, b_i, ldb_i, c_i, ldc_i,
00161                                   &scale_i );
00162 
00163     failed = compare_ztrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major middle-level interface to ztrsyl\n" );
00166     } else {
00167         printf( "FAILED: column-major middle-level interface to ztrsyl\n" );
00168     }
00169 
00170     /* Initialize input data, call the column-major high-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < lda*m; i++ ) {
00173         a_i[i] = a[i];
00174     }
00175     for( i = 0; i < ldb*n; i++ ) {
00176         b_i[i] = b[i];
00177     }
00178     for( i = 0; i < ldc*n; i++ ) {
00179         c_i[i] = c_save[i];
00180     }
00181     info_i = LAPACKE_ztrsyl( LAPACK_COL_MAJOR, trana_i, tranb_i, isgn_i, m_i,
00182                              n_i, a_i, lda_i, b_i, ldb_i, c_i, ldc_i,
00183                              &scale_i );
00184 
00185     failed = compare_ztrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00186     if( failed == 0 ) {
00187         printf( "PASSED: column-major high-level interface to ztrsyl\n" );
00188     } else {
00189         printf( "FAILED: column-major high-level interface to ztrsyl\n" );
00190     }
00191 
00192     /* Initialize input data, call the row-major middle-level
00193      * interface to LAPACK routine and check the results */
00194     for( i = 0; i < lda*m; i++ ) {
00195         a_i[i] = a[i];
00196     }
00197     for( i = 0; i < ldb*n; i++ ) {
00198         b_i[i] = b[i];
00199     }
00200     for( i = 0; i < ldc*n; i++ ) {
00201         c_i[i] = c_save[i];
00202     }
00203 
00204     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, m, a_i, lda, a_r, m+2 );
00205     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00206     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00207     info_i = LAPACKE_ztrsyl_work( LAPACK_ROW_MAJOR, trana_i, tranb_i, isgn_i,
00208                                   m_i, n_i, a_r, lda_r, b_r, ldb_r, c_r, ldc_r,
00209                                   &scale_i );
00210 
00211     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00212 
00213     failed = compare_ztrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00214     if( failed == 0 ) {
00215         printf( "PASSED: row-major middle-level interface to ztrsyl\n" );
00216     } else {
00217         printf( "FAILED: row-major middle-level interface to ztrsyl\n" );
00218     }
00219 
00220     /* Initialize input data, call the row-major high-level
00221      * interface to LAPACK routine and check the results */
00222     for( i = 0; i < lda*m; i++ ) {
00223         a_i[i] = a[i];
00224     }
00225     for( i = 0; i < ldb*n; i++ ) {
00226         b_i[i] = b[i];
00227     }
00228     for( i = 0; i < ldc*n; i++ ) {
00229         c_i[i] = c_save[i];
00230     }
00231 
00232     /* Init row_major arrays */
00233     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, m, a_i, lda, a_r, m+2 );
00234     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00235     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00236     info_i = LAPACKE_ztrsyl( LAPACK_ROW_MAJOR, trana_i, tranb_i, isgn_i, m_i,
00237                              n_i, a_r, lda_r, b_r, ldb_r, c_r, ldc_r,
00238                              &scale_i );
00239 
00240     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00241 
00242     failed = compare_ztrsyl( c, c_i, scale, scale_i, info, info_i, ldc, n );
00243     if( failed == 0 ) {
00244         printf( "PASSED: row-major high-level interface to ztrsyl\n" );
00245     } else {
00246         printf( "FAILED: row-major high-level interface to ztrsyl\n" );
00247     }
00248 
00249     /* Release memory */
00250     if( a != NULL ) {
00251         LAPACKE_free( a );
00252     }
00253     if( a_i != NULL ) {
00254         LAPACKE_free( a_i );
00255     }
00256     if( a_r != NULL ) {
00257         LAPACKE_free( a_r );
00258     }
00259     if( b != NULL ) {
00260         LAPACKE_free( b );
00261     }
00262     if( b_i != NULL ) {
00263         LAPACKE_free( b_i );
00264     }
00265     if( b_r != NULL ) {
00266         LAPACKE_free( b_r );
00267     }
00268     if( c != NULL ) {
00269         LAPACKE_free( c );
00270     }
00271     if( c_i != NULL ) {
00272         LAPACKE_free( c_i );
00273     }
00274     if( c_r != NULL ) {
00275         LAPACKE_free( c_r );
00276     }
00277     if( c_save != NULL ) {
00278         LAPACKE_free( c_save );
00279     }
00280 
00281     return 0;
00282 }
00283 
00284 /* Auxiliary function: ztrsyl scalar parameters initialization */
00285 static void init_scalars_ztrsyl( char *trana, char *tranb, lapack_int *isgn,
00286                                  lapack_int *m, lapack_int *n, lapack_int *lda,
00287                                  lapack_int *ldb, lapack_int *ldc )
00288 {
00289     *trana = 'N';
00290     *tranb = 'N';
00291     *isgn = 1;
00292     *m = 4;
00293     *n = 4;
00294     *lda = 8;
00295     *ldb = 8;
00296     *ldc = 8;
00297 
00298     return;
00299 }
00300 
00301 /* Auxiliary functions: ztrsyl array parameters initialization */
00302 static void init_a( lapack_int size, lapack_complex_double *a ) {
00303     lapack_int i;
00304     for( i = 0; i < size; i++ ) {
00305         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00306     }
00307     a[0] = lapack_make_complex_double( -6.00000000000000000e+000,
00308                                        -7.00000000000000000e+000 );
00309     a[8] = lapack_make_complex_double( 3.59999999999999990e-001,
00310                                        -3.59999999999999990e-001 );
00311     a[16] = lapack_make_complex_double( -1.90000000000000000e-001,
00312                                         4.79999999999999980e-001 );
00313     a[24] = lapack_make_complex_double( 8.80000000000000000e-001,
00314                                         -2.50000000000000000e-001 );
00315     a[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00316                                        0.00000000000000000e+000 );
00317     a[9] = lapack_make_complex_double( -5.00000000000000000e+000,
00318                                        2.00000000000000000e+000 );
00319     a[17] = lapack_make_complex_double( -2.99999999999999990e-002,
00320                                         -7.19999999999999970e-001 );
00321     a[25] = lapack_make_complex_double( -2.30000000000000010e-001,
00322                                         1.30000000000000000e-001 );
00323     a[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00324                                        0.00000000000000000e+000 );
00325     a[10] = lapack_make_complex_double( 0.00000000000000000e+000,
00326                                         0.00000000000000000e+000 );
00327     a[18] = lapack_make_complex_double( 8.00000000000000000e+000,
00328                                         -1.00000000000000000e+000 );
00329     a[26] = lapack_make_complex_double( 9.39999999999999950e-001,
00330                                         5.30000000000000030e-001 );
00331     a[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00332                                        0.00000000000000000e+000 );
00333     a[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00334                                         0.00000000000000000e+000 );
00335     a[19] = lapack_make_complex_double( 0.00000000000000000e+000,
00336                                         0.00000000000000000e+000 );
00337     a[27] = lapack_make_complex_double( 3.00000000000000000e+000,
00338                                         -4.00000000000000000e+000 );
00339 }
00340 static void init_b( lapack_int size, lapack_complex_double *b ) {
00341     lapack_int i;
00342     for( i = 0; i < size; i++ ) {
00343         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00344     }
00345     b[0] = lapack_make_complex_double( 5.00000000000000000e-001,
00346                                        -2.00000000000000010e-001 );
00347     b[8] = lapack_make_complex_double( -2.89999999999999980e-001,
00348                                        -1.60000000000000000e-001 );
00349     b[16] = lapack_make_complex_double( -3.70000000000000000e-001,
00350                                         8.39999999999999970e-001 );
00351     b[24] = lapack_make_complex_double( -5.50000000000000040e-001,
00352                                         7.29999999999999980e-001 );
00353     b[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00354                                        0.00000000000000000e+000 );
00355     b[9] = lapack_make_complex_double( -4.00000000000000020e-001,
00356                                        9.00000000000000020e-001 );
00357     b[17] = lapack_make_complex_double( 5.99999999999999980e-002,
00358                                         2.20000000000000000e-001 );
00359     b[25] = lapack_make_complex_double( -4.29999999999999990e-001,
00360                                         1.70000000000000010e-001 );
00361     b[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00362                                        0.00000000000000000e+000 );
00363     b[10] = lapack_make_complex_double( 0.00000000000000000e+000,
00364                                         0.00000000000000000e+000 );
00365     b[18] = lapack_make_complex_double( -9.00000000000000020e-001,
00366                                         -1.00000000000000010e-001 );
00367     b[26] = lapack_make_complex_double( -8.90000000000000010e-001,
00368                                         -4.19999999999999980e-001 );
00369     b[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00370                                        0.00000000000000000e+000 );
00371     b[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00372                                         0.00000000000000000e+000 );
00373     b[19] = lapack_make_complex_double( 0.00000000000000000e+000,
00374                                         0.00000000000000000e+000 );
00375     b[27] = lapack_make_complex_double( 2.99999999999999990e-001,
00376                                         -6.99999999999999960e-001 );
00377 }
00378 static void init_c( lapack_int size, lapack_complex_double *c ) {
00379     lapack_int i;
00380     for( i = 0; i < size; i++ ) {
00381         c[i] = lapack_make_complex_double( 0.0, 0.0 );
00382     }
00383     c[0] = lapack_make_complex_double( 6.30000000000000000e-001,
00384                                        3.49999999999999980e-001 );
00385     c[8] = lapack_make_complex_double( 4.50000000000000010e-001,
00386                                        -5.60000000000000050e-001 );
00387     c[16] = lapack_make_complex_double( 8.00000000000000020e-002,
00388                                         -1.40000000000000010e-001 );
00389     c[24] = lapack_make_complex_double( -1.70000000000000010e-001,
00390                                         -2.30000000000000010e-001 );
00391     c[1] = lapack_make_complex_double( -1.70000000000000010e-001,
00392                                        8.99999999999999970e-002 );
00393     c[9] = lapack_make_complex_double( -7.00000000000000070e-002,
00394                                        -3.10000000000000000e-001 );
00395     c[17] = lapack_make_complex_double( 2.70000000000000020e-001,
00396                                         -5.40000000000000040e-001 );
00397     c[25] = lapack_make_complex_double( 3.49999999999999980e-001,
00398                                         1.21000000000000000e+000 );
00399     c[2] = lapack_make_complex_double( -9.30000000000000050e-001,
00400                                        -4.40000000000000000e-001 );
00401     c[10] = lapack_make_complex_double( -3.30000000000000020e-001,
00402                                         -3.49999999999999980e-001 );
00403     c[18] = lapack_make_complex_double( 4.09999999999999980e-001,
00404                                         -2.99999999999999990e-002 );
00405     c[26] = lapack_make_complex_double( 5.69999999999999950e-001,
00406                                         8.39999999999999970e-001 );
00407     c[3] = lapack_make_complex_double( 5.40000000000000040e-001,
00408                                        2.50000000000000000e-001 );
00409     c[11] = lapack_make_complex_double( -6.20000000000000000e-001,
00410                                         -5.00000000000000030e-002 );
00411     c[19] = lapack_make_complex_double( -5.20000000000000020e-001,
00412                                         -1.30000000000000000e-001 );
00413     c[27] = lapack_make_complex_double( 1.10000000000000000e-001,
00414                                         -8.00000000000000020e-002 );
00415 }
00416 
00417 /* Auxiliary function: C interface to ztrsyl results check */
00418 /* Return value: 0 - test is passed, non-zero - test is failed */
00419 static int compare_ztrsyl( lapack_complex_double *c, lapack_complex_double *c_i,
00420                            double scale, double scale_i, lapack_int info,
00421                            lapack_int info_i, lapack_int ldc, lapack_int n )
00422 {
00423     lapack_int i;
00424     int failed = 0;
00425     for( i = 0; i < ldc*n; i++ ) {
00426         failed += compare_complex_doubles(c[i],c_i[i]);
00427     }
00428     failed += compare_doubles(scale,scale_i);
00429     failed += (info == info_i) ? 0 : 1;
00430     if( info != 0 || info_i != 0 ) {
00431         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00432     }
00433 
00434     return failed;
00435 }


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