Convert to an int32 or int64 tensor, defaulting to int32 if empty.
(shape)
| 950 | |
| 951 | |
| 952 | def shape_tensor(shape): # pylint: disable=invalid-name |
| 953 | """Convert to an int32 or int64 tensor, defaulting to int32 if empty.""" |
| 954 | dtype = None |
| 955 | if isinstance(shape, (tuple, list)): |
| 956 | if not shape: |
| 957 | dtype = dtypes.int32 |
| 958 | else: |
| 959 | # If there are Dimension objects in the shape, unwrap them. This can be a |
| 960 | # problem if v1 and v2 TensorShape objects get mixed up in partial |
| 961 | # conversions, leading to shapes such as (1, 2, Dimension(5)), which are |
| 962 | # not convertible to Tensors becasue of mixed content. |
| 963 | shape = tuple(map(tensor_shape.dimension_value, shape)) |
| 964 | return ops.convert_to_tensor(shape, dtype=dtype, name="shape") |
| 965 | |
| 966 | |
| 967 | # DO NOT USE: For testing only. |
no test coverage detected