blob: d5cce936441a86874513acb7734de85b1a351ddc [file] [log] [blame]
Austin Schuh9a24b372018-01-28 16:12:29 -08001/**************************************************************************************************
2* *
3* This file is part of BLASFEO. *
4* *
5* BLASFEO -- BLAS For Embedded Optimization. *
6* Copyright (C) 2016-2017 by Gianluca Frison. *
7* Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. *
8* All rights reserved. *
9* *
10* HPMPC is free software; you can redistribute it and/or *
11* modify it under the terms of the GNU Lesser General Public *
12* License as published by the Free Software Foundation; either *
13* version 2.1 of the License, or (at your option) any later version. *
14* *
15* HPMPC is distributed in the hope that it will be useful, *
16* but WITHOUT ANY WARRANTY; without even the implied warranty of *
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18* See the GNU Lesser General Public License for more details. *
19* *
20* You should have received a copy of the GNU Lesser General Public *
21* License along with HPMPC; if not, write to the Free Software *
22* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
23* *
24* Author: Gianluca Frison, giaf (at) dtu.dk *
25* gianluca.frison (at) imtek.uni-freiburg.de *
26* *
27**************************************************************************************************/
28
29
30
31#if defined(LA_REFERENCE) | defined(LA_BLAS)
32
33
34
35// dgemm with A diagonal matrix (stored as strvec)
36void GEMM_L_DIAG_LIBSTR(int m, int n, REAL alpha, struct STRVEC *sA, int ai, struct STRMAT *sB, int bi, int bj, double beta, struct STRMAT *sC, int ci, int cj, struct STRMAT *sD, int di, int dj)
37 {
38 if(m<=0 | n<=0)
39 return;
40 int ii, jj;
41 int ldb = sB->m;
42 int ldd = sD->m;
43 REAL *dA = sA->pa + ai;
44 REAL *pB = sB->pA + bi + bj*ldb;
45 REAL *pD = sD->pA + di + dj*ldd;
46 REAL a0, a1;
47 if(beta==0.0)
48 {
49 ii = 0;
50 for(; ii<m-1; ii+=2)
51 {
52 a0 = alpha * dA[ii+0];
53 a1 = alpha * dA[ii+1];
54 for(jj=0; jj<n; jj++)
55 {
56 pD[ii+0+ldd*jj] = a0 * pB[ii+0+ldb*jj];
57 pD[ii+1+ldd*jj] = a1 * pB[ii+1+ldb*jj];
58 }
59 }
60 for(; ii<m; ii++)
61 {
62 a0 = alpha * dA[ii];
63 for(jj=0; jj<n; jj++)
64 {
65 pD[ii+0+ldd*jj] = a0 * pB[ii+0+ldb*jj];
66 }
67 }
68 }
69 else
70 {
71 int ldc = sC->m;
72 REAL *pC = sC->pA + ci + cj*ldc;
73 ii = 0;
74 for(; ii<m-1; ii+=2)
75 {
76 a0 = alpha * dA[ii+0];
77 a1 = alpha * dA[ii+1];
78 for(jj=0; jj<n; jj++)
79 {
80 pD[ii+0+ldd*jj] = a0 * pB[ii+0+ldb*jj] + beta * pC[ii+0+ldc*jj];
81 pD[ii+1+ldd*jj] = a1 * pB[ii+1+ldb*jj] + beta * pC[ii+1+ldc*jj];
82 }
83 }
84 for(; ii<m; ii++)
85 {
86 a0 = alpha * dA[ii];
87 for(jj=0; jj<n; jj++)
88 {
89 pD[ii+0+ldd*jj] = a0 * pB[ii+0+ldb*jj] + beta * pC[ii+0+ldc*jj];
90 }
91 }
92 }
93 return;
94 }
95
96
97
98// dgemm with B diagonal matrix (stored as strvec)
99void GEMM_R_DIAG_LIBSTR(int m, int n, REAL alpha, struct STRMAT *sA, int ai, int aj, struct STRVEC *sB, int bi, double beta, struct STRMAT *sC, int ci, int cj, struct STRMAT *sD, int di, int dj)
100 {
101 if(m<=0 | n<=0)
102 return;
103 int ii, jj;
104 int lda = sA->m;
105 int ldd = sD->m;
106 REAL *pA = sA->pA + ai + aj*lda;
107 REAL *dB = sB->pa + bi;
108 REAL *pD = sD->pA + di + dj*ldd;
109 REAL a0, a1;
110 if(beta==0)
111 {
112 jj = 0;
113 for(; jj<n-1; jj+=2)
114 {
115 a0 = alpha * dB[jj+0];
116 a1 = alpha * dB[jj+1];
117 for(ii=0; ii<m; ii++)
118 {
119 pD[ii+ldd*(jj+0)] = a0 * pA[ii+lda*(jj+0)];
120 pD[ii+ldd*(jj+1)] = a1 * pA[ii+lda*(jj+1)];
121 }
122 }
123 for(; jj<n; jj++)
124 {
125 a0 = alpha * dB[jj+0];
126 for(ii=0; ii<m; ii++)
127 {
128 pD[ii+ldd*(jj+0)] = a0 * pA[ii+lda*(jj+0)];
129 }
130 }
131 }
132 else
133 {
134 int ldc = sC->m;
135 REAL *pC = sC->pA + ci + cj*ldc;
136 jj = 0;
137 for(; jj<n-1; jj+=2)
138 {
139 a0 = alpha * dB[jj+0];
140 a1 = alpha * dB[jj+1];
141 for(ii=0; ii<m; ii++)
142 {
143 pD[ii+ldd*(jj+0)] = a0 * pA[ii+lda*(jj+0)] + beta * pC[ii+ldc*(jj+0)];
144 pD[ii+ldd*(jj+1)] = a1 * pA[ii+lda*(jj+1)] + beta * pC[ii+ldc*(jj+1)];
145 }
146 }
147 for(; jj<n; jj++)
148 {
149 a0 = alpha * dB[jj+0];
150 for(ii=0; ii<m; ii++)
151 {
152 pD[ii+ldd*(jj+0)] = a0 * pA[ii+lda*(jj+0)] + beta * pC[ii+ldc*(jj+0)];
153 }
154 }
155 }
156 return;
157 }
158
159
160
161#else
162
163#error : wrong LA choice
164
165#endif
166
167
168
169
170