cungqr_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 * cungqr_1 is the test program for the C interface to LAPACK
00036 * routine cungqr
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_cungqr( 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_float *a );
00057 static void init_tau( lapack_int size, lapack_complex_float *tau );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_cungqr( lapack_complex_float *a, lapack_complex_float *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_float *a = NULL, *a_i = NULL;
00078     lapack_complex_float *tau = NULL, *tau_i = NULL;
00079     lapack_complex_float *work = NULL, *work_i = NULL;
00080     lapack_complex_float *a_save = NULL;
00081     lapack_complex_float *a_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_cungqr( &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_float *)
00094         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00095     tau = (lapack_complex_float *)
00096         LAPACKE_malloc( k * sizeof(lapack_complex_float) );
00097     work = (lapack_complex_float *)
00098         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     a_i = (lapack_complex_float *)
00102         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00103     tau_i = (lapack_complex_float *)
00104         LAPACKE_malloc( k * sizeof(lapack_complex_float) );
00105     work_i = (lapack_complex_float *)
00106         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00107 
00108     /* Allocate memory for the backup arrays */
00109     a_save = (lapack_complex_float *)
00110         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     a_r = (lapack_complex_float *)
00114         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
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     cungqr_( &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_cungqr_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_cungqr( a, a_i, info, info_i, lda, n );
00144     if( failed == 0 ) {
00145         printf( "PASSED: column-major middle-level interface to cungqr\n" );
00146     } else {
00147         printf( "FAILED: column-major middle-level interface to cungqr\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_cungqr( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00162                              tau_i );
00163 
00164     failed = compare_cungqr( a, a_i, info, info_i, lda, n );
00165     if( failed == 0 ) {
00166         printf( "PASSED: column-major high-level interface to cungqr\n" );
00167     } else {
00168         printf( "FAILED: column-major high-level interface to cungqr\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00184     info_i = LAPACKE_cungqr_work( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00185                                   tau_i, work_i, lwork_i );
00186 
00187     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00188 
00189     failed = compare_cungqr( a, a_i, info, info_i, lda, n );
00190     if( failed == 0 ) {
00191         printf( "PASSED: row-major middle-level interface to cungqr\n" );
00192     } else {
00193         printf( "FAILED: row-major middle-level interface to cungqr\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00210     info_i = LAPACKE_cungqr( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00211                              tau_i );
00212 
00213     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00214 
00215     failed = compare_cungqr( a, a_i, info, info_i, lda, n );
00216     if( failed == 0 ) {
00217         printf( "PASSED: row-major high-level interface to cungqr\n" );
00218     } else {
00219         printf( "FAILED: row-major high-level interface to cungqr\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: cungqr scalar parameters initialization */
00252 static void init_scalars_cungqr( 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: cungqr array parameters initialization */
00265 static void init_a( lapack_int size, lapack_complex_float *a ) {
00266     lapack_int i;
00267     for( i = 0; i < size; i++ ) {
00268         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00269     }
00270     a[0] = lapack_make_complex_float( -3.087005138e+000, 0.000000000e+000 );
00271     a[8] = lapack_make_complex_float( -4.884994030e-001, -1.141689062e+000 );
00272     a[16] = lapack_make_complex_float( 3.773559928e-001, -1.243729830e+000 );
00273     a[24] = lapack_make_complex_float( -8.551653028e-001, -7.073198557e-001 );
00274     a[1] = lapack_make_complex_float( -3.269784153e-001, 4.238066077e-001 );
00275     a[9] = lapack_make_complex_float( 1.516316056e+000, 0.000000000e+000 );
00276     a[17] = lapack_make_complex_float( 1.373054981e+000, -8.176293373e-001 );
00277     a[25] = lapack_make_complex_float( -2.508625686e-001, 8.203486204e-001 );
00278     a[2] = lapack_make_complex_float( 1.691724658e-001, -7.980476320e-002 );
00279     a[10] = lapack_make_complex_float( -4.537104368e-001, -6.491497159e-003 );
00280     a[18] = lapack_make_complex_float( -2.171345234e+000, 0.000000000e+000 );
00281     a[26] = lapack_make_complex_float( -2.272676229e-001, -2.957314849e-001 );
00282     a[3] = lapack_make_complex_float( -1.059736237e-001, 7.268618047e-002 );
00283     a[11] = lapack_make_complex_float( -2.734071612e-001, 9.780790657e-002 );
00284     a[19] = lapack_make_complex_float( -2.918227613e-001, 4.888080955e-001 );
00285     a[27] = lapack_make_complex_float( -2.353376150e+000, 0.000000000e+000 );
00286     a[4] = lapack_make_complex_float( 1.729396135e-001, 1.606326252e-001 );
00287     a[12] = lapack_make_complex_float( -3.236304522e-001, 1.230006963e-001 );
00288     a[20] = lapack_make_complex_float( 2.727684677e-001, 4.697696120e-002 );
00289     a[28] = lapack_make_complex_float( 7.054226995e-001, 2.515080869e-001 );
00290     a[5] = lapack_make_complex_float( 2.698996663e-001, -1.516707987e-002 );
00291     a[13] = lapack_make_complex_float( -1.645935327e-001, 3.389006853e-001 );
00292     a[21] = lapack_make_complex_float( 5.348393917e-001, 3.988290727e-001 );
00293     a[29] = lapack_make_complex_float( 2.703070045e-001, -7.268778235e-002 );
00294 }
00295 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00296     lapack_int i;
00297     for( i = 0; i < size; i++ ) {
00298         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00299     }
00300     tau[0] = lapack_make_complex_float( 1.310981035e+000, -2.623902261e-001 );
00301     tau[1] = lapack_make_complex_float( 1.105103970e+000, -4.503625035e-001 );
00302     tau[2] = lapack_make_complex_float( 1.040251970e+000, 2.121757567e-001 );
00303     tau[3] = lapack_make_complex_float( 1.185958982e+000, 2.011836171e-001 );
00304 }
00305 static void init_work( lapack_int size, lapack_complex_float *work ) {
00306     lapack_int i;
00307     for( i = 0; i < size; i++ ) {
00308         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00309     }
00310 }
00311 
00312 /* Auxiliary function: C interface to cungqr results check */
00313 /* Return value: 0 - test is passed, non-zero - test is failed */
00314 static int compare_cungqr( lapack_complex_float *a, lapack_complex_float *a_i,
00315                            lapack_int info, lapack_int info_i, lapack_int lda,
00316                            lapack_int n )
00317 {
00318     lapack_int i;
00319     int failed = 0;
00320     for( i = 0; i < lda*n; i++ ) {
00321         failed += compare_complex_floats(a[i],a_i[i]);
00322     }
00323     failed += (info == info_i) ? 0 : 1;
00324     if( info != 0 || info_i != 0 ) {
00325         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00326     }
00327 
00328     return failed;
00329 }


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