PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lapacke/src/lapacke_dggevx.c

https://bitbucket.org/iricpt/lapack
C | 121 lines | 82 code | 2 blank | 37 comment | 25 complexity | 60444132078f1e293e8796da06e04cdf MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*****************************************************************************
  2. Copyright (c) 2014, Intel Corp.
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Intel Corporation nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. THE POSSIBILITY OF SUCH DAMAGE.
  25. *****************************************************************************
  26. * Contents: Native high-level C interface to LAPACK function dggevx
  27. * Author: Intel Corporation
  28. *****************************************************************************/
  29. #include "lapacke_utils.h"
  30. lapack_int LAPACKE_dggevx( int matrix_layout, char balanc, char jobvl,
  31. char jobvr, char sense, lapack_int n, double* a,
  32. lapack_int lda, double* b, lapack_int ldb,
  33. double* alphar, double* alphai, double* beta,
  34. double* vl, lapack_int ldvl, double* vr,
  35. lapack_int ldvr, lapack_int* ilo, lapack_int* ihi,
  36. double* lscale, double* rscale, double* abnrm,
  37. double* bbnrm, double* rconde, double* rcondv )
  38. {
  39. lapack_int info = 0;
  40. lapack_int lwork = -1;
  41. lapack_logical* bwork = NULL;
  42. lapack_int* iwork = NULL;
  43. double* work = NULL;
  44. double work_query;
  45. if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
  46. LAPACKE_xerbla( "LAPACKE_dggevx", -1 );
  47. return -1;
  48. }
  49. #ifndef LAPACK_DISABLE_NAN_CHECK
  50. if( LAPACKE_get_nancheck() ) {
  51. /* Optionally check input matrices for NaNs */
  52. if( LAPACKE_dge_nancheck( matrix_layout, n, n, a, lda ) ) {
  53. return -7;
  54. }
  55. if( LAPACKE_dge_nancheck( matrix_layout, n, n, b, ldb ) ) {
  56. return -9;
  57. }
  58. }
  59. #endif
  60. /* Allocate memory for working array(s) */
  61. if( LAPACKE_lsame( sense, 'b' ) || LAPACKE_lsame( sense, 'e' ) ||
  62. LAPACKE_lsame( sense, 'v' ) ) {
  63. bwork = (lapack_logical*)
  64. LAPACKE_malloc( sizeof(lapack_logical) * MAX(1,n) );
  65. if( bwork == NULL ) {
  66. info = LAPACK_WORK_MEMORY_ERROR;
  67. goto exit_level_0;
  68. }
  69. }
  70. if( LAPACKE_lsame( sense, 'b' ) || LAPACKE_lsame( sense, 'n' ) ||
  71. LAPACKE_lsame( sense, 'v' ) ) {
  72. iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * MAX(1,n+6) );
  73. if( iwork == NULL ) {
  74. info = LAPACK_WORK_MEMORY_ERROR;
  75. goto exit_level_1;
  76. }
  77. }
  78. /* Query optimal working array(s) size */
  79. info = LAPACKE_dggevx_work( matrix_layout, balanc, jobvl, jobvr, sense, n, a,
  80. lda, b, ldb, alphar, alphai, beta, vl, ldvl, vr,
  81. ldvr, ilo, ihi, lscale, rscale, abnrm, bbnrm,
  82. rconde, rcondv, &work_query, lwork, iwork,
  83. bwork );
  84. if( info != 0 ) {
  85. goto exit_level_2;
  86. }
  87. lwork = (lapack_int)work_query;
  88. /* Allocate memory for work arrays */
  89. work = (double*)LAPACKE_malloc( sizeof(double) * lwork );
  90. if( work == NULL ) {
  91. info = LAPACK_WORK_MEMORY_ERROR;
  92. goto exit_level_2;
  93. }
  94. /* Call middle-level interface */
  95. info = LAPACKE_dggevx_work( matrix_layout, balanc, jobvl, jobvr, sense, n, a,
  96. lda, b, ldb, alphar, alphai, beta, vl, ldvl, vr,
  97. ldvr, ilo, ihi, lscale, rscale, abnrm, bbnrm,
  98. rconde, rcondv, work, lwork, iwork, bwork );
  99. /* Release memory and exit */
  100. LAPACKE_free( work );
  101. exit_level_2:
  102. if( LAPACKE_lsame( sense, 'b' ) || LAPACKE_lsame( sense, 'n' ) ||
  103. LAPACKE_lsame( sense, 'v' ) ) {
  104. LAPACKE_free( iwork );
  105. }
  106. exit_level_1:
  107. if( LAPACKE_lsame( sense, 'b' ) || LAPACKE_lsame( sense, 'e' ) ||
  108. LAPACKE_lsame( sense, 'v' ) ) {
  109. LAPACKE_free( bwork );
  110. }
  111. exit_level_0:
  112. if( info == LAPACK_WORK_MEMORY_ERROR ) {
  113. LAPACKE_xerbla( "LAPACKE_dggevx", info );
  114. }
  115. return info;
  116. }