cupgtr_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 * cupgtr_1 is the test program for the C interface to LAPACK
00036 * routine cupgtr
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_cupgtr( char *uplo, lapack_int *n, lapack_int *ldq );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_tau( lapack_int size, lapack_complex_float *tau );
00057 static void init_q( lapack_int size, lapack_complex_float *q );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_cupgtr( lapack_complex_float *q, lapack_complex_float *q_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldq,
00061                            lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int ldq, ldq_i;
00069     lapack_int ldq_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     lapack_complex_float *ap = NULL, *ap_i = NULL;
00076     lapack_complex_float *tau = NULL, *tau_i = NULL;
00077     lapack_complex_float *q = NULL, *q_i = NULL;
00078     lapack_complex_float *work = NULL, *work_i = NULL;
00079     lapack_complex_float *q_save = NULL;
00080     lapack_complex_float *ap_r = NULL;
00081     lapack_complex_float *q_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_cupgtr( &uplo, &n, &ldq );
00085     ldq_r = n+2;
00086     uplo_i = uplo;
00087     n_i = n;
00088     ldq_i = ldq;
00089 
00090     /* Allocate memory for the LAPACK routine arrays */
00091     ap = (lapack_complex_float *)
00092         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00093     tau = (lapack_complex_float *)
00094         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00095     q = (lapack_complex_float *)
00096         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00097     work = (lapack_complex_float *)
00098         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     ap_i = (lapack_complex_float *)
00102         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00103     tau_i = (lapack_complex_float *)
00104         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00105     q_i = (lapack_complex_float *)
00106         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00107     work_i = (lapack_complex_float *)
00108         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00109 
00110     /* Allocate memory for the backup arrays */
00111     q_save = (lapack_complex_float *)
00112         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00113 
00114     /* Allocate memory for the row-major arrays */
00115     ap_r = (lapack_complex_float *)
00116         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00117     q_r = (lapack_complex_float *)
00118         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00119 
00120     /* Initialize input arrays */
00121     init_ap( (n*(n+1)/2), ap );
00122     init_tau( (n-1), tau );
00123     init_q( ldq*n, q );
00124     init_work( (n-1), work );
00125 
00126     /* Backup the ouptut arrays */
00127     for( i = 0; i < ldq*n; i++ ) {
00128         q_save[i] = q[i];
00129     }
00130 
00131     /* Call the LAPACK routine */
00132     cupgtr_( &uplo, &n, ap, tau, q, &ldq, work, &info );
00133 
00134     /* Initialize input data, call the column-major middle-level
00135      * interface to LAPACK routine and check the results */
00136     for( i = 0; i < (n*(n+1)/2); i++ ) {
00137         ap_i[i] = ap[i];
00138     }
00139     for( i = 0; i < (n-1); i++ ) {
00140         tau_i[i] = tau[i];
00141     }
00142     for( i = 0; i < ldq*n; i++ ) {
00143         q_i[i] = q_save[i];
00144     }
00145     for( i = 0; i < (n-1); i++ ) {
00146         work_i[i] = work[i];
00147     }
00148     info_i = LAPACKE_cupgtr_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i,
00149                                   q_i, ldq_i, work_i );
00150 
00151     failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major middle-level interface to cupgtr\n" );
00154     } else {
00155         printf( "FAILED: column-major middle-level interface to cupgtr\n" );
00156     }
00157 
00158     /* Initialize input data, call the column-major high-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[i];
00162     }
00163     for( i = 0; i < (n-1); i++ ) {
00164         tau_i[i] = tau[i];
00165     }
00166     for( i = 0; i < ldq*n; i++ ) {
00167         q_i[i] = q_save[i];
00168     }
00169     for( i = 0; i < (n-1); i++ ) {
00170         work_i[i] = work[i];
00171     }
00172     info_i = LAPACKE_cupgtr( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i, q_i,
00173                              ldq_i );
00174 
00175     failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major high-level interface to cupgtr\n" );
00178     } else {
00179         printf( "FAILED: column-major high-level interface to cupgtr\n" );
00180     }
00181 
00182     /* Initialize input data, call the row-major middle-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 < (n-1); i++ ) {
00188         tau_i[i] = tau[i];
00189     }
00190     for( i = 0; i < ldq*n; i++ ) {
00191         q_i[i] = q_save[i];
00192     }
00193     for( i = 0; i < (n-1); i++ ) {
00194         work_i[i] = work[i];
00195     }
00196 
00197     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00199     info_i = LAPACKE_cupgtr_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i,
00200                                   q_r, ldq_r, work_i );
00201 
00202     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00203 
00204     failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00205     if( failed == 0 ) {
00206         printf( "PASSED: row-major middle-level interface to cupgtr\n" );
00207     } else {
00208         printf( "FAILED: row-major middle-level interface to cupgtr\n" );
00209     }
00210 
00211     /* Initialize input data, call the row-major high-level
00212      * interface to LAPACK routine and check the results */
00213     for( i = 0; i < (n*(n+1)/2); i++ ) {
00214         ap_i[i] = ap[i];
00215     }
00216     for( i = 0; i < (n-1); i++ ) {
00217         tau_i[i] = tau[i];
00218     }
00219     for( i = 0; i < ldq*n; i++ ) {
00220         q_i[i] = q_save[i];
00221     }
00222     for( i = 0; i < (n-1); i++ ) {
00223         work_i[i] = work[i];
00224     }
00225 
00226     /* Init row_major arrays */
00227     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00229     info_i = LAPACKE_cupgtr( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i, q_r,
00230                              ldq_r );
00231 
00232     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00233 
00234     failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00235     if( failed == 0 ) {
00236         printf( "PASSED: row-major high-level interface to cupgtr\n" );
00237     } else {
00238         printf( "FAILED: row-major high-level interface to cupgtr\n" );
00239     }
00240 
00241     /* Release memory */
00242     if( ap != NULL ) {
00243         LAPACKE_free( ap );
00244     }
00245     if( ap_i != NULL ) {
00246         LAPACKE_free( ap_i );
00247     }
00248     if( ap_r != NULL ) {
00249         LAPACKE_free( ap_r );
00250     }
00251     if( tau != NULL ) {
00252         LAPACKE_free( tau );
00253     }
00254     if( tau_i != NULL ) {
00255         LAPACKE_free( tau_i );
00256     }
00257     if( q != NULL ) {
00258         LAPACKE_free( q );
00259     }
00260     if( q_i != NULL ) {
00261         LAPACKE_free( q_i );
00262     }
00263     if( q_r != NULL ) {
00264         LAPACKE_free( q_r );
00265     }
00266     if( q_save != NULL ) {
00267         LAPACKE_free( q_save );
00268     }
00269     if( work != NULL ) {
00270         LAPACKE_free( work );
00271     }
00272     if( work_i != NULL ) {
00273         LAPACKE_free( work_i );
00274     }
00275 
00276     return 0;
00277 }
00278 
00279 /* Auxiliary function: cupgtr scalar parameters initialization */
00280 static void init_scalars_cupgtr( char *uplo, lapack_int *n, lapack_int *ldq )
00281 {
00282     *uplo = 'L';
00283     *n = 4;
00284     *ldq = 8;
00285 
00286     return;
00287 }
00288 
00289 /* Auxiliary functions: cupgtr array parameters initialization */
00290 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00291     lapack_int i;
00292     for( i = 0; i < size; i++ ) {
00293         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00294     }
00295     ap[0] = lapack_make_complex_float( -2.279999971e+000, 0.000000000e+000 );
00296     ap[1] = lapack_make_complex_float( -4.338455677e+000, 0.000000000e+000 );
00297     ap[2] = lapack_make_complex_float( 3.278606534e-001, -1.251226068e-001 );
00298     ap[3] = lapack_make_complex_float( -1.412565559e-001, -3.666364849e-001 );
00299     ap[4] = lapack_make_complex_float( -1.284568310e-001, 0.000000000e+000 );
00300     ap[5] = lapack_make_complex_float( -2.022594690e+000, 0.000000000e+000 );
00301     ap[6] = lapack_make_complex_float( -3.083218634e-001, 1.763225943e-001 );
00302     ap[7] = lapack_make_complex_float( -1.665935516e-001, 0.000000000e+000 );
00303     ap[8] = lapack_make_complex_float( -1.802322745e+000, 0.000000000e+000 );
00304     ap[9] = lapack_make_complex_float( -1.924949646e+000, 0.000000000e+000 );
00305 }
00306 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00307     lapack_int i;
00308     for( i = 0; i < size; i++ ) {
00309         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00310     }
00311     tau[0] = lapack_make_complex_float( 1.410284281e+000, 4.679084122e-001 );
00312     tau[1] = lapack_make_complex_float( 1.302420378e+000, 7.853320837e-001 );
00313     tau[2] = lapack_make_complex_float( 1.093973756e+000, -9.955747128e-001 );
00314 }
00315 static void init_q( lapack_int size, lapack_complex_float *q ) {
00316     lapack_int i;
00317     for( i = 0; i < size; i++ ) {
00318         q[i] = lapack_make_complex_float( 0.0f, 0.0f );
00319     }
00320 }
00321 static void init_work( lapack_int size, lapack_complex_float *work ) {
00322     lapack_int i;
00323     for( i = 0; i < size; i++ ) {
00324         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00325     }
00326 }
00327 
00328 /* Auxiliary function: C interface to cupgtr results check */
00329 /* Return value: 0 - test is passed, non-zero - test is failed */
00330 static int compare_cupgtr( lapack_complex_float *q, lapack_complex_float *q_i,
00331                            lapack_int info, lapack_int info_i, lapack_int ldq,
00332                            lapack_int n )
00333 {
00334     lapack_int i;
00335     int failed = 0;
00336     for( i = 0; i < ldq*n; i++ ) {
00337         failed += compare_complex_floats(q[i],q_i[i]);
00338     }
00339     failed += (info == info_i) ? 0 : 1;
00340     if( info != 0 || info_i != 0 ) {
00341         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00342     }
00343 
00344     return failed;
00345 }


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