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

Go to the source code of this file.

Functions

int ck_standardize_vector_f32_checked (const float *input, const float *mean, const float *scale, float *out, size_t elements)
static float standardize (float input, float mean, float scale)
static int valid_span (const float *ptr, size_t elements)

Function Documentation

◆ ck_standardize_vector_f32_checked()

int ck_standardize_vector_f32_checked ( const float * input,
const float * mean,
const float * scale,
float * out,
size_t elements )

Definition at line 17 of file standardize_vector_f32_checked.c.

19{
20 if (!elements || !valid_span(input, elements) || !valid_span(mean, elements) ||
21 !valid_span(scale, elements) || !valid_span(out, elements))
22 return -2;
23 const uintptr_t dst = (uintptr_t)out;
24 const size_t bytes = elements * sizeof(float);
25 const float *sources[] = {input, mean, scale};
26 for (size_t i = 0; i < 3; ++i) {
27 const uintptr_t src = (uintptr_t)sources[i];
28 if (dst < src + bytes && src < dst + bytes)
29 return -2;
30 }
31 for (size_t i = 0; i < elements; ++i)
32 if (!isfinite(input[i]) || !isfinite(mean[i]) || !isfinite(scale[i]) || scale[i] <= 0.0f ||
33 !isfinite(standardize(input[i], mean[i], scale[i])))
34 return -3;
35 for (size_t i = 0; i < elements; ++i)
36 out[i] = standardize(input[i], mean[i], scale[i]);
37 return 0;
38}
static int valid_span(const float *ptr, size_t elements)
static float standardize(float input, float mean, float scale)

References standardize(), and valid_span().

◆ standardize()

float standardize ( float input,
float mean,
float scale )
static

Definition at line 11 of file standardize_vector_f32_checked.c.

12{
13 const volatile float centered = input - mean;
14 return centered / scale;
15}
static float centered(float value, int zero)

References centered().

Referenced by ck_standardize_vector_f32_checked().

◆ valid_span()

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

Definition at line 5 of file standardize_vector_f32_checked.c.

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

Referenced by ck_standardize_vector_f32_checked().