<commit_before>#include "Halide.h"
#include <cstdio>
#include "benchmark.h"

using namespace Halide;

template<typename A>
const char *string_of_type();

#define DECL_SOT(name)                                          \
    template<>                                                  \
    const char *string_of_type<name>() {return #name;}

DECL_SOT(uint8_t);
DECL_SOT(int8_t);
DECL_SOT(uint16_t);
DECL_SOT(int16_t);
DECL_SOT(uint32_t);
DECL_SOT(int32_t);
DECL_SOT(float);
DECL_SOT(double);

template<typename A>
bool test(int vec_width) {

    int W = vec_width*1;
    int H = 10000;

    Image<A> input(W, H+20);
    for (int y = 0; y < H+20; y++) {
        for (int x = 0; x < W; x++) {
            input(x, y) = (A)((rand() & 0xffff)*0.125 + 1.0);
        }
    }

    Var x, y;
    Func f, g;

    Expr e = input(x, y);
    for (int i = 1; i < 5; i++) {
        e = e + input(x, y+i);
    }

    for (int i = 5; i >= 0; i--) {
        e = e + input(x, y+i);
    }

    f(x, y) = e;
    g(x, y) = e;
    f.bound(x, 0, vec_width).vectorize(x);

    Image<A> outputg = g.realize(W, H);
    Image<A> outputf = f.realize(W, H);

    double t_g = benchmark(1, 10, [&]() {
        g.realize(outputg);
    });
    double t_f = benchmark(1, 10, [&]() {
        f.realize(outputf);
    });

    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (outputf(x, y) != outputg(x, y)) {
                printf("%s x %d failed at %d %d: %d vs %d\n",<commit_msg>Make vectorization test more robust<commit_after>#include "Halide.h"
#include <cstdio>
#include "benchmark.h"

using namespace Halide;

template<typename A>
const char *string_of_type();

#define DECL_SOT(name)                                          \
    template<>                                                  \
    const char *string_of_type<name>() {return #name;}

DECL_SOT(uint8_t);
DECL_SOT(int8_t);
DECL_SOT(uint16_t);
DECL_SOT(int16_t);
DECL_SOT(uint32_t);
DECL_SOT(int32_t);
DECL_SOT(float);
DECL_SOT(double);

template<typename A>
bool test(int vec_width) {

    int W = vec_width*1;
    int H = 10000;

    Image<A> input(W, H+20);
    for (int y = 0; y < H+20; y++) {
        for (int x = 0; x < W; x++) {
            input(x, y) = (A)((rand() & 0xffff)*0.125 + 1.0);
        }
    }

    Var x, y;
    Func f, g;

    Expr e = input(x, y);
    for (int i = 1; i < 5; i++) {
        e = e + input(x, y+i);
    }

    for (int i = 5; i >= 0; i--) {
        e = e + input(x, y+i);
    }

    f(x, y) = e;
    g(x, y) = e;
    f.bound(x, 0, vec_width).vectorize(x);

    // Stop llvm from auto-vectorizing the scalar case and messing up
    // the comparison. Also causes cache effects, but the entire input
    // is small enough to fit in cache.
    g.reorder(y, x);

    Image<A> outputg = g.realize(W, H);
    Image<A> outputf = f.realize(W, H);

    double t_g = benchmark(10, 10, [&]() {
        g.realize(outputg);
    });
    double t_f = benchmark(10, 10, [&]() {
        f.realize(outputf);
    });

    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (outputf(x, y) != outputg(x, y)) {
                printf("%s x %d failed at %d %d: %d vs %d\n",
{'fraction_non_alphanumeric': 0.17455343152616734, 'fraction_numerical': 0.02695079912253212, 'mean_word_length': 1.944649446494465, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493347', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1254, 'n_words': 334}