MayaFlux 1.0.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 * @struct TransformerConfig
163 * @brief Initial settings shared by concrete transformer families.
164 * @tparam Operation Operation enum of the selected transformer family.
165 *
166 * Pass this aggregate with designated initializers to a concrete transformer.
167 * Named parameters are applied after the typed settings and keys.
168 */
169template <typename Operation>
171 /** Operation to perform within the selected family. */
172 Operation operation {};
173 /** How transformation work is performed. */
175 /** Requested transformation quality. */
177 /** Portion of the input to transform. */
179 /** Overall transformation strength. */
180 double intensity { 1.0 };
181 /** Transformation keys to register before processing. */
182 std::vector<TransformationKey> keys;
183 /** Additional named parameters applied last. */
184 std::map<std::string, std::any> parameters;
185};
186
187/**
188 * @class UniversalTransformer
189 * @brief Template-flexible transformer base with instance-defined I/O types
190 * @tparam InputType Input data type (defaults to Kakshya::DataVariant)
191 * @tparam OutputType Output data type (defaults to InputType)
192 *
193 * The UniversalTransformer provides a clean, concept-based foundation for all transformation
194 * operations. I/O types are defined at instantiation time, providing maximum flexibility
195 * while maintaining type safety through C++20 concepts.
196 *
197 * Unlike traditional transformers that only handle simple signal processing, this embraces the
198 * digital paradigm with multi-modal transformation, cross-domain operations, and computational
199 * approaches that go beyond analog metaphors.
200 *
201 * ## Supported Transformation Types
202 * - **Temporal**: Time-domain operations (reverse, stretch, delay, fade)
203 * - **Spectral**: Frequency-domain operations (pitch shift, filtering, enhancement)
204 * - **Mathematical**: Pure mathematical operations (gain, polynomial, trigonometric)
205 * - **Convolution**: Convolution-based operations (filtering, correlation, deconvolution)
206 * - **Cross-modal**: Operations that translate between different data modalities
207 * - **Generative**: AI/ML-driven transformations and procedural generation
208 *
209 * ## Usage Patterns
210 * ```cpp
211 * // Basic mathematical transformation
212 * auto math_transformer = std::make_unique<MathematicalTransformer<>>();
213 * math_transformer->set_parameter("operation", "gain");
214 * math_transformer->set_parameter("gain_factor", 2.0);
215 *
216 * // Spectral processing with custom quality
217 * auto spectral_transformer = std::make_unique<SpectralTransformer<>>();
218 * spectral_transformer->set_quality(TransformationQuality::HIGH_QUALITY);
219 * spectral_transformer->set_strategy(TransformationStrategy::BUFFERED);
220 * ```
221 */
222template <ComputeData InputType = Kakshya::DataVariant, ComputeData OutputType = InputType>
223class UniversalTransformer : public ComputeOperation<InputType, OutputType> {
224public:
228
229 /**
230 * @brief Virtual destructor for proper inheritance cleanup
231 */
232 virtual ~UniversalTransformer() = default;
233
234 /**
235 * @brief Gets the transformation type category for this transformer
236 * @return TransformationType enum value indicating the category of transformation
237 *
238 * This is used for transformer discovery, organization, and determining
239 * compatibility with different processing pipelines.
240 */
241 [[nodiscard]] virtual TransformationType get_transformation_type() const = 0;
242
243 /**
244 * @brief Gets human-readable name for this transformer
245 * @return String identifier for the transformer
246 *
247 * Implementation delegates to get_transformer_name() which derived classes override.
248 * Used for debugging, logging, and user interface display.
249 */
250 [[nodiscard]] std::string get_name() const override
251 {
252 return get_transformer_name();
253 }
254
255 [[nodiscard]] OperationType get_operation_type() const override
256 {
258 }
259
260 /**
261 * @brief Type-safe parameter management with transformation-specific defaults
262 * @param name Parameter name
263 * @param value Parameter value (type-erased)
264 *
265 * Handles core transformer parameters (strategy, quality, scope) and delegates
266 * transformer-specific parameters to set_transformation_parameter().
267 *
268 * Core parameters:
269 * - "strategy": TransformationStrategy enum or string
270 * - "quality": TransformationQuality enum or string
271 * - "scope": TransformationScope enum or string
272 */
273 void set_parameter(const std::string& name, std::any value) override
274 {
275 if (name == "strategy") {
276 auto strategy_result = safe_any_cast<TransformationStrategy>(value);
277 if (strategy_result) {
278 m_strategy = *strategy_result.value;
279 return;
280 }
281 auto str_result = safe_any_cast<std::string>(value);
282 if (str_result) {
283 auto strategy_enum = Reflect::string_to_enum_case_insensitive<TransformationStrategy>(*str_result.value);
284 if (strategy_enum) {
285 m_strategy = *strategy_enum;
286 return;
287 }
288 }
289 }
290 if (name == "quality") {
291 auto quality_result = safe_any_cast<TransformationQuality>(value);
292 if (quality_result) {
293 m_quality = *quality_result.value;
294 return;
295 }
296 auto str_result = safe_any_cast<std::string>(value);
297 if (str_result) {
298 auto quality_enum = Reflect::string_to_enum_case_insensitive<TransformationQuality>(*str_result.value);
299 if (quality_enum) {
300 m_quality = *quality_enum;
301 return;
302 }
303 }
304 }
305 if (name == "scope") {
306 auto scope_result = safe_any_cast<TransformationScope>(value);
307 if (scope_result) {
308 m_scope = *scope_result.value;
309 return;
310 }
311 auto str_result = safe_any_cast<std::string>(value);
312 if (str_result) {
313 auto scope_enum = Reflect::string_to_enum_case_insensitive<TransformationScope>(*str_result.value);
314 if (scope_enum) {
315 m_scope = *scope_enum;
316 return;
317 }
318 }
319 }
321 }
322
323 /**
324 * @brief Gets a parameter value by name
325 * @param name Parameter name
326 * @return Parameter value or empty std::any if not found
327 *
328 * Handles core transformer parameters and delegates to get_transformation_parameter()
329 * for transformer-specific parameters.
330 */
331 [[nodiscard]] std::any get_parameter(const std::string& name) const override
332 {
333 if (name == "strategy") {
334 return m_strategy;
335 }
336 if (name == "quality") {
337 return m_quality;
338 }
339 if (name == "scope") {
340 return m_scope;
341 }
343 }
344
345 /**
346 * @brief Gets all parameters as a map
347 * @return Map of parameter names to values
348 *
349 * Combines core transformer parameters with transformer-specific parameters.
350 * Useful for serialization, debugging, and parameter inspection.
351 */
352 [[nodiscard]] std::map<std::string, std::any> get_all_parameters() const override
353 {
354 auto params = get_transformation_parameters();
355 params["strategy"] = m_strategy;
356 params["quality"] = m_quality;
357 params["scope"] = m_scope;
358 return params;
359 }
360
361 /**
362 * @brief Sets the transformation strategy
363 * @param strategy How the transformation should be executed
364 *
365 * Strategies control memory usage, performance, and behavior:
366 * - IN_PLACE: Modify input data directly (memory efficient)
367 * - BUFFERED: Create copy for output (preserves input)
368 * - STREAMING: Process in chunks for large data
369 * - PARALLEL: Use multiple threads where possible
370 */
371 void set_strategy(TransformationStrategy strategy) { m_strategy = strategy; }
372
373 /**
374 * @brief Gets the current transformation strategy
375 * @return Current strategy setting
376 */
377 [[nodiscard]] TransformationStrategy get_strategy() const { return m_strategy; }
378
379 /**
380 * @brief Sets the transformation quality level
381 * @param quality Quality vs performance trade-off setting
382 *
383 * Quality levels control the computational cost vs result quality:
384 * - DRAFT: Fast processing for previews
385 * - STANDARD: Balanced for real-time use
386 * - HIGH_QUALITY: Better results, may be slower
387 * - REFERENCE: Maximum quality regardless of cost
388 */
389 void set_quality(TransformationQuality quality) { m_quality = quality; }
390
391 /**
392 * @brief Gets the current transformation quality level
393 * @return Current quality setting
394 */
395 [[nodiscard]] TransformationQuality get_quality() const { return m_quality; }
396
397 /**
398 * @brief Sets the transformation scope
399 * @param scope What portion of the data to transform
400 *
401 * Scope controls which parts of the input data are processed:
402 * - FULL_DATA: Process entire input
403 * - TARGETED_REGIONS: Process specific regions only
404 * - SELECTIVE_BANDS: Process specific frequency/spatial bands
405 * - CONDITIONAL: Process based on dynamic conditions
406 */
407 void set_scope(TransformationScope scope) { m_scope = scope; }
408
409 /**
410 * @brief Gets the current transformation scope
411 * @return Current scope setting
412 */
413 [[nodiscard]] TransformationScope get_scope() const { return m_scope; }
414
415 /**
416 * @brief Set transformation intensity (0.0 = no transformation, 1.0 = full transformation)
417 * @param intensity Intensity value (clamped to 0.0-2.0 range)
418 *
419 * Intensity controls how strongly the transformation is applied:
420 * - 0.0: No transformation (passthrough)
421 * - 1.0: Full transformation as configured
422 * - >1.0: Extreme/exaggerated transformation (up to 2.0)
423 */
425 {
426 m_intensity = std::clamp(intensity, 0.0, 2.0); // Allow > 1.0 for extreme transformations
427 }
428
429 /**
430 * @brief Gets the current transformation intensity
431 * @return Current intensity value (0.0-2.0)
432 */
433 [[nodiscard]] double get_intensity() const { return m_intensity; }
434
435 /**
436 * @brief Add transformation key for multi-dimensional transformations
437 * @param key Transformation key specification
438 *
439 * Transformation keys enable complex, multi-parameter transformations where
440 * different aspects of the input data control different transformation parameters.
441 * Useful for data-driven and adaptive transformations.
442 */
444 {
445 m_transformation_keys.push_back(key);
446 }
447
448 /**
449 * @brief Clear all transformation keys
450 *
451 * Removes all transformation keys, returning to simple parameter-based operation.
452 */
454 {
455 m_transformation_keys.clear();
456 }
457
458 /**
459 * @brief Get all transformation keys
460 * @return Vector of current transformation keys
461 */
462 [[nodiscard]] const std::vector<TransformationKey>& get_transformation_keys() const
463 {
465 }
466
467 /**
468 * @brief Set a custom transformation function for mathematical transformations
469 * @tparam T Data type for the custom function
470 * @param func Custom transformation function
471 *
472 * Allows injection of custom transformation logic for specialized use cases.
473 * The function will be called for each data element during transformation.
474 */
475 template <ComputeData T>
476 void set_custom_function(std::function<T(const T&)> func)
477 {
478 m_custom_function = [func](const std::any& a) -> std::any {
479 auto val_result = safe_any_cast<T>(a);
480 if (val_result) {
481 return func(*val_result);
482 }
483 return a; // Return unchanged if cast fails
484 };
485 }
486
487 /**
488 * @brief Indicates whether the transformation modifies the input data directly
489 * @return True if the operation modifies input in-place, false if it creates a new output
490 *
491 * This is determined by the current transformation strategy. IN_PLACE strategy
492 * modifies input directly, while other strategies preserve the input.
493 */
494 [[nodiscard]] virtual bool is_in_place() const { return m_strategy == TransformationStrategy::IN_PLACE; }
495
496 /**
497 * @brief Reports the current progress of a long-running transformation
498 * @return Progress value between 0.0 (not started) and 1.0 (completed)
499 *
500 * Base implementation returns 1.0 (completed). Derived classes can override
501 * to provide actual progress reporting for long-running operations.
502 */
503 [[nodiscard]] virtual double get_transformation_progress() const { return 1.0; }
504
505 /**
506 * @brief Estimates the computational cost of the transformation
507 * @return Relative cost factor (1.0 = standard, >1.0 = more expensive, <1.0 = cheaper)
508 *
509 * Base implementation returns 1.0. Derived classes should override to provide
510 * realistic cost estimates for scheduling and resource allocation.
511 */
512 [[nodiscard]] virtual double estimate_computational_cost() const { return 1.0; }
513
514protected:
515 /**
516 * @brief Core operation implementation - called by ComputeOperation interface
517 * @param input Input data with metadata
518 * @return Output data with metadata
519 *
520 * This is the main entry point called by the ComputeOperation framework.
521 * It validates input, delegates to transform_implementation(), and applies
522 * scope/quality processing to the result.
523 */
525 {
526 if (!validate_input(input)) {
528 }
529 auto raw_result = transform_implementation(const_cast<input_type&>(input));
530 return apply_scope_and_quality_processing(raw_result);
531 }
532
533 /**
534 * @brief Pure virtual transformation implementation - derived classes implement this
535 * @param input Input data with metadata (may be modified for in-place operations)
536 * @return Raw transformation output before scope/quality processing
537 *
538 * This is where derived transformers implement their core transformation logic.
539 * The input may be modified for in-place operations. The result will be
540 * post-processed based on scope and quality settings.
541 */
543
544 /**
545 * @brief Get transformer-specific name (derived classes override this)
546 * @return Transformer name string
547 *
548 * Derived classes should override this to provide meaningful names like
549 * "MathematicalTransformer_GAIN" or "SpectralTransformer_PITCH_SHIFT".
550 */
551 [[nodiscard]] virtual std::string get_transformer_name() const { return "UniversalTransformer"; }
552
553 /**
554 * @brief Transformation-specific parameter handling (override for custom parameters)
555 * @param name Parameter name
556 * @param value Parameter value
557 *
558 * Base implementation stores parameters in a map. Derived classes should override
559 * to handle transformer-specific parameters with proper type checking and validation.
560 */
561 virtual void set_transformation_parameter(const std::string& name, std::any value)
562 {
563 m_parameters[name] = std::move(value);
564 }
565
566 /**
567 * @brief Gets a transformation-specific parameter value
568 * @param name Parameter name
569 * @return Parameter value or empty std::any if not found
570 */
571 [[nodiscard]] virtual std::any get_transformation_parameter(const std::string& name) const
572 {
573 auto it = m_parameters.find(name);
574 return (it != m_parameters.end()) ? it->second : std::any {};
575 }
576
577 /**
578 * @brief Gets all transformation-specific parameters
579 * @return Map of transformer-specific parameter names to values
580 */
581 [[nodiscard]] virtual std::map<std::string, std::any> get_transformation_parameters() const
582 {
583 return m_parameters;
584 }
585
586 /**
587 * @brief Apply scope and quality filtering to the transformation result
588 * @param result Raw transformation result
589 * @return Processed result with scope and quality adjustments applied
590 *
591 * Base implementation returns the result unchanged. Derived classes can override
592 * to implement scope-specific processing (e.g., regional transforms) and
593 * quality adjustments (e.g., interpolation quality, precision control).
594 */
596 {
597 return result;
598 }
599
600 /**
601 * @brief Helper method to apply transformation keys to extract parameters
602 * @param input Input data to extract parameters from
603 * @return Vector of extracted parameter values
604 *
605 * Processes all transformation keys to extract parameter values from the input data.
606 * Applies normalization, intensity, and weight adjustments as configured.
607 * Used for data-driven and adaptive transformations.
608 */
609 std::vector<double> extract_transformation_parameters(const input_type& input) const
610 {
611 std::vector<double> parameters;
612 parameters.reserve(m_transformation_keys.size());
613
614 for (const auto& key : m_transformation_keys) {
615 try {
616 double param {};
617 if (key.axis.has_value()) {
618 // TODO: Implement dimension validation
619 } else {
620 param = key.parameter_extractor(input.data[key.channel]);
621 }
622 if (key.normalize) {
623 param = std::clamp(param, 0.0, 1.0);
624 }
625 parameters.push_back(param * key.intensity * key.weight);
626 } catch (...) {
627 parameters.push_back(0.0);
628 }
629 }
630
631 return parameters;
632 }
633
634 /**
635 * @brief Basic input validation that derived classes can override
636 * @param input Input data to validate
637 * @return true if input is valid for processing, false otherwise
638 *
639 * Base implementation checks for:
640 * - Non-empty data
641 * - Basic data type validity
642 * - Finite values (no NaN/infinity in sample data)
643 *
644 * Derived transformers can override to add specific requirements
645 * (e.g., minimum size for spectral operations, specific data structure requirements).
646 */
647 bool validate_input(const input_type& input) const override
648 {
649 if constexpr (RequiresContainer<InputType>) {
650 if (!input.has_container()) {
651 return false;
652 }
653 auto numeric_data = OperationHelper::extract_numeric_data(input.data, input.container.value());
654 return validate_multi_channel_data(numeric_data);
655 } else {
656 auto numeric_data = OperationHelper::extract_numeric_data(input.data);
657 return validate_multi_channel_data(numeric_data);
658 }
659 }
660
661private:
662 /**
663 * @brief Creates a safe fallback output when input validation fails
664 * @param input Original input (for type/structure reference)
665 * @return Safe output that won't cause further processing errors
666 *
667 * The behavior is:
668 * - For same input/output types: return input unchanged
669 * - For type conversion: create appropriate empty/minimal output
670 * - Always preserves metadata structure
671 * - Adds metadata indicating validation failure
672 */
674 {
675 output_type result;
676
677 result.dimensions = input.dimensions;
678 result.modality = input.modality;
679 result.metadata = input.metadata;
680 result.metadata["validation_failed"] = true;
681 result.metadata["fallback_reason"] = "Input validation failed";
682
683 if constexpr (std::is_same_v<InputType, OutputType>) {
684 result.data = input.data;
685 } else {
686 if constexpr (RequiresContainer<InputType>) {
687 if (!input.has_container()) {
688 result.container = std::make_shared<Kakshya::SignalSourceContainer>();
689 } else {
690 result.container = input.container;
691 }
692 }
693 result.data = {};
694 }
695
696 return result;
697 }
698
699 /**
700 * @brief Validates multi-channel numeric data for NaN/Infinity values
701 * @param channels Vector of spans representing each channel's data
702 * @return true if all channels are valid, false if any contain invalid values
703 *
704 * Checks each channel's samples to ensure they are finite numbers.
705 * Empty channels are considered valid.
706 */
707 [[nodiscard]] bool validate_multi_channel_data(const std::vector<std::span<double>>& channels) const
708 {
709 if (channels.empty()) {
710 return false;
711 }
712
713 for (const auto& channel : channels) {
714 if (channel.empty()) {
715 continue;
716 }
717
718 for (double sample : channel) {
719 if (std::isnan(sample)) {
720 return false;
721 }
722 if (std::isinf(sample)) {
723 return false;
724 }
725 }
726 }
727
728 return true;
729 }
730
731 /** @brief Core transformation configuration */
735 double m_intensity = 1.0; ///< Transformation intensity (0.0-2.0)
736
737 /** @brief Multi-dimensional transformation keys */
738 std::vector<TransformationKey> m_transformation_keys; ///< Keys for data-driven transformations
739
740 /** @brief Custom transformation function for mathematical operations */
741 std::function<std::any(const std::any&)> m_custom_function; ///< User-defined transformation function
742
743 /** @brief Generic parameter storage for transformer-specific settings */
744 std::map<std::string, std::any> m_parameters; ///< Transformer-specific parameter storage
745};
746
747} // namespace MayaFlux::Yantra
Core::GlobalInputConfig input
Definition Config.cpp:42
float intensity
Definition Decoder.cpp:94
size_t a
glm::vec3 value
std::string name
Definition VKDevice.cpp:123
uint32_t channels
Base interface for all computational operations in the processing pipeline.
static std::span< double > extract_numeric_data(const T &compute_data)
extract numeric data from single-variant types
TransformationScope m_scope
Current processing scope.
virtual ~UniversalTransformer()=default
Virtual destructor for proper inheritance cleanup.
TransformationStrategy m_strategy
Core transformation configuration.
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.
OperationType get_operation_type() const override
Returns the category of this operation for grammar and registry discovery.
double m_intensity
Transformation intensity (0.0-2.0)
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.
TransformationQuality m_quality
Current quality level.
Template-flexible transformer base with instance-defined I/O types.
Types that need an associated SignalSourceContainer to extract data.
Definition DataSpec.hpp:110
@ 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.
@ FULL_DATA
Transform entire data set.
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.
@ STANDARD
Balanced quality/performance for real-time use.
@ REFERENCE
Maximum quality, computational cost is secondary.
OperationType
Operation categories for organization and discovery.
@ IN_PLACE
Sort data in-place (modifies input)
@ CROSS_MODAL
Sort one modality by features of another.
@ STANDARD
Traditional comparison-based sorting.
@ 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.
@ IN_PLACE
Transform data in-place (modifies input)
@ STREAMING
Stream-based transformation for large data.
@ FULL_DATA
Extract all available data.
@ TARGETED_REGIONS
Extract only specific regions.
T data
The actual computation data.
Definition DataIO.hpp:27
std::vector< Kakshya::DataDimension > dimensions
Data dimensional structure.
Definition DataIO.hpp:28
std::optional< std::shared_ptr< Kakshya::SignalSourceContainer > > container
Optional reference to container, required for regions.
Definition DataIO.hpp:33
Kakshya::DataModality modality
Data modality (audio, image, spectral, etc.)
Definition DataIO.hpp:29
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Definition DataIO.hpp:30
Input/Output container for computation pipeline data flow with structure preservation.
Definition DataIO.hpp:26
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.
TransformationQuality quality
Requested transformation quality.
TransformationScope scope
Portion of the input to transform.
Operation operation
Operation to perform within the selected family.
TransformationStrategy strategy
How transformation work is performed.
std::vector< TransformationKey > keys
Transformation keys to register before processing.
std::map< std::string, std::any > parameters
Additional named parameters applied last.
double intensity
Overall transformation strength.
Initial settings shared by concrete transformer families.