zgeqrf_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 * zgeqrf_1 is the test program for the C interface to LAPACK
00036 * routine zgeqrf
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_zgeqrf( lapack_int *m, lapack_int *n, lapack_int *lda,
00055                                  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_zgeqrf( lapack_complex_double *a, lapack_complex_double *a_i,
00060                            lapack_complex_double *tau,
00061                            lapack_complex_double *tau_i, lapack_int info,
00062                            lapack_int info_i, lapack_int lda, lapack_int m,
00063                            lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     lapack_int m, m_i;
00069     lapack_int n, n_i;
00070     lapack_int lda, lda_i;
00071     lapack_int lda_r;
00072     lapack_int lwork, lwork_i;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     lapack_complex_double *a = NULL, *a_i = NULL;
00079     lapack_complex_double *tau = NULL, *tau_i = NULL;
00080     lapack_complex_double *work = NULL, *work_i = NULL;
00081     lapack_complex_double *a_save = NULL;
00082     lapack_complex_double *tau_save = NULL;
00083     lapack_complex_double *a_r = NULL;
00084 
00085     /* Iniitialize the scalar parameters */
00086     init_scalars_zgeqrf( &m, &n, &lda, &lwork );
00087     lda_r = n+2;
00088     m_i = m;
00089     n_i = n;
00090     lda_i = lda;
00091     lwork_i = lwork;
00092 
00093     /* Allocate memory for the LAPACK routine arrays */
00094     a = (lapack_complex_double *)
00095         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00096     tau = (lapack_complex_double *)
00097         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00098     work = (lapack_complex_double *)
00099         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00100 
00101     /* Allocate memory for the C interface function arrays */
00102     a_i = (lapack_complex_double *)
00103         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00104     tau_i = (lapack_complex_double *)
00105         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00106     work_i = (lapack_complex_double *)
00107         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00108 
00109     /* Allocate memory for the backup arrays */
00110     a_save = (lapack_complex_double *)
00111         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00112     tau_save = (lapack_complex_double *)
00113         LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00114 
00115     /* Allocate memory for the row-major arrays */
00116     a_r = (lapack_complex_double *)
00117         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00118 
00119     /* Initialize input arrays */
00120     init_a( lda*n, a );
00121     init_tau( (MIN(m,n)), tau );
00122     init_work( lwork, work );
00123 
00124     /* Backup the ouptut arrays */
00125     for( i = 0; i < lda*n; i++ ) {
00126         a_save[i] = a[i];
00127     }
00128     for( i = 0; i < (MIN(m,n)); i++ ) {
00129         tau_save[i] = tau[i];
00130     }
00131 
00132     /* Call the LAPACK routine */
00133     zgeqrf_( &m, &n, a, &lda, tau, work, &lwork, &info );
00134 
00135     /* Initialize input data, call the column-major middle-level
00136      * interface to LAPACK routine and check the results */
00137     for( i = 0; i < lda*n; i++ ) {
00138         a_i[i] = a_save[i];
00139     }
00140     for( i = 0; i < (MIN(m,n)); i++ ) {
00141         tau_i[i] = tau_save[i];
00142     }
00143     for( i = 0; i < lwork; i++ ) {
00144         work_i[i] = work[i];
00145     }
00146     info_i = LAPACKE_zgeqrf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, tau_i,
00147                                   work_i, lwork_i );
00148 
00149     failed = compare_zgeqrf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00150     if( failed == 0 ) {
00151         printf( "PASSED: column-major middle-level interface to zgeqrf\n" );
00152     } else {
00153         printf( "FAILED: column-major middle-level interface to zgeqrf\n" );
00154     }
00155 
00156     /* Initialize input data, call the column-major high-level
00157      * interface to LAPACK routine and check the results */
00158     for( i = 0; i < lda*n; i++ ) {
00159         a_i[i] = a_save[i];
00160     }
00161     for( i = 0; i < (MIN(m,n)); i++ ) {
00162         tau_i[i] = tau_save[i];
00163     }
00164     for( i = 0; i < lwork; i++ ) {
00165         work_i[i] = work[i];
00166     }
00167     info_i = LAPACKE_zgeqrf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, tau_i );
00168 
00169     failed = compare_zgeqrf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00170     if( failed == 0 ) {
00171         printf( "PASSED: column-major high-level interface to zgeqrf\n" );
00172     } else {
00173         printf( "FAILED: column-major high-level interface to zgeqrf\n" );
00174     }
00175 
00176     /* Initialize input data, call the row-major middle-level
00177      * interface to LAPACK routine and check the results */
00178     for( i = 0; i < lda*n; i++ ) {
00179         a_i[i] = a_save[i];
00180     }
00181     for( i = 0; i < (MIN(m,n)); i++ ) {
00182         tau_i[i] = tau_save[i];
00183     }
00184     for( i = 0; i < lwork; i++ ) {
00185         work_i[i] = work[i];
00186     }
00187 
00188     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00189     info_i = LAPACKE_zgeqrf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, tau_i,
00190                                   work_i, lwork_i );
00191 
00192     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00193 
00194     failed = compare_zgeqrf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: row-major middle-level interface to zgeqrf\n" );
00197     } else {
00198         printf( "FAILED: row-major middle-level interface to zgeqrf\n" );
00199     }
00200 
00201     /* Initialize input data, call the row-major high-level
00202      * interface to LAPACK routine and check the results */
00203     for( i = 0; i < lda*n; i++ ) {
00204         a_i[i] = a_save[i];
00205     }
00206     for( i = 0; i < (MIN(m,n)); i++ ) {
00207         tau_i[i] = tau_save[i];
00208     }
00209     for( i = 0; i < lwork; i++ ) {
00210         work_i[i] = work[i];
00211     }
00212 
00213     /* Init row_major arrays */
00214     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00215     info_i = LAPACKE_zgeqrf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, tau_i );
00216 
00217     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00218 
00219     failed = compare_zgeqrf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00220     if( failed == 0 ) {
00221         printf( "PASSED: row-major high-level interface to zgeqrf\n" );
00222     } else {
00223         printf( "FAILED: row-major high-level interface to zgeqrf\n" );
00224     }
00225 
00226     /* Release memory */
00227     if( a != NULL ) {
00228         LAPACKE_free( a );
00229     }
00230     if( a_i != NULL ) {
00231         LAPACKE_free( a_i );
00232     }
00233     if( a_r != NULL ) {
00234         LAPACKE_free( a_r );
00235     }
00236     if( a_save != NULL ) {
00237         LAPACKE_free( a_save );
00238     }
00239     if( tau != NULL ) {
00240         LAPACKE_free( tau );
00241     }
00242     if( tau_i != NULL ) {
00243         LAPACKE_free( tau_i );
00244     }
00245     if( tau_save != NULL ) {
00246         LAPACKE_free( tau_save );
00247     }
00248     if( work != NULL ) {
00249         LAPACKE_free( work );
00250     }
00251     if( work_i != NULL ) {
00252         LAPACKE_free( work_i );
00253     }
00254 
00255     return 0;
00256 }
00257 
00258 /* Auxiliary function: zgeqrf scalar parameters initialization */
00259 static void init_scalars_zgeqrf( lapack_int *m, lapack_int *n, lapack_int *lda,
00260                                  lapack_int *lwork )
00261 {
00262     *m = 6;
00263     *n = 4;
00264     *lda = 8;
00265     *lwork = 512;
00266 
00267     return;
00268 }
00269 
00270 /* Auxiliary functions: zgeqrf array parameters initialization */
00271 static void init_a( lapack_int size, lapack_complex_double *a ) {
00272     lapack_int i;
00273     for( i = 0; i < size; i++ ) {
00274         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00275     }
00276     a[0] = lapack_make_complex_double( 9.59999999999999960e-001,
00277                                        -8.10000000000000050e-001 );
00278     a[8] = lapack_make_complex_double( -2.99999999999999990e-002,
00279                                        9.59999999999999960e-001 );
00280     a[16] = lapack_make_complex_double( -9.10000000000000030e-001,
00281                                         2.06000000000000010e+000 );
00282     a[24] = lapack_make_complex_double( -5.00000000000000030e-002,
00283                                         4.09999999999999980e-001 );
00284     a[1] = lapack_make_complex_double( -9.79999999999999980e-001,
00285                                        1.98000000000000000e+000 );
00286     a[9] = lapack_make_complex_double( -1.20000000000000000e+000,
00287                                        1.90000000000000000e-001 );
00288     a[17] = lapack_make_complex_double( -6.60000000000000030e-001,
00289                                         4.19999999999999980e-001 );
00290     a[25] = lapack_make_complex_double( -8.10000000000000050e-001,
00291                                         5.60000000000000050e-001 );
00292     a[2] = lapack_make_complex_double( 6.20000000000000000e-001,
00293                                        -4.60000000000000020e-001 );
00294     a[10] = lapack_make_complex_double( 1.01000000000000000e+000,
00295                                         2.00000000000000000e-002 );
00296     a[18] = lapack_make_complex_double( 6.30000000000000000e-001,
00297                                         -1.70000000000000010e-001 );
00298     a[26] = lapack_make_complex_double( -1.11000000000000010e+000,
00299                                         5.99999999999999980e-001 );
00300     a[3] = lapack_make_complex_double( -3.70000000000000000e-001,
00301                                        3.80000000000000000e-001 );
00302     a[11] = lapack_make_complex_double( 1.90000000000000000e-001,
00303                                         -5.40000000000000040e-001 );
00304     a[19] = lapack_make_complex_double( -9.79999999999999980e-001,
00305                                         -3.59999999999999990e-001 );
00306     a[27] = lapack_make_complex_double( 2.20000000000000000e-001,
00307                                         -2.00000000000000010e-001 );
00308     a[4] = lapack_make_complex_double( 8.29999999999999960e-001,
00309                                        5.10000000000000010e-001 );
00310     a[12] = lapack_make_complex_double( 2.00000000000000010e-001,
00311                                         1.00000000000000000e-002 );
00312     a[20] = lapack_make_complex_double( -1.70000000000000010e-001,
00313                                         -4.60000000000000020e-001 );
00314     a[28] = lapack_make_complex_double( 1.47000000000000000e+000,
00315                                         1.59000000000000010e+000 );
00316     a[5] = lapack_make_complex_double( 1.08000000000000010e+000,
00317                                        -2.80000000000000030e-001 );
00318     a[13] = lapack_make_complex_double( 2.00000000000000010e-001,
00319                                         -1.20000000000000000e-001 );
00320     a[21] = lapack_make_complex_double( -7.00000000000000070e-002,
00321                                         1.23000000000000000e+000 );
00322     a[29] = lapack_make_complex_double( 2.60000000000000010e-001,
00323                                         2.60000000000000010e-001 );
00324 }
00325 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00326     lapack_int i;
00327     for( i = 0; i < size; i++ ) {
00328         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00329     }
00330 }
00331 static void init_work( lapack_int size, lapack_complex_double *work ) {
00332     lapack_int i;
00333     for( i = 0; i < size; i++ ) {
00334         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00335     }
00336 }
00337 
00338 /* Auxiliary function: C interface to zgeqrf results check */
00339 /* Return value: 0 - test is passed, non-zero - test is failed */
00340 static int compare_zgeqrf( lapack_complex_double *a, lapack_complex_double *a_i,
00341                            lapack_complex_double *tau,
00342                            lapack_complex_double *tau_i, lapack_int info,
00343                            lapack_int info_i, lapack_int lda, lapack_int m,
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     for( i = 0; i < (MIN(m,n)); i++ ) {
00352         failed += compare_complex_doubles(tau[i],tau_i[i]);
00353     }
00354     failed += (info == info_i) ? 0 : 1;
00355     if( info != 0 || info_i != 0 ) {
00356         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00357     }
00358 
00359     return failed;
00360 }


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