Skip to content

Commit

Permalink
Merge pull request #8 from roboticarm2000/fixwarnings
Browse files Browse the repository at this point in the history
Fix warnings reported by VS 2019 and its code analyzer
  • Loading branch information
f0uriest authored Nov 17, 2021
2 parents 78158e3 + ecfa542 commit 51b18e1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
14 changes: 7 additions & 7 deletions include/k2c_activations.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ k2c_activationType * k2c_linear = k2c_linear_func;
void k2c_exponential_func(float * x, const size_t size) {

for (size_t i=0; i<size; ++i) {
x[i] = exp(x[i]);
x[i] = expf(x[i]);
}
}
k2c_activationType * k2c_exponential = k2c_exponential_func;
Expand Down Expand Up @@ -95,7 +95,7 @@ k2c_activationType * k2c_hard_sigmoid = k2c_hard_sigmoid_func;
void k2c_tanh_func(float * x, const size_t size) {

for (size_t i=0; i<size; ++i) {
x[i] = tanh(x[i]);
x[i] = tanhf(x[i]);
}
}
k2c_activationType * k2c_tanh = k2c_tanh_func;
Expand All @@ -111,7 +111,7 @@ k2c_activationType * k2c_tanh = k2c_tanh_func;
void k2c_sigmoid_func(float * x, const size_t size) {

for (size_t i=0; i < size; ++i) {
x[i] = 1/(1+exp(-x[i]));
x[i] = 1/(1+expf(-x[i]));
}
}
k2c_activationType * k2c_sigmoid = k2c_sigmoid_func;
Expand All @@ -136,7 +136,7 @@ void k2c_softmax_func(float * x, const size_t size) {
}

for (size_t i=0; i < size; ++i) {
x[i] = exp(x[i]-xmax);
x[i] = expf(x[i]-xmax);
}

for (size_t i=0; i < size; ++i) {
Expand All @@ -161,7 +161,7 @@ k2c_activationType * k2c_softmax = k2c_softmax_func;
void k2c_softplus_func(float * x, const size_t size) {

for (size_t i=0; i < size; ++i) {
x[i] = log1p(exp(x[i]));
x[i] = log1pf(expf(x[i]));
}
}
k2c_activationType * k2c_softplus = k2c_softplus_func;
Expand All @@ -177,7 +177,7 @@ k2c_activationType * k2c_softplus = k2c_softplus_func;
void k2c_softsign_func(float * x, const size_t size) {

for (size_t i=0; i < size; ++i) {
x[i] = x[i]/(1.0f + fabs(x[i]));
x[i] = x[i]/(1.0f + fabsf(x[i]));
}
}
k2c_activationType * k2c_softsign = k2c_softsign_func;
Expand Down Expand Up @@ -237,7 +237,7 @@ void k2c_ELU(float * x, const size_t size, const float alpha) {

for (size_t i=0; i < size; ++i) {
if (x[i] <= 0.0f) {
x[i] = alpha*expm1(x[i]);
x[i] = alpha*expm1f(x[i]);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions include/k2c_helper_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ void k2c_flip(k2c_tensor *A, const size_t axis) {
*/
float* k2c_read_array(const char* filename, const size_t array_size) {
float* ptr = (float*) malloc(array_size * sizeof(float));
if (!ptr) {
printf("cannot allocate memory %s \n", filename);
exit(-1);
}
size_t ctr = 0;
FILE *finp;
int foo;
Expand Down
2 changes: 1 addition & 1 deletion include/k2c_recurrent_layers.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void k2c_gru(k2c_tensor* output, const k2c_tensor* input, float * state,
}
}
else {
for (int i=0; i<in_height; ++i) {
for (size_t i=0; i<in_height; ++i) {
k2c_grucell(state, &input->array[i*in_width], kernel, recurrent_kernel, bias,
fwork, reset_after, recurrent_activation, output_activation);
if (return_sequences) {
Expand Down
9 changes: 5 additions & 4 deletions keras2c/make_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def make_test_suite(model, function_name, malloc_vars, num_tests=10, stateful=Fa
s += 'float maxabs(k2c_tensor *tensor1, k2c_tensor *tensor2);\n'
s += 'struct timeval GetTimeStamp(); \n \n'
file.write(s)
s = 'int main(){\n'
file.write(s)
for i in range(num_tests):
if i == num_tests//2 and stateful:
model.reset_states()
Expand Down Expand Up @@ -109,6 +107,9 @@ def make_test_suite(model, function_name, malloc_vars, num_tests=10, stateful=Fa
model_outputs[j] + '_test' + str(i+1)))
file.write(Weights2C.array2c(np.zeros(output.shape), 'c_' +
model_outputs[j] + '_test' + str(i+1)))
s = 'int main(){\n'
file.write(s)

s = ' float errors[' + str(num_tests*num_outputs) + '];\n'
s += ' size_t num_tests = ' + str(num_tests) + '; \n'
s += 'size_t num_outputs = ' + str(num_outputs) + '; \n'
Expand Down Expand Up @@ -138,7 +139,7 @@ def make_test_suite(model, function_name, malloc_vars, num_tests=10, stateful=Fa
file.write('\n')
s = 'clock_t t1 = clock(); \n'
s += 'printf("Average time over ' + str(num_tests) + \
' tests: %e s \\n\", \n (double)(t1-t0)/(double)CLOCKS_PER_SEC/(double)' + \
' tests: %e s \\n\", \n ((double)t1-t0)/(double)CLOCKS_PER_SEC/(double)' + \
str(num_tests) + '); \n'
file.write(s)

Expand Down Expand Up @@ -169,7 +170,7 @@ def make_test_suite(model, function_name, malloc_vars, num_tests=10, stateful=Fa
float x = 0; \n
float y = 0; \n
for(size_t i=0; i<tensor1->numel; i++){\n
y = fabs(tensor1->array[i]-tensor2->array[i]);
y = fabsf(tensor1->array[i]-tensor2->array[i]);
if (y>x) {x=y;}}
return x;}\n\n"""
file.write(s)
Expand Down
4 changes: 2 additions & 2 deletions keras2c/weights2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def array2c(array, name, malloc=False):
elif temp[i] == -np.inf:
s += "-HUGE_VALF,"
else:
s += "{:+.8e}".format(temp[i]) + ','
s += "{:+.8e}f".format(temp[i]) + ','
count += 1
if (count) % 5 is 0:
if (count) % 5 == 0:
s += '\n'
s += '}; \n'
s += 'k2c_tensor ' + name + ' = {&' + name + \
Expand Down

0 comments on commit 51b18e1

Please sign in to comment.