Returns range(0, rank(x)) if reduction_indices is None.
(x, axis, reduction_indices=None)
| 1429 | |
| 1430 | # Reduction operations |
| 1431 | def _ReductionDims(x, axis, reduction_indices=None): # pylint: disable=invalid-name |
| 1432 | """Returns range(0, rank(x)) if reduction_indices is None.""" |
| 1433 | # TODO(aselle): Remove this after deprecation |
| 1434 | if reduction_indices is not None: |
| 1435 | if axis is not None: |
| 1436 | raise ValueError("Can't specify both axis' and 'reduction_indices'.") |
| 1437 | axis = reduction_indices |
| 1438 | if axis is not None: |
| 1439 | return axis |
| 1440 | else: |
| 1441 | # Fast path: avoid creating Rank and Range ops if ndims is known. |
| 1442 | rank = common_shapes.rank(x) |
| 1443 | if rank is not None: |
| 1444 | return constant_op.constant(np.arange(rank), dtype=dtypes.int32) |
| 1445 | if (isinstance(x, sparse_tensor.SparseTensor) and |
| 1446 | x.dense_shape.shape.is_fully_defined()): |
| 1447 | rank = x.dense_shape.shape.dims[0].value # sparse.dense_shape is 1-D. |
| 1448 | return constant_op.constant(np.arange(rank), dtype=dtypes.int32) |
| 1449 | |
| 1450 | # Otherwise, we rely on Range and Rank to do the right thing at run-time. |
| 1451 | return range(0, array_ops.rank(x)) |
| 1452 | |
| 1453 | |
| 1454 | def _may_reduce_to_scalar(keepdims, axis, output): |
no test coverage detected