Skip to content

Commit

Permalink
avoid HUGE_VAL, define LARGE_VAL
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Jan 8, 2022
1 parent d7855b9 commit c26551f
Show file tree
Hide file tree
Showing 50 changed files with 159 additions and 149 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.87-1-gccf53467'
__version__ = '0.87-10-gd7855b91'
4 changes: 2 additions & 2 deletions catalogs/usnob-scamp-catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "os-features.h"
#include "scamp-catalog.h"
#include "usnob-fits.h"
//#include "healpix-utils.h"
#include "healpix.h"
#include "starutil.h"
#include "errors.h"
#include "log.h"
#include "mathutil.h"

const char* OPTIONS = "hu:o:A:D:r:n:RBNv";

Expand Down Expand Up @@ -92,7 +92,7 @@ int main(int argc, char** args) {
}
log_init(loglvl);

if (ra == HUGE_VAL || dec == HUGE_VAL || !usnobpath || !scampref || radius == 0.0 || !nside) {
if (ra == LARGE_VAL || dec == LARGE_VAL || !usnobpath || !scampref || radius == 0.0 || !nside) {
print_help(args[0]);
printf("\n\nNeed RA, Dec, USNOB path, Nside, Scamp output file, and radius.\n");
exit(-1);
Expand Down
5 changes: 3 additions & 2 deletions include/astrometry/kdtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

#define KDTREE_MAX_LEVELS 1000

#define KDT_INFTY_DOUBLE HUGE_VAL
#define KDT_INFTY_FLOAT HUGE_VALF
// negatives of these values should be valid also
#define KDT_LARGEVAL 1e308
#define KDT_LARGEVALF 1e38

enum kd_rangesearch_options {
KD_OPTIONS_COMPUTE_DISTS = 0x1,
Expand Down
3 changes: 3 additions & 0 deletions include/astrometry/mathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "astrometry/keywords.h"
#include "bl.h"

#define LARGE_VAL 1e30
#define LARGE_VALF 1e30f

int point_in_polygon(double x, double y, const dl* polygon);

/*
Expand Down
3 changes: 0 additions & 3 deletions include/astrometry/os-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
? __x_n >= __LDBL_MIN__ \
: __x_n >= __DBL_MIN__), 1); })

#undef HUGE_VALF
#define HUGE_VALF (1e50f)

#endif


Expand Down
2 changes: 1 addition & 1 deletion include/astrometry/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct solver_t {
double logratio_bail_threshold;

// During verification, if the log-odds ratio rises above this level, we accept the
// match and bail out. Default: HUGE_VAL (ie, don't bail out: keep going to find the
// match and bail out. Default: LARGE_VAL (ie, don't bail out: keep going to find the
// maximum Bayes factor value).
double logratio_stoplooking;

Expand Down
2 changes: 1 addition & 1 deletion libkd/dualtree_nearestneighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void dualtree_nearestneighbour(kdtree_t* xtree, kdtree_t* ytree, double maxdist2
params.nearest_d2 = malloc(NY * sizeof(double));

if (maxdist2 == 0.0)
maxdist2 = HUGE_VAL;
maxdist2 = LARGE_VAL;
for (i=0; i<NY; i++)
params.nearest_d2[i] = maxdist2;

Expand Down
4 changes: 2 additions & 2 deletions libkd/kdint_dtype_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ typedef double dtype;
#define DTYPE_INTEGER 0
#define DTYPE_DOUBLE 1

#define DTYPE_MAX KDT_INFTY_DOUBLE
#define DTYPE_MIN -KDT_INFTY_DOUBLE
#define DTYPE_MAX KDT_LARGEVAL
#define DTYPE_MIN -KDT_LARGEVAL

#define DTYPE d
#define DTYPE_M d
Expand Down
4 changes: 2 additions & 2 deletions libkd/kdint_dtype_f.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ typedef float dtype;
#define DTYPE_INTEGER 0
#define DTYPE_DOUBLE 0

#define DTYPE_MAX KDT_INFTY_FLOAT
#define DTYPE_MIN -KDT_INFTY_FLOAT
#define DTYPE_MAX KDT_LARGEVALF
#define DTYPE_MIN -KDT_LARGEVALF

#define DTYPE f
#define DTYPE_M f
Expand Down
4 changes: 2 additions & 2 deletions libkd/kdint_etype_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef double etype;

#define ETYPE_INTEGER 0

#define ETYPE_MAX KDT_INFTY_DOUBLE
#define ETYPE_MIN -KDT_INFTY_DOUBLE
#define ETYPE_MAX KDT_LARGEVAL
#define ETYPE_MIN -KDT_LARGEVAL

#define ETYPE d
4 changes: 2 additions & 2 deletions libkd/kdint_etype_f.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef float etype;

#define ETYPE_INTEGER 0

#define ETYPE_MAX KDT_INFTY_FLOAT
#define ETYPE_MIN -KDT_INFTY_FLOAT
#define ETYPE_MAX KDT_LARGEVALF
#define ETYPE_MIN -KDT_LARGEVALF

#define ETYPE f
6 changes: 3 additions & 3 deletions libkd/kdint_ttype_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
typedef double ttype;

#define BIGTTYPE double
#define BIGTTYPE_MAX KDT_INFTY_DOUBLE
#define BIGTTYPE_MAX KDT_LARGEVAL
typedef double bigttype;

#define TTYPE_INTEGER 0

#define TTYPE_MIN -KDT_INFTY_DOUBLE
#define TTYPE_MAX KDT_INFTY_DOUBLE
#define TTYPE_MIN -KDT_LARGEVAL
#define TTYPE_MAX KDT_LARGEVAL
#define TTYPE_SQRT_MAX 1e154

#define TTYPE d
Expand Down
6 changes: 3 additions & 3 deletions libkd/kdint_ttype_f.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
typedef float ttype;

#define BIGTTYPE float
#define BIGTTYPE_MAX KDT_INFTY_FLOAT
#define BIGTTYPE_MAX KDT_LARGEVALF
typedef float bigttype;

#define TTYPE_INTEGER 0

#define TTYPE_MIN -KDT_INFTY_FLOAT
#define TTYPE_MAX KDT_INFTY_FLOAT
#define TTYPE_MIN -KDT_LARGEVALF
#define TTYPE_MAX KDT_LARGEVALF
#define TTYPE_SQRT_MAX 1e19

#define TTYPE f
Expand Down
11 changes: 6 additions & 5 deletions libkd/kdtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "an-fls.h"
#include "errors.h"
#include "log.h"
#include "mathutil.h"

kdtree_t* kdtree_build(kdtree_t* kd, void *data, int N, int D, int Nleaf,
int treetype, unsigned int options) {
Expand Down Expand Up @@ -565,7 +566,7 @@ void kdtree_free(kdtree_t *kd) {
}

int kdtree_nearest_neighbour(const kdtree_t* kd, const void* pt, double* p_mindist2) {
return kdtree_nearest_neighbour_within(kd, pt, HUGE_VAL, p_mindist2);
return kdtree_nearest_neighbour_within(kd, pt, LARGE_VAL, p_mindist2);
}

int kdtree_check(const kdtree_t* kd) {
Expand All @@ -590,7 +591,7 @@ KD_DECLARE(kdtree_node_node_mindist2, double, (const kdtree_t* kd1, int node1, c

double kdtree_node_node_mindist2(const kdtree_t* kd1, int node1,
const kdtree_t* kd2, int node2) {
double res = HUGE_VAL;
double res = LARGE_VAL;
KD_DISPATCH(kdtree_node_node_mindist2, kd1->treetype, res=, (kd1, node1, kd2, node2));
return res;
}
Expand All @@ -599,7 +600,7 @@ KD_DECLARE(kdtree_node_node_maxdist2, double, (const kdtree_t* kd1, int node1, c

double kdtree_node_node_maxdist2(const kdtree_t* kd1, int node1,
const kdtree_t* kd2, int node2) {
double res = HUGE_VAL;
double res = LARGE_VAL;
KD_DISPATCH(kdtree_node_node_maxdist2, kd1->treetype, res=, (kd1, node1, kd2, node2));
return res;
}
Expand Down Expand Up @@ -627,15 +628,15 @@ int kdtree_node_node_maxdist2_exceeds(const kdtree_t* kd1, int node1,
KD_DECLARE(kdtree_node_point_mindist2, double, (const kdtree_t* kd, int node, const void* query));

double kdtree_node_point_mindist2(const kdtree_t* kd, int node, const void* pt) {
double res = HUGE_VAL;
double res = LARGE_VAL;
KD_DISPATCH(kdtree_node_point_mindist2, kd->treetype, res=, (kd, node, pt));
return res;
}

KD_DECLARE(kdtree_node_point_maxdist2, double, (const kdtree_t* kd, int node, const void* query));

double kdtree_node_point_maxdist2(const kdtree_t* kd, int node, const void* pt) {
double res = HUGE_VAL;
double res = LARGE_VAL;
KD_DISPATCH(kdtree_node_point_maxdist2, kd->treetype, res=, (kd, node, pt));
return res;
}
Expand Down
13 changes: 7 additions & 6 deletions libkd/kdtree_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "kdtree_mem.h"
#include "keywords.h"
#include "errors.h"
#include "mathutil.h"

#define KDTREE_MAX_RESULTS 1000
#define KDTREE_MAX_DIM 100
Expand Down Expand Up @@ -659,7 +660,7 @@ static void kdtree_nn_bb(const kdtree_t* kd, const etype* query,
continue;
}

childd2[0] = childd2[1] = HUGE_VAL;
childd2[0] = childd2[1] = LARGE_VAL;
for (child=0; child<2; child++) {
anbool bailed;
double dist2;
Expand Down Expand Up @@ -728,11 +729,11 @@ static void kdtree_nn_bb(const kdtree_t* kd, const etype* query,
secondid = KD_CHILD_LEFT(nodeid);
}

if (firstd2 == HUGE_VAL)
if (firstd2 == LARGE_VAL)
continue;

// it's a stack, so put the "second" one on first.
if (secondd2 != HUGE_VAL) {
if (secondd2 != LARGE_VAL) {
stackpos++;
nodestack[stackpos] = secondid;
dist2stack[stackpos] = secondd2;
Expand Down Expand Up @@ -1215,7 +1216,7 @@ kdtree_qres_t* MANGLE(kdtree_rangesearch_options)
// HACK - should do "use_dtype", just like "use_ttype".
if (dist2_exceeds(kd, query, data, D, maxd2))
continue;
if (!add_result(kd, res, HUGE_VAL, KD_PERM(kd, i), data,
if (!add_result(kd, res, LARGE_VAL, KD_PERM(kd, i), data,
D, do_dists, do_points))
return NULL;
}
Expand Down Expand Up @@ -1309,7 +1310,7 @@ kdtree_qres_t* MANGLE(kdtree_rangesearch_options)
}
} else {
for (i=L; i<=R; i++)
if (!add_result(kd, res, HUGE_VAL, KD_PERM(kd, i),
if (!add_result(kd, res, LARGE_VAL, KD_PERM(kd, i),
KD_DATA(kd, D, i), D,
do_dists, do_points))
return NULL;
Expand Down Expand Up @@ -2531,7 +2532,7 @@ double MANGLE(kdtree_node_point_mindist2)
double d2 = 0.0;
if (!bboxes(kd, node, &tlo, &thi, D)) {
ERROR("Error: kdtree does not have bounding boxes!");
return HUGE_VAL;
return LARGE_VAL;
}
for (d=0; d<D; d++) {
etype delta;
Expand Down
3 changes: 2 additions & 1 deletion libkd/pyspherematch.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "dualtree_rangesearch.h"
#include "dualtree_nearestneighbour.h"
#include "bl.h"
#include "mathutil.h"

typedef struct {
PyObject_HEAD
Expand Down Expand Up @@ -734,7 +735,7 @@ static PyObject* spherematch_nn(PyObject* self, PyObject* args) {

for (i=0; i<NY; i++) {
pinds[i] = -1;
pdist2s[i] = HUGE_VAL;
pdist2s[i] = LARGE_VAL;
}
// and apply kd2's permutation array!
for (i=0; i<NY; i++) {
Expand Down
2 changes: 1 addition & 1 deletion libkd/test_libkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static void run_test_nn(CuTest* tc, int treetype, int treeopts,

ind = kdtree_nearest_neighbour(kd, query, &d2);

trued2 = HUGE_VAL;
trued2 = LARGE_VAL;
trueind = -1;
for (i=0; i<N; i++) {
double d2 = distsq(query, origdata + i*D, D);
Expand Down
8 changes: 4 additions & 4 deletions plot/plotimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ static unsigned char* read_fits_image(const plot_args_t* pargs, plotimage_t* arg
}
{
// DEBUG
double plo = HUGE_VAL;
double phi = -HUGE_VAL;
double plo = LARGE_VAL;
double phi = -LARGE_VAL;
int i;
for (i=0; i<(pargs->W * pargs->H); i++) {
plo = MIN(plo, rimg[i]);
Expand Down Expand Up @@ -367,8 +367,8 @@ unsigned char* plot_image_scale_float(plotimage_t* args, const float* fimg) {
if (args->auto_scale) {
// min/max, or percentiles?
/*
double mn = HUGE_VAL;
double mx = -HUGE_VAL;
double mn = LARGE_VAL;
double mx = -LARGE_VAL;
for (i=0; i<(args->W*args->H); i++) {
mn = MIN(mn, fimg[i]);
mx = MAX(mx, fimg[i]);
Expand Down
10 changes: 6 additions & 4 deletions qfits-an/qfits_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

#define ELEMENT_MAX_DISPLAY_SIZE 50

#define LARGE_VALF 1e30f

/*-----------------------------------------------------------------------------
Function prototypes
-----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -565,17 +567,17 @@ qfits_table * qfits_table_open2(const qfits_header* hdr, off_t offset_beg, size_
/* zero <-> TZERO */
sprintf(keyword, "TZERO%d", i+1);
zero_present = 1;
zero = qfits_header_getdouble(hdr, keyword, HUGE_VAL);
if (zero == HUGE_VAL) {
zero = qfits_header_getdouble(hdr, keyword, LARGE_VALF);
if (zero == LARGE_VALF) {
zero = 0.0;
zero_present = 0;
}

/* scale <-> TSCAL */
sprintf(keyword, "TSCAL%d", i+1);
scale_present = 1;
scale = qfits_header_getdouble(hdr, keyword, HUGE_VAL);
if (scale == HUGE_VAL) {
scale = qfits_header_getdouble(hdr, keyword, LARGE_VALF);
if (scale == LARGE_VALF) {
scale = 1.0;
scale_present = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion solver/agreeable.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
int fieldfile;
int totalsolved, totalunsolved;
int mode = MODE_BEST;
double logodds_tosolve = -HUGE_VAL;
double logodds_tosolve = -LARGE_VAL;
anbool agree = FALSE;

MatchObj* bestmo;
Expand Down
Loading

0 comments on commit c26551f

Please sign in to comment.