Validate that an Einsum subscript contains exactly one or zero ellipsis; and that periods (.) occur only within an ellipses (...).
| 277 | // Validate that an Einsum subscript contains exactly one or zero ellipsis; and |
| 278 | // that periods (.) occur only within an ellipses (...). |
| 279 | Status ValidateEinsumEllipsis(absl::string_view subscript, |
| 280 | bool* found_ellipsis) { |
| 281 | const int num_periods = absl::c_count(subscript, '.'); |
| 282 | if (num_periods != 0 && num_periods != 3) { |
| 283 | return errors::InvalidArgument( |
| 284 | "Expected at most one ellipsis (...), but found ", num_periods, |
| 285 | " periods (.) in the input subscript: ", subscript); |
| 286 | } |
| 287 | if (num_periods == 3 && !absl::StrContains(subscript, "...")) { |
| 288 | return errors::InvalidArgument( |
| 289 | "Periods found outside of ellipsis in subscript: ", subscript); |
| 290 | } |
| 291 | *found_ellipsis = num_periods > 0; |
| 292 | return Status::OK(); |
| 293 | } |
| 294 | |
| 295 | } // namespace |
| 296 |
no test coverage detected