| 1076 | } |
| 1077 | |
| 1078 | Status InferenceContext::Subtract(DimensionHandle first, |
| 1079 | DimensionOrConstant second, |
| 1080 | DimensionHandle* out) { |
| 1081 | const int64 first_value = Value(first); |
| 1082 | const int64 second_value = Value(second); |
| 1083 | // Special cases. |
| 1084 | if (second_value == 0) { |
| 1085 | *out = first; |
| 1086 | } else if (first_value == kUnknownDim || second_value == kUnknownDim) { |
| 1087 | *out = UnknownDim(); |
| 1088 | } else { |
| 1089 | // Invariant: Both values are known, first_value is non-negative, and |
| 1090 | // second_value is positive. |
| 1091 | if (first_value < second_value) { |
| 1092 | return errors::InvalidArgument( |
| 1093 | "Negative dimension size caused by subtracting ", second_value, |
| 1094 | " from ", first_value); |
| 1095 | } |
| 1096 | *out = MakeDim(first_value - second_value); |
| 1097 | } |
| 1098 | return Status::OK(); |
| 1099 | } |
| 1100 | |
| 1101 | Status InferenceContext::Multiply(DimensionHandle first, |
| 1102 | DimensionOrConstant second, |