MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
UniversalTransformer.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8/**
9 * @brief Float Processing Guidelines
10 *
11 * Transformers support float data processing but with some caveats:
12 *
13 * 1. **Recommended**: Use double precision for maximum compatibility
14 * 2. **Supported**: Float processing works in most environments
15 * 3. **Warning**: Mixed float/double processing may cause memory issues
16 * 4. **Best Practice**: Stick to one numeric type per transformer instance
17 *
18 * Example safe usage:
19 * ```cpp
20 * // Good: Consistent double usage
21 * auto transformer = std::make_unique<MathematicalTransformer<>>();
22 * std::vector<double> data = {1.0, 2.0, 3.0};
23 *
24 * // Okay: Consistent float usage (with warning)
25 * auto float_transformer = std::make_unique<MathematicalTransformer<>>();
26 * std::vector<float> float_data = {1.0f, 2.0f, 3.0f};
27 *
28 * // Risky: Mixed types (may cause issues)
29 * transformer->process(double_data); // First call
30 * transformer->process(float_data); // Second call - risky!
31 * ```
32 */
33
34/**
35 * @file UniversalTransformer.hpp
36 * @brief Modern, digital-first universal transformation framework for Maya Flux
37 *
38 * The UniversalTransformer system provides a clean, extensible foundation for data transformation
39 * in the Maya Flux ecosystem. Unlike traditional audio transformers limited to analog metaphors,
40 * this embraces the digital paradigm: data-driven workflows, multi-modal transformations, and
41 * computational possibilities beyond physical analog constraints.
42 *
43 * ## Core Philosophy
44 * A transformer **modifies ComputeData** through digital-first approaches:
45 * 1. **Temporal transformations:** Time-stretching, reversing, granular manipulation
46 * 2. **Spectral transformations:** Frequency domain processing, spectral morphing, cross-synthesis
47 * 3. **Mathematical transformations:** Polynomial mapping, matrix operations, recursive algorithms
48 * 4. **Cross-modal transformations:** Audio-to-visual mapping, pattern translation between modalities
49 * 5. **Generative transformations:** AI-driven, grammar-based, stochastic transformations
50 * 6. **Multi-dimensional transformations:** N-dimensional data manipulation, spatial transformations
51 *
52 * ## Key Features
53 * - **Universal input/output:** Template-based I/O types defined at instantiation
54 * - **Type-safe transformation:** C++20 concepts and compile-time guarantees
55 * - **Transformation strategies:** In-place, buffered, streaming, recursive
56 * - **Composable operations:** Integrates with ComputeMatrix execution modes
57 * - **Digital-first design:** Embraces computational possibilities beyond analog metaphors
58 *
59 * ## Usage Examples
60 * ```cpp
61 * // Transform DataVariant containing audio/video/texture data
62 * auto transformer = std::make_shared<MyTransformer<Kakshya::DataVariant>>();
63 *
64 * // Transform signal containers with time-stretching
65 * auto time_transformer = std::make_shared<MyTransformer<
66 * std::shared_ptr<Kakshya::SignalSourceContainer>,
67 * std::shared_ptr<Kakshya::SignalSourceContainer>>>();
68 *
69 * // Transform matrices with mathematical operations
70 * auto matrix_transformer = std::make_shared<MyTransformer<
71 * Eigen::MatrixXd,
72 * Eigen::MatrixXd>>();
73 * ```
74 */
75
76namespace MayaFlux::Yantra {
77
78/**
79 * @enum TransformationType
80 * @brief Categories of transformation operations for discovery and organization
81 */
82enum class TransformationType : uint8_t {
83 TEMPORAL, ///< Time-based transformations (time-stretch, reverse, delay)
84 SPECTRAL, ///< Frequency domain transformations (pitch-shift, spectral filtering)
85 MATHEMATICAL, ///< Mathematical transformations (polynomial mapping, matrix operations)
86 CROSS_MODAL, ///< Cross-modality transformations (audio-to-visual, pattern translation)
87 GENERATIVE, ///< AI/ML-driven or algorithmic generation-based transformations
88 SPATIAL, ///< Multi-dimensional spatial transformations
89 PATTERN_BASED, ///< Pattern recognition and transformation
90 RECURSIVE, ///< Recursive/fractal transformations
91 GRANULAR, ///< Granular synthesis and micro-temporal transformations
92 CONVOLUTION, ///< Convolution-based transformations (impulse response, filters)
93 CUSTOM ///< User-defined transformation types
94};
95
96/**
97 * @enum TransformationStrategy
98 * @brief Transformation execution strategies
99 */
100enum class TransformationStrategy : uint8_t {
101 IN_PLACE, ///< Transform data in-place (modifies input)
102 BUFFERED, ///< Create transformed copy (preserves input)
103 STREAMING, ///< Stream-based transformation for large data
104 INCREMENTAL, ///< Progressive transformation with intermediate results
105 LAZY, ///< Lazy evaluation transformation (future: coroutines)
106 CHUNKED, ///< Transform in chunks for efficient processing
107 PARALLEL, ///< Parallel/concurrent transformation
108 RECURSIVE ///< Recursive transformation with feedback
109};
110
111/**
112 * @enum TransformationQuality
113 * @brief Quality vs performance trade-off control
114 */
115enum class TransformationQuality : uint8_t {
116 DRAFT, ///< Fast, low-quality transformation for previews
117 STANDARD, ///< Balanced quality/performance for real-time use
118 HIGH_QUALITY, ///< High-quality transformation, may be slower
119 REFERENCE, ///< Maximum quality, computational cost is secondary
120 ADAPTIVE ///< Quality adapts based on available computational resources
121};
122
123/**
124 * @enum TransformationScope
125 * @brief Scope control for transformation operations
126 */
127enum class TransformationScope : uint8_t {
128 FULL_DATA, ///< Transform entire data set
129 TARGETED_REGIONS, ///< Transform only specific regions
130 SELECTIVE_BANDS, ///< Transform specific frequency/spatial bands
131 CONDITIONAL ///< Transform based on dynamic conditions
132};
133
134/**
135 * @struct TransformationKey
136 * @brief Multi-dimensional transformation key specification for complex transformations
137 */
139 std::string name; ///< Unique identifier for this transformation key
140 std::function<double(const std::any&)> parameter_extractor; ///< Extract parameter value from data
141
142 uint32_t channel = 0; ///< Which channel to extract for
143 std::optional<char> axis = std::nullopt; ///< Which axis (if spatial processing)
144
145 double intensity = 1.0; ///< Transformation intensity/amount
146 double weight = 1.0; ///< Weight for multi-key transformations
147 bool normalize = false; ///< Normalize parameters before transformation
148
149 /**
150 * @brief Constructs a TransformationKey with name and extractor
151 * @param n Name identifier for the key
152 * @param e Function to extract parameter values from input data
153 */
154 TransformationKey(std::string n, std::function<double(const std::any&)> e)
155 : name(std::move(n))
156 , parameter_extractor(std::move(e))
157 {
158 }
159};
160
161/**
162 * @class UniversalTransformer
163 * @brief Template-flexible transformer base with instance-defined I/O types
164 * @tparam InputType Input data type (defaults to Kakshya::DataVariant)
165 * @tparam OutputType Output data type (defaults to InputType)
166 *
167 * The UniversalTransformer provides a clean, concept-based foundation for all transformation
168 * operations. I/O types are defined at instantiation time, providing maximum flexibility
169 * while maintaining type safety through C++20 concepts.
170 *
171 * Unlike traditional transformers that only handle simple signal processing, this embraces the
172 * digital paradigm with multi-modal transformation, cross-domain operations, and computational
173 * approaches that go beyond analog metaphors.
174 *
175 * ## Supported Transformation Types
176 * - **Temporal**: Time-domain operations (reverse, stretch, delay, fade)
177 * - **Spectral**: Frequency-domain operations (pitch shift, filtering, enhancement)
178 * - **Mathematical**: Pure mathematical operations (gain, polynomial, trigonometric)
179 * - **Convolution**: Convolution-based operations (filtering, correlation, deconvolution)
180 * - **Cross-modal**: Operations that translate between different data modalities
181 * - **Generative**: AI/ML-driven transformations and procedural generation
182 *
183 * ## Usage Patterns
184 * ```cpp
185 * // Basic mathematical transformation
186 * auto math_transformer = std::make_unique<MathematicalTransformer<>>();
187 * math_transformer->set_parameter("operation", "gain");
188 * math_transformer->set_parameter("gain_factor", 2.0);
189 *
190 * // Spectral processing with custom quality
191 * auto spectral_transformer = std::make_unique<SpectralTransformer<>>();
192 * spectral_transformer->set_quality(TransformationQuality::HIGH_QUALITY);
193 * spectral_transformer->set_strategy(TransformationStrategy::BUFFERED);
194 * ```
195 */
196template <ComputeData InputType = Kakshya::DataVariant, ComputeData OutputType = InputType>
197class MAYAFLUX_API UniversalTransformer : public ComputeOperation<InputType, OutputType> {
198public:
202
203 /**
204 * @brief Virtual destructor for proper inheritance cleanup
205 */
206 virtual ~UniversalTransformer() = default;
207
208 /**
209 * @brief Gets the transformation type category for this transformer
210 * @return TransformationType enum value indicating the category of transformation
211 *
212 * This is used for transformer discovery, organization, and determining
213 * compatibility with different processing pipelines.
214 */
215 [[nodiscard]] virtual TransformationType get_transformation_type() const = 0;
216
217 /**
218 * @brief Gets human-readable name for this transformer
219 * @return String identifier for the transformer
220 *
221 * Implementation delegates to get_transformer_name() which derived classes override.
222 * Used for debugging, logging, and user interface display.
223 */
224 [[nodiscard]] std::string get_name() const override
225 {
226 return get_transformer_name();
227 }
228
229 /**
230 * @brief Type-safe parameter management with transformation-specific defaults
231 * @param name Parameter name
232 * @param value Parameter value (type-erased)
233 *
234 * Handles core transformer parameters (strategy, quality, scope) and delegates
235 * transformer-specific parameters to set_transformation_parameter().
236 *
237 * Core parameters:
238 * - "strategy": TransformationStrategy enum or string
239 * - "quality": TransformationQuality enum or string
240 * - "scope": TransformationScope enum or string
241 */
242 void set_parameter(const std::string& name, std::any value) override
243 {
244 if (name == "strategy") {
245 auto strategy_result = safe_any_cast<TransformationStrategy>(value);
246 if (strategy_result) {
247 m_strategy = *strategy_result.value;
248 return;
249 }
250 auto str_result = safe_any_cast<std::string>(value);
251 if (str_result) {
252 auto strategy_enum = Utils::string_to_enum_case_insensitive<TransformationStrategy>(*str_result.value);
253 if (strategy_enum) {
254 m_strategy = *strategy_enum;
255 return;
256 }
257 }
258 }
259 if (name == "quality") {
260 auto quality_result = safe_any_cast<TransformationQuality>(value);
261 if (quality_result) {
262 m_quality = *quality_result.value;
263 return;
264 }
265 auto str_result = safe_any_cast<std::string>(value);
266 if (str_result) {
267 auto quality_enum = Utils::string_to_enum_case_insensitive<TransformationQuality>(*str_result.value);
268 if (quality_enum) {
269 m_quality = *quality_enum;
270 return;
271 }
272 }
273 }
274 if (name == "scope") {
275 auto scope_result = safe_any_cast<TransformationScope>(value);
276 if (scope_result) {
277 m_scope = *scope_result.value;
278 return;
279 }
280 auto str_result = safe_any_cast<std::string>(value);
281 if (str_result) {
282 auto scope_enum = Utils::string_to_enum_case_insensitive<TransformationScope>(*str_result.value);
283 if (scope_enum) {
284 m_scope = *scope_enum;
285 return;
286 }
287 }
288 }
289 set_transformation_parameter(name, std::move(value));
290 }
291
292 /**
293 * @brief Gets a parameter value by name
294 * @param name Parameter name
295 * @return Parameter value or empty std::any if not found
296 *
297 * Handles core transformer parameters and delegates to get_transformation_parameter()
298 * for transformer-specific parameters.
299 */
300 [[nodiscard]] std::any get_parameter(const std::string& name) const override
301 {
302 if (name == "strategy") {
303 return m_strategy;
304 }
305 if (name == "quality") {
306 return m_quality;
307 }
308 if (name == "scope") {
309 return m_scope;
310 }
311 return get_transformation_parameter(name);
312 }
313
314 /**
315 * @brief Gets all parameters as a map
316 * @return Map of parameter names to values
317 *
318 * Combines core transformer parameters with transformer-specific parameters.
319 * Useful for serialization, debugging, and parameter inspection.
320 */
321 [[nodiscard]] std::map<std::string, std::any> get_all_parameters() const override
322 {
323 auto params = get_transformation_parameters();
324 params["strategy"] = m_strategy;
325 params["quality"] = m_quality;
326 params["scope"] = m_scope;
327 return params;
328 }
329
330 /**
331 * @brief Sets the transformation strategy
332 * @param strategy How the transformation should be executed
333 *
334 * Strategies control memory usage, performance, and behavior:
335 * - IN_PLACE: Modify input data directly (memory efficient)
336 * - BUFFERED: Create copy for output (preserves input)
337 * - STREAMING: Process in chunks for large data
338 * - PARALLEL: Use multiple threads where possible
339 */
340 void set_strategy(TransformationStrategy strategy) { m_strategy = strategy; }
341
342 /**
343 * @brief Gets the current transformation strategy
344 * @return Current strategy setting
345 */
346 [[nodiscard]] TransformationStrategy get_strategy() const { return m_strategy; }
347
348 /**
349 * @brief Sets the transformation quality level
350 * @param quality Quality vs performance trade-off setting
351 *
352 * Quality levels control the computational cost vs result quality:
353 * - DRAFT: Fast processing for previews
354 * - STANDARD: Balanced for real-time use
355 * - HIGH_QUALITY: Better results, may be slower
356 * - REFERENCE: Maximum quality regardless of cost
357 */
358 void set_quality(TransformationQuality quality) { m_quality = quality; }
359
360 /**
361 * @brief Gets the current transformation quality level
362 * @return Current quality setting
363 */
364 [[nodiscard]] TransformationQuality get_quality() const { return m_quality; }
365
366 /**
367 * @brief Sets the transformation scope
368 * @param scope What portion of the data to transform
369 *
370 * Scope controls which parts of the input data are processed:
371 * - FULL_DATA: Process entire input
372 * - TARGETED_REGIONS: Process specific regions only
373 * - SELECTIVE_BANDS: Process specific frequency/spatial bands
374 * - CONDITIONAL: Process based on dynamic conditions
375 */
376 void set_scope(TransformationScope scope) { m_scope = scope; }
377
378 /**
379 * @brief Gets the current transformation scope
380 * @return Current scope setting
381 */
382 [[nodiscard]] TransformationScope get_scope() const { return m_scope; }
383
384 /**
385 * @brief Set transformation intensity (0.0 = no transformation, 1.0 = full transformation)
386 * @param intensity Intensity value (clamped to 0.0-2.0 range)
387 *
388 * Intensity controls how strongly the transformation is applied:
389 * - 0.0: No transformation (passthrough)
390 * - 1.0: Full transformation as configured
391 * - >1.0: Extreme/exaggerated transformation (up to 2.0)
392 */
393 void set_intensity(double intensity)
394 {
395 m_intensity = std::clamp(intensity, 0.0, 2.0); // Allow > 1.0 for extreme transformations
396 }
397
398 /**
399 * @brief Gets the current transformation intensity
400 * @return Current intensity value (0.0-2.0)
401 */
402 [[nodiscard]] double get_intensity() const { return m_intensity; }
403
404 /**
405 * @brief Add transformation key for multi-dimensional transformations
406 * @param key Transformation key specification
407 *
408 * Transformation keys enable complex, multi-parameter transformations where
409 * different aspects of the input data control different transformation parameters.
410 * Useful for data-driven and adaptive transformations.
411 */
413 {
414 m_transformation_keys.push_back(key);
415 }
416
417 /**
418 * @brief Clear all transformation keys
419 *
420 * Removes all transformation keys, returning to simple parameter-based operation.
421 */
423 {
424 m_transformation_keys.clear();
425 }
426
427 /**
428 * @brief Get all transformation keys
429 * @return Vector of current transformation keys
430 */
431 [[nodiscard]] const std::vector<TransformationKey>& get_transformation_keys() const
432 {
433 return m_transformation_keys;
434 }
435
436 /**
437 * @brief Set a custom transformation function for mathematical transformations
438 * @tparam T Data type for the custom function
439 * @param func Custom transformation function
440 *
441 * Allows injection of custom transformation logic for specialized use cases.
442 * The function will be called for each data element during transformation.
443 */
444 template <ComputeData T>
445 void set_custom_function(std::function<T(const T&)> func)
446 {
447 m_custom_function = [func](const std::any& a) -> std::any {
448 auto val_result = safe_any_cast<T>(a);
449 if (val_result) {
450 return func(*val_result);
451 }
452 return a; // Return unchanged if cast fails
453 };
454 }
455
456 /**
457 * @brief Indicates whether the transformation modifies the input data directly
458 * @return True if the operation modifies input in-place, false if it creates a new output
459 *
460 * This is determined by the current transformation strategy. IN_PLACE strategy
461 * modifies input directly, while other strategies preserve the input.
462 */
463 [[nodiscard]] virtual bool is_in_place() const { return m_strategy == TransformationStrategy::IN_PLACE; }
464
465 /**
466 * @brief Reports the current progress of a long-running transformation
467 * @return Progress value between 0.0 (not started) and 1.0 (completed)
468 *
469 * Base implementation returns 1.0 (completed). Derived classes can override
470 * to provide actual progress reporting for long-running operations.
471 */
472 [[nodiscard]] virtual double get_transformation_progress() const { return 1.0; }
473
474 /**
475 * @brief Estimates the computational cost of the transformation
476 * @return Relative cost factor (1.0 = standard, >1.0 = more expensive, <1.0 = cheaper)
477 *
478 * Base implementation returns 1.0. Derived classes should override to provide
479 * realistic cost estimates for scheduling and resource allocation.
480 */
481 [[nodiscard]] virtual double estimate_computational_cost() const { return 1.0; }
482
483protected:
484 /**
485 * @brief Core operation implementation - called by ComputeOperation interface
486 * @param input Input data with metadata
487 * @return Output data with metadata
488 *
489 * This is the main entry point called by the ComputeOperation framework.
490 * It validates input, delegates to transform_implementation(), and applies
491 * scope/quality processing to the result.
492 */
494 {
495 if (!validate_input(input)) {
496 return create_safe_output(input);
497 }
498 auto raw_result = transform_implementation(const_cast<input_type&>(input));
499 return apply_scope_and_quality_processing(raw_result);
500 }
501
502 /**
503 * @brief Pure virtual transformation implementation - derived classes implement this
504 * @param input Input data with metadata (may be modified for in-place operations)
505 * @return Raw transformation output before scope/quality processing
506 *
507 * This is where derived transformers implement their core transformation logic.
508 * The input may be modified for in-place operations. The result will be
509 * post-processed based on scope and quality settings.
510 */
512
513 /**
514 * @brief Get transformer-specific name (derived classes override this)
515 * @return Transformer name string
516 *
517 * Derived classes should override this to provide meaningful names like
518 * "MathematicalTransformer_GAIN" or "SpectralTransformer_PITCH_SHIFT".
519 */
520 [[nodiscard]] virtual std::string get_transformer_name() const { return "UniversalTransformer"; }
521
522 /**
523 * @brief Transformation-specific parameter handling (override for custom parameters)
524 * @param name Parameter name
525 * @param value Parameter value
526 *
527 * Base implementation stores parameters in a map. Derived classes should override
528 * to handle transformer-specific parameters with proper type checking and validation.
529 */
530 virtual void set_transformation_parameter(const std::string& name, std::any value)
531 {
532 m_parameters[name] = std::move(value);
533 }
534
535 /**
536 * @brief Gets a transformation-specific parameter value
537 * @param name Parameter name
538 * @return Parameter value or empty std::any if not found
539 */
540 [[nodiscard]] virtual std::any get_transformation_parameter(const std::string& name) const
541 {
542 auto it = m_parameters.find(name);
543 return (it != m_parameters.end()) ? it->second : std::any {};
544 }
545
546 /**
547 * @brief Gets all transformation-specific parameters
548 * @return Map of transformer-specific parameter names to values
549 */
550 [[nodiscard]] virtual std::map<std::string, std::any> get_transformation_parameters() const
551 {
552 return m_parameters;
553 }
554
555 /**
556 * @brief Apply scope and quality filtering to the transformation result
557 * @param result Raw transformation result
558 * @return Processed result with scope and quality adjustments applied
559 *
560 * Base implementation returns the result unchanged. Derived classes can override
561 * to implement scope-specific processing (e.g., regional transforms) and
562 * quality adjustments (e.g., interpolation quality, precision control).
563 */
565 {
566 return result;
567 }
568
569 /**
570 * @brief Helper method to apply transformation keys to extract parameters
571 * @param input Input data to extract parameters from
572 * @return Vector of extracted parameter values
573 *
574 * Processes all transformation keys to extract parameter values from the input data.
575 * Applies normalization, intensity, and weight adjustments as configured.
576 * Used for data-driven and adaptive transformations.
577 */
578 std::vector<double> extract_transformation_parameters(const input_type& input) const
579 {
580 std::vector<double> parameters;
581 parameters.reserve(m_transformation_keys.size());
582
583 for (const auto& key : m_transformation_keys) {
584 try {
585 double param {};
586 if (key.axis.has_value()) {
587 // TODO: Implement dimension validation
588 } else {
589 param = key.parameter_extractor(input.data[key.channel]);
590 }
591 if (key.normalize) {
592 param = std::clamp(param, 0.0, 1.0);
593 }
594 parameters.push_back(param * key.intensity * key.weight);
595 } catch (...) {
596 parameters.push_back(0.0);
597 }
598 }
599
600 return parameters;
601 }
602
603 /**
604 * @brief Basic input validation that derived classes can override
605 * @param input Input data to validate
606 * @return true if input is valid for processing, false otherwise
607 *
608 * Base implementation checks for:
609 * - Non-empty data
610 * - Basic data type validity
611 * - Finite values (no NaN/infinity in sample data)
612 *
613 * Derived transformers can override to add specific requirements
614 * (e.g., minimum size for spectral operations, specific data structure requirements).
615 */
616 bool validate_input(const input_type& input) const override
617 {
618 if constexpr (RequiresContainer<InputType>) {
619 if (!input.has_container()) {
620 return false;
621 }
622 auto numeric_data = OperationHelper::extract_numeric_data(input.data, input.container.value());
623 return validate_multi_channel_data(numeric_data);
624 } else {
625 auto numeric_data = OperationHelper::extract_numeric_data(input.data);
626 return validate_multi_channel_data(numeric_data);
627 }
628 }
629
630private:
631 /**
632 * @brief Creates a safe fallback output when input validation fails
633 * @param input Original input (for type/structure reference)
634 * @return Safe output that won't cause further processing errors
635 *
636 * The behavior is:
637 * - For same input/output types: return input unchanged
638 * - For type conversion: create appropriate empty/minimal output
639 * - Always preserves metadata structure
640 * - Adds metadata indicating validation failure
641 */
643 {
644 output_type result;
645
646 result.dimensions = input.dimensions;
647 result.modality = input.modality;
648 result.metadata = input.metadata;
649 result.metadata["validation_failed"] = true;
650 result.metadata["fallback_reason"] = "Input validation failed";
651
652 if constexpr (std::is_same_v<InputType, OutputType>) {
653 result.data = input.data;
654 } else {
655 if constexpr (RequiresContainer<InputType>) {
656 if (!input.has_container()) {
657 result.container = std::make_shared<Kakshya::SignalSourceContainer>();
658 } else {
659 result.container = input.container;
660 }
661 }
662 result.data = {};
663 }
664
665 return result;
666 }
667
668 /**
669 * @brief Validates multi-channel numeric data for NaN/Infinity values
670 * @param channels Vector of spans representing each channel's data
671 * @return true if all channels are valid, false if any contain invalid values
672 *
673 * Checks each channel's samples to ensure they are finite numbers.
674 * Empty channels are considered valid.
675 */
676 [[nodiscard]] bool validate_multi_channel_data(const std::vector<std::span<double>>& channels) const
677 {
678 if (channels.empty()) {
679 return false;
680 }
681
682 for (const auto& channel : channels) {
683 if (channel.empty()) {
684 continue;
685 }
686
687 for (double sample : channel) {
688 if (std::isnan(sample)) {
689 return false;
690 }
691 if (std::isinf(sample)) {
692 return false;
693 }
694 }
695 }
696
697 return true;
698 }
699
700 /** @brief Core transformation configuration */
701 TransformationStrategy m_strategy = TransformationStrategy::BUFFERED; ///< Current execution strategy
702 TransformationQuality m_quality = TransformationQuality::STANDARD; ///< Current quality level
703 TransformationScope m_scope = TransformationScope::FULL_DATA; ///< Current processing scope
704 double m_intensity = 1.0; ///< Transformation intensity (0.0-2.0)
705
706 /** @brief Multi-dimensional transformation keys */
707 std::vector<TransformationKey> m_transformation_keys; ///< Keys for data-driven transformations
708
709 /** @brief Custom transformation function for mathematical operations */
710 std::function<std::any(const std::any&)> m_custom_function; ///< User-defined transformation function
711
712 /** @brief Generic parameter storage for transformer-specific settings */
713 std::map<std::string, std::any> m_parameters; ///< Transformer-specific parameter storage
714};
715
716} // namespace MayaFlux::Yantra
Base interface for all computational operations in the processing pipeline.
virtual ~UniversalTransformer()=default
Virtual destructor for proper inheritance cleanup.
std::vector< double > extract_transformation_parameters(const input_type &input) const
Helper method to apply transformation keys to extract parameters.
bool validate_input(const input_type &input) const override
Basic input validation that derived classes can override.
std::any get_parameter(const std::string &name) const override
Gets a parameter value by name.
virtual double estimate_computational_cost() const
Estimates the computational cost of the transformation.
output_type operation_function(const input_type &input) override
Core operation implementation - called by ComputeOperation interface.
virtual double get_transformation_progress() const
Reports the current progress of a long-running transformation.
const std::vector< TransformationKey > & get_transformation_keys() const
Get all transformation keys.
void set_strategy(TransformationStrategy strategy)
Sets the transformation strategy.
TransformationScope get_scope() const
Gets the current transformation scope.
TransformationQuality get_quality() const
Gets the current transformation quality level.
virtual TransformationType get_transformation_type() const =0
Gets the transformation type category for this transformer.
void clear_transformation_keys()
Clear all transformation keys.
TransformationStrategy get_strategy() const
Gets the current transformation strategy.
void set_intensity(double intensity)
Set transformation intensity (0.0 = no transformation, 1.0 = full transformation)
void set_scope(TransformationScope scope)
Sets the transformation scope.
virtual bool is_in_place() const
Indicates whether the transformation modifies the input data directly.
virtual std::any get_transformation_parameter(const std::string &name) const
Gets a transformation-specific parameter value.
void set_custom_function(std::function< T(const T &)> func)
Set a custom transformation function for mathematical transformations.
std::vector< TransformationKey > m_transformation_keys
Multi-dimensional transformation keys.
void set_parameter(const std::string &name, std::any value) override
Type-safe parameter management with transformation-specific defaults.
bool validate_multi_channel_data(const std::vector< std::span< double > > &channels) const
Validates multi-channel numeric data for NaN/Infinity values.
void set_quality(TransformationQuality quality)
Sets the transformation quality level.
virtual output_type apply_scope_and_quality_processing(const output_type &result)
Apply scope and quality filtering to the transformation result.
std::string get_name() const override
Gets human-readable name for this transformer.
virtual std::map< std::string, std::any > get_transformation_parameters() const
Gets all transformation-specific parameters.
std::map< std::string, std::any > m_parameters
Generic parameter storage for transformer-specific settings.
double get_intensity() const
Gets the current transformation intensity.
virtual std::string get_transformer_name() const
Get transformer-specific name (derived classes override this)
std::function< std::any(const std::any &)> m_custom_function
Custom transformation function for mathematical operations.
void add_transformation_key(const TransformationKey &key)
Add transformation key for multi-dimensional transformations.
output_type create_safe_output(const input_type &input) const
Creates a safe fallback output when input validation fails.
virtual void set_transformation_parameter(const std::string &name, std::any value)
Transformation-specific parameter handling (override for custom parameters)
std::map< std::string, std::any > get_all_parameters() const override
Gets all parameters as a map.
virtual output_type transform_implementation(input_type &input)=0
Pure virtual transformation implementation - derived classes implement this.
Template-flexible transformer base with instance-defined I/O types.
@ TEMPORAL
Time-based patterns, onset detection.
@ CUSTOM
User-defined analysis types.
@ SPATIAL
Multi-dimensional geometric analysis.
@ SPECTRAL
Spectral energy (FFT-based)
@ RECURSIVE
Recursive/nested extraction.
@ PATTERN_BASED
Extract based on pattern recognition.
@ CONVOLUTION
Convolution-based operations.
TransformationScope
Scope control for transformation operations.
@ SELECTIVE_BANDS
Transform specific frequency/spatial bands.
@ CONDITIONAL
Transform based on dynamic conditions.
TransformationQuality
Quality vs performance trade-off control.
@ HIGH_QUALITY
High-quality transformation, may be slower.
@ DRAFT
Fast, low-quality transformation for previews.
@ ADAPTIVE
Quality adapts based on available computational resources.
@ REFERENCE
Maximum quality, computational cost is secondary.
@ IN_PLACE
Sort data in-place (modifies input)
@ CROSS_MODAL
Sort one modality by features of another.
@ STANDARD
std::sort with comparator
@ PARALLEL
Parallel with other operations.
TransformationType
Categories of transformation operations for discovery and organization.
@ GENERATIVE
AI/ML-driven or algorithmic generation-based transformations.
@ GRANULAR
Granular synthesis and micro-temporal transformations.
@ MATHEMATICAL
Mathematical transformations (polynomial mapping, matrix operations)
TransformationStrategy
Transformation execution strategies.
@ BUFFERED
Create transformed copy (preserves input)
@ LAZY
Lazy evaluation transformation (future: coroutines)
@ CHUNKED
Transform in chunks for efficient processing.
@ INCREMENTAL
Progressive transformation with intermediate results.
@ STREAMING
Stream-based transformation for large data.
@ FULL_DATA
Extract all available data.
@ TARGETED_REGIONS
Extract only specific regions.
bool has_container() const
Check if a container reference is associated.
Definition DataIO.hpp:155
T data
The actual computation data.
Definition DataIO.hpp:25
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Definition DataIO.hpp:28
std::optional< std::shared_ptr< Kakshya::SignalSourceContainer > > container
Optional reference to container, required for regions.
Definition DataIO.hpp:31
std::vector< Kakshya::DataDimension > dimensions
Data dimensional structure.
Definition DataIO.hpp:26
Kakshya::DataModality modality
Data modality (audio, image, spectral, etc.)
Definition DataIO.hpp:27
Input/Output container for computation pipeline data flow with structure preservation.
Definition DataIO.hpp:24
std::string name
Unique identifier for this transformation key.
bool normalize
Normalize parameters before transformation.
double intensity
Transformation intensity/amount.
double weight
Weight for multi-key transformations.
TransformationKey(std::string n, std::function< double(const std::any &)> e)
Constructs a TransformationKey with name and extractor.
std::optional< char > axis
Which axis (if spatial processing)
std::function< double(const std::any &)> parameter_extractor
Extract parameter value from data.
uint32_t channel
Which channel to extract for.
Multi-dimensional transformation key specification for complex transformations.