Static Graph Syntax —— Operators
Arithmetic operators and assignment operators support the Number
and Tensor
operations, as well as the Tensor
operations of different dtype
.
Unary Arithmetic Operators
Unary Arithmetic Operator |
Supported Type |
---|---|
|
|
|
|
|
|
notes:
In native python the
~
operator get the bitwise inversion of its integer argument; in Mindspore the~
redefined to get logic not forTensor(Bool)
.
Binary Arithmetic Operators
Binary Arithmetic Operator |
Supported Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Restrictions:
If all operands are
Number
type, operations betweenFloat64
andInt32
are not supported. Operators including+
,-
,*
,/
,%
,**
,//
all support left and right operands to beBool
value.If either operand is
Tensor
type, left and right operands can’t both beBool
value.The
*
operation onList/Tuple
andNumber
means thatList/Tuple
is copied fromNumber
and then concatenated. The data type insideList
can be any data type supported by the graph mode, and multi-layer nesting is also supported. The data type inTuple
must beNumber
,String
,None
, and multi-layer nesting is also supported.
Assignment Operators
Assignment Operator |
Supported Type、 |
---|---|
|
All Built-in Python Types that MindSpore supported and MindSpore User-defined Data Types. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Constraints:
If all operands of
AugAssign
areNumber
type, value of Number can’t beBool
.If all operands of
AugAssign
areNumber
type, operations betweenFloat64
andInt32
are not supported.If either operand of
AugAssign
isTensor
type, left and right operands can’t both beBool
value.The
*=
operation onList/Tuple
andNumber
means thatList/Tuple
is copied fromNumber
and then concatenated, and the elements of the object withinList/Tuple
can contain any of the types supported by the intentional pattern, and multiple levels of nesting are also supported.
Logical Operators
Logical Operator |
Supported Type |
---|---|
|
|
|
|
|
|
Restrictions:
The left operand of operator
and
,or
must be able to be converted to boolean value. For example, left operand can not be Tensor with multiple elements. If the left operand ofand
,or
is variableTensor
, the right operand must also be single-elementTensor
with the same type. Otherwise, there is no requirement for right operand.
Compare Operators
Compare Operator |
Supported Type |
---|---|
|
|
|
Same as |
|
The value can only be |
|
The value can only be |
< |
|
<= |
|
> |
|
>= |
|
!= |
|
== |
|
Restrictions:
For operators
<
,<=
,>
,>=
,!=
, if all operators areNumber
type, value of Number can’t beBool
.For operators
<
,<=
,>
,>=
,!=
,==
, if all operands areNumber
type, operations betweenFloat64
andInt32
are not supported.For operators
<
,<=
,>
,>=
,!=
,==
, if either operand isTensor
type, left and right operands can’t both beBool
value.For operator
==
, if all operands areNumber
type, support bothNumber
haveBool
value, not support only oneNumber
hasBool
value.For operators
!=
,==
, all supported types butmstype
can compare withNone
.The chain comparison like:
a>b>c
is not supported.