From c5ffb4a774c161a5b9ddf2d811c0c075b7fef36c Mon Sep 17 00:00:00 2001 From: lianliguang Date: Wed, 9 Jun 2021 20:35:22 +0800 Subject: [PATCH] add example --- mindspore/ops/primitive.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mindspore/ops/primitive.py b/mindspore/ops/primitive.py index 834f4d5b280..0f64b24060a 100644 --- a/mindspore/ops/primitive.py +++ b/mindspore/ops/primitive.py @@ -187,14 +187,19 @@ class Primitive(Primitive_): Examples: >>> class AddN(Primitive): - >>> @prim_attr_register - >>> def __init__(self): - >>> self.init_prim_io_names(inputs=["inputs"], outputs=["sum"]) - >>> def check_elim(self, inputs): - >>> if len(inputs) != 1: - >>> return (False, None) - >>> if isinstance(inputs[0], Tensor): - >>> return (True, inputs[0]) + ... @prim_attr_register + ... def __init__(self): + ... self.init_prim_io_names(inputs=["inputs"], outputs=["sum"]) + ... def check_elim(self, inputs): + ... if len(inputs) != 1: + ... return (False, None) + ... if isinstance(inputs[0], Tensor): + ... return (True, inputs[0]) + >>> addn = AddN() + >>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float32 + >>> output = addn.check_elim((input_x,)) + >>> print(output) + (True, Tensor(shape = [3], dtype = Float32, value = [1,0000000e+00,2,0000000e+00,3,0000000e+00])) """ return (False, None)