diff options
author | 2017-07-20 13:58:27 -0700 | |
---|---|---|
committer | 2017-07-20 14:02:15 -0700 | |
commit | 5dbae025a1b61155883c2f3c868bed9e53000e09 (patch) | |
tree | 7b0376995ebb2b91c0acae339bbffbea60f0b969 /tensorflow/compiler | |
parent | 306c585a179d9983afa3f6d3f54d4e4a532cb479 (diff) |
Simplify type casts in conversion to array slices.
This change introduces a slight semantics change. Empty vectors are guaranteed to not assert, because v.data() is allowed on empty vectors.
PiperOrigin-RevId: 162661944
Diffstat (limited to 'tensorflow/compiler')
-rw-r--r-- | tensorflow/compiler/xla/literal_util.cc | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/tensorflow/compiler/xla/literal_util.cc b/tensorflow/compiler/xla/literal_util.cc index ef21148b8b..0db9bd757d 100644 --- a/tensorflow/compiler/xla/literal_util.cc +++ b/tensorflow/compiler/xla/literal_util.cc @@ -926,25 +926,21 @@ template <> tensorflow::gtl::MutableArraySlice<bool> Literal::GetMutableArraySlice() { auto values = mutable_preds(); return tensorflow::gtl::MutableArraySlice<bool>( - reinterpret_cast<bool*>(&(*values)[0]), values->size()); + reinterpret_cast<bool*>(values->data()), values->size()); } template <> tensorflow::gtl::MutableArraySlice<int8> Literal::GetMutableArraySlice() { - // C++11 standard, basic_string 21.4.1.5, values should be stored - // contiguously. From C++17 a mutable data() member will be provided. auto values = mutable_u8s(); return tensorflow::gtl::MutableArraySlice<int8>( - reinterpret_cast<int8*>(&(*values)[0]), values->size()); + reinterpret_cast<int8*>(values->data()), values->size()); } template <> tensorflow::gtl::MutableArraySlice<uint8> Literal::GetMutableArraySlice() { - // C++11 standard, basic_string 21.4.1.5, values should be stored - // contiguously. From C++17 a mutable data() member will be provided. auto values = mutable_u8s(); - return tensorflow::gtl::MutableArraySlice<uint8>( - reinterpret_cast<uint8*>(&(*values)[0]), values->size()); + return tensorflow::gtl::MutableArraySlice<uint8>(values->data(), + values->size()); } template <> @@ -1006,13 +1002,11 @@ tensorflow::gtl::MutableArraySlice<double> Literal::GetMutableArraySlice() { template <> tensorflow::gtl::MutableArraySlice<half> Literal::GetMutableArraySlice<half>() { - // C++11 standard, basic_string 21.4.1.5, values should be stored - // contiguously. From C++17 a mutable data() member will be provided. // TODO - there is an endianess problem here. fix it, or wait for uint16 // support in protobuf auto values = mutable_f16s(); - return tensorflow::gtl::MutableArraySlice<half>( - reinterpret_cast<half*>(&(*values)[0]), values->size()); + return tensorflow::gtl::MutableArraySlice<half>(values->data(), + values->size()); } template <> @@ -1069,9 +1063,8 @@ tensorflow::gtl::ArraySlice<double> Literal::GetArraySlice<double>() const { template <> tensorflow::gtl::ArraySlice<half> Literal::GetArraySlice<half>() const { CHECK_EQ(shape().element_type(), F16); - return tensorflow::gtl::ArraySlice<half>( - reinterpret_cast<const half*>(f16s().data()), - f16s().size() / sizeof(half)); + return tensorflow::gtl::ArraySlice<half>(f16s().data(), + f16s().size() / sizeof(half)); } template <typename NativeT> |