tensorflow/python/framework/op_def_library_pybind.cc
// Returns the input Tensor's DType.
Returns the input Tensor's DType.
Returns the input Tensor ' s DType .
py::object GetInputType(
    const py::object& input_tensor, const ArgDef& input_arg,
    const AllowedAttrMap& allowed_list_attr_map,
    const std::string& op_type_name, const std::string& input_name,
    py::dict& attrs,
    absl::flat_hash_map<std::string, std::string>& inferred_from) {
  py::object dtype = input_tensor.attr(kDType);
  py::object base_type = dtype.attr(kBaseDType);
  if (input_arg.type() != DataType::DT_INVALID &&
      input_arg.type() != dtype.cast<DataType>() &&
      input_arg.type() != base_type.cast<DataType>()) {
    throw PyTypeError(absl::StrCat("Input '", input_name, "' of '",
                                   op_type_name, "' Op has type ",
                                   base_type.attr("name").cast<std::string>(),
                                   " that does not match expected type of ",
                                   DataTypeToPybindObject(input_arg.type())
                                       .attr("name")
                                       .cast<std::string>(),
                                   "."));
  }
  const std::string& type_attr = input_arg.type_attr();
  if (!type_attr.empty()) {
    if (attrs.contains(type_attr) &&
        attrs[type_attr.c_str()].cast<py::object>() != base_type) {
      throw PyTypeError(absl::StrCat(
          "Input '", input_name, "' of '", op_type_name, "' Op has type ",
          base_type.attr("name").cast<std::string>(),
          " that does not match type ",
          attrs[type_attr.c_str()].attr("name").cast<std::string>(),
          " of argument '", inferred_from.at(type_attr), "'."));
    } else {
      AssertSatisfiesAllowedListAttrTypeConstraint(
          type_attr, allowed_list_attr_map, base_type, input_name);
      attrs[type_attr.c_str()] = base_type;
      inferred_from[input_arg.type_attr()] = input_name;
    }
  } else if (base_type.cast<DataType>() != input_arg.type()) {
    throw PyTypeError("Unreachable");
  }
  if (input_arg.is_ref()) return dtype;
  return base_type;
}
py :: object GetInputType ( const py :: object & input_tensor , const ArgDef & input_arg , const AllowedAttrMap & allowed_list_attr_map , const std :: string & op_type_name , const std :: string & input_name , py :: dict & attrs , absl :: flat_hash_map < std :: string , std :: string > & inferred_from ) { py :: object dtype = input_tensor . attr ( kDType ) ; py :: object base_type = dtype . attr ( kBaseDType ) ; if ( input_arg . type ( ) != DataType :: DT_INVALID && input_arg . type ( ) != dtype . cast < DataType > ( ) && input_arg . type ( ) != base_type . cast < DataType > ( ) ) { throw PyTypeError ( absl :: StrCat ( " " , input_name , " " , op_type_name , " " , base_type . attr ( " " ) . cast < std :: string > ( ) , " " , DataTypeToPybindObject ( input_arg . type ( ) ) . attr ( " " ) . cast < std :: string > ( ) , " " ) ) ; } const std :: string & type_attr = input_arg . type_attr ( ) ; if ( ! type_attr . empty ( ) ) { if ( attrs . contains ( type_attr ) && attrs [ type_attr . c_str ( ) ] . cast < py :: object > ( ) != base_type ) { throw PyTypeError ( absl :: StrCat ( " " , input_name , " " , op_type_name , " " , base_type . attr ( " " ) . cast < std :: string > ( ) , " " , attrs [ type_attr . c_str ( ) ] . attr ( " " ) . cast < std :: string > ( ) , " " , inferred_from . at ( type_attr ) , " " ) ) ; } else { AssertSatisfiesAllowedListAttrTypeConstraint ( type_attr , allowed_list_attr_map , base_type , input_name ) ; attrs [ type_attr . c_str ( ) ] = base_type ; inferred_from [ input_arg . type_attr ( ) ] = input_name ; } } else if ( base_type . cast < DataType > ( ) != input_arg . type ( ) ) { throw PyTypeError ( " " ) ; } if ( input_arg . is_ref ( ) ) return dtype ; return base_type ; }
Returns the input Tensor's DType.
Returns the input Tensor ' s DType .
// Check that the input_arg and the input are compatible. // Added to match the python behaviour.