| 1099 | } |
| 1100 | |
| 1101 | Status InferenceContext::Multiply(DimensionHandle first, |
| 1102 | DimensionOrConstant second, |
| 1103 | DimensionHandle* out) { |
| 1104 | const int64 first_value = Value(first); |
| 1105 | const int64 second_value = Value(second); |
| 1106 | // Special cases. |
| 1107 | if (first_value == 0) { |
| 1108 | *out = first; |
| 1109 | } else if (second_value == 0) { |
| 1110 | *out = MakeDim(second); |
| 1111 | } else if (first_value == 1) { |
| 1112 | *out = MakeDim(second); |
| 1113 | } else if (second_value == 1) { |
| 1114 | *out = first; |
| 1115 | } else if (first_value == kUnknownDim || second_value == kUnknownDim) { |
| 1116 | *out = UnknownDim(); |
| 1117 | } else { |
| 1118 | // Invariant: Both values are known and greater than 1. |
| 1119 | const int64 product = first_value * second_value; |
| 1120 | if (product < 0) { |
| 1121 | return errors::InvalidArgument( |
| 1122 | "Negative dimension size caused by overflow when multiplying ", |
| 1123 | first_value, " and ", second_value); |
| 1124 | } |
| 1125 | *out = MakeDim(product); |
| 1126 | } |
| 1127 | return Status::OK(); |
| 1128 | } |
| 1129 | |
| 1130 | Status InferenceContext::Min(DimensionHandle first, DimensionOrConstant second, |
| 1131 | DimensionHandle* out) { |