Pads `value` to the front and/or back of a `Tensor` dim, `count` times. Args: x: `Tensor` input. axis: Scalar `int`-like `Tensor` representing the single dimension to pad. (Negative indexing is supported.) front: Python `bool`; if `True` the beginning of the `axis` dimension is
(x, axis, front=False, back=False, value=0, count=1, name=None)
| 1280 | |
| 1281 | |
| 1282 | def pad(x, axis, front=False, back=False, value=0, count=1, name=None): |
| 1283 | """Pads `value` to the front and/or back of a `Tensor` dim, `count` times. |
| 1284 | |
| 1285 | Args: |
| 1286 | x: `Tensor` input. |
| 1287 | axis: Scalar `int`-like `Tensor` representing the single dimension to pad. |
| 1288 | (Negative indexing is supported.) |
| 1289 | front: Python `bool`; if `True` the beginning of the `axis` dimension is |
| 1290 | padded with `value`, `count` times. If `False` no front padding is made. |
| 1291 | back: Python `bool`; if `True` the end of the `axis` dimension is padded |
| 1292 | with `value`, `count` times. If `False` no end padding is made. |
| 1293 | value: Scalar `int`-like `Tensor` representing the actual value added to the |
| 1294 | front and/or back of the `axis` dimension of `x`. |
| 1295 | count: Scalar `int`-like `Tensor` representing number of elements added to |
| 1296 | the front and/or back of the `axis` dimension of `x`. E.g., if `front = |
| 1297 | back = True` then `2 * count` elements are added. |
| 1298 | name: Python `str` name prefixed to Ops created by this function. |
| 1299 | |
| 1300 | Returns: |
| 1301 | pad: The padded version of input `x`. |
| 1302 | |
| 1303 | Raises: |
| 1304 | ValueError: if both `front` and `back` are `False`. |
| 1305 | TypeError: if `count` is not `int`-like. |
| 1306 | """ |
| 1307 | with ops.name_scope(name, "pad", [x, value, count]): |
| 1308 | x = ops.convert_to_tensor(x, name="x") |
| 1309 | value = ops.convert_to_tensor(value, dtype=x.dtype, name="value") |
| 1310 | count = ops.convert_to_tensor(count, name="count") |
| 1311 | if not count.dtype.is_integer: |
| 1312 | raise TypeError("`count.dtype` (`{}`) must be `int`-like.".format( |
| 1313 | count.dtype.name)) |
| 1314 | if not front and not back: |
| 1315 | raise ValueError("At least one of `front`, `back` must be `True`.") |
| 1316 | ndims = ( |
| 1317 | x.shape.ndims if x.shape.ndims is not None else array_ops.rank( |
| 1318 | x, name="ndims")) |
| 1319 | axis = ops.convert_to_tensor(axis, name="axis") |
| 1320 | axis_ = tensor_util.constant_value(axis) |
| 1321 | if axis_ is not None: |
| 1322 | axis = axis_ |
| 1323 | if axis < 0: |
| 1324 | axis = ndims + axis |
| 1325 | count_ = tensor_util.constant_value(count) |
| 1326 | if axis_ >= 0 or x.shape.ndims is not None: |
| 1327 | head = x.shape[:axis] |
| 1328 | middle = tensor_shape.TensorShape(None if count_ is None else ( |
| 1329 | tensor_shape.dimension_at_index(x.shape, axis) + count_ * |
| 1330 | (front + back))) |
| 1331 | tail = x.shape[axis + 1:] |
| 1332 | final_shape = head.concatenate(middle.concatenate(tail)) |
| 1333 | else: |
| 1334 | final_shape = None |
| 1335 | else: |
| 1336 | axis = array_ops.where_v2(axis < 0, ndims + axis, axis) |
| 1337 | final_shape = None |
| 1338 | x = array_ops.pad( |
| 1339 | x, |
nothing calls this directly
no test coverage detected