Browse Source

!9847 Change example for seed.py and api.py to pass doctest

From: @liangzhibo
Reviewed-by: @zhunaipan,@zh_qh
Signed-off-by: @zh_qh
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
34a9c03f6e
3 changed files with 9 additions and 8 deletions
  1. +3
    -3
      mindspore/common/api.py
  2. +5
    -4
      mindspore/common/seed.py
  3. +1
    -1
      mindspore/common/tensor.py

+ 3
- 3
mindspore/common/api.py View File

@@ -235,18 +235,18 @@ def ms_function(fn=None, obj=None, input_signature=None):
>>> from mindspore.ops import functional as F
...
>>> def tensor_add(x, y):
... z = F.tensor_add(x, y)
... z = x + y
... return z
...
>>> @ms_function
... def tensor_add_with_dec(x, y):
... z = F.tensor_add(x, y)
... z = x + y
... return z
...
>>> @ms_function(input_signature=(MetaTensor(mindspore.float32, (1, 1, 3, 3)),
... MetaTensor(mindspore.float32, (1, 1, 3, 3))))
... def tensor_add_with_sig(x, y):
... z = F.tensor_add(x, y)
... z = x + y
... return z
...
>>> x = Tensor(np.ones([1, 1, 3, 3]).astype(np.float32))


+ 5
- 4
mindspore/common/seed.py View File

@@ -78,7 +78,7 @@ def set_seed(seed):
>>> w1 = Parameter(initializer("uniform", [2, 2], ms.float32), name="w1") # W3
>>> w1 = Parameter(initializer("uniform", [2, 2], ms.float32), name="w1") # W4
>>>
>>> 2. If global seed is set, numpy.random and initializer will use it:
>>> # 2. If global seed is set, numpy.random and initializer will use it:
>>> set_seed(1234)
>>> np_1 = np.random.normal(0, 1, [1]).astype(np.float32) # A1
>>> np_1 = np.random.normal(0, 1, [1]).astype(np.float32) # A2
@@ -95,7 +95,7 @@ def set_seed(seed):
>>> # mindspore.nn.probability.distribution will choose a random seed:
>>> c1 = C.uniform((1, 4), minval, maxval) # C1
>>> c2 = C.uniform((1, 4), minval, maxval) # C2
>>> Rerun the program will get different results:
>>> # Rerun the program will get different results:
>>> c1 = C.uniform((1, 4), minval, maxval) # C3
>>> c2 = C.uniform((1, 4), minval, maxval) # C4
>>>
@@ -118,7 +118,7 @@ def set_seed(seed):
>>> set_seed(1234)
>>> c1 = C.uniform((1, 4), minval, maxval, seed=2) # C1
>>> c2 = C.uniform((1, 4), minval, maxval, seed=2) # C2
>>> Rerun the program will get the same results:
>>> # Rerun the program will get the same results:
>>> set_seed(1234)
>>> c1 = C.uniform((1, 4), minval, maxval, seed=2) # C1
>>> c2 = C.uniform((1, 4), minval, maxval, seed=2) # C2
@@ -235,7 +235,8 @@ def _get_graph_seed(op_seed, kernel_name):
Interger. The current graph-level seed.

Examples:
>>> _get_graph_seed(seed, 'normal')
>>> print(_get_graph_seed(0, 'normal'))
(0, 0)
"""
global_seed = get_seed()
if global_seed == 0:


+ 1
- 1
mindspore/common/tensor.py View File

@@ -301,7 +301,7 @@ class Tensor(Tensor_):
Reshape the tensor according to the input shape.

Args:
shape (Union(list[int], \*int)): Dimension of the output tensor.
shape (Union(tuple[int], \*int)): Dimension of the output tensor.

Returns:
Tensor, has the same dimension as the input shape.


Loading…
Cancel
Save