diff options
author | 2017-06-21 03:38:50 -0700 | |
---|---|---|
committer | 2017-06-21 03:42:05 -0700 | |
commit | 5478d53adf4e7af05449cae92fd4f7146caa3ccf (patch) | |
tree | 9c94138cffea4f8697755f46d42e50fedfa4c7f5 | |
parent | 50d1c07a42c60c25c409449136359c9ff8262944 (diff) |
Remove redundant `get` calls on smart pointers
PiperOrigin-RevId: 159675809
-rw-r--r-- | tensorflow/compiler/xla/literal_util_test.cc | 32 | ||||
-rw-r--r-- | tensorflow/compiler/xla/packed_literal_reader.cc | 2 | ||||
-rw-r--r-- | tensorflow/compiler/xla/service/hlo_evaluator.cc | 16 | ||||
-rw-r--r-- | tensorflow/compiler/xla/tests/literal_test_util.cc | 34 | ||||
-rw-r--r-- | tensorflow/compiler/xla/text_literal_reader.cc | 5 |
5 files changed, 44 insertions, 45 deletions
diff --git a/tensorflow/compiler/xla/literal_util_test.cc b/tensorflow/compiler/xla/literal_util_test.cc index 9dd13be80f..ffae623b0c 100644 --- a/tensorflow/compiler/xla/literal_util_test.cc +++ b/tensorflow/compiler/xla/literal_util_test.cc @@ -291,20 +291,20 @@ TEST_F(LiteralUtilTest, DifferentLayoutEquality) { auto colmajor = MakeUnique<Literal>(); *colmajor->mutable_shape() = ShapeUtil::MakeShape(F32, {2, 2}); *colmajor->mutable_shape()->mutable_layout() = LayoutUtil::MakeLayout({0, 1}); - colmajor.get()->Reserve(4); - colmajor.get()->Set<float>({0, 0}, 1.0); - colmajor.get()->Set<float>({0, 1}, 2.0); - colmajor.get()->Set<float>({1, 0}, 3.0); - colmajor.get()->Set<float>({1, 1}, 4.0); + colmajor->Reserve(4); + colmajor->Set<float>({0, 0}, 1.0); + colmajor->Set<float>({0, 1}, 2.0); + colmajor->Set<float>({1, 0}, 3.0); + colmajor->Set<float>({1, 1}, 4.0); auto rowmajor = MakeUnique<Literal>(); *rowmajor->mutable_shape() = ShapeUtil::MakeShape(F32, {2, 2}); *rowmajor->mutable_shape()->mutable_layout() = LayoutUtil::MakeLayout({1, 0}); - rowmajor.get()->Reserve(4); - rowmajor.get()->Set<float>({0, 0}, 1.0); - rowmajor.get()->Set<float>({0, 1}, 2.0); - rowmajor.get()->Set<float>({1, 0}, 3.0); - rowmajor.get()->Set<float>({1, 1}, 4.0); + rowmajor->Reserve(4); + rowmajor->Set<float>({0, 0}, 1.0); + rowmajor->Set<float>({0, 1}, 2.0); + rowmajor->Set<float>({1, 0}, 3.0); + rowmajor->Set<float>({1, 1}, 4.0); EXPECT_TRUE(rowmajor->Equal(*colmajor)); } @@ -694,7 +694,7 @@ TEST_F(LiteralUtilTest, Copy) { const int64 step[] = {1, 1, 1, 1}; uint32 seqnr = 0; auto init_proc = [&](const std::vector<int64>& indexes) { - source.get()->Set(indexes, ++seqnr); + source->Set(indexes, ++seqnr); return true; }; @@ -705,7 +705,7 @@ TEST_F(LiteralUtilTest, Copy) { const int64 dest_base[] = {6, 4, 12, 2}; const int64 copy_size[] = {7, 8, 11, 9}; - TF_EXPECT_OK(blank.get()->Copy(*source, src_base, dest_base, copy_size)); + TF_EXPECT_OK(blank->Copy(*source, src_base, dest_base, copy_size)); std::vector<int64> source_indexes(TF_ARRAYSIZE(dimensions), 0); std::vector<int64> blank_indexes(TF_ARRAYSIZE(dimensions), 0); bool matched = true; @@ -729,13 +729,13 @@ TEST_F(LiteralUtilTest, Copy) { TEST_F(LiteralUtilTest, CopyScalars) { auto zero = Literal::CreateR0<uint32>(0); auto nine = Literal::CreateR0<uint32>(9); - TF_EXPECT_OK(zero.get()->Copy(*nine, {}, {}, {})); + TF_EXPECT_OK(zero->Copy(*nine, {}, {}, {})); EXPECT_TRUE(zero->Equal(*nine)); auto vect = Literal::CreateR1<uint32>({3, 4, 9, 12, 5, 17, 21}); - TF_EXPECT_OK(zero.get()->Copy(*vect, {5}, {}, {})); + TF_EXPECT_OK(zero->Copy(*vect, {5}, {}, {})); EXPECT_EQ(zero->Get<uint32>({}), 17); - TF_EXPECT_OK(vect.get()->Copy(*zero, {}, {4}, {})); + TF_EXPECT_OK(vect->Copy(*zero, {}, {4}, {})); EXPECT_EQ(vect->Get<uint32>({4}), 17); } @@ -796,7 +796,7 @@ TEST_F(LiteralUtilTest, Populate) { // with zero. return literal->LinearIndex(indexes) + 17; }; - TF_EXPECT_OK(literal.get()->Populate<uint32>(generator)); + TF_EXPECT_OK(literal->Populate<uint32>(generator)); std::vector<int64> zero_base(data.dimensions.size(), 0); std::vector<int64> step(data.dimensions.size(), 1); diff --git a/tensorflow/compiler/xla/packed_literal_reader.cc b/tensorflow/compiler/xla/packed_literal_reader.cc index 1187079906..70e0f5a747 100644 --- a/tensorflow/compiler/xla/packed_literal_reader.cc +++ b/tensorflow/compiler/xla/packed_literal_reader.cc @@ -58,7 +58,7 @@ StatusOr<std::unique_ptr<Literal>> PackedLiteralReader::Read( } int64 elements = ShapeUtil::ElementsIn(shape); - result.get()->Resize(elements, std::numeric_limits<float>::quiet_NaN()); + result->Resize(elements, std::numeric_limits<float>::quiet_NaN()); std::vector<float>* field = result->mutable_f32s(); char* data = tensorflow::bit_cast<char*>(field->data()); uint64 bytes = elements * sizeof(float); diff --git a/tensorflow/compiler/xla/service/hlo_evaluator.cc b/tensorflow/compiler/xla/service/hlo_evaluator.cc index 393e25380e..f0512c0eaf 100644 --- a/tensorflow/compiler/xla/service/hlo_evaluator.cc +++ b/tensorflow/compiler/xla/service/hlo_evaluator.cc @@ -90,7 +90,7 @@ StatusOr<std::unique_ptr<Literal>> Compare(const Shape& shape, HloOpcode opcode, } auto result = Literal::CreateFromShape(shape); - TF_RETURN_IF_ERROR(result.get()->Populate<bool>( + TF_RETURN_IF_ERROR(result->Populate<bool>( [&](tensorflow::gtl::ArraySlice<int64> multi_index) { return compare_op(lhs_literal.Get<OperandT>(multi_index), rhs_literal.Get<OperandT>(multi_index)); @@ -119,7 +119,7 @@ StatusOr<std::unique_ptr<Literal>> ElementWiseUnaryOpImpl( auto result = Literal::CreateFromShape(shape); - TF_RETURN_IF_ERROR(result.get()->Populate<ReturnT>( + TF_RETURN_IF_ERROR(result->Populate<ReturnT>( [&](tensorflow::gtl::ArraySlice<int64> multi_index) { return unary_op(operand_literal.Get<NativeT>(multi_index)); })); @@ -439,7 +439,7 @@ class HloEvaluator::TypedVisitor : public DfsHloVisitorWithDefault { auto result = Literal::CreateFromShape(shape); - TF_RETURN_IF_ERROR(result.get()->Populate<ReturnT>( + TF_RETURN_IF_ERROR(result->Populate<ReturnT>( [&](tensorflow::gtl::ArraySlice<int64> multi_index) { return binary_op(lhs_literal.Get<ReturnT>(multi_index), rhs_literal.Get<ReturnT>(multi_index)); @@ -476,7 +476,7 @@ class HloEvaluator::TypedVisitor : public DfsHloVisitorWithDefault { auto result = Literal::CreateFromShape(shape); - TF_RETURN_IF_ERROR(result.get()->Populate<ReturnT>( + TF_RETURN_IF_ERROR(result->Populate<ReturnT>( [&](tensorflow::gtl::ArraySlice<int64> multi_index) { return ternary_op(lhs_literal.Get<LhsType>(multi_index), rhs_literal.Get<RhsType>(multi_index), @@ -637,7 +637,7 @@ Status HloEvaluator::HandleConcatenate( for (auto operand : operands) { const Shape& operand_shape = operand->shape(); - TF_RETURN_IF_ERROR(result_literal.get()->Copy( + TF_RETURN_IF_ERROR(result_literal->Copy( GetEvaluatedLiteralFor(operand), source_indices, dest_indices, AsInt64Slice(operand_shape.dimensions()))); dest_indices[concat_dim] += @@ -769,9 +769,9 @@ Status HloEvaluator::HandleSlice(HloInstruction* slice, DimensionVector dest_indices(slice->slice_starts().size(), 0); - TF_RETURN_IF_ERROR(literal.get()->Copy(GetEvaluatedLiteralFor(operand), - slice->slice_starts(), dest_indices, - AsInt64Slice(shape.dimensions()))); + TF_RETURN_IF_ERROR(literal->Copy(GetEvaluatedLiteralFor(operand), + slice->slice_starts(), dest_indices, + AsInt64Slice(shape.dimensions()))); evaluated_[slice] = std::move(literal); return Status::OK(); diff --git a/tensorflow/compiler/xla/tests/literal_test_util.cc b/tensorflow/compiler/xla/tests/literal_test_util.cc index 69c12cc437..cca04e17ca 100644 --- a/tensorflow/compiler/xla/tests/literal_test_util.cc +++ b/tensorflow/compiler/xla/tests/literal_test_util.cc @@ -508,7 +508,7 @@ class NearComparator { *shape_with_layout.mutable_layout() = LayoutUtil::MakeLayout(minor_to_major); // Allocate space in the new literal. - new_literal.get()->Reserve(ShapeUtil::ElementsIn(literal.shape())); + new_literal->Reserve(ShapeUtil::ElementsIn(literal.shape())); // Copy data into new literal, element-by-element. for (int64 i = 0; i < ShapeUtil::ElementsIn(literal.shape()); ++i) { @@ -518,36 +518,36 @@ class NearComparator { IndexUtil::LinearIndexToMultidimensionalIndex(shape_with_layout, i); switch (literal.shape().element_type()) { case PRED: - new_literal.get()->Set<bool>(to_multi_index, - literal.Get<bool>(from_multi_index)); + new_literal->Set<bool>(to_multi_index, + literal.Get<bool>(from_multi_index)); break; case U8: - new_literal.get()->Set<uint8>(to_multi_index, - literal.Get<uint8>(from_multi_index)); + new_literal->Set<uint8>(to_multi_index, + literal.Get<uint8>(from_multi_index)); break; case U32: - new_literal.get()->Set<uint32>(to_multi_index, - literal.Get<uint32>(from_multi_index)); + new_literal->Set<uint32>(to_multi_index, + literal.Get<uint32>(from_multi_index)); break; case S32: - new_literal.get()->Set<int32>(to_multi_index, - literal.Get<int32>(from_multi_index)); + new_literal->Set<int32>(to_multi_index, + literal.Get<int32>(from_multi_index)); break; case U64: - new_literal.get()->Set<uint64>(to_multi_index, - literal.Get<uint64>(from_multi_index)); + new_literal->Set<uint64>(to_multi_index, + literal.Get<uint64>(from_multi_index)); break; case S64: - new_literal.get()->Set<int64>(to_multi_index, - literal.Get<int64>(from_multi_index)); + new_literal->Set<int64>(to_multi_index, + literal.Get<int64>(from_multi_index)); break; case F32: - new_literal.get()->Set<float>(to_multi_index, - literal.Get<float>(from_multi_index)); + new_literal->Set<float>(to_multi_index, + literal.Get<float>(from_multi_index)); break; case F64: - new_literal.get()->Set<double>(to_multi_index, - literal.Get<double>(from_multi_index)); + new_literal->Set<double>(to_multi_index, + literal.Get<double>(from_multi_index)); break; default: LOG(FATAL) << "Unhandled primitive element type: " diff --git a/tensorflow/compiler/xla/text_literal_reader.cc b/tensorflow/compiler/xla/text_literal_reader.cc index afdc6726f1..4d060895d3 100644 --- a/tensorflow/compiler/xla/text_literal_reader.cc +++ b/tensorflow/compiler/xla/text_literal_reader.cc @@ -104,8 +104,7 @@ StatusOr<std::unique_ptr<Literal>> TextLiteralReader::ReadAllLines() { auto result = MakeUnique<Literal>(); const float fill = std::numeric_limits<float>::quiet_NaN(); - result.get()->PopulateWithValue<float>(fill, - AsInt64Slice(shape.dimensions())); + result->PopulateWithValue<float>(fill, AsInt64Slice(shape.dimensions())); std::vector<tensorflow::StringPiece> pieces; std::vector<tensorflow::StringPiece> coordinates; std::vector<int64> coordinate_values; @@ -147,7 +146,7 @@ StatusOr<std::unique_ptr<Literal>> TextLiteralReader::ReadAllLines() { "\"%s\"", shape.dimensions_size(), coordinate_values.size(), line.c_str()); } - result.get()->Set<float>(coordinate_values, value); + result->Set<float>(coordinate_values, value); } return std::move(result); } |