Now only supports promotion of complex type
| 125 | |
| 126 | // Now only supports promotion of complex type |
| 127 | proto::VarType::Type PromoteTypesIfComplexExists( |
| 128 | const proto::VarType::Type type_a, const proto::VarType::Type type_b) { |
| 129 | constexpr auto f4 = proto::VarType::FP32; // 5 |
| 130 | constexpr auto f8 = proto::VarType::FP64; // 6 |
| 131 | constexpr auto c4 = proto::VarType::COMPLEX64; // 23 |
| 132 | constexpr auto c8 = proto::VarType::COMPLEX128; // 24 |
| 133 | |
| 134 | if (!NeedPromoteTypes(type_a, type_b)) { |
| 135 | // NOTE(chenweihang): keep consistent with rule in original op's impl, |
| 136 | // kernel type based on the first input tensor's dtype |
| 137 | return type_a; |
| 138 | } |
| 139 | |
| 140 | int type_an = DataTypeNumAlign(type_a); |
| 141 | int type_bn = DataTypeNumAlign(type_b); |
| 142 | |
| 143 | // Here is a complete rules table, but some rules are not used. |
| 144 | // It is still written this way because array accessing is still |
| 145 | // more efficient than if-else |
| 146 | // NOLINTBEGIN(*-avoid-c-arrays) |
| 147 | static constexpr proto::VarType::Type promote_types_table[4][4] = { |
| 148 | /* f4 f8 c4 c8*/ |
| 149 | /* f4 */ {f4, f8, c4, c8}, |
| 150 | /* f8 */ {f8, f8, c8, c8}, |
| 151 | /* c4 */ {c4, c8, c4, c8}, |
| 152 | /* c8 */ {c8, c8, c8, c8}, |
| 153 | }; |
| 154 | // NOLINTEND(*-avoid-c-arrays) |
| 155 | |
| 156 | return promote_types_table[type_an][type_bn]; |
| 157 | } |
| 158 | |
| 159 | } // namespace paddle::framework |
no test coverage detected