From 915f055c43bf2de7a6cbd3c8807345d4d92fed8a Mon Sep 17 00:00:00 2001 From: Agrimagsrl Date: Sat, 21 Dec 2019 18:49:49 +0100 Subject: [PATCH] add attiny support --- MANIFEST | 1 - dist/micromlgen-0.5.tar.gz | Bin 3625 -> 0 bytes dist/micromlgen-0.6.tar.gz | Bin 0 -> 3358 bytes .../__pycache__/micromlgen.cpython-36.pyc | Bin 1236 -> 1286 bytes micromlgen/micromlgen.py | 5 +++-- micromlgen/templates/compute_kernels.jinja | 11 ++++++++++- micromlgen/templates/kernel_function.jinja | 9 +++++++-- publish | 2 +- setup.py | 4 ++-- 9 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 dist/micromlgen-0.5.tar.gz create mode 100644 dist/micromlgen-0.6.tar.gz diff --git a/MANIFEST b/MANIFEST index 8425fb4..0011e56 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,7 +3,6 @@ setup.cfg setup.py micromlgen/__init__.py micromlgen/micromlgen.py -micromlgen/micromlgen_test.py micromlgen/templates/binary_classification.jinja micromlgen/templates/classmap.jinja micromlgen/templates/compute_class.jinja diff --git a/dist/micromlgen-0.5.tar.gz b/dist/micromlgen-0.5.tar.gz deleted file mode 100644 index fdc33cf2d4eff93a20d14349d3f5a1bf69a49a06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3625 zcmV+^4%YD>iwFof+v{Bd|72-%bT4gbV{&h8Y-eR|Eif)ME_7jX0PP%WQ`<Q)TBvAgv>zyN5q8u)9r8ix8SVau#FTGdvgQEx%HS+CX2Ez;Q9 z08E3>_6gYv*w}OFdc4Q#@ zZSt1hQ^%W(sT-1BXou5)wA-XcDrDc8+}J7HLpP-EfDXw1bikk^eWDZ&d%c%$o53s&%u){Xe5#&-MQ%fNSRg z3&Ls0oB$Lb$UYlSJU=9SFKGOKQ6t0!n*c6hA=xp7G89kj{vAk409BW2-4#~eM`i=b zV0UqRCsGHU0_X-_ptzlg_gtIuWwlY^tZi-$kZamZD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=6@U2YM%eyRQ!i$R&J<+XKXPbDKJ(5mvzCn zVa2Dc|wG!w+SkP?QX6^7bMs?*Vq=S;Us#3LMp9&hXY#0iR&-PtFo3^<(bT$+@~bfu1@JH!?9e>=PbSU%elFAt8-h9 zH;KABw@+Ffmaok>tj%7=SCVoyoec2ImryT?FoKR)l%ljps>#%Xr*877?f0?&%DI3S zeg0E7t8x6-Fd7*D)#}yU{%-=*{2yQ6&o=t86?0EpsyZAzh^n}5O{Ot>#%3wq$oURQ zF*=n4Cikbf^(-3CvL!u}6nm?YqCT>8?Ls*>t7RVHNUFVD{vVTnOuba95|3mrzzrp*DB>C5T^yt)uIJiN0Zt0d+yaD&?r5ug5enu|;8Tn70f_y>w zuQp@(#}oj{f6K`2|EA=h3wW8#P;}qv@yjO4+d)!lmyS|(vKifna;yn}<87AZjGxJh zJI^fasUsaL+!^b`~6Z3!ddVc<6!}5Rsxco00 zdGH3*2PP@|-oKf;cXZH;*nE!OuZ(oZYjW`Or;{VAcle*KJneCtq~-1}Z!rnCx10x1 z9xy}>Mk&p!)8RTrc|4!mx<&C@j+~0!U6pnx-KjDGWwvq*tMc|gs)AZC|CYsE7FyP~ ze+}mG@Bhj7f6P{k$Nxs7m4E+bBM`mooxJLwT*~*m@n3Ey|9bX6xs1+!{&qF+`1^k* zmw&U`tkmbzs9P-P zI=(y0ze3^f%4y-R(*iM`67jDKC1M8zU&>D(FrV0S92y>v;7g<9T@mq0>GSTq_X7K} zfPAmCrK~6(?N4EeuMwnCUnSo#z|)Kp`-01V;i{Z4n2VxxU(%DKeB47`zyZv9CFAZha7UqA%`4t$RURuz7PB#sd=fL0C)fZY)xUV diff --git a/dist/micromlgen-0.6.tar.gz b/dist/micromlgen-0.6.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..7e13d1559e3bc7bd2e0c3a433df842afac8aafa4 GIT binary patch literal 3358 zcmV+(4dL=1iwFpKRsLN9|72-%bT4gbV{&h8Y-eR|Eif)NE_7jX0PP%UbJ|MMp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 0 %},{% endif %} {{ wj }} {% endfor %}); + {% if isAttiny %} + {% for j, wj in F.enumerate(w) %} w[{{ j }}] = {{ wj }}; {% endfor %} + kernels[{{ i }}] = compute_kernel(x, w); + {% else %} + kernels[{{ i }}] = compute_kernel(x, {% for j, wj in F.enumerate(w) %} {% if j > 0 %},{% endif %} {{ wj }} {% endfor %}); + {% endif %} {% endfor %} \ No newline at end of file diff --git a/micromlgen/templates/kernel_function.jinja b/micromlgen/templates/kernel_function.jinja index 0ca4bb2..c38fc9d 100644 --- a/micromlgen/templates/kernel_function.jinja +++ b/micromlgen/templates/kernel_function.jinja @@ -2,17 +2,22 @@ * Compute kernel between feature vector and support vector. * Kernel type: {{ KERNEL_TYPE }} */ +{% if isAttiny %} +double compute_kernel(double x[{{ FEATURES_DIM }}], double w[{{ FEATURES_DIM }}]) { + double kernel = 0.0; +{% else %} double compute_kernel(double x[{{ FEATURES_DIM }}], ...) { va_list w; double kernel = 0.0; va_start(w, {{ FEATURES_DIM }}); +{% endif %} for (uint16_t i = 0; i < {{ FEATURES_DIM }}; i++) {% if KERNEL_TYPE in ['linear', 'poly', 'sigmoid'] %} - kernel += x[i] * va_arg(w, double); + kernel += x[i] * {% if isAttiny %} w[i] {% else %} va_arg(w, double), 2) {% endif %}; {% elif KERNEL_TYPE == 'rbf' %} - kernel += pow(x[i] - va_arg(w, double), 2); + kernel += pow(x[i] - {% if isAttiny %} w[i] {% else %} va_arg(w, double), 2) {% endif %}; {% else %} #error "UNKNOWN KERNEL {{ kernel }}"; {% endif %} diff --git a/publish b/publish index b745c14..61a4270 100755 --- a/publish +++ b/publish @@ -1,6 +1,6 @@ #!/bin/bash -git push origin master -f +#git push origin master -f rm -rf dist/* python setup.py sdist twine upload dist/* \ No newline at end of file diff --git a/setup.py b/setup.py index ef7267b..ca929ca 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,13 @@ setup( name = 'micromlgen', packages = ['micromlgen'], - version = '0.5', + version = '0.6', license='MIT', description = 'Generate C code for microcontrollers from Python\'s sklearn classifiers', author = 'Simone Salerno', author_email = 'web@agrimag.it', url = 'https://github.com/agrimagsrl/micromlgen', - download_url = 'https://github.com/agrimagsrl/micromlgen/archive/v_05.tar.gz', + download_url = 'https://github.com/agrimagsrl/micromlgen/archive/v_06.tar.gz', keywords = ['ML', 'microcontrollers', 'sklearn', 'machine learning'], install_requires=[ 'jinja2',