cpptrf_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 * cpptrf_1 is the test program for the C interface to LAPACK
00036 * routine cpptrf
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_cpptrf( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static int compare_cpptrf( lapack_complex_float *ap, lapack_complex_float *ap_i,
00057                            lapack_int info, lapack_int info_i, lapack_int n );
00058 
00059 int main(void)
00060 {
00061     /* Local scalars */
00062     char uplo, uplo_i;
00063     lapack_int n, n_i;
00064     lapack_int info, info_i;
00065     lapack_int i;
00066     int failed;
00067 
00068     /* Local arrays */
00069     lapack_complex_float *ap = NULL, *ap_i = NULL;
00070     lapack_complex_float *ap_save = NULL;
00071     lapack_complex_float *ap_r = NULL;
00072 
00073     /* Iniitialize the scalar parameters */
00074     init_scalars_cpptrf( &uplo, &n );
00075     uplo_i = uplo;
00076     n_i = n;
00077 
00078     /* Allocate memory for the LAPACK routine arrays */
00079     ap = (lapack_complex_float *)
00080         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00081 
00082     /* Allocate memory for the C interface function arrays */
00083     ap_i = (lapack_complex_float *)
00084         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00085 
00086     /* Allocate memory for the backup arrays */
00087     ap_save = (lapack_complex_float *)
00088         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00089 
00090     /* Allocate memory for the row-major arrays */
00091     ap_r = (lapack_complex_float *)
00092         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00093 
00094     /* Initialize input arrays */
00095     init_ap( (n*(n+1)/2), ap );
00096 
00097     /* Backup the ouptut arrays */
00098     for( i = 0; i < (n*(n+1)/2); i++ ) {
00099         ap_save[i] = ap[i];
00100     }
00101 
00102     /* Call the LAPACK routine */
00103     cpptrf_( &uplo, &n, ap, &info );
00104 
00105     /* Initialize input data, call the column-major middle-level
00106      * interface to LAPACK routine and check the results */
00107     for( i = 0; i < (n*(n+1)/2); i++ ) {
00108         ap_i[i] = ap_save[i];
00109     }
00110     info_i = LAPACKE_cpptrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00111 
00112     failed = compare_cpptrf( ap, ap_i, info, info_i, n );
00113     if( failed == 0 ) {
00114         printf( "PASSED: column-major middle-level interface to cpptrf\n" );
00115     } else {
00116         printf( "FAILED: column-major middle-level interface to cpptrf\n" );
00117     }
00118 
00119     /* Initialize input data, call the column-major high-level
00120      * interface to LAPACK routine and check the results */
00121     for( i = 0; i < (n*(n+1)/2); i++ ) {
00122         ap_i[i] = ap_save[i];
00123     }
00124     info_i = LAPACKE_cpptrf( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00125 
00126     failed = compare_cpptrf( ap, ap_i, info, info_i, n );
00127     if( failed == 0 ) {
00128         printf( "PASSED: column-major high-level interface to cpptrf\n" );
00129     } else {
00130         printf( "FAILED: column-major high-level interface to cpptrf\n" );
00131     }
00132 
00133     /* Initialize input data, call the row-major middle-level
00134      * interface to LAPACK routine and check the results */
00135     for( i = 0; i < (n*(n+1)/2); i++ ) {
00136         ap_i[i] = ap_save[i];
00137     }
00138 
00139     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00140     info_i = LAPACKE_cpptrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00141 
00142     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00143 
00144     failed = compare_cpptrf( ap, ap_i, info, info_i, n );
00145     if( failed == 0 ) {
00146         printf( "PASSED: row-major middle-level interface to cpptrf\n" );
00147     } else {
00148         printf( "FAILED: row-major middle-level interface to cpptrf\n" );
00149     }
00150 
00151     /* Initialize input data, call the row-major high-level
00152      * interface to LAPACK routine and check the results */
00153     for( i = 0; i < (n*(n+1)/2); i++ ) {
00154         ap_i[i] = ap_save[i];
00155     }
00156 
00157     /* Init row_major arrays */
00158     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00159     info_i = LAPACKE_cpptrf( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00160 
00161     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00162 
00163     failed = compare_cpptrf( ap, ap_i, info, info_i, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: row-major high-level interface to cpptrf\n" );
00166     } else {
00167         printf( "FAILED: row-major high-level interface to cpptrf\n" );
00168     }
00169 
00170     /* Release memory */
00171     if( ap != NULL ) {
00172         LAPACKE_free( ap );
00173     }
00174     if( ap_i != NULL ) {
00175         LAPACKE_free( ap_i );
00176     }
00177     if( ap_r != NULL ) {
00178         LAPACKE_free( ap_r );
00179     }
00180     if( ap_save != NULL ) {
00181         LAPACKE_free( ap_save );
00182     }
00183 
00184     return 0;
00185 }
00186 
00187 /* Auxiliary function: cpptrf scalar parameters initialization */
00188 static void init_scalars_cpptrf( char *uplo, lapack_int *n )
00189 {
00190     *uplo = 'L';
00191     *n = 4;
00192 
00193     return;
00194 }
00195 
00196 /* Auxiliary functions: cpptrf array parameters initialization */
00197 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00198     lapack_int i;
00199     for( i = 0; i < size; i++ ) {
00200         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00201     }
00202     ap[0] = lapack_make_complex_float( 3.230000019e+000, 0.000000000e+000 );
00203     ap[1] = lapack_make_complex_float( 1.509999990e+000, 1.919999957e+000 );
00204     ap[2] = lapack_make_complex_float( 1.899999976e+000, -8.399999738e-001 );
00205     ap[3] = lapack_make_complex_float( 4.199999869e-001, -2.500000000e+000 );
00206     ap[4] = lapack_make_complex_float( 3.579999924e+000, 0.000000000e+000 );
00207     ap[5] = lapack_make_complex_float( -2.300000042e-001, -1.110000014e+000 );
00208     ap[6] = lapack_make_complex_float( -1.179999948e+000, -1.370000005e+000 );
00209     ap[7] = lapack_make_complex_float( 4.090000153e+000, 0.000000000e+000 );
00210     ap[8] = lapack_make_complex_float( 2.329999924e+000, 1.400000006e-001 );
00211     ap[9] = lapack_make_complex_float( 4.289999962e+000, 0.000000000e+000 );
00212 }
00213 
00214 /* Auxiliary function: C interface to cpptrf results check */
00215 /* Return value: 0 - test is passed, non-zero - test is failed */
00216 static int compare_cpptrf( lapack_complex_float *ap, lapack_complex_float *ap_i,
00217                            lapack_int info, lapack_int info_i, lapack_int n )
00218 {
00219     lapack_int i;
00220     int failed = 0;
00221     for( i = 0; i < (n*(n+1)/2); i++ ) {
00222         failed += compare_complex_floats(ap[i],ap_i[i]);
00223     }
00224     failed += (info == info_i) ? 0 : 1;
00225     if( info != 0 || info_i != 0 ) {
00226         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00227     }
00228 
00229     return failed;
00230 }


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