24template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
35 validate_operation_data_types();
48 return apply_operation_internal(input, m_last_execution_context);
64 m_last_execution_context.mode = ExecutionMode::DEPENDENCY;
66 for (
auto& dep : m_dependencies) {
67 if (dep->validate_input(input)) {
68 dep->apply_operation_internal(input, m_last_execution_context);
72 m_last_execution_context.mode = ExecutionMode::SYNC;
73 return apply_operation_internal(input, m_last_execution_context);
93 return apply_operation(
input_type { data }).data;
108 [[nodiscard]]
virtual std::any
get_parameter(
const std::string& name)
const = 0;
126 [[nodiscard]]
virtual std::string
get_name()
const {
return "ComputeOperation"; }
133 m_last_execution_context.mode = ExecutionMode::DEPENDENCY;
134 return apply_operation_internal(input, m_last_execution_context);
139 m_dependencies.push_back(std::move(dep));
146 m_container = container;
156 m_last_execution_context = ctx;
161 return m_last_execution_context;
166 m_last_execution_context.pre_execution_hook = hook;
171 m_last_execution_context.post_execution_hook = hook;
176 m_last_execution_context.reconstruction_callback = callback;
195 switch (context.
mode) {
196 case ExecutionMode::ASYNC:
198 return apply_operation_async(input).get();
200 case ExecutionMode::PARALLEL:
201 return apply_operation_parallel(input, context);
203 case ExecutionMode::CHAINED:
204 return apply_operation_chained(input, context);
206 case ExecutionMode::DEPENDENCY:
207 case ExecutionMode::SYNC:
209 return apply_hooks(input, context);
218 return std::async(std::launch::async, [
this, input]() {
219 return apply_hooks(input, m_last_execution_context);
228 return apply_hooks(input, ctx);
236 return apply_hooks(input, ctx);
244 std::any any_data = metadata;
245 if (m_last_execution_context.reconstruction_callback) {
246 auto reconstructed = m_last_execution_context.reconstruction_callback(result_data, any_data);
248 return std::any_cast<output_type>(reconstructed);
249 }
catch (
const std::bad_any_cast&) {
250 std::cerr <<
"Reconstruction callback did not return the correct output type\n";
251 return OperationHelper::reconstruct_from_double<output_type>(result_data, metadata);
254 return OperationHelper::reconstruct_from_double<output_type>(result_data, metadata);
269 if constexpr (std::is_same_v<InputType, Kakshya::Region>) {
270 std::cerr <<
"OPERATION WARNING: InputType 'Region' is an expressive marker, not a data holder.\n"
271 <<
"Operations will process coordinate data rather than signal data.\n"
272 <<
"Consider using DataVariant or SignalSourceContainer for signal processing.\n";
273 }
else if constexpr (std::is_same_v<InputType, Kakshya::RegionGroup>) {
274 std::cerr <<
"OPERATION WARNING: InputType 'RegionGroup' is an expressive marker, not a data holder.\n"
275 <<
"Operations will process coordinate data rather than signal data.\n"
276 <<
"Consider using DataVariant or SignalSourceContainer for signal processing.\n";
277 }
else if constexpr (std::is_same_v<InputType, std::vector<Kakshya::RegionSegment>>) {
278 std::cerr <<
"OPERATION WARNING: InputType 'RegionSegments' are expressive markers, not primary data holders.\n"
279 <<
"Operations will attempt to extract data from segment metadata.\n"
280 <<
"Consider using DataVariant or SignalSourceContainer for direct signal processing.\n";
283 if constexpr (std::is_same_v<OutputType, Kakshya::Region>) {
284 std::cerr <<
"OPERATION INFO: OutputType 'Region' will create spatial/temporal markers with results as metadata.\n";
285 }
else if constexpr (std::is_same_v<OutputType, Kakshya::RegionGroup>) {
286 std::cerr <<
"OPERATION INFO: OutputType 'RegionGroup' will organize results into spatial/temporal groups.\n";
287 }
else if constexpr (std::is_same_v<OutputType, std::vector<Kakshya::RegionSegment>>) {
288 std::cerr <<
"OPERATION INFO: OutputType 'RegionSegments' will create segments with results in metadata.\n";
295 std::any input_any =
const_cast<input_type&
>(input);
299 auto result = operation_function(input);
302 std::any result_any = &result;
Local execution orchestrator for computational operations.
void set_last_execution_context(const ExecutionContext &ctx)
virtual void set_parameter(const std::string &name, std::any value)=0
Sets a named parameter that configures the operation's behavior.
const ExecutionContext & get_last_execution_context() const
virtual ~ComputeOperation()=default
Virtual destructor for proper cleanup of derived classes.
void set_reconstruction_callback(const ReconstructionCallback &callback)
virtual void set_container_for_regions(const std::shared_ptr< Kakshya::SignalSourceContainer > &container)
output_type apply_hooks(const input_type &input, const ExecutionContext &context)
virtual std::any get_parameter(const std::string &name) const =0
Retrieves a parameter's current value.
void set_pre_execution_hook(const OpererationHookCallback &hook)
output_type apply_operation(const input_type &input)
Public synchronous execution interface.
void validate_operation_data_types() const
Validate input/output types and warn about marker types.
OutputType apply_to_data(const InputType &data)
Convenience overload that extracts just the data from result.
ExecutionContext m_last_execution_context
virtual output_type apply_operation_internal(const input_type &input, const ExecutionContext &context)
Internal execution method - ComputeMatrix can access this.
output_type operator()(const InputType &data)
Convenience overload for direct data processing (backward compatibility)
virtual output_type operation_function(const input_type &input)=0
Executes the computational transformation on the input data.
virtual bool validate_input(const input_type &) const
Validates if the input data meets the operation's requirements.
output_type apply_operation_with_dependencies(const input_type &input)
Applies the operation with dependencies resolved.
virtual output_type apply_operation_chained(const input_type &input, const ExecutionContext &ctx)
Optional chain-aware implementation - default delegates to operation_function.
std::shared_ptr< Kakshya::SignalSourceContainer > m_container
virtual const std::shared_ptr< Kakshya::SignalSourceContainer > & get_container_for_regions() const
std::vector< std::shared_ptr< ComputeOperation > > m_dependencies
virtual std::string get_name() const
Get operation name for debugging/introspection.
void set_post_execution_hook(const OpererationHookCallback &hook)
const auto & get_dependencies() const
output_type convert_result(std::vector< std::vector< double > > &result_data, DataStructureInfo &metadata)
Convert processed double data back to OutputType using metadata and optional callback.
ComputeOperation()
Constructor with data type validation warnings.
virtual std::future< output_type > apply_operation_async(const input_type &input)
Optional async implementation - default delegates to operation_function.
virtual std::map< std::string, std::any > get_all_parameters() const
Retrieves all parameters and their values.
void add_dependency(std::shared_ptr< ComputeOperation > dep)
output_type execute(const input_type &input)
OpUnit interface - operations can act as units in dependency graphs.
virtual output_type apply_operation_parallel(const input_type &input, const ExecutionContext &ctx)
Optional parallel-aware implementation - default delegates to operation_function.
Base interface for all computational operations in the processing pipeline.
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
std::function< void(std::any &)> OpererationHookCallback
Callback type for pre/post operation hooks.
std::function< std::any(std::vector< std::vector< double > > &, std::any &)> ReconstructionCallback
Callback type for custom reconstruction logic.
Metadata about data structure for reconstruction.
OpererationHookCallback post_execution_hook
OpererationHookCallback pre_execution_hook
Context information for operation execution.
Input/Output container for computation pipeline data flow with structure preservation.