CbmRoot
Loading...
Searching...
No Matches
CbmLitMatrixMath.cxx
Go to the documentation of this file.
1/* Copyright (C) 2009-2017 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
6
7#include <iostream>
8
9/*
10 * Matrix operations
11 */
12
13// SMij are indices for a 5x5 matrix.
14
15#define SM00 0
16#define SM01 1
17#define SM02 2
18#define SM03 3
19#define SM04 4
20
21#define SM10 1
22#define SM11 5
23#define SM12 6
24#define SM13 7
25#define SM14 8
26
27#define SM20 2
28#define SM21 6
29#define SM22 9
30#define SM23 10
31#define SM24 11
32
33#define SM30 3
34#define SM31 7
35#define SM32 10
36#define SM33 12
37#define SM34 13
38
39#define SM40 4
40#define SM41 8
41#define SM42 11
42#define SM43 13
43#define SM44 14
44
45bool InvSym15(std::vector<litfloat>& a)
46{
47 if (a.size() != 15) {
48 std::cout << "-E- InvSym15: size is not correct" << std::endl;
49 return false;
50 }
51
52 litfloat* pM = &a[0];
53
54 // Find all NECESSARY 2x2 dets: (25 of them)
55
56 const litfloat mDet2_23_01 = pM[SM20] * pM[SM31] - pM[SM21] * pM[SM30];
57 const litfloat mDet2_23_02 = pM[SM20] * pM[SM32] - pM[SM22] * pM[SM30];
58 const litfloat mDet2_23_03 = pM[SM20] * pM[SM33] - pM[SM23] * pM[SM30];
59 const litfloat mDet2_23_12 = pM[SM21] * pM[SM32] - pM[SM22] * pM[SM31];
60 const litfloat mDet2_23_13 = pM[SM21] * pM[SM33] - pM[SM23] * pM[SM31];
61 const litfloat mDet2_23_23 = pM[SM22] * pM[SM33] - pM[SM23] * pM[SM32];
62 const litfloat mDet2_24_01 = pM[SM20] * pM[SM41] - pM[SM21] * pM[SM40];
63 const litfloat mDet2_24_02 = pM[SM20] * pM[SM42] - pM[SM22] * pM[SM40];
64 const litfloat mDet2_24_03 = pM[SM20] * pM[SM43] - pM[SM23] * pM[SM40];
65 const litfloat mDet2_24_04 = pM[SM20] * pM[SM44] - pM[SM24] * pM[SM40];
66 const litfloat mDet2_24_12 = pM[SM21] * pM[SM42] - pM[SM22] * pM[SM41];
67 const litfloat mDet2_24_13 = pM[SM21] * pM[SM43] - pM[SM23] * pM[SM41];
68 const litfloat mDet2_24_14 = pM[SM21] * pM[SM44] - pM[SM24] * pM[SM41];
69 const litfloat mDet2_24_23 = pM[SM22] * pM[SM43] - pM[SM23] * pM[SM42];
70 const litfloat mDet2_24_24 = pM[SM22] * pM[SM44] - pM[SM24] * pM[SM42];
71 const litfloat mDet2_34_01 = pM[SM30] * pM[SM41] - pM[SM31] * pM[SM40];
72 const litfloat mDet2_34_02 = pM[SM30] * pM[SM42] - pM[SM32] * pM[SM40];
73 const litfloat mDet2_34_03 = pM[SM30] * pM[SM43] - pM[SM33] * pM[SM40];
74 const litfloat mDet2_34_04 = pM[SM30] * pM[SM44] - pM[SM34] * pM[SM40];
75 const litfloat mDet2_34_12 = pM[SM31] * pM[SM42] - pM[SM32] * pM[SM41];
76 const litfloat mDet2_34_13 = pM[SM31] * pM[SM43] - pM[SM33] * pM[SM41];
77 const litfloat mDet2_34_14 = pM[SM31] * pM[SM44] - pM[SM34] * pM[SM41];
78 const litfloat mDet2_34_23 = pM[SM32] * pM[SM43] - pM[SM33] * pM[SM42];
79 const litfloat mDet2_34_24 = pM[SM32] * pM[SM44] - pM[SM34] * pM[SM42];
80 const litfloat mDet2_34_34 = pM[SM33] * pM[SM44] - pM[SM34] * pM[SM43];
81
82 // Find all NECESSARY 3x3 dets: (30 of them)
83
84 const litfloat mDet3_123_012 = pM[SM10] * mDet2_23_12 - pM[SM11] * mDet2_23_02 + pM[SM12] * mDet2_23_01;
85 const litfloat mDet3_123_013 = pM[SM10] * mDet2_23_13 - pM[SM11] * mDet2_23_03 + pM[SM13] * mDet2_23_01;
86 const litfloat mDet3_123_023 = pM[SM10] * mDet2_23_23 - pM[SM12] * mDet2_23_03 + pM[SM13] * mDet2_23_02;
87 const litfloat mDet3_123_123 = pM[SM11] * mDet2_23_23 - pM[SM12] * mDet2_23_13 + pM[SM13] * mDet2_23_12;
88 const litfloat mDet3_124_012 = pM[SM10] * mDet2_24_12 - pM[SM11] * mDet2_24_02 + pM[SM12] * mDet2_24_01;
89 const litfloat mDet3_124_013 = pM[SM10] * mDet2_24_13 - pM[SM11] * mDet2_24_03 + pM[SM13] * mDet2_24_01;
90 const litfloat mDet3_124_014 = pM[SM10] * mDet2_24_14 - pM[SM11] * mDet2_24_04 + pM[SM14] * mDet2_24_01;
91 const litfloat mDet3_124_023 = pM[SM10] * mDet2_24_23 - pM[SM12] * mDet2_24_03 + pM[SM13] * mDet2_24_02;
92 const litfloat mDet3_124_024 = pM[SM10] * mDet2_24_24 - pM[SM12] * mDet2_24_04 + pM[SM14] * mDet2_24_02;
93 const litfloat mDet3_124_123 = pM[SM11] * mDet2_24_23 - pM[SM12] * mDet2_24_13 + pM[SM13] * mDet2_24_12;
94 const litfloat mDet3_124_124 = pM[SM11] * mDet2_24_24 - pM[SM12] * mDet2_24_14 + pM[SM14] * mDet2_24_12;
95 const litfloat mDet3_134_012 = pM[SM10] * mDet2_34_12 - pM[SM11] * mDet2_34_02 + pM[SM12] * mDet2_34_01;
96 const litfloat mDet3_134_013 = pM[SM10] * mDet2_34_13 - pM[SM11] * mDet2_34_03 + pM[SM13] * mDet2_34_01;
97 const litfloat mDet3_134_014 = pM[SM10] * mDet2_34_14 - pM[SM11] * mDet2_34_04 + pM[SM14] * mDet2_34_01;
98 const litfloat mDet3_134_023 = pM[SM10] * mDet2_34_23 - pM[SM12] * mDet2_34_03 + pM[SM13] * mDet2_34_02;
99 const litfloat mDet3_134_024 = pM[SM10] * mDet2_34_24 - pM[SM12] * mDet2_34_04 + pM[SM14] * mDet2_34_02;
100 const litfloat mDet3_134_034 = pM[SM10] * mDet2_34_34 - pM[SM13] * mDet2_34_04 + pM[SM14] * mDet2_34_03;
101 const litfloat mDet3_134_123 = pM[SM11] * mDet2_34_23 - pM[SM12] * mDet2_34_13 + pM[SM13] * mDet2_34_12;
102 const litfloat mDet3_134_124 = pM[SM11] * mDet2_34_24 - pM[SM12] * mDet2_34_14 + pM[SM14] * mDet2_34_12;
103 const litfloat mDet3_134_134 = pM[SM11] * mDet2_34_34 - pM[SM13] * mDet2_34_14 + pM[SM14] * mDet2_34_13;
104 const litfloat mDet3_234_012 = pM[SM20] * mDet2_34_12 - pM[SM21] * mDet2_34_02 + pM[SM22] * mDet2_34_01;
105 const litfloat mDet3_234_013 = pM[SM20] * mDet2_34_13 - pM[SM21] * mDet2_34_03 + pM[SM23] * mDet2_34_01;
106 const litfloat mDet3_234_014 = pM[SM20] * mDet2_34_14 - pM[SM21] * mDet2_34_04 + pM[SM24] * mDet2_34_01;
107 const litfloat mDet3_234_023 = pM[SM20] * mDet2_34_23 - pM[SM22] * mDet2_34_03 + pM[SM23] * mDet2_34_02;
108 const litfloat mDet3_234_024 = pM[SM20] * mDet2_34_24 - pM[SM22] * mDet2_34_04 + pM[SM24] * mDet2_34_02;
109 const litfloat mDet3_234_034 = pM[SM20] * mDet2_34_34 - pM[SM23] * mDet2_34_04 + pM[SM24] * mDet2_34_03;
110 const litfloat mDet3_234_123 = pM[SM21] * mDet2_34_23 - pM[SM22] * mDet2_34_13 + pM[SM23] * mDet2_34_12;
111 const litfloat mDet3_234_124 = pM[SM21] * mDet2_34_24 - pM[SM22] * mDet2_34_14 + pM[SM24] * mDet2_34_12;
112 const litfloat mDet3_234_134 = pM[SM21] * mDet2_34_34 - pM[SM23] * mDet2_34_14 + pM[SM24] * mDet2_34_13;
113 const litfloat mDet3_234_234 = pM[SM22] * mDet2_34_34 - pM[SM23] * mDet2_34_24 + pM[SM24] * mDet2_34_23;
114
115 // Find all NECESSARY 4x4 dets: (15 of them)
116
117 const litfloat mDet4_0123_0123 =
118 pM[SM00] * mDet3_123_123 - pM[SM01] * mDet3_123_023 + pM[SM02] * mDet3_123_013 - pM[SM03] * mDet3_123_012;
119 const litfloat mDet4_0124_0123 =
120 pM[SM00] * mDet3_124_123 - pM[SM01] * mDet3_124_023 + pM[SM02] * mDet3_124_013 - pM[SM03] * mDet3_124_012;
121 const litfloat mDet4_0124_0124 =
122 pM[SM00] * mDet3_124_124 - pM[SM01] * mDet3_124_024 + pM[SM02] * mDet3_124_014 - pM[SM04] * mDet3_124_012;
123 const litfloat mDet4_0134_0123 =
124 pM[SM00] * mDet3_134_123 - pM[SM01] * mDet3_134_023 + pM[SM02] * mDet3_134_013 - pM[SM03] * mDet3_134_012;
125 const litfloat mDet4_0134_0124 =
126 pM[SM00] * mDet3_134_124 - pM[SM01] * mDet3_134_024 + pM[SM02] * mDet3_134_014 - pM[SM04] * mDet3_134_012;
127 const litfloat mDet4_0134_0134 =
128 pM[SM00] * mDet3_134_134 - pM[SM01] * mDet3_134_034 + pM[SM03] * mDet3_134_014 - pM[SM04] * mDet3_134_013;
129 const litfloat mDet4_0234_0123 =
130 pM[SM00] * mDet3_234_123 - pM[SM01] * mDet3_234_023 + pM[SM02] * mDet3_234_013 - pM[SM03] * mDet3_234_012;
131 const litfloat mDet4_0234_0124 =
132 pM[SM00] * mDet3_234_124 - pM[SM01] * mDet3_234_024 + pM[SM02] * mDet3_234_014 - pM[SM04] * mDet3_234_012;
133 const litfloat mDet4_0234_0134 =
134 pM[SM00] * mDet3_234_134 - pM[SM01] * mDet3_234_034 + pM[SM03] * mDet3_234_014 - pM[SM04] * mDet3_234_013;
135 const litfloat mDet4_0234_0234 =
136 pM[SM00] * mDet3_234_234 - pM[SM02] * mDet3_234_034 + pM[SM03] * mDet3_234_024 - pM[SM04] * mDet3_234_023;
137 const litfloat mDet4_1234_0123 =
138 pM[SM10] * mDet3_234_123 - pM[SM11] * mDet3_234_023 + pM[SM12] * mDet3_234_013 - pM[SM13] * mDet3_234_012;
139 const litfloat mDet4_1234_0124 =
140 pM[SM10] * mDet3_234_124 - pM[SM11] * mDet3_234_024 + pM[SM12] * mDet3_234_014 - pM[SM14] * mDet3_234_012;
141 const litfloat mDet4_1234_0134 =
142 pM[SM10] * mDet3_234_134 - pM[SM11] * mDet3_234_034 + pM[SM13] * mDet3_234_014 - pM[SM14] * mDet3_234_013;
143 const litfloat mDet4_1234_0234 =
144 pM[SM10] * mDet3_234_234 - pM[SM12] * mDet3_234_034 + pM[SM13] * mDet3_234_024 - pM[SM14] * mDet3_234_023;
145 const litfloat mDet4_1234_1234 =
146 pM[SM11] * mDet3_234_234 - pM[SM12] * mDet3_234_134 + pM[SM13] * mDet3_234_124 - pM[SM14] * mDet3_234_123;
147
148 // Find the 5x5 det:
149
150 const litfloat det = pM[SM00] * mDet4_1234_1234 - pM[SM01] * mDet4_1234_0234 + pM[SM02] * mDet4_1234_0134
151 - pM[SM03] * mDet4_1234_0124 + pM[SM04] * mDet4_1234_0123;
152
153 if (det == 0) {
154 std::cout << "-E- InvSym15: zero determinant" << std::endl;
155 return false;
156 }
157
158 const litfloat oneOverDet = 1.0 / det;
159 const litfloat mn1OverDet = -oneOverDet;
160
161 pM[SM00] = mDet4_1234_1234 * oneOverDet;
162 pM[SM01] = mDet4_1234_0234 * mn1OverDet;
163 pM[SM02] = mDet4_1234_0134 * oneOverDet;
164 pM[SM03] = mDet4_1234_0124 * mn1OverDet;
165 pM[SM04] = mDet4_1234_0123 * oneOverDet;
166
167 pM[SM11] = mDet4_0234_0234 * oneOverDet;
168 pM[SM12] = mDet4_0234_0134 * mn1OverDet;
169 pM[SM13] = mDet4_0234_0124 * oneOverDet;
170 pM[SM14] = mDet4_0234_0123 * mn1OverDet;
171
172 pM[SM22] = mDet4_0134_0134 * oneOverDet;
173 pM[SM23] = mDet4_0134_0124 * mn1OverDet;
174 pM[SM24] = mDet4_0134_0123 * oneOverDet;
175
176 pM[SM33] = mDet4_0124_0124 * oneOverDet;
177 pM[SM34] = mDet4_0124_0123 * mn1OverDet;
178
179 pM[SM44] = mDet4_0123_0123 * oneOverDet;
180
181 return true;
182}
183
184
185bool Mult25(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
186{
187 if (a.size() != 25 || b.size() != 25 || c.size() != 25) {
188 std::cout << "-E- Mult25: size is not correct" << std::endl;
189 return false;
190 }
191
192 c[0] = a[0] * b[0] + a[1] * b[5] + a[2] * b[10] + a[3] * b[15] + a[4] * b[20];
193 c[1] = a[0] * b[1] + a[1] * b[6] + a[2] * b[11] + a[3] * b[16] + a[4] * b[21];
194 c[2] = a[0] * b[2] + a[1] * b[7] + a[2] * b[12] + a[3] * b[17] + a[4] * b[22];
195 c[3] = a[0] * b[3] + a[1] * b[8] + a[2] * b[13] + a[3] * b[18] + a[4] * b[23];
196 c[4] = a[0] * b[4] + a[1] * b[9] + a[2] * b[14] + a[3] * b[19] + a[4] * b[24];
197 c[5] = a[5] * b[0] + a[6] * b[5] + a[7] * b[10] + a[8] * b[15] + a[9] * b[20];
198 c[6] = a[5] * b[1] + a[6] * b[6] + a[7] * b[11] + a[8] * b[16] + a[9] * b[21];
199 c[7] = a[5] * b[2] + a[6] * b[7] + a[7] * b[12] + a[8] * b[17] + a[9] * b[22];
200 c[8] = a[5] * b[3] + a[6] * b[8] + a[7] * b[13] + a[8] * b[18] + a[9] * b[23];
201 c[9] = a[5] * b[4] + a[6] * b[9] + a[7] * b[14] + a[8] * b[19] + a[9] * b[24];
202 c[10] = a[10] * b[0] + a[11] * b[5] + a[12] * b[10] + a[13] * b[15] + a[14] * b[20];
203 c[11] = a[10] * b[1] + a[11] * b[6] + a[12] * b[11] + a[13] * b[16] + a[14] * b[21];
204 c[12] = a[10] * b[2] + a[11] * b[7] + a[12] * b[12] + a[13] * b[17] + a[14] * b[22];
205 c[13] = a[10] * b[3] + a[11] * b[8] + a[12] * b[13] + a[13] * b[18] + a[14] * b[23];
206 c[14] = a[10] * b[4] + a[11] * b[9] + a[12] * b[14] + a[13] * b[19] + a[14] * b[24];
207 c[15] = a[15] * b[0] + a[16] * b[5] + a[17] * b[10] + a[18] * b[15] + a[19] * b[20];
208 c[16] = a[15] * b[1] + a[16] * b[6] + a[17] * b[11] + a[18] * b[16] + a[19] * b[21];
209 c[17] = a[15] * b[2] + a[16] * b[7] + a[17] * b[12] + a[18] * b[17] + a[19] * b[22];
210 c[18] = a[15] * b[3] + a[16] * b[8] + a[17] * b[13] + a[18] * b[18] + a[19] * b[23];
211 c[19] = a[15] * b[4] + a[16] * b[9] + a[17] * b[14] + a[18] * b[19] + a[19] * b[24];
212 c[20] = a[20] * b[0] + a[21] * b[5] + a[22] * b[10] + a[23] * b[15] + a[24] * b[20];
213 c[21] = a[20] * b[1] + a[21] * b[6] + a[22] * b[11] + a[23] * b[16] + a[24] * b[21];
214 c[22] = a[20] * b[2] + a[21] * b[7] + a[22] * b[12] + a[23] * b[17] + a[24] * b[22];
215 c[23] = a[20] * b[3] + a[21] * b[8] + a[22] * b[13] + a[23] * b[18] + a[24] * b[23];
216 c[24] = a[20] * b[4] + a[21] * b[9] + a[22] * b[14] + a[23] * b[19] + a[24] * b[24];
217
218 return true;
219}
220
221bool Mult36(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
222{
223 if (a.size() != 36 || b.size() != 36 || c.size() != 36) {
224 std::cout << "-E- Mult36: size is not correct" << std::endl;
225 return false;
226 }
227
228 for (int i = 0; i < 6; ++i) {
229 for (int j = 0; j < 6; ++j) {
230 c[6 * i + j] = 0;
231
232 for (int k = 0; k < 6; ++k)
233 c[6 * i + j] += a[6 * i + k] * b[j + 6 * k];
234 }
235 }
236
237 return true;
238}
239
240bool Transpose25(std::vector<litfloat>& a)
241{
242 if (a.size() != 25) {
243 std::cout << "-E- Transpose25: size is not correct" << std::endl;
244 return true;
245 }
246 std::vector<litfloat> b(a);
247 a[0] = b[0];
248 a[1] = b[5];
249 a[2] = b[10];
250 a[3] = b[15];
251 a[4] = b[20];
252 a[5] = b[1];
253 a[6] = b[6];
254 a[7] = b[11];
255 a[8] = b[16];
256 a[9] = b[21];
257 a[10] = b[2];
258 a[11] = b[7];
259 a[12] = b[12];
260 a[13] = b[17];
261 a[14] = b[22];
262 a[15] = b[3];
263 a[16] = b[8];
264 a[17] = b[13];
265 a[18] = b[18];
266 a[19] = b[23];
267 a[20] = b[4];
268 a[21] = b[9];
269 a[22] = b[14];
270 a[23] = b[19];
271 a[24] = b[24];
272 return true;
273}
274
275
276bool Mult25On5(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
277{
278 if (a.size() != 25 || b.size() != 7 || c.size() != 7) {
279 std::cout << "-E- Mult25On5: size is not correct" << std::endl;
280 return false;
281 }
282 c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
283 c[1] = a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
284 c[2] = a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
285 c[3] = a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
286 c[4] = a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4];
287 return true;
288}
289
290bool Mult15On5(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
291{
292 if (a.size() != 15 || b.size() != 7 || c.size() != 7) {
293 std::cout << "-E- Mult15On5: size is not correct" << std::endl;
294 return false;
295 }
296 c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
297 c[1] = a[1] * b[0] + a[5] * b[1] + a[6] * b[2] + a[7] * b[3] + a[8] * b[4];
298 c[2] = a[2] * b[0] + a[6] * b[1] + a[9] * b[2] + a[10] * b[3] + a[11] * b[4];
299 c[3] = a[3] * b[0] + a[7] * b[1] + a[10] * b[2] + a[12] * b[3] + a[13] * b[4];
300 c[4] = a[4] * b[0] + a[8] * b[1] + a[11] * b[2] + a[13] * b[3] + a[14] * b[4];
301 return true;
302}
303
304bool Subtract(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
305{
306 if (a.size() != b.size() || a.size() != c.size()) {
307 std::cout << "-E- Subtract: size is not correct" << std::endl;
308 return false;
309 }
310 for (unsigned int i = 0; i < a.size(); ++i) {
311 c[i] = a[i] - b[i];
312 }
313 return true;
314}
315
316
317bool Add(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
318{
319 if (a.size() != b.size() || a.size() != c.size()) {
320 std::cout << "-E- Add: size is not correct" << std::endl;
321 return false;
322 }
323 for (unsigned int i = 0; i < a.size(); ++i) {
324 c[i] = a[i] + b[i];
325 }
326 return true;
327}
328
329
330/* a*b*a^T */
331bool Similarity(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
332{
333 if (a.size() != 25 || b.size() != 15 || c.size() != 15) {
334 std::cout << "-E- Similarity: size is not correct" << std::endl;
335 return false;
336 }
337
338 litfloat A = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
339 litfloat B = a[0] * b[1] + a[1] * b[5] + a[2] * b[6] + a[3] * b[7] + a[4] * b[8];
340 litfloat C = a[0] * b[2] + a[1] * b[6] + a[2] * b[9] + a[3] * b[10] + a[4] * b[11];
341 litfloat D = a[0] * b[3] + a[1] * b[7] + a[2] * b[10] + a[3] * b[12] + a[4] * b[13];
342 litfloat E = a[0] * b[4] + a[1] * b[8] + a[2] * b[11] + a[3] * b[13] + a[4] * b[14];
343
344 litfloat F = a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
345 litfloat G = a[5] * b[1] + a[6] * b[5] + a[7] * b[6] + a[8] * b[7] + a[9] * b[8];
346 litfloat H = a[5] * b[2] + a[6] * b[6] + a[7] * b[9] + a[8] * b[10] + a[9] * b[11];
347 litfloat I = a[5] * b[3] + a[6] * b[7] + a[7] * b[10] + a[8] * b[12] + a[9] * b[13];
348 litfloat J = a[5] * b[4] + a[6] * b[8] + a[7] * b[11] + a[8] * b[13] + a[9] * b[14];
349
350 litfloat K = a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
351 litfloat L = a[10] * b[1] + a[11] * b[5] + a[12] * b[6] + a[13] * b[7] + a[14] * b[8];
352 litfloat M = a[10] * b[2] + a[11] * b[6] + a[12] * b[9] + a[13] * b[10] + a[14] * b[11];
353 litfloat N = a[10] * b[3] + a[11] * b[7] + a[12] * b[10] + a[13] * b[12] + a[14] * b[13];
354 litfloat O = a[10] * b[4] + a[11] * b[8] + a[12] * b[11] + a[13] * b[13] + a[14] * b[14];
355
356 litfloat P = a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
357 litfloat Q = a[15] * b[1] + a[16] * b[5] + a[17] * b[6] + a[18] * b[7] + a[19] * b[8];
358 litfloat R = a[15] * b[2] + a[16] * b[6] + a[17] * b[9] + a[18] * b[10] + a[19] * b[11];
359 litfloat S = a[15] * b[3] + a[16] * b[7] + a[17] * b[10] + a[18] * b[12] + a[19] * b[13];
360 litfloat T = a[15] * b[4] + a[16] * b[8] + a[17] * b[11] + a[18] * b[13] + a[19] * b[14];
361
362 c[0] = A * a[0] + B * a[1] + C * a[2] + D * a[3] + E * a[4];
363 c[1] = A * a[5] + B * a[6] + C * a[7] + D * a[8] + E * a[9];
364 c[2] = A * a[10] + B * a[11] + C * a[12] + D * a[13] + E * a[14];
365 c[3] = A * a[15] + B * a[16] + C * a[17] + D * a[18] + E * a[19];
366 c[4] = A * a[20] + B * a[21] + C * a[22] + D * a[23] + E * a[24];
367
368 c[5] = F * a[5] + G * a[6] + H * a[7] + I * a[8] + J * a[9];
369 c[6] = F * a[10] + G * a[11] + H * a[12] + I * a[13] + J * a[14];
370 c[7] = F * a[15] + G * a[16] + H * a[17] + I * a[18] + J * a[19];
371 c[8] = F * a[20] + G * a[21] + H * a[22] + I * a[23] + J * a[24];
372
373 c[9] = K * a[10] + L * a[11] + M * a[12] + N * a[13] + O * a[14];
374 c[10] = K * a[15] + L * a[16] + M * a[17] + N * a[18] + O * a[19];
375 c[11] = K * a[20] + L * a[21] + M * a[22] + N * a[23] + O * a[24];
376
377 c[12] = P * a[15] + Q * a[16] + R * a[17] + S * a[18] + T * a[19];
378 c[13] = P * a[20] + Q * a[21] + R * a[22] + S * a[23] + T * a[24];
379
380 c[14] = (a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4]) * a[20]
381 + (a[20] * b[1] + a[21] * b[5] + a[22] * b[6] + a[23] * b[7] + a[24] * b[8]) * a[21]
382 + (a[20] * b[2] + a[21] * b[6] + a[22] * b[9] + a[23] * b[10] + a[24] * b[11]) * a[22]
383 + (a[20] * b[3] + a[21] * b[7] + a[22] * b[10] + a[23] * b[12] + a[24] * b[13]) * a[23]
384 + (a[20] * b[4] + a[21] * b[8] + a[22] * b[11] + a[23] * b[13] + a[24] * b[14]) * a[24];
385 return true;
386}
387
388
389bool Mult15On25(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
390{
391 if (a.size() != 15 || b.size() != 25 || c.size() != 25) {
392 std::cout << "-E- Mult15On25: size is not correct" << std::endl;
393 return false;
394 }
395 c[0] = a[0] * b[0] + a[1] * b[5] + a[2] * b[10] + a[3] * b[15] + a[4] * b[20];
396 c[1] = a[0] * b[1] + a[1] * b[6] + a[2] * b[11] + a[3] * b[16] + a[4] * b[21];
397 c[2] = a[0] * b[2] + a[1] * b[7] + a[2] * b[12] + a[3] * b[17] + a[4] * b[22];
398 c[3] = a[0] * b[3] + a[1] * b[8] + a[2] * b[13] + a[3] * b[18] + a[4] * b[23];
399 c[4] = a[0] * b[4] + a[1] * b[9] + a[2] * b[14] + a[3] * b[19] + a[4] * b[24];
400 c[5] = a[1] * b[0] + a[5] * b[5] + a[6] * b[10] + a[7] * b[15] + a[8] * b[20];
401 c[6] = a[1] * b[1] + a[5] * b[6] + a[6] * b[11] + a[7] * b[16] + a[8] * b[21];
402 c[7] = a[1] * b[2] + a[5] * b[7] + a[6] * b[12] + a[7] * b[17] + a[8] * b[22];
403 c[8] = a[1] * b[3] + a[5] * b[8] + a[6] * b[13] + a[7] * b[18] + a[8] * b[23];
404 c[9] = a[1] * b[4] + a[5] * b[9] + a[6] * b[14] + a[7] * b[19] + a[8] * b[24];
405 c[10] = a[2] * b[0] + a[6] * b[5] + a[9] * b[10] + a[10] * b[15] + a[11] * b[20];
406 c[11] = a[2] * b[1] + a[6] * b[6] + a[9] * b[11] + a[10] * b[16] + a[11] * b[21];
407 c[12] = a[2] * b[2] + a[6] * b[7] + a[9] * b[12] + a[10] * b[17] + a[11] * b[22];
408 c[13] = a[2] * b[3] + a[6] * b[8] + a[9] * b[13] + a[10] * b[18] + a[11] * b[23];
409 c[14] = a[2] * b[4] + a[6] * b[9] + a[9] * b[14] + a[10] * b[19] + a[11] * b[24];
410 c[15] = a[3] * b[0] + a[7] * b[5] + a[10] * b[10] + a[12] * b[15] + a[13] * b[20];
411 c[16] = a[3] * b[1] + a[7] * b[6] + a[10] * b[11] + a[12] * b[16] + a[13] * b[21];
412 c[17] = a[3] * b[2] + a[7] * b[7] + a[10] * b[12] + a[12] * b[17] + a[13] * b[22];
413 c[18] = a[3] * b[3] + a[7] * b[8] + a[10] * b[13] + a[12] * b[18] + a[13] * b[23];
414 c[19] = a[3] * b[4] + a[7] * b[9] + a[10] * b[14] + a[12] * b[19] + a[13] * b[24];
415 c[20] = a[4] * b[0] + a[8] * b[5] + a[11] * b[10] + a[13] * b[15] + a[14] * b[20];
416 c[21] = a[4] * b[1] + a[8] * b[6] + a[11] * b[11] + a[13] * b[16] + a[14] * b[21];
417 c[22] = a[4] * b[2] + a[8] * b[7] + a[11] * b[12] + a[13] * b[17] + a[14] * b[22];
418 c[23] = a[4] * b[3] + a[8] * b[8] + a[11] * b[13] + a[13] * b[18] + a[14] * b[23];
419 c[24] = a[4] * b[4] + a[8] * b[9] + a[11] * b[14] + a[13] * b[19] + a[14] * b[24];
420
421 return true;
422}
423
424bool Mult25On15(const std::vector<litfloat>& a, const std::vector<litfloat>& b, std::vector<litfloat>& c)
425{
426 if (a.size() != 25 || b.size() != 15 || c.size() != 25) {
427 std::cout << "-E- Mult15On25: size is not correct" << std::endl;
428 return false;
429 }
430 c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
431 c[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[6] + a[3] * b[7] + a[4] * b[8];
432 c[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[9] + a[3] * b[10] + a[4] * b[11];
433 c[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[10] + a[3] * b[12] + a[4] * b[13];
434 c[4] = a[0] * b[4] + a[1] * b[8] + a[2] * b[11] + a[3] * b[13] + a[4] * b[14];
435 c[5] = a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
436 c[6] = a[5] * b[1] + a[6] * b[5] + a[7] * b[6] + a[8] * b[7] + a[9] * b[8];
437 c[7] = a[5] * b[2] + a[6] * b[6] + a[7] * b[9] + a[8] * b[10] + a[9] * b[11];
438 c[8] = a[5] * b[3] + a[6] * b[7] + a[7] * b[10] + a[8] * b[12] + a[9] * b[13];
439 c[9] = a[5] * b[4] + a[6] * b[8] + a[7] * b[11] + a[8] * b[13] + a[9] * b[14];
440 c[10] = a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
441 c[11] = a[10] * b[1] + a[11] * b[5] + a[12] * b[6] + a[13] * b[7] + a[14] * b[8];
442 c[12] = a[10] * b[2] + a[11] * b[6] + a[12] * b[9] + a[13] * b[10] + a[14] * b[11];
443 c[13] = a[10] * b[3] + a[11] * b[7] + a[12] * b[10] + a[13] * b[12] + a[14] * b[13];
444 c[14] = a[10] * b[4] + a[11] * b[8] + a[12] * b[11] + a[13] * b[13] + a[14] * b[14];
445 c[15] = a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
446 c[16] = a[15] * b[1] + a[16] * b[5] + a[17] * b[6] + a[18] * b[7] + a[19] * b[8];
447 c[17] = a[15] * b[2] + a[16] * b[6] + a[17] * b[9] + a[18] * b[10] + a[19] * b[11];
448 c[18] = a[15] * b[3] + a[16] * b[7] + a[17] * b[10] + a[18] * b[12] + a[19] * b[13];
449 c[19] = a[15] * b[4] + a[16] * b[8] + a[17] * b[11] + a[18] * b[13] + a[19] * b[14];
450 c[20] = a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4];
451 c[21] = a[20] * b[1] + a[21] * b[5] + a[22] * b[6] + a[23] * b[7] + a[24] * b[8];
452 c[22] = a[20] * b[2] + a[21] * b[6] + a[22] * b[9] + a[23] * b[10] + a[24] * b[11];
453 c[23] = a[20] * b[3] + a[21] * b[7] + a[22] * b[10] + a[23] * b[12] + a[24] * b[13];
454 c[24] = a[20] * b[4] + a[21] * b[8] + a[22] * b[11] + a[23] * b[13] + a[24] * b[14];
455
456 return true;
457}
double litfloat
Definition CbmLitFloat.h:19
#define SM33
bool Similarity(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM12
#define SM13
#define SM40
#define SM14
bool Add(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Transpose25(std::vector< litfloat > &a)
bool Mult15On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM23
#define SM22
bool Subtract(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM10
bool Mult25On15(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM00
#define SM30
#define SM01
#define SM02
#define SM41
bool Mult25(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM21
#define SM32
#define SM11
#define SM20
#define SM44
bool Mult36(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
#define SM04
#define SM43
#define SM31
#define SM03
#define SM34
#define SM42
bool Mult25On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Mult15On25(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool InvSym15(std::vector< litfloat > &a)
#define SM24