mindspore.dtype
- class mindspore.dtype
Data type for MindSpore.
The actual path of
dtype
is/mindspore/common/dtype.py
. Run the following command to import the package:from mindspore import dtype as mstype
Numeric Type
Currently, MindSpore supports int
type, uint
type, float
type and complex
type.
The following table lists the details.
Definition |
Description |
---|---|
|
8-bit integer |
|
16-bit integer |
|
32-bit integer |
|
64-bit integer |
|
unsigned 8-bit integer |
|
unsigned 16-bit integer |
|
unsigned 32-bit integer |
|
unsigned 64-bit integer |
|
16-bit floating-point number |
|
32-bit floating-point number |
|
64-bit floating-point number |
|
16-bit brain-floating-point number |
|
64-bit complex number |
|
128-bit complex number |
Other Type
For other defined types, see the following table.
Type |
Description |
---|---|
|
MindSpore's |
|
Boolean |
|
Integer scalar. |
|
Unsigned integer scalar. |
|
Floating-point scalar. |
|
Complex scalar. |
|
Number, including |
|
List constructed by |
|
Tuple constructed by |
|
Function. Return in two ways, when function is not None, returns Func directly, the other returns Func(args: List[T0,T1,…,Tn], retval: T) when function is None. |
|
Type definition of type. |
|
No matching return type, corresponding to the |
|
The value of a variable is used as a key of the variable in |
|
Used to store the gradient of the free variable of a function, where the key is the |
Type conversion rules
When some inputs of an operator are required to have the same target type, type promotion will be automatically performed according to the type conversion rules. If these inputs have types of different sizes and categories (where complex > float > int > bool
), they will be promoted a type with sufficient size and category.
For the type conversion rules between Tensor and Tensor, please refer to the following table. The first row and the first column in the table both represent the types of the input Tensor
, and the corresponding position in the table represents the type of the output Tensor
. -
indicates that no type promotion will be performed.
For convenience of description, bool_
is used in the table to refer to mindspore.bool_
, int8
is used to refer to mindspore.int8
, and so on.
Tensor and Tensor |
bool_ |
int8 |
int16 |
int32 |
int64 |
uint8 |
uint16 |
uint32 |
uint64 |
float16 |
bfloat16 |
float32 |
float64 |
complex64 |
complex128 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bool_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bfloat16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
complex64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
complex128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For the type conversion rules between Number and Tensor, please refer to the following table. The first row in the table indicates the type of the input Number
, and the first column indicates the types of input Tensor
. The corresponding position in the table represents the type of the output Tensor
. -
indicates that no type promotion will be performed.
Number and Tensor |
bool |
int |
float |
---|---|---|---|
bool_ |
|
|
|
int8 |
|
|
|
int16 |
|
|
|
int32 |
|
|
|
int64 |
|
|
|
uint8 |
|
|
|
uint16 |
|
|
|
uint32 |
|
|
|
uint64 |
|
|
|
float16 |
|
|
|
bfloat16 |
|
|
|
float32 |
|
|
|
float64 |
|
|
|
complex64 |
|
|
|
complex128 |
|
|
|