cgetri_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 * cgetri_1 is the test program for the C interface to LAPACK
00036 * routine cgetri
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_cgetri( lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_cgetri( 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 n, n_i;
00067     lapack_int lda, lda_i;
00068     lapack_int lda_r;
00069     lapack_int lwork, lwork_i;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     lapack_complex_float *a = NULL, *a_i = NULL;
00076     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077     lapack_complex_float *work = NULL, *work_i = NULL;
00078     lapack_complex_float *a_save = NULL;
00079     lapack_complex_float *a_r = NULL;
00080 
00081     /* Iniitialize the scalar parameters */
00082     init_scalars_cgetri( &n, &lda, &lwork );
00083     lda_r = n+2;
00084     n_i = n;
00085     lda_i = lda;
00086     lwork_i = lwork;
00087 
00088     /* Allocate memory for the LAPACK routine arrays */
00089     a = (lapack_complex_float *)
00090         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00091     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00092     work = (lapack_complex_float *)
00093         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00094 
00095     /* Allocate memory for the C interface function arrays */
00096     a_i = (lapack_complex_float *)
00097         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00098     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00099     work_i = (lapack_complex_float *)
00100         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00101 
00102     /* Allocate memory for the backup arrays */
00103     a_save = (lapack_complex_float *)
00104         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00105 
00106     /* Allocate memory for the row-major arrays */
00107     a_r = (lapack_complex_float *)
00108         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00109 
00110     /* Initialize input arrays */
00111     init_a( lda*n, a );
00112     init_ipiv( n, ipiv );
00113     init_work( lwork, work );
00114 
00115     /* Backup the ouptut arrays */
00116     for( i = 0; i < lda*n; i++ ) {
00117         a_save[i] = a[i];
00118     }
00119 
00120     /* Call the LAPACK routine */
00121     cgetri_( &n, a, &lda, ipiv, work, &lwork, &info );
00122 
00123     /* Initialize input data, call the column-major middle-level
00124      * interface to LAPACK routine and check the results */
00125     for( i = 0; i < lda*n; i++ ) {
00126         a_i[i] = a_save[i];
00127     }
00128     for( i = 0; i < n; i++ ) {
00129         ipiv_i[i] = ipiv[i];
00130     }
00131     for( i = 0; i < lwork; i++ ) {
00132         work_i[i] = work[i];
00133     }
00134     info_i = LAPACKE_cgetri_work( LAPACK_COL_MAJOR, n_i, a_i, lda_i, ipiv_i,
00135                                   work_i, lwork_i );
00136 
00137     failed = compare_cgetri( a, a_i, info, info_i, lda, n );
00138     if( failed == 0 ) {
00139         printf( "PASSED: column-major middle-level interface to cgetri\n" );
00140     } else {
00141         printf( "FAILED: column-major middle-level interface to cgetri\n" );
00142     }
00143 
00144     /* Initialize input data, call the column-major high-level
00145      * interface to LAPACK routine and check the results */
00146     for( i = 0; i < lda*n; i++ ) {
00147         a_i[i] = a_save[i];
00148     }
00149     for( i = 0; i < n; i++ ) {
00150         ipiv_i[i] = ipiv[i];
00151     }
00152     for( i = 0; i < lwork; i++ ) {
00153         work_i[i] = work[i];
00154     }
00155     info_i = LAPACKE_cgetri( LAPACK_COL_MAJOR, n_i, a_i, lda_i, ipiv_i );
00156 
00157     failed = compare_cgetri( a, a_i, info, info_i, lda, n );
00158     if( failed == 0 ) {
00159         printf( "PASSED: column-major high-level interface to cgetri\n" );
00160     } else {
00161         printf( "FAILED: column-major high-level interface to cgetri\n" );
00162     }
00163 
00164     /* Initialize input data, call the row-major middle-level
00165      * interface to LAPACK routine and check the results */
00166     for( i = 0; i < lda*n; i++ ) {
00167         a_i[i] = a_save[i];
00168     }
00169     for( i = 0; i < n; i++ ) {
00170         ipiv_i[i] = ipiv[i];
00171     }
00172     for( i = 0; i < lwork; i++ ) {
00173         work_i[i] = work[i];
00174     }
00175 
00176     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00177     info_i = LAPACKE_cgetri_work( LAPACK_ROW_MAJOR, n_i, a_r, lda_r, ipiv_i,
00178                                   work_i, lwork_i );
00179 
00180     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00181 
00182     failed = compare_cgetri( a, a_i, info, info_i, lda, n );
00183     if( failed == 0 ) {
00184         printf( "PASSED: row-major middle-level interface to cgetri\n" );
00185     } else {
00186         printf( "FAILED: row-major middle-level interface to cgetri\n" );
00187     }
00188 
00189     /* Initialize input data, call the row-major high-level
00190      * interface to LAPACK routine and check the results */
00191     for( i = 0; i < lda*n; i++ ) {
00192         a_i[i] = a_save[i];
00193     }
00194     for( i = 0; i < n; i++ ) {
00195         ipiv_i[i] = ipiv[i];
00196     }
00197     for( i = 0; i < lwork; i++ ) {
00198         work_i[i] = work[i];
00199     }
00200 
00201     /* Init row_major arrays */
00202     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00203     info_i = LAPACKE_cgetri( LAPACK_ROW_MAJOR, n_i, a_r, lda_r, ipiv_i );
00204 
00205     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00206 
00207     failed = compare_cgetri( a, a_i, info, info_i, lda, n );
00208     if( failed == 0 ) {
00209         printf( "PASSED: row-major high-level interface to cgetri\n" );
00210     } else {
00211         printf( "FAILED: row-major high-level interface to cgetri\n" );
00212     }
00213 
00214     /* Release memory */
00215     if( a != NULL ) {
00216         LAPACKE_free( a );
00217     }
00218     if( a_i != NULL ) {
00219         LAPACKE_free( a_i );
00220     }
00221     if( a_r != NULL ) {
00222         LAPACKE_free( a_r );
00223     }
00224     if( a_save != NULL ) {
00225         LAPACKE_free( a_save );
00226     }
00227     if( ipiv != NULL ) {
00228         LAPACKE_free( ipiv );
00229     }
00230     if( ipiv_i != NULL ) {
00231         LAPACKE_free( ipiv_i );
00232     }
00233     if( work != NULL ) {
00234         LAPACKE_free( work );
00235     }
00236     if( work_i != NULL ) {
00237         LAPACKE_free( work_i );
00238     }
00239 
00240     return 0;
00241 }
00242 
00243 /* Auxiliary function: cgetri scalar parameters initialization */
00244 static void init_scalars_cgetri( lapack_int *n, lapack_int *lda,
00245                                  lapack_int *lwork )
00246 {
00247     *n = 4;
00248     *lda = 8;
00249     *lwork = 512;
00250 
00251     return;
00252 }
00253 
00254 /* Auxiliary functions: cgetri array parameters initialization */
00255 static void init_a( lapack_int size, lapack_complex_float *a ) {
00256     lapack_int i;
00257     for( i = 0; i < size; i++ ) {
00258         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00259     }
00260     a[0] = lapack_make_complex_float( -3.289999962e+000, -2.390000105e+000 );
00261     a[8] = lapack_make_complex_float( -1.909999967e+000, 4.420000076e+000 );
00262     a[16] = lapack_make_complex_float( -1.400000006e-001, -1.350000024e+000 );
00263     a[24] = lapack_make_complex_float( 1.720000029e+000, 1.350000024e+000 );
00264     a[1] = lapack_make_complex_float( 2.376120239e-001, 2.559596300e-001 );
00265     a[9] = lapack_make_complex_float( 4.895180702e+000, -7.113622427e-001 );
00266     a[17] = lapack_make_complex_float( -4.622798264e-001, 1.696610570e+000 );
00267     a[25] = lapack_make_complex_float( 1.226852775e+000, 6.189731956e-001 );
00268     a[2] = lapack_make_complex_float( -1.019521058e-001, -7.010135055e-001 );
00269     a[10] = lapack_make_complex_float( -6.691496968e-001, 3.688699007e-001 );
00270     a[18] = lapack_make_complex_float( -5.141410828e+000, -1.129969597e+000 );
00271     a[26] = lapack_make_complex_float( 9.982581139e-001, 3.850151896e-001 );
00272     a[3] = lapack_make_complex_float( -5.358546376e-001, 2.707273066e-001 );
00273     a[11] = lapack_make_complex_float( -2.040217221e-001, 8.601181507e-001 );
00274     a[19] = lapack_make_complex_float( 8.233040571e-003, 1.210636795e-001 );
00275     a[27] = lapack_make_complex_float( 1.482392550e-001, -1.252242178e-001 );
00276 }
00277 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00278     lapack_int i;
00279     for( i = 0; i < size; i++ ) {
00280         ipiv[i] = 0;
00281     }
00282     ipiv[0] = 3;
00283     ipiv[1] = 2;
00284     ipiv[2] = 3;
00285     ipiv[3] = 4;
00286 }
00287 static void init_work( lapack_int size, lapack_complex_float *work ) {
00288     lapack_int i;
00289     for( i = 0; i < size; i++ ) {
00290         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00291     }
00292 }
00293 
00294 /* Auxiliary function: C interface to cgetri results check */
00295 /* Return value: 0 - test is passed, non-zero - test is failed */
00296 static int compare_cgetri( lapack_complex_float *a, lapack_complex_float *a_i,
00297                            lapack_int info, lapack_int info_i, lapack_int lda,
00298                            lapack_int n )
00299 {
00300     lapack_int i;
00301     int failed = 0;
00302     for( i = 0; i < lda*n; i++ ) {
00303         failed += compare_complex_floats(a[i],a_i[i]);
00304     }
00305     failed += (info == info_i) ? 0 : 1;
00306     if( info != 0 || info_i != 0 ) {
00307         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00308     }
00309 
00310     return failed;
00311 }


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