<commit_before>#ifndef USE_BLAS
#include "third_party/Eigen/Core"
#endif
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#ifdef USE_BLAS
#include <cblas.h>

int _use_blas()
{
    return 1;
}
#else // USE_BLAS

float cblas_snrm2(const int N, const float *X, const int incX)
{
    float norm = 0;
    for (int i=0; i<N; i++) {
        norm += pow(X[i], 2);
    }
    return sqrtf(norm);
}

float cblas_sdot(const int N, const float *X, const int incX,
                 const float *Y, const int incY)
{
    // need non-const for vector
    float *pX = (float*)X;
    float *pY = (float*)Y;
    Eigen::Map<Eigen::VectorXf> a(pX, N);
    Eigen::Map<Eigen::VectorXf> b(pY, N);
    return -1.; //a.dot(b);
}
<commit_msg>implement sdot and snrm2 with eigen<commit_after>#ifndef USE_BLAS
#include "third_party/Eigen/Core"
#endif
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#ifdef USE_BLAS
#include <cblas.h>

int _use_blas()
{
    return 1;
}
#else // USE_BLAS

Eigen::VectorXf arr_to_vecf(const int N, const float *arr) {
    // need non-const for vector
    Eigen::Map<Eigen::VectorXf> v((float*)arr, N);
    return v;
}


float cblas_snrm2(const int N, const float *X, const int incX)
{
    Eigen::VectorXf v = arr_to_vecf(N, X);
    return v.norm();
}

float cblas_sdot(const int N, const float *X, const int incX,
                 const float *Y, const int incY)
{
    Eigen::VectorXf a = arr_to_vecf(N, X);
    Eigen::VectorXf b = arr_to_vecf(N, Y);
    return a.dot(b);
}

{'fraction_non_alphanumeric': 0.14458641560188298, 'fraction_numerical': 0.00605245460659045, 'mean_word_length': 3.227272727272727, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, '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': '2321963', 'n_tokens_mistral': 623, 'n_tokens_neox': 615, 'n_words': 163}