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

Function args_to_matching_eager

tensorflow/python/eager/execute.py:231–272  ·  view source on GitHub ↗

Convert sequence `l` to eager same-type Tensors.

(l, ctx, default_dtype=None)

Source from the content-addressed store, hash-verified

229
230
231def args_to_matching_eager(l, ctx, default_dtype=None):
232 """Convert sequence `l` to eager same-type Tensors."""
233 EagerTensor = ops.EagerTensor # pylint: disable=invalid-name
234 for x in l:
235 if not isinstance(x, EagerTensor):
236 break
237 else: # note: intentional for-else
238 return l[0]._datatype_enum(), l # pylint: disable=protected-access
239 # TODO(josh11b): Could we do a better job if we also passed in the
240 # allowed dtypes when that was known?
241
242 # Is some input already a Tensor with a dtype?
243 dtype = None
244 for t in l:
245 if isinstance(t, EagerTensor):
246 dtype = t.dtype
247 break
248
249 internal_convert_to_tensor = ops.internal_convert_to_tensor
250 if dtype is None:
251 # Infer a dtype based on the first value, and use that dtype for the
252 # remaining values.
253 ret = []
254 for t in l:
255 ret.append(
256 internal_convert_to_tensor(
257 t, dtype, preferred_dtype=default_dtype, ctx=ctx))
258 if dtype is None:
259 dtype = ret[-1].dtype
260 else:
261 ret = [internal_convert_to_tensor(t, dtype, ctx=ctx) for t in l]
262
263 # TODO(slebedev): consider removing this as it leaks a Keras concept.
264 # pylint: disable=protected-access
265 keras_symbolic_tensors = [x for x in ret if
266 ops._is_keras_symbolic_tensor(x)]
267 if keras_symbolic_tensors:
268 raise core._SymbolicException(
269 "Using symbolic output of a Keras layer during eager execution "
270 "{}".format(keras_symbolic_tensors))
271 # pylint: enable=protected-access
272 return dtype.as_datatype_enum, ret
273
274
275def convert_to_mixed_eager_tensors(values, ctx):

Callers

nothing calls this directly

Calls 4

_datatype_enumMethod · 0.80
appendMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected