zpptrs_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 * zpptrs_1 is the test program for the C interface to LAPACK
00036 * routine zpptrs
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_zpptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055                                  lapack_int *ldb );
00056 static void init_ap( lapack_int size, lapack_complex_double *ap );
00057 static void init_b( lapack_int size, lapack_complex_double *b );
00058 static int compare_zpptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00059                            lapack_int info, lapack_int info_i, lapack_int ldb,
00060                            lapack_int nrhs );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char uplo, uplo_i;
00066     lapack_int n, n_i;
00067     lapack_int nrhs, nrhs_i;
00068     lapack_int ldb, ldb_i;
00069     lapack_int ldb_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     lapack_complex_double *ap = NULL, *ap_i = NULL;
00076     lapack_complex_double *b = NULL, *b_i = NULL;
00077     lapack_complex_double *b_save = NULL;
00078     lapack_complex_double *ap_r = NULL;
00079     lapack_complex_double *b_r = NULL;
00080 
00081     /* Iniitialize the scalar parameters */
00082     init_scalars_zpptrs( &uplo, &n, &nrhs, &ldb );
00083     ldb_r = nrhs+2;
00084     uplo_i = uplo;
00085     n_i = n;
00086     nrhs_i = nrhs;
00087     ldb_i = ldb;
00088 
00089     /* Allocate memory for the LAPACK routine arrays */
00090     ap = (lapack_complex_double *)
00091         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00092     b = (lapack_complex_double *)
00093         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00094 
00095     /* Allocate memory for the C interface function arrays */
00096     ap_i = (lapack_complex_double *)
00097         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00098     b_i = (lapack_complex_double *)
00099         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00100 
00101     /* Allocate memory for the backup arrays */
00102     b_save = (lapack_complex_double *)
00103         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00104 
00105     /* Allocate memory for the row-major arrays */
00106     ap_r = (lapack_complex_double *)
00107         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00108     b_r = (lapack_complex_double *)
00109         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00110 
00111     /* Initialize input arrays */
00112     init_ap( (n*(n+1)/2), ap );
00113     init_b( ldb*nrhs, b );
00114 
00115     /* Backup the ouptut arrays */
00116     for( i = 0; i < ldb*nrhs; i++ ) {
00117         b_save[i] = b[i];
00118     }
00119 
00120     /* Call the LAPACK routine */
00121     zpptrs_( &uplo, &n, &nrhs, ap, b, &ldb, &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 < (n*(n+1)/2); i++ ) {
00126         ap_i[i] = ap[i];
00127     }
00128     for( i = 0; i < ldb*nrhs; i++ ) {
00129         b_i[i] = b_save[i];
00130     }
00131     info_i = LAPACKE_zpptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00132                                   b_i, ldb_i );
00133 
00134     failed = compare_zpptrs( b, b_i, info, info_i, ldb, nrhs );
00135     if( failed == 0 ) {
00136         printf( "PASSED: column-major middle-level interface to zpptrs\n" );
00137     } else {
00138         printf( "FAILED: column-major middle-level interface to zpptrs\n" );
00139     }
00140 
00141     /* Initialize input data, call the column-major high-level
00142      * interface to LAPACK routine and check the results */
00143     for( i = 0; i < (n*(n+1)/2); i++ ) {
00144         ap_i[i] = ap[i];
00145     }
00146     for( i = 0; i < ldb*nrhs; i++ ) {
00147         b_i[i] = b_save[i];
00148     }
00149     info_i = LAPACKE_zpptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i, b_i,
00150                              ldb_i );
00151 
00152     failed = compare_zpptrs( b, b_i, info, info_i, ldb, nrhs );
00153     if( failed == 0 ) {
00154         printf( "PASSED: column-major high-level interface to zpptrs\n" );
00155     } else {
00156         printf( "FAILED: column-major high-level interface to zpptrs\n" );
00157     }
00158 
00159     /* Initialize input data, call the row-major middle-level
00160      * interface to LAPACK routine and check the results */
00161     for( i = 0; i < (n*(n+1)/2); i++ ) {
00162         ap_i[i] = ap[i];
00163     }
00164     for( i = 0; i < ldb*nrhs; i++ ) {
00165         b_i[i] = b_save[i];
00166     }
00167 
00168     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00169     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00170     info_i = LAPACKE_zpptrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00171                                   b_r, ldb_r );
00172 
00173     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00174 
00175     failed = compare_zpptrs( b, b_i, info, info_i, ldb, nrhs );
00176     if( failed == 0 ) {
00177         printf( "PASSED: row-major middle-level interface to zpptrs\n" );
00178     } else {
00179         printf( "FAILED: row-major middle-level interface to zpptrs\n" );
00180     }
00181 
00182     /* Initialize input data, call the row-major high-level
00183      * interface to LAPACK routine and check the results */
00184     for( i = 0; i < (n*(n+1)/2); i++ ) {
00185         ap_i[i] = ap[i];
00186     }
00187     for( i = 0; i < ldb*nrhs; i++ ) {
00188         b_i[i] = b_save[i];
00189     }
00190 
00191     /* Init row_major arrays */
00192     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00193     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00194     info_i = LAPACKE_zpptrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r, b_r,
00195                              ldb_r );
00196 
00197     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00198 
00199     failed = compare_zpptrs( b, b_i, info, info_i, ldb, nrhs );
00200     if( failed == 0 ) {
00201         printf( "PASSED: row-major high-level interface to zpptrs\n" );
00202     } else {
00203         printf( "FAILED: row-major high-level interface to zpptrs\n" );
00204     }
00205 
00206     /* Release memory */
00207     if( ap != NULL ) {
00208         LAPACKE_free( ap );
00209     }
00210     if( ap_i != NULL ) {
00211         LAPACKE_free( ap_i );
00212     }
00213     if( ap_r != NULL ) {
00214         LAPACKE_free( ap_r );
00215     }
00216     if( b != NULL ) {
00217         LAPACKE_free( b );
00218     }
00219     if( b_i != NULL ) {
00220         LAPACKE_free( b_i );
00221     }
00222     if( b_r != NULL ) {
00223         LAPACKE_free( b_r );
00224     }
00225     if( b_save != NULL ) {
00226         LAPACKE_free( b_save );
00227     }
00228 
00229     return 0;
00230 }
00231 
00232 /* Auxiliary function: zpptrs scalar parameters initialization */
00233 static void init_scalars_zpptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00234                                  lapack_int *ldb )
00235 {
00236     *uplo = 'L';
00237     *n = 4;
00238     *nrhs = 2;
00239     *ldb = 8;
00240 
00241     return;
00242 }
00243 
00244 /* Auxiliary functions: zpptrs array parameters initialization */
00245 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00246     lapack_int i;
00247     for( i = 0; i < size; i++ ) {
00248         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00249     }
00250     ap[0] = lapack_make_complex_double( 1.79722007556114290e+000,
00251                                         0.00000000000000000e+000 );
00252     ap[1] = lapack_make_complex_double( 8.40186474952732460e-001,
00253                                         1.06831657742334190e+000 );
00254     ap[2] = lapack_make_complex_double( 1.05718827974184860e+000,
00255                                         -4.67388502622712030e-001 );
00256     ap[3] = lapack_make_complex_double( 2.33694251311356020e-001,
00257                                         -1.39103721018664310e+000 );
00258     ap[4] = lapack_make_complex_double( 1.31635343950968520e+000,
00259                                         0.00000000000000000e+000 );
00260     ap[5] = lapack_make_complex_double( -4.70174947010632950e-001,
00261                                         3.13065815599946400e-001 );
00262     ap[6] = lapack_make_complex_double( 8.33525092394419580e-002,
00263                                         3.67607144303747430e-002 );
00264     ap[7] = lapack_make_complex_double( 1.56039297713712430e+000,
00265                                         0.00000000000000000e+000 );
00266     ap[8] = lapack_make_complex_double( 9.35961733792340160e-001,
00267                                         9.89969219281573890e-001 );
00268     ap[9] = lapack_make_complex_double( 6.60333297365588770e-001,
00269                                         0.00000000000000000e+000 );
00270 }
00271 static void init_b( lapack_int size, lapack_complex_double *b ) {
00272     lapack_int i;
00273     for( i = 0; i < size; i++ ) {
00274         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00275     }
00276     b[0] = lapack_make_complex_double( 3.93000000000000020e+000,
00277                                        -6.13999999999999970e+000 );
00278     b[8] = lapack_make_complex_double( 1.48000000000000000e+000,
00279                                        6.58000000000000010e+000 );
00280     b[1] = lapack_make_complex_double( 6.16999999999999990e+000,
00281                                        9.41999999999999990e+000 );
00282     b[9] = lapack_make_complex_double( 4.65000000000000040e+000,
00283                                        -4.75000000000000000e+000 );
00284     b[2] = lapack_make_complex_double( -7.16999999999999990e+000,
00285                                        -2.18299999999999980e+001 );
00286     b[10] = lapack_make_complex_double( -4.91000000000000010e+000,
00287                                         2.29000000000000000e+000 );
00288     b[3] = lapack_make_complex_double( 1.99000000000000000e+000,
00289                                        -1.43800000000000010e+001 );
00290     b[11] = lapack_make_complex_double( 7.63999999999999970e+000,
00291                                         -1.07899999999999990e+001 );
00292 }
00293 
00294 /* Auxiliary function: C interface to zpptrs results check */
00295 /* Return value: 0 - test is passed, non-zero - test is failed */
00296 static int compare_zpptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00297                            lapack_int info, lapack_int info_i, lapack_int ldb,
00298                            lapack_int nrhs )
00299 {
00300     lapack_int i;
00301     int failed = 0;
00302     for( i = 0; i < ldb*nrhs; i++ ) {
00303         failed += compare_complex_doubles(b[i],b_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:56:43