csptrf_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 * csptrf_1 is the test program for the C interface to LAPACK
00036 * routine csptrf
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_csptrf( 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 int compare_csptrf( lapack_complex_float *ap, lapack_complex_float *ap_i,
00058                            lapack_int *ipiv, lapack_int *ipiv_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 *ap_save = NULL;
00074     lapack_int *ipiv_save = NULL;
00075     lapack_complex_float *ap_r = NULL;
00076 
00077     /* Iniitialize the scalar parameters */
00078     init_scalars_csptrf( &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 
00087     /* Allocate memory for the C interface function arrays */
00088     ap_i = (lapack_complex_float *)
00089         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00090     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00091 
00092     /* Allocate memory for the backup arrays */
00093     ap_save = (lapack_complex_float *)
00094         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00095     ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096 
00097     /* Allocate memory for the row-major arrays */
00098     ap_r = (lapack_complex_float *)
00099         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00100 
00101     /* Initialize input arrays */
00102     init_ap( (n*(n+1)/2), ap );
00103     init_ipiv( n, ipiv );
00104 
00105     /* Backup the ouptut arrays */
00106     for( i = 0; i < (n*(n+1)/2); i++ ) {
00107         ap_save[i] = ap[i];
00108     }
00109     for( i = 0; i < n; i++ ) {
00110         ipiv_save[i] = ipiv[i];
00111     }
00112 
00113     /* Call the LAPACK routine */
00114     csptrf_( &uplo, &n, ap, ipiv, &info );
00115 
00116     /* Initialize input data, call the column-major middle-level
00117      * interface to LAPACK routine and check the results */
00118     for( i = 0; i < (n*(n+1)/2); i++ ) {
00119         ap_i[i] = ap_save[i];
00120     }
00121     for( i = 0; i < n; i++ ) {
00122         ipiv_i[i] = ipiv_save[i];
00123     }
00124     info_i = LAPACKE_csptrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00125 
00126     failed = compare_csptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00127     if( failed == 0 ) {
00128         printf( "PASSED: column-major middle-level interface to csptrf\n" );
00129     } else {
00130         printf( "FAILED: column-major middle-level interface to csptrf\n" );
00131     }
00132 
00133     /* Initialize input data, call the column-major high-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     for( i = 0; i < n; i++ ) {
00139         ipiv_i[i] = ipiv_save[i];
00140     }
00141     info_i = LAPACKE_csptrf( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00142 
00143     failed = compare_csptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00144     if( failed == 0 ) {
00145         printf( "PASSED: column-major high-level interface to csptrf\n" );
00146     } else {
00147         printf( "FAILED: column-major high-level interface to csptrf\n" );
00148     }
00149 
00150     /* Initialize input data, call the row-major middle-level
00151      * interface to LAPACK routine and check the results */
00152     for( i = 0; i < (n*(n+1)/2); i++ ) {
00153         ap_i[i] = ap_save[i];
00154     }
00155     for( i = 0; i < n; i++ ) {
00156         ipiv_i[i] = ipiv_save[i];
00157     }
00158 
00159     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00160     info_i = LAPACKE_csptrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00161 
00162     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00163 
00164     failed = compare_csptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00165     if( failed == 0 ) {
00166         printf( "PASSED: row-major middle-level interface to csptrf\n" );
00167     } else {
00168         printf( "FAILED: row-major middle-level interface to csptrf\n" );
00169     }
00170 
00171     /* Initialize input data, call the row-major high-level
00172      * interface to LAPACK routine and check the results */
00173     for( i = 0; i < (n*(n+1)/2); i++ ) {
00174         ap_i[i] = ap_save[i];
00175     }
00176     for( i = 0; i < n; i++ ) {
00177         ipiv_i[i] = ipiv_save[i];
00178     }
00179 
00180     /* Init row_major arrays */
00181     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00182     info_i = LAPACKE_csptrf( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00183 
00184     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00185 
00186     failed = compare_csptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00187     if( failed == 0 ) {
00188         printf( "PASSED: row-major high-level interface to csptrf\n" );
00189     } else {
00190         printf( "FAILED: row-major high-level interface to csptrf\n" );
00191     }
00192 
00193     /* Release memory */
00194     if( ap != NULL ) {
00195         LAPACKE_free( ap );
00196     }
00197     if( ap_i != NULL ) {
00198         LAPACKE_free( ap_i );
00199     }
00200     if( ap_r != NULL ) {
00201         LAPACKE_free( ap_r );
00202     }
00203     if( ap_save != NULL ) {
00204         LAPACKE_free( ap_save );
00205     }
00206     if( ipiv != NULL ) {
00207         LAPACKE_free( ipiv );
00208     }
00209     if( ipiv_i != NULL ) {
00210         LAPACKE_free( ipiv_i );
00211     }
00212     if( ipiv_save != NULL ) {
00213         LAPACKE_free( ipiv_save );
00214     }
00215 
00216     return 0;
00217 }
00218 
00219 /* Auxiliary function: csptrf scalar parameters initialization */
00220 static void init_scalars_csptrf( char *uplo, lapack_int *n )
00221 {
00222     *uplo = 'L';
00223     *n = 4;
00224 
00225     return;
00226 }
00227 
00228 /* Auxiliary functions: csptrf array parameters initialization */
00229 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00230     lapack_int i;
00231     for( i = 0; i < size; i++ ) {
00232         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00233     }
00234     ap[0] = lapack_make_complex_float( -3.899999857e-001, -7.099999785e-001 );
00235     ap[1] = lapack_make_complex_float( 5.139999866e+000, -6.399999857e-001 );
00236     ap[2] = lapack_make_complex_float( -7.860000134e+000, -2.960000038e+000 );
00237     ap[3] = lapack_make_complex_float( 3.799999952e+000, 9.200000167e-001 );
00238     ap[4] = lapack_make_complex_float( 8.859999657e+000, 1.809999943e+000 );
00239     ap[5] = lapack_make_complex_float( -3.519999981e+000, 5.799999833e-001 );
00240     ap[6] = lapack_make_complex_float( 5.320000172e+000, -1.590000033e+000 );
00241     ap[7] = lapack_make_complex_float( -2.829999924e+000, -2.999999933e-002 );
00242     ap[8] = lapack_make_complex_float( -1.539999962e+000, -2.859999895e+000 );
00243     ap[9] = lapack_make_complex_float( -5.600000024e-001, 1.199999973e-001 );
00244 }
00245 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00246     lapack_int i;
00247     for( i = 0; i < size; i++ ) {
00248         ipiv[i] = 0;
00249     }
00250 }
00251 
00252 /* Auxiliary function: C interface to csptrf results check */
00253 /* Return value: 0 - test is passed, non-zero - test is failed */
00254 static int compare_csptrf( lapack_complex_float *ap, lapack_complex_float *ap_i,
00255                            lapack_int *ipiv, lapack_int *ipiv_i,
00256                            lapack_int info, lapack_int info_i, lapack_int n )
00257 {
00258     lapack_int i;
00259     int failed = 0;
00260     for( i = 0; i < (n*(n+1)/2); i++ ) {
00261         failed += compare_complex_floats(ap[i],ap_i[i]);
00262     }
00263     for( i = 0; i < n; i++ ) {
00264         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00265     }
00266     failed += (info == info_i) ? 0 : 1;
00267     if( info != 0 || info_i != 0 ) {
00268         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00269     }
00270 
00271     return failed;
00272 }


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