PageRenderTime 83ms CodeModel.GetById 20ms RepoModel.GetById 7ms app.codeStats 0ms

/lapacke/src/lapacke_dggevx_work.c

https://bitbucket.org/iricpt/lapack
C | 162 lines | 121 code | 2 blank | 39 comment | 30 complexity | 16829cde4bd7113a8a00c17f2c1ca533 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 middle-level C interface to LAPACK function dggevx
  27. * Author: Intel Corporation
  28. *****************************************************************************/
  29. #include "lapacke_utils.h"
  30. lapack_int LAPACKE_dggevx_work( 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,
  36. lapack_int* ihi, double* lscale, double* rscale,
  37. double* abnrm, double* bbnrm, double* rconde,
  38. double* rcondv, double* work, lapack_int lwork,
  39. lapack_int* iwork, lapack_logical* bwork )
  40. {
  41. lapack_int info = 0;
  42. if( matrix_layout == LAPACK_COL_MAJOR ) {
  43. /* Call LAPACK function and adjust info */
  44. LAPACK_dggevx( &balanc, &jobvl, &jobvr, &sense, &n, a, &lda, b, &ldb,
  45. alphar, alphai, beta, vl, &ldvl, vr, &ldvr, ilo, ihi,
  46. lscale, rscale, abnrm, bbnrm, rconde, rcondv, work,
  47. &lwork, iwork, bwork, &info );
  48. if( info < 0 ) {
  49. info = info - 1;
  50. }
  51. } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
  52. lapack_int lda_t = MAX(1,n);
  53. lapack_int ldb_t = MAX(1,n);
  54. lapack_int ldvl_t = MAX(1,n);
  55. lapack_int ldvr_t = MAX(1,n);
  56. double* a_t = NULL;
  57. double* b_t = NULL;
  58. double* vl_t = NULL;
  59. double* vr_t = NULL;
  60. /* Check leading dimension(s) */
  61. if( lda < n ) {
  62. info = -8;
  63. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  64. return info;
  65. }
  66. if( ldb < n ) {
  67. info = -10;
  68. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  69. return info;
  70. }
  71. if( ldvl < n ) {
  72. info = -15;
  73. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  74. return info;
  75. }
  76. if( ldvr < n ) {
  77. info = -17;
  78. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  79. return info;
  80. }
  81. /* Query optimal working array(s) size if requested */
  82. if( lwork == -1 ) {
  83. LAPACK_dggevx( &balanc, &jobvl, &jobvr, &sense, &n, a, &lda_t, b,
  84. &ldb_t, alphar, alphai, beta, vl, &ldvl_t, vr,
  85. &ldvr_t, ilo, ihi, lscale, rscale, abnrm, bbnrm,
  86. rconde, rcondv, work, &lwork, iwork, bwork, &info );
  87. return (info < 0) ? (info - 1) : info;
  88. }
  89. /* Allocate memory for temporary array(s) */
  90. a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
  91. if( a_t == NULL ) {
  92. info = LAPACK_TRANSPOSE_MEMORY_ERROR;
  93. goto exit_level_0;
  94. }
  95. b_t = (double*)LAPACKE_malloc( sizeof(double) * ldb_t * MAX(1,n) );
  96. if( b_t == NULL ) {
  97. info = LAPACK_TRANSPOSE_MEMORY_ERROR;
  98. goto exit_level_1;
  99. }
  100. if( LAPACKE_lsame( jobvl, 'v' ) ) {
  101. vl_t = (double*)
  102. LAPACKE_malloc( sizeof(double) * ldvl_t * MAX(1,n) );
  103. if( vl_t == NULL ) {
  104. info = LAPACK_TRANSPOSE_MEMORY_ERROR;
  105. goto exit_level_2;
  106. }
  107. }
  108. if( LAPACKE_lsame( jobvr, 'v' ) ) {
  109. vr_t = (double*)
  110. LAPACKE_malloc( sizeof(double) * ldvr_t * MAX(1,n) );
  111. if( vr_t == NULL ) {
  112. info = LAPACK_TRANSPOSE_MEMORY_ERROR;
  113. goto exit_level_3;
  114. }
  115. }
  116. /* Transpose input matrices */
  117. LAPACKE_dge_trans( matrix_layout, n, n, a, lda, a_t, lda_t );
  118. LAPACKE_dge_trans( matrix_layout, n, n, b, ldb, b_t, ldb_t );
  119. /* Call LAPACK function and adjust info */
  120. LAPACK_dggevx( &balanc, &jobvl, &jobvr, &sense, &n, a_t, &lda_t, b_t,
  121. &ldb_t, alphar, alphai, beta, vl_t, &ldvl_t, vr_t,
  122. &ldvr_t, ilo, ihi, lscale, rscale, abnrm, bbnrm, rconde,
  123. rcondv, work, &lwork, iwork, bwork, &info );
  124. if( info < 0 ) {
  125. info = info - 1;
  126. }
  127. /* Transpose output matrices */
  128. LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
  129. LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
  130. if( LAPACKE_lsame( jobvl, 'v' ) ) {
  131. LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, vl_t, ldvl_t, vl, ldvl );
  132. }
  133. if( LAPACKE_lsame( jobvr, 'v' ) ) {
  134. LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, vr_t, ldvr_t, vr, ldvr );
  135. }
  136. /* Release memory and exit */
  137. if( LAPACKE_lsame( jobvr, 'v' ) ) {
  138. LAPACKE_free( vr_t );
  139. }
  140. exit_level_3:
  141. if( LAPACKE_lsame( jobvl, 'v' ) ) {
  142. LAPACKE_free( vl_t );
  143. }
  144. exit_level_2:
  145. LAPACKE_free( b_t );
  146. exit_level_1:
  147. LAPACKE_free( a_t );
  148. exit_level_0:
  149. if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
  150. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  151. }
  152. } else {
  153. info = -1;
  154. LAPACKE_xerbla( "LAPACKE_dggevx_work", info );
  155. }
  156. return info;
  157. }