lapack_int LAPACKE_spotrf( int matrix_layout, char uplo, lapack_int n, float* a, lapack_int lda ) { if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_spotrf", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_spo_nancheck( matrix_layout, uplo, n, a, lda ) ) { return -4; } #endif return LAPACKE_spotrf_work( matrix_layout, uplo, n, a, lda ); }
int main(void) { /* Local scalars */ char uplo, uplo_i; lapack_int n, n_i; lapack_int lda, lda_i; lapack_int lda_r; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ float *a = NULL, *a_i = NULL; float *a_save = NULL; float *a_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_spotrf( &uplo, &n, &lda ); lda_r = n+2; uplo_i = uplo; n_i = n; lda_i = lda; /* Allocate memory for the LAPACK routine arrays */ a = (float *)LAPACKE_malloc( lda*n * sizeof(float) ); /* Allocate memory for the C interface function arrays */ a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) ); /* Allocate memory for the backup arrays */ a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) ); /* Allocate memory for the row-major arrays */ a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) ); /* Initialize input arrays */ init_a( lda*n, a ); /* Backup the ouptut arrays */ for( i = 0; i < lda*n; i++ ) { a_save[i] = a[i]; } /* Call the LAPACK routine */ spotrf_( &uplo, &n, a, &lda, &info ); /* Initialize input data, call the column-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } info_i = LAPACKE_spotrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i ); failed = compare_spotrf( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to spotrf\n" ); } else { printf( "FAILED: column-major middle-level interface to spotrf\n" ); } /* Initialize input data, call the column-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } info_i = LAPACKE_spotrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i ); failed = compare_spotrf( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to spotrf\n" ); } else { printf( "FAILED: column-major high-level interface to spotrf\n" ); } /* Initialize input data, call the row-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_spotrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r ); LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda ); failed = compare_spotrf( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to spotrf\n" ); } else { printf( "FAILED: row-major middle-level interface to spotrf\n" ); } /* Initialize input data, call the row-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } /* Init row_major arrays */ LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_spotrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r ); LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda ); failed = compare_spotrf( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to spotrf\n" ); } else { printf( "FAILED: row-major high-level interface to spotrf\n" ); } /* Release memory */ if( a != NULL ) { LAPACKE_free( a ); } if( a_i != NULL ) { LAPACKE_free( a_i ); } if( a_r != NULL ) { LAPACKE_free( a_r ); } if( a_save != NULL ) { LAPACKE_free( a_save ); } return 0; }