lapack_int LAPACKE_dorglq( int matrix_layout, lapack_int m, lapack_int n, lapack_int k, double* a, lapack_int lda, const double* tau ) { lapack_int info = 0; lapack_int lwork = -1; double* work = NULL; double work_query; if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_dorglq", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_dge_nancheck( matrix_layout, m, n, a, lda ) ) { return -5; } if( LAPACKE_d_nancheck( k, tau, 1 ) ) { return -7; } #endif /* Query optimal working array(s) size */ info = LAPACKE_dorglq_work( matrix_layout, m, n, k, a, lda, tau, &work_query, lwork ); if( info != 0 ) { goto exit_level_0; } lwork = (lapack_int)work_query; /* Allocate memory for work arrays */ work = (double*)LAPACKE_malloc( sizeof(double) * lwork ); if( work == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_0; } /* Call middle-level interface */ info = LAPACKE_dorglq_work( matrix_layout, m, n, k, a, lda, tau, work, lwork ); /* Release memory and exit */ LAPACKE_free( work ); exit_level_0: if( info == LAPACK_WORK_MEMORY_ERROR ) { LAPACKE_xerbla( "LAPACKE_dorglq", info ); } return info; }
int main(void) { /* Local scalars */ lapack_int m, m_i; lapack_int n, n_i; lapack_int k, k_i; lapack_int lda, lda_i; lapack_int lda_r; lapack_int lwork, lwork_i; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ double *a = NULL, *a_i = NULL; double *tau = NULL, *tau_i = NULL; double *work = NULL, *work_i = NULL; double *a_save = NULL; double *a_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_dorglq( &m, &n, &k, &lda, &lwork ); lda_r = n+2; m_i = m; n_i = n; k_i = k; lda_i = lda; lwork_i = lwork; /* Allocate memory for the LAPACK routine arrays */ a = (double *)LAPACKE_malloc( lda*n * sizeof(double) ); tau = (double *)LAPACKE_malloc( k * sizeof(double) ); work = (double *)LAPACKE_malloc( lwork * sizeof(double) ); /* Allocate memory for the C interface function arrays */ a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) ); tau_i = (double *)LAPACKE_malloc( k * sizeof(double) ); work_i = (double *)LAPACKE_malloc( lwork * 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( m*(n+2) * sizeof(double) ); /* Initialize input arrays */ init_a( lda*n, a ); init_tau( k, tau ); init_work( lwork, work ); /* Backup the ouptut arrays */ for( i = 0; i < lda*n; i++ ) { a_save[i] = a[i]; } /* Call the LAPACK routine */ dorglq_( &m, &n, &k, a, &lda, tau, work, &lwork, &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 < k; i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } info_i = LAPACKE_dorglq_work( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i, tau_i, work_i, lwork_i ); failed = compare_dorglq( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to dorglq\n" ); } else { printf( "FAILED: column-major middle-level interface to dorglq\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 < k; i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } info_i = LAPACKE_dorglq( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i, tau_i ); failed = compare_dorglq( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to dorglq\n" ); } else { printf( "FAILED: column-major high-level interface to dorglq\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 < k; i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_dorglq_work( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r, tau_i, work_i, lwork_i ); LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda ); failed = compare_dorglq( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to dorglq\n" ); } else { printf( "FAILED: row-major middle-level interface to dorglq\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 < k; i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } /* Init row_major arrays */ LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_dorglq( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r, tau_i ); LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda ); failed = compare_dorglq( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to dorglq\n" ); } else { printf( "FAILED: row-major high-level interface to dorglq\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( tau != NULL ) { LAPACKE_free( tau ); } if( tau_i != NULL ) { LAPACKE_free( tau_i ); } if( work != NULL ) { LAPACKE_free( work ); } if( work_i != NULL ) { LAPACKE_free( work_i ); } return 0; }