MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NDData.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4
5#include "typeindex"
6
7namespace MayaFlux::Kakshya {
8
9namespace detail {
10
11 template <typename V>
13
14 template <typename... Vecs>
15 struct span_const_from_vector_variant<std::variant<Vecs...>> {
16 using type = std::variant<std::span<const typename Vecs::value_type>...>;
17 };
18
19} // namespace detail
20
21/**
22 * @enum GpuDataFormat
23 * @brief GPU data formats with explicit precision levels
24 */
25enum class GpuDataFormat : uint8_t {
26 FLOAT32, // 32-bit float (standard GPU)
27 VEC2_F32, // glm::vec2 (32-bit components)
28 VEC3_F32, // glm::vec3 (32-bit components) — not a sampled image format
29 VEC4_F32, // glm::vec4 (32-bit components)
30
31 FLOAT64, // 64-bit double (audio precision)
32 VEC2_F64, // glm::dvec2 (64-bit components)
33 VEC3_F64, // glm::dvec3 (64-bit components)
34 VEC4_F64, // glm::dvec4 (64-bit components)
35
36 INT32,
37 UINT32,
38
39 UINT8, // uint8_t — R8 / RGBA8 texel data
40 UINT16, // uint16_t — R16F raw half-float storage, packed formats
41};
42
43/**
44 * @brief Byte size of one element of a GpuDataFormat.
45 *
46 * Single authoritative source for format sizing. Used by TextureAccess,
47 * ShaderSpec, and any other system that needs to derive byte counts from
48 * GpuDataFormat without duplicating the switch.
49 *
50 * @param fmt GpuDataFormat value.
51 * @return Byte size of one element, or 0 for unrecognised formats.
52 */
53MAYAFLUX_API size_t gpu_data_format_bytes(GpuDataFormat fmt) noexcept;
54
55/**
56 * @brief Memory layout for multi-dimensional data.
57 *
58 * Specifies how multi-dimensional data is mapped to linear memory.
59 * - ROW_MAJOR: Last dimension varies fastest (C/C++ style).
60 * - COLUMN_MAJOR: First dimension varies fastest (Fortran/MATLAB style).
61 *
62 * This abstraction enables flexible, efficient access patterns for
63 * digital-first, data-driven workflows, unconstrained by analog conventions.
64 */
65enum class MemoryLayout : uint8_t {
66 ROW_MAJOR, ///< C/C++ style (last dimension varies fastest)
67 COLUMN_MAJOR ///< Fortran/MATLAB style (first dimension varies fastest)
68};
69
70/**
71 * @brief Data organization strategy for multi-channel/multi-frame data.
72 *
73 * Determines how logical units (channels, frames) are stored in memory.
74 */
75enum class OrganizationStrategy : uint8_t {
76 INTERLEAVED, ///< Single DataVariant with interleaved data (LRLRLR for stereo)
77 PLANAR, ///< Separate DataVariant per logical unit (LLL...RRR for stereo)
78 HYBRID, ///< Mixed approach based on access patterns
79 USER_DEFINED ///< Custom organization
80};
81
82/**
83 * @brief Multi-type data storage for different precision needs.
84 *
85 * DataVariant enables containers to store and expose data in the most
86 * appropriate format for the application, supporting high-precision,
87 * standard-precision, integer, and complex types. This abstraction
88 * is essential for digital-first, data-driven processing pipelines.
89 */
90using DataVariant = std::variant<
91 std::vector<double>, ///< High precision floating point
92 std::vector<float>, ///< Standard precision floating point
93 std::vector<uint8_t>, ///< 8-bit data (images, compressed audio)
94 std::vector<uint16_t>, ///< 16-bit data (CD audio, images)
95 std::vector<uint32_t>, ///< 32-bit data (high precision int)
96 std::vector<std::complex<float>>, ///< Complex data (spectral)
97 std::vector<std::complex<double>>, ///< High precision complex
98 std::vector<glm::vec2>, ///< 2D vector data
99 std::vector<glm::vec3>, ///< 3D vector data
100 std::vector<glm::vec4>, ///< 4D vector data
101 std::vector<glm::mat4> ///< 4x4 matrix data
102 >;
103
104/**
105 * @brief Type traits to determine if a type is a valid DataVariant element.
106 *
107 * This trait is used to constrain template functions that operate on DataVariant types,
108 * ensuring that only supported data types are used in the context of NDData containers.
109 */
110template <typename T>
111struct is_data_variant_element : std::false_type { };
112
113/** high precision floating point data (double) (audio) */
114template <>
115struct is_data_variant_element<double> : std::true_type { };
116
117/** standard precision floating point data (float) (params) */
118template <>
119struct is_data_variant_element<float> : std::true_type { };
120
121/** 8-bit unsigned integer data (uint8_t) (images, compressed audio) */
122template <>
123struct is_data_variant_element<uint8_t> : std::true_type { };
124
125/** 16-bit unsigned integer data (uint16_t) (CD audio, images) */
126template <>
127struct is_data_variant_element<uint16_t> : std::true_type { };
128
129/** 32-bit unsigned integer data (uint32_t) (high precision int) */
130template <>
131struct is_data_variant_element<uint32_t> : std::true_type { };
132
133/** complex data (spectral) */
134template <>
135struct is_data_variant_element<std::complex<float>> : std::true_type { };
136
137/** high precision complex data (spectral) */
138template <>
139struct is_data_variant_element<std::complex<double>> : std::true_type { };
140
141/** 2D vector data (glm::vec2) */
142template <>
143struct is_data_variant_element<glm::vec2> : std::true_type { };
144
145/** 3D vector data (glm::vec3) */
146template <>
147struct is_data_variant_element<glm::vec3> : std::true_type { };
148
149/** 4D vector data (glm::vec4) */
150template <>
151struct is_data_variant_element<glm::vec4> : std::true_type { };
152
153/** 4x4 matrix data (glm::mat4) */
154template <>
155struct is_data_variant_element<glm::mat4> : std::true_type { };
156
157/** Concept to constrain types to valid DataVariant elements */
158template <typename T>
159concept DataVariantElement = is_data_variant_element<std::remove_cvref_t<T>>::value;
160
161/**
162 * @brief Data modality types for cross-modal analysis
163 */
164enum class DataModality : uint8_t {
165 AUDIO_1D, ///< 1D audio signal
166 AUDIO_MULTICHANNEL, ///< Multi-channel audio
167 IMAGE_2D, ///< 2D image (grayscale or single channel)
168 IMAGE_COLOR, ///< 2D RGB/RGBA image
169 IMAGE_COLOR_ARRAY, ///< 4D (idx + 2D + color)
170 VIDEO_GRAYSCALE, ///< 3D video (time + 2D grayscale)
171 VIDEO_COLOR, ///< 4D video (time + 2D + color)
172 TEXTURE_2D, ///< 2D texture data
173 TENSOR_ND, ///< N-dimensional tensor
174 SPECTRAL_2D, ///< 2D spectral data (time + frequency)
175 VOLUMETRIC_3D, ///< 3D volumetric data
176 VERTICES_3D, ///< 3D vertex data (positions, normals, etc.)
177 VERTEX_POSITIONS_3D, // glm::vec3 - vertex positions
178 VERTEX_NORMALS_3D, // glm::vec3 - vertex normals
179 VERTEX_TANGENTS_3D, // glm::vec3 - tangent vectors
180 VERTEX_COLORS_RGB, // glm::vec3 - RGB colors
181 VERTEX_COLORS_RGBA, // glm::vec4 - RGBA colors
182 TEXTURE_COORDS_2D, // glm::vec2 - UV coordinates
183 TRANSFORMATION_MATRIX, // glm::mat4 - transform matrices
184 SCALAR_F32, ///< Single-channel float data
185 UNKNOWN ///< Unknown or undefined modality
186};
187
188/**
189 * @brief Convert DataModality enum to string representation.
190 * @param modality DataModality value
191 * @return String view of the modality name
192 */
193std::string_view modality_to_string(DataModality modality);
194
195/**
196 * @brief Check if a modality represents structured data (vectors, matrices).
197 * @param modality DataModality value
198 * @return True if structured, false otherwise
199 */
201{
202 switch (modality) {
210 return true;
211 default:
212 return false;
213 }
214}
215
216/**
217 * @brief Minimal dimension descriptor focusing on structure only.
218 *
219 * DataDimension describes a single axis of an N-dimensional dataset,
220 * providing semantic hints (such as TIME, CHANNEL, SPATIAL_X, etc.)
221 * and structural information (name, size, stride).
222 *
223 * This abstraction enables containers to describe arbitrary data
224 * organizations, supporting digital-first, data-driven processing
225 * without imposing analog metaphors (e.g., "track", "tape", etc.).
226 */
227struct MAYAFLUX_API DataDimension {
228 /**
229 * @brief Semantic role of the dimension.
230 *
231 * Used to indicate the intended interpretation of the dimension,
232 * enabling generic algorithms to adapt to data structure.
233 */
234 enum class Role : uint8_t {
235 TIME, ///< Temporal progression (samples, frames, steps)
236 CHANNEL, ///< Parallel streams (audio channels, color channels)
237 SPATIAL_X, ///< Spatial X axis (images, tensors)
238 SPATIAL_Y, ///< Spatial Y axis
239 SPATIAL_Z, ///< Spatial Z axis
240 FREQUENCY, ///< Spectral/frequency axis
241 POSITION, ///< Vertex positions (3D space)
242 NORMAL, ///< Surface normals
243 TANGENT, ///< Tangent vectors
244 BITANGENT, ///< Bitangent vectors
245 UV, ///< Texture coordinates
246 COLOR, ///< Color data (RGB/RGBA)
247 INDEX, ///< Index buffer data
248 MIP_LEVEL, ///< Mipmap levels
249 CUSTOM ///< User-defined or application-specific
250 };
251
252 /**
253 * @brief Grouping information for sub-dimensions.
254 *
255 * Used to indicate that this dimension is composed of groups
256 * of sub-dimensions (e.g., color channels grouped per pixel).
257 */
259 uint8_t count;
260 uint8_t offset;
261
263 : count(0)
264 , offset(0)
265 {
266 }
267 ComponentGroup(uint8_t c, uint8_t o = 0)
268 : count(c)
269 , offset(o)
270 {
271 }
272 };
273
274 std::optional<ComponentGroup> grouping;
275
276 std::string name; ///< Human-readable identifier for the dimension
277 uint64_t size {}; ///< Number of elements in this dimension
278 uint64_t stride {}; ///< Memory stride (elements between consecutive indices)
279 Role role = Role::CUSTOM; ///< Semantic hint for common operations
280
281 DataDimension() = default;
282
283 /**
284 * @brief Construct a dimension descriptor.
285 * @param n Name of the dimension
286 * @param s Size (number of elements)
287 * @param st Stride (default: 1)
288 * @param r Semantic role (default: CUSTOM)
289 */
290 DataDimension(std::string n, uint64_t s, uint64_t st = 1, Role r = Role::CUSTOM);
291
292 /**
293 * @brief Convenience constructor for a temporal (time) dimension.
294 * @param samples Number of samples/frames
295 * @param name Optional name (default: "time")
296 * @return DataDimension representing time
297 */
298 static DataDimension time(uint64_t samples, std::string name = "time");
299
300 /**
301 * @brief Convenience constructor for a channel dimension.
302 * @param count Number of channels
303 * @param stride Memory stride (default: 1)
304 * @return DataDimension representing channels
305 */
306 static DataDimension channel(uint64_t count, uint64_t stride = 1);
307
308 /**
309 * @brief Convenience constructor for a frequency dimension.
310 * @param bins Number of frequency bins
311 * @param name Optional name (default: "frequency")
312 * @return DataDimension representing frequency
313 */
314 static DataDimension frequency(uint64_t bins, std::string name = "frequency");
315
316 /**
317 * @brief Convenience constructor for a spatial dimension.
318 * @param size Number of elements along this axis
319 * @param axis Axis character ('x', 'y', or 'z')
320 * @param stride Memory stride (default: 1)
321 * @param name Optional name (default: "pixels")
322 * @return DataDimension representing a spatial axis
323 */
324 static DataDimension spatial(uint64_t size, char axis, uint64_t stride = 1, std::string name = "spatial");
325
326 /**
327 * @brief Convenience constructor for an array dimension.
328 * @param count Number of array elements
329 * @param name Optional name (default: "array")
330 * @return DataDimension representing an array
331 */
332 static DataDimension spatial_1d(uint64_t width);
333
334 /**
335 * @brief Convenience constructor for a 2D spatial dimension.
336 * @param width Width in elements
337 * @param height Height in elements
338 * @return DataDimension representing 2D spatial data
339 */
340 static DataDimension spatial_2d(uint64_t width, uint64_t height);
341
342 /**
343 * @brief Convenience constructor for a 3D spatial dimension.
344 * @param width Width in elements
345 * @param height Height in elements
346 * @param depth Depth in elements
347 * @return DataDimension representing 3D spatial data
348 */
349 static DataDimension spatial_3d(uint64_t width, uint64_t height, uint64_t depth);
350
351 /**
352 * @brief Create dimension with component grouping
353 * @param name Dimension name
354 * @param element_count Number of elements (not components)
355 * @param components_per_element Components per element (e.g., 3 for vec3)
356 * @param role Semantic role
357 */
358 static DataDimension grouped(std::string name, uint64_t element_count, uint8_t components_per_element, Role role = Role::CUSTOM);
359
360 /**
361 * @brief Create dimension for vertex positions (vec3)
362 */
363 static DataDimension vertex_positions(uint64_t count);
364
365 /**
366 * @brief Create dimension for vertex normals (vec3)
367 */
368 static DataDimension vertex_normals(uint64_t count);
369
370 /**
371 * @brief Create dimension for texture coordinates (vec2)
372 */
373 static DataDimension texture_coords(uint64_t count);
374
375 /**
376 * @brief Create dimension for colors (vec3 or vec4)
377 */
378 static DataDimension vertex_colors(uint64_t count, bool has_alpha = false);
379
380 /**
381 * @brief Create dimension for mipmap levels.
382 */
383 static DataDimension mipmap_levels(uint64_t levels);
384
385 /**
386 * @brief Data container combining variants and dimensions.
387 */
388 using DataModule = std::pair<std::vector<DataVariant>, std::vector<DataDimension>>;
389
390 /**
391 * @brief Create data module for a specific modality.
392 * @tparam T Data type for storage
393 * @param modality Target data modality
394 * @param shape Dimensional sizes
395 * @param default_value Initial value for elements
396 * @param layout Memory layout strategy
397 * @param strategy Organization strategy
398 * @return DataModule with appropriate structure
399 */
400 template <typename T>
402 DataModality modality,
403 const std::vector<uint64_t>& shape,
404 T default_value = T {},
405 MemoryLayout layout = MemoryLayout::ROW_MAJOR,
406 OrganizationStrategy strategy = OrganizationStrategy::PLANAR)
407 {
408 auto dims = create_dimensions(modality, shape, layout);
409 auto variants = create_variants(modality, shape, default_value, strategy);
410
411 return { std::move(variants), std::move(dims) };
412 }
413
414 /**
415 * @brief Create dimension descriptors for a data modality.
416 * @param modality Target data modality
417 * @param shape Dimensional sizes
418 * @param layout Memory layout strategy
419 * @return Vector of DataDimension objects
420 */
421 static std::vector<DataDimension> create_dimensions(
422 DataModality modality,
423 const std::vector<uint64_t>& shape,
424 MemoryLayout layout = MemoryLayout::ROW_MAJOR);
425
426 /**
427 * @brief Create 1D audio data module.
428 * @tparam T Data type for storage
429 * @param samples Number of audio samples
430 * @param default_value Initial value for elements
431 * @return DataModule for 1D audio
432 */
433 template <typename T>
434 static DataModule create_audio_1d(uint64_t samples, T default_value = T {})
435 {
436 return create_for_modality(DataModality::AUDIO_1D, { samples }, default_value);
437 }
438
439 /**
440 * @brief Create multi-channel audio data module.
441 * @tparam T Data type for storage
442 * @param samples Number of audio samples
443 * @param channels Number of audio channels
444 * @param default_value Initial value for elements
445 * @return DataModule for multi-channel audio
446 */
447 template <typename T>
448 static DataModule create_audio_multichannel(uint64_t samples, uint64_t channels, T default_value = T {})
449 {
450 return create_for_modality(DataModality::AUDIO_MULTICHANNEL, { samples, channels }, default_value);
451 }
452
453 /**
454 * @brief Create 2D image data module.
455 * @tparam T Data type for storage
456 * @param height Image height in pixels
457 * @param width Image width in pixels
458 * @param default_value Initial value for elements
459 * @return DataModule for 2D image
460 */
461 template <typename T>
462 static DataModule create_image_2d(uint64_t height, uint64_t width, T default_value = T {})
463 {
464 return create_for_modality(DataModality::IMAGE_2D, { height, width }, default_value);
465 }
466
467 /**
468 * @brief Create 2D spectral data module.
469 * @tparam T Data type for storage
470 * @param time_windows Number of time windows
471 * @param frequency_bins Number of frequency bins
472 * @param default_value Initial value for elements
473 * @return DataModule for spectral data
474 */
475 template <typename T>
476 static DataModule create_spectral_2d(uint64_t time_windows, uint64_t frequency_bins, T default_value = T {})
477 {
478 return create_for_modality(DataModality::SPECTRAL_2D, { time_windows, frequency_bins }, default_value);
479 }
480
481 /**
482 * @brief Calculate memory strides based on shape and layout.
483 * @param shape Dimensional sizes
484 * @param layout Memory layout strategy
485 * @return Vector of stride values for each dimension
486 */
487 static std::vector<uint64_t> calculate_strides(
488 const std::vector<uint64_t>& shape,
489 MemoryLayout layout);
490
491private:
492 /**
493 * @brief Create data variants for a specific modality.
494 * @tparam T Data type for storage
495 * @param modality Target data modality
496 * @param shape Dimensional sizes
497 * @param default_value Initial value for elements
498 * @param org Organization strategy
499 * @return Vector of DataVariant objects
500 */
501 template <typename T>
502 static std::vector<DataVariant> create_variants(
503 DataModality modality,
504 const std::vector<uint64_t>& shape,
505 T default_value,
506 OrganizationStrategy org = OrganizationStrategy::PLANAR)
507 {
508 std::vector<DataVariant> variants;
509
510 if (org == OrganizationStrategy::INTERLEAVED) {
511 uint64_t total = std::accumulate(shape.begin(), shape.end(), uint64_t(1), std::multiplies<>());
512 variants.emplace_back(std::vector<T>(total, default_value));
513 return variants;
514 }
515
516 switch (modality) {
517 case DataModality::AUDIO_1D:
518 variants.emplace_back(std::vector<T>(shape[0], default_value));
519 break;
520
521 case DataModality::AUDIO_MULTICHANNEL: {
522 uint64_t samples = shape[0];
523 uint64_t channels = shape[1];
524 variants.reserve(channels);
525 for (uint64_t ch = 0; ch < channels; ++ch) {
526 variants.emplace_back(std::vector<T>(samples, default_value));
527 }
528 break;
529 }
530
531 case DataModality::IMAGE_2D:
532 variants.emplace_back(std::vector<T>(shape[0] * shape[1], default_value));
533 break;
534
535 case DataModality::IMAGE_COLOR: {
536 uint64_t height = shape[0];
537 uint64_t width = shape[1];
538 uint64_t channels = shape[2];
539 uint64_t pixels = height * width;
540 variants.reserve(channels);
541 for (uint64_t ch = 0; ch < channels; ++ch) {
542 variants.emplace_back(std::vector<T>(pixels, default_value));
543 }
544 break;
545 }
546
547 case DataModality::SPECTRAL_2D:
548 variants.emplace_back(std::vector<T>(shape[0] * shape[1], default_value));
549 break;
550
551 case DataModality::VOLUMETRIC_3D:
552 variants.emplace_back(std::vector<T>(shape[0] * shape[1] * shape[2], default_value));
553 break;
554
555 case DataModality::VIDEO_GRAYSCALE: {
556 uint64_t frames = shape[0];
557 uint64_t height = shape[1];
558 uint64_t width = shape[2];
559 uint64_t frame_size = height * width;
560 variants.reserve(frames);
561 for (uint64_t f = 0; f < frames; ++f) {
562 variants.emplace_back(std::vector<T>(frame_size, default_value));
563 }
564 break;
565 }
566
567 case DataModality::VIDEO_COLOR: {
568 uint64_t frames = shape[0];
569 uint64_t height = shape[1];
570 uint64_t width = shape[2];
571 uint64_t channels = shape[3];
572 uint64_t frame_size = height * width;
573 variants.reserve(frames * channels);
574 for (uint64_t f = 0; f < frames; ++f) {
575 for (uint64_t ch = 0; ch < channels; ++ch) {
576 variants.emplace_back(std::vector<T>(frame_size, default_value));
577 }
578 }
579 break;
580 }
581
582 default:
583 uint64_t total = std::accumulate(shape.begin(), shape.end(), uint64_t(1), std::multiplies<>());
584 variants.emplace_back(std::vector<T>(total, default_value));
585 break;
586 }
587
588 return variants;
589 }
590};
591
593
594/**
595 * @class FrameView
596 * @brief Zero-copy typed view over one frame of container storage.
597 *
598 * FrameView is the return type of NDDataContainer::get_frame(). It holds a
599 * DataSpanVariant — a span into the container's live storage — without copying
600 * or converting data. The active span alternative matches the container's native
601 * element type: uint8_t for 8-bit image and video, uint16_t for 16-bit image,
602 * float for HDR image, double for audio.
603 *
604 * Callers retrieve typed data via as(), which returns an empty span on type
605 * mismatch rather than throwing. element_type() provides a runtime query for
606 * callers whose branch depends on the native type.
607 *
608 * @par Lifetime
609 * The span inside FrameView points directly into the owning container's internal
610 * buffer. It is valid only for the duration of the current processing turn.
611 * FrameView must not be stored across buffer cycles, frame callbacks, or any
612 * point at which the container may write new data.
613 *
614 * @par Threading
615 * FrameView is not thread-safe. The container's read lock (if any) is held only
616 * during get_frame_span_impl(); it is released before FrameView is returned.
617 * Callers must not access the view concurrently with container writes.
618 *
619 * @see NDDataContainer::get_frame(), DataSpanVariant, DataVariantElement
620 */
622public:
623 /** @brief Construct an empty FrameView. empty() returns true. */
624 FrameView() = default;
625
626 /**
627 * @brief Construct from a DataSpanVariant produced by get_frame_span_impl().
628 * @param span Active alternative must match the container's native element type.
629 */
631 : m_span(span)
632 {
633 }
634
635 /** @brief Returns true if the view holds no elements. */
636 [[nodiscard]] bool empty() const
637 {
638 return std::visit([](const auto& s) { return s.empty(); }, m_span);
639 }
640
641 /** @brief Number of elements in the frame, in units of the native element type. */
642 [[nodiscard]] size_t size() const
643 {
644 return std::visit([](const auto& s) { return s.size(); }, m_span);
645 }
646
647 /**
648 * @brief Runtime query for the native element type of this frame.
649 *
650 * Returns std::type_index of the active span's value_type. Typical values:
651 * - typeid(uint8_t) — 8-bit image/video (RGBA, etc.)
652 * - typeid(uint16_t) — 16-bit image (UNORM or half-float encoded)
653 * - typeid(float) — HDR image (R32F/RGBA32F)
654 * - typeid(double) — audio
655 *
656 * Use this to branch once before calling as<T>() when the container type
657 * is not statically known at the call site.
658 */
659 [[nodiscard]] std::type_index element_type() const
660 {
661 return std::visit([](const auto& s) {
662 return std::type_index(typeid(typename std::decay_t<decltype(s)>::value_type));
663 },
664 m_span);
665 }
666
667 /**
668 * @brief Return a typed span over the frame data without conversion.
669 *
670 * Returns an empty span if T does not match the native element type.
671 * Callers should query element_type() first when the type is not statically known.
672 * The returned span is valid only for the lifetime of the owning container's frame buffer.
673 *
674 * @tparam T Element type. Must satisfy DataVariantElement.
675 * @return Span of const T, empty on type mismatch.
676 */
677 /**
678 * @brief Return a typed span over the frame data without conversion or allocation.
679 *
680 * Returns an empty span if T does not match the native element type.
681 * No exception is thrown on mismatch; check empty() or call element_type() first
682 * when the container type is not statically known.
683 *
684 * The returned span aliases the container's internal buffer directly.
685 * See class-level lifetime and threading notes.
686 *
687 * @tparam T Element type. Must satisfy DataVariantElement.
688 * @return Span of const T into live storage, empty on type mismatch.
689 */
690 template <DataVariantElement T>
691 [[nodiscard]] std::span<const T> as() const
692 {
693 const auto* s = std::get_if<std::span<const T>>(&m_span);
694 return s ? *s : std::span<const T> {};
695 }
696
697 /**
698 * @brief Direct access to the underlying DataSpanVariant for internal use.
699 *
700 * Intended for infrastructure (processors, Yantra pipeline) that must
701 * forward the view without branching on type. Not for general callers.
702 */
703 [[nodiscard]] const DataSpanVariant& raw() const { return m_span; }
704
705private:
707};
708
709} // namespace MayaFlux::Kakshya
uint32_t width
Definition Decoder.cpp:66
const std::vector< float > * pixels
Definition Decoder.cpp:65
double frequency
size_t count
float value
float offset
uint32_t height
FrameView()=default
Construct an empty FrameView.
const DataSpanVariant & raw() const
Direct access to the underlying DataSpanVariant for internal use.
Definition NDData.hpp:703
std::span< const T > as() const
Return a typed span over the frame data without conversion.
Definition NDData.hpp:691
size_t size() const
Number of elements in the frame, in units of the native element type.
Definition NDData.hpp:642
std::type_index element_type() const
Runtime query for the native element type of this frame.
Definition NDData.hpp:659
FrameView(DataSpanVariant span)
Construct from a DataSpanVariant produced by get_frame_span_impl().
Definition NDData.hpp:630
bool empty() const
Returns true if the view holds no elements.
Definition NDData.hpp:636
Zero-copy typed view over one frame of container storage.
Definition NDData.hpp:621
Concept to constrain types to valid DataVariant elements.
Definition NDData.hpp:159
size_t gpu_data_format_bytes(GpuDataFormat fmt) noexcept
Byte size of one element of a GpuDataFormat.
Definition NDData.cpp:9
typename detail::span_const_from_vector_variant< DataVariant >::type DataSpanVariant
Definition NDData.hpp:592
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:102
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:164
@ AUDIO_MULTICHANNEL
Multi-channel audio.
@ SPECTRAL_2D
2D spectral data (time + frequency)
@ UNKNOWN
Unknown or undefined modality.
@ IMAGE_COLOR_ARRAY
4D (idx + 2D + color)
@ VERTICES_3D
3D vertex data (positions, normals, etc.)
@ SCALAR_F32
Single-channel float data.
@ VOLUMETRIC_3D
3D volumetric data
@ VIDEO_GRAYSCALE
3D video (time + 2D grayscale)
@ VIDEO_COLOR
4D video (time + 2D + color)
@ TENSOR_ND
N-dimensional tensor.
@ IMAGE_COLOR
2D RGB/RGBA image
@ IMAGE_2D
2D image (grayscale or single channel)
MemoryLayout
Memory layout for multi-dimensional data.
Definition NDData.hpp:65
@ ROW_MAJOR
C/C++ style (last dimension varies fastest)
@ COLUMN_MAJOR
Fortran/MATLAB style (first dimension varies fastest)
OrganizationStrategy
Data organization strategy for multi-channel/multi-frame data.
Definition NDData.hpp:75
@ HYBRID
Mixed approach based on access patterns.
@ PLANAR
Separate DataVariant per logical unit (LLL...RRR for stereo)
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)
bool is_structured_modality(DataModality modality)
Check if a modality represents structured data (vectors, matrices).
Definition NDData.hpp:200
GpuDataFormat
GPU data formats with explicit precision levels.
Definition NDData.hpp:25
std::string_view modality_to_string(DataModality modality)
Convert DataModality enum to string representation.
Definition NDData.cpp:111
Grouping information for sub-dimensions.
Definition NDData.hpp:258
static DataModule create_audio_multichannel(uint64_t samples, uint64_t channels, T default_value=T {})
Create multi-channel audio data module.
Definition NDData.hpp:448
Role
Semantic role of the dimension.
Definition NDData.hpp:234
static DataModule create_spectral_2d(uint64_t time_windows, uint64_t frequency_bins, T default_value=T {})
Create 2D spectral data module.
Definition NDData.hpp:476
std::string name
Human-readable identifier for the dimension.
Definition NDData.hpp:276
static DataModule create_audio_1d(uint64_t samples, T default_value=T {})
Create 1D audio data module.
Definition NDData.hpp:434
static DataModule create_image_2d(uint64_t height, uint64_t width, T default_value=T {})
Create 2D image data module.
Definition NDData.hpp:462
std::pair< std::vector< DataVariant >, std::vector< DataDimension > > DataModule
Data container combining variants and dimensions.
Definition NDData.hpp:388
static std::vector< DataVariant > create_variants(DataModality modality, const std::vector< uint64_t > &shape, T default_value, OrganizationStrategy org=OrganizationStrategy::PLANAR)
Create data variants for a specific modality.
Definition NDData.hpp:502
static DataModule create_for_modality(DataModality modality, const std::vector< uint64_t > &shape, T default_value=T {}, MemoryLayout layout=MemoryLayout::ROW_MAJOR, OrganizationStrategy strategy=OrganizationStrategy::PLANAR)
Create data module for a specific modality.
Definition NDData.hpp:401
std::optional< ComponentGroup > grouping
Definition NDData.hpp:274
Minimal dimension descriptor focusing on structure only.
Definition NDData.hpp:227
std::variant< std::span< const typename Vecs::value_type >... > type
Definition NDData.hpp:16
Type traits to determine if a type is a valid DataVariant element.
Definition NDData.hpp:111