Note: The type variable must be LoD Tensor Array.
(self, var)
| 395 | |
| 396 | @static_only |
| 397 | def append(self, var): |
| 398 | """ |
| 399 | |
| 400 | Note: |
| 401 | The type variable must be LoD Tensor Array. |
| 402 | |
| 403 | """ |
| 404 | if not isinstance(var, Variable): |
| 405 | if in_to_static_mode(): |
| 406 | """In dy2static mode, x may be tensor values such as int, float, np.array""" |
| 407 | from paddle.tensor.creation import to_tensor |
| 408 | |
| 409 | var = to_tensor(var) |
| 410 | else: |
| 411 | raise TypeError( |
| 412 | f"Required input var should be Variable, but received {type(var)}" |
| 413 | ) |
| 414 | if self.type != core.VarDesc.VarType.DENSE_TENSOR_ARRAY: |
| 415 | raise TypeError( |
| 416 | f"Only Variable with VarType.DENSE_TENSOR_ARRAY support `append` method, but received type: {self.type}" |
| 417 | ) |
| 418 | from paddle.tensor.array import array_length, array_write |
| 419 | |
| 420 | array_write(x=var, i=array_length(self), array=self) |
| 421 | |
| 422 | @static_only |
| 423 | def _item(self): |
nothing calls this directly
no test coverage detected