Converts `values` to a list of `Tensor` objects. Args: values: A list of objects that can be consumed by `tf.convert_to_tensor()`. dtype: (Optional.) The required `DType` of the returned `Tensor` objects. name: (Optional.) A name prefix to used when a new `Tensor` is created, in
(values,
dtype=None,
name=None,
as_ref=False,
preferred_dtype=None,
ctx=None)
| 1316 | |
| 1317 | |
| 1318 | def internal_convert_n_to_tensor(values, |
| 1319 | dtype=None, |
| 1320 | name=None, |
| 1321 | as_ref=False, |
| 1322 | preferred_dtype=None, |
| 1323 | ctx=None): |
| 1324 | """Converts `values` to a list of `Tensor` objects. |
| 1325 | |
| 1326 | Args: |
| 1327 | values: A list of objects that can be consumed by `tf.convert_to_tensor()`. |
| 1328 | dtype: (Optional.) The required `DType` of the returned `Tensor` objects. |
| 1329 | name: (Optional.) A name prefix to used when a new `Tensor` is created, in |
| 1330 | which case element `i` will be given the name `name + '_' + i`. |
| 1331 | as_ref: True if the caller wants the results as ref tensors. |
| 1332 | preferred_dtype: Optional element type for the returned tensors, used when |
| 1333 | dtype is None. In some cases, a caller may not have a dtype in mind when |
| 1334 | converting to a tensor, so preferred_dtype can be used as a soft |
| 1335 | preference. If the conversion to `preferred_dtype` is not possible, this |
| 1336 | argument has no effect. |
| 1337 | ctx: The value of context.context(). |
| 1338 | |
| 1339 | Returns: |
| 1340 | A list of `Tensor` and/or `IndexedSlices` objects. |
| 1341 | |
| 1342 | Raises: |
| 1343 | TypeError: If no conversion function is registered for an element in |
| 1344 | `values`. |
| 1345 | RuntimeError: If a registered conversion function returns an invalid |
| 1346 | value. |
| 1347 | """ |
| 1348 | if not isinstance(values, collections_abc.Sequence): |
| 1349 | raise TypeError("values must be a sequence.") |
| 1350 | ret = [] |
| 1351 | if ctx is None: |
| 1352 | ctx = context.context() |
| 1353 | for i, value in enumerate(values): |
| 1354 | n = None if name is None else "%s_%d" % (name, i) |
| 1355 | ret.append( |
| 1356 | internal_convert_to_tensor( |
| 1357 | value, |
| 1358 | dtype=dtype, |
| 1359 | name=n, |
| 1360 | as_ref=as_ref, |
| 1361 | preferred_dtype=preferred_dtype, |
| 1362 | ctx=ctx)) |
| 1363 | return ret |
| 1364 | |
| 1365 | |
| 1366 | def convert_n_to_tensor(values, dtype=None, name=None, preferred_dtype=None): |
no test coverage detected