[-Wsign-compare] warning fixes batch 6
This commit is contained in:
parent
6dbeb8d948
commit
6162dbe55e
@ -441,7 +441,8 @@ REGISTER_OP("XlaReduce")
|
||||
auto dim_in_range = [rank](int64 dim) {
|
||||
return dim >= 0 && dim < rank;
|
||||
};
|
||||
if (rank < dimensions_to_reduce.size() ||
|
||||
const int dimensions_to_reduce_size = dimensions_to_reduce.size();
|
||||
if (rank < dimensions_to_reduce_size ||
|
||||
dims_set.size() != dimensions_to_reduce.size() ||
|
||||
!absl::c_all_of(dimensions_to_reduce, dim_in_range)) {
|
||||
return errors::InvalidArgument(
|
||||
|
@ -62,14 +62,14 @@ InferenceContext::InferenceContext(
|
||||
}
|
||||
std::vector<std::unique_ptr<std::vector<ShapeAndType>>> handle_data(
|
||||
input_shapes.size());
|
||||
for (int i = 0; i < input_handle_shapes_and_types.size(); ++i) {
|
||||
for (int i = 0, iter_limit = input_handle_shapes_and_types.size(); i < iter_limit; ++i) {
|
||||
const auto& v = input_handle_shapes_and_types[i];
|
||||
if (v == nullptr) {
|
||||
continue;
|
||||
}
|
||||
handle_data[i].reset(new std::vector<ShapeAndType>(v->size()));
|
||||
auto& new_v = *handle_data[i];
|
||||
for (int j = 0; j < v->size(); ++j) {
|
||||
for (int j = 0, iter_limit = v->size(); j < iter_limit; ++j) {
|
||||
const auto& p = (*v)[j];
|
||||
construction_status_.Update(
|
||||
MakeShapeFromPartialTensorShape(p.first, &new_v[j].shape));
|
||||
@ -123,7 +123,8 @@ Status InferenceContext::set_output(StringPiece output_name,
|
||||
} else {
|
||||
const int start = result->second.first;
|
||||
const int size = result->second.second - start;
|
||||
if (size != shapes.size()) {
|
||||
const int shapes_size = shapes.size();
|
||||
if (size != shapes_size) {
|
||||
return errors::InvalidArgument("Must have exactly ", shapes.size(),
|
||||
" shapes.");
|
||||
}
|
||||
@ -181,7 +182,8 @@ void InferenceContext::PreInputInit(
|
||||
}
|
||||
|
||||
Status InferenceContext::ExpandOutputs(int new_output_size) {
|
||||
if (new_output_size < outputs_.size()) {
|
||||
int outputs_size_ = outputs_.size();
|
||||
if (new_output_size < outputs_size_) {
|
||||
return errors::InvalidArgument("Trying to reduce number of outputs of op.");
|
||||
}
|
||||
outputs_.resize(new_output_size, nullptr);
|
||||
@ -209,8 +211,8 @@ void InferenceContext::PostInputInit(
|
||||
}
|
||||
input_handle_shapes_and_types_ = std::move(input_handle_data);
|
||||
}
|
||||
|
||||
if (inputs_.size() != num_inputs_from_node_def) {
|
||||
int inputs_size_ = inputs_.size();
|
||||
if (inputs_size_ != num_inputs_from_node_def) {
|
||||
construction_status_ = errors::InvalidArgument(
|
||||
"Wrong number of inputs passed: ", inputs_.size(), " while ",
|
||||
num_inputs_from_node_def, " expected based on NodeDef");
|
||||
@ -718,7 +720,8 @@ Status InferenceContext::MakeShapeFromShapeTensorTreatScalarAsUnknownShape(
|
||||
TF_RETURN_IF_ERROR(WithRankAtMost(input(input_idx), 1, &input_shape));
|
||||
|
||||
requested_input_tensor_as_partial_shape_[input_idx] = true;
|
||||
if (input_idx < input_tensors_as_shapes_.size() &&
|
||||
int input_tensors_as_shapes_size_ = input_tensors_as_shapes_.size();
|
||||
if (input_idx < input_tensors_as_shapes_size_ &&
|
||||
input_tensors_as_shapes_[input_idx].IsSet() &&
|
||||
RankKnown(input_tensors_as_shapes_[input_idx])) {
|
||||
*out = input_tensors_as_shapes_[input_idx];
|
||||
@ -736,7 +739,8 @@ Status InferenceContext::MakeShapeFromShapeTensor(int input_idx,
|
||||
TF_RETURN_IF_ERROR(WithRank(input(input_idx), 1, &input_shape));
|
||||
|
||||
requested_input_tensor_as_partial_shape_[input_idx] = true;
|
||||
if (input_idx < input_tensors_as_shapes_.size() &&
|
||||
int input_tensors_as_shapes_size_ = input_tensors_as_shapes_.size();
|
||||
if (input_idx < input_tensors_as_shapes_size_ &&
|
||||
input_tensors_as_shapes_[input_idx].IsSet() &&
|
||||
RankKnown(input_tensors_as_shapes_[input_idx])) {
|
||||
*out = input_tensors_as_shapes_[input_idx];
|
||||
@ -1099,14 +1103,16 @@ Status InferenceContext::AttachContext(const Status& status) {
|
||||
std::vector<string> input_from_tensors_str;
|
||||
std::vector<string> input_from_tensors_as_shape_str;
|
||||
input_from_tensors_as_shape_str.reserve(inputs_.size());
|
||||
for (int i = 0; i < inputs_.size(); ++i) {
|
||||
for (int i = 0, iter_limit = inputs_.size(); i < iter_limit; ++i) {
|
||||
int input_tensors_size_ = input_tensors_.size();
|
||||
int input_tensors_as_shapes_size_ = input_tensors_as_shapes_.size();
|
||||
if (requested_input_tensor_as_partial_shape_[i] &&
|
||||
i < input_tensors_as_shapes_.size() &&
|
||||
i < input_tensors_as_shapes_size_ &&
|
||||
input_tensors_as_shapes_[i].IsSet() &&
|
||||
RankKnown(input_tensors_as_shapes_[i])) {
|
||||
input_from_tensors_as_shape_str.push_back(strings::StrCat(
|
||||
"input[", i, "] = ", DebugString(input_tensors_as_shapes_[i])));
|
||||
} else if (requested_input_tensor_[i] && i < input_tensors_.size() &&
|
||||
} else if (requested_input_tensor_[i] && i < input_tensors_size_ &&
|
||||
input_tensors_[i] != nullptr) {
|
||||
input_from_tensors_str.push_back(strings::StrCat(
|
||||
"input[", i, "] = <",
|
||||
@ -1140,7 +1146,7 @@ bool InferenceContext::MergeHandleShapesAndTypes(
|
||||
}
|
||||
std::vector<ShapeAndType> new_values(shapes_and_types.size());
|
||||
bool refined = false;
|
||||
for (int i = 0; i < shapes_and_types.size(); ++i) {
|
||||
for (int i = 0, iter_limit = shapes_and_types.size(); i < iter_limit; ++i) {
|
||||
const ShapeAndType& existing = (*to_update)[i];
|
||||
if (shapes_and_types[i].dtype == existing.dtype) {
|
||||
new_values[i].dtype = existing.dtype;
|
||||
@ -1164,7 +1170,7 @@ bool InferenceContext::MergeHandleShapesAndTypes(
|
||||
if (!refined) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < new_values.size(); ++i) {
|
||||
for (int i = 0, iter_limit = new_values.size(); i < iter_limit; ++i) {
|
||||
(*to_update)[i] = new_values[i];
|
||||
}
|
||||
return true;
|
||||
@ -1199,7 +1205,7 @@ bool InferenceContext::RelaxHandleShapesAndMergeTypes(
|
||||
return false;
|
||||
}
|
||||
std::vector<ShapeAndType> new_values(shapes_and_types.size());
|
||||
for (int i = 0; i < shapes_and_types.size(); ++i) {
|
||||
for (int i = 0, iter_limit = shapes_and_types.size(); i < iter_limit; ++i) {
|
||||
const ShapeAndType& existing = (*to_update)[i];
|
||||
if (shapes_and_types[i].dtype == existing.dtype) {
|
||||
new_values[i].dtype = existing.dtype;
|
||||
|
@ -1469,9 +1469,10 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
|
||||
found_unknown_shapes = a_input_shape_unknown || b_input_shape_unknown ||
|
||||
(a_input.shape().dim_size() < matrix_rank) ||
|
||||
(b_input.shape().dim_size() < matrix_rank);
|
||||
|
||||
if (a_input_str.size() != a_input_shape.dim_size() ||
|
||||
b_input_str.size() != b_input_shape.dim_size()) {
|
||||
int a_input_str_size = a_input_str.size();
|
||||
int b_input_str_size = b_input_str.size();
|
||||
if (a_input_str_size != a_input_shape.dim_size() ||
|
||||
b_input_str_size != b_input_shape.dim_size()) {
|
||||
VLOG(1) << "Missing accurate estimator for op: " << op_info.op()
|
||||
<< ", equation subscripts don't match tensor rank.";
|
||||
return PredictCostOfAnUnknownOp(op_context);
|
||||
@ -1513,7 +1514,7 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
|
||||
n_dim.set_size(1);
|
||||
k_dim.set_size(1);
|
||||
|
||||
for (int i_idx = 0; i_idx < a_input_str.size(); ++i_idx) {
|
||||
for (int i_idx = 0, iter_limit = a_input_str.size(); i_idx < iter_limit; ++i_idx) {
|
||||
if (b_input_str.find(a_input_str[i_idx]) == std::string::npos) {
|
||||
if (rhs_str.find(a_input_str[i_idx]) == std::string::npos) {
|
||||
VLOG(1) << "Missing accurate estimator for op: " << op_info.op();
|
||||
@ -1533,7 +1534,7 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
|
||||
*(a_matrix_shape->add_dim()) = a_input_shape.dim(i_idx);
|
||||
*(b_matrix_shape->add_dim()) = a_input_shape.dim(i_idx);
|
||||
}
|
||||
for (int i_idx = 0; i_idx < b_input_str.size(); ++i_idx) {
|
||||
for (int i_idx = 0, iter_limit = b_input_str.size(); i_idx < iter_limit; ++i_idx) {
|
||||
if (a_input_str.find(b_input_str[i_idx]) == std::string::npos) {
|
||||
if (rhs_str.find(b_input_str[i_idx]) == std::string::npos) {
|
||||
VLOG(1) << "Missing accurate estimator for op: " << op_info.op();
|
||||
|
@ -73,7 +73,7 @@ class UniqueNodes {
|
||||
if (it == memoized_signatures_.end()) return;
|
||||
|
||||
std::vector<NodeDef*>& candidates = rep_[it->second];
|
||||
for (int i = 0; i < candidates.size(); ++i) {
|
||||
for (int i = 0, iter_limit = candidates.size(); i < iter_limit; ++i) {
|
||||
if (candidates[i] == node) {
|
||||
std::swap(candidates[i], candidates[candidates.size() - 1]);
|
||||
candidates.resize(candidates.size() - 1);
|
||||
|
@ -63,7 +63,7 @@ Status DebugStripper::Optimize(Cluster* cluster, const GrapplerItem& item,
|
||||
node.mutable_attr()->swap(new_attr);
|
||||
// As Identity op only takes one input, mark redundant inputs as control
|
||||
// input.
|
||||
for (size_t i = 1; i < node.input_size(); ++i) {
|
||||
for (int i = 1, iter_limit = node.input_size(); i < iter_limit; ++i) {
|
||||
if (!IsControlInput(node.input(i))) {
|
||||
*node.mutable_input(i) = AsControlDependency(NodeName(node.input(i)));
|
||||
}
|
||||
|
@ -401,9 +401,10 @@ Status SplitIdentityNInputs(GraphDef* graph,
|
||||
}
|
||||
|
||||
const int num_non_control_inputs = NumNonControlInputs(*node);
|
||||
const int terminal_second_size = terminal.second.size();
|
||||
if (node->attr().count("T") == 0 ||
|
||||
node->attr().at("T").list().type_size() != num_non_control_inputs ||
|
||||
terminal.second.size() >= num_non_control_inputs) {
|
||||
terminal_second_size >= num_non_control_inputs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ void PermuteNodesInPlace(GraphDef* graph, std::vector<int>* permutation,
|
||||
}
|
||||
permutation->swap(inv_perm);
|
||||
}
|
||||
for (std::size_t n = 0; n + 1 < permutation->size(); ++n) {
|
||||
for (int n = 0, iter_limit = permutation->size(); n + 1 < iter_limit; ++n) {
|
||||
while (n != (*permutation)[n]) {
|
||||
std::size_t r = (*permutation)[n];
|
||||
graph->mutable_node()->SwapElements(n, r);
|
||||
|
@ -81,7 +81,8 @@ Status ComputeTopologicalOrder(
|
||||
int ready_node = (*ready_nodes)[front];
|
||||
for (int fanout : graph_view.GetFanout(ready_node)) {
|
||||
++num_ready_inputs[fanout];
|
||||
if (num_ready_inputs[fanout] == graph_view.GetFanin(fanout).size()) {
|
||||
int graph_view_GetFanin_fanout_size = graph_view.GetFanin(fanout).size();
|
||||
if (num_ready_inputs[fanout] == graph_view_GetFanin_fanout_size) {
|
||||
ready_nodes->push_back(fanout);
|
||||
++back;
|
||||
}
|
||||
@ -95,7 +96,8 @@ Status ComputeTopologicalOrder(
|
||||
"at node = "
|
||||
<< graph.node(back).DebugString();
|
||||
for (int i = 0; i < graph_view.num_nodes(); ++i) {
|
||||
if (num_ready_inputs[i] != graph_view.GetFanin(i).size()) {
|
||||
int graph_view_GetFanin_i_size = graph_view.GetFanin(i).size();
|
||||
if (num_ready_inputs[i] != graph_view_GetFanin_i_size) {
|
||||
VLOG(1) << "Node not ready: " << graph.node(i).DebugString();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ Status InitializableLookupTable::Initialize(InitTableIterator& iter) {
|
||||
|
||||
Status InitializableLookupTable::AreEntriesSame(const InitTableIterator& iter,
|
||||
bool* result) {
|
||||
*result = iter.total_size() == size();
|
||||
*result = static_cast<size_t>(iter.total_size()) == size();
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ class TextFileLineIterator
|
||||
std::vector<string> tokens;
|
||||
if (!ignore_split_) {
|
||||
tokens = str_util::Split(line, delimiter_);
|
||||
if (std::max(key_index_, value_index_) >= tokens.size()) {
|
||||
if ( static_cast<size_t>(std::max(key_index_, value_index_)) >= tokens.size()) {
|
||||
status_ = errors::InvalidArgument(
|
||||
"Invalid number of columns in ", filename_, " line ", next_id_,
|
||||
" (", line, ") : expected ", std::max(key_index_, value_index_),
|
||||
|
@ -130,7 +130,7 @@ void DerivedXLineBuilder::ExpandOrAddLevelEvent(const XEvent& event,
|
||||
}
|
||||
|
||||
void DerivedXLineBuilder::ResetLastEvents(int level) {
|
||||
for (int i = level; i < last_event_by_level_.size(); ++i) {
|
||||
for (int i = level, iter_limit = last_event_by_level_.size(); i < iter_limit; ++i) {
|
||||
last_event_by_level_[i] = absl::nullopt;
|
||||
}
|
||||
if (level == 0) ResetDependentLines();
|
||||
|
@ -155,7 +155,7 @@ void SortXSpace(XSpace* space) {
|
||||
// smaller than these value.
|
||||
void NormalizeTimestamps(XPlane* plane, uint64 start_time_ns) {
|
||||
for (XLine& line : *plane->mutable_lines()) {
|
||||
if (line.timestamp_ns() >= start_time_ns) {
|
||||
if (line.timestamp_ns() >= static_cast<int64>(start_time_ns)) {
|
||||
line.set_timestamp_ns(line.timestamp_ns() - start_time_ns);
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,8 @@ BCastList<N>::BCastList(const BCastList::Vec (&x)[N],
|
||||
if (x[i] != x[0]) {
|
||||
all_equal = false;
|
||||
}
|
||||
if (x[i].size() > largest_rank) {
|
||||
int x_i_size = x[i].size();
|
||||
if (x_i_size > largest_rank) {
|
||||
largest_rank = x[i].size();
|
||||
}
|
||||
}
|
||||
@ -176,7 +177,8 @@ BCastList<N>::BCastList(const BCastList::Vec (&x)[N],
|
||||
|
||||
// 1-extend and align all vectors.
|
||||
for (int i = 0; i < N; ++i) {
|
||||
if (copy[i].size() < largest_rank) {
|
||||
int copy_i_size = copy[i].size();
|
||||
if (copy_i_size < largest_rank) {
|
||||
copy[i].resize(largest_rank, 1);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ void AddInferredAttr(const string& indentation, const string& attr_name,
|
||||
string VectorToTuple(const std::vector<string>& l) {
|
||||
if (l.size() == 1) return strings::StrCat("(", l.front(), ",)");
|
||||
string ret = "(";
|
||||
for (int i = 0; i < l.size(); ++i) {
|
||||
for (int i = 0, iter_limit = l.size(); i < iter_limit; ++i) {
|
||||
if (i > 0) {
|
||||
strings::StrAppend(&ret, ", ");
|
||||
}
|
||||
@ -75,11 +75,11 @@ string VectorToTuple(const std::vector<string>& l) {
|
||||
|
||||
void Unflatten(const string& prefix, const std::vector<string>& output_sizes,
|
||||
const string& var, string* result) {
|
||||
for (int i = 0; i < output_sizes.size(); ++i) {
|
||||
for (int i = 0, iter_limit = output_sizes.size(); i < iter_limit; ++i) {
|
||||
if (!output_sizes[i].empty()) {
|
||||
strings::StrAppend(result, prefix, var, " = ");
|
||||
if (i > 0) strings::StrAppend(result, var, "[:", i, "] + ");
|
||||
if (i + 1 < output_sizes.size()) {
|
||||
if (i + 1 < iter_limit) {
|
||||
// Special case i == 0 to avoid "0 +" in the generated code.
|
||||
if (i == 0) {
|
||||
strings::StrAppend(result, "[", var, "[:", output_sizes[i], "]] + ",
|
||||
@ -295,7 +295,7 @@ string GenEagerPythonOp::Code() {
|
||||
// from the end of params_no_default_, and adding params_no_default_.
|
||||
attrs_.reserve(params_no_default_.size() - op_def_.input_arg_size() +
|
||||
params_with_default_.size());
|
||||
for (int i = op_def_.input_arg_size(); i < params_no_default_.size(); ++i) {
|
||||
for (int i = op_def_.input_arg_size(), iter_limit = params_no_default_.size(); i < iter_limit; ++i) {
|
||||
attrs_.push_back(params_no_default_[i].GetName());
|
||||
}
|
||||
for (const auto& p : params_with_default_) {
|
||||
@ -331,7 +331,7 @@ string GenEagerPythonOp::Code() {
|
||||
parameters_with_defaults.empty() ? "" : ", ", "name=None");
|
||||
|
||||
// Add attr_expressions_ for attrs that are params.
|
||||
for (int i = 0; i < attrs_.size(); ++i) {
|
||||
for (int i = 0, iter_limit = attrs_.size(); i < iter_limit; ++i) {
|
||||
const string& attr_name = attrs_[i];
|
||||
const string& attr_api_name =
|
||||
param_names_[i + op_def_.input_arg_size()].GetRenameTo();
|
||||
@ -522,7 +522,7 @@ bool GenEagerPythonOp::GetEagerFunctionSetup(const string& indentation,
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < attrs_.size(); ++i) {
|
||||
for (int i = 0, iter_limit = attrs_.size(); i < iter_limit; ++i) {
|
||||
const string& attr_name = attrs_[i];
|
||||
const auto& param = param_names_[i + op_def_.input_arg_size()];
|
||||
const auto& attr = *FindAttr(attr_name, op_def_);
|
||||
|
@ -561,10 +561,10 @@ string GenPythonOp::Code() {
|
||||
// from the end of args_no_default, and adding args_no_default.
|
||||
attrs_.reserve(params_no_default.size() - op_def_.input_arg_size() +
|
||||
params_with_default.size());
|
||||
for (int i = op_def_.input_arg_size(); i < params_no_default.size(); ++i) {
|
||||
for (int i = op_def_.input_arg_size(), iter_limit = params_no_default.size(); i < iter_limit; ++i) {
|
||||
attrs_.push_back(params_no_default[i].GetName());
|
||||
}
|
||||
for (int i = 0; i < params_with_default.size(); ++i) {
|
||||
for (int i = 0, iter_limit = params_with_default.size(); i < iter_limit; ++i) {
|
||||
attrs_.push_back(params_with_default[i].GetName());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user