Use cmath instead of math.h for fabs (#1217)

* Use cmath instead of math.h so qualify some fabs calls with std:: due to change.

* Remove accidental text
This commit is contained in:
Scott McKay 2019-06-13 10:58:49 +10:00 committed by GitHub
parent c1a34a8ba6
commit fa2eea7339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -2,9 +2,9 @@
// Licensed under the MIT License.
#include "core/providers/cpu/tensor/upsample.h"
#include <math.h> //for fabs
#include <cmath>
using namespace ::onnxruntime::common;
using namespace onnxruntime::common;
using namespace std;
namespace onnxruntime {
@ -185,8 +185,8 @@ void upsampleBilinear(
float in_y = std::min(y / height_scale, static_cast<float>(input_height - 1));
const int64_t in_y1 = std::min(static_cast<int64_t>(in_y), input_height - 1);
const int64_t in_y2 = std::min(in_y1 + 1, input_height - 1);
dy1[y] = fabs(in_y - in_y1);
dy2[y] = fabs(in_y - in_y2);
dy1[y] = std::fabs(in_y - in_y1);
dy2[y] = std::fabs(in_y - in_y2);
if (in_y1 == in_y2) {
dy1[y] = 0.5f;
dy2[y] = 0.5f;

View file

@ -2,7 +2,7 @@
// Licensed under the MIT License.
#include <typeinfo>
#include <math.h> //for fabs
#include <cmath>
#include "core/framework/data_types.h"
#include "core/graph/onnx_protobuf.h"
@ -359,7 +359,7 @@ TEST_F(DataTypeTest, BFloat16Test) {
BFloat16 flt16(sample);
auto int_rep = flt16.val;
BFloat16 flt_from_int(int_rep);
const double diff = fabs(sample - flt_from_int.ToFloat());
const double diff = std::fabs(sample - flt_from_int.ToFloat());
if (diff > FLT_EPSILON || (std::isnan(diff) && !std::isnan(sample))) {
EXPECT_TRUE(false);
}
@ -371,7 +371,7 @@ TEST_F(DataTypeTest, BFloat16Test) {
static_assert(sizeof(sample) / sizeof(float) == sizeof(converted) / sizeof(BFloat16), "Must have the same count");
FloatToBFloat16(sample, converted, sizeof(sample) / sizeof(float));
for (size_t i = 0; i < sizeof(sample) / sizeof(float); ++i) {
const double diff = fabs(sample[i] - converted[i].ToFloat());
const double diff = std::fabs(sample[i] - converted[i].ToFloat());
if (diff > FLT_EPSILON || (std::isnan(diff) && !std::isnan(sample[i]))) {
EXPECT_TRUE(false);
}
@ -380,7 +380,7 @@ TEST_F(DataTypeTest, BFloat16Test) {
float back_converted[sizeof(sample) / sizeof(float)];
BFloat16ToFloat(converted, back_converted, sizeof(sample) / sizeof(float));
for (size_t i = 0; i < sizeof(sample) / sizeof(float); ++i) {
const double diff = fabs(sample[i] - back_converted[i]);
const double diff = std::fabs(sample[i] - back_converted[i]);
if (diff > FLT_EPSILON || (std::isnan(diff) && !std::isnan(sample[i]))) {
EXPECT_TRUE(false);
}