MindSpore Implicit Type Conversion Operator List

Linux Ascend GPU CPU Model Development Beginner Intermediate Expert

View Source On Gitee

Implicit Type Conversion

conversion rules

  • Scalar and Tensor operations: during operation, the scalar is automatically converted to Tensor, and the data type is consistent with the Tensor data type involved in the operation; when Tensor is bool data type and the scalar is int or float, both the scalar and Tensor are converted to the Tensor with the data type of int32 or float32; when Tensor is int or uint data type and the scalar is float, both the scalar and Tensor are converted to the Tensor with the data type of float32.

  • Tensor operation of different data types: the priority of data type is bool < uint8 < int8 < int16 < int32 < int64 < float16 < float32 < float64, during the operation, first determine the data type with the relatively highest priority among the Tensors involved in the operation, and then convert the low priority data type Tensor to the relatively highest priority data type; when the Tensor of int8 and uint8 data types are operated, they are converted to int16 Tensor.

  • Data type conversion of Parameter is not supported: If inferred according to the conversion rules, RuntimeError exception will be thrown when the data type conversion of Parameter defined in the network is required.

data types involved in conversion

  • bool

  • int8

  • uint8

  • int16

  • int32

  • int64

  • float16

  • float32

  • float64

support ops

mindspore.ops.Add mindspore.ops.ApplyAdadelta mindspore.ops.ApplyAdagrad
mindspore.ops.ApplyAdagradV2 mindspore.ops.ApplyAdaMax mindspore.ops.ApplyAddSign
mindspore.ops.ApplyGradientDescent mindspore.ops.ApplyMomentum mindspore.ops.ApplyPowerSign
mindspore.ops.ApplyProximalAdagrad mindspore.ops.ApplyProximalGradientDescent mindspore.ops.ApproximateEqual
mindspore.ops.Assign mindspore.ops.AssignAdd mindspore.ops.AssignSub
mindspore.ops.Atan2 mindspore.ops.BitwiseAnd mindspore.ops.BitwiseOr
mindspore.ops.BitwiseXor mindspore.ops.Div mindspore.ops.DivNoNan
mindspore.ops.Equal mindspore.ops.FloorDiv mindspore.ops.FloorMod
mindspore.ops.FusedSparseAdam mindspore.ops.FusedSparseFtrl mindspore.ops.FusedSparseLazyAdam
mindspore.ops.FusedSparseProximalAdagrad mindspore.ops.Greater mindspore.ops.GreaterEqual
mindspore.ops.Less mindspore.ops.LessEqual mindspore.ops.LogicalAnd
mindspore.ops.LogicalOr mindspore.ops.Maximum mindspore.ops.Minimum
mindspore.ops.Mod mindspore.ops.Mul mindspore.ops.NotEqual
mindspore.ops.Pow mindspore.ops.RealDiv mindspore.ops.ScatterAdd
mindspore.ops.ScatterDiv mindspore.ops.ScatterMax mindspore.ops.ScatterMin
mindspore.ops.ScatterMul mindspore.ops.ScatterNdAdd mindspore.ops.ScatterNdSub
mindspore.ops.ScatterNdUpdate mindspore.ops.ScatterNonAliasingAdd mindspore.ops.ScatterSub
mindspore.ops.ScatterUpdate mindspore.ops.SparseApplyAdagrad mindspore.ops.SparseApplyAdagradV2
mindspore.ops.SparseApplyFtrl mindspore.ops.SparseApplyFtrlV2 mindspore.ops.SparseApplyProximalAdagrad
mindspore.ops.SquaredDifference mindspore.ops.Sub mindspore.ops.TruncateDiv
mindspore.ops.TruncateMod mindspore.ops.Xdivy mindspore.ops.Xlogy