15 const void *opaque,
size_t context_bytes,
16 const int32_t *
ids,
size_t id_elements,
size_t tokens,
size_t channels,
17 float *output,
size_t output_elements,
18 float *scratch,
size_t scratch_elements) {
21 !tokens || !channels || tokens > SIZE_MAX / channels)
23 const size_t elements = tokens * channels;
24 if (elements > SIZE_MAX /
sizeof(
float) || tokens > SIZE_MAX /
sizeof(int32_t) ||
25 id_elements < tokens || output_elements < elements || scratch_elements < elements)
27 uintptr_t lo[5], hi[5];
29 !
span(
ids, tokens *
sizeof(int32_t), &lo[1], &hi[1]) ||
30 !
span(output, elements *
sizeof(
float), &lo[2], &hi[2]) ||
31 !
span(scratch, elements *
sizeof(
float), &lo[3], &hi[3]) ||
32 (uintptr_t)
ids % _Alignof(int32_t) ||
33 (uintptr_t)output % _Alignof(
float) || (uintptr_t)scratch % _Alignof(
float))
39 !span(ctx->
features, channels *
sizeof(
float), &lo[4], &hi[4]) ||
40 (uintptr_t)ctx->
features % _Alignof(
float))
44 for (
size_t i = 0; i < 5; ++i)
45 for (
size_t j = i + 1; j < 5; ++j)
46 if (lo[i] < hi[j] && lo[j] < hi[i])
return -2;
49 if (capacity <= 0 || vocabulary <= 0 || tokens > (
size_t)capacity)
return -2;
50 for (
size_t row = 0; row < tokens; ++row)
51 if (
ids[row] < 0 ||
ids[row] >= vocabulary)
return -1;
54 for (
size_t row = 0; status == 0 && row < tokens; ++row) {
64 for (
size_t col = 0; col < channels; ++col) {
65 const float value = ctx->
features[col];
66 if (!isfinite(value)) {
70 scratch[row * channels + col] = value;
76 if (status)
return status;
77 memcpy(output, scratch, elements *
sizeof(
float));
int decoder_features_sequence_checked_f32(const void *opaque, size_t context_bytes, const int32_t *ids, size_t id_elements, size_t tokens, size_t channels, float *output, size_t output_elements, float *scratch, size_t scratch_elements)