case U64:
return StrCat(Get<uint64>(multi_index, shape_index));
case F16:
- return StrCat(Get<half>(multi_index, shape_index));
+ return StrCat(static_cast<float>(Get<half>(multi_index, shape_index)));
case F32:
return StrCat(Get<float>(multi_index, shape_index));
case BF16:
return StrCat(
GetSparseElement<uint64>(sparse_element_number, shape_index));
case F16:
- return StrCat(GetSparseElement<half>(sparse_element_number, shape_index));
+ return StrCat(static_cast<float>(
+ GetSparseElement<half>(sparse_element_number, shape_index)));
case F32:
return StrCat(
GetSparseElement<float>(sparse_element_number, shape_index));
ASSERT_EQ(Literal::CreateSparse<half>(dimensions, indices,
{half{1.0}, half{2.0}, half{3.0}})
->GetSparseElementAsString(1),
- tensorflow::strings::StrCat(half{2.0}));
+ tensorflow::strings::StrCat(static_cast<float>(half{2.0})));
ASSERT_EQ(
Literal::CreateSparse<complex64>(
dimensions, indices,
#undef CASE
namespace {
+
+// StrCat and StrAppend don't support Eigen::half directly at the moment, and
+// we would like to keep them compatible with their absl counterparts, for ease
+// of migration. We could rely on errors::internal::PrepareForStrCat() but the
+// logic is so simple we can just replicate it here, where it is close to its
+// usage and easy to change later. And there's the extra benefit of not
+// accessing an 'internal' namespace.
+inline const strings::AlphaNum& PrintOneElement(const strings::AlphaNum& a) {
+ return a;
+}
+inline float PrintOneElement(const Eigen::half& h) {
+ return static_cast<float>(h);
+}
+
// Print from left dim to right dim recursively.
template <typename T>
void PrintOneDim(int dim_index, const gtl::InlinedVector<int64, 4>& shape,
for (int64 i = 0; i < element_count; i++) {
if (*data_index >= limit) return;
if (i > 0) strings::StrAppend(result, " ");
- strings::StrAppend(result, data[(*data_index)++]);
+ strings::StrAppend(result, PrintOneElement(data[(*data_index)++]));
}
return;
}
if (shape.empty()) {
for (int64 i = 0; i < limit; ++i) {
if (i > 0) strings::StrAppend(&ret, " ");
- strings::StrAppend(&ret, array[i]);
+ strings::StrAppend(&ret, PrintOneElement(array[i]));
}
if (num_elts > limit) strings::StrAppend(&ret, "...");
return ret;
#include <stdio.h>
#include <string.h>
-#include "third_party/eigen3/Eigen/Core"
#include "tensorflow/core/lib/gtl/stl_util.h"
#include "tensorflow/core/platform/logging.h"
namespace tensorflow {
namespace strings {
-AlphaNum::AlphaNum(const Eigen::half &f)
- : piece_(digits_, strlen(FloatToBuffer(static_cast<float>(f), digits_))) {}
-
AlphaNum::AlphaNum(Hex hex) {
char *const end = &digits_[kFastToBufferSize];
char *writer = end;
#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/platform/types.h"
-namespace Eigen {
-struct half;
-}
-
// The AlphaNum type was designed to be used as the parameter type for StrCat().
// Any routine accepting either a string or a number may accept it.
// The basic idea is that by accepting a "const AlphaNum &" as an argument
AlphaNum(double f) // NOLINT(runtime/explicit)
: piece_(digits_, strlen(DoubleToBuffer(f, digits_))) {}
- AlphaNum(const Eigen::half &f); // NOLINT(runtime/explicit)
AlphaNum(Hex hex); // NOLINT(runtime/explicit)
AlphaNum(const char *c_str) : piece_(c_str) {} // NOLINT(runtime/explicit)
#include <string>
-#include "third_party/eigen3/Eigen/Core"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/types.h"
result = tensorflow::strings::StrCat("A hundred K and a half squared is ", d);
EXPECT_EQ(result, "A hundred K and a half squared is 10000100000.25");
- Eigen::half h(10007.0f);
- result =
- tensorflow::strings::StrCat("Ten thousand seven is approximately ", h);
- EXPECT_EQ(result, "Ten thousand seven is approximately 10008");
-
result = tensorflow::strings::StrCat(1, 2, 333, 4444, 55555, 666666, 7777777,
88888888, 999999999);
EXPECT_EQ(result, "12333444455555666666777777788888888999999999");
#include "tensorflow/stream_executor/platform/port.h"
+#include "third_party/eigen3/Eigen/Core"
#include "tensorflow/stream_executor/blas.h"
#include "tensorflow/stream_executor/host_buffer.h"
#include "tensorflow/stream_executor/lib/stacktrace.h"
return ToVlogString(*memory);
}
-string ToVlogString(const Eigen::half &h) { return port::StrCat(h); }
+string ToVlogString(const Eigen::half &h) {
+ return port::StrCat(static_cast<float>(h));
+}
string ToVlogString(int i) { return port::StrCat(i); }