| 32 | } |
| 33 | |
| 34 | void BinaryOpShared::SetComputeError(OpKernelContext* ctx) { |
| 35 | // For speed, errors during compute are caught only via boolean flag, with no |
| 36 | // associated information. This is sufficient for now, since the only binary |
| 37 | // ops that have compute errors are integer division and mod, and the only |
| 38 | // error they produce is zero division. |
| 39 | const string& op = ctx->op_kernel().type_string(); |
| 40 | if ((op == "Div" || op == "Mod" || op == "FloorMod" || op == "FloorDiv") && |
| 41 | DataTypeIsInteger(ctx->op_kernel().input_type(0))) { |
| 42 | ctx->CtxFailure(errors::InvalidArgument("Integer division by zero")); |
| 43 | } else if ((op == "Pow") && |
| 44 | DataTypeIsInteger(ctx->op_kernel().input_type(0)) && |
| 45 | DataTypeIsSigned(ctx->op_kernel().input_type(1))) { |
| 46 | ctx->CtxFailure(errors::InvalidArgument( |
| 47 | "Integers to negative integer powers are not allowed")); |
| 48 | } else { |
| 49 | ctx->CtxFailure( |
| 50 | errors::Internal("Unexpected error in binary operator " |
| 51 | "(only integer div and mod should have errors)")); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | BinaryOpShared::BinaryOpState::BinaryOpState(OpKernelContext* ctx) |
| 56 | : in0(ctx->input(0)), |
nothing calls this directly
no test coverage detected