66template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
97 template <
typename ConcreteOpType>
100 static_assert(std::is_base_of_v<ComputeOperation<InputType, OutputType>, ConcreteOpType>,
101 "Operation must derive from ComputeOperation");
126 template <
typename ConcreteOpType,
typename... Args>
129 auto operation = std::make_shared<ConcreteOpType>(std::forward<Args>(args)...);
160 if (
auto best_rule =
m_grammar->find_best_match(current_data, current_context)) {
161 if (
auto rule_result =
m_grammar->execute_rule(best_rule->name, current_data, current_context)) {
162 auto cast_result = safe_any_cast<input_type>(*rule_result);
165 current_data = *cast_result.value;
170 "Grammar rule '{}' returned incompatible type: {}",
179 auto result = operation->apply_operation(current_data);
180 current_data = result;
181 }
catch (
const std::exception& e) {
184 "Pipeline operation '{}' failed: {}",
name, e.what());
188 if constexpr (std::is_same_v<InputType, OutputType>) {
203 [[nodiscard]] std::shared_ptr<ComputationGrammar>
get_grammar()
const
238 template <
typename ConcreteOpType>
242 if (op_name ==
name) {
243 return std::dynamic_pointer_cast<ConcreteOpType>(operation);
269 template <
typename ConcreteOpType>
271 const std::function<
void(std::shared_ptr<ConcreteOpType>)>& configurator)
274 if (op_name ==
name) {
275 if (
auto concrete_op = std::dynamic_pointer_cast<ConcreteOpType>(operation)) {
276 configurator(concrete_op);
313 std::vector<std::string> names;
315 std::ranges::transform(
m_operations, std::back_inserter(names),
316 [](
const auto& op_pair) {
return op_pair.second; });
331 [&
name](
const auto& op_pair) {
return op_pair.second ==
name; });
342 std::vector<std::pair<std::shared_ptr<ComputeOperation<InputType, OutputType>>, std::string>>
m_operations;
352namespace PipelineFactory {
369 template <ComputeData DataType = std::vector<Kakshya::DataVariant>>
372 auto pipeline = std::make_shared<ComputationPipeline<DataType>>();
397 template <ComputeData DataType = std::vector<Kakshya::DataVariant>>
400 auto pipeline = std::make_shared<ComputationPipeline<DataType>>();
483 template <ComputeData InputType>
489 if (
auto best_rule = m_grammar->find_best_match(
current, context)) {
490 if (
auto rule_result = m_grammar->execute_rule(best_rule->name,
current, context)) {
491 auto cast_result = safe_any_cast<Datum<InputType>>(*rule_result);
496 Journal::Component::Yantra,
497 Journal::Context::Runtime,
498 "Grammar rule '{}' returned incompatible type: {}",
517 template <ComputeData InputType>
519 const std::string& rule_name,
524 if (
auto rule_result = m_grammar->execute_rule(rule_name,
current, context)) {
525 auto cast_result = safe_any_cast<Datum<InputType>>(*rule_result);
530 Journal::Component::Yantra,
531 Journal::Context::Runtime,
532 "Grammar rule '{}' returned incompatible type: {}",
538 Journal::Component::Yantra,
539 Journal::Context::Runtime,
540 "Grammar rule '{}' not found",
567 m_grammar = std::move(grammar);
580 m_grammar->add_rule(std::move(rule));
602 return m_grammar->create_rule(
name);
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Core::GlobalInputConfig input
Fluent interface for building rules with method chaining.
Core grammar system for rule-based computation in Maya Flux.
Datum< InputType > input_type
std::shared_ptr< ConcreteOpType > get_operation(const std::string &name) const
Get operation by name.
Datum< OutputType > output_type
ComputationPipeline & create_operation(const std::string &name="", Args &&... args)
Create and add operation by type.
bool remove_operation(const std::string &name)
Remove operation by name.
std::shared_ptr< ComputationGrammar > get_grammar() const
Get the grammar instance.
void clear_operations()
Clear all operations.
size_t operation_count() const
Get number of operations in pipeline.
void set_grammar(std::shared_ptr< ComputationGrammar > grammar)
Set grammar instance.
output_type process(const input_type &input, const ExecutionContext &context={})
Execute the pipeline with grammar rule application.
std::vector< std::pair< std::shared_ptr< ComputeOperation< InputType, OutputType > >, std::string > > m_operations
Operations and their names in execution order.
std::shared_ptr< ComputationGrammar > m_grammar
Grammar instance for rule-based operation selection.
ComputationPipeline(std::shared_ptr< ComputationGrammar > grammar=nullptr)
Constructor with optional grammar.
std::vector< std::string > get_operation_names() const
Get all operation names in the pipeline.
bool configure_operation(const std::string &name, const std::function< void(std::shared_ptr< ConcreteOpType >)> &configurator)
Configure operation by name.
ComputationPipeline & add_operation(std::shared_ptr< ConcreteOpType > operation, const std::string &name="")
Add a concrete operation instance to the pipeline.
Pipeline that uses grammar rules for operation composition.
Local execution orchestrator for computational operations.
Base interface for all computational operations in the processing pipeline.
Datum< InputType > execute_with_grammar(const std::string &rule_name, const Datum< InputType > &input, const ExecutionContext &context={})
Execute a named grammar rule explicitly by name.
std::shared_ptr< ComputationGrammar > m_grammar
Grammar instance for rule-based operation selection.
void add_grammar_rule(ComputationGrammar::Rule rule)
Add a grammar rule directly to the matrix.
std::shared_ptr< ComputationGrammar > get_grammar() const
Get the grammar instance.
GrammarAwareComputeMatrix(std::shared_ptr< ComputationGrammar > grammar=nullptr)
Constructor with optional grammar.
void set_grammar(std::shared_ptr< ComputationGrammar > grammar)
Set grammar instance.
Datum< InputType > execute_with_grammar(const Datum< InputType > &input, const ExecutionContext &context={})
Execute operations with grammar rule pre-processing.
ComputationGrammar::RuleBuilder create_grammar_rule(const std::string &name)
Create a rule builder for this matrix's grammar.
ComputeMatrix extension that integrates grammar-based operation selection.
@ Runtime
General runtime operations (default fallback)
void error_rethrow(Component component, Context context, std::source_location location=std::source_location::current(), std::string_view additional_context="")
Catch and log an exception, then rethrow it.
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::shared_ptr< ComputationPipeline< DataType > > create_audio_pipeline()
Create an audio processing pipeline.
std::shared_ptr< ComputationPipeline< DataType > > create_analysis_pipeline()
Create an analysis pipeline.
Represents a computation rule with matching and execution logic.
Input/Output container for computation pipeline data flow with structure preservation.
Context information controlling how a compute operation executes.