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

Function args_to_mixed_eager_tensors

tensorflow/python/eager/execute.py:281–316  ·  view source on GitHub ↗

Converts a list of same-length lists of values to eager tensors.

(lists, ctx)

Source from the content-addressed store, hash-verified

279
280
281def args_to_mixed_eager_tensors(lists, ctx):
282 """Converts a list of same-length lists of values to eager tensors."""
283 assert len(lists) > 1
284
285 # Generate an error if len(lists[i]) is not the same for all i.
286 lists_ret = []
287 for l in lists[1:]:
288 if len(l) != len(lists[0]):
289 raise ValueError(
290 "Expected list arguments to be the same length: %d != %d (%r vs. %r)."
291 % (len(lists[0]), len(l), lists[0], l))
292 lists_ret.append([])
293
294 # Convert the first element of each list first, then the second element, etc.
295 types = []
296 for i in range(len(lists[0])):
297 dtype = None
298 # If any list has a Tensor, use that dtype
299 for l in lists:
300 if isinstance(l[i], ops.EagerTensor):
301 dtype = l[i].dtype
302 break
303 if dtype is None:
304 # Convert the first one and use its dtype.
305 lists_ret[0].append(ops.internal_convert_to_tensor(lists[0][i], ctx=ctx))
306 dtype = lists_ret[0][i].dtype
307 for j in range(1, len(lists)):
308 lists_ret[j].append(
309 ops.internal_convert_to_tensor(lists[j][i], dtype=dtype, ctx=ctx))
310 else:
311 # Convert everything to the found dtype.
312 for j in range(len(lists)):
313 lists_ret[j].append(
314 ops.internal_convert_to_tensor(lists[j][i], dtype=dtype, ctx=ctx))
315 types.append(dtype.as_datatype_enum)
316 return types, lists_ret

Callers

nothing calls this directly

Calls 2

rangeFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected