Browse Source

fix the wrong output of some operators

tags/v1.4.0
dinglinhe 4 years ago
parent
commit
3d85948d11
5 changed files with 34 additions and 6 deletions
  1. +1
    -1
      mindspore/nn/layer/math.py
  2. +1
    -0
      mindspore/ops/operations/array_ops.py
  3. +7
    -2
      mindspore/ops/operations/debug_ops.py
  4. +24
    -2
      mindspore/ops/operations/math_ops.py
  5. +1
    -1
      mindspore/ops/operations/other_ops.py

+ 1
- 1
mindspore/nn/layer/math.py View File

@@ -957,7 +957,7 @@ class Moments(Cell):
>>> output = net(x)
>>> print(output)
(Tensor(shape=[1, 1, 1, 4], dtype=Float32, value=
[[[[ 1.00000000e+00, 2.00000000e+00, 3.00000000e+00, 4.00000000e+00]]]]),
[[[[ 2.00000000e+00, 3.00000000e+00, 4.00000000e+00, 5.00000000e+00]]]]),
Tensor(shape=[1, 1, 1, 4], dtype=Float32, value=
[[[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]]]))
>>> net = nn.Moments(axis=3, keep_dims=True)


+ 1
- 0
mindspore/ops/operations/array_ops.py View File

@@ -3114,6 +3114,7 @@ class StridedSlice(PrimitiveWithInfer):
>>> # ]
>>> # ]
>>> # The final output after finishing is:
>>> print(output)
[[[3], [5]]]
>>> # another example like :
>>> output = strided_slice(input_x, (1, 0, 0), (2, 1, 3), (1, 1, 1))


+ 7
- 2
mindspore/ops/operations/debug_ops.py View File

@@ -371,6 +371,9 @@ class Print(PrimitiveWithInfer):
- **input_x** (Union[Tensor, bool, int, float, str]) - The graph node to attach to.
Supports multiple inputs which are separated by ','.

Outputs:
Tensor, has the same data type and shape as original `input_x`.

Raises:
TypeError: If `input_x` is not one of the following: Tensor, bool, int, float, str.

@@ -392,10 +395,12 @@ class Print(PrimitiveWithInfer):
>>> net = PrintDemo()
>>> result = net(x, y)
Print Tensor x and Tensor y:
Tensor(shape=[2, 1], dtype=Int32, value=
[[1]
[1]]
[1]])
Tensor(shape=[2, 2], dtype=Int32, value=
[[1 1]
[1 1]]
[1 1]])
"""

@prim_attr_register


+ 24
- 2
mindspore/ops/operations/math_ops.py View File

@@ -198,10 +198,21 @@ class AssignAdd(PrimitiveWithInfer):
and the data type is consistent with the Tensor data type involved in the operation.
RuntimeError exception will be thrown when the data type conversion of Parameter is required.

Note:
Since `variable` is a data type Parameter, the data type cannot be changed,
so only the type of `value` is allowed to be promoted to the type of `variable`.
And the conversion type supported by different devices will be different,
it is recommended to use the same data type when using this operator.

Inputs:
- **variable** (Parameter) - The `Parameter`.
:math:`(N,*)` where :math:`*` means, any number of additional dimensions.
- **value** (Union[numbers.Number, Tensor]) - The value to be added to the `variable`.
It must have the same shape as `variable` if it is a Tensor.
it is recommended to use the same data type when using this operator.

Outputs:
Tensor, has the same data type and shape as original `variable`.

Raises:
TypeError: If `value` is neither Number nor Tensor.
@@ -224,7 +235,7 @@ class AssignAdd(PrimitiveWithInfer):
>>> value = Tensor(np.ones([1]).astype(np.int64)*100)
>>> output = net(value)
>>> print(output)
Parameter (name=global_step, shape=(1,), dtype=Int64, requires_grad=True)
[101]
"""
__mindspore_signature__ = (
sig.make_sig('x', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
@@ -257,10 +268,21 @@ class AssignSub(PrimitiveWithInfer):
and the data type is consistent with the Tensor data type involved in the operation.
RuntimeError exception will be thrown when the data type conversion of Parameter is required.

Note:
Since `variable` is a data type Parameter, the data type cannot be changed,
so only the type of `value` is allowed to be promoted to the type of `variable`.
And the conversion type supported by different devices will be different,
it is recommended to use the same data type when using this operator.

Inputs:
- **variable** (Parameter) - The `Parameter`.
:math:`(N,*)` where :math:`*` means, any number of additional dimensions.
- **value** (Union[numbers.Number, Tensor]) - The value to be subtracted from the `variable`.
It must have the same shape as `variable` if it is a Tensor.
it is recommended to use the same data type when using this operator.

Outputs:
Tensor, has the same data type and shape as original `variable`.

Raises:
TypeError: If `value` is neither Number nor Tensor.
@@ -283,7 +305,7 @@ class AssignSub(PrimitiveWithInfer):
>>> value = Tensor(np.ones([1]).astype(np.int32)*100)
>>> output = net(value)
>>> print(output)
Parameter (name=global_step, shape=(1,), dtype=Int32, requires_grad=True)
[-99]
"""

__mindspore_signature__ = (


+ 1
- 1
mindspore/ops/operations/other_ops.py View File

@@ -61,7 +61,7 @@ class Assign(Primitive):
>>> net = Net()
>>> output = net(x)
>>> print(output)
Parameter (name=y, shape=(1,), dtype=Float32, requires_grad=True)
[2.]
"""
__mindspore_signature__ = (
sig.make_sig('variable', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),


Loading…
Cancel
Save