Inserts `batch_size` in front of the `shape`. Args: batch_size(int): the inserted integer value of batch size. Returns: The original InputSpec instance by inserting `batch_size` in front of `shape`. Examples: .. code-block:: pyc
(self, batch_size: int | Size1)
| 344 | return cls(ndarray.shape, ndarray.dtype, name) |
| 345 | |
| 346 | def batch(self, batch_size: int | Size1) -> Self: |
| 347 | """ |
| 348 | Inserts `batch_size` in front of the `shape`. |
| 349 | |
| 350 | Args: |
| 351 | batch_size(int): the inserted integer value of batch size. |
| 352 | |
| 353 | Returns: |
| 354 | The original InputSpec instance by inserting `batch_size` in front of `shape`. |
| 355 | |
| 356 | Examples: |
| 357 | .. code-block:: pycon |
| 358 | |
| 359 | >>> from paddle.static import InputSpec |
| 360 | |
| 361 | >>> x_spec = InputSpec(shape=[64], dtype='float32', name='x') |
| 362 | >>> x_spec.batch(4) |
| 363 | >>> print(x_spec) |
| 364 | InputSpec(shape=(4, 64), dtype=paddle.float32, name=x, stop_gradient=False) |
| 365 | |
| 366 | """ |
| 367 | if isinstance(batch_size, (list, tuple)): |
| 368 | if len(batch_size) != 1: |
| 369 | raise ValueError( |
| 370 | f"Length of batch_size: {batch_size} shall be 1, but received {len(batch_size)}." |
| 371 | ) |
| 372 | batch_size = batch_size[0] |
| 373 | elif not isinstance(batch_size, int): |
| 374 | raise TypeError( |
| 375 | f"type(batch_size) shall be `int`, but received {type(batch_size).__name__}." |
| 376 | ) |
| 377 | |
| 378 | new_shape = [batch_size, *list(self.shape)] |
| 379 | self.shape = tuple(new_shape) |
| 380 | |
| 381 | return self |
| 382 | |
| 383 | def unbatch(self) -> Self: |
| 384 | """ |