CR2RE Pipeline Reference Manual 1.6.10
hdrl_elemop-test.c
1/* $Id: hdrl_elemop-test.c,v 1.4 2013-09-25 12:06:52 jtaylor Exp $
2 *
3 * This file is part of the HDRL
4 * Copyright (C) 2013 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-09-25 12:06:52 $
24 * $Revision: 1.4 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "hdrl_elemop.h"
37#include "hdrl_types.h"
38#include <cpl.h>
39
40#include <math.h>
41#include <stdlib.h>
42
43#ifndef ARRAY_LEN
44#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
45#endif
46
47
48/*----------------------------------------------------------------------------*/
52/*----------------------------------------------------------------------------*/
53
54static cpl_error_code
55hdrl_test_add(void)
56{
57 {
58 hdrl_data_t a = 0., b = 0.;
59 hdrl_error_t ea = 0., eb = 0.;
60 hdrl_elemop_add(&a, &ea, 1, &b, &eb, 2, NULL);
61 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
62 }
63
64 {
65 hdrl_data_t a = 2;
66 hdrl_error_t ea = 0.5;
67 const hdrl_data_t b = 2;
68 const hdrl_error_t eb = 0.5;
69
70 hdrl_elemop_add(&a, &ea, 1, &b, &eb, 1, NULL);
71
72 cpl_test_rel(a, 4., HDRL_EPS_DATA);
73 cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR);
74 }
75
76 {
77 hdrl_data_t a = 2;
78 hdrl_error_t ea = 0.5;
79
80 hdrl_elemop_add(&a, &ea, 1, &a, &ea, 1, NULL);
81
82 cpl_test_rel(a, 4., HDRL_EPS_DATA);
83 cpl_test_rel(ea, sqrt(1.0), HDRL_EPS_ERROR);
84 }
85
86 {
87 hdrl_data_t a[] = {2, 3};
88 hdrl_error_t ea[] = {0.5, 1};
89 const hdrl_data_t b[] = {-2, 6};
90 const hdrl_error_t eb[] = {0.5, 3};
91
92 hdrl_elemop_add(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
93
94 cpl_test_rel(a[0], 0., HDRL_EPS_DATA);
95 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
96 cpl_test_rel(a[1], 9., HDRL_EPS_DATA);
97 cpl_test_rel(ea[1], sqrt(1 * 1 + 3 * 3), HDRL_EPS_ERROR);
98 }
99
100 {
101 hdrl_data_t a[] = {2, 3};
102 hdrl_error_t ea[] = {0.5, 1};
103
104 hdrl_elemop_add(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL);
105
106 cpl_test_rel(a[0], 4., HDRL_EPS_DATA);
107 cpl_test_rel(ea[0], 1, HDRL_EPS_ERROR);
108 cpl_test_rel(a[1], 6., HDRL_EPS_DATA);
109 cpl_test_rel(ea[1], 2., HDRL_EPS_ERROR);
110 }
111
112 {
113 hdrl_data_t a[] = {2, 3};
114 hdrl_error_t ea[] = {0.5, 1};
115 const hdrl_data_t b = -2;
116 const hdrl_error_t eb = 0.5;
117
118 hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
119
120 cpl_test_rel(a[0], 0., HDRL_EPS_DATA);
121 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
122 cpl_test_rel(a[1], 1., HDRL_EPS_DATA);
123 cpl_test_rel(ea[1], sqrt(1 * 1 + 0.5 * 0.5), HDRL_EPS_ERROR);
124 }
125
126 {
127 hdrl_data_t a[] = {2, 3};
128 hdrl_error_t ea[] = {0.5, 1};
129 const hdrl_data_t b = -2;
130 const hdrl_error_t eb = 0.5;
131 cpl_binary mask[] = {0, 1};
132
133 hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
134
135 cpl_test_rel(a[0], 0., HDRL_EPS_DATA);
136 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
137 cpl_test_rel(a[1], 3., HDRL_EPS_DATA);
138 cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR);
139 }
140
141 /*{
142 hdrl_data_t a = 2;
143 hdrl_error_t ea = 0.7;
144 hdrl_data_t a2 = a;
145 hdrl_error_t ea2 = ea;
146 const hdrl_data_t b = 2;
147 const hdrl_error_t eb = 0.7;
148 const double covab = 1;
149
150 hdrl_elemop_add(&a, &ea, &a, &ea, 1);
151 hdrl_elemop_add_cov(&a2, &ea2, &b, &eb, &covab, 1);
152
153 cpl_test_rel(a, a2, HDRL_EPS_DATA);
154 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR);
155 cpl_test_rel(ea, 1.4, HDRL_EPS_ERROR);
156 }*/
157
158 return cpl_error_get_code();
159}
160
161static cpl_error_code
162hdrl_test_sub(void)
163{
164 {
165 hdrl_data_t a = 0., b = 0.;
166 hdrl_error_t ea = 0., eb = 0.;
167 hdrl_elemop_sub(&a, &ea, 1, &b, &eb, 2, NULL);
168 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
169 }
170
171 {
172 hdrl_data_t a = 2;
173 hdrl_error_t ea = 0.5;
174 const hdrl_data_t b = 2;
175 const hdrl_error_t eb = 0.5;
176
177 hdrl_elemop_sub(&a, &ea, 1, &b, &eb, 1, NULL);
178
179 cpl_test_rel(a, 0., HDRL_EPS_DATA);
180 cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR);
181 }
182
183 {
184 hdrl_data_t a = 2;
185 hdrl_error_t ea = 0.5;
186
187 hdrl_elemop_sub(&a, &ea, 1, &a, &ea, 1, NULL);
188
189 cpl_test_rel(a, 0., HDRL_EPS_DATA);
190 cpl_test_rel(ea, 0., HDRL_EPS_ERROR);
191 }
192
193 {
194 hdrl_data_t a[] = {2, 3};
195 hdrl_error_t ea[] = {0.5, 1};
196 const hdrl_data_t b[] = {-2, 6};
197 const hdrl_error_t eb[] = {0.5, 3};
198
199 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
200
201 cpl_test_rel(a[0], 4., HDRL_EPS_DATA);
202 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
203 cpl_test_rel(a[1], -3., HDRL_EPS_DATA);
204 cpl_test_rel(ea[1], sqrt(1 * 1 + 3 * 3), HDRL_EPS_ERROR);
205 }
206
207 {
208 hdrl_data_t a[] = {2, 3};
209 hdrl_error_t ea[] = {0.5, 1};
210
211 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL);
212
213 cpl_test_rel(a[0], 0., HDRL_EPS_DATA);
214 cpl_test_rel(ea[0], 0., HDRL_EPS_ERROR);
215 cpl_test_rel(a[1], 0., HDRL_EPS_DATA);
216 cpl_test_rel(ea[1], 0., HDRL_EPS_ERROR);
217 }
218
219 {
220 hdrl_data_t a[] = {2, 3};
221 hdrl_error_t ea[] = {0.5, 1};
222 const hdrl_data_t b = -2;
223 const hdrl_error_t eb = 0.5;
224
225 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
226
227 cpl_test_rel(a[0], 4., HDRL_EPS_DATA);
228 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
229 cpl_test_rel(a[1], 5., HDRL_EPS_DATA);
230 cpl_test_rel(ea[1], sqrt(1 * 1 + 0.5 * 0.5), HDRL_EPS_ERROR);
231 }
232
233 {
234 hdrl_data_t a[] = {2, 3};
235 hdrl_error_t ea[] = {0.5, 1};
236 const hdrl_data_t b = -2;
237 const hdrl_error_t eb = 0.5;
238 cpl_binary mask[] = {0, 1};
239
240 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
241
242 cpl_test_rel(a[0], 4., HDRL_EPS_DATA);
243 cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR);
244 cpl_test_rel(a[1], 3., HDRL_EPS_DATA);
245 cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR);
246 }
247
248 return cpl_error_get_code();
249}
250
251
252static cpl_error_code
253hdrl_test_mul(void)
254{
255 {
256 hdrl_data_t a = 0., b = 0.;
257 hdrl_error_t ea = 0., eb = 0.;
258 hdrl_elemop_mul(&a, &ea, 1, &b, &eb, 2, NULL);
259 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
260 }
261
262 {
263 hdrl_data_t a = 2;
264 hdrl_error_t ea = 0.5;
265 const hdrl_data_t b = 3;
266 const hdrl_error_t eb = 0.5;
267
268 hdrl_elemop_mul(&a, &ea, 1, &b, &eb, 1, NULL);
269
270 cpl_test_rel(a, 6., HDRL_EPS_DATA);
271 cpl_test_rel(ea, sqrt(3.25), HDRL_EPS_ERROR * 10);
272 }
273
274 {
275 hdrl_data_t a = 2;
276 hdrl_error_t ea = 0.5;
277
278 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
279
280 cpl_test_rel(a, 4., HDRL_EPS_DATA);
281 cpl_test_rel(ea, 2., HDRL_EPS_ERROR * 10);
282
283 a = 1.7;
284 ea = 2.8;
285
286 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
287
288 cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA);
289 cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10);
290
291 a = -1.7;
292 ea = 2.8;
293
294 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
295
296 cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA);
297 cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10);
298 }
299
300 {
301 hdrl_data_t a[] = {2, 3};
302 hdrl_error_t ea[] = {0.5, 1};
303 const hdrl_data_t b[] = {-2, 6};
304 const hdrl_error_t eb[] = {0.5, 3};
305
306 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
307
308 cpl_test_rel(a[0], -4., HDRL_EPS_DATA);
309 cpl_test_rel(ea[0], sqrt(2), HDRL_EPS_ERROR * 10);
310 cpl_test_rel(a[1], 18., HDRL_EPS_DATA);
311 cpl_test_rel(ea[1], 10.816653826391969, HDRL_EPS_ERROR * 10);
312 }
313
314 {
315 hdrl_data_t a[] = {2, 3};
316 hdrl_error_t ea[] = {0.5, 1};
317 const hdrl_data_t b = -2;
318 const hdrl_error_t eb = 0.5;
319
320 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
321
322 cpl_test_rel(a[0], -4., HDRL_EPS_DATA);
323 cpl_test_rel(ea[0], sqrt(2.), HDRL_EPS_ERROR * 10);
324 cpl_test_rel(a[1], -6., HDRL_EPS_DATA);
325 cpl_test_rel(ea[1], 2.5, HDRL_EPS_ERROR * 10);
326 }
327
328 {
329 hdrl_data_t a[] = {2, 3};
330 hdrl_error_t ea[] = {0.5, 1};
331 const hdrl_data_t b = -2;
332 const hdrl_error_t eb = 0.5;
333 cpl_binary mask[] = {0, 1};
334
335 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
336
337 cpl_test_rel(a[0], -4., HDRL_EPS_DATA);
338 cpl_test_rel(ea[0], sqrt(2.), HDRL_EPS_ERROR * 10);
339 cpl_test_rel(a[1], 3., HDRL_EPS_DATA);
340 cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR);
341 }
342
343 /* {
344 hdrl_data_t a = 2;
345 hdrl_error_t ea = 0.7;
346 hdrl_data_t a2 = a;
347 hdrl_error_t ea2 = ea;
348 const hdrl_data_t b = 2;
349 const hdrl_error_t eb = 0.7;
350 const double covab = 1;
351
352 hdrl_elemop_mul(&a, &ea, &a, &ea, 1);
353 hdrl_elemop_mul_cov(&a2, &ea2, &b, &eb, &covab, 1);
354
355 cpl_test_rel(a, a2, HDRL_EPS_DATA);
356 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR);
357 cpl_test_rel(ea, 2.8, HDRL_EPS_ERROR);
358 } */
359
360 return cpl_error_get_code();
361}
362
363
364static cpl_error_code
365hdrl_test_div(void)
366{
367 {
368 hdrl_data_t a = 0., b = 0.;
369 hdrl_error_t ea = 0., eb = 0.;
370 hdrl_elemop_div(&a, &ea, 1, &b, &eb, 2, NULL);
371 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
372 }
373
374 {
375 hdrl_data_t a = 2;
376 hdrl_error_t ea = 0.5;
377 const hdrl_data_t b = 3;
378 const hdrl_error_t eb = 0.5;
379
380 hdrl_elemop_div(&a, &ea, 1, &b, &eb, 1, NULL);
381
382 cpl_test_rel(a, 2. / 3., HDRL_EPS_DATA);
383 cpl_test_rel(ea, 0.20030840419244383, HDRL_EPS_ERROR * 10);
384 }
385
386 {
387 hdrl_data_t a = 2;
388 hdrl_error_t ea = 0.5;
389
390 hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL);
391
392 cpl_test_rel(a, 1., HDRL_EPS_DATA);
393 cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10);
394
395 a = 1.7;
396 ea = 2.8;
397
398 hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL);
399
400 cpl_test_rel(a, 1., HDRL_EPS_DATA);
401 cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10);
402 }
403
404 {
405 hdrl_data_t a[] = {2, 3};
406 hdrl_error_t ea[] = {0.5, 1};
407 const hdrl_data_t b[] = {-2, 6};
408 const hdrl_error_t eb[] = {0.5, 3};
409
410 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
411
412 cpl_test_rel(a[0], -1., HDRL_EPS_DATA);
413 cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10);
414 cpl_test_rel(a[1], 3./6., HDRL_EPS_DATA);
415 cpl_test_rel(ea[1], 0.3004626062886658, HDRL_EPS_ERROR * 10);
416 }
417
418 /* division by 0. */
419 {
420 hdrl_data_t a[] = {2, 3};
421 hdrl_error_t ea[] = {0.5, 1};
422 hdrl_data_t b[] = {-2, 0.};
423 const hdrl_error_t eb[] = {0.5, 3};
424
425 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
426
427 cpl_test_rel(a[0], -1., HDRL_EPS_DATA);
428 cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10);
429 cpl_test(isnan(a[1]));
430 cpl_test(isnan(ea[1]));
431
432 b[0] = 0.;
433 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, 1, NULL);
434
435 cpl_test(isnan(a[0]));
436 cpl_test(isnan(ea[0]));
437 cpl_test(isnan(a[1]));
438 cpl_test(isnan(ea[1]));
439 }
440
441 {
442 hdrl_data_t a[] = {2, 3};
443 hdrl_error_t ea[] = {0.5, 1};
444 const hdrl_data_t b = -2;
445 const hdrl_error_t eb = 0.5;
446
447 hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
448
449 cpl_test_rel(a[0], -1., HDRL_EPS_DATA);
450 cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10);
451 cpl_test_rel(a[1], -3. / 2., HDRL_EPS_DATA);
452 cpl_test_rel(ea[1], 0.625, HDRL_EPS_ERROR * 10);
453 }
454
455 {
456 hdrl_data_t a[] = {2, 3};
457 hdrl_error_t ea[] = {0.5, 1};
458 const hdrl_data_t b = -2;
459 const hdrl_error_t eb = 0.5;
460 cpl_binary mask[] = {0, 1};
461
462 hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
463
464 cpl_test_rel(a[0], -1., HDRL_EPS_DATA);
465 cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10);
466 cpl_test_rel(a[1], 3., HDRL_EPS_DATA);
467 cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR);
468 }
469
470 return cpl_error_get_code();
471}
472
473static cpl_error_code
474hdrl_test_pow(void)
475{
476 {
477 hdrl_data_t a = 0., b = 0.;
478 hdrl_error_t ea = 0., eb = 0.;
479 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 2, NULL);
480 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
481 }
482
483 {
484 hdrl_data_t a = 1.2;
485 hdrl_error_t ea = 0.5;
486
487 hdrl_elemop_pow(&a, &ea, 1, &a, &ea, 1, NULL);
488
489 cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA);
490 cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10);
491 }
492
493 /* square root test */
494 {
495 hdrl_data_t a = 1.2;
496 hdrl_error_t ea = 0.6;
497 hdrl_data_t b = 0.5;
498 hdrl_error_t eb = 0.;
499
500 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
501
502 cpl_test_rel(a, sqrt(1.2), HDRL_EPS_DATA);
503 cpl_test_rel(ea, 0.27386127875258304, HDRL_EPS_ERROR * 10);
504
505 a = -1.2;
506 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
507
508 cpl_test(isnan(a));
509 cpl_test(isnan(ea));
510
511 /* negative value test */
512 a = -1.2;
513 ea = 0.6;
514 b = 3.;
515 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
516
517 cpl_test_rel(a, pow(-1.2, 3.), HDRL_EPS_DATA);
518 cpl_test_rel(ea, 2.592, HDRL_EPS_ERROR * 10);
519 }
520
521 /* pow with error free power 2 exponent == repeated multiplication */
522 {
523 hdrl_data_t a = -1.2;
524 hdrl_error_t ea = 0.5;
525 hdrl_data_t b = 2.0;
526 hdrl_error_t eb = 0.0;
527
528 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
529
530 hdrl_data_t a2 = -1.2;
531 hdrl_error_t ea2 = 0.5;
532 hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL);
533
534 cpl_test_rel(a, a2, HDRL_EPS_DATA);
535 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10);
536
537 a = -1.2;
538 ea = 0.5;
539 b = 4.0;
540 eb = 0.0;
541 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
542 hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL);
543 cpl_test_rel(a, a2, HDRL_EPS_DATA);
544 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10);
545 }
546 /* array pow with error free power 2 exponent == repeated multiplication */
547 {
548 hdrl_data_t a[] = {0.3, 10.};
549 hdrl_error_t ea[] = {0.5, 2.};
550 hdrl_data_t b[] = {2.0, 2.0};
551 hdrl_error_t eb[] = {0., 0.};
552
553 hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL);
554
555 hdrl_data_t a2[] = {0.3, 10.};
556 hdrl_error_t ea2[] = {0.5, 2.};
557 hdrl_elemop_mul(a2, ea2, 2, a2, ea2, 2, NULL);
558
559 cpl_test_rel(a[0], a2[0], HDRL_EPS_DATA);
560 cpl_test_rel(ea[0], ea2[0], HDRL_EPS_ERROR * 10);
561 cpl_test_rel(a[1], a2[1], HDRL_EPS_DATA);
562 cpl_test_rel(ea[1], ea2[1], HDRL_EPS_ERROR * 10);
563 }
564
565 /* pow with error free -1 exponent == reciprocal */
566 {
567 hdrl_data_t a = 1.2;
568 hdrl_error_t ea = 0.5;
569 hdrl_data_t b = -1.0;
570 hdrl_error_t eb = 0.0;
571
572 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
573
574 hdrl_data_t a2 = 1.0;
575 hdrl_error_t ea2 = 0.;
576 hdrl_data_t b2 = 1.2;
577 hdrl_error_t eb2 = 0.5;
578 hdrl_elemop_div(&a2, &ea2, 1, &b2, &eb2, 1, NULL);
579
580 cpl_test_rel(a, a2, HDRL_EPS_DATA);
581 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10);
582 }
583
584 /* array pow with error free -1 exponent == reciprocal*/
585 {
586 hdrl_data_t a[] = {0.3, 10.};
587 hdrl_error_t ea[] = {0.5, 2.};
588 hdrl_data_t b[] = {-1.0, -1.0};
589 hdrl_error_t eb[] = {0., 0.};
590
591 hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL);
592
593 hdrl_data_t a2[] = {1.0, 1.0};
594 hdrl_error_t ea2[] = {0., 0.};
595 hdrl_data_t b2[] = {0.3, 10.};
596 hdrl_error_t eb2[] = {0.5, 2.};
597 hdrl_elemop_div(a2, ea2, 2, b2, eb2, 2, NULL);
598
599 cpl_test_rel(a[0], a2[0], HDRL_EPS_DATA);
600 cpl_test_rel(ea[0], ea2[0], HDRL_EPS_ERROR * 10);
601 cpl_test_rel(a[1], a2[1], HDRL_EPS_DATA);
602 cpl_test_rel(ea[1], ea2[1], HDRL_EPS_ERROR * 10);
603 }
604
605 {
606 hdrl_data_t a = 1.2;
607 hdrl_error_t ea = 0.5;
608 hdrl_data_t b = 2.0;
609 hdrl_error_t eb = 2.0;
610
611 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
612
613 cpl_test_rel(a, pow(1.2, b), HDRL_EPS_DATA);
614 cpl_test_rel(ea, 1.3098531960320208, HDRL_EPS_ERROR * 10);
615 }
616
617 {
618 hdrl_data_t a = 0.;
619 hdrl_error_t ea = 0.5;
620 hdrl_data_t b = -1.;
621 hdrl_error_t eb = 0.;
622
623 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
624
625 cpl_test(isnan(a));
626 cpl_test(isnan(ea));
627 }
628
629 {
630 hdrl_data_t a[] = {0., 0.};
631 hdrl_error_t ea[] = {0.5, 0.5};
632 hdrl_data_t b = -1.;
633 hdrl_error_t eb = 0.;
634
635 hdrl_elemop_pow(a, ea, 2, &b, &eb, 1, NULL);
636
637 cpl_test(isnan(a[0]));
638 cpl_test(isnan(ea[0]));
639 cpl_test(isnan(a[1]));
640 cpl_test(isnan(ea[1]));
641 }
642
643 {
644 hdrl_data_t a[] = {2, 3};
645 hdrl_error_t ea[] = {0.5, 1};
646 const hdrl_data_t b[] = {-2, 6};
647 const hdrl_error_t eb[] = {0.5, 3};
648
649 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
650
651 cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA);
652 cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
653 cpl_test_rel(a[1], 729, HDRL_EPS_DATA);
654 cpl_test_rel(ea[1], 2810.438304633068, HDRL_EPS_ERROR * 10);
655 }
656
657 {
658 hdrl_data_t a[] = {2, 3};
659 hdrl_error_t ea[] = {0.5, 1};
660 const hdrl_data_t b = -2;
661 const hdrl_error_t eb = 0.5;
662
663 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
664
665 cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA);
666 cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
667 cpl_test_rel(a[1], 0.1111111111111111, HDRL_EPS_DATA);
668 cpl_test_rel(ea[1], 0.09597978726560344, HDRL_EPS_ERROR * 10);
669 }
670
671 /* masked test */
672 {
673 hdrl_data_t a[] = {2, 3};
674 hdrl_error_t ea[] = {0.5, 1};
675 const hdrl_data_t b[] = {-2, 6};
676 const hdrl_error_t eb[] = {0.5, 3};
677 cpl_binary mask[] = {0, 1};
678
679 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), mask);
680
681 cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA);
682 cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
683 cpl_test_rel(a[1], 3., HDRL_EPS_DATA);
684 cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR * 10);
685 }
686
687 return cpl_error_get_code();
688}
689
690
691static cpl_error_code
692hdrl_test_pow_inverted(void)
693{
694 {
695 hdrl_data_t a = 0., b = 0.;
696 hdrl_error_t ea = 0., eb = 0.;
697 hdrl_elemop_pow_inverted(&a, &ea, 1, &b, &eb, 2, NULL);
698 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
699 }
700
701 {
702 hdrl_data_t a = 1.2;
703 hdrl_error_t ea = 0.5;
704
705 hdrl_elemop_pow_inverted(&a, &ea, 1, &a, &ea, 1, NULL);
706
707 cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA);
708 cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10);
709 }
710
711 /* square root test */
712 {
713 hdrl_data_t a = 1.2;
714 hdrl_error_t ea = 0.6;
715 hdrl_data_t b = 0.5;
716 hdrl_error_t eb = 0.;
717
718 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
719
720 cpl_test_rel(b, sqrt(1.2), HDRL_EPS_DATA);
721 cpl_test_rel(eb, 0.27386127875258304, HDRL_EPS_ERROR * 10);
722
723 a = -1.2;
724 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
725
726 cpl_test(isnan(b));
727 cpl_test(isnan(eb));
728
729 /* negative value test */
730 a = -1.2;
731 ea = 0.6;
732 b = 3.;
733 eb = 0.0;
734 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
735
736 cpl_test_rel(b, pow(-1.2, 3.), HDRL_EPS_DATA);
737 cpl_test_rel(eb, 2.592, HDRL_EPS_ERROR * 10);
738 }
739
740 /* pow with error free exper 2 exponent == repeated multiplication */
741 {
742 hdrl_data_t a = -1.2;
743 hdrl_error_t ea = 0.5;
744 hdrl_data_t b = 2.0;
745 hdrl_error_t eb = 0.0;
746
747 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
748
749 hdrl_data_t a2 = -1.2;
750 hdrl_error_t ea2 = 0.5;
751 hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL);
752
753 cpl_test_rel(b, a2, HDRL_EPS_DATA);
754 cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10);
755
756 a = -1.2;
757 ea = 0.5;
758 b = 4.0;
759 eb = 0.0;
760 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
761 hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL);
762 cpl_test_rel(b, a2, HDRL_EPS_DATA);
763 cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10);
764 }
765 /* array pow with error free exper 2 exponent == repeated multiplication */
766 {
767 hdrl_data_t a[] = {0.3, 10.};
768 hdrl_error_t ea[] = {0.5, 2.};
769 hdrl_data_t b[] = {2.0, 2.0};
770 hdrl_error_t eb[] = {0., 0.};
771
772 hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL);
773
774 hdrl_data_t a2[] = {0.3, 10.};
775 hdrl_error_t ea2[] = {0.5, 2.};
776 hdrl_elemop_mul(a2, ea2, 2, a2, ea2, 2, NULL);
777
778 cpl_test_rel(b[0], a2[0], HDRL_EPS_DATA);
779 cpl_test_rel(eb[0], ea2[0], HDRL_EPS_ERROR * 10);
780 cpl_test_rel(b[1], a2[1], HDRL_EPS_DATA);
781 cpl_test_rel(eb[1], ea2[1], HDRL_EPS_ERROR * 10);
782 }
783
784 /* pow with error free -1 exponent == reciprocal */
785 {
786 hdrl_data_t a = 1.2;
787 hdrl_error_t ea = 0.5;
788 hdrl_data_t b = -1.0;
789 hdrl_error_t eb = 0.0;
790
791 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
792
793 hdrl_data_t a2 = 1.0;
794 hdrl_error_t ea2 = 0.;
795 hdrl_data_t b2 = 1.2;
796 hdrl_error_t eb2 = 0.5;
797 hdrl_elemop_div(&a2, &ea2, 1, &b2, &eb2, 1, NULL);
798
799 cpl_test_rel(b, a2, HDRL_EPS_DATA);
800 cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10);
801 }
802
803 /* array pow with error free -1 exponent == reciprocal*/
804 {
805 hdrl_data_t a[] = {0.3, 10.};
806 hdrl_error_t ea[] = {0.5, 2.};
807 hdrl_data_t b[] = {-1.0, -1.0};
808 hdrl_error_t eb[] = {0., 0.};
809
810 hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL);
811
812 hdrl_data_t a2[] = {1.0, 1.0};
813 hdrl_error_t ea2[] = {0., 0.};
814 hdrl_data_t b2[] = {0.3, 10.};
815 hdrl_error_t eb2[] = {0.5, 2.};
816 hdrl_elemop_div(a2, ea2, 2, b2, eb2, 2, NULL);
817
818 cpl_test_rel(b[0], a2[0], HDRL_EPS_DATA);
819 cpl_test_rel(eb[0], ea2[0], HDRL_EPS_ERROR * 10);
820 cpl_test_rel(b[1], a2[1], HDRL_EPS_DATA);
821 cpl_test_rel(eb[1], ea2[1], HDRL_EPS_ERROR * 10);
822 }
823
824 {
825 hdrl_data_t a = 1.2;
826 hdrl_error_t ea = 0.5;
827 hdrl_data_t b = 2.0;
828 hdrl_error_t eb = 2.0;
829
830 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
831
832 cpl_test_rel(b, pow(a, 2.0), HDRL_EPS_DATA);
833 cpl_test_rel(eb, 1.3098531960320208, HDRL_EPS_ERROR * 10);
834 }
835
836 {
837 hdrl_data_t a = 0.;
838 hdrl_error_t ea = 0.5;
839 hdrl_data_t b = -1.;
840 hdrl_error_t eb = 0.;
841
842 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
843
844 cpl_test(isnan(b));
845 cpl_test(isnan(eb));
846 }
847
848 {
849 hdrl_data_t a[] = {-1., 3.};
850 hdrl_error_t ea[] = {0.0, 0.1};
851 hdrl_data_t b = 0.;
852 hdrl_error_t eb = 2.;
853
854 hdrl_elemop_pow_inverted(a, ea, 2, &b, &eb, 1, NULL);
855
856 cpl_test(isnan(a[0]));
857 cpl_test(isnan(ea[0]));
858 cpl_test(!isnan(a[1]));
859 cpl_test_rel(a[1], 0.0, HDRL_EPS_ERROR);
860 /* it is null because in the error calculation we divide by the base (0) */
861 cpl_test(isnan(ea[1]));
862 }
863
864 {
865 const hdrl_data_t a[] = {2, 3};
866 const hdrl_error_t ea[] = {0.5, 1};
867 hdrl_data_t b[] = {-2, 6};
868 hdrl_error_t eb[] = {0.5, 3};
869
870 hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(a), a, ea, ARRAY_LEN(b), NULL);
871
872 cpl_test_rel(b[0], 0.25, HDRL_EPS_DATA);
873 cpl_test_rel(eb[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
874 cpl_test_rel(b[1], 729, HDRL_EPS_DATA);
875 cpl_test_rel(eb[1], 2810.438304633068, HDRL_EPS_ERROR * 10);
876 }
877
878 {
879 hdrl_data_t a[] = {-2, 3};
880 hdrl_error_t ea[] = {0.5, .2};
881 const hdrl_data_t b = 2;
882 const hdrl_error_t eb = 0.5;
883
884 hdrl_elemop_pow_inverted(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
885
886 cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA);
887 cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
888 cpl_test_rel(a[1], 8., HDRL_EPS_DATA);
889 cpl_test_rel(ea[1], 6.10163582292737, HDRL_EPS_ERROR * 10);
890 }
891
892 /* masked test */
893 {
894 const hdrl_data_t a[] = {2, 3};
895 const hdrl_error_t ea[] = {0.5, 1};
896 hdrl_data_t b[] = {-2, 6};
897 hdrl_error_t eb[] = {0.5, 3};
898 cpl_binary mask[] = {0, 1};
899
900 hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(b), a, ea, ARRAY_LEN(a), mask);
901
902 cpl_test_rel(b[0], 0.25, HDRL_EPS_DATA);
903 cpl_test_rel(eb[0], 0.15209233492346647, HDRL_EPS_ERROR * 10);
904 cpl_test_rel(b[1], 6., HDRL_EPS_DATA);
905 cpl_test_rel(eb[1], 3., HDRL_EPS_ERROR * 10);
906 }
907
908 return cpl_error_get_code();
909}
910
911static cpl_error_code
912hdrl_test_image(void)
913{
914 int is_rej;
915
916 hdrl_data_t ad[] = {2, 2};
917 hdrl_error_t ae[] = {0.5, 0.5};
918 cpl_image *iad = cpl_image_wrap(1, 2, HDRL_TYPE_DATA, ad);
919 cpl_image *iae = cpl_image_wrap(1, 2, HDRL_TYPE_ERROR, ae);
920
921 hdrl_data_t bd[] = {3, 3};
922 hdrl_error_t be[] = {0.5, 0.5};
923 cpl_image *ibd = cpl_image_wrap(1, 2, HDRL_TYPE_DATA, bd);
924 cpl_image *ibe = cpl_image_wrap(1, 2, HDRL_TYPE_ERROR, be);
925
926 hdrl_elemop_image_add_image(iad, iae, ibd, ibe);
927
928 cpl_test_rel(ad[0], 5., HDRL_EPS_DATA);
929 cpl_test_rel(ae[0], sqrt(0.5), HDRL_EPS_ERROR);
930
931 hdrl_elemop_image_sub_image(iad, iae, ibd, ibe);
932 cpl_test_rel(ad[0], 5. - 3., HDRL_EPS_DATA);
933
934 hdrl_elemop_image_mul_image(iad, iae, ibd, ibe);
935 cpl_test_rel(ad[0], (5. - 3.) * 3., HDRL_EPS_DATA);
936
937 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
938 cpl_test_rel(ad[0], ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
939
940 hdrl_elemop_image_pow_image(iad, iae, ibd, ibe);
941 cpl_test_rel(ad[0], pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
942
943 cpl_image_set(iad, 1, 1, 0.);
944 cpl_image_set(ibd, 1, 1, -1.);
945 hdrl_elemop_image_pow_image(iad, iae, ibd, ibe);
946 cpl_test(cpl_image_is_rejected(iad, 1, 1));
947
948 cpl_image_set(iad, 1, 1, 2.);
949 cpl_image_set(ibd, 1, 1, 0.);
950 cpl_image_accept_all(iad);
951 cpl_image_accept_all(iae);
952 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
953 cpl_test(cpl_image_is_rejected(iad, 1, 1));
954
955 /* test a has bpm */
956 cpl_image_set(iad, 1, 1, 2. );
957 cpl_image_set(iae, 1, 1, 0.5);
958 cpl_image_set(ibd, 1, 1, 3. );
959 cpl_image_reject(iad, 1, 1);
960 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
961 cpl_test(cpl_image_is_rejected(iad, 1, 1));
962 cpl_test_rel(ad[0], 2., 0);
963
964 cpl_image_accept_all(iad);
965 cpl_test_rel(cpl_image_get(iad, 1, 1, &is_rej), 2., 0);
966
967 /* test a and b have bpm */
968 cpl_image_set(iad, 1, 1, 2. );
969 cpl_image_set(iae, 1, 1, 0.5);
970 cpl_image_reject(iad, 1, 1);
971 cpl_image_reject(ibd, 1, 2);
972 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
973 cpl_test(cpl_image_is_rejected(iad, 1, 1));
974 cpl_test(cpl_image_is_rejected(iad, 1, 2));
975 cpl_test_rel(ad[0], 2., 0);
976 cpl_test_rel(ae[0], 0.5, 0);
977
978 /* test b has bpm */
979 cpl_image_set(iad, 1, 2, 2. );
980 cpl_image_set(iae, 1, 2, 0.5);
981 cpl_image_set(ibd, 1, 2, 2. );
982 cpl_image_set(ibe, 1, 2, 0.5);
983 cpl_image_accept_all(iad);
984 cpl_image_reject(ibd, 1, 2);
985 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
986 cpl_test(cpl_image_is_rejected(iad, 1, 2));
987 cpl_test_rel(ad[1], 2., 0);
988 cpl_test_rel(ae[1], 0.5, 0);
989
990 cpl_image_unwrap(iad);
991 cpl_image_unwrap(iae);
992 cpl_image_unwrap(ibd);
993 cpl_image_unwrap(ibe);
994
995 return cpl_error_get_code();
996}
997
998
999static cpl_error_code
1000hdrl_test_image_scalar(void)
1001{
1002 int is_rej;
1003 hdrl_data_t ad = 2;
1004 hdrl_error_t ae = 0.5;
1005 const hdrl_data_t bd = 3;
1006 const hdrl_error_t be = 0.5;
1007 cpl_image * iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad);
1008 cpl_image * iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae);
1009
1010 hdrl_elemop_image_add_scalar(iad, iae, bd, be);
1011
1012 cpl_test_rel(ad, 5., HDRL_EPS_DATA);
1013 cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR);
1014
1015 hdrl_elemop_image_sub_scalar(iad, iae, bd, be);
1016 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1017
1018 hdrl_elemop_image_mul_scalar(iad, iae, bd, be);
1019 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1020
1021 hdrl_elemop_image_div_scalar(iad, iae, bd, be);
1022 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1023
1024 hdrl_data_t ad_old = ad;
1025 hdrl_elemop_image_exp_scalar(iad, iae, bd, be);
1026 cpl_test_rel(ad, pow(3., ((5. - 3.) * 3.) / 3.), HDRL_EPS_DATA);
1027
1028 ad = ad_old;
1029 hdrl_elemop_image_pow_scalar(iad, iae, bd, be);
1030 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
1031
1032 /* divide image by scalar zero (emits warning) */
1033 hdrl_elemop_image_div_scalar(iad, iae, 0., be);
1034 cpl_test(cpl_image_is_rejected(iad, 1, 1));
1035
1036 cpl_image_accept_all(iad);
1037 cpl_image_set(iad, 1, 1, 0.);
1038 hdrl_elemop_image_pow_scalar(iad, iae, -1., be);
1039 cpl_test(cpl_image_is_rejected(iad, 1, 1));
1040
1041 cpl_image_set(iad, 1, 1, -1);
1042 cpl_image_reject(iad, 1, 1);
1043 hdrl_elemop_image_exp_scalar(iad, iae, 0., be);
1044 cpl_test(cpl_image_is_rejected(iad, 1, 1));
1045
1046 cpl_image_set(iad, 1, 1, 2.);
1047 cpl_image_reject(iad, 1, 1);
1048 hdrl_elemop_image_div_scalar(iad, iae, bd, be);
1049 cpl_test(cpl_image_is_rejected(iad, 1, 1));
1050 cpl_image_accept_all(iad);
1051 cpl_test_rel(cpl_image_get(iad, 1, 1, &is_rej), 2., 0);
1052
1053 cpl_image_unwrap(iad);
1054 cpl_image_unwrap(iae);
1055
1056 return cpl_error_get_code();
1057}
1058
1059
1060static cpl_error_code
1061hdrl_test_imagelist(void)
1062{
1063 int is_rej;
1064 hdrl_data_t ad = 2;
1065 hdrl_error_t ae = 0.5;
1066 hdrl_data_t bd = 3;
1067 hdrl_error_t be = 0.5;
1068 cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad);
1069 cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae);
1070 cpl_image * _ibd = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &bd);
1071 cpl_image * _ibe = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &be);
1072 cpl_imagelist * iad = cpl_imagelist_new();
1073 cpl_imagelist * iae = cpl_imagelist_new();
1074 cpl_imagelist * ibd = cpl_imagelist_new();
1075 cpl_imagelist * ibe = cpl_imagelist_new();
1076 cpl_imagelist_set(iad, _iad, 0);
1077 cpl_imagelist_set(ibd, _ibd, 0);
1078 cpl_imagelist_set(iae, _iae, 0);
1079 cpl_imagelist_set(ibe, _ibe, 0);
1080
1081 hdrl_elemop_imagelist_add_imagelist(iad, iae, ibd, ibe);
1082 cpl_test_rel(ad, 5., HDRL_EPS_DATA);
1083 cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR);
1084
1085 hdrl_elemop_imagelist_sub_imagelist(iad, iae, ibd, ibe);
1086 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1087
1088 hdrl_elemop_imagelist_mul_imagelist(iad, iae, ibd, ibe);
1089 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1090
1091 hdrl_elemop_imagelist_div_imagelist(iad, iae, ibd, ibe);
1092 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1093
1094 hdrl_elemop_imagelist_pow_imagelist(iad, iae, ibd, ibe);
1095 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
1096
1097 cpl_image_set(_iad, 1, 1, 2.);
1098 cpl_image_reject(_iad, 1, 1);
1099 hdrl_elemop_imagelist_div_imagelist(iad, iae, ibd, ibe);
1100 cpl_test(cpl_image_is_rejected(_iad, 1, 1));
1101 cpl_image_accept_all(_iad);
1102 cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0);
1103 cpl_imagelist_unwrap(iad);
1104 cpl_imagelist_unwrap(iae);
1105 cpl_imagelist_unwrap(ibd);
1106 cpl_imagelist_unwrap(ibe);
1107 cpl_image_unwrap(_iad);
1108 cpl_image_unwrap(_iae);
1109 cpl_image_unwrap(_ibd);
1110 cpl_image_unwrap(_ibe);
1111
1112 return cpl_error_get_code();
1113}
1114
1115static cpl_error_code
1116hdrl_test_imagelist_image(void)
1117{
1118 int is_rej;
1119 hdrl_data_t ad = 2;
1120 hdrl_error_t ae = 0.5;
1121 hdrl_data_t bd = 3;
1122 hdrl_error_t be = 0.5;
1123 cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad);
1124 cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae);
1125 cpl_image * ibd = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &bd);
1126 cpl_image * ibe = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &be);
1127 cpl_imagelist * iad = cpl_imagelist_new();
1128 cpl_imagelist * iae = cpl_imagelist_new();
1129 cpl_imagelist_set(iad, _iad, 0);
1130 cpl_imagelist_set(iae, _iae, 0);
1131
1132 hdrl_elemop_imagelist_add_image(iad, iae, ibd, ibe);
1133 cpl_test_rel(ad, 5., HDRL_EPS_DATA);
1134 cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR);
1135
1136 hdrl_elemop_imagelist_sub_image(iad, iae, ibd, ibe);
1137 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1138
1139 hdrl_elemop_imagelist_mul_image(iad, iae, ibd, ibe);
1140 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1141
1142 hdrl_elemop_imagelist_div_image(iad, iae, ibd, ibe);
1143 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1144
1145 hdrl_elemop_imagelist_pow_image(iad, iae, ibd, ibe);
1146 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
1147
1148 cpl_image_set(_iad, 1, 1, 2.);
1149 cpl_image_reject(_iad, 1, 1);
1150 hdrl_elemop_imagelist_div_image(iad, iae, ibd, ibe);
1151 cpl_test(cpl_image_is_rejected(_iad, 1, 1));
1152 cpl_image_accept_all(_iad);
1153 cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0);
1154 cpl_imagelist_unwrap(iad);
1155 cpl_imagelist_unwrap(iae);
1156 cpl_image_unwrap(_iad);
1157 cpl_image_unwrap(_iae);
1158 cpl_image_unwrap(ibd);
1159 cpl_image_unwrap(ibe);
1160
1161 return cpl_error_get_code();
1162}
1163
1164
1165static cpl_error_code
1166hdrl_test_imagelist_vector(void)
1167{
1168 int is_rej;
1169
1170 hdrl_data_t ad = 2;
1171 hdrl_error_t ae = 0.5;
1172
1173 double bd[1] = {3};
1174 double be[1] = {0.5};
1175
1176 cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad);
1177 cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae);
1178
1179 cpl_vector * ibd = cpl_vector_wrap(ARRAY_LEN(bd), bd);
1180 cpl_vector * ibe = cpl_vector_wrap(ARRAY_LEN(be), be);
1181
1182 cpl_imagelist * iad = cpl_imagelist_new();
1183 cpl_imagelist * iae = cpl_imagelist_new();
1184 cpl_imagelist_set(iad, _iad, 0);
1185 cpl_imagelist_set(iae, _iae, 0);
1186
1187 hdrl_elemop_imagelist_add_vector(iad, iae, ibd, ibe);
1188 cpl_test_rel(ad, 5., HDRL_EPS_DATA);
1189 cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR);
1190
1191 hdrl_elemop_imagelist_sub_vector(iad, iae, ibd, ibe);
1192 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1193
1194 hdrl_elemop_imagelist_mul_vector(iad, iae, ibd, ibe);
1195 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1196
1197 hdrl_elemop_imagelist_div_vector(iad, iae, ibd, ibe);
1198 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1199
1200 hdrl_elemop_imagelist_pow_vector(iad, iae, ibd, ibe);
1201 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
1202
1203 cpl_image_set(_iad, 1, 1, 2.);
1204 cpl_image_reject(_iad, 1, 1);
1205 hdrl_elemop_imagelist_div_vector(iad, iae, ibd, ibe);
1206 cpl_test(cpl_image_is_rejected(_iad, 1, 1));
1207 cpl_image_accept_all(_iad);
1208 cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0);
1209
1210 cpl_imagelist_unwrap(iad);
1211 cpl_imagelist_unwrap(iae);
1212 cpl_image_unwrap(_iad);
1213 cpl_image_unwrap(_iae);
1214 cpl_vector_unwrap(ibd);
1215 cpl_vector_unwrap(ibe);
1216
1217 return cpl_error_get_code();
1218}
1219
1220/*----------------------------------------------------------------------------*/
1224/*----------------------------------------------------------------------------*/
1225int main(void)
1226{
1227 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1228
1229 hdrl_test_add();
1230 hdrl_test_sub();
1231 hdrl_test_mul();
1232 hdrl_test_div();
1233 hdrl_test_pow();
1234 hdrl_test_pow_inverted();
1235
1236 hdrl_test_image();
1237 hdrl_test_image_scalar();
1238
1239 hdrl_test_imagelist();
1240 hdrl_test_imagelist_image();
1241 hdrl_test_imagelist_vector();
1242
1243 return cpl_test_end(0);
1244}