MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / IsCompatible

Function IsCompatible

tensorflow/python/eager/pywrap_tensor.cc:196–212  ·  view source on GitHub ↗

This function checks whether the desired type is "compatible" with the inferred type. At a high level, compatibility means that all integral types are compatible with each other, and all floating types are compatible with each other. Type compatibility doesn't consider overflows (i.e. int64 is *always compatible with int32). This is intended to match graph behavior.

Source from the content-addressed store, hash-verified

194// Type compatibility doesn't consider overflows (i.e. int64 is *always*
195// compatible with int32). This is intended to match graph behavior.
196bool IsCompatible(DataType desired, DataType returned) {
197 if (desired == returned) return true;
198
199 if (DataTypeIsInteger(desired) && DataTypeIsInteger(returned)) {
200 return true;
201 } else if (DataTypeIsFloating(desired) &&
202 (DataTypeIsFloating(returned) || DataTypeIsInteger(returned))) {
203 return true;
204 } else if (DataTypeIsComplex(desired) &&
205 (DataTypeIsComplex(returned) || DataTypeIsInteger(returned) ||
206 DataTypeIsFloating(returned))) {
207 return true;
208 } else if (DataTypeIsQuantized(desired) && DataTypeIsInteger(returned)) {
209 return true;
210 }
211 return false;
212}
213
214// TODO(nareshmodi): Move EagerCast and ReadVariableOp (which use the C API to
215// execute TFE Ops) to a separate common library.

Callers 2

XlaOpRegistrarMethod · 0.85

Calls 4

DataTypeIsIntegerFunction · 0.85
DataTypeIsFloatingFunction · 0.85
DataTypeIsComplexFunction · 0.85
DataTypeIsQuantizedFunction · 0.85

Tested by

no test coverage detected