1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008-2008 - INRIA - Arnaud TORSET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include "prod.h"
/* #define LOCAL_DEBUG */
#define ERROR(x) printf("diff = %e\n", x)
static int dprodsTest(void) {
double value1 = 3.0;
double value2 = 1.123456789;
printf("\n>>>> prod Double Scalar Test\n");
assert(dprods(value1) == 3.0);
assert(dprods(value2) == 1.123456789);
return 0;
}
static int dprodaTest(void) {
double table1[3] = {3.0, 3.0, 3.0};
double table2[5] = {9.186784563,
9.186784563,
9.186784563,
9.186784563,
9.186784563};
printf("\n>>>> prod Double Array Test\n");
printf("%f\n", dproda(table1, 3));
assert(dproda(table1, 3) == 27.0);
assert((dproda(table2, 5) - (9.186784563 * 9.186784563 * 9.186784563 * 9.186784563 * 9.186784563)) / dproda(table2, 5) < 3e-15);
return 0;
}
static int dcolumnprodaTest(void) {
int i = 0;
double table1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0};
double table2[10] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
double columnProductedTable1_3_3[3] = {0};
double columnProductedTable1_1_9[1] = {0};
double columnProductedTable1_9_1[9] = {0};
double columnProductedTable2_2_5[2] = {0};
double columnProductedTable2_5_2[5] = {0};
printf("\n>>>> Column prod Double Array Test\n");
/*
[ 1 2 3 ] [ 1*2*3=6 ]
[ 4 5 6 ] => [ 4*5*6=120 ]
[ 7 8 9 ] [ 7*8*9=504 ]
*/
dcolumnproda(table1, 3, 3,columnProductedTable1_3_3);
assert(columnProductedTable1_3_3[0] == 6.0);
assert(columnProductedTable1_3_3[1] == 120.0);
assert(columnProductedTable1_3_3[2] == 504.0);
/*
[ 1 2 3 4 5 6 7 8 9 ] => [ 362880 ]
*/
dcolumnproda(table1, 1, 9,columnProductedTable1_1_9);
assert(columnProductedTable1_1_9[0] == 362880.0);
/*
[ 1 ] [ 1 ]
[ 2 ] [ 2 ]
[ 3 ] [ 3 ]
[ 4 ] [ 4 ]
[ 5 ] => [ 5 ]
[ 6 ] [ 6 ]
[ 7 ] [ 7 ]
[ 8 ] [ 8 ]
[ 9 ] [ 9 ]
*/
dcolumnproda(table1, 9, 1,columnProductedTable1_9_1);
for ( i = 0 ; i < 9 ; ++i) {
printf("columnProductedTable1_9_1[%d] = %e\n", i, columnProductedTable1_9_1[i]);
assert(columnProductedTable1_9_1[i] == table1[i]);
}
/*
[ 1 3 5 7 9 ] [ 945 ]
[ 2 4 6 8 10 ] => [ 3840 ]
*/
dcolumnproda(table2, 2, 5,columnProductedTable2_2_5);
assert(columnProductedTable2_2_5[0] == 945.0);
assert(columnProductedTable2_2_5[1] == 3840.0);
for ( i = 0 ; i < 2 ; ++i) {
printf("columnProductedTable2_2_5[%d] = %e\n", i, columnProductedTable2_2_5[i]);
}
/*
[ 1 6 ] [ 6 ]
[ 2 7 ] => [ 14 ]
[ 3 8 ] [ 24 ]
[ 4 9 ] [ 36 ]
[ 5 10 ] [ 50 ]
*/
dcolumnproda(table2, 5, 2,columnProductedTable2_5_2);
assert(columnProductedTable2_5_2[0] == 6.0);
assert(columnProductedTable2_5_2[1] == 14.0);
assert(columnProductedTable2_5_2[2] == 24.0);
assert(columnProductedTable2_5_2[3] == 36.0);
assert(columnProductedTable2_5_2[4] == 50.0);
for ( i = 0 ; i < 5 ; ++i) {
printf("columnProductedTable2_5_2[%d] = %e\n", i, columnProductedTable2_5_2[i]);
}
return 0;
}
static int drowprodaTest(void) {
int i = 0;
double table1[9] = {1.0, 4.0, 7.0, 2.0 , 5.0, 8.0, 3.0, 6.0, 9.0};
double table2[10] = {1.0, 2.0, 3.0, 4.0 , 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
double rowProductedTable1_3_3[3] = {0};
double rowProductedTable1_1_9[9] = {0};
double rowProductedTable1_9_1[1] = {0};
double rowProductedTable2_2_5[5] = {0};
double rowProductedTable2_5_2[2] = {0};
printf("\n>>>> Row prod Double Array Test\n");
/*
[ 1 2 3 ]
[ 4 5 6 ] => [ 28 80 162 ]
[ 7 8 9 ]
*/
drowproda(table1, 3, 3,rowProductedTable1_3_3);
for ( i = 0 ; i < 3 ; ++i) {
printf("rowProductedTable1_3_3[%d] = %e\n", i, rowProductedTable1_3_3[i]);
}
assert(rowProductedTable1_3_3[0] == 28.0);
assert(rowProductedTable1_3_3[1] == 80.0);
assert(rowProductedTable1_3_3[2] == 162.0);
/*
[ 1 2 3 4 5 6 7 8 9 ] => [ 1 2 3 4 5 6 7 8 9 ]
*/
drowproda(table1, 1, 9,rowProductedTable1_1_9);
for ( i = 0 ; i < 9 ; ++i) {
printf("rowProductedTable1_1_9[%d] = %e\n", i, rowProductedTable1_1_9[i]);
assert(rowProductedTable1_1_9[i] == table1[i]);
}
/*
[ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
[ 5 ] => [ 362880 ]
[ 6 ]
[ 7 ]
[ 8 ]
[ 9 ]
*/
drowproda(table1, 9, 1,rowProductedTable1_9_1);
assert(rowProductedTable1_9_1[0] == 362880.0);
/*
[ 1 3 5 7 9 ]
[ 2 4 6 8 10 ] => [ 2 12 30 56 90 ]
*/
drowproda(table2, 2, 5,rowProductedTable2_2_5);
assert(rowProductedTable2_2_5[0] == 2.0);
assert(rowProductedTable2_2_5[1] == 12.0);
assert(rowProductedTable2_2_5[2] == 30.0);
assert(rowProductedTable2_2_5[3] == 56.0);
assert(rowProductedTable2_2_5[4] == 90.0);
for ( i = 0 ; i < 5 ; ++i) {
printf("rowProductedTable2_2_5[%d] = %e\n", i, rowProductedTable2_2_5[i]);
}
/*
[ 1 6 ]
[ 2 7 ] => [ 120 30240 ]
[ 3 8 ]
[ 4 9 ]
[ 5 10 ]
*/
drowproda(table2, 5, 2,rowProductedTable2_5_2);
assert(rowProductedTable2_5_2[0] == 120.0);
assert(rowProductedTable2_5_2[1] == 30240.0);
for ( i = 0 ; i < 2 ; ++i) {
printf("rowProductedTable2_5_2[%d] = %e\n", i, rowProductedTable2_5_2[i]);
}
return 0;
}
static int zprodsTest(void) {
doubleComplex value1 = DoubleComplex(3.0, 3.0);
doubleComplex value2 = DoubleComplex(1.123456789, 1.123456789);
printf("\n>>>> prod Double Complex Scalar Test\n");
assert(zreals(zprods(value1)) == 3.0);
assert(zimags(zprods(value1)) == 3.0);
assert(zreals(zprods(value2)) == 1.123456789);
assert(zimags(zprods(value2)) == 1.123456789);
return 0;
}
static int zprodaTest(void) {
doubleComplex value1 = DoubleComplex(3.0, 3.0);
doubleComplex table1[3];
doubleComplex value2 = DoubleComplex(9.186784563,9.186784563);
doubleComplex table2[5];
printf("\n>>>> prod Double Complex Array Test\n");
table1[0] = value1;
table1[1] = value1;
table1[2] = value1;
table2[0] = value2;
table2[1] = value2;
table2[2] = value2;
table2[3] = value2;
table2[4] = value2;
#ifdef LOCAL_DEBUG
printf("--------\n");
printf("%e\n", zreals(zproda(table1, 3)));
printf("%e\n", zimags(zproda(table1, 3)));
printf("%1.20f\n", zreals(zproda(table2, 5)));
printf("%1.20f\n", zimags(zproda(table2, 5)));
printf("%1.20f\n", zreals(zproda(table2, 5)) + 261744.55211053110542707);
printf("--------\n");
#endif
assert(zreals(zproda(table1, 3)) == -54.0);
assert(zimags(zproda(table1, 3)) == 54.0);
assert(fabs(zreals(zproda(table2, 5)) + 261744.55211053110542707) < 3e-16);
assert(fabs(zimags(zproda(table2, 5)) + 261744.55211053110542707) < 3e-16);
return 0;
}
static int zrowprodaTest(void) {
int i = 0;
doubleComplex in[12];
doubleComplex rowProductedIn_4_3[3];
doubleComplex rowProductedIn_3_4[4];
doubleComplex rowProductedIn_6_2[2];
doubleComplex rowProductedIn_2_6[6];
doubleComplex rowProductedIn_1_12[12];
doubleComplex rowProductedIn_12_1[1];
printf("\n>>>> Row prod Double Complex Array Test\n");
/* Init input var */
for (i = 0 ; i < 12 ; ++i)
{
in[i] = DoubleComplex((double) i / 10.0, (11.0 - (double) i) / 10.0);
}
/*
[ 1.1i 0.4+0.7i 0.8+0.3i ]
[ 0.1+i 0.5+0.6i 0.9+0.2i ] => [ 0.6787000000000000810019 - 0.5456i
[ 0.2+0.9i 0.6+0.5i 1+0.1i ] - 0.3964999999999999635847,
[ 0.3+0.8i 0.7+0.4i 1.1 ] 0.678700000000000192024 + 0.5456i]
*/
zrowproda(in, 4, 3, rowProductedIn_4_3);
for (i = 0 ; i < 3 ; ++i) {
printf("rowProductedIn_4_3[%d] = %e + %ei\n", i, zreals(rowProductedIn_4_3[i]), zimags(rowProductedIn_4_3[i]));
}
assert(fabs(zreals(rowProductedIn_4_3[0]) - 0.6787000000000000810019) < 3e-16);
assert(fabs(zimags(rowProductedIn_4_3[0]) + 0.5456) < 3e-16);
assert(fabs(zreals(rowProductedIn_4_3[1]) + 0.3964999999999999635847) < 3e-16);
assert(fabs(zimags(rowProductedIn_4_3[1]) - 0.0) < 3e-16);
assert(fabs(zreals(rowProductedIn_4_3[2]) - 0.6787000000000000810019) < 3e-16);
assert(fabs(zimags(rowProductedIn_4_3[2]) - 0.5456) < 3e-16);
/*
[ 1.1i 0.3+0.8i 0.6+0.5i 0.9+0.2i ]
[ 0.1+i 0.4+0.7i 0.7+0.4i 1+0.1i ] => [ - 0.3190000000000000612843 - 0.9680000000000000826006i,
[ 0.2+0.9i 0.5+0.6i 0.8+0.3i 1.1 ] - 0.5380000000000000337508 + 0.0010000000000000563993i,
- 0.0010000000000000008882 + 0.5379999999999999227285i,
0.9680000000000000826006 + 0.3190000000000000612843i ]
*/
zrowproda(in, 3, 4, rowProductedIn_3_4);
for (i = 0 ; i < 4 ; ++i) {
printf("rowProductedIn_3_4[%d] = %e + %ei\n", i, zreals(rowProductedIn_3_4[i]), zimags(rowProductedIn_3_4[i]));
}
assert(fabs(zreals(rowProductedIn_3_4[0]) + 0.3190000000000000612843) < 3e-16);
assert(fabs(zimags(rowProductedIn_3_4[0]) + 0.9680000000000000826006) < 3e-16);
assert(fabs(zreals(rowProductedIn_3_4[1]) + 0.5380000000000000337508) < 3e-16);
assert(fabs(zimags(rowProductedIn_3_4[1]) - 0.0010000000000000563993 ) < 3e-16);
assert(fabs(zreals(rowProductedIn_3_4[2]) + 0.0010000000000000008882) < 3e-16);
assert(fabs(zimags(rowProductedIn_3_4[2]) - 0.5379999999999999227285) < 3e-16);
assert(fabs(zreals(rowProductedIn_3_4[3]) - 0.9680000000000000826006) < 3e-16);
assert(fabs(zimags(rowProductedIn_3_4[3]) - 0.3190000000000000612843) < 3e-16);
/*
[ 1.1i 0.6+0.5i ]
[ 0.1+i 0.7+0.4i ]
[ 0.2+0.9i 0.8+0.3i ] => [ 0.1725900000000000766853 + 0.5204650000000000664713i,
[ 0.3+0.8i 0.9+0.2i ] - 0.1725899999999999934186 + 0.5204649999999999554490i ]
[ 0.4+0.7i 1+0.1i ]
[ 0.5+0.6i 1.1 ]
*/
zrowproda(in, 6, 2, rowProductedIn_6_2);
for (i = 0 ; i < 2 ; ++i) {
printf("rowProductedIn_6_2[%d] = %e + %ei\n", i, zreals(rowProductedIn_6_2[i]), zimags(rowProductedIn_6_2[i]));
}
assert(fabs(zreals(rowProductedIn_6_2[0]) - 0.1725900000000000766853) < 3e-16);
assert(fabs(zimags(rowProductedIn_6_2[0]) - 0.5204650000000000664713) < 3e-16);
assert(fabs(zreals(rowProductedIn_6_2[1]) + 0.1725899999999999934186) < 3e-16);
assert(fabs(zimags(rowProductedIn_6_2[1]) - 0.5204649999999999554490 ) < 3e-16);
/*
[ 1.1i 0.2+0.9i 0.4+0.7i 0.6+0.5i 0.8+0.3i 1+0.1i ]
[ 0.1+i 0.3+0.8i 0.5+0.6i 0.7+0.4i 0.9+0.2i 1.1 ] => [ - 1.1000000000000000888178 + 0.11i,
- 0.6600000000000001421086 + 0.4300000000000000488498i,
- 0.2199999999999999733547 + 0.5899999999999999689138i,
0.2199999999999999733547 + 0.5899999999999999689138i,
0.6600000000000001421086 + 0.4300000000000000488498i,
1.1000000000000000888178 + 0.11i ]
*/
zrowproda(in, 2, 6, rowProductedIn_2_6);
for (i = 0 ; i < 6 ; ++i) {
printf("rowProductedIn_2_6[%d] = %e + %ei\n", i, zreals(rowProductedIn_2_6[i]), zimags(rowProductedIn_2_6[i]));
}
assert(fabs(zreals(rowProductedIn_2_6[0]) + 1.1000000000000000888178) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[0]) - 0.11) < 3e-16);
assert(fabs(zreals(rowProductedIn_2_6[1]) + 0.6600000000000001421086) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[1]) - 0.4300000000000000488498 ) < 3e-16);
assert(fabs(zreals(rowProductedIn_2_6[2]) + 0.2199999999999999733547) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[2]) - 0.5899999999999999689138) < 3e-16);
assert(fabs(zreals(rowProductedIn_2_6[3]) - 0.2199999999999999733547) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[3]) - 0.5899999999999999689138 ) < 3e-16);
assert(fabs(zreals(rowProductedIn_2_6[4]) - 0.6600000000000001421086) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[4]) - 0.4300000000000000488498) < 3e-16);
assert(fabs(zreals(rowProductedIn_2_6[5]) - 1.1000000000000000888178) < 3e-16);
assert(fabs(zimags(rowProductedIn_2_6[5]) - 0.11 ) < 3e-16);
/*
[ 1.1i 0.1+i 0.2+0.9i 0.3+0.8i 0.4+0.7i 0.5+0.6i 0.6+0.5i 0.7+0.4i 0.8+0.3i 0.9+0.2i 1+0.1i 1.1 ]
=>
[ 1.1i 0.1+i 0.2+0.9i 0.3+0.8i 0.4+0.7i 0.5+0.6i 0.6+0.5i 0.7+0.4i 0.8+0.3i 0.9+0.2i 1+0.1i 1.1 ]
*/
zrowproda(in, 1, 12, rowProductedIn_1_12);
for (i = 0 ; i < 12 ; ++i) {
printf("rowProductedIn_1_12[%d] = %e + %ei\n", i, zreals(rowProductedIn_1_12[i]), zimags(rowProductedIn_1_12[i]));
assert(zreals(rowProductedIn_1_12[i]) == zreals(in[i]) && zimags(rowProductedIn_1_12[i]) == zimags(in[i]));
}
/*
[ 1.1i ]
[ 0.1+i ]
[ 0.2+0.9i ]
[ 0.3+0.8i ]
[ 0.4+0.7i ]
[ 0.5+0.6i ]
[ 0.6+0.5i ] => [- 0.3006711243250001497351 + 0.0000000000000000038164i ]
[ 0.7+0.4i ]
[ 0.8+0.3i ]
[ 0.9+0.2i ]
[ 1+0.1i ]
[ 1.1 ]
*/
zrowproda(in, 12, 1, rowProductedIn_12_1);
printf("rowProductedIn_12_1[%d] = %e + %ei\n", 0, zreals(rowProductedIn_12_1[0]), zimags(rowProductedIn_12_1[0]));
assert(fabs(zreals(rowProductedIn_12_1[0]) + 0.3006711243250001497351) < 3e-16);
assert(fabs(zimags(rowProductedIn_12_1[0]) - 0.0000000000000000038164) < 3e-16);
return 0;
}
static int zcolumnprodaTest(void) {
int i = 0;
doubleComplex in[12];
doubleComplex columnProductedIn_4_3[4];
doubleComplex columnProductedIn_3_4[3];
doubleComplex columnProductedIn_6_2[6];
doubleComplex columnProductedIn_2_6[2];
doubleComplex columnProductedIn_1_12[1];
doubleComplex columnProductedIn_12_1[12];
printf("\n>>>> Columnprod Double Complex Array Test\n");
/* Init input var */
for (i = 0 ; i < 12 ; ++i)
{
in[i] = DoubleComplex((double) i / 10.0, (11.0 - (double) i) / 10.0);
}
/*
[ 1.1i 0.4+0.7i 0.8+0.3i ] [ - 0.7480000000000001092460 + 0.1210000000000001074696i ]
[ 0.1+i 0.5+0.6i 0.9+0.2i ] => [ - 0.6069999999999999840128 + 0.3940000000000001278977i ]
[ 0.2+0.9i 0.6+0.5i 1+0.1i ] [ - 0.3940000000000000168754 + 0.6069999999999999840128i ]
[ 0.3+0.8i 0.7+0.4i 1.1 ] [ - 0.1210000000000000935918 + 0.7479999999999999982236i ]
*/
zcolumnproda(in, 4, 3, columnProductedIn_4_3);
for (i = 0 ; i < 4 ; ++i) {
printf("columnProductedIn_4_3[%d] = %e + %ei\n", i, zreals(columnProductedIn_4_3[i]), zimags(columnProductedIn_4_3[i]));
}
assert(fabs(zreals(columnProductedIn_4_3[0]) + 0.7480000000000001092460) < 3e-16);
assert(fabs(zimags(columnProductedIn_4_3[0]) - 0.1210000000000001074696) < 3e-16);
assert(fabs(zreals(columnProductedIn_4_3[1]) + 0.6069999999999999840128) < 3e-16);
assert(fabs(zimags(columnProductedIn_4_3[1]) - 0.394000000000000127897) < 3e-16);
assert(fabs(zreals(columnProductedIn_4_3[2]) + 0.3940000000000000168754) < 3e-16);
assert(fabs(zimags(columnProductedIn_4_3[2]) - 0.606999999999999984012) < 3e-16);
assert(fabs(zreals(columnProductedIn_4_3[3]) + 0.1210000000000000935918) < 3e-16);
assert(fabs(zimags(columnProductedIn_4_3[3]) - 0.7479999999999999982236) < 3e-16);
/*
[ 1.1i 0.3+0.8i 0.6+0.5i 0.9+0.2i ] [ - 0.5753000000000000335731 - 0.3564000000000000500933i ]
[ 0.1+i 0.4+0.7i 0.7+0.4i 1+0.1i ] => [ - 0.6564999999999998614442 + 0.0000000000000000693889i ]
[ 0.2+0.9i 0.5+0.6i 0.8+0.3i 1.1 ] [ - 0.5753000000000001445955 + 0.3564000000000001056044i ]
*/
zcolumnproda(in, 3, 4, columnProductedIn_3_4);
for (i = 0 ; i < 3 ; ++i) {
printf("columnProductedIn_3_4[%d] = %e + %ei\n", i, zreals(columnProductedIn_3_4[i]), zimags(columnProductedIn_3_4[i]));
}
assert(fabs(zreals(columnProductedIn_3_4[0]) + 0.5753000000000000335731) < 3e-16);
assert(fabs(zimags(columnProductedIn_3_4[0]) + 0.3564000000000000500933) < 3e-16);
assert(fabs(zreals(columnProductedIn_3_4[1]) + 0.6564999999999998614442) < 3e-16);
assert(fabs(zimags(columnProductedIn_3_4[1]) - 0.0000000000000000693889) < 3e-16);
assert(fabs(zreals(columnProductedIn_3_4[2]) + 0.5753000000000001445955) < 3e-16);
assert(fabs(zimags(columnProductedIn_3_4[2]) - 0.3564000000000001056044) < 3e-16);
/*
[ 1.1i 0.6+0.5i ] [ - 0.5500000000000000444089 + 0.6600000000000000310862i ]
[ 0.1+i 0.7+0.4i ] [ - 0.3300000000000000155431 + 0.7399999999999999911182i ]
[ 0.2+0.9i 0.8+0.3i ] => [ - 0.1099999999999999866773 + 0.7800000000000000266454i ]
[ 0.3+0.8i 0.9+0.2i ] [ 0.1099999999999999866773 + 0.7800000000000000266454i ]
[ 0.4+0.7i 1+0.1i ] [ 0.3300000000000000155431 + 0.7399999999999999911182i ]
[ 0.5+0.6i 1.1 ] [ 0.5500000000000000444089 + 0.6600000000000000310862i ]
*/
zcolumnproda(in, 6, 2, columnProductedIn_6_2);
for (i = 0 ; i < 6 ; ++i) {
printf("columnProductedIn_6_2[%d] = %e + %ei\n", i, zreals(columnProductedIn_6_2[i]), zimags(columnProductedIn_6_2[i]));
}
assert(fabs(zreals(columnProductedIn_6_2[0]) + 0.5500000000000000444089) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[0]) - 0.6600000000000000310862) < 3e-16);
assert(fabs(zreals(columnProductedIn_6_2[1]) + 0.3300000000000000155431) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[1]) - 0.7399999999999999911182) < 3e-16);
assert(fabs(zreals(columnProductedIn_6_2[2]) + 0.1099999999999999866773) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[2]) - 0.7800000000000000266454) < 3e-16);
assert(fabs(zreals(columnProductedIn_6_2[3]) - 0.1099999999999999866773) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[3]) - 0.7800000000000000266454) < 3e-16);
assert(fabs(zreals(columnProductedIn_6_2[4]) - 0.3300000000000000155431) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[4]) - 0.7399999999999999911182) < 3e-16);
assert(fabs(zreals(columnProductedIn_6_2[5]) - 0.5500000000000000444089) < 3e-16);
assert(fabs(zimags(columnProductedIn_6_2[5]) - 0.6600000000000000310862) < 3e-16);
/*
[ 1.1i 0.2+0.9i 0.4+0.7i 0.6+0.5i 0.8+0.3i 1+0.1i ] [ 0.2212649999999999894662 - 0.5017100000000001003286i ]
[ 0.1+i 0.3+0.8i 0.5+0.6i 0.7+0.4i 0.9+0.2i 1.1 ] => [ - 0.2212649999999999894662 - 0.5017100000000001003286i ]
*/
zcolumnproda(in, 2, 6, columnProductedIn_2_6);
for (i = 0 ; i < 2 ; ++i) {
printf("columnProductedIn_2_6[%d] = %e + %ei\n", i, zreals(columnProductedIn_2_6[i]), zimags(columnProductedIn_2_6[i]));
}
assert(fabs(zreals(columnProductedIn_2_6[0]) - 0.2212649999999999894662) < 3e-16);
assert(fabs(zimags(columnProductedIn_2_6[0]) + 0.5017100000000001003286) < 3e-16);
assert(fabs(zreals(columnProductedIn_2_6[1]) + 0.2212649999999999894662) < 3e-16);
assert(fabs(zimags(columnProductedIn_2_6[1]) + 0.5017100000000001003286) < 3e-16);
/*
[ 1.1i 0.1+i 0.2+0.9i 0.3+0.8i 0.4+0.7i 0.5+0.6i 0.6+0.5i 0.7+0.4i 0.8+0.3i 0.9+0.2i 1+0.1i 1.1 ]
=>
[ - 0.3006711243250001497351 + 0.0000000000000000038164i ]
*/
zcolumnproda(in, 1, 12, columnProductedIn_1_12);
printf("columnProductedIn_1_12[%d] = %e + %ei\n", 0, zreals(columnProductedIn_1_12[0]), zimags(columnProductedIn_1_12[0]));
assert(fabs(zreals(columnProductedIn_1_12[0]) + 0.3006711243250001497351) < 3e-16);
assert(fabs(zimags(columnProductedIn_1_12[0]) - 0.0000000000000000038164) < 3e-16);
/*
[ 1.1i ] => [ 1.1i ]
[ 0.1+i ] => [ 0.1+i ]
[ 0.2+0.9i ] => [ 0.2+0.9i ]
[ 0.3+0.8i ] => [ 0.3+0.8i ]
[ 0.4+0.7i ] => [ 0.4+0.7i ]
[ 0.5+0.6i ] => [ 0.5+0.6i ]
[ 0.6+0.5i ] => [ 0.6+0.5i ]
[ 0.7+0.4i ] => [ 0.7+0.4i ]
[ 0.8+0.3i ] => [ 0.8+0.3i ]
[ 0.9+0.2i ] => [ 0.9+0.2i ]
[ 1+0.1i ] => [ 1+0.1i ]
[ 1.1 ] => [ 1.1 ]
*/
zcolumnproda(in, 12, 1, columnProductedIn_12_1);
for (i = 0 ; i < 12 ; ++i) {
printf("columnProductedIn_12_1[%d] = %e + %ei\n", i, zreals(columnProductedIn_12_1[i]), zimags(columnProductedIn_12_1[i]));
assert(zreals(columnProductedIn_12_1[i]) == zreals(in[i]) && zimags(columnProductedIn_12_1[i]) == zimags(in[i]));
}
return 0;
}
static int testprod(void) {
dprodsTest();
dprodaTest();
drowprodaTest();
dcolumnprodaTest();
zprodsTest();
zprodaTest();
zrowprodaTest();
zcolumnprodaTest();
return 0;
}
int main(void) {
assert(testprod() == 0);
return 0;
}
|