← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
audio_text_embedding.c
Go to the documentation of this file.
2#include "ckernel_tts.h"
3
4#include <math.h>
5#include <stdint.h>
6
8 const int32_t *ids, size_t id_elements,
9 const float *table, size_t table_elements,
10 size_t vocabulary, size_t channels, size_t table_stride,
11 float *output, size_t output_elements,
12 size_t tokens, size_t output_stride) {
13 if (!ids || !table || !output || !vocabulary || !channels ||
14 !tokens || table_stride < channels || output_stride < tokens)
16 if (vocabulary - 1 > (SIZE_MAX - channels) / table_stride ||
17 channels - 1 > (SIZE_MAX - tokens) / output_stride)
19 size_t table_required = (vocabulary - 1) * table_stride + channels;
20 size_t output_required = (channels - 1) * output_stride + tokens;
21 if (table_required > SIZE_MAX / sizeof(float) ||
22 output_required > SIZE_MAX / sizeof(float))
24 if (id_elements < tokens || table_elements < table_required ||
25 output_elements < output_required)
27 for (size_t token = 0; token < tokens; ++token) {
28 int32_t id = ids[token];
29 if (id < 0 || (size_t)id >= vocabulary)
31 const float *row = table + (size_t)id * table_stride;
32 for (size_t channel = 0; channel < channels; ++channel)
33 if (!isfinite(row[channel])) return CK_AUDIO_EXTENT_INVALID;
34 }
35 for (size_t channel = 0; channel < channels; ++channel) {
36 float *out = output + channel * output_stride;
37 for (size_t token = 0; token < tokens; ++token)
38 out[token] = table[(size_t)ids[token] * table_stride + channel];
39 }
40 return CK_AUDIO_EXTENT_OK;
41}
int audio_text_embedding_channel_major_f32(const int32_t *ids, size_t id_elements, const float *table, size_t table_elements, size_t vocabulary, size_t channels, size_t table_stride, float *output, size_t output_elements, size_t tokens, size_t output_stride)
@ CK_AUDIO_EXTENT_INVALID
Definition ckernel_tts.h:42
@ CK_AUDIO_EXTENT_LIMIT
Definition ckernel_tts.h:43
@ CK_AUDIO_EXTENT_OVERFLOW
Definition ckernel_tts.h:44
@ CK_AUDIO_EXTENT_OK
Definition ckernel_tts.h:41
const int32_t * ids
Definition tokenizer.h:444
const char * token
Definition tokenizer.h:307