strsen_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 * strsen_1 is the test program for the C interface to LAPACK
00036 * routine strsen
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_strsen( char *job, char *compq, lapack_int *n,
00055                                  lapack_int *ldt, lapack_int *ldq,
00056                                  lapack_int *lwork, lapack_int *liwork );
00057 static void init_select( lapack_int size, lapack_int *select );
00058 static void init_t( lapack_int size, float *t );
00059 static void init_q( lapack_int size, float *q );
00060 static void init_wr( lapack_int size, float *wr );
00061 static void init_wi( lapack_int size, float *wi );
00062 static void init_work( lapack_int size, float *work );
00063 static void init_iwork( lapack_int size, lapack_int *iwork );
00064 static int compare_strsen( float *t, float *t_i, float *q, float *q_i,
00065                            float *wr, float *wr_i, float *wi, float *wi_i,
00066                            lapack_int m, lapack_int m_i, float s, float s_i,
00067                            float sep, float sep_i, lapack_int info,
00068                            lapack_int info_i, char compq, lapack_int ldq,
00069                            lapack_int ldt, lapack_int n );
00070 
00071 int main(void)
00072 {
00073     /* Local scalars */
00074     char job, job_i;
00075     char compq, compq_i;
00076     lapack_int n, n_i;
00077     lapack_int ldt, ldt_i;
00078     lapack_int ldt_r;
00079     lapack_int ldq, ldq_i;
00080     lapack_int ldq_r;
00081     lapack_int m, m_i;
00082     float s, s_i;
00083     float sep, sep_i;
00084     lapack_int lwork, lwork_i;
00085     lapack_int liwork, liwork_i;
00086     lapack_int info, info_i;
00087     lapack_int i;
00088     int failed;
00089 
00090     /* Local arrays */
00091     lapack_int *select = NULL, *select_i = NULL;
00092     float *t = NULL, *t_i = NULL;
00093     float *q = NULL, *q_i = NULL;
00094     float *wr = NULL, *wr_i = NULL;
00095     float *wi = NULL, *wi_i = NULL;
00096     float *work = NULL, *work_i = NULL;
00097     lapack_int *iwork = NULL, *iwork_i = NULL;
00098     float *t_save = NULL;
00099     float *q_save = NULL;
00100     float *wr_save = NULL;
00101     float *wi_save = NULL;
00102     float *t_r = NULL;
00103     float *q_r = NULL;
00104 
00105     /* Iniitialize the scalar parameters */
00106     init_scalars_strsen( &job, &compq, &n, &ldt, &ldq, &lwork, &liwork );
00107     ldt_r = n+2;
00108     ldq_r = n+2;
00109     job_i = job;
00110     compq_i = compq;
00111     n_i = n;
00112     ldt_i = ldt;
00113     ldq_i = ldq;
00114     lwork_i = lwork;
00115     liwork_i = liwork;
00116 
00117     /* Allocate memory for the LAPACK routine arrays */
00118     select = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00119     t = (float *)LAPACKE_malloc( ldt*n * sizeof(float) );
00120     q = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00121     wr = (float *)LAPACKE_malloc( n * sizeof(float) );
00122     wi = (float *)LAPACKE_malloc( n * sizeof(float) );
00123     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00124     iwork = (lapack_int *)LAPACKE_malloc( liwork * sizeof(lapack_int) );
00125 
00126     /* Allocate memory for the C interface function arrays */
00127     select_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00128     t_i = (float *)LAPACKE_malloc( ldt*n * sizeof(float) );
00129     q_i = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00130     wr_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00131     wi_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00132     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00133     iwork_i = (lapack_int *)LAPACKE_malloc( liwork * sizeof(lapack_int) );
00134 
00135     /* Allocate memory for the backup arrays */
00136     t_save = (float *)LAPACKE_malloc( ldt*n * sizeof(float) );
00137     q_save = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00138     wr_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00139     wi_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00140 
00141     /* Allocate memory for the row-major arrays */
00142     t_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00143     q_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00144 
00145     /* Initialize input arrays */
00146     init_select( n, select );
00147     init_t( ldt*n, t );
00148     init_q( ldq*n, q );
00149     init_wr( n, wr );
00150     init_wi( n, wi );
00151     init_work( lwork, work );
00152     init_iwork( liwork, iwork );
00153 
00154     /* Backup the ouptut arrays */
00155     for( i = 0; i < ldt*n; i++ ) {
00156         t_save[i] = t[i];
00157     }
00158     for( i = 0; i < ldq*n; i++ ) {
00159         q_save[i] = q[i];
00160     }
00161     for( i = 0; i < n; i++ ) {
00162         wr_save[i] = wr[i];
00163     }
00164     for( i = 0; i < n; i++ ) {
00165         wi_save[i] = wi[i];
00166     }
00167 
00168     /* Call the LAPACK routine */
00169     strsen_( &job, &compq, select, &n, t, &ldt, q, &ldq, wr, wi, &m, &s, &sep,
00170              work, &lwork, iwork, &liwork, &info );
00171 
00172     /* Initialize input data, call the column-major middle-level
00173      * interface to LAPACK routine and check the results */
00174     for( i = 0; i < n; i++ ) {
00175         select_i[i] = select[i];
00176     }
00177     for( i = 0; i < ldt*n; i++ ) {
00178         t_i[i] = t_save[i];
00179     }
00180     for( i = 0; i < ldq*n; i++ ) {
00181         q_i[i] = q_save[i];
00182     }
00183     for( i = 0; i < n; i++ ) {
00184         wr_i[i] = wr_save[i];
00185     }
00186     for( i = 0; i < n; i++ ) {
00187         wi_i[i] = wi_save[i];
00188     }
00189     for( i = 0; i < lwork; i++ ) {
00190         work_i[i] = work[i];
00191     }
00192     for( i = 0; i < liwork; i++ ) {
00193         iwork_i[i] = iwork[i];
00194     }
00195     info_i = LAPACKE_strsen_work( LAPACK_COL_MAJOR, job_i, compq_i, select_i,
00196                                   n_i, t_i, ldt_i, q_i, ldq_i, wr_i, wi_i, &m_i,
00197                                   &s_i, &sep_i, work_i, lwork_i, iwork_i,
00198                                   liwork_i );
00199 
00200     failed = compare_strsen( t, t_i, q, q_i, wr, wr_i, wi, wi_i, m, m_i, s, s_i,
00201                              sep, sep_i, info, info_i, compq, ldq, ldt, n );
00202     if( failed == 0 ) {
00203         printf( "PASSED: column-major middle-level interface to strsen\n" );
00204     } else {
00205         printf( "FAILED: column-major middle-level interface to strsen\n" );
00206     }
00207 
00208     /* Initialize input data, call the column-major high-level
00209      * interface to LAPACK routine and check the results */
00210     for( i = 0; i < n; i++ ) {
00211         select_i[i] = select[i];
00212     }
00213     for( i = 0; i < ldt*n; i++ ) {
00214         t_i[i] = t_save[i];
00215     }
00216     for( i = 0; i < ldq*n; i++ ) {
00217         q_i[i] = q_save[i];
00218     }
00219     for( i = 0; i < n; i++ ) {
00220         wr_i[i] = wr_save[i];
00221     }
00222     for( i = 0; i < n; i++ ) {
00223         wi_i[i] = wi_save[i];
00224     }
00225     for( i = 0; i < lwork; i++ ) {
00226         work_i[i] = work[i];
00227     }
00228     for( i = 0; i < liwork; i++ ) {
00229         iwork_i[i] = iwork[i];
00230     }
00231     info_i = LAPACKE_strsen( LAPACK_COL_MAJOR, job_i, compq_i, select_i, n_i,
00232                              t_i, ldt_i, q_i, ldq_i, wr_i, wi_i, &m_i, &s_i,
00233                              &sep_i );
00234 
00235     failed = compare_strsen( t, t_i, q, q_i, wr, wr_i, wi, wi_i, m, m_i, s, s_i,
00236                              sep, sep_i, info, info_i, compq, ldq, ldt, n );
00237     if( failed == 0 ) {
00238         printf( "PASSED: column-major high-level interface to strsen\n" );
00239     } else {
00240         printf( "FAILED: column-major high-level interface to strsen\n" );
00241     }
00242 
00243     /* Initialize input data, call the row-major middle-level
00244      * interface to LAPACK routine and check the results */
00245     for( i = 0; i < n; i++ ) {
00246         select_i[i] = select[i];
00247     }
00248     for( i = 0; i < ldt*n; i++ ) {
00249         t_i[i] = t_save[i];
00250     }
00251     for( i = 0; i < ldq*n; i++ ) {
00252         q_i[i] = q_save[i];
00253     }
00254     for( i = 0; i < n; i++ ) {
00255         wr_i[i] = wr_save[i];
00256     }
00257     for( i = 0; i < n; i++ ) {
00258         wi_i[i] = wi_save[i];
00259     }
00260     for( i = 0; i < lwork; i++ ) {
00261         work_i[i] = work[i];
00262     }
00263     for( i = 0; i < liwork; i++ ) {
00264         iwork_i[i] = iwork[i];
00265     }
00266 
00267     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
00268     if( LAPACKE_lsame( compq, 'v' ) ) {
00269         LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00270     }
00271     info_i = LAPACKE_strsen_work( LAPACK_ROW_MAJOR, job_i, compq_i, select_i,
00272                                   n_i, t_r, ldt_r, q_r, ldq_r, wr_i, wi_i, &m_i,
00273                                   &s_i, &sep_i, work_i, lwork_i, iwork_i,
00274                                   liwork_i );
00275 
00276     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
00277     if( LAPACKE_lsame( compq, 'v' ) ) {
00278         LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00279     }
00280 
00281     failed = compare_strsen( t, t_i, q, q_i, wr, wr_i, wi, wi_i, m, m_i, s, s_i,
00282                              sep, sep_i, info, info_i, compq, ldq, ldt, n );
00283     if( failed == 0 ) {
00284         printf( "PASSED: row-major middle-level interface to strsen\n" );
00285     } else {
00286         printf( "FAILED: row-major middle-level interface to strsen\n" );
00287     }
00288 
00289     /* Initialize input data, call the row-major high-level
00290      * interface to LAPACK routine and check the results */
00291     for( i = 0; i < n; i++ ) {
00292         select_i[i] = select[i];
00293     }
00294     for( i = 0; i < ldt*n; i++ ) {
00295         t_i[i] = t_save[i];
00296     }
00297     for( i = 0; i < ldq*n; i++ ) {
00298         q_i[i] = q_save[i];
00299     }
00300     for( i = 0; i < n; i++ ) {
00301         wr_i[i] = wr_save[i];
00302     }
00303     for( i = 0; i < n; i++ ) {
00304         wi_i[i] = wi_save[i];
00305     }
00306     for( i = 0; i < lwork; i++ ) {
00307         work_i[i] = work[i];
00308     }
00309     for( i = 0; i < liwork; i++ ) {
00310         iwork_i[i] = iwork[i];
00311     }
00312 
00313     /* Init row_major arrays */
00314     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
00315     if( LAPACKE_lsame( compq, 'v' ) ) {
00316         LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00317     }
00318     info_i = LAPACKE_strsen( LAPACK_ROW_MAJOR, job_i, compq_i, select_i, n_i,
00319                              t_r, ldt_r, q_r, ldq_r, wr_i, wi_i, &m_i, &s_i,
00320                              &sep_i );
00321 
00322     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
00323     if( LAPACKE_lsame( compq, 'v' ) ) {
00324         LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00325     }
00326 
00327     failed = compare_strsen( t, t_i, q, q_i, wr, wr_i, wi, wi_i, m, m_i, s, s_i,
00328                              sep, sep_i, info, info_i, compq, ldq, ldt, n );
00329     if( failed == 0 ) {
00330         printf( "PASSED: row-major high-level interface to strsen\n" );
00331     } else {
00332         printf( "FAILED: row-major high-level interface to strsen\n" );
00333     }
00334 
00335     /* Release memory */
00336     if( select != NULL ) {
00337         LAPACKE_free( select );
00338     }
00339     if( select_i != NULL ) {
00340         LAPACKE_free( select_i );
00341     }
00342     if( t != NULL ) {
00343         LAPACKE_free( t );
00344     }
00345     if( t_i != NULL ) {
00346         LAPACKE_free( t_i );
00347     }
00348     if( t_r != NULL ) {
00349         LAPACKE_free( t_r );
00350     }
00351     if( t_save != NULL ) {
00352         LAPACKE_free( t_save );
00353     }
00354     if( q != NULL ) {
00355         LAPACKE_free( q );
00356     }
00357     if( q_i != NULL ) {
00358         LAPACKE_free( q_i );
00359     }
00360     if( q_r != NULL ) {
00361         LAPACKE_free( q_r );
00362     }
00363     if( q_save != NULL ) {
00364         LAPACKE_free( q_save );
00365     }
00366     if( wr != NULL ) {
00367         LAPACKE_free( wr );
00368     }
00369     if( wr_i != NULL ) {
00370         LAPACKE_free( wr_i );
00371     }
00372     if( wr_save != NULL ) {
00373         LAPACKE_free( wr_save );
00374     }
00375     if( wi != NULL ) {
00376         LAPACKE_free( wi );
00377     }
00378     if( wi_i != NULL ) {
00379         LAPACKE_free( wi_i );
00380     }
00381     if( wi_save != NULL ) {
00382         LAPACKE_free( wi_save );
00383     }
00384     if( work != NULL ) {
00385         LAPACKE_free( work );
00386     }
00387     if( work_i != NULL ) {
00388         LAPACKE_free( work_i );
00389     }
00390     if( iwork != NULL ) {
00391         LAPACKE_free( iwork );
00392     }
00393     if( iwork_i != NULL ) {
00394         LAPACKE_free( iwork_i );
00395     }
00396 
00397     return 0;
00398 }
00399 
00400 /* Auxiliary function: strsen scalar parameters initialization */
00401 static void init_scalars_strsen( char *job, char *compq, lapack_int *n,
00402                                  lapack_int *ldt, lapack_int *ldq,
00403                                  lapack_int *lwork, lapack_int *liwork )
00404 {
00405     *job = 'B';
00406     *compq = 'V';
00407     *n = 4;
00408     *ldt = 8;
00409     *ldq = 8;
00410     *lwork = 32;
00411     *liwork = 32;
00412 
00413     return;
00414 }
00415 
00416 /* Auxiliary functions: strsen array parameters initialization */
00417 static void init_select( lapack_int size, lapack_int *select ) {
00418     lapack_int i;
00419     for( i = 0; i < size; i++ ) {
00420         select[i] = 0;
00421     }
00422     select[0] = -1;
00423     select[1] = 0;
00424     select[2] = 0;
00425     select[3] = -1;
00426 }
00427 static void init_t( lapack_int size, float *t ) {
00428     lapack_int i;
00429     for( i = 0; i < size; i++ ) {
00430         t[i] = 0;
00431     }
00432     t[0] = 7.994999886e-001;  /* t[0,0] */
00433     t[8] = -1.143999994e-001;  /* t[0,1] */
00434     t[16] = 6.000000052e-003;  /* t[0,2] */
00435     t[24] = 3.359999880e-002;  /* t[0,3] */
00436     t[1] = 0.000000000e+000;  /* t[1,0] */
00437     t[9] = -9.939999878e-002;  /* t[1,1] */
00438     t[17] = 2.477999926e-001;  /* t[1,2] */
00439     t[25] = 3.474000096e-001;  /* t[1,3] */
00440     t[2] = 0.000000000e+000;  /* t[2,0] */
00441     t[10] = -6.482999921e-001;  /* t[2,1] */
00442     t[18] = -9.939999878e-002;  /* t[2,2] */
00443     t[26] = 2.026000023e-001;  /* t[2,3] */
00444     t[3] = 0.000000000e+000;  /* t[3,0] */
00445     t[11] = 0.000000000e+000;  /* t[3,1] */
00446     t[19] = 0.000000000e+000;  /* t[3,2] */
00447     t[27] = -1.006999984e-001;  /* t[3,3] */
00448 }
00449 static void init_q( lapack_int size, float *q ) {
00450     lapack_int i;
00451     for( i = 0; i < size; i++ ) {
00452         q[i] = 0;
00453     }
00454     q[0] = 6.550999880e-001;  /* q[0,0] */
00455     q[8] = 1.036999971e-001;  /* q[0,1] */
00456     q[16] = 3.449999988e-001;  /* q[0,2] */
00457     q[24] = 6.640999913e-001;  /* q[0,3] */
00458     q[1] = 5.235999823e-001;  /* q[1,0] */
00459     q[9] = -5.806999803e-001;  /* q[1,1] */
00460     q[17] = -6.140999794e-001;  /* q[1,2] */
00461     q[25] = -1.067999974e-001;  /* q[1,3] */
00462     q[2] = -5.361999869e-001;  /* q[2,0] */
00463     q[10] = -3.073000014e-001;  /* q[2,1] */
00464     q[18] = -2.935000062e-001;  /* q[2,2] */
00465     q[26] = 7.293000221e-001;  /* q[2,3] */
00466     q[3] = 9.560000151e-002;  /* q[3,0] */
00467     q[11] = 7.466999888e-001;  /* q[3,1] */
00468     q[19] = -6.463000178e-001;  /* q[3,2] */
00469     q[27] = 1.248999983e-001;  /* q[3,3] */
00470 }
00471 static void init_wr( lapack_int size, float *wr ) {
00472     lapack_int i;
00473     for( i = 0; i < size; i++ ) {
00474         wr[i] = 0;
00475     }
00476 }
00477 static void init_wi( lapack_int size, float *wi ) {
00478     lapack_int i;
00479     for( i = 0; i < size; i++ ) {
00480         wi[i] = 0;
00481     }
00482 }
00483 static void init_work( lapack_int size, float *work ) {
00484     lapack_int i;
00485     for( i = 0; i < size; i++ ) {
00486         work[i] = 0;
00487     }
00488 }
00489 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00490     lapack_int i;
00491     for( i = 0; i < size; i++ ) {
00492         iwork[i] = 0;
00493     }
00494 }
00495 
00496 /* Auxiliary function: C interface to strsen results check */
00497 /* Return value: 0 - test is passed, non-zero - test is failed */
00498 static int compare_strsen( float *t, float *t_i, float *q, float *q_i,
00499                            float *wr, float *wr_i, float *wi, float *wi_i,
00500                            lapack_int m, lapack_int m_i, float s, float s_i,
00501                            float sep, float sep_i, lapack_int info,
00502                            lapack_int info_i, char compq, lapack_int ldq,
00503                            lapack_int ldt, lapack_int n )
00504 {
00505     lapack_int i;
00506     int failed = 0;
00507     for( i = 0; i < ldt*n; i++ ) {
00508         failed += compare_floats(t[i],t_i[i]);
00509     }
00510     if( LAPACKE_lsame( compq, 'v' ) ) {
00511         for( i = 0; i < ldq*n; i++ ) {
00512             failed += compare_floats(q[i],q_i[i]);
00513         }
00514     }
00515     for( i = 0; i < n; i++ ) {
00516         failed += compare_floats(wr[i],wr_i[i]);
00517     }
00518     for( i = 0; i < n; i++ ) {
00519         failed += compare_floats(wi[i],wi_i[i]);
00520     }
00521     failed += (m == m_i) ? 0 : 1;
00522     failed += compare_floats(s,s_i);
00523     failed += compare_floats(sep,sep_i);
00524     failed += (info == info_i) ? 0 : 1;
00525     if( info != 0 || info_i != 0 ) {
00526         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00527     }
00528 
00529     return failed;
00530 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:15