FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use cpp numericlimits helper fns instead of C macros · arrayfire/arrayfire@126e878 · GitHub

Repository navigation

Commit 126e878

Browse files
committed
Use cpp numericlimits helper fns instead of C macros
1 parent 82abee9 commit 126e878

5 files changed

Lines changed: 26 additions & 16 deletions

File tree

‎src/backend/cpu/homography.cpp‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <af/dim4.hpp>
1717

1818
#include <array>
19-
#include <cfloat>
2019
#include <cmath>
2120
#include <cstring>
21+
#include <limits>
2222
#include <vector>
2323

2424
using af::dim4;
@@ -27,6 +27,7 @@ using std::array;
2727
using std::log;
2828
using std::max;
2929
using std::min;
30+
using std::numeric_limits;
3031
using std::pow;
3132
using std::round;
3233
using std::sqrt;
@@ -47,17 +48,17 @@ static const float LMEDSOutlierRatio = 0.4f;
4748

4849
template<typename T>
4950
struct EPS {
50-
T eps() { return FLT_EPSILON; }
51+
T eps() { return numeric_limits<float>::epsilon(); }
5152
};
5253

5354
template<>
5455
struct EPS<float> {
55-
static float eps() { return FLT_EPSILON; }
56+
static float eps() { return numeric_limits<float>::epsilon(); }
5657
};
5758

5859
template<>
5960
struct EPS<double> {
60-
static double eps() { return DBL_EPSILON; }
61+
static double eps() { return numeric_limits<double>::epsilon(); }
6162
};
6263

6364
template<typename T, int M, int N>
@@ -138,7 +139,7 @@ unsigned updateIterations(float inlier_ratio, unsigned iter) {
138139
float wn = pow(1 - w, 4.f);
139140

140141
float d = 1.f - wn;
141-
if (d < FLT_MIN) { return 0; }
142+
if (d < numeric_limits<float>::min()) { return 0; }
142143

143144
d = log(d);
144145

@@ -284,7 +285,7 @@ int findBestHomography(Array<T>& bestH, const Array<float>& x_src,
284285
unsigned iter = iterations;
285286
unsigned bestIdx = 0;
286287
int bestInliers = 0;
287-
float minMedian = FLT_MAX;
288+
float minMedian = numeric_limits<float>::max();
288289

289290
for (unsigned i = 0; i < iter; i++) {
290291
const unsigned Hidx = Hdims[0] * i;
@@ -344,7 +345,8 @@ int findBestHomography(Array<T>& bestH, const Array<float>& x_src,
344345
median = (median + err[nsamples / 2 - 1]) * 0.5f;
345346
}
346347

347-
if (median < minMedian && median > FLT_EPSILON) {
348+
if (median < minMedian &&
349+
median > numeric_limits<float>::epsilon()) {
348350
minMedian = median;
349351
bestIdx = i;
350352
}

‎src/backend/cpu/kernel/sift.hpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <resize.hpp>
2121
#include <sort_index.hpp>
2222

23-
#include <cfloat>
2423
#include <cstring>
24+
#include <limits>
2525
#include <vector>
2626

2727
using af::dim4;
@@ -330,8 +330,9 @@ void interpolateExtrema(float* x_out, float* y_out, unsigned* layer_out,
330330
float det = dxx * dyy - dxy * dxy;
331331

332332
// add FLT_EPSILON for double-precision compatibility
333-
if (det <= 0 || tr * tr * edge_thr >=
334-
(edge_thr + 1) * (edge_thr + 1) * det + FLT_EPSILON)
333+
if (det <= 0 ||
334+
tr * tr * edge_thr >= (edge_thr + 1) * (edge_thr + 1) * det +
335+
std::numeric_limits<float>::epsilon())
335336
continue;
336337

337338
if (*counter < max_feat) {
@@ -692,7 +693,7 @@ void computeGLOHDescriptor(float* desc_out, const unsigned desc_len,
692693
(float)(GLOHRadii[1] - GLOHRadii[0])
693694
: min(2 + (r - GLOHRadii[1]) /
694695
(float)(GLOHRadii[2] - GLOHRadii[1]),
695-
3.f - FLT_EPSILON));
696+
3.f - std::numeric_limits<float>::epsilon()));
696697

697698
if (r <= GLOHRadii[rb - 1] && y > 0 && y < idims[0] - 1 && x > 0 &&
698699
x < idims[1] - 1) {

‎src/backend/cuda/homography.cu‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <af/dim4.hpp>
1515
#include <algorithm>
1616

17-
#include <cfloat>
17+
#include <limits>
1818

1919
using af::dim4;
2020

@@ -39,7 +39,8 @@ int homography(Array<T> &bestH, const Array<float> &x_src,
3939
iter = ::std::min(
4040
iter, (unsigned)(log(1.f - LMEDSConfidence) /
4141
log(1.f - pow(1.f - LMEDSOutlierRatio, 4.f))));
42-
err = createValueArray<float>(af::dim4(nsamples, iter), FLT_MAX);
42+
err = createValueArray<float>(af::dim4(nsamples, iter),
43+
std::numeric_limits<float>::max());
4344
}
4445

4546
af::dim4 rdims(4, iter);

‎src/backend/opencl/homography.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include <af/dim4.hpp>
1515

1616
#include <algorithm>
17+
#include <limits>
1718

1819
using af::dim4;
20+
using std::numeric_limits;
1921

2022
namespace opencl {
2123

@@ -39,7 +41,8 @@ int homography(Array<T> &bestH, const Array<float> &x_src,
3941
::std::min(iter, static_cast<unsigned>(
4042
log(1.f - LMEDSConfidence) /
4143
log(1.f - pow(1.f - LMEDSOutlierRatio, 4.f))));
42-
err = createValueArray<float>(af::dim4(nsamples, iter), FLT_MAX);
44+
err = createValueArray<float>(af::dim4(nsamples, iter),
45+
numeric_limits<float>::max());
4346
} else {
4447
// Avoid passing "null" cl_mem object to kernels
4548
err = createEmptyArray<float>(af::dim4(1));

‎src/backend/opencl/kernel/homography.hpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <memory.hpp>
2020
#include <af/defines.h>
2121

22+
#include <limits>
2223
#include <string>
2324
#include <vector>
2425

@@ -36,8 +37,10 @@ std::array<Kernel, 5> getHomographyKernels(const af_homography_type htype) {
3637
DefineKeyValue(T, dtype_traits<T>::getName()),
3738
};
3839
options.emplace_back(getTypeBuildDefinition<T>());
39-
options.emplace_back(DefineKeyValue(
40-
EPS, (std::is_same<T, double>::value ? DBL_EPSILON : FLT_EPSILON)));
40+
options.emplace_back(
41+
DefineKeyValue(EPS, (std::is_same<T, double>::value
42+
? std::numeric_limits<double>::epsilon()
43+
: std::numeric_limits<float>::epsilon())));
4144
if (htype == AF_HOMOGRAPHY_RANSAC) {
4245
options.emplace_back(DefineKey(RANSAC));
4346
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL