<commit_before>#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/gather.h>
#include <thrust/segmented_scan.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <iostream>
#include <iomanip>

// This example computes a summed area table using segmented scan
// http://en.wikipedia.org/wiki/Summed_area_table



// convert a linear index to a linear index in the transpose 
struct transpose_index
{
    size_t m, n;

    typedef size_t result_type;
    
    __host__ __device__
    transpose_index(size_t _m, size_t _n) : m(_m), n(_n) {}

    __host__ __device__
    size_t operator()(size_t linear_index)
    {
        size_t i = linear_index / n;
        size_t j = linear_index % n;

        return m * j + i;
    }
};

// convert a linear index to a row index
struct row_index
{
    size_t n;
    
    typedef size_t result_type;

    __host__ __device__
    row_index(size_t _n) : n(_n) {}

    __host__ __device__
    size_t operator()(size_t i)
    {
        return i / n;
    }
};

// transpose an M-by-N array
template <typename T>
void transpose(size_t m, size_t n, thrust::device_vector<T>& src, thrust::device_vector<T>& dst)
{
    thrust::experimental::counting_iterator<size_t> indices(0);
    
    thrust::gather(dst.begin(), dst.end(),
                   make_transform_iterator(indices, transpose_index(n, m)),
                   src.begin());
}


// scan the rows of an M-by-N array
template <typename T>
void scan_horizontally(size_t m, size_t n, thrust::device_vector<T>& d_data)
{
    thrust::experimental::counting_iterator<size_t> indices(0);

    thrust::experimental::inclusive_segmented_scan(d_data.begin(), d_data.end(),
                                     make_transform_iterator(indices, row_index(n)),
                                     d_data.begin());
}

// print an M-by-N array
template <typename T>
void print(size_t m, size_t n, thrust::device_vector<T>& d_data)
{
    thrust::host_vector<T> h_data = d_data;

    for(size_t i = 0; i < m; i++)
    {
        for(size_t j = 0; j < n; j++)
            std::cout << std::setw(8) << h_data[i * n + j] << " ";
        std::cout << "\n";
    }
}

int main(void)
{
    size_t m = 3; // number of rows<commit_msg>added missing namespace to make_transform_iterator()<commit_after>#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/gather.h>
#include <thrust/segmented_scan.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <iostream>
#include <iomanip>

// This example computes a summed area table using segmented scan
// http://en.wikipedia.org/wiki/Summed_area_table



// convert a linear index to a linear index in the transpose 
struct transpose_index
{
    size_t m, n;

    typedef size_t result_type;
    
    __host__ __device__
    transpose_index(size_t _m, size_t _n) : m(_m), n(_n) {}

    __host__ __device__
    size_t operator()(size_t linear_index)
    {
        size_t i = linear_index / n;
        size_t j = linear_index % n;

        return m * j + i;
    }
};

// convert a linear index to a row index
struct row_index
{
    size_t n;
    
    typedef size_t result_type;

    __host__ __device__
    row_index(size_t _n) : n(_n) {}

    __host__ __device__
    size_t operator()(size_t i)
    {
        return i / n;
    }
};

// transpose an M-by-N array
template <typename T>
void transpose(size_t m, size_t n, thrust::device_vector<T>& src, thrust::device_vector<T>& dst)
{
    thrust::experimental::counting_iterator<size_t> indices(0);
    
    thrust::gather(dst.begin(), dst.end(),
                   thrust::make_transform_iterator(indices, transpose_index(n, m)),
                   src.begin());
}


// scan the rows of an M-by-N array
template <typename T>
void scan_horizontally(size_t m, size_t n, thrust::device_vector<T>& d_data)
{
    thrust::experimental::counting_iterator<size_t> indices(0);

    thrust::experimental::inclusive_segmented_scan(d_data.begin(), d_data.end(),
                                                   thrust::make_transform_iterator(indices, row_index(n)),
                                                   d_data.begin());
}

// print an M-by-N array
template <typename T>
void print(size_t m, size_t n, thrust::device_vector<T>& d_data)
{
    thrust::host_vector<T> h_data = d_data;

    for(size_t i = 0; i < m; i++)
    {
        for(size_t j = 0; j < n; j++)
            std::cout << std::setw(8) << h_data[i * n + j] << " ";
        std::cout << "\n";
    }
}

int main(void)
{
    size_t m = 3; // number of rows
{'fraction_non_alphanumeric': 0.12540400775694893, 'fraction_numerical': 0.002585649644473174, 'mean_word_length': 2.789387755102041, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 39, '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': '7531319', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1598, 'n_words': 385}