Create dimension descriptors for a data modality.
109{
110 std::vector<DataDimension> dims;
112
113 switch (modality) {
115 if (shape.size() != 1) {
116 throw std::invalid_argument("AUDIO_1D requires 1D shape");
117 }
119 break;
120
122 if (shape.size() != 2) {
123 throw std::invalid_argument("AUDIO_MULTICHANNEL requires 2D shape [samples, channels]");
124 }
127 break;
128
130 if (shape.size() != 2) {
131 throw std::invalid_argument("IMAGE_2D requires 2D shape [height, width]");
132 }
135 break;
136
138 if (shape.size() != 3) {
139 throw std::invalid_argument("IMAGE_COLOR requires 3D shape [height, width, channels]");
140 }
144 break;
145
147 if (shape.size() != 2) {
148 throw std::invalid_argument("SPECTRAL_2D requires 2D shape [time_windows, frequency_bins]");
149 }
152 dims[1].stride = strides[1];
153 break;
154
156 if (shape.size() != 3) {
157 throw std::invalid_argument("VOLUMETRIC_3D requires 3D shape [x, y, z]");
158 }
162 break;
163
165 if (shape.size() != 3) {
166 throw std::invalid_argument("VIDEO_GRAYSCALE requires 3D shape [frames, height, width]");
167 }
171 break;
172
174 if (shape.size() != 4) {
175 throw std::invalid_argument("VIDEO_COLOR requires 4D shape [frames, height, width, channels]");
176 }
181 break;
182
183 default:
184 throw std::invalid_argument("Unsupported modality for dimension creation");
185 }
186
187 return dims;
188}
@ AUDIO_MULTICHANNEL
Multi-channel audio.
@ SPECTRAL_2D
2D spectral data (time + frequency)
@ AUDIO_1D
1D audio signal
@ VOLUMETRIC_3D
3D volumetric data
@ VIDEO_GRAYSCALE
3D video (time + 2D grayscale)
@ VIDEO_COLOR
4D video (time + 2D + color)
@ IMAGE_COLOR
2D RGB/RGBA image
@ IMAGE_2D
2D image (grayscale or single channel)
static DataDimension spatial(uint64_t size, char axis, uint64_t stride=1, std::string name="spatial")
Convenience constructor for a spatial dimension.
static DataDimension frequency(uint64_t bins, std::string name="frequency")
Convenience constructor for a frequency dimension.
static DataDimension time(uint64_t samples, std::string name="time")
Convenience constructor for a temporal (time) dimension.
static std::vector< uint64_t > calculate_strides(const std::vector< uint64_t > &shape, MemoryLayout layout)
Calculate memory strides based on shape and layout.
static DataDimension channel(uint64_t count, uint64_t stride=1)
Convenience constructor for a channel dimension.