dormqr_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 * dormqr_1 is the test program for the C interface to LAPACK
00036 * routine dormqr
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_dormqr( 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, double *a );
00058 static void init_tau( lapack_int size, double *tau );
00059 static void init_c( lapack_int size, double *c );
00060 static void init_work( lapack_int size, double *work );
00061 static int compare_dormqr( double *c, double *c_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 side, side_i;
00068     char trans, trans_i;
00069     lapack_int m, m_i;
00070     lapack_int n, n_i;
00071     lapack_int k, k_i;
00072     lapack_int lda, lda_i;
00073     lapack_int lda_r;
00074     lapack_int ldc, ldc_i;
00075     lapack_int ldc_r;
00076     lapack_int lwork, lwork_i;
00077     lapack_int info, info_i;
00078     /* Declare scalars */
00079     lapack_int r;
00080     lapack_int i;
00081     int failed;
00082 
00083     /* Local arrays */
00084     double *a = NULL, *a_i = NULL;
00085     double *tau = NULL, *tau_i = NULL;
00086     double *c = NULL, *c_i = NULL;
00087     double *work = NULL, *work_i = NULL;
00088     double *c_save = NULL;
00089     double *a_r = NULL;
00090     double *c_r = NULL;
00091 
00092     /* Iniitialize the scalar parameters */
00093     init_scalars_dormqr( &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00094     r = LAPACKE_lsame( side, 'l' ) ? m : n;
00095     lda_r = k+2;
00096     ldc_r = n+2;
00097     side_i = side;
00098     trans_i = trans;
00099     m_i = m;
00100     n_i = n;
00101     k_i = k;
00102     lda_i = lda;
00103     ldc_i = ldc;
00104     lwork_i = lwork;
00105 
00106     /* Allocate memory for the LAPACK routine arrays */
00107     a = (double *)LAPACKE_malloc( lda*k * sizeof(double) );
00108     tau = (double *)LAPACKE_malloc( k * sizeof(double) );
00109     c = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00110     work = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00111 
00112     /* Allocate memory for the C interface function arrays */
00113     a_i = (double *)LAPACKE_malloc( lda*k * sizeof(double) );
00114     tau_i = (double *)LAPACKE_malloc( k * sizeof(double) );
00115     c_i = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00116     work_i = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00117 
00118     /* Allocate memory for the backup arrays */
00119     c_save = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00120 
00121     /* Allocate memory for the row-major arrays */
00122     a_r = (double *)LAPACKE_malloc( r*(k+2) * sizeof(double) );
00123     c_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00124 
00125     /* Initialize input arrays */
00126     init_a( lda*k, a );
00127     init_tau( k, tau );
00128     init_c( ldc*n, c );
00129     init_work( lwork, work );
00130 
00131     /* Backup the ouptut arrays */
00132     for( i = 0; i < ldc*n; i++ ) {
00133         c_save[i] = c[i];
00134     }
00135 
00136     /* Call the LAPACK routine */
00137     dormqr_( &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work, &lwork,
00138              &info );
00139 
00140     /* Initialize input data, call the column-major middle-level
00141      * interface to LAPACK routine and check the results */
00142     for( i = 0; i < lda*k; i++ ) {
00143         a_i[i] = a[i];
00144     }
00145     for( i = 0; i < k; i++ ) {
00146         tau_i[i] = tau[i];
00147     }
00148     for( i = 0; i < ldc*n; i++ ) {
00149         c_i[i] = c_save[i];
00150     }
00151     for( i = 0; i < lwork; i++ ) {
00152         work_i[i] = work[i];
00153     }
00154     info_i = LAPACKE_dormqr_work( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i,
00155                                   k_i, a_i, lda_i, tau_i, c_i, ldc_i, work_i,
00156                                   lwork_i );
00157 
00158     failed = compare_dormqr( c, c_i, info, info_i, ldc, n );
00159     if( failed == 0 ) {
00160         printf( "PASSED: column-major middle-level interface to dormqr\n" );
00161     } else {
00162         printf( "FAILED: column-major middle-level interface to dormqr\n" );
00163     }
00164 
00165     /* Initialize input data, call the column-major high-level
00166      * interface to LAPACK routine and check the results */
00167     for( i = 0; i < lda*k; i++ ) {
00168         a_i[i] = a[i];
00169     }
00170     for( i = 0; i < k; i++ ) {
00171         tau_i[i] = tau[i];
00172     }
00173     for( i = 0; i < ldc*n; i++ ) {
00174         c_i[i] = c_save[i];
00175     }
00176     for( i = 0; i < lwork; i++ ) {
00177         work_i[i] = work[i];
00178     }
00179     info_i = LAPACKE_dormqr( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00180                              a_i, lda_i, tau_i, c_i, ldc_i );
00181 
00182     failed = compare_dormqr( c, c_i, info, info_i, ldc, n );
00183     if( failed == 0 ) {
00184         printf( "PASSED: column-major high-level interface to dormqr\n" );
00185     } else {
00186         printf( "FAILED: column-major high-level interface to dormqr\n" );
00187     }
00188 
00189     /* Initialize input data, call the row-major middle-level
00190      * interface to LAPACK routine and check the results */
00191     for( i = 0; i < lda*k; i++ ) {
00192         a_i[i] = a[i];
00193     }
00194     for( i = 0; i < k; i++ ) {
00195         tau_i[i] = tau[i];
00196     }
00197     for( i = 0; i < ldc*n; i++ ) {
00198         c_i[i] = c_save[i];
00199     }
00200     for( i = 0; i < lwork; i++ ) {
00201         work_i[i] = work[i];
00202     }
00203 
00204     LAPACKE_dge_trans( LAPACK_COL_MAJOR, r, k, a_i, lda, a_r, k+2 );
00205     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00206     info_i = LAPACKE_dormqr_work( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i,
00207                                   k_i, a_r, lda_r, tau_i, c_r, ldc_r, work_i,
00208                                   lwork_i );
00209 
00210     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00211 
00212     failed = compare_dormqr( c, c_i, info, info_i, ldc, n );
00213     if( failed == 0 ) {
00214         printf( "PASSED: row-major middle-level interface to dormqr\n" );
00215     } else {
00216         printf( "FAILED: row-major middle-level interface to dormqr\n" );
00217     }
00218 
00219     /* Initialize input data, call the row-major high-level
00220      * interface to LAPACK routine and check the results */
00221     for( i = 0; i < lda*k; i++ ) {
00222         a_i[i] = a[i];
00223     }
00224     for( i = 0; i < k; i++ ) {
00225         tau_i[i] = tau[i];
00226     }
00227     for( i = 0; i < ldc*n; i++ ) {
00228         c_i[i] = c_save[i];
00229     }
00230     for( i = 0; i < lwork; i++ ) {
00231         work_i[i] = work[i];
00232     }
00233 
00234     /* Init row_major arrays */
00235     LAPACKE_dge_trans( LAPACK_COL_MAJOR, r, k, a_i, lda, a_r, k+2 );
00236     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00237     info_i = LAPACKE_dormqr( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00238                              a_r, lda_r, tau_i, c_r, ldc_r );
00239 
00240     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00241 
00242     failed = compare_dormqr( c, c_i, info, info_i, ldc, n );
00243     if( failed == 0 ) {
00244         printf( "PASSED: row-major high-level interface to dormqr\n" );
00245     } else {
00246         printf( "FAILED: row-major high-level interface to dormqr\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( tau != NULL ) {
00260         LAPACKE_free( tau );
00261     }
00262     if( tau_i != NULL ) {
00263         LAPACKE_free( tau_i );
00264     }
00265     if( c != NULL ) {
00266         LAPACKE_free( c );
00267     }
00268     if( c_i != NULL ) {
00269         LAPACKE_free( c_i );
00270     }
00271     if( c_r != NULL ) {
00272         LAPACKE_free( c_r );
00273     }
00274     if( c_save != NULL ) {
00275         LAPACKE_free( c_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: dormqr scalar parameters initialization */
00288 static void init_scalars_dormqr( char *side, char *trans, lapack_int *m,
00289                                  lapack_int *n, lapack_int *k, lapack_int *lda,
00290                                  lapack_int *ldc, lapack_int *lwork )
00291 {
00292     *side = 'L';
00293     *trans = 'T';
00294     *m = 6;
00295     *n = 2;
00296     *k = 5;
00297     *lda = 8;
00298     *ldc = 8;
00299     *lwork = 512;
00300 
00301     return;
00302 }
00303 
00304 /* Auxiliary functions: dormqr array parameters initialization */
00305 static void init_a( lapack_int size, double *a ) {
00306     lapack_int i;
00307     for( i = 0; i < size; i++ ) {
00308         a[i] = 0;
00309     }
00310     a[0] = 2.89044979198739950e+000;  /* a[0,0] */
00311     a[8] = 5.16182638472380990e-001;  /* a[0,1] */
00312     a[16] = -1.71983613546250200e+000;  /* a[0,2] */
00313     a[24] = 2.02390645781731050e-001;  /* a[0,3] */
00314     a[32] = -1.50263810568169690e+000;  /* a[0,4] */
00315     a[1] = 5.23410930858115080e-001;  /* a[1,0] */
00316     a[9] = -2.70840460118862050e+000;  /* a[1,1] */
00317     a[17] = -3.64771775129019820e-001;  /* a[1,2] */
00318     a[25] = -8.72578130883918110e-002;  /* a[1,3] */
00319     a[33] = 1.14752585214783200e+000;  /* a[1,4] */
00320     a[2] = 4.96569344660262980e-001;  /* a[2,0] */
00321     a[10] = -4.77807447011384670e-001;  /* a[2,1] */
00322     a[18] = 2.25233328333677820e+000;  /* a[2,2] */
00323     a[26] = 8.39728992469042530e-001;  /* a[2,3] */
00324     a[34] = -5.95216999148401320e-003;  /* a[2,4] */
00325     a[3] = 3.65716611945734290e-001;  /* a[3,0] */
00326     a[11] = -5.52004275578922950e-001;  /* a[3,1] */
00327     a[19] = -3.30617676999934770e-001;  /* a[3,2] */
00328     a[27] = -1.00860265702704340e+000;  /* a[3,3] */
00329     a[35] = 7.11629393779033890e-001;  /* a[3,4] */
00330     a[4] = -2.68415861978520550e-002;  /* a[4,0] */
00331     a[12] = 6.25855874605071420e-001;  /* a[4,1] */
00332     a[20] = -1.97275173915996900e-002;  /* a[4,2] */
00333     a[28] = 1.93418400495411730e-001;  /* a[4,3] */
00334     a[36] = -3.36445950941304230e-003;  /* a[4,4] */
00335     a[5] = 5.33476525682309630e-001;  /* a[5,0] */
00336     a[13] = -2.58811088544481960e-002;  /* a[5,1] */
00337     a[21] = 8.65080478099006060e-003;  /* a[5,2] */
00338     a[29] = -3.96117737057897270e-001;  /* a[5,3] */
00339     a[37] = -6.35195600985372090e-001;  /* a[5,4] */
00340 }
00341 static void init_tau( lapack_int size, double *tau ) {
00342     lapack_int i;
00343     for( i = 0; i < size; i++ ) {
00344         tau[i] = 0;
00345     }
00346     tau[0] = 1.03113702242795860e+000;
00347     tau[1] = 1.03875917742961610e+000;
00348     tau[2] = 1.80217188070268990e+000;
00349     tau[3] = 1.67459315904558000e+000;
00350     tau[4] = 1.42503586216506740e+000;
00351 }
00352 static void init_c( lapack_int size, double *c ) {
00353     lapack_int i;
00354     for( i = 0; i < size; i++ ) {
00355         c[i] = 0;
00356     }
00357     c[0] = -1.00000000000000000e-002;  /* c[0,0] */
00358     c[8] = -4.00000000000000010e-002;  /* c[0,1] */
00359     c[1] = 4.00000000000000010e-002;  /* c[1,0] */
00360     c[9] = -2.99999999999999990e-002;  /* c[1,1] */
00361     c[2] = 5.00000000000000030e-002;  /* c[2,0] */
00362     c[10] = 1.00000000000000000e-002;  /* c[2,1] */
00363     c[3] = -2.99999999999999990e-002;  /* c[3,0] */
00364     c[11] = -2.00000000000000000e-002;  /* c[3,1] */
00365     c[4] = 2.00000000000000000e-002;  /* c[4,0] */
00366     c[12] = 5.00000000000000030e-002;  /* c[4,1] */
00367     c[5] = -5.99999999999999980e-002;  /* c[5,0] */
00368     c[13] = 7.00000000000000070e-002;  /* c[5,1] */
00369 }
00370 static void init_work( lapack_int size, double *work ) {
00371     lapack_int i;
00372     for( i = 0; i < size; i++ ) {
00373         work[i] = 0;
00374     }
00375 }
00376 
00377 /* Auxiliary function: C interface to dormqr results check */
00378 /* Return value: 0 - test is passed, non-zero - test is failed */
00379 static int compare_dormqr( double *c, double *c_i, lapack_int info,
00380                            lapack_int info_i, lapack_int ldc, lapack_int n )
00381 {
00382     lapack_int i;
00383     int failed = 0;
00384     for( i = 0; i < ldc*n; i++ ) {
00385         failed += compare_doubles(c[i],c_i[i]);
00386     }
00387     failed += (info == info_i) ? 0 : 1;
00388     if( info != 0 || info_i != 0 ) {
00389         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00390     }
00391 
00392     return failed;
00393 }


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