forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcel_function_provider.cc
More file actions
47 lines (38 loc) · 1.29 KB
/
Copy pathcel_function_provider.cc
File metadata and controls
47 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "eval/public/cel_function_provider.h"
#include "absl/status/statusor.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
namespace {
// Impl for simple provider that looks up functions in an activation function
// registry.
class ActivationFunctionProviderImpl : public CelFunctionProvider {
public:
ActivationFunctionProviderImpl() {}
absl::StatusOr<const CelFunction*> GetFunction(
const CelFunctionDescriptor& descriptor,
const BaseActivation& activation) const override {
std::vector<const CelFunction*> overloads =
activation.FindFunctionOverloads(descriptor.name());
const CelFunction* matching_overload = nullptr;
for (const CelFunction* overload : overloads) {
if (overload->descriptor().ShapeMatches(descriptor)) {
if (matching_overload != nullptr) {
return absl::Status(absl::StatusCode::kInvalidArgument,
"Couldn't resolve function.");
}
matching_overload = overload;
}
}
return matching_overload;
}
};
} // namespace
std::unique_ptr<CelFunctionProvider> CreateActivationFunctionProvider() {
return std::make_unique<ActivationFunctionProviderImpl>();
}
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google