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 gets the bitwise inversion of its integer argument; in MindSpore,~is redefined to get logical 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 beboolvalues.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, the 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 graph mode, 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 a boolean value. For example, the left operand cannot be a Tensor with multiple elements. If the left operand ofandororis a variableTensor, the right operand must also be a single-elementTensorwith the same type. Otherwise, there is no requirement for the 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 operands are ofNumbertype, the 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, bothNumberoperands can haveboolvalues, but having only oneNumberwith aboolvalue is not supported.For operators
!=,==, all supported types exceptmstypecan be compared withNone.