IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28223


Ignore:
Timestamp:
Jun 4, 2010, 2:20:19 PM (16 years ago)
Author:
Paul Price
Message:

Add extra diagnostics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/types/tap_psTree.c

    r25256 r28223  
    33#include "pstap.h"
    44
    5 #define NUM 1000000                      // Number of points
     5#define NUM 1000000                     // Number of points
    66#define SPHERICAL_DISTANCE 3.0          // Distance of interest for spherical test
     7#define SEED 0                          // Random seed
     8
     9static double distance(double ra1, double dec1, double ra2, double dec2)
     10{
     11#if 0
     12    // Traditional formula
     13    return acos(sin(dec1) * sin(dec2) + cos(dec1) * cos(dec2) * cos(ra1 - ra2));
     14#else
     15    // Haversine formula: used in psTree
     16    double dphi = dec1 - dec2;
     17    double sindphi = sin(dphi/2.0);
     18    double dlambda = ra1 - ra2;
     19    double sindlambda = sin(dlambda/2.0);
     20    return 2.0 * asin(sqrt(PS_SQR(sindphi) + cos(dec1) * cos(dec2) * PS_SQR(sindlambda)));
     21#endif
     22}
    723
    824int main(int argc, char *argv[])
     
    5470            ok(closest->data.F64[0] == x->data.F64[bestIndex] &&
    5571               closest->data.F64[1] == y->data.F64[bestIndex],
    56                "correst coords: %lf,%lf(%lf) vs %lf,%lf(%lf)",
     72               "correct coords: %lf,%lf(%lf) vs %lf,%lf(%lf)",
    5773               closest->data.F64[0], closest->data.F64[1],
    5874               sqrt(PS_SQR(closest->data.F64[0]) + PS_SQR(closest->data.F64[1])),
     
    7793        psVector *dec = psVectorAlloc(NUM, PS_TYPE_F64);
    7894
    79         psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
     95        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, SEED);
    8096        for (int i = 0; i < NUM; i++) {
    8197            // Using http://mathworld.wolfram.com/SpherePointPicking.html
    82             ra->data.F64[i] = psRandomUniform(rng);
     98            ra->data.F64[i] = psRandomUniform(rng) * 2.0 * M_PI;
    8399            dec->data.F64[i] = acos(2.0 * psRandomUniform(rng) - 1.0) - M_PI_2;
    84100        }
     
    92108
    93109            psVector *coords = psVectorAlloc(2, PS_TYPE_F64);
    94             coords->data.F64[0] = psRandomUniform(rng);
     110#if 0
     111            coords->data.F64[0] = psRandomUniform(rng) * 2.0 * M_PI;
    95112            coords->data.F64[1] = acos(2.0 * psRandomUniform(rng) - 1.0) - M_PI_2;
     113#else
     114            psVectorInit(coords, 0);
     115#endif
    96116
    97117            psVector *indices = psTreeAllWithin(tree, coords, DEG_TO_RAD(SPHERICAL_DISTANCE));
     
    102122            ok(psVectorSortInPlace(indices), "sorted indices");
    103123
     124#if 0
     125            for (long i = 0; i < indices->n; i++) {
     126                long index = indices->data.S64[i];
     127                double dist = distance(coords->data.F64[0], coords->data.F64[1],
     128                                       ra->data.F64[index], dec->data.F64[index]);
     129                diag("%ld (%lf,%lf) is in the list (%lf vs %lf)",
     130                     index, ra->data.F64[index], dec->data.F64[index], RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
     131            }
     132#endif
     133
    104134            bool allgood = true;        // All points in the appropriate place?
    105135            double bestDistance = INFINITY; // Distance to best point
    106136            long bestIndex = -1;        // Index of best point
     137            long bad = 0;               // Number bad
    107138            for (long i = 0, j = 0; i < NUM; i++) {
    108 #if 1
    109                 // Traditional formula
    110                 double dist = acos(sin(coords->data.F64[1]) * sin(dec->data.F64[i]) +
    111                                    cos(coords->data.F64[1]) * cos(dec->data.F64[i]) *
    112                                    cos(coords->data.F64[0] - ra->data.F64[i]));
    113 #else
    114                 // Haversine formula: used in psTree
    115                 double dphi = coords->data.F64[1] - dec->data.F64[i];
    116                 double sindphi = sin(dphi/2.0);
    117                 double dlambda = coords->data.F64[0] - ra->data.F64[i];
    118                 double sindlambda = sin(dlambda/2.0);
    119                 double dist = 2.0 * asin(sqrt(PS_SQR(sindphi) +
    120                                               cos(coords->data.F64[1]) * cos(dec->data.F64[i]) *
    121                                               PS_SQR(sindlambda)));
    122 #endif
    123                                               if (dist < bestDistance) {
     139                double dist = distance(coords->data.F64[0], coords->data.F64[1],
     140                                       ra->data.F64[i], dec->data.F64[i]);
     141                if (dist < bestDistance) {
    124142                    bestDistance = dist;
    125143                    bestIndex = i;
    126144                }
    127                 if (i == indices->data.S64[j]) {
     145                if (j < indices->n && i == indices->data.S64[j]) {
    128146                    j++;
    129147                    if (dist > DEG_TO_RAD(SPHERICAL_DISTANCE)) {
    130                         diag("%ld is in the list, but shouldn't be (%lf vs %lf)",
    131                              i, RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
     148                        diag("%ld (%lf,%lf) is in the list, but shouldn't be (%lf vs %lf)",
     149                             i, ra->data.F64[i], dec->data.F64[i], RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
    132150                        allgood = false;
     151                        bad++;
     152                    } else {
     153#if 0
     154                        diag("%ld (%lf,%lf) correctly identified in the list (%lf vs %lf)",
     155                             i, ra->data.F64[i], dec->data.F64[i], RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
     156#endif
    133157                    }
    134158                } else if (dist <= DEG_TO_RAD(SPHERICAL_DISTANCE)) {
    135                     diag("%ld is not in the list, but should be (%lf vs %lf)",
    136                          i, RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
     159                    diag("%ld (%lf,%lf) is not in the list, but should be (%lf vs %lf)",
     160                         i, ra->data.F64[i], dec->data.F64[i], RAD_TO_DEG(dist), SPHERICAL_DISTANCE);
    137161                    allgood = false;
     162                    bad++;
    138163                }
    139164            }
    140             ok(allgood, "list is acurate");
     165            ok(allgood, "list is accurate: %ld bad", bad);
    141166            ok(bestIndex == closeIndex, "correct point: %ld vs %ld", closeIndex, bestIndex);
    142167
Note: See TracChangeset for help on using the changeset viewer.