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

Go to the source code of this file.

Functions

int leaky_relu_strided_f32_checked (const float *input, size_t input_elements, size_t input_stride, float *output, size_t output_elements, size_t output_stride, size_t rows, size_t columns, float negative_slope)
 
int tanh_strided_f32_checked (const float *input, size_t input_elements, size_t input_stride, float *output, size_t output_elements, size_t output_stride, size_t rows, size_t columns)
 
int transpose_strided_f32_checked (const float *input, size_t input_elements, size_t input_stride, float *output, size_t output_elements, size_t output_stride, size_t rows, size_t columns)
 

Function Documentation

◆ leaky_relu_strided_f32_checked()

int leaky_relu_strided_f32_checked ( const float *  input,
size_t  input_elements,
size_t  input_stride,
float *  output,
size_t  output_elements,
size_t  output_stride,
size_t  rows,
size_t  columns,
float  negative_slope 
)

Definition at line 23 of file strided_unary_checked.c.

26 {
27 size_t ni, no;
28 if (!ck_checked_span(rows, columns, input_stride, &ni) ||
29 !ck_checked_span(rows, columns, output_stride, &no) ||
30 input_elements < ni || output_elements < no)
31 return -2;
32 if (!isfinite(negative_slope) || negative_slope < 0 ||
33 !ck_checked_region(input, ni) || !ck_checked_region(output, no) ||
34 ck_checked_overlap(input, ni, output, no)) return -1;
35 for (size_t row = 0; row < rows; ++row)
36 for (size_t column = 0; column < columns; ++column) {
37 float value = input[row * input_stride + column];
38 if (!isfinite(value) || (value < 0 && !isfinite(value * negative_slope)))
39 return -3;
40 }
41 for (size_t row = 0; row < rows; ++row)
42 for (size_t column = 0; column < columns; ++column) {
43 float value = input[row * input_stride + column];
44 output[row * output_stride + column] =
45 value >= 0 ? value : value * negative_slope;
46 }
47 return 0;
48}
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)

References ck_checked_overlap(), ck_checked_region(), and ck_checked_span().

◆ tanh_strided_f32_checked()

int tanh_strided_f32_checked ( const float *  input,
size_t  input_elements,
size_t  input_stride,
float *  output,
size_t  output_elements,
size_t  output_stride,
size_t  rows,
size_t  columns 
)

Definition at line 50 of file strided_unary_checked.c.

53 {
54 size_t ni, no;
55 if (!ck_checked_span(rows, columns, input_stride, &ni) ||
56 !ck_checked_span(rows, columns, output_stride, &no) ||
57 input_elements < ni || output_elements < no)
58 return -2;
59 if (!ck_checked_region(input, ni) || !ck_checked_region(output, no) ||
60 ck_checked_overlap(input, ni, output, no)) return -1;
61 for (size_t row = 0; row < rows; ++row)
62 if (!ck_checked_finite(input + row * input_stride, columns)) return -3;
63 for (size_t row = 0; row < rows; ++row)
64 for (size_t column = 0; column < columns; ++column)
65 output[row * output_stride + column] =
66 tanhf(input[row * input_stride + column]);
67 return 0;
68}
static int ck_checked_finite(const float *ptr, size_t n)

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), and ck_checked_span().

◆ transpose_strided_f32_checked()

int transpose_strided_f32_checked ( const float *  input,
size_t  input_elements,
size_t  input_stride,
float *  output,
size_t  output_elements,
size_t  output_stride,
size_t  rows,
size_t  columns 
)

Definition at line 4 of file strided_unary_checked.c.

7 {
8 size_t ni, no;
9 if (!ck_checked_span(rows, columns, input_stride, &ni) ||
10 !ck_checked_span(columns, rows, output_stride, &no) ||
11 input_elements < ni || output_elements < no)
12 return -2;
13 if (!ck_checked_region(input, ni) || !ck_checked_region(output, no) ||
14 ck_checked_overlap(input, ni, output, no)) return -1;
15 for (size_t row = 0; row < rows; ++row)
16 if (!ck_checked_finite(input + row * input_stride, columns)) return -3;
17 for (size_t row = 0; row < rows; ++row)
18 for (size_t column = 0; column < columns; ++column)
19 output[column * output_stride + row] = input[row * input_stride + column];
20 return 0;
21}

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), and ck_checked_span().