<commit_before>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __BH_ARRAY_H
#define __BH_ARRAY_H

#include <algorithm>
#include <stdbool.h>
#include <iostream>
#include <cstring>
#include <cassert>
#include "bh_type.h"
#include "bh_win.h"

#include <boost/serialization/split_member.hpp>

// Forward declaration of class boost::serialization::access
namespace boost {namespace serialization {class access;}}

#define BH_MAXDIM (16)

struct bh_base
{
    /// Pointer to the actual data.
    bh_data_ptr   data;

    /// The type of data in the array
    bh_type       type;

    /// The number of elements in the array
    bh_index      nelem;

    template<class Archive>
    void save(Archive & ar, const unsigned int version) const
    {
        size_t tmp = (size_t)data;
        ar << tmp;
        ar & type;
        ar & nelem;
    }
    template<class Archive>
    void load(Archive & ar, const unsigned int version)
    {
        size_t tmp;
        ar >> tmp;
        data = (void*)tmp;
        ar & type;
        ar & nelem;
    }
    BOOST_SERIALIZATION_SPLIT_MEMBER()
};

struct bh_view
{
    bh_view(){}
    bh_view(const bh_view& view)
    {
        base = view.base;
        start = view.start;
        ndim = view.ndim;
        assert(ndim < BH_MAXDIM);
        std::memcpy(shape, view.shape, ndim * sizeof(bh_index));
        std::memcpy(stride, view.stride, ndim * sizeof(bh_index));
    }

    /// Pointer to the base array.
    bh_base*      base;

    /// Index of the start element
    bh_index      start;

    /// Number of dimensions
    bh_intp       ndim;

    /// Number of elements in each dimensions
    bh_index      shape[BH_MAXDIM];

    /// The stride for each dimensions
    bh_index      stride[BH_MAXDIM];

    bool operator<(const bh_view& other) const
    {
        if (base < other.base) return true;<commit_msg>core: now the bh_view copy constructor handles views that are constants correctly<commit_after>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __BH_ARRAY_H
#define __BH_ARRAY_H

#include <algorithm>
#include <stdbool.h>
#include <iostream>
#include <cstring>
#include <cassert>
#include "bh_type.h"
#include "bh_win.h"

#include <boost/serialization/split_member.hpp>

// Forward declaration of class boost::serialization::access
namespace boost {namespace serialization {class access;}}

#define BH_MAXDIM (16)

struct bh_base
{
    /// Pointer to the actual data.
    bh_data_ptr   data;

    /// The type of data in the array
    bh_type       type;

    /// The number of elements in the array
    bh_index      nelem;

    template<class Archive>
    void save(Archive & ar, const unsigned int version) const
    {
        size_t tmp = (size_t)data;
        ar << tmp;
        ar & type;
        ar & nelem;
    }
    template<class Archive>
    void load(Archive & ar, const unsigned int version)
    {
        size_t tmp;
        ar >> tmp;
        data = (void*)tmp;
        ar & type;
        ar & nelem;
    }
    BOOST_SERIALIZATION_SPLIT_MEMBER()
};

struct bh_view
{
    bh_view(){}
    bh_view(const bh_view& view)
    {
        base = view.base;
        if(base == NULL)
            return; //'view' is a constant thus the rest are garbage
        start = view.start;
        ndim = view.ndim;
        assert(ndim < BH_MAXDIM);
        std::memcpy(shape, view.shape, ndim * sizeof(bh_index));
        std::memcpy(stride, view.stride, ndim * sizeof(bh_index));
    }

    /// Pointer to the base array.
    bh_base*      base;

    /// Index of the start element
    bh_index      start;

    /// Number of dimensions
    bh_intp       ndim;

    /// Number of elements in each dimensions
    bh_index      shape[BH_MAXDIM];

    /// The stride for each dimensions
    bh_index      stride[BH_MAXDIM];

    bool operator<(const bh_view& other) const
    {
        if (base < other.base) return true;
{'fraction_non_alphanumeric': 0.08832565284178187, 'fraction_numerical': 0.0038402457757296467, 'mean_word_length': 2.6708949964763917, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '872637', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1564, 'n_words': 580}