| 1168 | } |
| 1169 | |
| 1170 | Status CastGrad(const Scope& scope, const Operation& op, |
| 1171 | const std::vector<Output>& grad_inputs, |
| 1172 | std::vector<Output>* grad_outputs) { |
| 1173 | if (op.num_inputs() != 1) { |
| 1174 | return errors::InvalidArgument("Cast requires 2 arguments"); |
| 1175 | } |
| 1176 | if (grad_inputs.size() != 1) { |
| 1177 | return errors::InvalidArgument("Cast grad requires 1 grad input"); |
| 1178 | } |
| 1179 | |
| 1180 | auto src_type = op.input_type(0); |
| 1181 | auto dst_type = grad_inputs[0].type(); |
| 1182 | if (IsFloatingPointDtype(src_type) && IsFloatingPointDtype(dst_type)) { |
| 1183 | grad_outputs->push_back(Cast(scope, grad_inputs[0], src_type)); |
| 1184 | } else { |
| 1185 | grad_outputs->push_back(NoGradient()); |
| 1186 | } |
| 1187 | return scope.status(); |
| 1188 | } |
| 1189 | REGISTER_GRADIENT_OP("Cast", CastGrad); |
| 1190 | |
| 1191 | Status SelectGrad(const Scope& scope, const Operation& op, |
nothing calls this directly
no test coverage detected