MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / ValidationCheck

Function ValidationCheck

paddle/phi/kernels/impl/einsum_kernel_impl.h:41–64  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
41inline 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
66enum LabelType {
67 ALL_TYPE = 0,

Callers 1

EinsumKernelImplFunction · 0.85

Calls 4

split_stringFunction · 0.85
sizeMethod · 0.45
findMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected