lapack_int LAPACKE_dsygst( int matrix_layout, lapack_int itype, char uplo, lapack_int n, double* a, lapack_int lda, const double* b, lapack_int ldb ) { if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_dsygst", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_dsy_nancheck( matrix_layout, uplo, n, a, lda ) ) { return -5; } if( LAPACKE_dge_nancheck( matrix_layout, n, n, b, ldb ) ) { return -7; } #endif return LAPACKE_dsygst_work( matrix_layout, itype, uplo, n, a, lda, b, ldb ); }
int main(void) { /* Local scalars */ lapack_int itype, itype_i; char uplo, uplo_i; lapack_int n, n_i; lapack_int lda, lda_i; lapack_int lda_r; lapack_int ldb, ldb_i; lapack_int ldb_r; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ double *a = NULL, *a_i = NULL; double *b = NULL, *b_i = NULL; double *a_save = NULL; double *a_r = NULL; double *b_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_dsygst( &itype, &uplo, &n, &lda, &ldb ); lda_r = n+2; ldb_r = n+2; itype_i = itype; uplo_i = uplo; n_i = n; lda_i = lda; ldb_i = ldb; /* Allocate memory for the LAPACK routine arrays */ a = (double *)LAPACKE_malloc( lda*n * sizeof(double) ); b = (double *)LAPACKE_malloc( ldb*n * sizeof(double) ); /* Allocate memory for the C interface function arrays */ a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) ); b_i = (double *)LAPACKE_malloc( ldb*n * sizeof(double) ); /* Allocate memory for the backup arrays */ a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) ); /* Allocate memory for the row-major arrays */ a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) ); b_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) ); /* Initialize input arrays */ init_a( lda*n, a ); init_b( ldb*n, b ); /* Backup the ouptut arrays */ for( i = 0; i < lda*n; i++ ) { a_save[i] = a[i]; } /* Call the LAPACK routine */ dsygst_( &itype, &uplo, &n, a, &lda, b, &ldb, &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]; } for( i = 0; i < ldb*n; i++ ) { b_i[i] = b[i]; } info_i = LAPACKE_dsygst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i, lda_i, b_i, ldb_i ); failed = compare_dsygst( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to dsygst\n" ); } else { printf( "FAILED: column-major middle-level interface to dsygst\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]; } for( i = 0; i < ldb*n; i++ ) { b_i[i] = b[i]; } info_i = LAPACKE_dsygst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i, lda_i, b_i, ldb_i ); failed = compare_dsygst( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to dsygst\n" ); } else { printf( "FAILED: column-major high-level interface to dsygst\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]; } for( i = 0; i < ldb*n; i++ ) { b_i[i] = b[i]; } LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 ); info_i = LAPACKE_dsygst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r, lda_r, b_r, ldb_r ); LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda ); failed = compare_dsygst( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to dsygst\n" ); } else { printf( "FAILED: row-major middle-level interface to dsygst\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]; } for( i = 0; i < ldb*n; i++ ) { b_i[i] = b[i]; } /* Init row_major arrays */ LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 ); info_i = LAPACKE_dsygst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r, lda_r, b_r, ldb_r ); LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda ); failed = compare_dsygst( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to dsygst\n" ); } else { printf( "FAILED: row-major high-level interface to dsygst\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 ); } if( b != NULL ) { LAPACKE_free( b ); } if( b_i != NULL ) { LAPACKE_free( b_i ); } if( b_r != NULL ) { LAPACKE_free( b_r ); } return 0; }