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