Cleanup: Use C++ casts, remove redundant casts, use CHECK_OK

PiperOrigin-RevId: 157522142
This commit is contained in:
A. Unique TensorFlower 2017-05-30 15:37:41 -07:00 committed by TensorFlower Gardener
parent e405b0f6b1
commit 346021ab4a
10 changed files with 29 additions and 25 deletions

View File

@ -771,7 +771,7 @@ TEST_F(LiteralUtilTest, F16) {
// TODO - modify if we make the data format machine endianess dependent // TODO - modify if we make the data format machine endianess dependent
auto m1 = LiteralUtil::CreateFromShape(ShapeUtil::MakeShape(F16, {2, 2})); auto m1 = LiteralUtil::CreateFromShape(ShapeUtil::MakeShape(F16, {2, 2}));
Literal* l1 = m1.get(); Literal* l1 = m1.get();
const char* d1 = (const char*)LiteralUtil::InternalData(*l1); const char* d1 = static_cast<const char*>(LiteralUtil::InternalData(*l1));
EXPECT_EQ(d1[0], 0); EXPECT_EQ(d1[0], 0);
EXPECT_EQ(d1[1], 0); EXPECT_EQ(d1[1], 0);
EXPECT_EQ(d1[2], 0); EXPECT_EQ(d1[2], 0);
@ -787,7 +787,7 @@ TEST_F(LiteralUtilTest, F16) {
half h2(2.0f); half h2(2.0f);
auto m2 = LiteralUtil::CreateR2<half>({{h1, h2}, {h2, h1}}); auto m2 = LiteralUtil::CreateR2<half>({{h1, h2}, {h2, h1}});
Literal* l2 = m2.get(); Literal* l2 = m2.get();
const char* d2 = (const char*)LiteralUtil::InternalData(*l2); const char* d2 = static_cast<const char*>(LiteralUtil::InternalData(*l2));
EXPECT_EQ(d2[0], 0); EXPECT_EQ(d2[0], 0);
EXPECT_EQ(d2[1], 0x3C); EXPECT_EQ(d2[1], 0x3C);
EXPECT_EQ(d2[2], 0); EXPECT_EQ(d2[2], 0);

View File

@ -57,8 +57,8 @@ class SingleImageRandomDotStereogramsOp : public OpKernel {
::tensorflow::TensorShapeProto output_image_shape; ::tensorflow::TensorShapeProto output_image_shape;
::tensorflow::TensorShapeProto output_data_window; ::tensorflow::TensorShapeProto output_data_window;
uint8 Cblack = (uint8)0; uint8 Cblack = 0;
uint8 Cwhite = (uint8)255; uint8 Cwhite = 255;
int indexMode = 0; // 0 - truncate XY, 1 - round XY, 2 - Interpolate XY (not int indexMode = 0; // 0 - truncate XY, 1 - round XY, 2 - Interpolate XY (not
// implemented yet, keep default of 0) // implemented yet, keep default of 0)

View File

@ -398,8 +398,8 @@ Status GPUTracerImpl::Start() {
// There can only be one CUPTI subscriber. If we can't create one then // There can only be one CUPTI subscriber. If we can't create one then
// there is another trace in progress (possibly by external code). // there is another trace in progress (possibly by external code).
CUptiResult ret; CUptiResult ret;
ret = cupti_wrapper_->Subscribe(&subscriber_, (CUpti_CallbackFunc)ApiCallback, ret = cupti_wrapper_->Subscribe(
this); &subscriber_, static_cast<CUpti_CallbackFunc>(ApiCallback), this);
if (ret == CUPTI_ERROR_MAX_LIMIT_REACHED) { if (ret == CUPTI_ERROR_MAX_LIMIT_REACHED) {
return errors::Unavailable("CUPTI subcriber limit reached."); return errors::Unavailable("CUPTI subcriber limit reached.");
} else if (ret != CUPTI_SUCCESS) { } else if (ret != CUPTI_SUCCESS) {

View File

@ -112,14 +112,14 @@ class FFTCPU : public FFTBase {
auto device = ctx->eigen_device<CPUDevice>(); auto device = ctx->eigen_device<CPUDevice>();
if (!IsReal()) { if (!IsReal()) {
auto input = ((Tensor)in).flat_inner_dims<complex64, FFTRank + 1>(); auto input = (Tensor(in)).flat_inner_dims<complex64, FFTRank + 1>();
// Compute the FFT using eigen. // Compute the FFT using eigen.
auto output = out->flat_inner_dims<complex64, FFTRank + 1>(); auto output = out->flat_inner_dims<complex64, FFTRank + 1>();
output.device(device) = input.template fft < Eigen::BothParts, output.device(device) = input.template fft < Eigen::BothParts,
Forward ? Eigen::FFT_FORWARD : Eigen::FFT_REVERSE > (axes); Forward ? Eigen::FFT_FORWARD : Eigen::FFT_REVERSE > (axes);
} else { } else {
if (IsForward()) { if (IsForward()) {
auto input = ((Tensor)in).flat_inner_dims<float, FFTRank + 1>(); auto input = (Tensor(in)).flat_inner_dims<float, FFTRank + 1>();
auto output = out->flat_inner_dims<complex64, FFTRank + 1>(); auto output = out->flat_inner_dims<complex64, FFTRank + 1>();
Eigen::DSizes<Eigen::DenseIndex, FFTRank + 1> startIndices; Eigen::DSizes<Eigen::DenseIndex, FFTRank + 1> startIndices;

View File

@ -106,7 +106,7 @@ Status SnappyInputBuffer::Inflate() {
// Output buffer must be large enough to fit the uncompressed block. // Output buffer must be large enough to fit the uncompressed block.
DCHECK_GE(output_buffer_capacity_, uncompressed_length); DCHECK_GE(output_buffer_capacity_, uncompressed_length);
next_out_ = (char*)output_buffer_.get(); next_out_ = output_buffer_.get();
bool status = port::Snappy_Uncompress(next_in_, compressed_block_length, bool status = port::Snappy_Uncompress(next_in_, compressed_block_length,
output_buffer_.get()); output_buffer_.get());

View File

@ -526,8 +526,9 @@ static bool Between(uint64 val, uint64 low, uint64 high) {
bool result = (val >= low) && (val <= high); bool result = (val >= low) && (val <= high);
if (!result) { if (!result) {
fprintf(stderr, "Value %llu is not in range [%llu, %llu]\n", fprintf(stderr, "Value %llu is not in range [%llu, %llu]\n",
(unsigned long long)(val), (unsigned long long)(low), static_cast<unsigned long long>(val),
(unsigned long long)(high)); static_cast<unsigned long long>(low),
static_cast<unsigned long long>(high));
} }
return result; return result;
} }

View File

@ -134,7 +134,9 @@ inline static void AppendBytes(string* dest, const char* src, size_t len) {
dest->append(src, len); dest->append(src, len);
} }
inline bool IsSpecialByte(char c) { return ((unsigned char)(c + 1)) < 2; } inline bool IsSpecialByte(char c) {
return (static_cast<unsigned char>(c + 1)) < 2;
}
// Return a pointer to the first byte in the range "[start..limit)" // Return a pointer to the first byte in the range "[start..limit)"
// whose value is 0 or 255 (kEscape1 or kEscape2). If no such byte // whose value is 0 or 255 (kEscape1 or kEscape2). If no such byte
@ -201,7 +203,7 @@ void OrderedCode::WriteNumIncreasing(string* dest, uint64 val) {
buf[9 - len] = (val & 0xff); buf[9 - len] = (val & 0xff);
val >>= 8; val >>= 8;
} }
buf[9 - len - 1] = (unsigned char)len; buf[9 - len - 1] = len;
len++; len++;
AppendBytes(dest, reinterpret_cast<const char*>(buf + 9 - len), len); AppendBytes(dest, reinterpret_cast<const char*>(buf + 9 - len), len);
} }

View File

@ -156,7 +156,7 @@ void MakeCheckOpValueString(std::ostream* os, const char& v) {
if (v >= 32 && v <= 126) { if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'"; (*os) << "'" << v << "'";
} else { } else {
(*os) << "char value " << (short)v; (*os) << "char value " << static_cast<short>(v);
} }
} }
@ -165,7 +165,7 @@ void MakeCheckOpValueString(std::ostream* os, const signed char& v) {
if (v >= 32 && v <= 126) { if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'"; (*os) << "'" << v << "'";
} else { } else {
(*os) << "signed char value " << (short)v; (*os) << "signed char value " << static_cast<short>(v);
} }
} }
@ -174,7 +174,7 @@ void MakeCheckOpValueString(std::ostream* os, const unsigned char& v) {
if (v >= 32 && v <= 126) { if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'"; (*os) << "'" << v << "'";
} else { } else {
(*os) << "unsigned char value " << (unsigned short)v; (*os) << "unsigned char value " << static_cast<unsigned short>(v);
} }
} }

View File

@ -57,15 +57,16 @@ bool IsPortAvailable(int* port, bool is_tcp) {
// Try binding to port. // Try binding to port.
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY; addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons((uint16_t)*port); addr.sin_port = htons(static_cast<uint16_t>(*port));
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { if (bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) < 0) {
LOG(WARNING) << "bind(port=" << *port << ") failed: " << strerror(errno); LOG(WARNING) << "bind(port=" << *port << ") failed: " << strerror(errno);
close(fd); close(fd);
return false; return false;
} }
// Get the bound port number. // Get the bound port number.
if (getsockname(fd, (struct sockaddr*)&addr, &addr_len) < 0) { if (getsockname(fd, reinterpret_cast<struct sockaddr*>(&addr), &addr_len) <
0) {
LOG(WARNING) << "getsockname() failed: " << strerror(errno); LOG(WARNING) << "getsockname() failed: " << strerror(errno);
close(fd); close(fd);
return false; return false;

View File

@ -39,9 +39,9 @@ static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU); // nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);
// nB = (int)(1.164 * nY + 1.596 * nV); // nB = (int)(1.164 * nY + 1.596 * nV);
int nR = (int)(1192 * nY + 1634 * nV); int nR = 1192 * nY + 1634 * nV;
int nG = (int)(1192 * nY - 833 * nV - 400 * nU); int nG = 1192 * nY - 833 * nV - 400 * nU;
int nB = (int)(1192 * nY + 2066 * nU); int nB = 1192 * nY + 2066 * nU;
nR = MIN(kMaxChannelValue, MAX(0, nR)); nR = MIN(kMaxChannelValue, MAX(0, nR));
nG = MIN(kMaxChannelValue, MAX(0, nG)); nG = MIN(kMaxChannelValue, MAX(0, nG));
@ -171,9 +171,9 @@ void ConvertYUV420SPToRGB565(const uint8_t* const input, uint16_t* const output,
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU); // nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);
// nB = (int)(1.164 * nY + 1.596 * nV); // nB = (int)(1.164 * nY + 1.596 * nV);
int nR = (int)(1192 * nY + 1634 * nV); int nR = 1192 * nY + 1634 * nV;
int nG = (int)(1192 * nY - 833 * nV - 400 * nU); int nG = 1192 * nY - 833 * nV - 400 * nU;
int nB = (int)(1192 * nY + 2066 * nU); int nB = 1192 * nY + 2066 * nU;
nR = MIN(kMaxChannelValue, MAX(0, nR)); nR = MIN(kMaxChannelValue, MAX(0, nR));
nG = MIN(kMaxChannelValue, MAX(0, nG)); nG = MIN(kMaxChannelValue, MAX(0, nG));