<commit_before>#include "HdfReader.h"
#include "h5io.h"
#include <cstdlib>
#include <cassert>

// ---------------------------------------------------------------------------

cigma::HdfReader::HdfReader()
{
    file_id = -1;
}

cigma::HdfReader::~HdfReader()
{
}

// ---------------------------------------------------------------------------


int cigma::HdfReader::
open(std::string filename)
{
    file_id = h5io_file_open(filename.c_str(), "r");
    assert(file_id >= 0);
    return 0; // XXX: change return value instead of using assert
}


void cigma::HdfReader::
close()
{
    herr_t status = H5Fclose(file_id);
    if (status < 0)
    {
        // XXX: emit warning?
    }
}

// ---------------------------------------------------------------------------

void cigma::HdfReader::
get_dataset(const char *loc, double **data, int *num, int *dim)
{
    int rank;
    hid_t type_id;
    hid_t dataset_id;
    herr_t status;
    int ierr;

    dataset_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
    assert(H5Tget_class(type_id) == H5T_FLOAT);
    assert(dataset_id >= 0);
    assert((rank == 1) || (rank == 2));
    status = H5Dclose(dataset_id);
    assert(status >= 0); // XXX: emit warning?

    if (rank == 2)
    {
        ierr = h5io_dset_read2(file_id, loc, H5T_NATIVE_DOUBLE,
                               (void **)data, num, dim);
    }
    else if (rank == 1)<commit_msg>Don't forget to initialize ierr in HdfReader::get_dataset()<commit_after>#include "HdfReader.h"
#include "h5io.h"
#include <cstdlib>
#include <cassert>

// ---------------------------------------------------------------------------

cigma::HdfReader::HdfReader()
{
    file_id = -1;
}

cigma::HdfReader::~HdfReader()
{
}

// ---------------------------------------------------------------------------


int cigma::HdfReader::
open(std::string filename)
{
    file_id = h5io_file_open(filename.c_str(), "r");
    assert(file_id >= 0);
    return 0; // XXX: change return value instead of using assert
}


void cigma::HdfReader::
close()
{
    herr_t status = H5Fclose(file_id);
    if (status < 0)
    {
        // XXX: emit warning?
    }
}

// ---------------------------------------------------------------------------

void cigma::HdfReader::
get_dataset(const char *loc, double **data, int *num, int *dim)
{
    int rank;
    hid_t type_id;
    hid_t dataset_id;
    herr_t status;
    int ierr = -1;

    dataset_id = h5io_dset_open(file_id, loc, &type_id, &rank, NULL, NULL);
    assert(H5Tget_class(type_id) == H5T_FLOAT);
    assert(dataset_id >= 0);
    assert((rank == 1) || (rank == 2));
    status = H5Dclose(dataset_id);
    assert(status >= 0); // XXX: emit warning?

    if (rank == 2)
    {
        ierr = h5io_dset_read2(file_id, loc, H5T_NATIVE_DOUBLE,
                               (void **)data, num, dim);
    }
    else if (rank == 1)
{'fraction_non_alphanumeric': 0.2888578414250786, 'fraction_numerical': 0.014320642682500873, 'mean_word_length': 1.6766355140186915, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '761165', 'n_tokens_mistral': 980, 'n_tokens_neox': 955, 'n_words': 208}