tensorflow/compiler/mlir/tfrt/jit/python_binding/conversion_utils.cc
// Returns Python buffer protocol's type string from TFRT's dtype.
Returns Python buffer protocol's type string from TFRT's dtype.
Returns Python buffer protocol ' s type string from TFRT ' s dtype .
const char* ToPythonStructFormat(DType dtype_kind) {
  switch (dtype_kind) {
    case DType::Invalid:
      throw std::runtime_error("Invalid dtype.");
    case DType::Unsupported:
      throw std::runtime_error("Unsupported dtype.");
    case DType::UI8:
      return "B";
    case DType::UI16:
      return "H";
    case DType::UI32:
      return "I";
    case DType::UI64:
      return "Q";
    case DType::I1:
      return "?";
    case DType::I8:
      return "b";
    case DType::I16:
      return "h";
    case DType::I32:
      return "i";
    case DType::I64:
      return "q";
    case DType::F32:
      return "f";
    case DType::F64:
      return "d";
    case DType::Complex64:
      throw std::runtime_error("Unimplemented.");
    case DType::Complex128:
      throw std::runtime_error("Unimplemented.");
    case DType::F16:
      throw std::runtime_error("Unimplemented.");
    case DType::BF16:
      throw std::runtime_error("Unimplemented.");
    case DType::String:
      throw std::runtime_error("Unimplemented.");
    default:
      throw std::runtime_error("Unimplemented.");
  }
}
const char * ToPythonStructFormat ( DType dtype_kind ) { switch ( dtype_kind ) { case DType :: Invalid : throw std :: runtime_error ( " " ) ; case DType :: Unsupported : throw std :: runtime_error ( " " ) ; case DType :: UI8 : return " " ; case DType :: UI16 : return " " ; case DType :: UI32 : return " " ; case DType :: UI64 : return " " ; case DType :: I1 : return " " ; case DType :: I8 : return " " ; case DType :: I16 : return " " ; case DType :: I32 : return " " ; case DType :: I64 : return " " ; case DType :: F32 : return " " ; case DType :: F64 : return " " ; case DType :: Complex64 : throw std :: runtime_error ( " " ) ; case DType :: Complex128 : throw std :: runtime_error ( " " ) ; case DType :: F16 : throw std :: runtime_error ( " " ) ; case DType :: BF16 : throw std :: runtime_error ( " " ) ; case DType :: String : throw std :: runtime_error ( " " ) ; default : throw std :: runtime_error ( " " ) ; } }
Returns Python buffer protocol's type string from TFRT's dtype.
Returns Python buffer protocol ' s type string from TFRT ' s dtype .
// Reference: https://docs.python.org/3/library/struct.html