LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_dorcsd2by1_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 dorcsd2by1
30 * Author: Intel Corporation
31 * Generated June 2016
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_dorcsd2by1_work( int matrix_layout, char jobu1, char jobu2,
37  char jobv1t, lapack_int m, lapack_int p,
38  lapack_int q, double* x11, lapack_int ldx11,
39  double* x21, lapack_int ldx21,
40  double* theta, double* u1, lapack_int ldu1,
41  double* u2, lapack_int ldu2, double* v1t,
42  lapack_int ldv1t, double* work, lapack_int lwork,
43  lapack_int* iwork )
44 {
45  lapack_int info = 0;
46  if( matrix_layout == LAPACK_COL_MAJOR ) {
47  /* Call LAPACK function and adjust info */
48  LAPACK_dorcsd2by1( &jobu1, &jobu2, &jobv1t, &m, &p,
49  &q, x11, &ldx11, x21, &ldx21,
50  theta, u1, &ldu1, u2, &ldu2, v1t, &ldv1t,
51  work, &lwork, iwork, &info );
52  if( info < 0 ) {
53  info = info - 1;
54  }
55  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
56  lapack_int nrows_x11 = p;
57  lapack_int nrows_x21 = m-p;
58  lapack_int nrows_u1 = ( LAPACKE_lsame( jobu1, 'y' ) ? p : 1);
59  lapack_int nrows_u2 = ( LAPACKE_lsame( jobu2, 'y' ) ? m-p : 1);
60  lapack_int nrows_v1t = ( LAPACKE_lsame( jobv1t, 'y' ) ? q : 1);
61  lapack_int ldu1_t = MAX(1,nrows_u1);
62  lapack_int ldu2_t = MAX(1,nrows_u2);
63  lapack_int ldv1t_t = MAX(1,nrows_v1t);
64  lapack_int ldx11_t = MAX(1,nrows_x11);
65  lapack_int ldx21_t = MAX(1,nrows_x21);
66  double* x11_t = NULL;
67  double* x21_t = NULL;
68  double* u1_t = NULL;
69  double* u2_t = NULL;
70  double* v1t_t = NULL;
71  /* Check leading dimension(s) */
72  if( ldu1 < p ) {
73  info = -21;
74  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
75  return info;
76  }
77  if( ldu2 < m-p ) {
78  info = -23;
79  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
80  return info;
81  }
82  if( ldv1t < q ) {
83  info = -25;
84  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
85  return info;
86  }
87  if( ldx11 < q ) {
88  info = -12;
89  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
90  return info;
91  }
92  if( ldx21 < q ) {
93  info = -16;
94  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
95  return info;
96  }
97  /* Query optimal working array(s) size if requested */
98  if( lwork == -1 ) {
99  LAPACK_dorcsd2by1( &jobu1, &jobu2, &jobv1t, &m, &p,
100  &q, x11, &ldx11_t, x21, &ldx21_t,
101  theta, u1, &ldu1_t, u2, &ldu2_t, v1t, &ldv1t_t,
102  work, &lwork, iwork, &info );
103  return (info < 0) ? (info - 1) : info;
104  }
105  /* Allocate memory for temporary array(s) */
106  x11_t = (double*)LAPACKE_malloc( sizeof(double) * ldx11_t * MAX(1,q) );
107  if( x11_t == NULL ) {
109  goto exit_level_0;
110  }
111  x21_t = (double*)LAPACKE_malloc( sizeof(double) * ldx21_t * MAX(1,q) );
112  if( x21_t == NULL ) {
114  goto exit_level_1;
115  }
116  if( LAPACKE_lsame( jobu1, 'y' ) ) {
117  u1_t = (double*)
118  LAPACKE_malloc( sizeof(double) * ldu1_t * MAX(1,p) );
119  if( u1_t == NULL ) {
121  goto exit_level_2;
122  }
123  }
124  if( LAPACKE_lsame( jobu2, 'y' ) ) {
125  u2_t = (double*)
126  LAPACKE_malloc( sizeof(double) * ldu2_t * MAX(1,m-p) );
127  if( u2_t == NULL ) {
129  goto exit_level_3;
130  }
131  }
132  if( LAPACKE_lsame( jobv1t, 'y' ) ) {
133  v1t_t = (double*)
134  LAPACKE_malloc( sizeof(double) * ldv1t_t * MAX(1,q) );
135  if( v1t_t == NULL ) {
137  goto exit_level_4;
138  }
139  }
140  /* Transpose input matrices */
141  LAPACKE_dge_trans( matrix_layout, nrows_x11, q, x11, ldx11, x11_t,
142  ldx11_t );
143  LAPACKE_dge_trans( matrix_layout, nrows_x21, q, x21, ldx21, x21_t,
144  ldx21_t );
145  /* Call LAPACK function and adjust info */
146  LAPACK_dorcsd2by1( &jobu1, &jobu2, &jobv1t, &m, &p,
147  &q, x11_t, &ldx11_t, x21_t, &ldx21_t,
148  theta, u1_t, &ldu1_t, u2_t, &ldu2_t, v1t_t, &ldv1t_t,
149  work, &lwork, iwork, &info );
150  if( info < 0 ) {
151  info = info - 1;
152  }
153  /* Transpose output matrices */
154  LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_x11, q, x11_t, ldx11_t, x11,
155  ldx11 );
156  LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_x21, q, x21_t, ldx21_t, x21,
157  ldx21 );
158  if( LAPACKE_lsame( jobu1, 'y' ) ) {
159  LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_u1, p, u1_t, ldu1_t, u1,
160  ldu1 );
161  }
162  if( LAPACKE_lsame( jobu2, 'y' ) ) {
163  LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_u2, m-p, u2_t, ldu2_t,
164  u2, ldu2 );
165  }
166  if( LAPACKE_lsame( jobv1t, 'y' ) ) {
167  LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_v1t, q, v1t_t, ldv1t_t,
168  v1t, ldv1t );
169  }
170  /* Release memory and exit */
171  if( LAPACKE_lsame( jobv1t, 'y' ) ) {
172  LAPACKE_free( v1t_t );
173  }
174 exit_level_4:
175  if( LAPACKE_lsame( jobu2, 'y' ) ) {
176  LAPACKE_free( u2_t );
177  }
178 exit_level_3:
179  if( LAPACKE_lsame( jobu1, 'y' ) ) {
180  LAPACKE_free( u1_t );
181  }
182 exit_level_2:
183  LAPACKE_free( x21_t );
184 exit_level_1:
185  LAPACKE_free( x11_t );
186 exit_level_0:
187  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
188  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
189  }
190  } else {
191  info = -1;
192  LAPACKE_xerbla( "LAPACKE_dorcsd2by1_work", info );
193  }
194  return info;
195 }
void LAPACKE_dge_trans(int matrix_layout, lapack_int m, lapack_int n, const double *in, lapack_int ldin, double *out, lapack_int ldout)
lapack_int LAPACKE_dorcsd2by1_work(int matrix_layout, char jobu1, char jobu2, char jobv1t, lapack_int m, lapack_int p, lapack_int q, double *x11, lapack_int ldx11, double *x21, lapack_int ldx21, double *theta, double *u1, lapack_int ldu1, double *u2, lapack_int ldu2, double *v1t, lapack_int ldv1t, double *work, lapack_int lwork, lapack_int *iwork)
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
#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
void LAPACK_dorcsd2by1(char *jobu1, char *jobu2, char *jobv1t, lapack_int *m, lapack_int *p, lapack_int *q, double *x11, lapack_int *ldx11, double *x21, lapack_int *ldx21, double *theta, double *u1, lapack_int *ldu1, double *u2, lapack_int *ldu2, double *v1t, lapack_int *ldv1t, double *work, lapack_int *lwork, lapack_int *iwork, lapack_int *info)
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
void LAPACKE_xerbla(const char *name, lapack_int info)
#define lapack_int
Definition: lapacke.h:47
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:123