r"""Returns a new tensor having a specified shape and filled with ones. Args: shape(int...): the shape of the output tensor. Keyword args: dtype(:attr:`.Tensor.dtype`, optional): output tensor data type. device(:attr:`.Tensor.device`, optional): device on which to p
(
shape: Union[int, Tuple[int, ...]],
*,
dtype="float32",
device: Optional[CompNode] = None
)
| 320 | |
| 321 | |
| 322 | def ones( |
| 323 | shape: Union[int, Tuple[int, ...]], |
| 324 | *, |
| 325 | dtype="float32", |
| 326 | device: Optional[CompNode] = None |
| 327 | ) -> Tensor: |
| 328 | r"""Returns a new tensor having a specified shape and filled with ones. |
| 329 | |
| 330 | Args: |
| 331 | shape(int...): the shape of the output tensor. |
| 332 | |
| 333 | Keyword args: |
| 334 | dtype(:attr:`.Tensor.dtype`, optional): output tensor data type. |
| 335 | device(:attr:`.Tensor.device`, optional): device on which to place the created tensor. |
| 336 | |
| 337 | Returns: |
| 338 | a tensor containing ones. |
| 339 | |
| 340 | Examples: |
| 341 | >>> F.ones(5) |
| 342 | Tensor([1. 1. 1. 1. 1.], device=xpux:0) |
| 343 | >>> F.ones((5, ), dtype='int32') |
| 344 | Tensor([1 1 1 1 1], dtype=int32, device=xpux:0) |
| 345 | >>> F.ones((2, 2)) |
| 346 | Tensor([[1. 1.] |
| 347 | [1. 1.]], device=xpux:0) |
| 348 | """ |
| 349 | if isinstance(shape, int): |
| 350 | shape = (shape,) |
| 351 | if device == None: |
| 352 | device = get_default_device() |
| 353 | op = builtin.Fill(1, dtype) |
| 354 | shape = astensor1d(shape, dtype="int32", device=device) |
| 355 | (x,) = apply(op, shape) |
| 356 | return x |
| 357 | |
| 358 | |
| 359 | def zeros( |
no test coverage detected