36#include "hdrl_elemop.h"
37#include "hdrl_types.h"
44#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
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);
66 hdrl_error_t ea = 0.5;
67 const hdrl_data_t b = 2;
68 const hdrl_error_t eb = 0.5;
70 hdrl_elemop_add(&a, &ea, 1, &b, &eb, 1, NULL);
72 cpl_test_rel(a, 4., HDRL_EPS_DATA);
73 cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR);
78 hdrl_error_t ea = 0.5;
80 hdrl_elemop_add(&a, &ea, 1, &a, &ea, 1, NULL);
82 cpl_test_rel(a, 4., HDRL_EPS_DATA);
83 cpl_test_rel(ea, sqrt(1.0), HDRL_EPS_ERROR);
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};
92 hdrl_elemop_add(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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);
101 hdrl_data_t a[] = {2, 3};
102 hdrl_error_t ea[] = {0.5, 1};
104 hdrl_elemop_add(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL);
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);
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;
118 hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
133 hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
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);
158 return cpl_error_get_code();
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);
173 hdrl_error_t ea = 0.5;
174 const hdrl_data_t b = 2;
175 const hdrl_error_t eb = 0.5;
177 hdrl_elemop_sub(&a, &ea, 1, &b, &eb, 1, NULL);
179 cpl_test_rel(a, 0., HDRL_EPS_DATA);
180 cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR);
185 hdrl_error_t ea = 0.5;
187 hdrl_elemop_sub(&a, &ea, 1, &a, &ea, 1, NULL);
189 cpl_test_rel(a, 0., HDRL_EPS_DATA);
190 cpl_test_rel(ea, 0., HDRL_EPS_ERROR);
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};
199 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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);
208 hdrl_data_t a[] = {2, 3};
209 hdrl_error_t ea[] = {0.5, 1};
211 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL);
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);
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;
225 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
240 hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
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);
248 return cpl_error_get_code();
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);
264 hdrl_error_t ea = 0.5;
265 const hdrl_data_t b = 3;
266 const hdrl_error_t eb = 0.5;
268 hdrl_elemop_mul(&a, &ea, 1, &b, &eb, 1, NULL);
270 cpl_test_rel(a, 6., HDRL_EPS_DATA);
271 cpl_test_rel(ea, sqrt(3.25), HDRL_EPS_ERROR * 10);
276 hdrl_error_t ea = 0.5;
278 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
280 cpl_test_rel(a, 4., HDRL_EPS_DATA);
281 cpl_test_rel(ea, 2., HDRL_EPS_ERROR * 10);
286 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
288 cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA);
289 cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10);
294 hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL);
296 cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA);
297 cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10);
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};
306 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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);
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;
320 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
335 hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
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);
360 return cpl_error_get_code();
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);
376 hdrl_error_t ea = 0.5;
377 const hdrl_data_t b = 3;
378 const hdrl_error_t eb = 0.5;
380 hdrl_elemop_div(&a, &ea, 1, &b, &eb, 1, NULL);
382 cpl_test_rel(a, 2. / 3., HDRL_EPS_DATA);
383 cpl_test_rel(ea, 0.20030840419244383, HDRL_EPS_ERROR * 10);
388 hdrl_error_t ea = 0.5;
390 hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL);
392 cpl_test_rel(a, 1., HDRL_EPS_DATA);
393 cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10);
398 hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL);
400 cpl_test_rel(a, 1., HDRL_EPS_DATA);
401 cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10);
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};
410 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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);
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};
425 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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]));
433 hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, 1, NULL);
435 cpl_test(isnan(a[0]));
436 cpl_test(isnan(ea[0]));
437 cpl_test(isnan(a[1]));
438 cpl_test(isnan(ea[1]));
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;
447 hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
462 hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask);
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);
470 return cpl_error_get_code();
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);
485 hdrl_error_t ea = 0.5;
487 hdrl_elemop_pow(&a, &ea, 1, &a, &ea, 1, NULL);
489 cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA);
490 cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10);
496 hdrl_error_t ea = 0.6;
498 hdrl_error_t eb = 0.;
500 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
502 cpl_test_rel(a, sqrt(1.2), HDRL_EPS_DATA);
503 cpl_test_rel(ea, 0.27386127875258304, HDRL_EPS_ERROR * 10);
506 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
515 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
517 cpl_test_rel(a, pow(-1.2, 3.), HDRL_EPS_DATA);
518 cpl_test_rel(ea, 2.592, HDRL_EPS_ERROR * 10);
523 hdrl_data_t a = -1.2;
524 hdrl_error_t ea = 0.5;
526 hdrl_error_t eb = 0.0;
528 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
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);
534 cpl_test_rel(a, a2, HDRL_EPS_DATA);
535 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10);
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);
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.};
553 hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL);
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);
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);
568 hdrl_error_t ea = 0.5;
569 hdrl_data_t b = -1.0;
570 hdrl_error_t eb = 0.0;
572 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
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);
580 cpl_test_rel(a, a2, HDRL_EPS_DATA);
581 cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10);
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.};
591 hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL);
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);
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);
607 hdrl_error_t ea = 0.5;
609 hdrl_error_t eb = 2.0;
611 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
613 cpl_test_rel(a, pow(1.2, b), HDRL_EPS_DATA);
614 cpl_test_rel(ea, 1.3098531960320208, HDRL_EPS_ERROR * 10);
619 hdrl_error_t ea = 0.5;
621 hdrl_error_t eb = 0.;
623 hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL);
630 hdrl_data_t a[] = {0., 0.};
631 hdrl_error_t ea[] = {0.5, 0.5};
633 hdrl_error_t eb = 0.;
635 hdrl_elemop_pow(a, ea, 2, &b, &eb, 1, NULL);
637 cpl_test(isnan(a[0]));
638 cpl_test(isnan(ea[0]));
639 cpl_test(isnan(a[1]));
640 cpl_test(isnan(ea[1]));
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};
649 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL);
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);
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;
663 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
679 hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), mask);
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);
687 return cpl_error_get_code();
692hdrl_test_pow_inverted(
void)
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);
703 hdrl_error_t ea = 0.5;
705 hdrl_elemop_pow_inverted(&a, &ea, 1, &a, &ea, 1, NULL);
707 cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA);
708 cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10);
714 hdrl_error_t ea = 0.6;
716 hdrl_error_t eb = 0.;
718 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
720 cpl_test_rel(b, sqrt(1.2), HDRL_EPS_DATA);
721 cpl_test_rel(eb, 0.27386127875258304, HDRL_EPS_ERROR * 10);
724 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
734 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
736 cpl_test_rel(b, pow(-1.2, 3.), HDRL_EPS_DATA);
737 cpl_test_rel(eb, 2.592, HDRL_EPS_ERROR * 10);
742 hdrl_data_t a = -1.2;
743 hdrl_error_t ea = 0.5;
745 hdrl_error_t eb = 0.0;
747 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
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);
753 cpl_test_rel(b, a2, HDRL_EPS_DATA);
754 cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10);
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);
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.};
772 hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL);
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);
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);
787 hdrl_error_t ea = 0.5;
788 hdrl_data_t b = -1.0;
789 hdrl_error_t eb = 0.0;
791 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
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);
799 cpl_test_rel(b, a2, HDRL_EPS_DATA);
800 cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10);
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.};
810 hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL);
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);
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);
826 hdrl_error_t ea = 0.5;
828 hdrl_error_t eb = 2.0;
830 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
832 cpl_test_rel(b, pow(a, 2.0), HDRL_EPS_DATA);
833 cpl_test_rel(eb, 1.3098531960320208, HDRL_EPS_ERROR * 10);
838 hdrl_error_t ea = 0.5;
840 hdrl_error_t eb = 0.;
842 hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL);
849 hdrl_data_t a[] = {-1., 3.};
850 hdrl_error_t ea[] = {0.0, 0.1};
852 hdrl_error_t eb = 2.;
854 hdrl_elemop_pow_inverted(a, ea, 2, &b, &eb, 1, NULL);
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);
861 cpl_test(isnan(ea[1]));
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};
870 hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(a), a, ea, ARRAY_LEN(b), NULL);
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);
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;
884 hdrl_elemop_pow_inverted(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL);
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);
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};
900 hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(b), a, ea, ARRAY_LEN(a), mask);
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);
908 return cpl_error_get_code();
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);
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);
926 hdrl_elemop_image_add_image(iad, iae, ibd, ibe);
928 cpl_test_rel(ad[0], 5., HDRL_EPS_DATA);
929 cpl_test_rel(ae[0], sqrt(0.5), HDRL_EPS_ERROR);
931 hdrl_elemop_image_sub_image(iad, iae, ibd, ibe);
932 cpl_test_rel(ad[0], 5. - 3., HDRL_EPS_DATA);
934 hdrl_elemop_image_mul_image(iad, iae, ibd, ibe);
935 cpl_test_rel(ad[0], (5. - 3.) * 3., HDRL_EPS_DATA);
937 hdrl_elemop_image_div_image(iad, iae, ibd, ibe);
938 cpl_test_rel(ad[0], ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
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);
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));
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));
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);
964 cpl_image_accept_all(iad);
965 cpl_test_rel(cpl_image_get(iad, 1, 1, &is_rej), 2., 0);
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);
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);
990 cpl_image_unwrap(iad);
991 cpl_image_unwrap(iae);
992 cpl_image_unwrap(ibd);
993 cpl_image_unwrap(ibe);
995 return cpl_error_get_code();
1000hdrl_test_image_scalar(
void)
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);
1010 hdrl_elemop_image_add_scalar(iad, iae, bd, be);
1012 cpl_test_rel(ad, 5., HDRL_EPS_DATA);
1013 cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR);
1015 hdrl_elemop_image_sub_scalar(iad, iae, bd, be);
1016 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1018 hdrl_elemop_image_mul_scalar(iad, iae, bd, be);
1019 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1021 hdrl_elemop_image_div_scalar(iad, iae, bd, be);
1022 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
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);
1029 hdrl_elemop_image_pow_scalar(iad, iae, bd, be);
1030 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
1033 hdrl_elemop_image_div_scalar(iad, iae, 0., be);
1034 cpl_test(cpl_image_is_rejected(iad, 1, 1));
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));
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));
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);
1053 cpl_image_unwrap(iad);
1054 cpl_image_unwrap(iae);
1056 return cpl_error_get_code();
1060static cpl_error_code
1061hdrl_test_imagelist(
void)
1065 hdrl_error_t ae = 0.5;
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);
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);
1085 hdrl_elemop_imagelist_sub_imagelist(iad, iae, ibd, ibe);
1086 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1088 hdrl_elemop_imagelist_mul_imagelist(iad, iae, ibd, ibe);
1089 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1091 hdrl_elemop_imagelist_div_imagelist(iad, iae, ibd, ibe);
1092 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1094 hdrl_elemop_imagelist_pow_imagelist(iad, iae, ibd, ibe);
1095 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
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);
1112 return cpl_error_get_code();
1115static cpl_error_code
1116hdrl_test_imagelist_image(
void)
1120 hdrl_error_t ae = 0.5;
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);
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);
1136 hdrl_elemop_imagelist_sub_image(iad, iae, ibd, ibe);
1137 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1139 hdrl_elemop_imagelist_mul_image(iad, iae, ibd, ibe);
1140 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1142 hdrl_elemop_imagelist_div_image(iad, iae, ibd, ibe);
1143 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1145 hdrl_elemop_imagelist_pow_image(iad, iae, ibd, ibe);
1146 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
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);
1161 return cpl_error_get_code();
1165static cpl_error_code
1166hdrl_test_imagelist_vector(
void)
1171 hdrl_error_t ae = 0.5;
1174 double be[1] = {0.5};
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);
1179 cpl_vector * ibd = cpl_vector_wrap(ARRAY_LEN(bd), bd);
1180 cpl_vector * ibe = cpl_vector_wrap(ARRAY_LEN(be), be);
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);
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);
1191 hdrl_elemop_imagelist_sub_vector(iad, iae, ibd, ibe);
1192 cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA);
1194 hdrl_elemop_imagelist_mul_vector(iad, iae, ibd, ibe);
1195 cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA);
1197 hdrl_elemop_imagelist_div_vector(iad, iae, ibd, ibe);
1198 cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA);
1200 hdrl_elemop_imagelist_pow_vector(iad, iae, ibd, ibe);
1201 cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA);
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);
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);
1217 return cpl_error_get_code();
1227 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1234 hdrl_test_pow_inverted();
1237 hdrl_test_image_scalar();
1239 hdrl_test_imagelist();
1240 hdrl_test_imagelist_image();
1241 hdrl_test_imagelist_vector();
1243 return cpl_test_end(0);