diff --git a/tests/spm_tests.h b/tests/spm_tests.h index 758c720c5bd28fb4e628cb64658e35a996dfe9b4..f742e181cd35ca0ee343bd500e4151509bece4a1 100644 --- a/tests/spm_tests.h +++ b/tests/spm_tests.h @@ -87,4 +87,18 @@ void s_spm_print_check( char *filename, const spmatrix_t *spm ); int s_spm_matvec_check( int trans, const spmatrix_t *spm ); int s_spm_norm_check( const spmatrix_t *spm ); +static inline +void spm_norm_print_result( double norms, double normd, double result ) +{ + if ( (result >= 0.) && (result < 1.) ) { + printf("SUCCESS !\n"); + } else { + printf("FAILED !\n"); + ret++; + } + + printf(" Nsparse = %e, Ndense = %e\n", norms, normd ); + printf(" | Nsparse - Ndense | / Ndense = %e\n", result); +} + #endif /* _spm_tests_h_ */ diff --git a/tests/z_spm_tests.c b/tests/z_spm_tests.c index 6d74e8f894bb6ce1e8c0f79426d679e3ab988066..71c58b2b51908821bf2868b47f53bbbab3ccc734 100644 --- a/tests/z_spm_tests.c +++ b/tests/z_spm_tests.c @@ -204,16 +204,7 @@ z_spm_norm_check( const spmatrix_t *spm ) norms = spmNorm( SpmMaxNorm, spm ); normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'M', spm->gNexp, spm->gNexp, A, spm->gNexp ); result = fabs(norms - normd) / (normd * eps); - - if ( (result >= 0.) && (result < 1.) ) { - printf("SUCCESS !\n"); - } else { - printf("FAILED !\n"); - ret++; - } - - printf(" Nsparse = %e, Ndense = %e\n", norms, normd ); - printf(" | Nsparse - Ndense | / Ndense = %e\n", result); + spm_norm_print_result( norms, normd, result ); /** * Test Norm Inf @@ -223,16 +214,7 @@ z_spm_norm_check( const spmatrix_t *spm ) normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->gNexp, spm->gNexp, A, spm->gNexp ); result = fabs(norms - normd) / (normd * eps); result = result * ((double)(spm->gNexp)) / ((double)(spm->gnnzexp)); - - if ( (result >= 0.) && (result < 1.) ) { - printf("SUCCESS !\n"); - } else { - printf("FAILED !\n"); - ret++; - } - - printf(" Nsparse = %e, Ndense = %e\n", norms, normd ); - printf(" | Nsparse - Ndense | / Ndense = %e\n", result); + spm_norm_print_result( norms, normd, result ); /** * Test Norm One @@ -242,16 +224,7 @@ z_spm_norm_check( const spmatrix_t *spm ) normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'O', spm->gNexp, spm->gNexp, A, spm->gNexp ); result = fabs(norms - normd) / (normd * eps); result = result * ((double)(spm->gNexp)) / ((double)(spm->gnnzexp)); - - if ( (result >= 0.) && (result < 1.) ) { - printf("SUCCESS !\n"); - } else { - printf("FAILED !\n"); - ret++; - } - - printf(" Nsparse = %e, Ndense = %e\n", norms, normd ); - printf(" | Nsparse - Ndense | / Ndense = %e\n", result); + spm_norm_print_result( norms, normd, result ); /** * Test Norm Frobenius @@ -261,16 +234,7 @@ z_spm_norm_check( const spmatrix_t *spm ) normd = LAPACKE_zlange( LAPACK_COL_MAJOR, 'F', spm->gNexp, spm->gNexp, A, spm->gNexp ); result = fabs(norms - normd) / (normd * eps); result = result / ((double)spm->gnnzexp); - - if ( (result >= 0.) && (result < 1.) ) { - printf("SUCCESS !\n"); - } else { - printf("FAILED !\n"); - ret++; - } - - printf(" Nsparse = %e, Ndense = %e\n", norms, normd ); - printf(" | Nsparse - Ndense | / Ndense = %e\n", result); + spm_norm_print_result( norms, normd, result ); free(A); return ret;