<commit_before>//#####################################################################
// Class RawArray
//#####################################################################
//
// Version of an array that doesn't own its data, for use in threaded or performance critical code.
// RAW_ARRAYs are returned by default by Slice and other functions (i.e., unless Slice_Own is called).
//
//#####################################################################
#pragma once

#include <other/core/array/forward.h>
#include <other/core/array/ArrayBase.h>
#include <other/core/vector/Vector.h>
#include <other/core/python/from_python.h>
#include <other/core/utility/HasCheapCopy.h>
#include <other/core/utility/CopyConst.h>
#include <other/core/utility/range.h>
#include <boost/type_traits/remove_const.hpp>
#include <iomanip>
namespace other {

template<class T> struct IsArray<RawArray<T> >:public mpl::true_{};
template<class T> struct HasCheapCopy<RawArray<T> >:public mpl::true_{};

template<class T,int d> struct FromPython<RawArray<T,d> >:public FromPython<Array<T,d> >{};

template<class T_>
class RawArray<T_,1> : public ArrayBase<T_,RawArray<T_,1> > {
  typedef T_ T;
public:
  enum Workaroun1 {d=1};
  enum Workaround1 {dimension=d};
  typedef typename boost::remove_const<T>::type Element;
  static const bool is_const=boost::is_const<T>::value;
  typedef T& result_type;

private:
  friend class RawArray<Element>;
  friend class RawArray<const Element>;
  struct Unusable{};

  T* const data_;
public:
  const int m;

  RawArray()
    : data_(0), m(0) {}

  RawArray(const Array<Element>& source)
    : data_(source.data()), m(source.size()) {}

  RawArray(const Array<const Element>& source)
    : data_(source.data()), m(source.size()) {}

  RawArray(const NdArray<T>& array)
    : data_(array.data()), m(array.flat.size()) {
    OTHER_ASSERT(array.rank()==1);
  }

  RawArray(const RawArray<Element>& source)
    : data_(source.data_), m(source.m) {}

  RawArray(const RawArray<const Element>& source)
    : data_(source.data_), m(source.m) {}

  RawArray(typename CopyConst<std::vector<Element,std::allocator<Element> >,T>::type& source)
    : data_(source.size()?&source[0]:0), m((int)source.size()) {}

  RawArray(const int m, T* data)
    : data_(data), m(m) {}

  const RawArray& operator=(const RawArray& source) const {
    assert(size()==source.size());
    memcpy(data_,source.data_,sizeof(T)*m);
    return *this;
  }

  template<class TArray> const RawArray& operator=(const TArray& source) const {
    assert(size()==(int)source.size());
    for (int i=0;i<m;i++) data_[i] = source[i];
    return *this;
  }

  int size() const {
    return m;
  }

  Vector<int,1> sizes() const {
    return Vector<int,1>(m);<commit_msg>given 1D RawArray a .flat reference to self for consistency<commit_after>//#####################################################################
// Class RawArray
//#####################################################################
//
// Version of an array that doesn't own its data, for use in threaded or performance critical code.
// RAW_ARRAYs are returned by default by Slice and other functions (i.e., unless Slice_Own is called).
//
//#####################################################################
#pragma once

#include <other/core/array/forward.h>
#include <other/core/array/ArrayBase.h>
#include <other/core/vector/Vector.h>
#include <other/core/python/from_python.h>
#include <other/core/utility/HasCheapCopy.h>
#include <other/core/utility/CopyConst.h>
#include <other/core/utility/range.h>
#include <boost/type_traits/remove_const.hpp>
#include <iomanip>
namespace other {

template<class T> struct IsArray<RawArray<T> >:public mpl::true_{};
template<class T> struct HasCheapCopy<RawArray<T> >:public mpl::true_{};

template<class T,int d> struct FromPython<RawArray<T,d> >:public FromPython<Array<T,d> >{};

template<class T_>
class RawArray<T_,1> : public ArrayBase<T_,RawArray<T_,1> > {
  typedef T_ T;
public:
  enum Workaroun1 {d=1};
  enum Workaround1 {dimension=d};
  typedef typename boost::remove_const<T>::type Element;
  static const bool is_const=boost::is_const<T>::value;
  typedef T& result_type;

private:
  friend class RawArray<Element>;
  friend class RawArray<const Element>;
  struct Unusable{};

  T* const data_;
public:
  const int m;
  RawArray<T, 1> &flat;

  RawArray()
    : data_(0), m(0), flat(*this) {}

  RawArray(const Array<Element>& source)
    : data_(source.data()), m(source.size()), flat(*this) {}

  RawArray(const Array<const Element>& source)
    : data_(source.data()), m(source.size()), flat(*this) {}

  RawArray(const NdArray<T>& array)
    : data_(array.data()), m(array.flat.size()), flat(*this) {
    OTHER_ASSERT(array.rank()==1);
  }

  RawArray(const RawArray<Element>& source)
    : data_(source.data_), m(source.m), flat(*this) {}

  RawArray(const RawArray<const Element>& source)
    : data_(source.data_), m(source.m), flat(*this) {}

  RawArray(typename CopyConst<std::vector<Element,std::allocator<Element> >,T>::type& source)
    : data_(source.size()?&source[0]:0), m((int)source.size()), flat(*this) {}

  RawArray(const int m, T* data)
    : data_(data), m(m), flat(*this) {}

  const RawArray& operator=(const RawArray& source) const {
    assert(size()==source.size());
    memcpy(data_,source.data_,sizeof(T)*m);
    return *this;
  }

  template<class TArray> const RawArray& operator=(const TArray& source) const {
    assert(size()==(int)source.size());
    for (int i=0;i<m;i++) data_[i] = source[i];
    return *this;
  }

  int size() const {
    return m;
  }

  Vector<int,1> sizes() const {
    return Vector<int,1>(m);
{'fraction_non_alphanumeric': 0.22854115153655952, 'fraction_numerical': 0.004945249028611798, 'mean_word_length': 5.209429824561403, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 82, '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': '2798267', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1826, 'n_words': 419}