diff --git a/tests/pkg/emlearn/.gitignore b/tests/pkg/emlearn/.gitignore index 3fec32c84275..7848be991941 100644 --- a/tests/pkg/emlearn/.gitignore +++ b/tests/pkg/emlearn/.gitignore @@ -1 +1,4 @@ tmp/ +/model_head.h +/model_tail.h +/tmp.h diff --git a/tests/pkg/emlearn/Makefile b/tests/pkg/emlearn/Makefile index fb0721bb2058..1e4376cc3c8f 100644 --- a/tests/pkg/emlearn/Makefile +++ b/tests/pkg/emlearn/Makefile @@ -8,6 +8,21 @@ BUILDDEPS += model.h include $(RIOTBASE)/Makefile.include -model.h: $(CURDIR)/model +model_head.h: + $(Q)echo "#ifndef MODEL_H" > model_head.h + $(Q)echo "#define MODEL_H" >> model_head.h + $(Q)echo "#ifdef __cplusplus" >> model_head.h + $(Q)echo "extern \"C\" {" >> model_head.h + $(Q)echo "#endif" >> model_head.h + +model_tail.h: + $(Q)echo "#ifdef __cplusplus" > model_tail.h + $(Q)echo "}" >> model_tail.h + $(Q)echo "#endif" >> model_tail.h + $(Q)echo "#endif /* MODEL_H */" >> model_tail.h + +model.h: $(CURDIR)/model model_head.h model_tail.h $(Q)$(CURDIR)/generate_model.py - $(Q)echo "/* fix for no newline at eof */" >> model.h + $(Q)sed -i model.h -e 's/[\t ]*$$//g' + $(Q)cat model_head.h model.h model_tail.h > tmp.h + $(Q)mv tmp.h model.h diff --git a/tests/pkg/emlearn/model.h b/tests/pkg/emlearn/model.h index a18c45ba1faa..4ecfc772b541 100644 --- a/tests/pkg/emlearn/model.h +++ b/tests/pkg/emlearn/model.h @@ -1,8 +1,13 @@ +#ifndef MODEL_H +#define MODEL_H +#ifdef __cplusplus +extern "C" { +#endif // !!! This file is generated using emlearn !!! #include - + EmlTreesNode model_nodes[1433] = { { 34, 3.5, 1, 79 }, @@ -1437,14 +1442,14 @@ EmlTreesNode model_nodes[1433] = { { 19, 2.5, 25, 1430 }, { 10, 12.0, 31, 25 }, { 37, 11.5, 31, 27 }, - { 17, 6.0, 119, 27 } + { 17, 6.0, 119, 27 } }; int32_t model_tree_roots[10] = { 0, 168, 304, 448, 589, 719, 866, 1001, 1152, 1307 }; EmlTrees model = { 1433, - model_nodes, + model_nodes, 10, model_tree_roots, }; @@ -2084,7 +2089,7 @@ static inline int32_t model_predict_tree_0(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_1(const float *features, int32_t features_length) { if (features[42] < 7.5) { @@ -2633,7 +2638,7 @@ static inline int32_t model_predict_tree_1(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_2(const float *features, int32_t features_length) { if (features[10] < 7.5) { @@ -3214,7 +3219,7 @@ static inline int32_t model_predict_tree_2(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_3(const float *features, int32_t features_length) { if (features[30] < 1.5) { @@ -3783,7 +3788,7 @@ static inline int32_t model_predict_tree_3(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_4(const float *features, int32_t features_length) { if (features[36] < 0.5) { @@ -4308,7 +4313,7 @@ static inline int32_t model_predict_tree_4(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_5(const float *features, int32_t features_length) { if (features[30] < 0.5) { @@ -4901,7 +4906,7 @@ static inline int32_t model_predict_tree_5(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_6(const float *features, int32_t features_length) { if (features[21] < 0.5) { @@ -5446,7 +5451,7 @@ static inline int32_t model_predict_tree_6(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_7(const float *features, int32_t features_length) { if (features[41] < 0.5) { @@ -6055,7 +6060,7 @@ static inline int32_t model_predict_tree_7(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_8(const float *features, int32_t features_length) { if (features[58] < 5.5) { @@ -6680,7 +6685,7 @@ static inline int32_t model_predict_tree_8(const float *features, int32_t featur } } } - + static inline int32_t model_predict_tree_9(const float *features, int32_t features_length) { if (features[34] < 3.5) { @@ -7189,7 +7194,7 @@ static inline int32_t model_predict_tree_9(const float *features, int32_t featur } } } - + int32_t model_predict(const float *features, int32_t features_length) { @@ -7206,7 +7211,7 @@ int32_t model_predict(const float *features, int32_t features_length) { _class = model_predict_tree_7(features, features_length); votes[_class] += 1; _class = model_predict_tree_8(features, features_length); votes[_class] += 1; _class = model_predict_tree_9(features, features_length); votes[_class] += 1; - + int32_t most_voted_class = -1; int32_t most_voted_votes = 0; for (int32_t i=0; i<10; i++) { @@ -7218,4 +7223,7 @@ int32_t model_predict(const float *features, int32_t features_length) { } return most_voted_class; } - /* fix for no newline at eof */ +#ifdef __cplusplus +} +#endif +#endif /* MODEL_H */