tensorflow/contrib/tensorboard/db/summary_db_writer.cc
// Tries to fudge shape and dtype to something with smaller storage.
Tries to fudge shape and dtype to something with smaller storage.
Tries to fudge shape and dtype to something with smaller storage .
Status CoerceScalar(const Tensor& t, Tensor* out) {
  switch (t.dtype()) {
    case DT_DOUBLE:
      *out = t;
      break;
    case DT_INT64:
      *out = t;
      break;
    case DT_FLOAT:
      *out = {DT_DOUBLE, {}};
      out->scalar<double>()() = t.scalar<float>()();
      break;
    case DT_HALF:
      *out = {DT_DOUBLE, {}};
      out->scalar<double>()() = static_cast<double>(t.scalar<Eigen::half>()());
      break;
    case DT_INT32:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<int32>()();
      break;
    case DT_INT16:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<int16>()();
      break;
    case DT_INT8:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<int8>()();
      break;
    case DT_UINT32:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<uint32>()();
      break;
    case DT_UINT16:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<uint16>()();
      break;
    case DT_UINT8:
      *out = {DT_INT64, {}};
      out->scalar<int64>()() = t.scalar<uint8>()();
      break;
    default:
      return errors::Unimplemented("Scalar summary for dtype ",
                                   DataTypeString(t.dtype()),
                                   " is not supported.");
  }
  return Status::OK();
}
Status CoerceScalar ( const Tensor & t , Tensor * out ) { switch ( t . dtype ( ) ) { case DT_DOUBLE : * out = t ; break ; case DT_INT64 : * out = t ; break ; case DT_FLOAT : * out = { DT_DOUBLE , { } } ; out -> scalar < double > ( ) ( ) = t . scalar < float > ( ) ( ) ; break ; case DT_HALF : * out = { DT_DOUBLE , { } } ; out -> scalar < double > ( ) ( ) = static_cast < double > ( t . scalar < Eigen :: half > ( ) ( ) ) ; break ; case DT_INT32 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < int32 > ( ) ( ) ; break ; case DT_INT16 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < int16 > ( ) ( ) ; break ; case DT_INT8 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < int8 > ( ) ( ) ; break ; case DT_UINT32 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < uint32 > ( ) ( ) ; break ; case DT_UINT16 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < uint16 > ( ) ( ) ; break ; case DT_UINT8 : * out = { DT_INT64 , { } } ; out -> scalar < int64 > ( ) ( ) = t . scalar < uint8 > ( ) ( ) ; break ; default : return errors :: Unimplemented ( " " , DataTypeString ( t . dtype ( ) ) , " " ) ; } return Status :: OK ( ) ; }
Tries to fudge shape and dtype to something with smaller storage.
Tries to fudge shape and dtype to something with smaller storage .