LAPACK  3.10.0
LAPACK: Linear Algebra PACKage
lapacke_sbdsqr_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 sbdsqr
30 * Author: Intel Corporation
31 *****************************************************************************/
32 
33 #include "lapacke_utils.h"
34 
35 lapack_int LAPACKE_sbdsqr_work( int matrix_layout, char uplo, lapack_int n,
36  lapack_int ncvt, lapack_int nru, lapack_int ncc,
37  float* d, float* e, float* vt, lapack_int ldvt,
38  float* u, lapack_int ldu, float* c,
39  lapack_int ldc, float* work )
40 {
41  lapack_int info = 0;
42  if( matrix_layout == LAPACK_COL_MAJOR ) {
43  /* Call LAPACK function and adjust info */
44  LAPACK_sbdsqr( &uplo, &n, &ncvt, &nru, &ncc, d, e, vt, &ldvt, u, &ldu,
45  c, &ldc, work, &info );
46  if( info < 0 ) {
47  info = info - 1;
48  }
49  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
50  lapack_int ldc_t = MAX(1,n);
51  lapack_int ldu_t = MAX(1,nru);
52  lapack_int ldvt_t = MAX(1,n);
53  float* vt_t = NULL;
54  float* u_t = NULL;
55  float* c_t = NULL;
56  /* Check leading dimension(s) */
57  if( ldc < ncc ) {
58  info = -14;
59  LAPACKE_xerbla( "LAPACKE_sbdsqr_work", info );
60  return info;
61  }
62  if( ldu < n ) {
63  info = -12;
64  LAPACKE_xerbla( "LAPACKE_sbdsqr_work", info );
65  return info;
66  }
67  if( ldvt < ncvt ) {
68  info = -10;
69  LAPACKE_xerbla( "LAPACKE_sbdsqr_work", info );
70  return info;
71  }
72  /* Allocate memory for temporary array(s) */
73  if( ncvt != 0 ) {
74  vt_t = (float*)
75  LAPACKE_malloc( sizeof(float) * ldvt_t * MAX(1,ncvt) );
76  if( vt_t == NULL ) {
78  goto exit_level_0;
79  }
80  }
81  if( nru != 0 ) {
82  u_t = (float*)LAPACKE_malloc( sizeof(float) * ldu_t * MAX(1,n) );
83  if( u_t == NULL ) {
85  goto exit_level_1;
86  }
87  }
88  if( ncc != 0 ) {
89  c_t = (float*)LAPACKE_malloc( sizeof(float) * ldc_t * MAX(1,ncc) );
90  if( c_t == NULL ) {
92  goto exit_level_2;
93  }
94  }
95  /* Transpose input matrices */
96  if( ncvt != 0 ) {
97  LAPACKE_sge_trans( matrix_layout, n, ncvt, vt, ldvt, vt_t, ldvt_t );
98  }
99  if( nru != 0 ) {
100  LAPACKE_sge_trans( matrix_layout, nru, n, u, ldu, u_t, ldu_t );
101  }
102  if( ncc != 0 ) {
103  LAPACKE_sge_trans( matrix_layout, n, ncc, c, ldc, c_t, ldc_t );
104  }
105  /* Call LAPACK function and adjust info */
106  LAPACK_sbdsqr( &uplo, &n, &ncvt, &nru, &ncc, d, e, vt_t, &ldvt_t, u_t,
107  &ldu_t, c_t, &ldc_t, work, &info );
108  if( info < 0 ) {
109  info = info - 1;
110  }
111  /* Transpose output matrices */
112  if( ncvt != 0 ) {
113  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, ncvt, vt_t, ldvt_t, vt,
114  ldvt );
115  }
116  if( nru != 0 ) {
117  LAPACKE_sge_trans( LAPACK_COL_MAJOR, nru, n, u_t, ldu_t, u, ldu );
118  }
119  if( ncc != 0 ) {
120  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, ncc, c_t, ldc_t, c, ldc );
121  }
122  /* Release memory and exit */
123  if( ncc != 0 ) {
124  LAPACKE_free( c_t );
125  }
126 exit_level_2:
127  if( nru != 0 ) {
128  LAPACKE_free( u_t );
129  }
130 exit_level_1:
131  if( ncvt != 0 ) {
132  LAPACKE_free( vt_t );
133  }
134 exit_level_0:
135  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
136  LAPACKE_xerbla( "LAPACKE_sbdsqr_work", info );
137  }
138  } else {
139  info = -1;
140  LAPACKE_xerbla( "LAPACKE_sbdsqr_work", info );
141  }
142  return info;
143 }
#define LAPACK_sbdsqr(...)
Definition: lapack.h:356
#define lapack_int
Definition: lapack.h:83
#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_sbdsqr_work(int matrix_layout, char uplo, lapack_int n, lapack_int ncvt, lapack_int nru, lapack_int ncc, float *d, float *e, float *vt, lapack_int ldvt, float *u, lapack_int ldu, float *c, lapack_int ldc, float *work)
void LAPACKE_xerbla(const char *name, lapack_int info)
void LAPACKE_sge_trans(int matrix_layout, lapack_int m, lapack_int n, const float *in, lapack_int ldin, float *out, lapack_int ldout)
#define MAX(x, y)
Definition: lapacke_utils.h:46