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

Go to the source code of this file.

Functions

int ck_row_prefix_f32_checked (const float *input, float *output, size_t input_elements, size_t output_elements, size_t rows, size_t input_width, size_t output_width, size_t prefix_width)
static int valid_span (const float *ptr, size_t elements)

Function Documentation

◆ ck_row_prefix_f32_checked()

int ck_row_prefix_f32_checked ( const float * input,
float * output,
size_t input_elements,
size_t output_elements,
size_t rows,
size_t input_width,
size_t output_width,
size_t prefix_width )

Definition at line 13 of file row_prefix_f32_checked.c.

16{
17 if (!rows || !prefix_width || prefix_width > input_width || prefix_width > output_width ||
18 rows > SIZE_MAX / input_width || rows > SIZE_MAX / output_width ||
19 input_elements != rows * input_width || output_elements != rows * output_width ||
20 !valid_span(input, input_elements) || !valid_span(output, output_elements))
21 return -2;
22 const uintptr_t src = (uintptr_t)input, dst = (uintptr_t)output;
23 if (src < dst + output_elements * sizeof(float) && dst < src + input_elements * sizeof(float))
24 return -2;
25 for (size_t r = 0; r < rows; ++r)
26 for (size_t c = 0; c < prefix_width; ++c)
27 if (!isfinite(input[r * input_width + c]))
28 return -3;
29 for (size_t r = 0; r < rows; ++r) {
30 float *out = output + r * output_width;
31 memcpy(out, input + r * input_width, prefix_width * sizeof(float));
32 memset(out + prefix_width, 0, (output_width - prefix_width) * sizeof(float));
33 }
34 return 0;
35}
static int valid_span(const float *ptr, size_t elements)

References valid_span().

◆ valid_span()

int valid_span ( const float * ptr,
size_t elements )
static

Definition at line 6 of file row_prefix_f32_checked.c.

7{
8 return ptr && (uintptr_t)ptr % _Alignof(float) == 0 &&
9 elements <= (UINTPTR_MAX - (uintptr_t)ptr) / sizeof(float);
10}

Referenced by ck_row_prefix_f32_checked().