<commit_before>#pragma once

#include <armadillo>
#include <nanoflann.hpp>


namespace fgt {


class ArmadilloAdaptor {
public:
    ArmadilloAdaptor(const arma::mat& data) : m_data(data) {}

    arma::uword kdtree_get_point_count() const { return m_data.n_rows; }
    double kdtree_distance(const double* p1, const arma::uword idx_p2,
                           size_t size) const {
        double distance = 0;
        // Direct pointer access used in a (probably misguided) attempt at speed
        const double* point = m_data.memptr() + idx_p2;
        for (size_t i = 0; i < size; ++i) {
            double d = p1[i] - point[i * m_data.n_rows];
            distance += d * d;
        }
        return distance;
    }
    double kdtree_get_pt(const arma::uword idx, int dim) const {
        return m_data(idx, dim);
    }
    template <class BBOX>
    bool kdtree_get_bbox(BBOX& bounding_box) const {
        return false;
    }

private:
    const arma::mat& m_data;
};


typedef nanoflann::L2_Simple_Adaptor<double, ArmadilloAdaptor>
    L2_Simple_ArmadilloAdaptor;
}
<commit_msg>KISS in the Armadillo adapter<commit_after>#pragma once

#include <armadillo>
#include <nanoflann.hpp>


namespace fgt {


class ArmadilloAdaptor {
public:
    ArmadilloAdaptor(const arma::mat& data) : m_data(data) {}

    const arma::mat& derived() const { return m_data; };
    arma::uword kdtree_get_point_count() const { return m_data.n_rows; }
    double kdtree_distance(const double* p1, const arma::uword idx_p2,
                           size_t size) const {
        return arma::accu(
            arma::pow(m_data.row(idx_p2) - arma::rowvec(p1, size), 2));
    }
    double kdtree_get_pt(const arma::uword idx, int dim) const {
        return m_data(idx, dim);
    }
    template <class BBOX>
    bool kdtree_get_bbox(BBOX& bounding_box) const {
        // TODO implement using arma methods
        return false;
    }

private:
    const arma::mat& m_data;
};


typedef nanoflann::L2_Simple_Adaptor<double, ArmadilloAdaptor>
    L2_Simple_ArmadilloAdaptor;
}

{'fraction_non_alphanumeric': 0.10457198443579767, 'fraction_numerical': 0.007295719844357977, 'mean_word_length': 2.9106463878326996, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707372', 'n_tokens_mistral': 756, 'n_tokens_neox': 729, 'n_words': 171}