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