If `data` is scalar, then add a dimension; otherwise return as-is.
(data)
| 4971 | |
| 4972 | |
| 4973 | def _with_nonzero_rank(data): |
| 4974 | """If `data` is scalar, then add a dimension; otherwise return as-is.""" |
| 4975 | if data.shape.ndims is not None: |
| 4976 | if data.shape.ndims == 0: |
| 4977 | return stack([data]) |
| 4978 | else: |
| 4979 | return data |
| 4980 | else: |
| 4981 | data_shape = shape(data) |
| 4982 | data_ndims = rank(data) |
| 4983 | return reshape(data, concat([[1], data_shape], axis=0)[-data_ndims:]) |
| 4984 | |
| 4985 | |
| 4986 | @tf_export("repeat") |