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
.