107 {
109 [only, factory = std::move(factory), priority](
110 const ComputationSignature& signature, const OperationConfig* supplied) -> std::optional<Binding> {
111 const auto selection = signature.template selection<E>(0);
112 if (signature.size() != 1 || !selection || (only && *only != *selection)) {
113 return std::nullopt;
114 }
115 Config config {};
116 if (supplied) {
117 if constexpr (std::same_as<Config, OperationConfig>) {
118 config = *supplied;
119 } else {
120 const auto* typed = supplied->template get<Config>();
121 if (!typed) {
122 return std::nullopt;
123 }
124 config = *typed;
125 }
126 }
127 if constexpr (
requires { config.method = *
selection; }
128 ||
requires { config.operation = *
selection; }
129 ||
requires { config.algorithm = *
selection; }) {
131 } else if (!only) {
133 std::source_location::current(),
134 "Catalog a single enum selection for an implementation without a method selector");
135 }
136 std::shared_ptr<Op> operation;
137 if (factory) {
138 operation = factory(config);
139 } else if constexpr (std::constructible_from<Op, Config>) {
140 operation = std::make_shared<Op>(config);
141 } else if constexpr (std::default_initializable<Op>) {
142 operation = std::make_shared<Op>();
143 } else {
145 std::source_location::current(), "Catalog a factory for this operation");
146 }
147 if (!operation) {
149 std::source_location::current(), "Catalog factory returned no operation");
150 }
151 if constexpr (requires { operation->set_config(config); }) {
152 operation->set_config(config);
153 }
154 using Input = std::remove_cvref_t<decltype(std::declval<typename Op::input_type>().data)>;
155 using Output = std::remove_cvref_t<decltype(std::declval<typename Op::output_type>().data)>;
156 std::shared_ptr<ComputeOperation<Input, Output>> base = std::move(operation);
158 .type = std::type_index(typeid(Op)),
159 .matcher = [base](const std::any& input, const ExecutionContext&) {
160 const auto* typed = std::any_cast<typename Op::input_type>(&input);
161 return typed && base->validate_input(*typed);
162 },
163 .executor = [base](const std::any& input, const ExecutionContext& ctx) -> std::any {
165 base->set_last_execution_context(ctx);
166 return base->apply_operation(safe_any_cast_or_throw<typename Op::input_type>(input));
167 },
168 .priority = priority,
172 };
173 });
174 return *this;
175 }
std::vector< Registration > m_registrations
@ Runtime
General runtime operations (default fallback).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::optional< std::pair< size_t, size_t > > selection(const EditableText &s)
The selected byte range as (begin, end), begin first whichever end the cursor is, or nullopt when not...
void apply_context_parameters(std::shared_ptr< OperationType > operation, const ExecutionContext &ctx)
Applies context settings to an operation.
constexpr Target target_of_v
The target an operation class declares through static constexpr Target target, or the CPU when it dec...
constexpr bool stateful_v
Whether the class keeps state between calls and must stay on its candidate.
Fitness fitness_of()
The candidate's fitness for an erased input.
Config select_operation(E selection, Config config)
Set the config's method selector from its corresponding operation enum.
A constructed implementation with its erased input and execution contracts.