7 const float *
right,
size_t right_elements,
8 float *output,
size_t output_elements,
size_t rows,
9 size_t width,
size_t joined_width,
float epsilon)
11 size_t elements, joined;
12 if (!width || width > SIZE_MAX / 2 || joined_width != width * 2 ||
13 !isfinite(epsilon) || epsilon <= 0.0f ||
16 left_elements < elements || right_elements < elements || output_elements < joined)
24 for (
size_t row = 0; row < rows; ++row) {
25 const float *inputs[] = {
left + row * width,
right + row * width};
26 for (
size_t side = 0; side < 2; ++side) {
27 const float *x = inputs[side];
29 for (
size_t i = 0; i < width; ++i) squared += (
double)x[i] * x[i];
30 const double scale = 1.0 / sqrt(squared / (
double)width + epsilon);
31 for (
size_t i = 0; i < width; ++i)
32 output[row * joined_width + side * width + i] = (
float)(x[i] * scale);
38static double mix(
float input,
float message,
float forget,
float gain)
40 return (1.0 - (
double)forget) * input + (double)gain * message;
44 const float *message,
size_t message_elements,
45 const float *forget,
size_t forget_elements,
46 const float *gain,
size_t gain_elements,
47 float *output,
size_t output_elements,
size_t elements)
49 if (!elements || input_elements < elements || message_elements < elements ||
50 forget_elements < elements || gain_elements < elements || output_elements < elements)
53 const float *inputs[] = {input, message, forget, gain};
54 for (
size_t i = 0; i <
sizeof(inputs) /
sizeof(inputs[0]); ++i) {
59 for (
size_t i = 0; i < elements; ++i) {
60 if (fabsf(forget[i]) > 1.0f || fabsf(gain[i]) > 1.0f ||
61 fabs(
mix(input[i], message[i], forget[i], gain[i])) > FLT_MAX)
return -3;
63 for (
size_t i = 0; i < elements; ++i)
64 output[i] = (
float)
mix(input[i], message[i], forget[i], gain[i]);
69 const float *
right,
size_t right_elements,
70 float *output,
size_t output_elements,
71 size_t rows,
size_t left_width,
size_t right_width,
size_t width)
74 if (!left_width || !right_width || left_width > SIZE_MAX - right_width ||
75 width != left_width + right_width ||
79 left_elements < l || right_elements < r || output_elements < o)
return -2;
84 for (
size_t row = 0; row < rows; ++row) {
85 memcpy(output + row * width,
left + row * left_width, left_width *
sizeof(
float));
86 memcpy(output + row * width + left_width,
right + row * right_width, right_width *
sizeof(
float));
static int ck_checked_finite(const float *ptr, size_t n)
static int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span)
static int ck_checked_region(const float *ptr, size_t n)
static int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb)
int rms_pair_concat_rows_checked_f32(const float *left, size_t left_elements, const float *right, size_t right_elements, float *output, size_t output_elements, size_t rows, size_t width, size_t joined_width, float epsilon)
int message_control_rows_checked_f32(const float *input, size_t input_elements, const float *message, size_t message_elements, const float *forget, size_t forget_elements, const float *gain, size_t gain_elements, float *output, size_t output_elements, size_t elements)
static double mix(float input, float message, float forget, float gain)
int concat_feature_rows_checked_f32(const float *left, size_t left_elements, const float *right, size_t right_elements, float *output, size_t output_elements, size_t rows, size_t left_width, size_t right_width, size_t width)
const char const char * right