zunmlq_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 * zunmlq_1 is the test program for the C interface to LAPACK
00036 * routine zunmlq
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_zunmlq( char *side, char *trans, lapack_int *m,
00055                                  lapack_int *n, lapack_int *k, lapack_int *lda,
00056                                  lapack_int *ldc, lapack_int *lwork );
00057 static void init_a( lapack_int size, lapack_complex_double *a );
00058 static void init_tau( lapack_int size, lapack_complex_double *tau );
00059 static void init_c( lapack_int size, lapack_complex_double *c );
00060 static void init_work( lapack_int size, lapack_complex_double *work );
00061 static int compare_zunmlq( lapack_complex_double *c, lapack_complex_double *c_i,
00062                            lapack_int info, lapack_int info_i, lapack_int ldc,
00063                            lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     char side, side_i;
00069     char trans, trans_i;
00070     lapack_int m, m_i;
00071     lapack_int n, n_i;
00072     lapack_int k, k_i;
00073     lapack_int lda, lda_i;
00074     lapack_int lda_r;
00075     lapack_int ldc, ldc_i;
00076     lapack_int ldc_r;
00077     lapack_int lwork, lwork_i;
00078     lapack_int info, info_i;
00079     lapack_int i;
00080     int failed;
00081 
00082     /* Local arrays */
00083     lapack_complex_double *a = NULL, *a_i = NULL;
00084     lapack_complex_double *tau = NULL, *tau_i = NULL;
00085     lapack_complex_double *c = NULL, *c_i = NULL;
00086     lapack_complex_double *work = NULL, *work_i = NULL;
00087     lapack_complex_double *c_save = NULL;
00088     lapack_complex_double *a_r = NULL;
00089     lapack_complex_double *c_r = NULL;
00090 
00091     /* Iniitialize the scalar parameters */
00092     init_scalars_zunmlq( &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00093     lda_r = m+2;
00094     ldc_r = n+2;
00095     side_i = side;
00096     trans_i = trans;
00097     m_i = m;
00098     n_i = n;
00099     k_i = k;
00100     lda_i = lda;
00101     ldc_i = ldc;
00102     lwork_i = lwork;
00103 
00104     /* Allocate memory for the LAPACK routine arrays */
00105     a = (lapack_complex_double *)
00106         LAPACKE_malloc( lda*m * sizeof(lapack_complex_double) );
00107     tau = (lapack_complex_double *)
00108         LAPACKE_malloc( k * sizeof(lapack_complex_double) );
00109     c = (lapack_complex_double *)
00110         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00111     work = (lapack_complex_double *)
00112         LAPACKE_malloc( lwork * 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     tau_i = (lapack_complex_double *)
00118         LAPACKE_malloc( k * sizeof(lapack_complex_double) );
00119     c_i = (lapack_complex_double *)
00120         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00121     work_i = (lapack_complex_double *)
00122         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00123 
00124     /* Allocate memory for the backup arrays */
00125     c_save = (lapack_complex_double *)
00126         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00127 
00128     /* Allocate memory for the row-major arrays */
00129     a_r = (lapack_complex_double *)
00130         LAPACKE_malloc( k*(m+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_tau( k, tau );
00137     init_c( ldc*n, c );
00138     init_work( lwork, work );
00139 
00140     /* Backup the ouptut arrays */
00141     for( i = 0; i < ldc*n; i++ ) {
00142         c_save[i] = c[i];
00143     }
00144 
00145     /* Call the LAPACK routine */
00146     zunmlq_( &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work, &lwork,
00147              &info );
00148 
00149     /* Initialize input data, call the column-major middle-level
00150      * interface to LAPACK routine and check the results */
00151     for( i = 0; i < lda*m; i++ ) {
00152         a_i[i] = a[i];
00153     }
00154     for( i = 0; i < k; i++ ) {
00155         tau_i[i] = tau[i];
00156     }
00157     for( i = 0; i < ldc*n; i++ ) {
00158         c_i[i] = c_save[i];
00159     }
00160     for( i = 0; i < lwork; i++ ) {
00161         work_i[i] = work[i];
00162     }
00163     info_i = LAPACKE_zunmlq_work( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i,
00164                                   k_i, a_i, lda_i, tau_i, c_i, ldc_i, work_i,
00165                                   lwork_i );
00166 
00167     failed = compare_zunmlq( c, c_i, info, info_i, ldc, n );
00168     if( failed == 0 ) {
00169         printf( "PASSED: column-major middle-level interface to zunmlq\n" );
00170     } else {
00171         printf( "FAILED: column-major middle-level interface to zunmlq\n" );
00172     }
00173 
00174     /* Initialize input data, call the column-major high-level
00175      * interface to LAPACK routine and check the results */
00176     for( i = 0; i < lda*m; i++ ) {
00177         a_i[i] = a[i];
00178     }
00179     for( i = 0; i < k; i++ ) {
00180         tau_i[i] = tau[i];
00181     }
00182     for( i = 0; i < ldc*n; i++ ) {
00183         c_i[i] = c_save[i];
00184     }
00185     for( i = 0; i < lwork; i++ ) {
00186         work_i[i] = work[i];
00187     }
00188     info_i = LAPACKE_zunmlq( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00189                              a_i, lda_i, tau_i, c_i, ldc_i );
00190 
00191     failed = compare_zunmlq( c, c_i, info, info_i, ldc, n );
00192     if( failed == 0 ) {
00193         printf( "PASSED: column-major high-level interface to zunmlq\n" );
00194     } else {
00195         printf( "FAILED: column-major high-level interface to zunmlq\n" );
00196     }
00197 
00198     /* Initialize input data, call the row-major middle-level
00199      * interface to LAPACK routine and check the results */
00200     for( i = 0; i < lda*m; i++ ) {
00201         a_i[i] = a[i];
00202     }
00203     for( i = 0; i < k; i++ ) {
00204         tau_i[i] = tau[i];
00205     }
00206     for( i = 0; i < ldc*n; i++ ) {
00207         c_i[i] = c_save[i];
00208     }
00209     for( i = 0; i < lwork; i++ ) {
00210         work_i[i] = work[i];
00211     }
00212 
00213     LAPACKE_zge_trans( LAPACK_COL_MAJOR, k, m, a_i, lda, a_r, m+2 );
00214     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00215     info_i = LAPACKE_zunmlq_work( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i,
00216                                   k_i, a_r, lda_r, tau_i, c_r, ldc_r, work_i,
00217                                   lwork_i );
00218 
00219     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00220 
00221     failed = compare_zunmlq( c, c_i, info, info_i, ldc, n );
00222     if( failed == 0 ) {
00223         printf( "PASSED: row-major middle-level interface to zunmlq\n" );
00224     } else {
00225         printf( "FAILED: row-major middle-level interface to zunmlq\n" );
00226     }
00227 
00228     /* Initialize input data, call the row-major high-level
00229      * interface to LAPACK routine and check the results */
00230     for( i = 0; i < lda*m; i++ ) {
00231         a_i[i] = a[i];
00232     }
00233     for( i = 0; i < k; i++ ) {
00234         tau_i[i] = tau[i];
00235     }
00236     for( i = 0; i < ldc*n; i++ ) {
00237         c_i[i] = c_save[i];
00238     }
00239     for( i = 0; i < lwork; i++ ) {
00240         work_i[i] = work[i];
00241     }
00242 
00243     /* Init row_major arrays */
00244     LAPACKE_zge_trans( LAPACK_COL_MAJOR, k, m, a_i, lda, a_r, m+2 );
00245     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00246     info_i = LAPACKE_zunmlq( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00247                              a_r, lda_r, tau_i, c_r, ldc_r );
00248 
00249     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00250 
00251     failed = compare_zunmlq( c, c_i, info, info_i, ldc, n );
00252     if( failed == 0 ) {
00253         printf( "PASSED: row-major high-level interface to zunmlq\n" );
00254     } else {
00255         printf( "FAILED: row-major high-level interface to zunmlq\n" );
00256     }
00257 
00258     /* Release memory */
00259     if( a != NULL ) {
00260         LAPACKE_free( a );
00261     }
00262     if( a_i != NULL ) {
00263         LAPACKE_free( a_i );
00264     }
00265     if( a_r != NULL ) {
00266         LAPACKE_free( a_r );
00267     }
00268     if( tau != NULL ) {
00269         LAPACKE_free( tau );
00270     }
00271     if( tau_i != NULL ) {
00272         LAPACKE_free( tau_i );
00273     }
00274     if( c != NULL ) {
00275         LAPACKE_free( c );
00276     }
00277     if( c_i != NULL ) {
00278         LAPACKE_free( c_i );
00279     }
00280     if( c_r != NULL ) {
00281         LAPACKE_free( c_r );
00282     }
00283     if( c_save != NULL ) {
00284         LAPACKE_free( c_save );
00285     }
00286     if( work != NULL ) {
00287         LAPACKE_free( work );
00288     }
00289     if( work_i != NULL ) {
00290         LAPACKE_free( work_i );
00291     }
00292 
00293     return 0;
00294 }
00295 
00296 /* Auxiliary function: zunmlq scalar parameters initialization */
00297 static void init_scalars_zunmlq( char *side, char *trans, lapack_int *m,
00298                                  lapack_int *n, lapack_int *k, lapack_int *lda,
00299                                  lapack_int *ldc, lapack_int *lwork )
00300 {
00301     *side = 'L';
00302     *trans = 'C';
00303     *m = 4;
00304     *n = 2;
00305     *k = 3;
00306     *lda = 8;
00307     *ldc = 8;
00308     *lwork = 512;
00309 
00310     return;
00311 }
00312 
00313 /* Auxiliary functions: zunmlq array parameters initialization */
00314 static void init_a( lapack_int size, lapack_complex_double *a ) {
00315     lapack_int i;
00316     for( i = 0; i < size; i++ ) {
00317         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00318     }
00319     a[0] = lapack_make_complex_double( -2.22551117723546850e+000,
00320                                        0.00000000000000000e+000 );
00321     a[8] = lapack_make_complex_double( 2.43844259461276080e-001,
00322                                        -3.08206993291480160e-001 );
00323     a[16] = lapack_make_complex_double( -2.74136498519149120e-001,
00324                                         -2.30966496866882000e-001 );
00325     a[24] = lapack_make_complex_double( 5.80770951470128920e-001,
00326                                         3.46866360216428750e-001 );
00327     a[1] = lapack_make_complex_double( 8.20755257796100150e-001,
00328                                        1.23845704671937580e+000 );
00329     a[9] = lapack_make_complex_double( 1.68810098934606920e+000,
00330                                        0.00000000000000000e+000 );
00331     a[17] = lapack_make_complex_double( -1.93641525844946090e-001,
00332                                         5.42951785523693940e-001 );
00333     a[25] = lapack_make_complex_double( 2.78908485124207680e-001,
00334                                         -2.20317579745833100e-001 );
00335     a[2] = lapack_make_complex_double( 1.03347043300727750e-003,
00336                                        -6.82225286276042620e-001 );
00337     a[10] = lapack_make_complex_double( 7.74751330164005660e-001,
00338                                         -6.15472715853114580e-001 );
00339     a[18] = lapack_make_complex_double( -1.59025825045931810e+000,
00340                                         0.00000000000000000e+000 );
00341     a[26] = lapack_make_complex_double( -1.26766851611322510e-001,
00342                                         1.10984520235717200e-001 );
00343 }
00344 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00345     lapack_int i;
00346     for( i = 0; i < size; i++ ) {
00347         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00348     }
00349     tau[0] = lapack_make_complex_double( 1.12581379184436000e+000,
00350                                          1.61760589514177240e-001 );
00351     tau[1] = lapack_make_complex_double( 1.09905366916895430e+000,
00352                                          5.46859059846678370e-001 );
00353     tau[2] = lapack_make_complex_double( 1.13292565731157910e+000,
00354                                          -9.59054047896148680e-001 );
00355 }
00356 static void init_c( lapack_int size, lapack_complex_double *c ) {
00357     lapack_int i;
00358     for( i = 0; i < size; i++ ) {
00359         c[i] = lapack_make_complex_double( 0.0, 0.0 );
00360     }
00361     c[0] = lapack_make_complex_double( 6.06602210678164670e-001,
00362                                        -8.53736444658157730e-002 );
00363     c[8] = lapack_make_complex_double( -2.17028790931521120e+000,
00364                                        1.19972437223014780e+000 );
00365     c[1] = lapack_make_complex_double( 5.21674740443920190e+000,
00366                                        -2.51239703167304330e+000 );
00367     c[9] = lapack_make_complex_double( -2.37717868179399620e+000,
00368                                        2.98745649704337610e+000 );
00369     c[2] = lapack_make_complex_double( 6.29316213882646650e+000,
00370                                        -7.86109817665201850e+000 );
00371     c[10] = lapack_make_complex_double( 1.21499129356356890e-001,
00372                                         4.58724036761384900e-001 );
00373     c[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00374                                        0.00000000000000000e+000 );
00375     c[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00376                                         0.00000000000000000e+000 );
00377 }
00378 static void init_work( lapack_int size, lapack_complex_double *work ) {
00379     lapack_int i;
00380     for( i = 0; i < size; i++ ) {
00381         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00382     }
00383 }
00384 
00385 /* Auxiliary function: C interface to zunmlq results check */
00386 /* Return value: 0 - test is passed, non-zero - test is failed */
00387 static int compare_zunmlq( lapack_complex_double *c, lapack_complex_double *c_i,
00388                            lapack_int info, lapack_int info_i, lapack_int ldc,
00389                            lapack_int n )
00390 {
00391     lapack_int i;
00392     int failed = 0;
00393     for( i = 0; i < ldc*n; i++ ) {
00394         failed += compare_complex_doubles(c[i],c_i[i]);
00395     }
00396     failed += (info == info_i) ? 0 : 1;
00397     if( info != 0 || info_i != 0 ) {
00398         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00399     }
00400 
00401     return failed;
00402 }


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