qpOASES-3.0beta/src/BLASReplacement.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
6  * Christian Kirches et al. All rights reserved.
7  *
8  * qpOASES is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * qpOASES is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with qpOASES; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 
34 #include <qpOASES/PrivateUtils.hpp>
35 
37 
38 extern "C" void dgemm_ ( const char *TRANSA, const char *TRANSB,
39  const unsigned long *M, const unsigned long *N, const unsigned long *K,
40  const double *ALPHA, const double *A, const unsigned long *LDA, const double *B, const unsigned long *LDB,
41  const double *BETA, double *C, const unsigned long *LDC)
42 {
43  unsigned int i, j, k;
44 
45  if (isExactlyZero(*BETA))
46  for (k = 0; k < *N; k++)
47  for (j = 0; j < *M; j++)
48  C[j+(*LDC)*k] = 0.0;
49  else if (isExactlyMinusOne(*BETA))
50  for (k = 0; k < *N; k++)
51  for (j = 0; j < *M; j++)
52  C[j+(*LDC)*k] = -C[j+(*LDC)*k];
53  else if (!isExactlyOne(*BETA))
54  for (k = 0; k < *N; k++)
55  for (j = 0; j < *M; j++)
56  C[j+(*LDC)*k] *= *BETA;
57 
58  if (TRANSA[0] == 'N')
59  if (isExactlyOne(*ALPHA))
60  for (k = 0; k < *N; k++)
61  for (j = 0; j < *M; j++)
62  for (i = 0; i < *K; i++)
63  C[j+(*LDC)*k] += A[j+(*LDA)*i] * B[i+(*LDB)*k];
64  else if (isExactlyMinusOne(*ALPHA))
65  for (k = 0; k < *N; k++)
66  for (j = 0; j < *M; j++)
67  for (i = 0; i < *K; i++)
68  C[j+(*LDC)*k] -= A[j+(*LDA)*i] * B[i+(*LDB)*k];
69  else
70  for (k = 0; k < *N; k++)
71  for (j = 0; j < *M; j++)
72  for (i = 0; i < *K; i++)
73  C[j+(*LDC)*k] += *ALPHA * A[j+(*LDA)*i] * B[i+(*LDB)*k];
74  else
75  if (isExactlyOne(*ALPHA))
76  for (k = 0; k < *N; k++)
77  for (j = 0; j < *M; j++)
78  for (i = 0; i < *K; i++)
79  C[j+(*LDC)*k] += A[i+(*LDA)*j] * B[i+(*LDB)*k];
80  else if (isExactlyMinusOne(*ALPHA))
81  for (k = 0; k < *N; k++)
82  for (j = 0; j < *M; j++)
83  for (i = 0; i < *K; i++)
84  C[j+(*LDC)*k] -= A[i+(*LDA)*j] * B[i+(*LDB)*k];
85  else
86  for (k = 0; k < *N; k++)
87  for (j = 0; j < *M; j++)
88  for (i = 0; i < *K; i++)
89  C[j+(*LDC)*k] += *ALPHA * A[i+(*LDA)*j] * B[i+(*LDB)*k];
90 }
91 
92 extern "C" void sgemm_ ( const char *TRANSA, const char *TRANSB,
93  const unsigned long *M, const unsigned long *N, const unsigned long *K,
94  const float *ALPHA, const float *A, const unsigned long *LDA, const float *B, const unsigned long *LDB,
95  const float *BETA, float *C, const unsigned long *LDC)
96 {
97  unsigned int i, j, k;
98 
99  if (isExactlyZero(*BETA))
100  for (k = 0; k < *N; k++)
101  for (j = 0; j < *M; j++)
102  C[j+(*LDC)*k] = 0.0;
103  else if (isExactlyMinusOne(*BETA))
104  for (k = 0; k < *N; k++)
105  for (j = 0; j < *M; j++)
106  C[j+(*LDC)*k] = -C[j+(*LDC)*k];
107  else if (!isExactlyOne(*BETA))
108  for (k = 0; k < *N; k++)
109  for (j = 0; j < *M; j++)
110  C[j+(*LDC)*k] *= *BETA;
111 
112  if (TRANSA[0] == 'N')
113  if (isExactlyOne(*ALPHA))
114  for (k = 0; k < *N; k++)
115  for (j = 0; j < *M; j++)
116  for (i = 0; i < *K; i++)
117  C[j+(*LDC)*k] += A[j+(*LDA)*i] * B[i+(*LDB)*k];
118  else if (isExactlyMinusOne(*ALPHA))
119  for (k = 0; k < *N; k++)
120  for (j = 0; j < *M; j++)
121  for (i = 0; i < *K; i++)
122  C[j+(*LDC)*k] -= A[j+(*LDA)*i] * B[i+(*LDB)*k];
123  else
124  for (k = 0; k < *N; k++)
125  for (j = 0; j < *M; j++)
126  for (i = 0; i < *K; i++)
127  C[j+(*LDC)*k] += *ALPHA * A[j+(*LDA)*i] * B[i+(*LDB)*k];
128  else
129  if (isExactlyOne(*ALPHA))
130  for (k = 0; k < *N; k++)
131  for (j = 0; j < *M; j++)
132  for (i = 0; i < *K; i++)
133  C[j+(*LDC)*k] += A[i+(*LDA)*j] * B[i+(*LDB)*k];
134  else if (isExactlyMinusOne(*ALPHA))
135  for (k = 0; k < *N; k++)
136  for (j = 0; j < *M; j++)
137  for (i = 0; i < *K; i++)
138  C[j+(*LDC)*k] -= A[i+(*LDA)*j] * B[i+(*LDB)*k];
139  else
140  for (k = 0; k < *N; k++)
141  for (j = 0; j < *M; j++)
142  for (i = 0; i < *K; i++)
143  C[j+(*LDC)*k] += *ALPHA * A[i+(*LDA)*j] * B[i+(*LDB)*k];
144 }
145 
#define N
void sgemm_(const char *TRANSA, const char *TRANSB, const unsigned long *M, const unsigned long *N, const unsigned long *K, const float *ALPHA, const float *A, const unsigned long *LDA, const float *B, const unsigned long *LDB, const float *BETA, float *C, const unsigned long *LDC)
bool isExactlyMinusOne(real_t a)
BEGIN_NAMESPACE_QPOASES bool isExactlyOne(real_t a)
USING_NAMESPACE_QPOASES void dgemm_(const char *TRANSA, const char *TRANSB, const unsigned long *M, const unsigned long *N, const unsigned long *K, const double *ALPHA, const double *A, const unsigned long *LDA, const double *B, const unsigned long *LDB, const double *BETA, double *C, const unsigned long *LDC)
bool isExactlyZero(real_t a)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:29