zungqr_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 * zungqr_1 is the test program for the C interface to LAPACK
00036 * routine zungqr
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_zungqr( lapack_int *m, lapack_int *n, lapack_int *k,
00055                                  lapack_int *lda, lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_tau( lapack_int size, lapack_complex_double *tau );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zungqr( lapack_complex_double *a, lapack_complex_double *a_i,
00060                            lapack_int info, lapack_int info_i, lapack_int lda,
00061                            lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     lapack_int m, m_i;
00067     lapack_int n, n_i;
00068     lapack_int k, k_i;
00069     lapack_int lda, lda_i;
00070     lapack_int lda_r;
00071     lapack_int lwork, lwork_i;
00072     lapack_int info, info_i;
00073     lapack_int i;
00074     int failed;
00075 
00076     /* Local arrays */
00077     lapack_complex_double *a = NULL, *a_i = NULL;
00078     lapack_complex_double *tau = NULL, *tau_i = NULL;
00079     lapack_complex_double *work = NULL, *work_i = NULL;
00080     lapack_complex_double *a_save = NULL;
00081     lapack_complex_double *a_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_zungqr( &m, &n, &k, &lda, &lwork );
00085     lda_r = n+2;
00086     m_i = m;
00087     n_i = n;
00088     k_i = k;
00089     lda_i = lda;
00090     lwork_i = lwork;
00091 
00092     /* Allocate memory for the LAPACK routine arrays */
00093     a = (lapack_complex_double *)
00094         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00095     tau = (lapack_complex_double *)
00096         LAPACKE_malloc( k * sizeof(lapack_complex_double) );
00097     work = (lapack_complex_double *)
00098         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     a_i = (lapack_complex_double *)
00102         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00103     tau_i = (lapack_complex_double *)
00104         LAPACKE_malloc( k * sizeof(lapack_complex_double) );
00105     work_i = (lapack_complex_double *)
00106         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00107 
00108     /* Allocate memory for the backup arrays */
00109     a_save = (lapack_complex_double *)
00110         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     a_r = (lapack_complex_double *)
00114         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00115 
00116     /* Initialize input arrays */
00117     init_a( lda*n, a );
00118     init_tau( k, tau );
00119     init_work( lwork, work );
00120 
00121     /* Backup the ouptut arrays */
00122     for( i = 0; i < lda*n; i++ ) {
00123         a_save[i] = a[i];
00124     }
00125 
00126     /* Call the LAPACK routine */
00127     zungqr_( &m, &n, &k, a, &lda, tau, work, &lwork, &info );
00128 
00129     /* Initialize input data, call the column-major middle-level
00130      * interface to LAPACK routine and check the results */
00131     for( i = 0; i < lda*n; i++ ) {
00132         a_i[i] = a_save[i];
00133     }
00134     for( i = 0; i < k; i++ ) {
00135         tau_i[i] = tau[i];
00136     }
00137     for( i = 0; i < lwork; i++ ) {
00138         work_i[i] = work[i];
00139     }
00140     info_i = LAPACKE_zungqr_work( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00141                                   tau_i, work_i, lwork_i );
00142 
00143     failed = compare_zungqr( a, a_i, info, info_i, lda, n );
00144     if( failed == 0 ) {
00145         printf( "PASSED: column-major middle-level interface to zungqr\n" );
00146     } else {
00147         printf( "FAILED: column-major middle-level interface to zungqr\n" );
00148     }
00149 
00150     /* Initialize input data, call the column-major high-level
00151      * interface to LAPACK routine and check the results */
00152     for( i = 0; i < lda*n; i++ ) {
00153         a_i[i] = a_save[i];
00154     }
00155     for( i = 0; i < k; i++ ) {
00156         tau_i[i] = tau[i];
00157     }
00158     for( i = 0; i < lwork; i++ ) {
00159         work_i[i] = work[i];
00160     }
00161     info_i = LAPACKE_zungqr( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00162                              tau_i );
00163 
00164     failed = compare_zungqr( a, a_i, info, info_i, lda, n );
00165     if( failed == 0 ) {
00166         printf( "PASSED: column-major high-level interface to zungqr\n" );
00167     } else {
00168         printf( "FAILED: column-major high-level interface to zungqr\n" );
00169     }
00170 
00171     /* Initialize input data, call the row-major middle-level
00172      * interface to LAPACK routine and check the results */
00173     for( i = 0; i < lda*n; i++ ) {
00174         a_i[i] = a_save[i];
00175     }
00176     for( i = 0; i < k; i++ ) {
00177         tau_i[i] = tau[i];
00178     }
00179     for( i = 0; i < lwork; i++ ) {
00180         work_i[i] = work[i];
00181     }
00182 
00183     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00184     info_i = LAPACKE_zungqr_work( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00185                                   tau_i, work_i, lwork_i );
00186 
00187     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00188 
00189     failed = compare_zungqr( a, a_i, info, info_i, lda, n );
00190     if( failed == 0 ) {
00191         printf( "PASSED: row-major middle-level interface to zungqr\n" );
00192     } else {
00193         printf( "FAILED: row-major middle-level interface to zungqr\n" );
00194     }
00195 
00196     /* Initialize input data, call the row-major high-level
00197      * interface to LAPACK routine and check the results */
00198     for( i = 0; i < lda*n; i++ ) {
00199         a_i[i] = a_save[i];
00200     }
00201     for( i = 0; i < k; i++ ) {
00202         tau_i[i] = tau[i];
00203     }
00204     for( i = 0; i < lwork; i++ ) {
00205         work_i[i] = work[i];
00206     }
00207 
00208     /* Init row_major arrays */
00209     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00210     info_i = LAPACKE_zungqr( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00211                              tau_i );
00212 
00213     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00214 
00215     failed = compare_zungqr( a, a_i, info, info_i, lda, n );
00216     if( failed == 0 ) {
00217         printf( "PASSED: row-major high-level interface to zungqr\n" );
00218     } else {
00219         printf( "FAILED: row-major high-level interface to zungqr\n" );
00220     }
00221 
00222     /* Release memory */
00223     if( a != NULL ) {
00224         LAPACKE_free( a );
00225     }
00226     if( a_i != NULL ) {
00227         LAPACKE_free( a_i );
00228     }
00229     if( a_r != NULL ) {
00230         LAPACKE_free( a_r );
00231     }
00232     if( a_save != NULL ) {
00233         LAPACKE_free( a_save );
00234     }
00235     if( tau != NULL ) {
00236         LAPACKE_free( tau );
00237     }
00238     if( tau_i != NULL ) {
00239         LAPACKE_free( tau_i );
00240     }
00241     if( work != NULL ) {
00242         LAPACKE_free( work );
00243     }
00244     if( work_i != NULL ) {
00245         LAPACKE_free( work_i );
00246     }
00247 
00248     return 0;
00249 }
00250 
00251 /* Auxiliary function: zungqr scalar parameters initialization */
00252 static void init_scalars_zungqr( lapack_int *m, lapack_int *n, lapack_int *k,
00253                                  lapack_int *lda, lapack_int *lwork )
00254 {
00255     *m = 6;
00256     *n = 4;
00257     *k = 4;
00258     *lda = 8;
00259     *lwork = 512;
00260 
00261     return;
00262 }
00263 
00264 /* Auxiliary functions: zungqr array parameters initialization */
00265 static void init_a( lapack_int size, lapack_complex_double *a ) {
00266     lapack_int i;
00267     for( i = 0; i < size; i++ ) {
00268         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00269     }
00270     a[0] = lapack_make_complex_double( -3.08700502105195800e+000,
00271                                        0.00000000000000000e+000 );
00272     a[8] = lapack_make_complex_double( -4.88499367417976620e-001,
00273                                        -1.14168910512461390e+000 );
00274     a[16] = lapack_make_complex_double( 3.77356043173210700e-001,
00275                                         -1.24372975548049110e+000 );
00276     a[24] = lapack_make_complex_double( -8.55165437696762120e-001,
00277                                         -7.07319873181135650e-001 );
00278     a[1] = lapack_make_complex_double( -3.26978431123342020e-001,
00279                                        4.23806608064021150e-001 );
00280     a[9] = lapack_make_complex_double( 1.51631604729093160e+000,
00281                                        0.00000000000000000e+000 );
00282     a[17] = lapack_make_complex_double( 1.37305509662697790e+000,
00283                                         -8.17629335421158570e-001 );
00284     a[25] = lapack_make_complex_double( -2.50862720262847670e-001,
00285                                         8.20348604045144430e-001 );
00286     a[2] = lapack_make_complex_double( 1.69172476430465120e-001,
00287                                        -7.98047673307239890e-002 );
00288     a[10] = lapack_make_complex_double( -4.53710486149829670e-001,
00289                                         -6.49149959135295050e-003 );
00290     a[18] = lapack_make_complex_double( -2.17134536255717010e+000,
00291                                         0.00000000000000000e+000 );
00292     a[26] = lapack_make_complex_double( -2.27267620328359900e-001,
00293                                         -2.95731405907064150e-001 );
00294     a[3] = lapack_make_complex_double( -1.05973629513027950e-001,
00295                                        7.26861860966964010e-002 );
00296     a[11] = lapack_make_complex_double( -2.73407174139646880e-001,
00297                                         9.78078838704348470e-002 );
00298     a[19] = lapack_make_complex_double( -2.91822737804995960e-001,
00299                                         4.88808144155306160e-001 );
00300     a[27] = lapack_make_complex_double( -2.35337610655542080e+000,
00301                                         0.00000000000000000e+000 );
00302     a[4] = lapack_make_complex_double( 1.72939632545932170e-001,
00303                                        1.60632640429298590e-001 );
00304     a[12] = lapack_make_complex_double( -3.23630471463261900e-001,
00305                                         1.23000700219973860e-001 );
00306     a[20] = lapack_make_complex_double( 2.72768506164479230e-001,
00307                                         4.69769330690376700e-002 );
00308     a[28] = lapack_make_complex_double( 7.05422688603155710e-001,
00309                                         2.51508056610988850e-001 );
00310     a[5] = lapack_make_complex_double( 2.69899674468747240e-001,
00311                                        -1.51670836485297000e-002 );
00312     a[13] = lapack_make_complex_double( -1.64593543935458470e-001,
00313                                         3.38900720348261240e-001 );
00314     a[21] = lapack_make_complex_double( 5.34839525361778920e-001,
00315                                         3.98829067784022160e-001 );
00316     a[29] = lapack_make_complex_double( 2.70306990523076050e-001,
00317                                         -7.26878326406570770e-002 );
00318 }
00319 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00320     lapack_int i;
00321     for( i = 0; i < size; i++ ) {
00322         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00323     }
00324     tau[0] = lapack_make_complex_double( 1.31098102965600650e+000,
00325                                          -2.62390243772255500e-001 );
00326     tau[1] = lapack_make_complex_double( 1.10510398911057410e+000,
00327                                          -4.50362538745018080e-001 );
00328     tau[2] = lapack_make_complex_double( 1.04025187161551910e+000,
00329                                          2.12175810726109660e-001 );
00330     tau[3] = lapack_make_complex_double( 1.18595901116610980e+000,
00331                                          2.01183600330743640e-001 );
00332 }
00333 static void init_work( lapack_int size, lapack_complex_double *work ) {
00334     lapack_int i;
00335     for( i = 0; i < size; i++ ) {
00336         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00337     }
00338 }
00339 
00340 /* Auxiliary function: C interface to zungqr results check */
00341 /* Return value: 0 - test is passed, non-zero - test is failed */
00342 static int compare_zungqr( lapack_complex_double *a, lapack_complex_double *a_i,
00343                            lapack_int info, lapack_int info_i, lapack_int lda,
00344                            lapack_int n )
00345 {
00346     lapack_int i;
00347     int failed = 0;
00348     for( i = 0; i < lda*n; i++ ) {
00349         failed += compare_complex_doubles(a[i],a_i[i]);
00350     }
00351     failed += (info == info_i) ? 0 : 1;
00352     if( info != 0 || info_i != 0 ) {
00353         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00354     }
00355 
00356     return failed;
00357 }


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