|
|
@@ -240,32 +240,19 @@ def zeros_like(inp: Union[Tensor, SymbolVar]) -> Union[Tensor, SymbolVar]: |
|
|
|
|
|
|
|
|
|
|
|
def ones_like(inp: Union[Tensor, SymbolVar]) -> Union[Tensor, SymbolVar]: |
|
|
|
r"""Returns a ones tensor with the same shape as input tensor. |
|
|
|
r"""Returns a tensor filled with ones with the same shape and data type as input tensor. |
|
|
|
|
|
|
|
Args: |
|
|
|
inp: input tensor. |
|
|
|
inp (Tensor): input tensor. |
|
|
|
|
|
|
|
Return: |
|
|
|
output tensor. |
|
|
|
a tensor containing ones. |
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
|
|
.. testcode:: |
|
|
|
|
|
|
|
import numpy as np |
|
|
|
from megengine import tensor |
|
|
|
import megengine.functional as F |
|
|
|
|
|
|
|
inp = tensor(np.arange(1, 7, dtype=np.int32).reshape(2,3)) |
|
|
|
out = F.ones_like(inp) |
|
|
|
print(out.numpy()) |
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
|
|
.. testoutput:: |
|
|
|
|
|
|
|
[[1 1 1] |
|
|
|
[1 1 1]] |
|
|
|
>>> input = F.arange(6, dtype='int32').reshape(2,3) |
|
|
|
>>> F.ones_like(input) |
|
|
|
Tensor([[1 1 1] |
|
|
|
[1 1 1]], dtype=int32, device=xpux:0) |
|
|
|
""" |
|
|
|
return full_like(inp, 1.0) |
|
|
|
|
|
|
|