← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
ckernel_select_next_id_checked.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Enumerations

enum  { CK_NEXT_ID_CONTINUE = 0 , CK_NEXT_ID_STOP = 1 , CK_NEXT_ID_BUDGET_EXHAUSTED = 2 }

Functions

int ck_select_next_id_checked_f32 (const float *values, size_t values_elements, size_t rows, size_t channels, size_t row_stride, size_t emitted_frames, size_t min_frames, size_t max_frames, size_t stop_id, size_t suppressed_begin, size_t suppressed_end, int32_t *selected, size_t selected_elements)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CK_NEXT_ID_CONTINUE 
CK_NEXT_ID_STOP 
CK_NEXT_ID_BUDGET_EXHAUSTED 

Definition at line 11 of file ckernel_select_next_id_checked.h.

Function Documentation

◆ ck_select_next_id_checked_f32()

int ck_select_next_id_checked_f32 ( const float * values,
size_t values_elements,
size_t rows,
size_t channels,
size_t row_stride,
size_t emitted_frames,
size_t min_frames,
size_t max_frames,
size_t stop_id,
size_t suppressed_begin,
size_t suppressed_end,
int32_t * selected,
size_t selected_elements )

Definition at line 6 of file select_next_id_checked.c.

12{
13 if (!rows || !channels || channels > INT32_MAX || row_stride < channels ||
14 !max_frames || min_frames > max_frames || emitted_frames > max_frames ||
15 stop_id >= channels || suppressed_begin > suppressed_end ||
16 suppressed_end > channels)
17 return -2;
18 if (rows - 1 > (SIZE_MAX - channels) / row_stride)
19 return -2;
20 const size_t span = (rows - 1) * row_stride + channels;
21 if (span > SIZE_MAX / sizeof(float) || values_elements < span ||
22 selected_elements < 1)
23 return -2;
24 if (!values || !selected ||
25 (uintptr_t)values % _Alignof(float) != 0 ||
26 (uintptr_t)selected % _Alignof(int32_t) != 0 ||
27 (uintptr_t)values > UINTPTR_MAX - span * sizeof(float) ||
28 (uintptr_t)selected > UINTPTR_MAX - sizeof(int32_t))
29 return -1;
30 const uintptr_t begin = (uintptr_t)values;
31 const uintptr_t end = begin + span * sizeof(float);
32 const uintptr_t output = (uintptr_t)selected;
33 if (begin < output + sizeof(int32_t) && output < end)
34 return -1;
35 if (emitted_frames == max_frames)
37
38 const float *row = values + (rows - 1) * row_stride;
39 size_t best = SIZE_MAX;
40 float maximum = 0.0f;
41 for (size_t index = 0; index < channels; ++index) {
42 const float value = row[index];
43 if (!isfinite(value)) return -3;
44 if ((emitted_frames < min_frames && index == stop_id) ||
45 (index >= suppressed_begin && index < suppressed_end &&
46 index != stop_id))
47 continue;
48 if (best == SIZE_MAX || value > maximum) {
49 best = index;
50 maximum = value;
51 }
52 }
53 if (best == SIZE_MAX) return -2;
54 *selected = (int32_t)best;
55 return best == stop_id ? CK_NEXT_ID_STOP : CK_NEXT_ID_CONTINUE;
56}
uint32_t end
Definition utf8.c:215

References CK_NEXT_ID_BUDGET_EXHAUSTED, CK_NEXT_ID_CONTINUE, CK_NEXT_ID_STOP, and end.