<commit_before>#ifndef SQAOD_CUDA_CUDA_MATRIX_H__
#define SQAOD_CUDA_CUDA_MATRIX_H__

#include <common/types.h>
#include <cuda/DeviceObject.h>

namespace sqaod_cuda {

/* light-weight matrix classes for C++ API */

template<class V>
struct DeviceMatrixType : DeviceObject {
    typedef V ValueType;
    typedef sqaod::SizeType SizeType;
    
    DeviceMatrixType() {
        d_data = NULL;
        rows = cols = (SizeType)-1;
    }
    
    DeviceMatrixType(V *_d_data, SizeType _rows, SizeType _cols) {
        d_data = _d_data;
        rows = _rows;
        cols = _cols;
    }
    
    virtual ~DeviceMatrixType() {
    }

    sqaod::Dim dim() const { return sqaod::Dim(rows, cols); }

    V *row(sqaod::IdxType row) {
        return &d_data[row * cols];
    }
    const V *row(sqaod::IdxType row) const {
        return &d_data[row * cols];
    }

    SizeType rows, cols;
    V *d_data;

private:
    DeviceMatrixType(const DeviceMatrixType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
        rows = cols = (SizeType)-1;
    }
};
    

template<class V>
struct DeviceVectorType : DeviceObject {
    typedef V ValueType;
    typedef sqaod::SizeType SizeType;
    
    DeviceVectorType() {
        d_data = NULL;
        size = (SizeType)-1;
    }

    DeviceVectorType(V *_d_data, SizeType _size) {
        d_data = _d_data;
        size = _size;
    }
    
    virtual ~DeviceVectorType() {
    }
    
    SizeType size;
    V *d_data;

private:
    DeviceVectorType(const DeviceVectorType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
        size = (SizeType)-1;
    }
};



template<class V>
struct DeviceScalarType : DeviceObject {
    typedef V ValueType;

    DeviceScalarType() {
        d_data = NULL;
    }

    DeviceScalarType(V *_d_data) {
        d_data = _d_data;
    }
    
    virtual ~DeviceScalarType() {
    }
    
    V *d_data;
private:
    DeviceScalarType(const DeviceScalarType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
    }
};

typedef DeviceVectorType<char> DeviceBits;
typedef DeviceMatrixType<char> DeviceBitMatrix;

}

        
#endif
<commit_msg>Element accessor added, intended to access from CPU when using managed device memory.<commit_after>#ifndef SQAOD_CUDA_CUDA_MATRIX_H__
#define SQAOD_CUDA_CUDA_MATRIX_H__

#include <common/defines.h>
#include <common/types.h>
#include <cuda/DeviceObject.h>

namespace sqaod_cuda {

/* light-weight matrix classes for C++ API */

template<class V>
struct DeviceMatrixType : DeviceObject {
    typedef V ValueType;
    typedef sqaod::SizeType SizeType;
    
    DeviceMatrixType() {
        d_data = NULL;
        rows = cols = (SizeType)-1;
    }
    
    DeviceMatrixType(V *_d_data, SizeType _rows, SizeType _cols) {
        d_data = _d_data;
        rows = _rows;
        cols = _cols;
    }
    
    virtual ~DeviceMatrixType() {
    }

    sqaod::Dim dim() const { return sqaod::Dim(rows, cols); }

    V *row(sqaod::IdxType row) {
        return &d_data[row * cols];
    }
    const V *row(sqaod::IdxType row) const {
        return &d_data[row * cols];
    }

    V &operator()(sqaod::IdxType r, sqaod::IdxType c) {
        assert((0 <= r) && (r < (sqaod::IdxType)rows));
        assert((0 <= c) && (c < (sqaod::IdxType)cols));
        return d_data[r * cols + c];
    }
    
    const V &operator()(sqaod::IdxType r, sqaod::IdxType c) const {
        assert((0 <= r) && (r < (sqaod::IdxType)rows));
        assert((0 <= c) && (c < (sqaod::IdxType)cols));
        return d_data[r * cols + c];
    }

    SizeType rows, cols;
    V *d_data;

private:
    DeviceMatrixType(const DeviceMatrixType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
        rows = cols = (SizeType)-1;
    }
};
    

template<class V>
struct DeviceVectorType : DeviceObject {
    typedef V ValueType;
    typedef sqaod::SizeType SizeType;
    
    DeviceVectorType() {
        d_data = NULL;
        size = (SizeType)-1;
    }

    DeviceVectorType(V *_d_data, SizeType _size) {
        d_data = _d_data;
        size = _size;
    }
    
    V &operator()(sqaod::IdxType idx) {
        return d_data[idx];
    }
    
    const V &operator()(sqaod::IdxType idx) const {
        return d_data[idx];
    }

    virtual ~DeviceVectorType() {
    }
    
    SizeType size;
    V *d_data;

private:
    DeviceVectorType(const DeviceVectorType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
        size = (SizeType)-1;
    }
};



template<class V>
struct DeviceScalarType : DeviceObject {
    typedef V ValueType;

    DeviceScalarType() {
        d_data = NULL;
    }

    DeviceScalarType(V *_d_data) {
        d_data = _d_data;
    }
    
    virtual ~DeviceScalarType() {
    }
    
    V *d_data;
private:
    DeviceScalarType(const DeviceScalarType<V>&);
    virtual void get_data(void **ppv) { 
        *ppv = d_data;
        d_data = NULL;
    }
};

typedef DeviceVectorType<char> DeviceBits;
typedef DeviceMatrixType<char> DeviceBitMatrix;

}

        
#endif

{'fraction_non_alphanumeric': 0.11870642912470952, 'fraction_numerical': 0.0023237800154918666, 'mean_word_length': 2.4250663129973473, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 24, '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': '7530114', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1817, 'n_words': 394}