/**
 * Compute kernel between feature vector and support vector.
 * Kernel type: {{ KERNEL_TYPE }}
 */
{% if isAttiny %}
double compute_kernel(double x[{{ FEATURES_DIM }}], float 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] * {% if isAttiny %} w[i] {% else %} va_arg(w, double) {% endif %};
        {% elif KERNEL_TYPE == 'rbf' %}
            kernel += pow(x[i] - {% if isAttiny %} w[i] {% else %} va_arg(w, double) {% endif %}, 2);
        {% else %}
            #error "UNKNOWN KERNEL {{ kernel }}";
        {% endif %}

    {% if KERNEL_TYPE == 'poly' %}
        kernel = pow(({{ KERNEL_GAMMA }} * kernel) + {{ KERNEL_COEF }}, {{ KERNEL_DEGREE }});
    {% elif KERNEL_TYPE == 'rbf' %}
        kernel = exp(-{{ KERNEL_GAMMA }} * kernel);
    {% elif KERNEL_TYPE == 'sigmoid' %}
        kernel = sigmoid(({{ KERNEL_GAMMA }} * kernel) + {{ KERNEL_COEF }});
    {% endif %}

    return kernel;
}