LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_cgejsv.c
Go to the documentation of this file.
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 cgejsv
30 * Author: Intel Corporation
31 * Generated June 2016
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_cgejsv( int matrix_layout, char joba, char jobu, char jobv,
37  char jobr, char jobt, char jobp, lapack_int m,
38  lapack_int n, lapack_complex_float* a, lapack_int lda, float* sva,
40  float* stat, lapack_int* istat )
41 {
42  lapack_int info = 0;
43  lapack_int lwork = (
44  // 1.1
45  ( LAPACKE_lsame( jobu, 'n' ) && LAPACKE_lsame( jobv, 'n' ) &&
46  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) )) ? 2*n+1 :
47 
48  //1.2
49  ( ( LAPACKE_lsame( jobu, 'n' ) && LAPACKE_lsame( jobv, 'n' ) &&
50  !( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) )) ? n*n+3*n :
51 
52  //2.1
53  ( ( ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
54  !( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
55  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 3*n :
56 
57 
58  //2.2
59  ( ( ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
60  !( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
61  !( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 3*n :
62 
63  //3.1
64  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' )) &&
65  !( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' )) &&
66  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 3*n :
67 
68  //3.2
69  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' )) &&
70  !(LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' )) &&
71  !(LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 3*n :
72 
73  //4.1
74  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
75  ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
76  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 5*n+2*n*n :
77 
78  //4.2
79  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
80  ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
81  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? 4*n*n:
82  1) ) ) ) ) ) ) );
83  lapack_int lrwork = (
84  // 1.1
85  ( LAPACKE_lsame( jobu, 'n' ) && LAPACKE_lsame( jobv, 'n' ) &&
86  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) )) ? MAX(7,n+2*m) :
87 
88  //1.2
89  ( ( LAPACKE_lsame( jobu, 'n' ) && LAPACKE_lsame( jobv, 'n' ) &&
90  !( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) )) ? MAX(7,2*n) :
91 
92  //2.1
93  ( ( ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
94  !( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
95  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX( 7, n+ 2*m ) :
96 
97 
98  //2.2
99  ( ( ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
100  !( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
101  !( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX(7,2*n) :
102 
103  //3.1
104  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' )) &&
105  !( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' )) &&
106  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX( 7, n+ 2*m ) :
107 
108  //3.2
109  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' )) &&
110  !(LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' )) &&
111  !(LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX(7,2*n) :
112 
113  //4.1
114  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
115  ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
116  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX( 7, n+ 2*m ) :
117 
118  //4.2
119  ( ( ( LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' ) ) &&
120  ( LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' ) ) &&
121  ( LAPACKE_lsame( jobt, 't' ) || LAPACKE_lsame( joba, 'f' ) || LAPACKE_lsame( joba, 'g' ) ))? MAX(7,2*n) :
122  7 ))))))));
123  lapack_int* iwork = NULL;
124  float* rwork = NULL;
125  lapack_complex_float* cwork = NULL;
126  lapack_int i;
127  lapack_int nu, nv;
128  if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
129  LAPACKE_xerbla( "LAPACKE_cgejsv", -1 );
130  return -1;
131  }
132 #ifndef LAPACK_DISABLE_NAN_CHECK
133  /* Optionally check input matrices for NaNs */
134  nu = LAPACKE_lsame( jobu, 'n' ) ? 1 : m;
135  nv = LAPACKE_lsame( jobv, 'n' ) ? 1 : n;
136  if( LAPACKE_cge_nancheck( matrix_layout, m, n, a, lda ) ) {
137  return -10;
138  }
139 #endif
140  /* Allocate memory for working array(s) */
141  iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * MAX(3,m+2*n) );
142  if( iwork == NULL ) {
144  goto exit_level_0;
145  }
146  lwork = MAX( lwork, 1 );
147  { /* FIXUP LWORK */
148  int want_u = LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' );
149  int want_v = LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' );
150  int want_sce = LAPACKE_lsame( joba, 'e' ) || LAPACKE_lsame( joba, 'g' );
151  if( !want_u && !want_v && !want_sce ) lwork = MAX( lwork, 2*n+1 ); // 1.1
152  if( !want_u && !want_v && want_sce ) lwork = MAX( lwork, n*n+3*n ); // 1.2
153  if( want_u && LAPACKE_lsame( jobv, 'v' ) ) lwork = MAX( lwork, 5*n+2*n*n ); // 4.1
154  if( want_u && LAPACKE_lsame( jobv, 'j' ) ) lwork = MAX( lwork, 4*n+n*n ); // 4.2
155  }
156  cwork = (lapack_complex_float*)LAPACKE_malloc( sizeof(lapack_complex_float) * lwork );
157  if( cwork == NULL ) {
159  goto exit_level_1;
160  }
161  lrwork = MAX3( lrwork, 7, n+2*m );
162  rwork = (float*)LAPACKE_malloc( sizeof(float) * lrwork );
163  if( rwork == NULL ) {
165  goto exit_level_2;
166  }
167  /* Call middle-level interface */
168  info = LAPACKE_cgejsv_work( matrix_layout, joba, jobu, jobv, jobr, jobt,
169  jobp, m, n, a, lda, sva, u, ldu, v, ldv, cwork,
170  lwork, rwork, lrwork, iwork );
171  /* Backup significant data from working array(s) */
172  for( i=0; i<7; i++ ) {
173  stat[i] = rwork[i];
174  }
175  for( i=0; i<3; i++ ) {
176  istat[i] = iwork[i];
177  }
178  /* Release memory and exit */
179  LAPACKE_free( cwork );
180 exit_level_2:
181  LAPACKE_free( rwork );
182 exit_level_1:
183  LAPACKE_free( iwork );
184 exit_level_0:
185  if( info == LAPACK_WORK_MEMORY_ERROR ) {
186  LAPACKE_xerbla( "LAPACKE_cgejsv", info );
187  }
188  return info;
189 }
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
#define LAPACK_WORK_MEMORY_ERROR
Definition: lapacke.h:122
lapack_int LAPACKE_cgejsv(int matrix_layout, char joba, char jobu, char jobv, char jobr, char jobt, char jobp, lapack_int m, lapack_int n, lapack_complex_float *a, lapack_int lda, float *sva, lapack_complex_float *u, lapack_int ldu, lapack_complex_float *v, lapack_int ldv, float *stat, lapack_int *istat)
#define lapack_complex_float
Definition: lapacke.h:74
#define MAX3(x, y, z)
Definition: lapacke_utils.h:53
lapack_logical LAPACKE_cge_nancheck(int matrix_layout, lapack_int m, lapack_int n, const lapack_complex_float *a, lapack_int lda)
#define MAX(x, y)
Definition: lapacke_utils.h:47
#define LAPACKE_free(p)
Definition: lapacke.h:113
#define LAPACKE_malloc(size)
Definition: lapacke.h:110
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:36
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
void LAPACKE_xerbla(const char *name, lapack_int info)
#define lapack_int
Definition: lapacke.h:47
lapack_int LAPACKE_cgejsv_work(int matrix_layout, char joba, char jobu, char jobv, char jobr, char jobt, char jobp, lapack_int m, lapack_int n, lapack_complex_float *a, lapack_int lda, float *sva, lapack_complex_float *u, lapack_int ldu, lapack_complex_float *v, lapack_int ldv, lapack_complex_float *cwork, lapack_int lwork, float *work, lapack_int lrwork, lapack_int *iwork)