MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / zeros

Function zeros

imperative/python/megengine/functional/tensor.py:359–389  ·  view source on GitHub ↗

r"""Returns a new tensor having a specified shape and filled with zeros. 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

(
    shape: Union[int, Tuple[int, ...]],
    *,
    dtype="float32",
    device: Optional[CompNode] = None
)

Source from the content-addressed store, hash-verified

357
358
359def zeros(
360 shape: Union[int, Tuple[int, ...]],
361 *,
362 dtype="float32",
363 device: Optional[CompNode] = None
364) -> Tensor:
365 r"""Returns a new tensor having a specified shape and filled with zeros.
366
367 Args:
368 shape(int...): the shape of the output tensor.
369
370 Keyword args:
371 dtype(:attr:`.Tensor.dtype`, optional): output tensor data type.
372 device(:attr:`.Tensor.device`, optional): device on which to place the created tensor.
373
374 Returns:
375 a tensor containing zeros.
376
377 Examples:
378 >>> F.zeros((2, 3))
379 Tensor([[0. 0. 0.]
380 [0. 0. 0.]], device=xpux:0)
381 """
382 if isinstance(shape, int):
383 shape = (shape,)
384 if device == None:
385 device = get_default_device()
386 op = builtin.Fill(0, dtype)
387 shape = astensor1d(shape, dtype="int32", device=device)
388 (x,) = apply(op, shape)
389 return x
390
391
392def zeros_like(inp: Tensor) -> Tensor:

Callers 5

_gen_repeat_idxFunction · 0.70
_expand_labelFunction · 0.70
ctc_lossFunction · 0.70
one_hotFunction · 0.70
_simulate_errorFunction · 0.70

Calls 3

astensor1dFunction · 0.85
get_default_deviceFunction · 0.50
applyFunction · 0.50

Tested by

no test coverage detected