LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_slarfb_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 slarfb
30 * Author: Intel Corporation
31 * Generated November 2015
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_slarfb_work( int matrix_layout, char side, char trans,
37  char direct, char storev, lapack_int m,
38  lapack_int n, lapack_int k, const float* v,
39  lapack_int ldv, const float* t, lapack_int ldt,
40  float* c, lapack_int ldc, float* work,
41  lapack_int ldwork )
42 {
43  lapack_int info = 0;
44  lapack_int nrows_v, ncols_v;
45  lapack_int ldc_t, ldt_t, ldv_t;
46  float *v_t = NULL, *t_t = NULL, *c_t = NULL;
47  if( matrix_layout == LAPACK_COL_MAJOR ) {
48  /* Call LAPACK function and adjust info */
49  LAPACK_slarfb( &side, &trans, &direct, &storev, &m, &n, &k, v, &ldv, t,
50  &ldt, c, &ldc, work, &ldwork );
51  if( info < 0 ) {
52  info = info - 1;
53  }
54  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
55  nrows_v = ( LAPACKE_lsame( storev, 'c' ) &&
56  LAPACKE_lsame( side, 'l' ) ) ? m :
57  ( ( LAPACKE_lsame( storev, 'c' ) &&
58  LAPACKE_lsame( side, 'r' ) ) ? n :
59  ( LAPACKE_lsame( storev, 'r' ) ? k : 1) );
60  ncols_v = LAPACKE_lsame( storev, 'c' ) ? k :
61  ( ( LAPACKE_lsame( storev, 'r' ) &&
62  LAPACKE_lsame( side, 'l' ) ) ? m :
63  ( ( LAPACKE_lsame( storev, 'r' ) &&
64  LAPACKE_lsame( side, 'r' ) ) ? n : 1) );
65  ldc_t = MAX(1,m);
66  ldt_t = MAX(1,k);
67  ldv_t = MAX(1,nrows_v);
68  /* Check leading dimension(s) */
69  if( ldc < n ) {
70  info = -14;
71  LAPACKE_xerbla( "LAPACKE_slarfb_work", info );
72  return info;
73  }
74  if( ldt < k ) {
75  info = -12;
76  LAPACKE_xerbla( "LAPACKE_slarfb_work", info );
77  return info;
78  }
79  if( ldv < ncols_v ) {
80  info = -10;
81  LAPACKE_xerbla( "LAPACKE_slarfb_work", info );
82  return info;
83  }
84  /* Allocate memory for temporary array(s) */
85  v_t = (float*)LAPACKE_malloc( sizeof(float) * ldv_t * MAX(1,ncols_v) );
86  if( v_t == NULL ) {
88  goto exit_level_0;
89  }
90  t_t = (float*)LAPACKE_malloc( sizeof(float) * ldt_t * MAX(1,k) );
91  if( t_t == NULL ) {
93  goto exit_level_1;
94  }
95  c_t = (float*)LAPACKE_malloc( sizeof(float) * ldc_t * MAX(1,n) );
96  if( c_t == NULL ) {
98  goto exit_level_2;
99  }
100  /* Transpose input matrices */
101  if( LAPACKE_lsame( storev, 'c' ) && LAPACKE_lsame( direct, 'f' ) ) {
102  LAPACKE_str_trans( matrix_layout, 'l', 'u', k, v, ldv, v_t, ldv_t );
103  LAPACKE_sge_trans( matrix_layout, nrows_v-k, ncols_v, &v[k*ldv], ldv,
104  &v_t[k], ldv_t );
105  } else if( LAPACKE_lsame( storev, 'c' ) &&
106  LAPACKE_lsame( direct, 'b' ) ) {
107  if( k > nrows_v ) {
108  LAPACKE_xerbla( "LAPACKE_slarfb_work", -8 );
109  return -8;
110  }
111  LAPACKE_str_trans( matrix_layout, 'u', 'u', k, &v[(nrows_v-k)*ldv],
112  ldv, &v_t[nrows_v-k], ldv_t );
113  LAPACKE_sge_trans( matrix_layout, nrows_v-k, ncols_v, v, ldv, v_t,
114  ldv_t );
115  } else if( LAPACKE_lsame( storev, 'r' ) &&
116  LAPACKE_lsame( direct, 'f' ) ) {
117  LAPACKE_str_trans( matrix_layout, 'u', 'u', k, v, ldv, v_t, ldv_t );
118  LAPACKE_sge_trans( matrix_layout, nrows_v, ncols_v-k, &v[k], ldv,
119  &v_t[k*ldv_t], ldv_t );
120  } else if( LAPACKE_lsame( storev, 'r' ) &&
121  LAPACKE_lsame( direct, 'f' ) ) {
122  if( k > ncols_v ) {
123  LAPACKE_xerbla( "LAPACKE_slarfb_work", -8 );
124  return -8;
125  }
126  LAPACKE_str_trans( matrix_layout, 'l', 'u', k, &v[ncols_v-k], ldv,
127  &v_t[(ncols_v-k)*ldv_t], ldv_t );
128  LAPACKE_sge_trans( matrix_layout, nrows_v, ncols_v-k, v, ldv, v_t,
129  ldv_t );
130  }
131  LAPACKE_sge_trans( matrix_layout, k, k, t, ldt, t_t, ldt_t );
132  LAPACKE_sge_trans( matrix_layout, m, n, c, ldc, c_t, ldc_t );
133  /* Call LAPACK function and adjust info */
134  LAPACK_slarfb( &side, &trans, &direct, &storev, &m, &n, &k, v_t, &ldv_t,
135  t_t, &ldt_t, c_t, &ldc_t, work, &ldwork );
136  info = 0; /* LAPACK call is ok! */
137  /* Transpose output matrices */
138  LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_t, ldc_t, c, ldc );
139  /* Release memory and exit */
140  LAPACKE_free( c_t );
141 exit_level_2:
142  LAPACKE_free( t_t );
143 exit_level_1:
144  LAPACKE_free( v_t );
145 exit_level_0:
146  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
147  LAPACKE_xerbla( "LAPACKE_slarfb_work", info );
148  }
149  } else {
150  info = -1;
151  LAPACKE_xerbla( "LAPACKE_slarfb_work", info );
152  }
153  return info;
154 }
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
void LAPACKE_str_trans(int matrix_layout, char uplo, char diag, lapack_int n, const float *in, lapack_int ldin, float *out, lapack_int ldout)
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:47
lapack_int LAPACKE_slarfb_work(int matrix_layout, char side, char trans, char direct, char storev, lapack_int m, lapack_int n, lapack_int k, const float *v, lapack_int ldv, const float *t, lapack_int ldt, float *c, lapack_int ldc, float *work, lapack_int ldwork)
#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
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:123
void LAPACK_slarfb(char *side, char *trans, char *direct, char *storev, lapack_int *m, lapack_int *n, lapack_int *k, const float *v, lapack_int *ldv, const float *t, lapack_int *ldt, float *c, lapack_int *ldc, float *work, lapack_int *ldwork)