54 #include "planck_rng.h" 55 #include "lsconstants.h" 59 #include "geom_utils.h" 60 #include "walltimer.h" 62 #include "compress_utils.h" 65 #include "crangeset.h" 75 #define FAIL(a) {a; if (++errcount>100) planck_fail("unit test errors");} 80 const int nsamples = 1000000;
86 void random_dir (pointing &ptg)
88 ptg.theta = acos(rng.rand_uni()*2-1);
89 ptg.phi = rng.rand_uni()*twopi;
91 void random_zphi (
double &z,
double &phi)
93 z = rng.rand_uni()*2-1;
94 phi = rng.rand_uni()*twopi;
97 template<
typename I>
string bname()
98 {
return string(
"(basetype: ")+type2typename<I>()+
")"; }
101 template<
typename I> rangeset<I> randomRangeSet(
int num, I start,
int dist)
105 for (
int i=0; i<num; ++i)
107 I v1=curval+1+(rng.int_rand_uni()%dist);
108 I v2=v1+1+(rng.int_rand_uni()%dist);
114 template<
typename I> Moc<I> randomMoc(
int num, I start,
int dist)
117 I curval=start+(I(1)<<(2*Moc<I>::maxorder));
118 for (
int i=0; i<num; ++i)
120 I v1=curval+1+(rng.int_rand_uni()%dist);
121 I v2=v1+1+(rng.int_rand_uni()%dist);
122 moc.addPixelRange(Moc<I>::maxorder,v1,v2);
128 template<
typename I> rangeset<I> makeRS(
const string &input)
130 istringstream is(input);
136 planck_assert (is||is.eof(),
"aargh");
137 if (is) res.append(a,b);
141 template<
typename I>
void rsOps(
const rangeset<I> &a,
const rangeset<I> &b)
143 planck_assert(!b.overlaps(a.op_andnot(b)),
"error");
144 planck_assert(a.op_or(b).nval()>=a.nval(),
"error");
145 planck_assert(a.op_or(b).nval()>=b.nval(),
"error");
146 planck_assert(a.op_and(b).nval()<=a.nval(),
"error");
147 planck_assert(a.op_and(b).nval()<=b.nval(),
"error");
148 planck_assert(a.op_or(b).contains(a),
"error");
149 planck_assert(a.op_or(b).contains(b),
"error");
150 planck_assert(!a.op_andnot(b).overlaps(b),
"error");
151 planck_assert(!b.op_andnot(a).overlaps(a),
"error");
152 planck_assert(a.op_or(b).nval()==a.nval()+b.nval()-a.op_and(b).nval(),
154 planck_assert(a.op_or(b).op_andnot(a.op_and(b)).nval()==
155 a.op_or(b).nval()-a.op_and(b).nval(),
"error");
156 planck_assert(a.op_xor(b)==a.op_andnot(b).op_or(b.op_andnot(a)),
"error");
158 template<
typename I>
void check_rangeset()
160 cout <<
"testing rangeset " << bname<I>() << endl;
164 planck_assert(b==makeRS<I>(
"1 11"),
"mismatch");
166 planck_assert(b==makeRS<I>(
"1 15"),
"mismatch");
168 planck_assert(b==makeRS<I>(
"1 15"),
"mismatch");
170 planck_assert(b==makeRS<I>(
"1 15"),
"mismatch");
173 planck_assert(b==makeRS<I>(
"1 15 30 41"),
"mismatch");
177 planck_fail(
"Should have raised an IllegalArgumentException");
179 catch (PlanckError E) {}
183 rangeset<I> b=makeRS<I>(
"1 11 30 41");
184 planck_assert(!b.contains(0),
"error");
185 planck_assert(b.contains(1),
"error");
186 planck_assert(b.contains(5),
"error");
187 planck_assert(b.contains(10),
"error");
188 planck_assert(!b.contains(11),
"error");
189 planck_assert(!b.contains(29),
"error");
190 planck_assert(b.contains(30),
"error");
191 planck_assert(b.contains(35),
"error");
192 planck_assert(b.contains(40),
"error");
193 planck_assert(!b.contains(41),
"errror");
198 planck_assert(b==makeRS<I>(
"5 11"),
"error");
200 planck_assert(b==makeRS<I>(
"1 11"),
"error");
202 planck_assert(b==makeRS<I>(
"1 11"),
"error");
204 planck_assert(b==makeRS<I>(
"1 11 30 41"),
"error");
206 planck_assert(b==makeRS<I>(
"1 11 30 41"),
"error");
208 planck_assert(b==makeRS<I>(
"-1 0 1 11 30 41"),
"error");
210 planck_assert(b==makeRS<I>(
"-2 0 1 11 30 41"),
"error");
212 planck_assert(b==makeRS<I>(
"-2 0 1 11 30 41"),
"error");
214 planck_assert(b==makeRS<I>(
"-2 0 1 11 30 41"),
"error");
216 planck_assert(b==makeRS<I>(
"-2 0 1 11 30 41"),
"error");
218 planck_assert(b==makeRS<I>(
"-2 0 1 11 15 21 30 41"),
"error");
221 rangeset<I> b = makeRS<I>(
"0 11 20 31");
223 planck_assert(b==makeRS<I>(
"0 5 25 31"),
"error");
225 planck_assert(b==makeRS<I>(
"0 5 25 31"),
"error");
227 planck_assert(b==makeRS<I>(
"0 5 25 31"),
"error");
229 planck_assert(b==makeRS<I>(
"0 5 25 31"),
"error");
231 planck_assert(b==makeRS<I>(
"0 5 25 27 29 31"),
"error");
233 planck_assert(b==makeRS<I>(
"0 5 26 27 29 31"),
"error");
235 planck_assert(b==makeRS<I>(
"0 4 26 27 29 31"),
"error");
237 planck_assert(b==makeRS<I>(
""),
"error");
239 planck_assert(b==makeRS<I>(
""),
"error");
242 rangeset<I> b = makeRS<I>(
"0 11 20 31");
244 planck_assert(b==makeRS<I>(
"2 11 20 29"),
"error");
246 planck_assert(b==makeRS<I>(
"2 11 20 29"),
"error");
248 planck_assert(b==makeRS<I>(
"2 11 20 29"),
"error");
250 planck_assert(b==makeRS<I>(
"2 11 20 29"),
"error");
252 planck_assert(b==makeRS<I>(
"2 11 20 29"),
"error");
254 planck_assert(b==makeRS<I>(
"3 11"),
"error");
255 b = makeRS<I>(
"0 11 20 31");
257 planck_assert(b==makeRS<I>(
"3 11"),
"error");
258 b = makeRS<I>(
"0 11 20 31");
260 planck_assert(b==makeRS<I>(
"20 30"),
"error");
261 b = makeRS<I>(
"0 11 20 31");
263 planck_assert(b==makeRS<I>(
""),
"error");
264 b = makeRS<I>(
"0 11 20 31");
266 planck_assert(b==makeRS<I>(
""),
"error");
267 b = makeRS<I>(
"0 11 20 31");
269 planck_assert(b==makeRS<I>(
""),
"error");
272 planck_assert(makeRS<I>(
"1 11 20 31 40 56")==
273 makeRS<I>(
"20 31 40 51").op_or
274 (makeRS<I>(
"1 11 45 56")),
"error");
275 planck_assert(makeRS<I>(
"1 11 45 56")==
277 (makeRS<I>(
"1 11 45 56")),
"error");
278 planck_assert(makeRS<I>(
"1 11 45 56")==
279 makeRS<I>(
"1 11 45 56").op_or
280 (makeRS<I>(
"")),
"error");
283 planck_assert(makeRS<I>(
"22 24 45 51")==
284 makeRS<I>(
"20 31 40 51").op_and
285 (makeRS<I>(
"1 11 22 24 45 56")),
"error");
286 planck_assert(makeRS<I>(
"20 31 40 51 90 101 110 121 200 201")==
287 makeRS<I>(
"10 101 110 121 200 221").op_and
288 (makeRS<I>(
"20 31 40 51 90 201")),
"error");
289 planck_assert(makeRS<I>(
"")==
290 makeRS<I>(
"20 31 40 51").op_and
291 (makeRS<I>(
"")),
"error");
292 planck_assert(makeRS<I>(
"")==
294 (makeRS<I>(
"20 31 40 51")),
"error");
297 planck_assert(makeRS<I>(
"20 31 40 45")==
298 makeRS<I>(
"20 31 40 51").op_andnot
299 (makeRS<I>(
"1 11 45 56")),
"error");
300 planck_assert(makeRS<I>(
"")==
301 makeRS<I>(
"").op_andnot
302 (makeRS<I>(
"1 11 45 56")),
"error");
303 planck_assert(makeRS<I>(
"1 11 45 56")==
304 makeRS<I>(
"1 11 45 56").op_andnot
305 (makeRS<I>(
"")),
"error");
308 rangeset<I> b = makeRS<I>(
"20 31 40 51");
310 planck_assert(!b.contains(0,11),
"error");
311 planck_assert(!b.contains(10,21),
"error");
312 planck_assert(!b.contains(19,20),
"error");
313 planck_assert(b.contains(20,21),
"error");
314 planck_assert(b.contains(21,22),
"error");
315 planck_assert(b.contains(20,31),
"error");
316 planck_assert(!b.contains(25,36),
"error");
317 planck_assert(b.contains(30,31),
"error");
318 planck_assert(!b.contains(31,32),
"error");
319 planck_assert(!b.contains(35,38),
"error");
320 planck_assert(!b.contains(35,46),
"error");
321 planck_assert(b.contains(40,41),
"error");
322 planck_assert(!b.contains(45,56),
"error");
323 planck_assert(!b.contains(60,71),
"error");
326 rangeset<I> b = makeRS<I>(
"20 31 40 51");
328 planck_assert(b.contains(makeRS<I>(
"20 31 40 51")),
"error");
329 planck_assert(b.contains(makeRS<I>(
"20 21")),
"error");
330 planck_assert(b.contains(makeRS<I>(
"50 51")),
"error");
331 planck_assert(!b.contains(makeRS<I>(
"19 31 40 51")),
"error");
332 planck_assert(!b.contains(makeRS<I>(
"20 31 40 52")),
"error");
333 planck_assert(!b.contains(makeRS<I>(
"20 51")),
"error");
334 planck_assert(!b.contains(makeRS<I>(
"0 1")),
"error");
335 planck_assert(!b.contains(makeRS<I>(
"0 20 31 40 51 100")),
"error");
338 rangeset<I> b = makeRS<I>(
"20 31 40 51");
340 planck_assert(!b.overlaps(0,11),
"error");
341 planck_assert(b.overlaps(10,21),
"error");
342 planck_assert(!b.overlaps(19,20),
"error");
343 planck_assert(b.overlaps(20,21),
"error");
344 planck_assert(b.overlaps(21,22),
"error");
345 planck_assert(b.overlaps(20,31),
"error");
346 planck_assert(b.overlaps(25,36),
"error");
347 planck_assert(b.overlaps(30,37),
"error");
348 planck_assert(!b.overlaps(31,32),
"error");
349 planck_assert(!b.overlaps(35,38),
"error");
350 planck_assert(b.overlaps(35,46),
"error");
351 planck_assert(b.overlaps(40,41),
"error");
352 planck_assert(b.overlaps(45,56),
"error");
353 planck_assert(!b.overlaps(60,71),
"error");
356 rangeset<I> b = makeRS<I>(
"20 31 40 51");
358 planck_assert(b.overlaps(makeRS<I>(
"20 31 40 51")),
"error");
359 planck_assert(b.overlaps(makeRS<I>(
"20 21")),
"error");
360 planck_assert(b.overlaps(makeRS<I>(
"50 51")),
"error");
361 planck_assert(b.overlaps(makeRS<I>(
"19 31 40 51")),
"error");
362 planck_assert(b.overlaps(makeRS<I>(
"20 31 40 52")),
"error");
363 planck_assert(b.overlaps(makeRS<I>(
"20 51")),
"error");
364 planck_assert(!b.overlaps(makeRS<I>(
"0 1")),
"error");
365 planck_assert(!b.overlaps(makeRS<I>(
"0 20 31 40 51 100")),
"error");
368 const int niter = 1000;
369 for (
int iter=0; iter<niter; ++iter)
371 rangeset<I> a = randomRangeSet<I>(1000, 0, 100);
372 rangeset<I> b = randomRangeSet<I>(1000, 0, 100);
373 rangeset<I> c = randomRangeSet<I>(10, 10000, 100);
380 template<
typename I> crangeset<I> randomCRangeSet(
int num, I start,
int dist)
384 for (
int i=0; i<num; ++i)
386 I v1=curval+1+(rng.int_rand_uni()%dist);
387 I v2=v1+1+(rng.int_rand_uni()%dist);
393 template<
typename I> crangeset<I> makeCRS(
const string &input)
395 istringstream is(input);
401 planck_assert (is||is.eof(),
"aargh");
402 if (is) res.append(a,b);
406 template<
typename I>
void crsOps(
const crangeset<I> &a,
const crangeset<I> &b)
408 planck_assert(!b.overlaps(a.op_andnot(b)),
"error");
409 planck_assert(a.op_or(b).nval()>=a.nval(),
"error");
410 planck_assert(a.op_or(b).nval()>=b.nval(),
"error");
411 planck_assert(a.op_and(b).nval()<=a.nval(),
"error");
412 planck_assert(a.op_and(b).nval()<=b.nval(),
"error");
413 planck_assert(a.op_or(b).contains(a),
"error");
414 planck_assert(a.op_or(b).contains(b),
"error");
415 planck_assert(!a.op_andnot(b).overlaps(b),
"error");
416 planck_assert(!b.op_andnot(a).overlaps(a),
"error");
417 planck_assert(a.op_or(b).nval()==a.nval()+b.nval()-a.op_and(b).nval(),
419 planck_assert(a.op_or(b).op_andnot(a.op_and(b)).nval()==
420 a.op_or(b).nval()-a.op_and(b).nval(),
"error");
421 planck_assert(a.op_xor(b)==a.op_andnot(b).op_or(b.op_andnot(a)),
"error");
423 template<
typename I>
void check_crangeset()
425 cout <<
"testing crangeset " << bname<I>() << endl;
429 planck_assert(b==makeCRS<I>(
"1 11"),
"mismatch");
431 planck_assert(b==makeCRS<I>(
"1 15"),
"mismatch");
433 planck_assert(b==makeCRS<I>(
"1 15"),
"mismatch");
435 planck_assert(b==makeCRS<I>(
"1 15"),
"mismatch");
438 planck_assert(b==makeRS<I>(
"1 15 30 41"),
"mismatch");
442 planck_fail(
"Should have raised an IllegalArgumentException");
444 catch (PlanckError E) {}
448 crangeset<I> b=makeCRS<I>(
"1 11 30 41");
449 planck_assert(!b.contains(0),
"error");
450 planck_assert(b.contains(1),
"error");
451 planck_assert(b.contains(5),
"error");
452 planck_assert(b.contains(10),
"error");
453 planck_assert(!b.contains(11),
"error");
454 planck_assert(!b.contains(29),
"error");
455 planck_assert(b.contains(30),
"error");
456 planck_assert(b.contains(35),
"error");
457 planck_assert(b.contains(40),
"error");
458 planck_assert(!b.contains(41),
"errror");
461 planck_assert(makeCRS<I>(
"1 11 20 31 40 56")==
462 makeCRS<I>(
"20 31 40 51").op_or
463 (makeCRS<I>(
"1 11 45 56")),
"error");
464 planck_assert(makeCRS<I>(
"1 11 45 56")==
466 (makeCRS<I>(
"1 11 45 56")),
"error");
467 planck_assert(makeCRS<I>(
"1 11 45 56")==
468 makeCRS<I>(
"1 11 45 56").op_or
469 (makeCRS<I>(
"")),
"error");
472 planck_assert(makeCRS<I>(
"22 24 45 51")==
473 makeCRS<I>(
"20 31 40 51").op_and
474 (makeCRS<I>(
"1 11 22 24 45 56")),
"error");
475 planck_assert(makeCRS<I>(
"20 31 40 51 90 101 110 121 200 201")==
476 makeCRS<I>(
"10 101 110 121 200 221").op_and
477 (makeCRS<I>(
"20 31 40 51 90 201")),
"error");
478 planck_assert(makeCRS<I>(
"")==
479 makeCRS<I>(
"20 31 40 51").op_and
480 (makeCRS<I>(
"")),
"error");
481 planck_assert(makeCRS<I>(
"")==
482 makeCRS<I>(
"").op_and
483 (makeCRS<I>(
"20 31 40 51")),
"error");
486 planck_assert(makeCRS<I>(
"20 31 40 45")==
487 makeCRS<I>(
"20 31 40 51").op_andnot
488 (makeCRS<I>(
"1 11 45 56")),
"error");
489 planck_assert(makeCRS<I>(
"")==
490 makeCRS<I>(
"").op_andnot
491 (makeCRS<I>(
"1 11 45 56")),
"error");
492 planck_assert(makeCRS<I>(
"1 11 45 56")==
493 makeCRS<I>(
"1 11 45 56").op_andnot
494 (makeCRS<I>(
"")),
"error");
497 crangeset<I> b = makeCRS<I>(
"20 31 40 51");
499 planck_assert(!b.contains(0,11),
"error");
500 planck_assert(!b.contains(10,21),
"error");
501 planck_assert(!b.contains(19,20),
"error");
502 planck_assert(b.contains(20,21),
"error");
503 planck_assert(b.contains(21,22),
"error");
504 planck_assert(b.contains(20,31),
"error");
505 planck_assert(!b.contains(25,36),
"error");
506 planck_assert(b.contains(30,31),
"error");
507 planck_assert(!b.contains(31,32),
"error");
508 planck_assert(!b.contains(35,38),
"error");
509 planck_assert(!b.contains(35,46),
"error");
510 planck_assert(b.contains(40,41),
"error");
511 planck_assert(!b.contains(45,56),
"error");
512 planck_assert(!b.contains(60,71),
"error");
515 crangeset<I> b = makeCRS<I>(
"20 31 40 51");
517 planck_assert(b.contains(makeCRS<I>(
"20 31 40 51")),
"error");
518 planck_assert(b.contains(makeCRS<I>(
"20 21")),
"error");
519 planck_assert(b.contains(makeCRS<I>(
"50 51")),
"error");
520 planck_assert(!b.contains(makeCRS<I>(
"19 31 40 51")),
"error");
521 planck_assert(!b.contains(makeCRS<I>(
"20 31 40 52")),
"error");
522 planck_assert(!b.contains(makeCRS<I>(
"20 51")),
"error");
523 planck_assert(!b.contains(makeCRS<I>(
"0 1")),
"error");
524 planck_assert(!b.contains(makeCRS<I>(
"0 20 31 40 51 100")),
"error");
527 crangeset<I> b = makeCRS<I>(
"20 31 40 51");
529 planck_assert(!b.overlaps(0,11),
"error");
530 planck_assert(b.overlaps(10,21),
"error");
531 planck_assert(!b.overlaps(19,20),
"error");
532 planck_assert(b.overlaps(20,21),
"error");
533 planck_assert(b.overlaps(21,22),
"error");
534 planck_assert(b.overlaps(20,31),
"error");
535 planck_assert(b.overlaps(25,36),
"error");
536 planck_assert(b.overlaps(30,37),
"error");
537 planck_assert(!b.overlaps(31,32),
"error");
538 planck_assert(!b.overlaps(35,38),
"error");
539 planck_assert(b.overlaps(35,46),
"error");
540 planck_assert(b.overlaps(40,41),
"error");
541 planck_assert(b.overlaps(45,56),
"error");
542 planck_assert(!b.overlaps(60,71),
"error");
545 crangeset<I> b = makeCRS<I>(
"20 31 40 51");
547 planck_assert(b.overlaps(makeCRS<I>(
"20 31 40 51")),
"error");
548 planck_assert(b.overlaps(makeCRS<I>(
"20 21")),
"error");
549 planck_assert(b.overlaps(makeCRS<I>(
"50 51")),
"error");
550 planck_assert(b.overlaps(makeCRS<I>(
"19 31 40 51")),
"error");
551 planck_assert(b.overlaps(makeCRS<I>(
"20 31 40 52")),
"error");
552 planck_assert(b.overlaps(makeCRS<I>(
"20 51")),
"error");
553 planck_assert(!b.overlaps(makeCRS<I>(
"0 1")),
"error");
554 planck_assert(!b.overlaps(makeCRS<I>(
"0 20 31 40 51 100")),
"error");
557 const int niter = 1000;
558 for (
int iter=0; iter<niter; ++iter)
560 crangeset<I> a = randomCRangeSet<I>(1000, 0, 100);
561 crangeset<I> b = randomCRangeSet<I>(1000, 0, 100);
562 crangeset<I> c = randomCRangeSet<I>(10, 10000, 100);
569 template<
typename I>
void check_Moc()
571 cout <<
"testing MOC " << bname<I>() << endl;
573 moc.addPixelRange(0,4,5);
574 moc.addPixelRange(0,6,7);
575 moc.addPixelRange(2,4,17);
576 moc.addPixelRange(10,3000000,3000001);
578 planck_assert(moc==moc.complement().complement(),
"error");
579 planck_assert(moc==Moc<I>::fromUniq(moc.toUniq()),
"error");
580 planck_assert(moc.maxOrder()==10,
"error");
581 Moc<I> xtmp = moc.degradedToOrder(8,
false);
582 planck_assert(moc.contains(xtmp),
"error");
583 planck_assert(!xtmp.contains(moc),
"error");
584 planck_assert(xtmp.overlaps(moc),
"error");
585 xtmp=moc.degradedToOrder(8,
true);
586 planck_assert(!moc.contains(xtmp),
"error");
587 planck_assert(xtmp.contains(moc),
"error");
588 planck_assert(xtmp.overlaps(moc),
"error");
589 planck_assert(moc==Moc<I>::fromCompressed(moc.toCompressed()),
"error");
591 assertEquals(
"inconsistency",moc,MocUtil.mocFromString(
" 0/4, 6 2/ \t 4 -16 10/3000000 \t\n "));
592 assertEquals(
"inconsistency",moc,MocUtil.mocFromString(
"0/6 2/ 5 2/4 2/6- 16 0/4 10/3000000"));
593 assertEquals(
"inconsistency",moc,MocUtil.mocFromString
594 (
"{\"0\":[6] , \"2\": [5 ], \"2\":[ 4,6,7,8,9,10,11,12,13,14,15,16], \"0\":[4], \"10\":[3000000]}"));
595 assertEquals(
"inconsistency",moc,MocUtil.mocFromString(MocUtil.mocToStringASCII(moc)));
596 assertEquals(
"inconsistency",moc,MocUtil.mocFromString(MocUtil.mocToStringJSON(moc)));
597 ByteArrayOutputStream out=
new ByteArrayOutputStream();
598 MocUtil.mocToFits(moc,out);
599 ByteArrayInputStream inp =
new ByteArrayInputStream(out.toByteArray());
600 assertEquals(
"inconsistency",moc,MocUtil.mocFromFits(inp));
604 Moc<I> full; full.addPixelRange(0,0,12);
606 for (tsize iter=0; iter<niter; ++iter)
608 Moc<I> a = randomMoc<I>(1000, 0, 100);
609 planck_assert(a.complement().complement()==a,
"error");
610 planck_assert(!a.overlaps(a.complement()),
"error");
611 planck_assert(a.op_or(a.complement())==full,
"error");
612 planck_assert(a.op_and(a.complement())==empty,
"error");
614 write_Moc_to_fits(
"!healpixtestmoctmp",a);
615 planck_assert(a==read_Moc_from_fits<I>(
"healpixtestmoctmp"),
"FITS problem");
620 template<
typename I>
void check_compress()
622 cout <<
"testing interpolation coding " << bname<I>() << endl;
623 planck_assert(trailingZeros(4)==2,
"error");
624 planck_assert(trailingZeros(5)==0,
"error");
625 planck_assert(trailingZeros(int64(1)<<48)==48,
"error");
626 for (tsize x=0; x<100; ++x)
628 rangeset<I> a = randomRangeSet<I>(1000, 0, 100);
630 for (tsize i=0; i<a.nranges(); ++i)
631 b.append(a.ivbegin(i)<<6,a.ivend(i)<<6);
632 const vector<I> &v=b.data();
634 interpol_encode(v.begin(),v.end(),obs);
635 vector<uint8> comp=obs.state();
637 ibitstream ibs(comp);
638 interpol_decode(v2,ibs);
639 planck_assert(v==v2,
"data mismatch");
643 template<
typename I>
void check_ringnestring()
645 cout <<
"testing ring2nest(nest2ring(m))==m " << bname<I>() << endl;
646 for (
int order=0; order<=T_Healpix_Base<I>::order_max; ++order)
649 for (
int m=0; m<nsamples; ++m)
651 I pix = I(rng.rand_uni()*base.Npix());
652 if (base.ring2nest(base.nest2ring(pix))!=pix)
653 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
658 template<
typename I>
void check_nestpeanonest()
660 cout <<
"testing peano2nest(nest2peano(m))==m " << bname<I>() << endl;
661 for (
int order=0; order<=T_Healpix_Base<I>::order_max; ++order)
664 for (
int m=0; m<nsamples; ++m)
666 I pix = I(rng.rand_uni()*base.Npix());
667 if (base.peano2nest(base.nest2peano(pix))!=pix)
668 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
673 template<
typename I>
void check_pixzphipix()
675 cout <<
"testing zphi2pix(pix2zphi(m))==m " << bname<I>() << endl;
677 for (
int order=0; order<=omax; ++order)
680 for (
int m=0; m<nsamples; ++m)
683 I pix = I(rng.rand_uni()*base1.Npix());
684 base1.pix2zphi(pix,z,phi);
685 if (base1.zphi2pix(z,phi)!=pix)
686 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
687 base2.pix2zphi(pix,z,phi);
688 if (base2.zphi2pix(z,phi)!=pix)
689 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
692 for (I nside=3; nside<(I(1)<<omax); nside+=nside/2+1)
695 for (
int m=0; m<nsamples; ++m)
698 I pix = I(rng.rand_uni()*base.Npix());
699 base.pix2zphi(pix,z,phi);
700 if (base.zphi2pix(z,phi)!=pix)
701 FAIL(cout<<
" PROBLEM: nside = "<<nside<<
", pixel = "<<pix<<endl)
706 template<
typename I>
void check_zphipixzphi()
708 cout <<
"testing pix2zphi(zphi2pix(ptg)) approx zphi " << bname<I>() << endl;
710 for (
int order=0; order<=omax; ++order)
713 double mincos = min (cos(base1.max_pixrad()),0.999999999999999);
714 for (
int m=0; m<nsamples; ++m)
716 double z,phi,z2,phi2;
718 base1.pix2zphi(base1.zphi2pix(z,phi),z2,phi2);
719 if (cosdist_zphi(z,phi,z2,phi2)<mincos)
720 FAIL(cout <<
" PROBLEM: order = " << order
721 <<
", zphi = " << z <<
", " << phi << endl)
722 base2.pix2zphi(base2.zphi2pix(z,phi),z2,phi2);
723 if (cosdist_zphi(z,phi,z2,phi2)<mincos)
724 FAIL(cout <<
" PROBLEM: order = " << order
725 <<
", zphi = " << z <<
", " << phi << endl)
728 for (
int nside=3; nside<(I(1)<<omax); nside+=nside/2+1)
731 double mincos = min (cos(base.max_pixrad()),0.999999999999999);
732 for (
int m=0; m<nsamples; ++m)
734 double z,phi,z2,phi2;
736 base.pix2zphi(base.zphi2pix(z,phi),z2,phi2);
737 if (cosdist_zphi(z,phi,z2,phi2)<mincos)
738 FAIL(cout <<
" PROBLEM: nside = " << nside
739 <<
", zphi = " << z <<
", " << phi << endl)
744 template<
typename I>
void check_pixangpix()
746 cout <<
"testing ang2pix(pix2ang(m))==m " << bname<I>() << endl;
748 for (
int order=0; order<=omax; ++order)
751 for (
int m=0; m<nsamples; ++m)
753 I pix = I(rng.rand_uni()*base1.Npix());
754 if (base1.ang2pix(base1.pix2ang(pix))!=pix)
755 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
756 if (base2.ang2pix(base2.pix2ang(pix))!=pix)
757 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pixel = "<<pix<<endl)
760 for (I nside=3; nside<(I(1)<<omax); nside+=nside/2+1)
763 for (
int m=0; m<nsamples; ++m)
765 I pix = I(rng.rand_uni()*base.Npix());
766 if (base.ang2pix(base.pix2ang(pix))!=pix)
767 FAIL(cout<<
" PROBLEM: nside = "<<nside<<
", pixel = "<<pix<<endl)
772 template<
typename I>
void check_neighbors()
774 cout <<
"testing neighbor function " << bname<I>() << endl;
776 for (
int order=0; order<=omax; ++order)
779 double maxang = 2.01*base.max_pixrad();
780 for (
int m=0; m<nsamples/10; ++m)
782 I pix = I(rng.rand_uni()*base.Npix());
784 vec3 pixpt = base.pix2vec(pix);
785 base.neighbors(pix,nb);
786 base2.neighbors(base.nest2ring(pix),nb2);
787 for (
int n=0; n<8; ++n)
789 planck_assert(nb2[n]<0,
"neighbor inconsistency");
791 planck_assert(base.nest2ring(nb[n])==nb2[n],
"neighbor inconsistency");
792 sort(&nb[0],&nb[0]+8);
794 for (
int n=0; n<8; ++n)
800 if (v_angle(base.pix2vec(nb[n]),pixpt)>maxang)
801 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pix = "<<pix<<endl)
802 if ((n>0) && (nb[n]==nb[n-1]))
803 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pix = "<<pix<<endl)
806 planck_assert((check<=1)||((order==0)&&(check<=2)),
"too few neighbors");
809 for (I nside=3; nside<(I(1)<<omax); nside+=nside/2+1)
812 double maxang = 2.01*base.max_pixrad();
813 for (
int m=0; m<nsamples/10; ++m)
815 I pix = I(rng.rand_uni()*base.Npix());
817 vec3 pixpt = base.pix2vec(pix);
818 base.neighbors(pix,nb);
819 for (
int n=0; n<8; ++n)
820 if ((nb[n]>=0) && (v_angle(base.pix2vec(nb[n]),pixpt)>maxang))
821 FAIL(cout<<
" PROBLEM: nside = "<<nside<<
", pix = "<<pix<<endl)
826 void check_swap_scheme()
828 cout <<
"testing whether double swap_scheme() returns the original map" 829 << endl <<
"(for orders 0 to 10)." << endl;
830 for (
int order=0; order<=10; ++order)
833 for (
int m=0; m<map.Npix(); ++m) map[m]=uint8(m&0xFF);
836 for (
int m=0; m<map.Npix(); ++m)
837 if (map[m]!=(m&0xFF))
838 FAIL(cout<<
" PROBLEM: order = "<<order<<
", pix = "<<m<<endl)
844 cout <<
"checking issue #229" << endl;
849 for (
int m=0; m<vmap.Npix(); ++m)
850 vmap[m]=vmap.pix2vec(m);
851 pointing ptg(halfpi-0.1,0);
853 auto pixset = map.query_disc(ptg,rad);
855 double cosrad=cos(rad);
856 for (tsize j=0; j<pixset.nranges(); ++j)
857 for (
int i=pixset.ivbegin(j); i<pixset.ivend(j); ++i)
859 for (
int i=0; i<map.Npix(); ++i)
861 bool inside = dotprod(vmap[i],vptg)>cosrad;
863 FAIL(cout <<
" PROBLEM: issue 229" << endl)
867 void check_issue_968 ()
869 cout <<
"checking issue #968" << endl;
872 pointing ptg(174*pi/180., 45*pi/180.);
874 base.query_disc_inclusive (ptg, 9.9*pi/180., res, 4);
875 if (find(res.begin(), res.end(), 190) == res.end())
876 FAIL(cout <<
" PROBLEM: issue 968" << endl)
881 cout <<
"testing whether all pixels found by query_disc() really" << endl
882 <<
"lie inside the disk (and vice versa)" << endl;
883 cout <<
"Ordering scheme: " << (scheme==
RING ?
"RING" :
"NEST") << endl;
885 for (
int order=0; order<=5; ++order)
890 for (
int m=0; m<vmap.Npix(); ++m)
891 vmap[m]=vmap.pix2vec(m);
892 for (
int m=0; m<100000; ++m)
896 double rad = pi/1 * rng.rand_uni();
897 auto pixset = map.query_disc(ptg,rad);
899 double cosrad=cos(rad);
900 for (tsize j=0; j<pixset.nranges(); ++j)
901 for (
int i=pixset.ivbegin(j); i<pixset.ivend(j); ++i)
903 for (
int i=0; i<map.Npix(); ++i)
905 bool inside = dotprod(vmap[i],vptg)>cosrad;
907 FAIL(cout<<
" PROBLEM: order = "<<order<<
", ptg = "<<ptg<<endl)
909 for (tsize j=0; j<pixset.nranges(); ++j)
910 for (
int i=pixset.ivbegin(j); i<pixset.ivend(j); ++i)
916 template<
typename I>
void check_query_disc()
918 cout <<
"checking query_disc() " << bname<I>() << endl;
921 for (
int order=0; order<=omax; ++order)
924 int niter=max(1,min(1000,100000>>order));
925 for (
int m=0; m<niter; ++m)
929 double rad = pi/1 * rng.rand_uni();
930 auto pixset = rbase.query_disc(ptg,rad);
931 rangeset<I> pslast=pixset;
932 for (tsize fct=5; fct>0; --fct)
934 auto psi = rbase.query_disc_inclusive(ptg,rad,fct);
935 if (!psi.contains(pslast))
936 cout <<
" Potential problem: RING pixel sets inconsistent" << endl;
939 I nval = pixset.nval();
940 pixset = nbase.query_disc(ptg,rad);
942 for (tsize fct=8; fct>0; fct>>=1)
944 auto psi = nbase.query_disc_inclusive(ptg,rad,fct);
945 if (!psi.contains(pslast))
946 FAIL(cout <<
" PROBLEM: NEST pixel sets inconsistent" << endl)
949 if (nval!=pixset.nval())
950 FAIL(cout <<
" PROBLEM: number of pixels different: " 951 << nval <<
" vs. " << pixset.nval() << endl)
955 template<
typename I>
void check_query_polygon()
957 cout <<
"checking query_polygon() " << bname<I>() << endl;
960 for (
int order=0; order<=omax; ++order)
963 int niter=max(1,min(1000,100000>>order));
964 for (
int m=0; m<niter; ++m)
966 vector<pointing> corner(3);
967 random_dir(corner[0]); random_dir(corner[1]); random_dir(corner[2]);
968 auto pixset = rbase.query_polygon(corner);
969 I nval = pixset.nval();
970 pixset = nbase.query_polygon(corner);
971 if (nval!=pixset.nval())
972 FAIL(cout <<
" PROBLEM: number of pixels different: " 973 << nval <<
" vs. " << pixset.nval() << endl)
974 pixset = rbase.query_polygon_inclusive(corner,4);
976 pixset = nbase.query_polygon_inclusive(corner,4);
979 FAIL(cout <<
" PROBLEM: inclusive(RING)<inclusive(NEST): " 980 << nv1 <<
" vs. " << nv2 << endl)
982 FAIL(cout <<
" PROBLEM: inclusive(NEST)<non-inclusive: " 983 << nv2 <<
" vs. " << nval << endl)
988 void helper_oop (
int order)
991 for (
int m=0; m<map.Npix(); ++m) map[m] = rng.rand_uni()+0.01;
994 for (
int m=0; m<map.Npix(); ++m)
995 if (!approx(map[m],map3[m],1e-12))
996 FAIL(cout <<
"PROBLEM: order = " << order << endl)
1002 for (
int m=0; m<map.Npix(); ++m) map[m] = rng.rand_uni()+0.01;
1005 for (
int m=0; m<map.Npix(); ++m)
1006 if (!approx(map[m],map3[m],1e-12))
1007 FAIL(cout <<
"PROBLEM: order = " << order << endl)
1009 void helper_udgrade2 (
int nside)
1012 map3 (nside,
RING,SET_NSIDE);
1013 for (
int m=0; m<map.Npix(); ++m) map[m] = rng.rand_uni()+0.01;
1016 for (
int m=0; m<map.Npix(); ++m)
1017 if (!approx(map[m],map3[m],1e-12))
1018 FAIL(cout <<
"PROBLEM: nside = " << nside << endl)
1023 cout <<
"testing out-of-place swapping" << endl;
1024 for (
int order=0; order<=7; ++order)
1026 cout <<
"testing downgrade(upgrade(map)) == map" << endl;
1027 for (
int order=0; order<=7; ++order)
1034 for (
int nside=3; nside<500; nside+=nside/2+1)
1035 helper_udgrade2(nside);
1038 void check_average()
1040 cout <<
"testing whether average(map) == average(downgraded map)" << endl;
1041 for (
int order=1; order<=10; ++order)
1044 for (
int m=0; m<map.Npix(); ++m)
1045 map[m] = rng.rand_uni()+0.01;
1047 double avg=map.average(), avg2=map2.average();
1048 if (!approx(avg,avg2,1e-13))
1049 FAIL(cout <<
"PROBLEM: order = " << order <<
" " << avg/avg2-1 << endl)
1051 for (
int nside=3; nside<1000; nside += nside/2+1)
1054 for (
int m=0; m<map.Npix(); ++m)
1055 map[m] = rng.rand_uni()+0.01;
1057 double avg=map.average(), avg2=map2.average();
1058 if (!approx(avg,avg2,1e-13))
1059 FAIL(cout <<
"PROBLEM: nside = " << nside <<
" " << avg/avg2-1 << endl)
1063 void random_alm (
Alm<xcomplex<double> >&almT,
Alm<xcomplex<double> >&almG,
1064 Alm<xcomplex<double> >&almC,
int lmax,
int mmax)
1066 almT.Set(lmax,mmax); almG.Set(lmax,mmax); almC.Set(lmax,mmax);
1068 for (
int l=0; l<=lmax; ++l)
1070 almT(l,0)=dcomplex(rng.rand_gauss(),0.);
1071 almG(l,0)=dcomplex(rng.rand_gauss(),0.);
1072 almC(l,0)=dcomplex(rng.rand_gauss(),0.);
1075 for (
int m=1; m<=mmax; ++m)
1076 for (
int l=m; l<=lmax; ++l)
1078 almT(l,m).real(rng.rand_gauss()); almT(l,m).imag(rng.rand_gauss());
1079 almG(l,m).real(rng.rand_gauss()); almG(l,m).imag(rng.rand_gauss());
1080 almC(l,m).real(rng.rand_gauss()); almC(l,m).imag(rng.rand_gauss());
1082 almG(0,0)=almC(0,0)=almG(1,0)=almC(1,0)=almG(1,1)=almC(1,1)=0;
1085 void random_alm (
Alm<xcomplex<double> >&alm,
int lmax,
int mmax)
1089 for (
int l=0; l<=lmax; ++l)
1090 { alm(l,0)=dcomplex(rng.rand_gauss(),0.); }
1092 for (
int m=1; m<=mmax; ++m)
1093 for (
int l=m; l<=lmax; ++l)
1094 { alm(l,m).real(rng.rand_gauss()); alm(l,m).imag(rng.rand_gauss()); }
1097 void check_alm (
const Alm<xcomplex<double> >&oalm,
1098 const Alm<xcomplex<double> >&alm,
double epsilon)
1100 for (
int m=0; m<=alm.Mmax(); ++m)
1101 for (
int l=m; l<=alm.Lmax(); ++l)
1103 if (!abs_approx(oalm(l,m).real(),alm(l,m).real(),epsilon))
1104 FAIL(cout <<
"Problemr " << l <<
" " << m << endl)
1105 if (!abs_approx(oalm(l,m).imag(),alm(l,m).imag(),epsilon))
1106 FAIL(cout <<
"Problemi " << l <<
" " << m << endl)
1110 void check_alm2map2alm (
int lmax,
int mmax,
int nside)
1112 cout <<
"testing whether a_lm->map->a_lm returns original a_lm" << endl;
1113 cout <<
"lmax=" << lmax <<
", mmax=" << mmax <<
", nside=" << nside << endl;
1114 const double epsilon = 1e-8;
1116 oalmG(lmax,mmax),almG(lmax,mmax),oalmC(lmax,mmax),almC(lmax,mmax);
1118 mapU(nside,
RING,SET_NSIDE);
1120 const double eps0=1e-11;
1121 const double eps=1e-12;
1123 random_alm(oalmT,oalmG,oalmC,lmax,mmax);
1125 map2alm_iter2(mapT,almT,eps0,eps0);
1126 check_alm (oalmT, almT, epsilon);
1128 alm2map_spin(oalmG,oalmC,mapQ,mapU,1);
1129 map2alm_spin_iter2(mapQ,mapU,almG,almC,1,eps,eps);
1130 check_alm (oalmG, almG, epsilon);
1131 check_alm (oalmC, almC, epsilon);
1134 map2alm_pol_iter2(mapT,mapQ,mapU,almT,almG,almC,max(eps,eps0),max(eps,eps0));
1135 check_alm (oalmT, almT, epsilon);
1136 check_alm (oalmG, almG, epsilon);
1137 check_alm (oalmC, almC, epsilon);
1140 void check_smooth_alm ()
1142 cout <<
"testing whether unsmooth(smooth(a_lm)) returns a_lm" << endl;
1143 const double epsilon = 1e-14;
1144 const double fwhm = 100.*arcmin2rad;
1145 const int lmax=300, mmax=300;
1147 oalmG(lmax,mmax),almG(lmax,mmax),oalmC(lmax,mmax),almC(lmax,mmax);
1149 random_alm(oalmT,oalmG,oalmC,lmax,mmax);
1151 almT=oalmT; almG=oalmG; almC=oalmC;
1152 smoothWithGauss (almT, fwhm);
1153 smoothWithGauss (almT, -fwhm);
1154 check_alm (oalmT, almT, epsilon);
1156 smoothWithGauss (almT, almG, almC, fwhm);
1157 smoothWithGauss (almT, almG, almC, -fwhm);
1158 check_alm (oalmT, almT, epsilon);
1159 check_alm (oalmG, almG, epsilon);
1160 check_alm (oalmC, almC, epsilon);
1163 void check_rot_alm ()
1165 cout <<
"testing whether rot^-1(rot(a_lm)) returns a_lm" << endl;
1166 const double epsilon = 2e-13;
1170 random_alm(oalm,lmax,lmax);
1173 rotate_alm (alm,3,4,5);
1174 rotate_alm (alm,-5,-4,-3);
1175 check_alm (oalm, alm, epsilon);
1180 planck_assert(a.
conformable(b),
"maps are not conformable");
1182 for (
int i=0; i<a.
Npix(); ++i)
1184 double diff=a[i]-b[i];
1190 void check_ringweights ()
1192 cout <<
"testing the accuracy of ring weights" << endl;
1196 arr<double> rwgt(2*nside);
1197 for (tsize i=0; i<rwgt.size(); ++i) rwgt[i]=rwgt0[i]+1.;
1201 map2alm(omap,alm,arr<double>(2*nside,1.));
1203 double ressimple = map_residual(omap,map2);
1206 double reswgt = map_residual(omap,map2);
1207 double resquot=sqrt(reswgt/ressimple);
1209 FAIL(cout <<
" PROBLEM with ringweights: resquot = " << resquot << endl)
1212 void check_fullweights ()
1214 cout <<
"testing the accuracy of pixel weights" << endl;
1221 map2alm(omap,alm,arr<double>(2*nside,1.));
1223 double ressimple = map_residual(omap,map2);
1226 map2alm(map2,alm,arr<double>(2*nside,1.));
1228 double reswgt = map_residual(omap,map2);
1229 double resquot=sqrt(reswgt/ressimple);
1231 FAIL(cout <<
" PROBLEM with full weights: resquot = " << resquot << endl)
1236 cout <<
"testing whether isqrt() works reliably" << endl;
1237 uint64 val=uint64(0xF234)<<16, valsq=val*val;
1238 if (isqrt(valsq)!=val) FAIL(cout <<
"PROBLEM1" << endl)
1239 if (isqrt(valsq-1)!=val-1) FAIL(cout <<
"PROBLEM2" << endl)
1242 void check_pix2ang_acc()
1244 cout <<
"testing accuracy of pix2ang at the poles" << endl;
1245 for (
int m=0; m<=29;++m)
1248 if (base.pix2ang(1).theta==0.)
1249 FAIL(cout <<
"PROBLEM: order " << m << endl)
1253 const int nsteps=1000000;
1255 template<
typename I>
void perf_neighbors(
const string &name,
1259 wallTimers.start(name);
1261 for (
int order=0; order<=omax; ++order)
1264 I dpix=max(base.Npix()/nsteps,I(1));
1266 for (I pix=0; pix<base.Npix(); pix+=dpix)
1268 base.neighbors(pix,nres);
1272 wallTimers.stop(name);
1273 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1275 template<
typename I>
void perf_pix2ang(
const string &name,
1279 wallTimers.start(name);
1281 for (
int order=0; order<=omax; ++order)
1284 I dpix=max(base.Npix()/nsteps,I(1));
1285 for (I pix=0; pix<base.Npix(); pix+=dpix)
1287 pointing p(base.pix2ang(pix));
1288 dummy+=p.theta+p.phi;
1292 wallTimers.stop(name);
1293 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1295 template<
typename I>
void perf_pix2vec(
const string &name,
1299 wallTimers.start(name);
1301 for (
int order=0; order<=omax; ++order)
1304 I dpix=max(base.Npix()/nsteps,I(1));
1305 for (I pix=0; pix<base.Npix(); pix+=dpix)
1307 vec3 v(base.pix2vec(pix));
1312 wallTimers.stop(name);
1313 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1315 template<
typename I>
void perf_pix2zphi(
const string &name,
1319 wallTimers.start(name);
1321 for (
int order=0; order<=omax; ++order)
1324 I dpix=max(base.Npix()/nsteps,I(1));
1326 for (I pix=0; pix<base.Npix(); pix+=dpix)
1328 base.pix2zphi(pix,z,phi);
1333 wallTimers.stop(name);
1334 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1336 template<
typename I>
void perf_zphi2pix(
const string &name,
1340 wallTimers.start(name);
1342 double dz=2./sqrt(nsteps);
1343 double dph=twopi/sqrt(nsteps);
1344 for (
int order=0; order<=omax; ++order)
1347 for (
double z=-1; z<1; z+=dz)
1348 for (
double phi=0; phi<twopi; phi+=dph)
1350 dummy+=base.zphi2pix(z,phi);
1354 wallTimers.stop(name);
1355 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1357 template<
typename I>
void perf_ang2pix(
const string &name,
1361 wallTimers.start(name);
1363 double dth=pi/sqrt(nsteps);
1364 double dph=twopi/sqrt(nsteps);
1365 for (
int order=0; order<=omax; ++order)
1368 for (
double theta=0; theta<pi; theta+=dth)
1369 for (
double phi=0; phi<twopi; phi+=dph)
1371 dummy+=base.ang2pix(pointing(theta+1e-15*phi,phi));
1375 wallTimers.stop(name);
1376 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1378 template<
typename I>
void perf_ring2nest(
const string &name,
double &dummy)
1381 wallTimers.start(name);
1383 for (
int order=0; order<=omax; ++order)
1386 I dpix=max(base.Npix()/nsteps,I(1));
1387 for (I pix=0; pix<base.Npix(); pix+=dpix)
1389 dummy+=base.ring2nest(pix);
1393 wallTimers.stop(name);
1394 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1396 template<
typename I>
void perf_nest2ring(
const string &name,
double &dummy)
1399 wallTimers.start(name);
1401 for (
int order=0; order<=omax; ++order)
1404 I dpix=max(base.Npix()/nsteps,I(1));
1405 for (I pix=0; pix<base.Npix(); pix+=dpix)
1407 dummy+=base.nest2ring(pix);
1411 wallTimers.stop(name);
1412 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1414 template<
typename I>
void perf_peano2nest(
const string &name,
double &dummy)
1417 wallTimers.start(name);
1419 for (
int order=0; order<=omax; ++order)
1422 I dpix=max(base.Npix()/nsteps,I(1));
1423 for (I pix=0; pix<base.Npix(); pix+=dpix)
1425 dummy+=base.peano2nest(pix);
1429 wallTimers.stop(name);
1430 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1432 template<
typename I>
void perf_nest2peano(
const string &name,
double &dummy)
1435 wallTimers.start(name);
1437 for (
int order=0; order<=omax; ++order)
1440 I dpix=max(base.Npix()/nsteps,I(1));
1441 for (I pix=0; pix<base.Npix(); pix+=dpix)
1443 dummy+=base.nest2peano(pix);
1447 wallTimers.stop(name);
1448 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-6 <<
"MOps/s" << endl;
1450 template<
typename I>
void perf_query_disc(
const string &name,
1455 wallTimers.start(name);
1456 for (
int m=0; m<1000; ++m)
1458 dummy += base.query_disc(vec3(1,0,0),halfpi/9).nranges();
1461 wallTimers.stop(name);
1462 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-3 <<
"kOps/s" << endl;
1464 template<
typename I>
void perf_query_triangle(
const string &name,
1469 vector<pointing> corner;
1470 corner.push_back(vec3(1,0.01,0.01));
1471 corner.push_back(vec3(0.01,1,0.01));
1472 corner.push_back(vec3(0.01,0.01,1));
1473 wallTimers.start(name);
1474 for (
int m=0; m<1000; ++m)
1476 dummy += base.query_polygon(corner).nranges();
1479 wallTimers.stop(name);
1480 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-3 <<
"kOps/s" << endl;
1482 template<
typename I>
void perf_query_polygon(
const string &name,
1487 vector<pointing> corner;
1488 corner.push_back(vec3(1,0.01,0.01));
1489 corner.push_back(vec3(1,1,-0.3));
1490 corner.push_back(vec3(0.01,1,0.01));
1491 corner.push_back(vec3(0.01,0.01,1));
1492 wallTimers.start(name);
1493 for (
int m=0; m<1000; ++m)
1495 dummy += base.query_polygon(corner).nranges();
1498 wallTimers.stop(name);
1499 cout << name <<
": " << cnt/wallTimers.acc(name)*1e-3 <<
"kOps/s" << endl;
1505 cout <<
"Measuring performance of Healpix_Base methods." << endl;
1506 perf_pix2zphi<int> (
"pix2zphi (RING):int ",
RING,dummy);
1507 perf_pix2zphi<int> (
"pix2zphi (NEST):int ",
NEST,dummy);
1508 perf_pix2zphi<int64> (
"pix2zphi (RING):int64",
RING,dummy);
1509 perf_pix2zphi<int64> (
"pix2zphi (NEST):int64",
NEST,dummy);
1510 perf_zphi2pix<int> (
"zphi2pix (RING):int ",
RING,dummy);
1511 perf_zphi2pix<int> (
"zphi2pix (NEST):int ",
NEST,dummy);
1512 perf_zphi2pix<int64> (
"zphi2pix (RING):int64",
RING,dummy);
1513 perf_zphi2pix<int64> (
"zphi2pix (NEST):int64",
NEST,dummy);
1514 perf_pix2ang<int> (
"pix2ang (RING):int ",
RING,dummy);
1515 perf_pix2ang<int> (
"pix2ang (NEST):int ",
NEST,dummy);
1516 perf_pix2ang<int64> (
"pix2ang (RING):int64",
RING,dummy);
1517 perf_pix2ang<int64> (
"pix2ang (NEST):int64",
NEST,dummy);
1518 perf_ang2pix<int> (
"ang2pix (RING):int ",
RING,dummy);
1519 perf_ang2pix<int> (
"ang2pix (NEST):int ",
NEST,dummy);
1520 perf_ang2pix<int64> (
"ang2pix (RING):int64",
RING,dummy);
1521 perf_ang2pix<int64> (
"ang2pix (NEST):int64",
NEST,dummy);
1522 perf_pix2vec<int> (
"pix2vec (RING):int ",
RING,dummy);
1523 perf_pix2vec<int> (
"pix2vec (NEST):int ",
NEST,dummy);
1524 perf_pix2vec<int64> (
"pix2vec (RING):int64",
RING,dummy);
1525 perf_pix2vec<int64> (
"pix2vec (NEST):int64",
NEST,dummy);
1526 perf_neighbors<int> (
"neighbors(NEST):int ",
NEST);
1527 perf_neighbors<int> (
"neighbors(RING):int ",
RING);
1528 perf_neighbors<int64>(
"neighbors(NEST):int64",
NEST);
1529 perf_neighbors<int64>(
"neighbors(RING):int64",
RING);
1530 perf_ring2nest<int> (
"ring2nest :int ",dummy);
1531 perf_ring2nest<int64>(
"ring2nest :int64",dummy);
1532 perf_nest2ring<int> (
"nest2ring :int ",dummy);
1533 perf_nest2ring<int64>(
"nest2ring :int64",dummy);
1534 perf_peano2nest<int> (
"peano2nest :int ",dummy);
1535 perf_peano2nest<int64>(
"peano2nest :int64",dummy);
1536 perf_nest2peano<int> (
"nest2peano :int ",dummy);
1537 perf_nest2peano<int64>(
"nest2peano :int64",dummy);
1538 perf_query_disc<int> (
"query_disc (RING):int ",
RING,dummy);
1539 perf_query_disc<int> (
"query_disc (NEST):int ",
NEST,dummy);
1540 perf_query_disc<int64> (
"query_disc (RING):int64",
RING,dummy);
1541 perf_query_disc<int64> (
"query_disc (NEST):int64",
NEST,dummy);
1542 perf_query_triangle<int> (
"query_triangle(RING):int ",
RING,dummy);
1543 perf_query_triangle<int> (
"query_triangle(NEST):int ",
NEST,dummy);
1544 perf_query_triangle<int64>(
"query_triangle(RING):int64",
RING,dummy);
1545 perf_query_triangle<int64>(
"query_triangle(NEST):int64",
NEST,dummy);
1546 perf_query_polygon<int> (
"query_polygon (RING):int ",
RING,dummy);
1547 perf_query_polygon<int> (
"query_polygon (NEST):int ",
NEST,dummy);
1548 perf_query_polygon<int64> (
"query_polygon (RING):int64",
RING,dummy);
1549 perf_query_polygon<int64> (
"query_polygon (NEST):int64",
NEST,dummy);
1551 if (dummy<0) cout << dummy << endl;
1556 int main(
int argc,
const char **argv)
1558 module_startup (
"hpxtest",argc,argv,1,
"");
1560 check_compress<int>();
1561 check_compress<unsigned>();
1562 check_compress<int64>();
1563 check_compress<uint64>();
1566 check_rangeset<int>();
1567 check_rangeset<int64>();
1568 check_crangeset<int>();
1569 check_crangeset<int64>();
1571 check_pix2ang_acc();
1574 check_alm2map2alm(620,620,256);
1575 check_alm2map2alm(620,2,256);
1578 check_ringnestring<int>();
1579 check_ringnestring<int64>();
1580 check_nestpeanonest<int>();
1581 check_nestpeanonest<int64>();
1582 check_pixzphipix<int>();
1583 check_pixzphipix<int64>();
1584 check_zphipixzphi<int>();
1585 check_zphipixzphi<int64>();
1586 check_pixangpix<int>();
1587 check_pixangpix<int64>();
1588 check_neighbors<int>();
1589 check_neighbors<int64>();
1590 check_swap_scheme();
1591 check_query_disc_strict(
RING);
1592 check_query_disc_strict(
NEST);
1593 check_issue_229(
RING);
1594 check_issue_229(
NEST);
1595 check_query_disc<int>();
1596 check_query_disc<int64>();
1597 check_query_polygon<int>();
1598 check_query_polygon<int64>();
1599 check_ringweights();
1600 check_fullweights();
1603 if (errcount>0) planck_fail(
"unit test errors");
vector< double > get_fullweights(int nside, int lmax, double epsilon, int itmax, double &epsilon_out)
void map2alm(const Healpix_Map< T > &map, Alm< xcomplex< T > > &alm, const arr< double > &weight, bool add_alm)
void apply_fullweights(Healpix_Map< T > &map, const std::vector< double > &wgt)
void alm2map_pol(const Alm< xcomplex< T > > &almT, const Alm< xcomplex< T > > &almG, const Alm< xcomplex< T > > &almC, Healpix_Map< T > &mapT, Healpix_Map< T > &mapQ, Healpix_Map< T > &mapU, bool add_map)
void alm2map(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, bool add_map)
bool conformable(const T_Healpix_Base &other) const
vector< double > get_ringweights(int nside, int lmax, double epsilon, int itmax, double &epsilon_out)