LAPACK  3.10.0
LAPACK: Linear Algebra PACKage
lapacke_dggsvp3_work.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 middle-level C interface to LAPACK function dggsvp3
30 * Author: Intel Corporation
31 *****************************************************************************/
32 
33 #include "lapacke_utils.h"
34 
35 lapack_int LAPACKE_dggsvp3_work( int matrix_layout, char jobu, char jobv,
36  char jobq, lapack_int m, lapack_int p,
37  lapack_int n, double* a, lapack_int lda,
38  double* b, lapack_int ldb, double tola,
39  double tolb, lapack_int* k, lapack_int* l,
40  double* u, lapack_int ldu, double* v,
41  lapack_int ldv, double* q, lapack_int ldq,
42  lapack_int* iwork, double* tau, double* work,
43  lapack_int lwork )
44 {
45  lapack_int info = 0;
46  if( matrix_layout == LAPACK_COL_MAJOR ) {
47  /* Call LAPACK function and adjust info */
48  LAPACK_dggsvp3( &jobu, &jobv, &jobq, &m, &p, &n, a, &lda, b, &ldb, &tola,
49  &tolb, k, l, u, &ldu, v, &ldv, q, &ldq, iwork, tau, work,
50  &lwork, &info );
51  if( info < 0 ) {
52  info = info - 1;
53  }
54  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
55  lapack_int lda_t = MAX(1,m);
56  lapack_int ldb_t = MAX(1,p);
57  lapack_int ldq_t = MAX(1,n);
58  lapack_int ldu_t = MAX(1,m);
59  lapack_int ldv_t = MAX(1,p);
60  double* a_t = NULL;
61  double* b_t = NULL;
62  double* u_t = NULL;
63  double* v_t = NULL;
64  double* q_t = NULL;
65  /* Check leading dimension(s) */
66  if( lda < n ) {
67  info = -9;
68  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
69  return info;
70  }
71  if( ldb < n ) {
72  info = -11;
73  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
74  return info;
75  }
76  if( ldq < n ) {
77  info = -21;
78  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
79  return info;
80  }
81  if( ldu < m ) {
82  info = -17;
83  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
84  return info;
85  }
86  if( ldv < p ) {
87  info = -19;
88  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
89  return info;
90  }
91  if( lwork == -1 ) {
92  LAPACK_dggsvp3( &jobu, &jobv, &jobq, &m, &p, &n, a, &lda_t, b,
93  &ldb_t, &tola, &tolb, k, l, u, &ldu_t, v,
94  &ldv_t, q, &ldq_t, iwork, tau, work, &lwork,
95  &info );
96  return (info < 0) ? (info - 1) : info;
97  }
98  /* Allocate memory for temporary array(s) */
99  a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
100  if( a_t == NULL ) {
102  goto exit_level_0;
103  }
104  b_t = (double*)LAPACKE_malloc( sizeof(double) * ldb_t * MAX(1,n) );
105  if( b_t == NULL ) {
107  goto exit_level_1;
108  }
109  if( LAPACKE_lsame( jobu, 'u' ) ) {
110  u_t = (double*)LAPACKE_malloc( sizeof(double) * ldu_t * MAX(1,m) );
111  if( u_t == NULL ) {
113  goto exit_level_2;
114  }
115  }
116  if( LAPACKE_lsame( jobv, 'v' ) ) {
117  v_t = (double*)LAPACKE_malloc( sizeof(double) * ldv_t * MAX(1,p) );
118  if( v_t == NULL ) {
120  goto exit_level_3;
121  }
122  }
123  if( LAPACKE_lsame( jobq, 'q' ) ) {
124  q_t = (double*)LAPACKE_malloc( sizeof(double) * ldq_t * MAX(1,n) );
125  if( q_t == NULL ) {
127  goto exit_level_4;
128  }
129  }
130  /* Transpose input matrices */
131  LAPACKE_dge_trans( matrix_layout, m, n, a, lda, a_t, lda_t );
132  LAPACKE_dge_trans( matrix_layout, p, n, b, ldb, b_t, ldb_t );
133  /* Call LAPACK function and adjust info */
134  LAPACK_dggsvp3( &jobu, &jobv, &jobq, &m, &p, &n, a_t, &lda_t, b_t,
135  &ldb_t, &tola, &tolb, k, l, u_t, &ldu_t, v_t, &ldv_t,
136  q_t, &ldq_t, iwork, tau, work, &lwork, &info );
137  if( info < 0 ) {
138  info = info - 1;
139  }
140  /* Transpose output matrices */
141  LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_t, lda_t, a, lda );
142  LAPACKE_dge_trans( LAPACK_COL_MAJOR, p, n, b_t, ldb_t, b, ldb );
143  if( LAPACKE_lsame( jobu, 'u' ) ) {
144  LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, m, u_t, ldu_t, u, ldu );
145  }
146  if( LAPACKE_lsame( jobv, 'v' ) ) {
147  LAPACKE_dge_trans( LAPACK_COL_MAJOR, p, p, v_t, ldv_t, v, ldv );
148  }
149  if( LAPACKE_lsame( jobq, 'q' ) ) {
150  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
151  }
152  /* Release memory and exit */
153  if( LAPACKE_lsame( jobq, 'q' ) ) {
154  LAPACKE_free( q_t );
155  }
156 exit_level_4:
157  if( LAPACKE_lsame( jobv, 'v' ) ) {
158  LAPACKE_free( v_t );
159  }
160 exit_level_3:
161  if( LAPACKE_lsame( jobu, 'u' ) ) {
162  LAPACKE_free( u_t );
163  }
164 exit_level_2:
165  LAPACKE_free( b_t );
166 exit_level_1:
167  LAPACKE_free( a_t );
168 exit_level_0:
169  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
170  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
171  }
172  } else {
173  info = -1;
174  LAPACKE_xerbla( "LAPACKE_dggsvp3_work", info );
175  }
176  return info;
177 }
#define lapack_int
Definition: lapack.h:83
#define LAPACK_dggsvp3(...)
Definition: lapack.h:5594
#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_int LAPACKE_dggsvp3_work(int matrix_layout, char jobu, char jobv, char jobq, lapack_int m, lapack_int p, lapack_int n, double *a, lapack_int lda, double *b, lapack_int ldb, double tola, double tolb, lapack_int *k, lapack_int *l, double *u, lapack_int ldu, double *v, lapack_int ldv, double *q, lapack_int ldq, lapack_int *iwork, double *tau, double *work, lapack_int lwork)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, lapack_int info)
#define MAX(x, y)
Definition: lapacke_utils.h:46
void LAPACKE_dge_trans(int matrix_layout, lapack_int m, lapack_int n, const double *in, lapack_int ldin, double *out, lapack_int ldout)