Internal change

PiperOrigin-RevId: 521949598
This commit is contained in:
MediaPipe Team 2023-04-04 21:32:34 -07:00 committed by Copybara-Service
parent 7cb8c647ca
commit 1990fe00d3
3 changed files with 114 additions and 114 deletions

View File

@ -75,17 +75,17 @@ BENCHMARK(BM_IntCast);
static void BM_Int64Cast(benchmark::State& state) {
double x = 0.1;
int64 sum = 0;
int64_t sum = 0;
for (auto _ : state) {
sum += static_cast<int64>(x);
sum += static_cast<int64_t>(x);
x += 0.1;
sum += static_cast<int64>(x);
sum += static_cast<int64_t>(x);
x += 0.1;
sum += static_cast<int64>(x);
sum += static_cast<int64_t>(x);
x += 0.1;
sum += static_cast<int64>(x);
sum += static_cast<int64_t>(x);
x += 0.1;
sum += static_cast<int64>(x);
sum += static_cast<int64_t>(x);
x += 0.1;
}
EXPECT_NE(sum, 0); // Don't let 'sum' get optimized away.
@ -134,15 +134,15 @@ static void BM_Int64Round(benchmark::State& state) {
double x = 0.1;
int sum = 0;
for (auto _ : state) {
sum += mediapipe::MathUtil::Round<int64>(x);
sum += mediapipe::MathUtil::Round<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<int64>(x);
sum += mediapipe::MathUtil::Round<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<int64>(x);
sum += mediapipe::MathUtil::Round<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<int64>(x);
sum += mediapipe::MathUtil::Round<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<int64>(x);
sum += mediapipe::MathUtil::Round<int64_t>(x);
x += 0.1;
}
EXPECT_NE(sum, 0); // Don't let 'sum' get optimized away.
@ -153,15 +153,15 @@ static void BM_UintRound(benchmark::State& state) {
double x = 0.1;
int sum = 0;
for (auto _ : state) {
sum += mediapipe::MathUtil::Round<uint32>(x);
sum += mediapipe::MathUtil::Round<uint32_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<uint32>(x);
sum += mediapipe::MathUtil::Round<uint32_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<uint32>(x);
sum += mediapipe::MathUtil::Round<uint32_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<uint32>(x);
sum += mediapipe::MathUtil::Round<uint32_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::Round<uint32>(x);
sum += mediapipe::MathUtil::Round<uint32_t>(x);
x += 0.1;
}
EXPECT_NE(sum, 0); // Don't let 'sum' get optimized away.
@ -191,15 +191,15 @@ static void BM_SafeInt64Cast(benchmark::State& state) {
double x = 0.1;
int sum = 0;
for (auto _ : state) {
sum += mediapipe::MathUtil::SafeCast<int64>(x);
sum += mediapipe::MathUtil::SafeCast<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeCast<int64>(x);
sum += mediapipe::MathUtil::SafeCast<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeCast<int64>(x);
sum += mediapipe::MathUtil::SafeCast<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeCast<int64>(x);
sum += mediapipe::MathUtil::SafeCast<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeCast<int64>(x);
sum += mediapipe::MathUtil::SafeCast<int64_t>(x);
x += 0.1;
}
EXPECT_NE(sum, 0); // Don't let 'sum' get optimized away.
@ -229,15 +229,15 @@ static void BM_SafeInt64Round(benchmark::State& state) {
double x = 0.1;
int sum = 0;
for (auto _ : state) {
sum += mediapipe::MathUtil::SafeRound<int64>(x);
sum += mediapipe::MathUtil::SafeRound<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeRound<int64>(x);
sum += mediapipe::MathUtil::SafeRound<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeRound<int64>(x);
sum += mediapipe::MathUtil::SafeRound<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeRound<int64>(x);
sum += mediapipe::MathUtil::SafeRound<int64_t>(x);
x += 0.1;
sum += mediapipe::MathUtil::SafeRound<int64>(x);
sum += mediapipe::MathUtil::SafeRound<int64_t>(x);
x += 0.1;
}
EXPECT_NE(sum, 0); // Don't let 'sum' get optimized away.
@ -262,8 +262,8 @@ TEST(MathUtil, IntRound) {
// A double-precision number has a 53-bit mantissa (52 fraction bits),
// so the following value can be represented exactly.
int64 value64 = static_cast<int64_t>(0x1234567890abcd00);
EXPECT_EQ(mediapipe::MathUtil::Round<int64>(static_cast<double>(value64)),
int64_t value64 = static_cast<int64_t>(0x1234567890abcd00);
EXPECT_EQ(mediapipe::MathUtil::Round<int64_t>(static_cast<double>(value64)),
value64);
}
@ -369,7 +369,7 @@ class SafeCastTester {
if (sizeof(FloatIn) >= 64) {
// A double-precision number has a 53-bit mantissa (52 fraction bits),
// so the following value can be represented exactly by a double.
int64 value64 = static_cast<int64_t>(0x1234567890abcd00);
int64_t value64 = static_cast<int64_t>(0x1234567890abcd00);
const IntOut expected =
(sizeof(IntOut) >= 64) ? static_cast<IntOut>(value64) : imax;
EXPECT_EQ(
@ -536,22 +536,22 @@ class SafeCastTester {
};
TEST(MathUtil, SafeCast) {
SafeCastTester<float, int8>::Run();
SafeCastTester<double, int8>::Run();
SafeCastTester<float, int16>::Run();
SafeCastTester<double, int16>::Run();
SafeCastTester<float, int32>::Run();
SafeCastTester<double, int32>::Run();
SafeCastTester<float, int64>::Run();
SafeCastTester<double, int64>::Run();
SafeCastTester<float, uint8>::Run();
SafeCastTester<double, uint8>::Run();
SafeCastTester<float, uint16>::Run();
SafeCastTester<double, uint16>::Run();
SafeCastTester<float, uint32>::Run();
SafeCastTester<double, uint32>::Run();
SafeCastTester<float, uint64>::Run();
SafeCastTester<double, uint64>::Run();
SafeCastTester<float, int8_t>::Run();
SafeCastTester<double, int8_t>::Run();
SafeCastTester<float, int16_t>::Run();
SafeCastTester<double, int16_t>::Run();
SafeCastTester<float, int32_t>::Run();
SafeCastTester<double, int32_t>::Run();
SafeCastTester<float, int64_t>::Run();
SafeCastTester<double, int64_t>::Run();
SafeCastTester<float, uint8_t>::Run();
SafeCastTester<double, uint8_t>::Run();
SafeCastTester<float, uint16_t>::Run();
SafeCastTester<double, uint16_t>::Run();
SafeCastTester<float, uint32_t>::Run();
SafeCastTester<double, uint32_t>::Run();
SafeCastTester<float, uint64_t>::Run();
SafeCastTester<double, uint64_t>::Run();
// Spot-check SafeCast<int>
EXPECT_EQ(mediapipe::MathUtil::SafeCast<int>(static_cast<float>(12345.678)),
@ -682,7 +682,7 @@ class SafeRoundTester {
if (sizeof(FloatIn) >= 64) {
// A double-precision number has a 53-bit mantissa (52 fraction bits),
// so the following value can be represented exactly by a double.
int64 value64 = static_cast<int64_t>(0x1234567890abcd00);
int64_t value64 = static_cast<int64_t>(0x1234567890abcd00);
const IntOut expected =
(sizeof(IntOut) >= 64) ? static_cast<IntOut>(value64) : imax;
EXPECT_EQ(
@ -843,22 +843,22 @@ class SafeRoundTester {
};
TEST(MathUtil, SafeRound) {
SafeRoundTester<float, int8>::Run();
SafeRoundTester<double, int8>::Run();
SafeRoundTester<float, int16>::Run();
SafeRoundTester<double, int16>::Run();
SafeRoundTester<float, int32>::Run();
SafeRoundTester<double, int32>::Run();
SafeRoundTester<float, int64>::Run();
SafeRoundTester<double, int64>::Run();
SafeRoundTester<float, uint8>::Run();
SafeRoundTester<double, uint8>::Run();
SafeRoundTester<float, uint16>::Run();
SafeRoundTester<double, uint16>::Run();
SafeRoundTester<float, uint32>::Run();
SafeRoundTester<double, uint32>::Run();
SafeRoundTester<float, uint64>::Run();
SafeRoundTester<double, uint64>::Run();
SafeRoundTester<float, int8_t>::Run();
SafeRoundTester<double, int8_t>::Run();
SafeRoundTester<float, int16_t>::Run();
SafeRoundTester<double, int16_t>::Run();
SafeRoundTester<float, int32_t>::Run();
SafeRoundTester<double, int32_t>::Run();
SafeRoundTester<float, int64_t>::Run();
SafeRoundTester<double, int64_t>::Run();
SafeRoundTester<float, uint8_t>::Run();
SafeRoundTester<double, uint8_t>::Run();
SafeRoundTester<float, uint16_t>::Run();
SafeRoundTester<double, uint16_t>::Run();
SafeRoundTester<float, uint32_t>::Run();
SafeRoundTester<double, uint32_t>::Run();
SafeRoundTester<float, uint64_t>::Run();
SafeRoundTester<double, uint64_t>::Run();
// Spot-check SafeRound<int>
EXPECT_EQ(mediapipe::MathUtil::SafeRound<int>(static_cast<float>(12345.678)),

View File

@ -244,7 +244,7 @@ TEST_F(MonotonicClockTest, RealTime) {
// Call mono_clock->Now() continuously for FLAGS_real_test_secs seconds.
absl::Time start = absl::Now();
absl::Time time = start;
int64 num_calls = 0;
int64_t num_calls = 0;
do {
absl::Time last_time = time;
time = mono_clock->TimeNow();
@ -406,7 +406,7 @@ class ClockFrenzy {
while (Running()) {
// 40% of the time, advance a simulated clock.
// 50% of the time, read a monotonic clock.
const int32 u = UniformRandom(100);
const int32_t u = UniformRandom(100);
if (u < 40) {
// Pick a simulated clock and advance it.
const int nclocks = sim_clocks_.size();
@ -463,9 +463,9 @@ class ClockFrenzy {
// Thread-safe random number generation functions for use by other class
// member functions.
int32 UniformRandom(int32 n) {
int32_t UniformRandom(int32_t n) {
absl::MutexLock l(&lock_);
return std::uniform_int_distribution<int32>(0, n - 1)(*random_);
return std::uniform_int_distribution<int32_t>(0, n - 1)(*random_);
}
float RndFloatRandom() {

View File

@ -20,21 +20,21 @@
#include "mediapipe/framework/port/gtest.h"
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt8, int8,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt8, int8_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt8, uint8,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt8, uint8_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt16, int16,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt16, int16_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt16, uint16,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt16, uint16_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt32, int32,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt32, int32_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt64, int64,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeInt64, int64_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt32, uint32,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt32, uint32_t,
mediapipe::intops::LogFatalOnError);
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt64, uint64,
MEDIAPIPE_DEFINE_SAFE_INT_TYPE(SafeUInt64, uint64_t,
mediapipe::intops::LogFatalOnError);
namespace mediapipe {
@ -102,8 +102,8 @@ TYPED_TEST(SignNeutralSafeIntTest, TestCtorFailures) {
typedef typename T::ValueType V;
{ // Test out-of-bounds construction.
if (std::numeric_limits<V>::is_signed || sizeof(V) < sizeof(uint64)) {
EXPECT_DEATH((T(std::numeric_limits<uint64>::max())), "bounds");
if (std::numeric_limits<V>::is_signed || sizeof(V) < sizeof(uint64_t)) {
EXPECT_DEATH((T(std::numeric_limits<uint64_t>::max())), "bounds");
}
}
{ // Test out-of-bounds construction from float.
@ -233,20 +233,20 @@ TYPED_TEST(SignNeutralSafeIntTest, TestMultiply) {
typedef typename T::ValueType V;
// Test positive vs. positive multiplication across types.
TEST_T_OP_NUM(9, *, int32, 3);
TEST_T_OP_NUM(9, *, uint32, 3);
TEST_T_OP_NUM(9, *, int32_t, 3);
TEST_T_OP_NUM(9, *, uint32_t, 3);
TEST_T_OP_NUM(9, *, float, 3);
TEST_T_OP_NUM(9, *, double, 3);
// Test positive vs. zero multiplication commutatively across types. This
// was a real bug.
TEST_T_OP_NUM(93, *, int32, 0);
TEST_T_OP_NUM(93, *, uint32, 0);
TEST_T_OP_NUM(93, *, int32_t, 0);
TEST_T_OP_NUM(93, *, uint32_t, 0);
TEST_T_OP_NUM(93, *, float, 0);
TEST_T_OP_NUM(93, *, double, 0);
TEST_T_OP_NUM(0, *, int32, 76);
TEST_T_OP_NUM(0, *, uint32, 76);
TEST_T_OP_NUM(0, *, int32_t, 76);
TEST_T_OP_NUM(0, *, uint32_t, 76);
TEST_T_OP_NUM(0, *, float, 76);
TEST_T_OP_NUM(0, *, double, 76);
@ -279,14 +279,14 @@ TYPED_TEST(SignNeutralSafeIntTest, TestDivide) {
typedef typename T::ValueType V;
// Test positive vs. positive division across types.
TEST_T_OP_NUM(9, /, int32, 3);
TEST_T_OP_NUM(9, /, uint32, 3);
TEST_T_OP_NUM(9, /, int32_t, 3);
TEST_T_OP_NUM(9, /, uint32_t, 3);
TEST_T_OP_NUM(9, /, float, 3);
TEST_T_OP_NUM(9, /, double, 3);
// Test zero vs. positive division across types.
TEST_T_OP_NUM(0, /, int32, 76);
TEST_T_OP_NUM(0, /, uint32, 76);
TEST_T_OP_NUM(0, /, int32_t, 76);
TEST_T_OP_NUM(0, /, uint32_t, 76);
TEST_T_OP_NUM(0, /, float, 76);
TEST_T_OP_NUM(0, /, double, 76);
}
@ -307,12 +307,12 @@ TYPED_TEST(SignNeutralSafeIntTest, TestModulo) {
typedef typename T::ValueType V;
// Test positive vs. positive modulo across signedness.
TEST_T_OP_NUM(7, %, int32, 6);
TEST_T_OP_NUM(7, %, uint32, 6);
TEST_T_OP_NUM(7, %, int32_t, 6);
TEST_T_OP_NUM(7, %, uint32_t, 6);
// Test zero vs. positive modulo across signedness.
TEST_T_OP_NUM(0, %, int32, 6);
TEST_T_OP_NUM(0, %, uint32, 6);
TEST_T_OP_NUM(0, %, int32_t, 6);
TEST_T_OP_NUM(0, %, uint32_t, 6);
}
TYPED_TEST(SignNeutralSafeIntTest, TestModuloFailures) {
@ -534,28 +534,28 @@ TYPED_TEST(SignedSafeIntTest, TestMultiply) {
typedef typename T::ValueType V;
// Test negative vs. positive multiplication across types.
TEST_T_OP_NUM(-9, *, int32, 3);
TEST_T_OP_NUM(-9, *, uint32, 3);
TEST_T_OP_NUM(-9, *, int32_t, 3);
TEST_T_OP_NUM(-9, *, uint32_t, 3);
TEST_T_OP_NUM(-9, *, float, 3);
TEST_T_OP_NUM(-9, *, double, 3);
// Test positive vs. negative multiplication across types.
TEST_T_OP_NUM(9, *, int32, -3);
TEST_T_OP_NUM(9, *, int32_t, -3);
// Don't cover unsigneds that are initialized from negative values.
TEST_T_OP_NUM(9, *, float, -3);
TEST_T_OP_NUM(9, *, double, -3);
// Test negative vs. negative multiplication across types.
TEST_T_OP_NUM(-9, *, int32, -3);
TEST_T_OP_NUM(-9, *, int32_t, -3);
// Don't cover unsigneds that are initialized from negative values.
TEST_T_OP_NUM(-9, *, float, -3);
TEST_T_OP_NUM(-9, *, double, -3);
// Test negative vs. zero multiplication commutatively across types.
TEST_T_OP_NUM(-93, *, int32, 0);
TEST_T_OP_NUM(-93, *, uint32, 0);
TEST_T_OP_NUM(-93, *, int32_t, 0);
TEST_T_OP_NUM(-93, *, uint32_t, 0);
TEST_T_OP_NUM(-93, *, float, 0);
TEST_T_OP_NUM(-93, *, double, 0);
TEST_T_OP_NUM(0, *, int32, -76);
TEST_T_OP_NUM(0, *, uint32, -76);
TEST_T_OP_NUM(0, *, int32_t, -76);
TEST_T_OP_NUM(0, *, uint32_t, -76);
TEST_T_OP_NUM(0, *, float, -76);
TEST_T_OP_NUM(0, *, double, -76);
@ -600,24 +600,24 @@ TYPED_TEST(SignedSafeIntTest, TestDivide) {
typedef typename T::ValueType V;
// Test negative vs. positive division across types.
TEST_T_OP_NUM(-9, /, int32, 3);
TEST_T_OP_NUM(-9, /, uint32, 3);
TEST_T_OP_NUM(-9, /, int32_t, 3);
TEST_T_OP_NUM(-9, /, uint32_t, 3);
TEST_T_OP_NUM(-9, /, float, 3);
TEST_T_OP_NUM(-9, /, double, 3);
// Test positive vs. negative division across types.
TEST_T_OP_NUM(9, /, int32, -3);
TEST_T_OP_NUM(9, /, uint32, -3);
TEST_T_OP_NUM(9, /, int32_t, -3);
TEST_T_OP_NUM(9, /, uint32_t, -3);
TEST_T_OP_NUM(9, /, float, -3);
TEST_T_OP_NUM(9, /, double, -3);
// Test negative vs. negative division across types.
TEST_T_OP_NUM(-9, /, int32, -3);
TEST_T_OP_NUM(-9, /, uint32, -3);
TEST_T_OP_NUM(-9, /, int32_t, -3);
TEST_T_OP_NUM(-9, /, uint32_t, -3);
TEST_T_OP_NUM(-9, /, float, -3);
TEST_T_OP_NUM(-9, /, double, -3);
// Test zero vs. negative division across types.
TEST_T_OP_NUM(0, /, int32, -76);
TEST_T_OP_NUM(0, /, uint32, -76);
TEST_T_OP_NUM(0, /, int32_t, -76);
TEST_T_OP_NUM(0, /, uint32_t, -76);
TEST_T_OP_NUM(0, /, float, -76);
TEST_T_OP_NUM(0, /, double, -76);
}
@ -638,18 +638,18 @@ TYPED_TEST(SignedSafeIntTest, TestModulo) {
typedef typename T::ValueType V;
// Test negative vs. positive modulo across signedness.
TEST_T_OP_NUM(-7, %, int32, 6);
TEST_T_OP_NUM(-7, %, uint32, 6);
TEST_T_OP_NUM(-7, %, int32_t, 6);
TEST_T_OP_NUM(-7, %, uint32_t, 6);
// Test positive vs. negative modulo across signedness.
TEST_T_OP_NUM(7, %, int32, -6);
TEST_T_OP_NUM(7, %, uint32, -6);
TEST_T_OP_NUM(7, %, int32_t, -6);
TEST_T_OP_NUM(7, %, uint32_t, -6);
// Test negative vs. negative modulo across signedness.
TEST_T_OP_NUM(-7, %, int32, -6);
TEST_T_OP_NUM(-7, %, uint32, -6);
TEST_T_OP_NUM(-7, %, int32_t, -6);
TEST_T_OP_NUM(-7, %, uint32_t, -6);
// Test zero vs. negative modulo across signedness.
TEST_T_OP_NUM(0, %, int32, -6);
TEST_T_OP_NUM(0, %, uint32, -6);
TEST_T_OP_NUM(0, %, int32_t, -6);
TEST_T_OP_NUM(0, %, uint32_t, -6);
}
TYPED_TEST(SignedSafeIntTest, TestModuloFailures) {