LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ LAPACKE_cgesvd_work()

lapack_int LAPACKE_cgesvd_work ( int  matrix_layout,
char  jobu,
char  jobvt,
lapack_int  m,
lapack_int  n,
lapack_complex_float a,
lapack_int  lda,
float *  s,
lapack_complex_float u,
lapack_int  ldu,
lapack_complex_float vt,
lapack_int  ldvt,
lapack_complex_float work,
lapack_int  lwork,
float *  rwork 
)

Definition at line 35 of file lapacke_cgesvd_work.c.

42{
43 lapack_int info = 0;
44 if( matrix_layout == LAPACK_COL_MAJOR ) {
45 /* Call LAPACK function and adjust info */
46 LAPACK_cgesvd( &jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt,
47 work, &lwork, rwork, &info );
48 if( info < 0 ) {
49 info = info - 1;
50 }
51 } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
52 lapack_int nrows_u = ( LAPACKE_lsame( jobu, 'a' ) ||
53 LAPACKE_lsame( jobu, 's' ) ) ? m : 1;
54 lapack_int ncols_u = LAPACKE_lsame( jobu, 'a' ) ? m :
55 ( LAPACKE_lsame( jobu, 's' ) ? MIN(m,n) : 1);
56 lapack_int nrows_vt = LAPACKE_lsame( jobvt, 'a' ) ? n :
57 ( LAPACKE_lsame( jobvt, 's' ) ? MIN(m,n) : 1);
58 lapack_int ncols_vt = ( LAPACKE_lsame( jobvt, 'a' ) ||
59 LAPACKE_lsame( jobvt, 's' ) ) ? n : 1;
60 lapack_int lda_t = MAX(1,m);
61 lapack_int ldu_t = MAX(1,nrows_u);
62 lapack_int ldvt_t = MAX(1,nrows_vt);
63 lapack_complex_float* a_t = NULL;
64 lapack_complex_float* u_t = NULL;
65 lapack_complex_float* vt_t = NULL;
66 /* Check leading dimension(s) */
67 if( lda < n ) {
68 info = -7;
69 LAPACKE_xerbla( "LAPACKE_cgesvd_work", info );
70 return info;
71 }
72 if( ldu < ncols_u ) {
73 info = -10;
74 LAPACKE_xerbla( "LAPACKE_cgesvd_work", info );
75 return info;
76 }
77 if( ldvt < ncols_vt ) {
78 info = -12;
79 LAPACKE_xerbla( "LAPACKE_cgesvd_work", info );
80 return info;
81 }
82 /* Query optimal working array(s) size if requested */
83 if( lwork == -1 ) {
84 LAPACK_cgesvd( &jobu, &jobvt, &m, &n, a, &lda_t, s, u, &ldu_t, vt,
85 &ldvt_t, work, &lwork, rwork, &info );
86 return (info < 0) ? (info - 1) : info;
87 }
88 /* Allocate memory for temporary array(s) */
90 LAPACKE_malloc( sizeof(lapack_complex_float) * lda_t * MAX(1,n) );
91 if( a_t == NULL ) {
93 goto exit_level_0;
94 }
95 if( LAPACKE_lsame( jobu, 'a' ) || LAPACKE_lsame( jobu, 's' ) ) {
98 ldu_t * MAX(1,ncols_u) );
99 if( u_t == NULL ) {
101 goto exit_level_1;
102 }
103 }
104 if( LAPACKE_lsame( jobvt, 'a' ) || LAPACKE_lsame( jobvt, 's' ) ) {
105 vt_t = (lapack_complex_float*)
107 ldvt_t * MAX(1,n) );
108 if( vt_t == NULL ) {
110 goto exit_level_2;
111 }
112 }
113 /* Transpose input matrices */
114 LAPACKE_cge_trans( matrix_layout, m, n, a, lda, a_t, lda_t );
115 /* Call LAPACK function and adjust info */
116 LAPACK_cgesvd( &jobu, &jobvt, &m, &n, a_t, &lda_t, s, u_t, &ldu_t, vt_t,
117 &ldvt_t, work, &lwork, rwork, &info );
118 if( info < 0 ) {
119 info = info - 1;
120 }
121 /* Transpose output matrices */
122 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_t, lda_t, a, lda );
123 if( LAPACKE_lsame( jobu, 'a' ) || LAPACKE_lsame( jobu, 's' ) ) {
124 LAPACKE_cge_trans( LAPACK_COL_MAJOR, nrows_u, ncols_u, u_t, ldu_t,
125 u, ldu );
126 }
127 if( LAPACKE_lsame( jobvt, 'a' ) || LAPACKE_lsame( jobvt, 's' ) ) {
128 LAPACKE_cge_trans( LAPACK_COL_MAJOR, nrows_vt, n, vt_t, ldvt_t, vt,
129 ldvt );
130 }
131 /* Release memory and exit */
132 if( LAPACKE_lsame( jobvt, 'a' ) || LAPACKE_lsame( jobvt, 's' ) ) {
133 LAPACKE_free( vt_t );
134 }
135exit_level_2:
136 if( LAPACKE_lsame( jobu, 'a' ) || LAPACKE_lsame( jobu, 's' ) ) {
137 LAPACKE_free( u_t );
138 }
139exit_level_1:
140 LAPACKE_free( a_t );
141exit_level_0:
142 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
143 LAPACKE_xerbla( "LAPACKE_cgesvd_work", info );
144 }
145 } else {
146 info = -1;
147 LAPACKE_xerbla( "LAPACKE_cgesvd_work", info );
148 }
149 return info;
150}
#define LAPACK_cgesvd(...)
Definition: lapack.h:3387
#define lapack_int
Definition: lapack.h:87
#define lapack_complex_float
Definition: lapack.h:46
#define LAPACK_COL_MAJOR
Definition: lapacke.h:53
#define LAPACKE_free(p)
Definition: lapacke.h:46
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:52
#define LAPACKE_malloc(size)
Definition: lapacke.h:43
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:56
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, lapack_int info)
#define MIN(x, y)
Definition: lapacke_utils.h:49
#define MAX(x, y)
Definition: lapacke_utils.h:46
void LAPACKE_cge_trans(int matrix_layout, lapack_int m, lapack_int n, const lapack_complex_float *in, lapack_int ldin, lapack_complex_float *out, lapack_int ldout)
Here is the call graph for this function:
Here is the caller graph for this function: