MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ContainerUtils.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @brief Extract processing state information from container.
9 * @param container Container to analyze.
10 * @return Map containing processing state metadata.
11 */
12std::unordered_map<std::string, std::any> extract_processing_state_info(const std::shared_ptr<SignalSourceContainer>& container);
13
14/**
15 * @brief Extract processor information from container.
16 * @param container Container to analyze.
17 * @return Map containing processor metadata.
18 */
19std::unordered_map<std::string, std::any> extract_processor_info(const std::shared_ptr<SignalSourceContainer>& container);
20
21/**
22 * @brief Perform a state transition for a ProcessingState, with optional callback.
23 * @param current_state Current state (modified in place).
24 * @param new_state State to transition to.
25 * @param on_transition Optional callback to invoke on transition.
26 * @return True if transition was valid and performed.
27 */
28bool transition_state(ProcessingState& current_state, ProcessingState new_state, std::function<void()> on_transition = nullptr);
29
30/**
31 * @brief Determine optimal memory access pattern for region.
32 * @param region Region to analyze.
33 * @param container Container providing layout information.
34 * @return Recommended access pattern information.
35 */
36std::unordered_map<std::string, std::any> analyze_access_pattern(const Region& region,
37 const std::shared_ptr<SignalSourceContainer>& container);
38
39/**
40 * @brief Interleave multiple channels of data into a single vector.
41 * @tparam T Data type.
42 * @param channels Vector of channel vectors.
43 * @return Interleaved data vector.
44 */
45template <typename T>
46std::vector<T> interleave_channels(const std::vector<std::vector<T>>& channels)
47{
48 if (channels.empty()) {
49 return {};
50 }
51 size_t num_channels = channels.size();
52 size_t samples_per_channel = channels[0].size();
53 std::vector<T> result(num_channels * samples_per_channel);
54 for (size_t i = 0; i < samples_per_channel; ++i) {
55 for (size_t ch = 0; ch < num_channels; ++ch) {
56 result[i * num_channels + ch] = channels[ch][i];
57 }
58 }
59 return result;
60}
61
62/**
63 * @brief Deinterleave a single vector into multiple channels.
64 * @tparam T Data type.
65 * @param interleaved Interleaved data span.
66 * @param num_channels Number of channels.
67 * @return Vector of channel vectors.
68 */
69template <typename T>
70std::vector<std::vector<T>> deinterleave_channels(std::span<const T> interleaved, size_t num_channels)
71{
72 if (interleaved.empty() || num_channels == 0) {
73 return {};
74 }
75 size_t samples_per_channel = interleaved.size() / num_channels;
76 std::vector<std::vector<T>> result(num_channels);
77 for (size_t ch = 0; ch < num_channels; ++ch) {
78 result[ch].resize(samples_per_channel);
79 for (size_t i = 0; i < samples_per_channel; ++i) {
80 result[ch][i] = interleaved[i * num_channels + ch];
81 }
82 }
83 return result;
84}
85
86/**
87 * @brief Extract data from a specific channel.
88 * @param container The container to extract from.
89 * @param channel_index Index of the channel to extract.
90 * @return DataVariant containing channel data.
91 */
92DataVariant extract_channel_data(const std::shared_ptr<SignalSourceContainer>& container,
93 uint32_t channel_index);
94
95/**
96 * @brief Validates container for analysis operations with comprehensive checks
97 * @param container Container to validate
98 * @return Pair of validated container and its dimensions
99 * @throws std::invalid_argument if container is null or has no data
100 * @throws std::runtime_error if container has no dimensions
101 */
102std::pair<std::shared_ptr<SignalSourceContainer>, std::vector<DataDimension>>
103validate_container_for_analysis(const std::shared_ptr<SignalSourceContainer>& container);
104
105/**
106 * @brief Extracts numeric data from container with fallback handling
107 * @param container Container to extract from
108 * @return Vector of double values from container data
109 * @throws std::runtime_error if no numeric data can be extracted
110 */
111std::vector<std::span<double>> extract_numeric_data(const std::shared_ptr<SignalSourceContainer>& container);
112
113/**
114 * @brief Validates numeric data for analysis operations
115 * @param data Data to validate
116 * @param operation_name Name of operation for error messages
117 * @param min_size Minimum required data size (default 1)
118 * @throws std::invalid_argument if data is invalid for analysis
119 */
120void validate_numeric_data_for_analysis(const std::vector<double>& data,
121 const std::string& operation_name,
122 size_t min_size = 1);
123
124}
ProcessingState
Represents the current processing lifecycle state of a container.
std::unordered_map< std::string, std::any > analyze_access_pattern(const Region &region, const std::shared_ptr< SignalSourceContainer > &container)
Determine optimal memory access pattern for region.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:73
DataVariant extract_channel_data(const std::shared_ptr< SignalSourceContainer > &container, uint32_t channel_index)
Extract data from a specific channel.
std::unordered_map< std::string, std::any > extract_processing_state_info(const std::shared_ptr< SignalSourceContainer > &container)
Extract processing state information from container.
std::vector< std::span< double > > extract_numeric_data(const std::shared_ptr< SignalSourceContainer > &container)
Extracts numeric data from container with fallback handling.
void validate_numeric_data_for_analysis(const std::vector< double > &data, const std::string &operation_name, size_t min_size)
Validates numeric data for analysis operations.
std::vector< T > interleave_channels(const std::vector< std::vector< T > > &channels)
Interleave multiple channels of data into a single vector.
std::pair< std::shared_ptr< SignalSourceContainer >, std::vector< DataDimension > > validate_container_for_analysis(const std::shared_ptr< SignalSourceContainer > &container)
Validates container for analysis operations with comprehensive checks.
std::unordered_map< std::string, std::any > extract_processor_info(const std::shared_ptr< SignalSourceContainer > &container)
Extract processor information from container.
std::vector< std::vector< T > > deinterleave_channels(std::span< const T > interleaved, size_t num_channels)
Deinterleave a single vector into multiple channels.
bool transition_state(ProcessingState &current_state, ProcessingState new_state, std::function< void()> on_transition)
Perform a state transition for a ProcessingState, with optional callback.