{% include 'pca/_dot_product.jinja' %}

/**
 * Apply PCA to x vector.
 * Overrides the original vector.
 */
void pca(float x[{{ X_DIM }}]) {
    float u[{{ PCA_DIM }}];

    {% for vector in pca_components %}
    u[{{ loop.index - 1 }}] = dot_product(x, {{ X_DIM }}, {% for vi in vector %} {% if loop.index > 1 %}, {% endif %} {{ F.round(vi, 9) }} {% endfor %});
    {% endfor %}

    {% for vector in pca_components %}
    x[{{ loop.index - 1 }}] = u[{{ loop.index - 1 }}];
    {% endfor %}

    {% for i in range(PCA_DIM, X_DIM) %}
    x[{{ i }}] = 0;
    {% endfor %}
}