<commit_before>#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <stdio.h>
#include "ghost/util.h"
#include "ghost/bincrs.h"
#include "ghost/machine.h"

static inline uint32_t bswap_32(uint32_t val)
{
    return ((val & (uint32_t)0x000000ffUL) << 24)
        | ((val & (uint32_t)0x0000ff00UL) <<  8)
        | ((val & (uint32_t)0x00ff0000UL) >>  8)
        | ((val & (uint32_t)0xff000000UL) >> 24);
}
static inline uint64_t bswap_64(uint64_t val)
{
    return ((val & (uint64_t)0x00000000000000ffULL) << 56)
        | ((val & (uint64_t)0x000000000000ff00ULL) << 40)
        | ((val & (uint64_t)0x0000000000ff0000ULL) << 24)
        | ((val & (uint64_t)0x00000000ff000000ULL) <<  8)
        | ((val & (uint64_t)0x000000ff00000000ULL) >>  8)
        | ((val & (uint64_t)0x0000ff0000000000ULL) >> 24)
        | ((val & (uint64_t)0x00ff000000000000ULL) >> 40)
        | ((val & (uint64_t)0xff00000000000000ULL) >> 56);
}

#define SWAPREQ(header) (header.endianess == GHOST_BINCRS_LITTLE_ENDIAN)?ghost_machine_bigendian()?1:0:ghost_machine_bigendian()?0:1


int ghost_sparsemat_rowfunc_bincrs(ghost_gidx_t row, ghost_lidx_t *rowlen, ghost_gidx_t *col, void *val, void *arg)
{
    UNUSED(arg);

    static ghost_gidx_t *colInd = NULL, *rowPtr = NULL;
    static char *values = NULL;
    static size_t dtsize = 0;

    if (row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_GETDIM) {
        ghost_bincrs_header_t header;
        ghost_sparsemat_rowfunc_bincrs_initargs args = 
            *(ghost_sparsemat_rowfunc_bincrs_initargs *)val;
        
        char *filename = args.filename;

        ghost_bincrs_header_read(&header,filename);

        col[0] = header.nrows;
        col[1] = header.ncols;
    } else if ((row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_GETRPT) || (row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_INIT)) {

        ghost_sparsemat_rowfunc_bincrs_initargs args = 
            *(ghost_sparsemat_rowfunc_bincrs_initargs *)val;
        char *filename = args.filename;
        ghost_datatype_t matdt = args.dt;
        ghost_datatype_size(&dtsize,matdt);
        ghost_bincrs_header_t header;
        ghost_bincrs_header_read(&header,filename);

        FILE *f;
        ghost_gidx_t i;
        size_t ret;

        if ((f = fopen64(filename,"r")) == NULL) {
            ERROR_LOG("fopen with %s failed!",filename);
            return 1;
        }
        

        if ((ghost_datatype_t)(header.datatype) != matdt) { 
            ERROR_LOG("Casting not yet implemented!");
            return 1;
        }
        if (header.symmetry != GHOST_BINCRS_SYMM_GENERAL) {
            ERROR_LOG("Only general matrices supported at the moment!");
            return 1;
        }

        ghost_malloc((void **)&colInd,header.nnz * sizeof(ghost_gidx_t));
        ghost_malloc((void **)&rowPtr,(header.nrows + 1) * sizeof(ghost_gidx_t));
        ghost_malloc((void **)&values,header.nnz * dtsize);<commit_msg>better warning if types don't match for binCRS files. this fixes #180<commit_after>#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <stdio.h>
#include "ghost/util.h"
#include "ghost/bincrs.h"
#include "ghost/machine.h"

static inline uint32_t bswap_32(uint32_t val)
{
    return ((val & (uint32_t)0x000000ffUL) << 24)
        | ((val & (uint32_t)0x0000ff00UL) <<  8)
        | ((val & (uint32_t)0x00ff0000UL) >>  8)
        | ((val & (uint32_t)0xff000000UL) >> 24);
}
static inline uint64_t bswap_64(uint64_t val)
{
    return ((val & (uint64_t)0x00000000000000ffULL) << 56)
        | ((val & (uint64_t)0x000000000000ff00ULL) << 40)
        | ((val & (uint64_t)0x0000000000ff0000ULL) << 24)
        | ((val & (uint64_t)0x00000000ff000000ULL) <<  8)
        | ((val & (uint64_t)0x000000ff00000000ULL) >>  8)
        | ((val & (uint64_t)0x0000ff0000000000ULL) >> 24)
        | ((val & (uint64_t)0x00ff000000000000ULL) >> 40)
        | ((val & (uint64_t)0xff00000000000000ULL) >> 56);
}

#define SWAPREQ(header) (header.endianess == GHOST_BINCRS_LITTLE_ENDIAN)?ghost_machine_bigendian()?1:0:ghost_machine_bigendian()?0:1


int ghost_sparsemat_rowfunc_bincrs(ghost_gidx_t row, ghost_lidx_t *rowlen, ghost_gidx_t *col, void *val, void *arg)
{
    UNUSED(arg);

    static ghost_gidx_t *colInd = NULL, *rowPtr = NULL;
    static char *values = NULL;
    static size_t dtsize = 0;

    if (row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_GETDIM) {
        ghost_bincrs_header_t header;
        ghost_sparsemat_rowfunc_bincrs_initargs args = 
            *(ghost_sparsemat_rowfunc_bincrs_initargs *)val;
        
        char *filename = args.filename;

        ghost_bincrs_header_read(&header,filename);

        col[0] = header.nrows;
        col[1] = header.ncols;
    } else if ((row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_GETRPT) || (row == GHOST_SPARSEMAT_ROWFUNC_BINCRS_ROW_INIT)) {

        ghost_sparsemat_rowfunc_bincrs_initargs args = 
            *(ghost_sparsemat_rowfunc_bincrs_initargs *)val;
        char *filename = args.filename;
        ghost_datatype_t matdt = args.dt;
        ghost_datatype_size(&dtsize,matdt);
        ghost_bincrs_header_t header;
        ghost_bincrs_header_read(&header,filename);

        FILE *f;
        ghost_gidx_t i;
        size_t ret;

        if ((f = fopen64(filename,"r")) == NULL) {
            ERROR_LOG("fopen with %s failed!",filename);
            return 1;
        }
        

        if ((ghost_datatype_t)(header.datatype) != matdt) { 
            ERROR_LOG("Value casting not implemented! Adjust your sparsemat datatype to match the file!");
            return 1;
        }
        if (header.symmetry != GHOST_BINCRS_SYMM_GENERAL) {
            ERROR_LOG("Only general matrices supported at the moment!");
            return 1;
        }

        ghost_malloc((void **)&colInd,header.nnz * sizeof(ghost_gidx_t));
        ghost_malloc((void **)&rowPtr,(header.nrows + 1) * sizeof(ghost_gidx_t));
        ghost_malloc((void **)&values,header.nnz * dtsize);
{'fraction_non_alphanumeric': 0.12449255751014884, 'fraction_numerical': 0.07493234100135318, 'mean_word_length': 3.143658023826209, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 16, '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': '1631062', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2190, 'n_words': 368}