Returns a 1D-tensor listing all dimensions in x.
(x)
| 3519 | |
| 3520 | |
| 3521 | def _all_dimensions(x): |
| 3522 | """Returns a 1D-tensor listing all dimensions in x.""" |
| 3523 | # Fast path: avoid creating Rank and Range ops if ndims is known. |
| 3524 | if isinstance(x, ops.Tensor) and x.get_shape().ndims is not None: |
| 3525 | return constant_op.constant( |
| 3526 | np.arange(x.get_shape().ndims), dtype=dtypes.int32) |
| 3527 | if (isinstance(x, sparse_tensor.SparseTensor) and |
| 3528 | x.dense_shape.get_shape().is_fully_defined()): |
| 3529 | r = x.dense_shape.get_shape().dims[0].value # sparse.dense_shape is 1-D. |
| 3530 | return constant_op.constant(np.arange(r), dtype=dtypes.int32) |
| 3531 | |
| 3532 | # Otherwise, we rely on `range` and `rank` to do the right thing at runtime. |
| 3533 | return gen_math_ops._range(0, rank(x), 1) |
| 3534 | |
| 3535 | |
| 3536 | @tf_export("sequence_mask") |
no test coverage detected