chptri_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 * chptri_1 is the test program for the C interface to LAPACK
00036 * routine chptri
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_chptri( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00057 static void init_work( lapack_int size, lapack_complex_float *work );
00058 static int compare_chptri( lapack_complex_float *ap, lapack_complex_float *ap_i,
00059                            lapack_int info, lapack_int info_i, lapack_int n );
00060 
00061 int main(void)
00062 {
00063     /* Local scalars */
00064     char uplo, uplo_i;
00065     lapack_int n, n_i;
00066     lapack_int info, info_i;
00067     lapack_int i;
00068     int failed;
00069 
00070     /* Local arrays */
00071     lapack_complex_float *ap = NULL, *ap_i = NULL;
00072     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00073     lapack_complex_float *work = NULL, *work_i = NULL;
00074     lapack_complex_float *ap_save = NULL;
00075     lapack_complex_float *ap_r = NULL;
00076 
00077     /* Iniitialize the scalar parameters */
00078     init_scalars_chptri( &uplo, &n );
00079     uplo_i = uplo;
00080     n_i = n;
00081 
00082     /* Allocate memory for the LAPACK routine arrays */
00083     ap = (lapack_complex_float *)
00084         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00085     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00086     work = (lapack_complex_float *)
00087         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00088 
00089     /* Allocate memory for the C interface function arrays */
00090     ap_i = (lapack_complex_float *)
00091         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00092     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093     work_i = (lapack_complex_float *)
00094         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00095 
00096     /* Allocate memory for the backup arrays */
00097     ap_save = (lapack_complex_float *)
00098         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00099 
00100     /* Allocate memory for the row-major arrays */
00101     ap_r = (lapack_complex_float *)
00102         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00103 
00104     /* Initialize input arrays */
00105     init_ap( (n*(n+1)/2), ap );
00106     init_ipiv( n, ipiv );
00107     init_work( n, work );
00108 
00109     /* Backup the ouptut arrays */
00110     for( i = 0; i < (n*(n+1)/2); i++ ) {
00111         ap_save[i] = ap[i];
00112     }
00113 
00114     /* Call the LAPACK routine */
00115     chptri_( &uplo, &n, ap, ipiv, work, &info );
00116 
00117     /* Initialize input data, call the column-major middle-level
00118      * interface to LAPACK routine and check the results */
00119     for( i = 0; i < (n*(n+1)/2); i++ ) {
00120         ap_i[i] = ap_save[i];
00121     }
00122     for( i = 0; i < n; i++ ) {
00123         ipiv_i[i] = ipiv[i];
00124     }
00125     for( i = 0; i < n; i++ ) {
00126         work_i[i] = work[i];
00127     }
00128     info_i = LAPACKE_chptri_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i,
00129                                   work_i );
00130 
00131     failed = compare_chptri( ap, ap_i, info, info_i, n );
00132     if( failed == 0 ) {
00133         printf( "PASSED: column-major middle-level interface to chptri\n" );
00134     } else {
00135         printf( "FAILED: column-major middle-level interface to chptri\n" );
00136     }
00137 
00138     /* Initialize input data, call the column-major high-level
00139      * interface to LAPACK routine and check the results */
00140     for( i = 0; i < (n*(n+1)/2); i++ ) {
00141         ap_i[i] = ap_save[i];
00142     }
00143     for( i = 0; i < n; i++ ) {
00144         ipiv_i[i] = ipiv[i];
00145     }
00146     for( i = 0; i < n; i++ ) {
00147         work_i[i] = work[i];
00148     }
00149     info_i = LAPACKE_chptri( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00150 
00151     failed = compare_chptri( ap, ap_i, info, info_i, n );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major high-level interface to chptri\n" );
00154     } else {
00155         printf( "FAILED: column-major high-level interface to chptri\n" );
00156     }
00157 
00158     /* Initialize input data, call the row-major middle-level
00159      * interface to LAPACK routine and check the results */
00160     for( i = 0; i < (n*(n+1)/2); i++ ) {
00161         ap_i[i] = ap_save[i];
00162     }
00163     for( i = 0; i < n; i++ ) {
00164         ipiv_i[i] = ipiv[i];
00165     }
00166     for( i = 0; i < n; i++ ) {
00167         work_i[i] = work[i];
00168     }
00169 
00170     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00171     info_i = LAPACKE_chptri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i,
00172                                   work_i );
00173 
00174     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00175 
00176     failed = compare_chptri( ap, ap_i, info, info_i, n );
00177     if( failed == 0 ) {
00178         printf( "PASSED: row-major middle-level interface to chptri\n" );
00179     } else {
00180         printf( "FAILED: row-major middle-level interface to chptri\n" );
00181     }
00182 
00183     /* Initialize input data, call the row-major high-level
00184      * interface to LAPACK routine and check the results */
00185     for( i = 0; i < (n*(n+1)/2); i++ ) {
00186         ap_i[i] = ap_save[i];
00187     }
00188     for( i = 0; i < n; i++ ) {
00189         ipiv_i[i] = ipiv[i];
00190     }
00191     for( i = 0; i < n; i++ ) {
00192         work_i[i] = work[i];
00193     }
00194 
00195     /* Init row_major arrays */
00196     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00197     info_i = LAPACKE_chptri( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00198 
00199     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00200 
00201     failed = compare_chptri( ap, ap_i, info, info_i, n );
00202     if( failed == 0 ) {
00203         printf( "PASSED: row-major high-level interface to chptri\n" );
00204     } else {
00205         printf( "FAILED: row-major high-level interface to chptri\n" );
00206     }
00207 
00208     /* Release memory */
00209     if( ap != NULL ) {
00210         LAPACKE_free( ap );
00211     }
00212     if( ap_i != NULL ) {
00213         LAPACKE_free( ap_i );
00214     }
00215     if( ap_r != NULL ) {
00216         LAPACKE_free( ap_r );
00217     }
00218     if( ap_save != NULL ) {
00219         LAPACKE_free( ap_save );
00220     }
00221     if( ipiv != NULL ) {
00222         LAPACKE_free( ipiv );
00223     }
00224     if( ipiv_i != NULL ) {
00225         LAPACKE_free( ipiv_i );
00226     }
00227     if( work != NULL ) {
00228         LAPACKE_free( work );
00229     }
00230     if( work_i != NULL ) {
00231         LAPACKE_free( work_i );
00232     }
00233 
00234     return 0;
00235 }
00236 
00237 /* Auxiliary function: chptri scalar parameters initialization */
00238 static void init_scalars_chptri( char *uplo, lapack_int *n )
00239 {
00240     *uplo = 'L';
00241     *n = 4;
00242 
00243     return;
00244 }
00245 
00246 /* Auxiliary functions: chptri array parameters initialization */
00247 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00248     lapack_int i;
00249     for( i = 0; i < size; i++ ) {
00250         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00251     }
00252     ap[0] = lapack_make_complex_float( -1.360000014e+000, 0.000000000e+000 );
00253     ap[1] = lapack_make_complex_float( 3.910000086e+000, -1.500000000e+000 );
00254     ap[2] = lapack_make_complex_float( 3.100287914e-001, 4.333020747e-002 );
00255     ap[3] = lapack_make_complex_float( -1.518120319e-001, 3.742958307e-001 );
00256     ap[4] = lapack_make_complex_float( -1.840000033e+000, 0.000000000e+000 );
00257     ap[5] = lapack_make_complex_float( 5.637050867e-001, 2.850349545e-001 );
00258     ap[6] = lapack_make_complex_float( 3.396582901e-001, 3.031452000e-002 );
00259     ap[7] = lapack_make_complex_float( -5.417624474e+000, 0.000000000e+000 );
00260     ap[8] = lapack_make_complex_float( 2.997244298e-001, 1.578268558e-001 );
00261     ap[9] = lapack_make_complex_float( -7.102810383e+000, 0.000000000e+000 );
00262 }
00263 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00264     lapack_int i;
00265     for( i = 0; i < size; i++ ) {
00266         ipiv[i] = 0;
00267     }
00268     ipiv[0] = -4;
00269     ipiv[1] = -4;
00270     ipiv[2] = 3;
00271     ipiv[3] = 4;
00272 }
00273 static void init_work( lapack_int size, lapack_complex_float *work ) {
00274     lapack_int i;
00275     for( i = 0; i < size; i++ ) {
00276         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00277     }
00278 }
00279 
00280 /* Auxiliary function: C interface to chptri results check */
00281 /* Return value: 0 - test is passed, non-zero - test is failed */
00282 static int compare_chptri( lapack_complex_float *ap, lapack_complex_float *ap_i,
00283                            lapack_int info, lapack_int info_i, lapack_int n )
00284 {
00285     lapack_int i;
00286     int failed = 0;
00287     for( i = 0; i < (n*(n+1)/2); i++ ) {
00288         failed += compare_complex_floats(ap[i],ap_i[i]);
00289     }
00290     failed += (info == info_i) ? 0 : 1;
00291     if( info != 0 || info_i != 0 ) {
00292         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00293     }
00294 
00295     return failed;
00296 }


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