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
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
*
* 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 "constant.h"
#include "cat.h"
static void srowcatsTest(void) {
int i = 0;
float output[2] = {0};
/*
** [ 42 51 ]
*/
srowcats(42.0, 51.0, output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e\n", i, output[i]);
}
assert(output[0] == 42.0);
assert(output[1] == 51.0);
/*
** [ PI PI/2 ]
*/
srowcats(FPI, FPI / 2, output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e\n", i, output[i]);
}
assert(output[0] == FPI);
assert(output[1] == FPI / 2);
}
static void scolumncatsTest(void) {
int i = 0;
float output[2] = {0};
/*
** [ 42 51 ]
*/
scolumncats(42.0, 51.0, output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e\n", i, output[i]);
}
assert(output[0] == 42.0);
assert(output[1] == 51.0);
/*
** [ PI PI/2 ]
*/
scolumncats(FPI, FPI / 2, output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e\n", i, output[i]);
}
assert(output[0] == FPI);
assert(output[1] == FPI / 2);
}
static void scolumncataTest(void) {
int i = 0;
float in1[12] = {0.0, 1.0, 2.0 , 3.0 , 4.0, 5.0 , 6.0 , 7.0 , 8.0 , 9.0, 10.0 , 11.0};
float in2_1_1[1] = {12.0};
float out_1_13[13] = {0};
float in2_2_2[4] = {FPI, FPI / 2, FPI / 3, FPI / 4};
float out_2_8[16] = {0};
/*
** columncat( [ 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 ], [ 12.0 ] )
** [ 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 ]
*/
scolumncata(in1, 1, 12, in2_1_1, 1, 1, out_1_13);
for (i = 0 ; i < 13 ; ++i) {
printf("out_1_13[%d] = %e\n", i, out_1_13[i]);
assert(out_1_13[i] == (float) i);
}
/*
** [ 0 2 4 6 8 10 ] , [ PI PI/3 ] => [ 0 2 4 6 8 10 PI PI/3 ]
** [ 1 3 5 7 9 11 ] [ PI/2 PI/4] [ 1 3 5 7 9 11 PI/2 PI/4 ]
*/
scolumncata(in1, 2, 6, in2_2_2, 2, 2, out_2_8);
for (i = 0 ; i < 16 ; ++i) {
printf("out_2_8[%d] = %e\n", i, out_2_8[i]);
}
for (i = 0 ; i < 12 ; ++i) {
assert(out_2_8[i] == in1[i]);
}
for (i = 0 ; i < 4 ; ++i) {
assert(out_2_8[i + 12] == in2_2_2[i]);
}
}
static void srowcataTest() {
int i = 0;
float in1[6] = {1.0 , 2.0, 5.0 , 6.0, 9.0 , 10.0};
float in2[6] = {3.0 , 4.0 , 7.0 , 8.0 , 11.0 , 12.0};
float out_4_3[12] = {0};
float out_6_2[12] = {0};
float inNono1[6]={1.0,3.0,5.0,2.0,4.0,6.0};
float inNono2[2]={1.0,2.0};
float outNono[8]={0};
/*
** [ 1 5 9 ] ; [ 3 7 11 ] => [ 1 5 9 ]
** [ 2 6 10 ] [ 4 8 12 ] [ 2 6 10 ]
** [ 3 7 11 ]
** [ 4 8 12 ]
*/
srowcata(in1, 2, 3, in2, 2, 3, out_4_3);
for (i = 0 ; i < 12 ; ++i) {
printf("out_4_3[%d] = %e\n", i, out_4_3[i]);
assert(out_4_3[i] == (float) i + 1.0);
}
/*
** [ 1 6 ] ; [ 3 8 ]
** [ 2 9 ] [ 4 11 ]
** [ 5 10 ] [ 7 12 ]
*/
srowcata(in1, 3, 2, in2, 3, 2, out_6_2);
for (i = 0 ; i < 12 ; ++i) {
printf("out_6_2[%d] = %e\n", i, out_6_2[i]);
}
assert(out_6_2[0] == 1.0);
assert(out_6_2[1] == 2.0);
assert(out_6_2[2] == 5.0);
assert(out_6_2[3] == 3.0);
assert(out_6_2[4] == 4.0);
assert(out_6_2[5] == 7.0);
assert(out_6_2[6] == 6.0);
assert(out_6_2[7] == 9.0);
assert(out_6_2[8] == 10.0);
assert(out_6_2[9] == 8.0);
assert(out_6_2[10] == 11.0);
assert(out_6_2[11] == 12.0);
srowcata(inNono1, 3, 2, inNono2, 1, 2, outNono);
assert(outNono[0] == 1.0);
assert(outNono[1] == 3.0);
assert(outNono[2] == 5.0);
assert(outNono[3] == 1.0);
assert(outNono[4] == 2.0);
assert(outNono[5] == 4.0);
assert(outNono[6] == 6.0);
assert(outNono[7] == 2.0);
}
static void crowcatsTest(void) {
int i = 0;
floatComplex output[2];
/*
** [ 42+25i 51+38i ]
*/
crowcats(FloatComplex(42.0, 25.0),
FloatComplex(51.0, 38.0),
output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e + %e i\n", i, creals(output[i]), cimags(output[i]));
}
assert(creals(output[0]) == 42.0);
assert(cimags(output[0]) == 25.0);
assert(creals(output[1]) == 51.0);
assert(cimags(output[1]) == 38.0);
/*
** [ PI+PI/2i PI/2+PIi ]
*/
crowcats(FloatComplex(FPI, FPI/2),
FloatComplex(FPI/2, FPI),
output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e + %e i\n", i, creals(output[i]), cimags(output[i]));
}
assert(creals(output[0]) == FPI);
assert(cimags(output[0]) == FPI / 2);
assert(creals(output[1]) == FPI / 2);
assert(cimags(output[1]) == FPI);
}
static void ccolumncatsTest(void) {
int i = 0;
floatComplex output[2];
/*
** [ 42+25i 51+38i ]
*/
ccolumncats(FloatComplex(42.0, 25.0),
FloatComplex(51.0, 38.0),
output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e + %e i\n", i, creals(output[i]), cimags(output[i]));
}
assert(creals(output[0]) == 42.0);
assert(cimags(output[0]) == 25.0);
assert(creals(output[1]) == 51.0);
assert(cimags(output[1]) == 38.0);
/*
** [ PI+PI/2i PI/2+PIi ]
*/
ccolumncats(FloatComplex(FPI, FPI/2),
FloatComplex(FPI/2, FPI),
output);
for (i = 0 ; i < 2 ; ++i) {
printf("output[%d] = %e + %e i\n", i, creals(output[i]), cimags(output[i]));
}
assert(creals(output[0]) == FPI);
assert(cimags(output[0]) == FPI / 2);
assert(creals(output[1]) == FPI / 2);
assert(cimags(output[1]) == FPI);
}
static void ccolumncataTest(void) {
int i = 0;
float in1_real[12] = {0.0 , 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 , 11.0};
float in1_imag[12] = {11.0 , 10.0 , 9.0 , 8.0 , 7.0 , 6.0 , 5.0 , 4.0 , 3.0 , 2.0 , 1.0 , 0.0};
floatComplex *in1 = FloatComplexMatrix(in1_real, in1_imag, 12);
float in2_real[1] = {12.0};
float in2_imag[1] = {-1.0};
floatComplex *in2_1_1 = FloatComplexMatrix(in2_real, in2_imag, 1);
floatComplex out_1_13[13];
float in2_2_2_real[4] = {FPI, FPI / 2, FPI / 3, FPI / 4};
float in2_2_2_imag[4] = {FPI / 4, FPI / 3, FPI / 2, FPI};
floatComplex *in2_2_2 = FloatComplexMatrix(in2_2_2_real, in2_2_2_imag, 4);
floatComplex out_2_8[16];
/*
** columncat( [ 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 ], [ 12.0 ] )
** [ 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 ]
*/
ccolumncata(in1, 1, 12, in2_1_1, 1, 1, out_1_13);
for (i = 0 ; i < 13 ; ++i) {
printf("out_1_13[%d] = %e + %e i\n", i, creals(out_1_13[i]), cimags(out_1_13[i]));
assert(creals(out_1_13[i]) == (float) i);
assert(cimags(out_1_13[i]) == 11.0 - (float) i);
}
/*
** [ 0 2 4 6 8 10 ] , [ PI PI/3 ] => [ 0 2 4 6 8 10 PI PI/3 ]
** [ 1 3 5 7 9 11 ] [ PI/2 PI/4] [ 1 3 5 7 9 11 PI/2 PI/4 ]
*/
ccolumncata(in1, 2, 6, in2_2_2, 2, 2, out_2_8);
for (i = 0 ; i < 16 ; ++i) {
printf("out_2_8[%d] = %e + %e i\n", i, creals(out_2_8[i]), cimags(out_2_8[i]));
}
for (i = 0 ; i < 12 ; ++i) {
assert(creals(out_2_8[i]) == creals(in1[i]));
assert(cimags(out_2_8[i]) == cimags(in1[i]));
}
for (i = 0 ; i < 4 ; ++i) {
assert(creals(out_2_8[i + 12]) == creals(in2_2_2[i]));
assert(cimags(out_2_8[i + 12]) == cimags(in2_2_2[i]));
}
}
static void crowcataTest() {
int i = 0;
float in1_real[6] = {1.0 , 2.0, 5.0 , 6.0, 9.0 , 10.0};
float in1_imag[6] = {1.0 , 2.0, 5.0 , 6.0, 9.0 , 10.0};
floatComplex *in1 = FloatComplexMatrix(in1_real, in1_imag, 6);
float in2_real[6] = {3.0 , 4.0 , 7.0 , 8.0 , 11.0 , 12.0};
float in2_imag[6] = {3.0 , 4.0 , 7.0 , 8.0 , 11.0 , 12.0};
floatComplex *in2 = FloatComplexMatrix(in2_real, in2_imag, 6);
floatComplex out_4_3[12];
floatComplex out_6_2[12];
/*
** [ 1 5 9 ] ; [ 3 7 11 ] => [ 1 5 9 ]
** [ 2 6 10 ] [ 4 8 12 ] [ 2 6 10 ]
** [ 3 7 11 ]
** [ 4 8 12 ]
*/
crowcata(in1, 2, 3, in2, 2, 3, out_4_3);
for (i = 0 ; i < 12 ; ++i) {
printf("out_4_3[%d] = %e + %e i\n", i, creals(out_4_3[i]), cimags(out_4_3[i]));
assert(creals(out_4_3[i]) == (float) i + 1.0);
assert(cimags(out_4_3[i]) == (float) i + 1.0);
}
/*
** [ 1 6 ] ; [ 3 8 ]
** [ 2 9 ] [ 4 11 ]
** [ 5 10 ] [ 7 12 ]
*/
crowcata(in1, 3, 2, in2, 3, 2, out_6_2);
for (i = 0 ; i < 12 ; ++i) {
printf("out_6_2[%d] = %e + %e i\n", i, creals(out_6_2[i]), cimags(out_6_2[i]));
}
assert(creals(out_6_2[0]) == 1.0);
assert(cimags(out_6_2[0]) == 1.0);
assert(creals(out_6_2[1]) == 2.0);
assert(cimags(out_6_2[1]) == 2.0);
assert(creals(out_6_2[2]) == 5.0);
assert(cimags(out_6_2[2]) == 5.0);
assert(creals(out_6_2[3]) == 3.0);
assert(cimags(out_6_2[3]) == 3.0);
assert(creals(out_6_2[4]) == 4.0);
assert(cimags(out_6_2[4]) == 4.0);
assert(creals(out_6_2[5]) == 7.0);
assert(cimags(out_6_2[5]) == 7.0);
assert(creals(out_6_2[6]) == 6.0);
assert(cimags(out_6_2[6]) == 6.0);
assert(creals(out_6_2[7]) == 9.0);
assert(cimags(out_6_2[7]) == 9.0);
assert(creals(out_6_2[8]) == 10.0);
assert(cimags(out_6_2[8]) == 10.0);
assert(creals(out_6_2[9]) == 8.0);
assert(cimags(out_6_2[9]) == 8.0);
assert(creals(out_6_2[10]) == 11.0);
assert(cimags(out_6_2[10]) == 11.0);
assert(creals(out_6_2[11]) == 12.0);
assert(cimags(out_6_2[11]) == 12.0);
}
int main(void) {
srowcatsTest();
scolumncatsTest();
srowcataTest();
scolumncataTest();
crowcatsTest();
ccolumncatsTest();
crowcataTest();
ccolumncataTest();
return 0;
}
|