43 template <ComputeData DataType>
47 return static_cast<bool>(safe_any_cast<Datum<DataType>>(input));
58 return [required_context](
const std::any& ,
const ExecutionContext& ctx) ->
bool {
59 auto it = ctx.execution_metadata.find(
"computation_context");
60 if (it == ctx.execution_metadata.end())
62 auto result = safe_any_cast<ComputationContext>(it->second);
63 return result && *result.value == required_context;
75 return [param_name, expected_value](
const std::any& ,
const ExecutionContext& ctx) ->
bool {
76 return ctx.execution_metadata.contains(param_name) && ctx.execution_metadata.at(param_name).type() == expected_value.type();
87 return [matchers = std::move(matchers)](
const std::any& input,
const ExecutionContext& ctx) ->
bool {
88 return std::ranges::all_of(matchers, [&](
const auto& matcher) {
89 return matcher(input, ctx);
101 return [matchers = std::move(matchers)](
const std::any& input,
const ExecutionContext& ctx) ->
bool {
102 return std::ranges::any_of(matchers, [&](
const auto& matcher) {
103 return matcher(input, ctx);
119 const std::unordered_map<std::string, std::any>& parameters,
122 auto operation = std::make_shared<OperationType>(std::forward<Args>(args)...);
124 for (
const auto& [param_name, param_value] : parameters) {
126 operation->set_parameter(param_name, param_value);
131 "Parameter '{}' with type {} does not apply to operation '{}'",
133 param_value.type().name(),
134 operation->get_name());
147template <
typename OperationType>
152 operation->set_parameter(ctx_name, ctx_value);
157 "Context parameter '{}' with type {} does not apply to operation '{}'",
159 ctx_value.type().name(),
160 operation->get_name());
#define MF_DEBUG(comp, ctx,...)
static MatcherFunc combine_or(std::vector< MatcherFunc > matchers)
Combines multiple matchers with OR logic.
static MatcherFunc create_context_matcher(ComputationContext required_context)
Creates a matcher that checks for specific computation contexts.
static MatcherFunc create_type_matcher()
Creates a matcher that checks for specific data types.
std::function< bool(const std::any &, const ExecutionContext &)> MatcherFunc
static MatcherFunc combine_and(std::vector< MatcherFunc > matchers)
Combines multiple matchers with AND logic.
static MatcherFunc create_parameter_matcher(const std::string ¶m_name, const std::any &expected_value)
Creates a matcher that checks for specific parameter values.
Type-agnostic pattern matching for computation rules.
@ Runtime
General runtime operations (default fallback)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::shared_ptr< OperationType > create_configured_operation(const std::unordered_map< std::string, std::any > ¶meters, Args &&... args)
Creates an operation instance with parameters using safe_any_cast system.
@ TEMPORAL
Time-based patterns, onset detection.
@ SPATIAL
Multi-dimensional geometric analysis.
@ SPECTRAL
Spectral energy (FFT-based)
@ RECURSIVE
Recursive/nested extraction.
void apply_context_parameters(std::shared_ptr< OperationType > operation, const ExecutionContext &ctx)
Applies context parameters to an operation.
ComputationContext
Defines the computational contexts in which rules can be applied.
@ SEMANTIC
Semantic operations.
@ STRUCTURAL
Graph/tree operations.
@ LOGICAL
Boolean/conditional operations.
@ CONCURRENT
Parallel/async operations.
@ PARAMETRIC
Parameter transformation.
@ REACTIVE
Event-driven operations.
@ CONVOLUTION
Convolution-based operations.
OperationType
Operation categories for organization and discovery.
std::unordered_map< std::string, std::any > execution_metadata
Arbitrary metadata parameters used by operations.
Context information controlling how a compute operation executes.