Commit 9b0de809 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added noexcept to square() and distance().

parent 6fc06906
......@@ -99,13 +99,13 @@ void LLtoXYZ(double lon, double lat, double *restrict xyz)
}
static constexpr
double square(const double x)
double square(const double x) noexcept
{
return x*x;
}
static constexpr
double distance(const double *restrict a, const double *restrict b)
double distance(const double *restrict a, const double *restrict b) noexcept
{
return square(a[0]-b[0]) + square(a[1]-b[1]) + square(a[2]-b[2]);
}
......@@ -185,9 +185,10 @@ void *gs_create_kdtree(size_t n, const double *restrict lons, const double *rest
struct kd_point *pointlist = (struct kd_point *) Malloc(n*sizeof(struct kd_point));
// see example_cartesian.c
if ( cdoVerbose ) printf("kdtree lib init 3D: n=%zu nthreads=%d\n", n, ompNumThreads);
kdata_t min[3], max[3];
min[0] = min[1] = min[2] = 1e9;
max[0] = max[1] = max[2] = -1e9;
kdata_t min[3] = { 1.e9, 1.e9, 1.e9};
kdata_t max[3] = {-1.e9, -1.e9, -1.e9};
#ifdef HAVE_OPENMP45
#pragma omp parallel for reduction(min: min[:3]) reduction(max: max[:3])
#endif
......@@ -224,9 +225,9 @@ void *gs_create_nanoflann(size_t n, const double *restrict lons, const double *r
PointCloud<double> *pointcloud = new PointCloud<double>();
if ( cdoVerbose ) printf("nanoflann init 3D: n=%zu nthreads=%d\n", n, ompNumThreads);
double min[3], max[3];
min[0] = min[1] = min[2] = 1e9;
max[0] = max[1] = max[2] = -1e9;
double min[3] = { 1.e9, 1.e9, 1.e9};
double max[3] = {-1.e9, -1.e9, -1.e9};
// Generating Point Cloud
pointcloud->pts.resize(n);
#ifdef HAVE_OPENMP45
......
......@@ -16,13 +16,13 @@
********************************************************************* */
static constexpr
kdata_t square(const kdata_t x)
kdata_t square(const kdata_t x) noexcept
{
return x*x;
}
static constexpr
kdata_t kd_dist_sq(const kdata_t *restrict a, const kdata_t *restrict b)
kdata_t kd_dist_sq(const kdata_t *restrict a, const kdata_t *restrict b) noexcept
{
return (float)(square((a[0]-b[0]))+square((a[1]-b[1]))+square((a[2]-b[2])));
}
......@@ -30,7 +30,7 @@ kdata_t kd_dist_sq(const kdata_t *restrict a, const kdata_t *restrict b)
kdata_t kd_min(kdata_t x, kdata_t y)
{
return x < y ? x : y;
return x < y ? x : y;
}
......
......@@ -111,9 +111,8 @@ size_t nbr_normalize_weights(size_t numNeighbors, double dist_tot, const bool *r
// This routine finds the closest num_neighbor points to a search point and computes a distance to each of the neighbors.
template <typename T>
static inline
void LLtoXYZ(double lon, double lat, T *restrict xyz)
void LLtoXYZ(double lon, double lat, double *restrict xyz)
{
double cos_lat = cos(lat);
xyz[0] = cos_lat * cos(lon);
......@@ -121,16 +120,14 @@ void LLtoXYZ(double lon, double lat, T *restrict xyz)
xyz[2] = sin(lat);
}
template <typename T>
static constexpr
T square(const T x)
double square(const double x) noexcept
{
return x*x;
}
template <typename T>
static constexpr
T distance(const T *restrict a, const T *restrict b)
double distance(const double *restrict a, const double *restrict b) noexcept
{
return square(a[0]-b[0]) + square(a[1]-b[1]) + square(a[2]-b[2]);
}
......@@ -220,7 +217,7 @@ void grid_search_nbr_reg2d(struct gridsearch *gs, size_t numNeighbors, size_t *r
double xyz[3];
double query_pt[3];
LLtoXYZ<double>(plon, plat, query_pt);
LLtoXYZ(plon, plat, query_pt);
double search_radius = SQR(gs->search_radius);
for ( size_t na = 0; na < num_add; ++na )
......@@ -233,7 +230,7 @@ void grid_search_nbr_reg2d(struct gridsearch *gs, size_t numNeighbors, size_t *r
xyz[1] = coslat[iy] * sinlon[ix];
xyz[2] = sinlat[iy];
// Find distance to this point
double dist = (float) distance<double>(query_pt, xyz);
double dist = (float) distance(query_pt, xyz);
if ( dist <= search_radius )
{
// Store the address and distance if this is one of the smallest so far
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment