Graph Mode 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
numbertype, operations betweenfloat64andint32are not supported. Operators including+,-,*,/,%,**,//all support left and right operands to beboolvalue.If either operand is
tensortype, left and right operands can't both beboolvalue.The
*operation onlist/tupleandnumbermeans thatlist/tupleis copied fromnumberand then concatenated. The data type insidelistcan be any data type supported by the graph mode, and multi-layer nesting is also supported. The data type intuplemust 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
AugAssignarenumbertype, value of Number can't bebool.If all operands of
AugAssignarenumbertype, operations betweenfloat64andint32are not supported.If either operand of
AugAssignistensortype, left and right operands can't both beboolvalue.The
*=operation onlist/tupleandnumbermeans thatlist/tupleis copied fromnumberand then concatenated, and the elements of the object withinlist/tuplecan 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
andorormust be able to be converted to boolean value. For example, left operand can not be Tensor with multiple elements. If the left operand ofandororis variableTensor, the right operand must also be single-elementTensorwith 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 are ofnumbertype, value of Number can't bebool.For operators
<,<=,>,>=,!=,==, if all operands are ofnumbertype, operations betweenfloat64andint32are not supported.For operators
<,<=,>,>=,!=,==, if either operand is oftensortype, left and right operands can't both beboolvalue.For operator
==, if all operands are ofnumbertype, support bothnumberhaveboolvalue, not support only onenumberhasboolvalue.For operators
!=,==, all supported types butmstypecan compare withnone.