check the validation of the Einsum equation. 1. the label must between 'a' - 'z'. 2. the dim of the same label must be same. 3. the broad cast dims in two operands is broadcastable. 4. there must exist '->' and the default output is complete in python. may be we can skip validation check in C++ and just put it in python.
| 39 | // 4. there must exist '->' and the default output is complete in python. |
| 40 | // may be we can skip validation check in C++ and just put it in python. |
| 41 | inline static void ValidationCheck(const std::string& equation) { |
| 42 | auto n_part = paddle::string::split_string(equation, "->").size(); |
| 43 | PADDLE_ENFORCE_EQ(n_part, |
| 44 | 2, |
| 45 | common::errors::InvalidArgument( |
| 46 | "Required at least one `->` in equation of EinsumOp.")); |
| 47 | size_t pos; |
| 48 | auto trimmed_equ = equation; |
| 49 | if ((pos = trimmed_equ.find("->", 0)) != std::string::npos) { |
| 50 | trimmed_equ.replace(pos, 2, ""); |
| 51 | } |
| 52 | auto is_valid_char = [](char c) { |
| 53 | if (c >= 'a' && c <= 'z') return true; |
| 54 | if (c == ',') return true; |
| 55 | return false; |
| 56 | }; |
| 57 | for (auto c : trimmed_equ) { |
| 58 | if (!is_valid_char(c)) |
| 59 | PADDLE_THROW(common::errors::InvalidArgument( |
| 60 | "Found invalid char in equation. Einsum only accept `a`-`z` and `...`" |
| 61 | "but get:`%c`", |
| 62 | c)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | enum LabelType { |
| 67 | ALL_TYPE = 0, |
no test coverage detected