<commit_before>//=======================================================================
// Copyright (c) 2014 <NAME>
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#ifndef ETL_DYN_MATRIX_HPP
#define ETL_DYN_MATRIX_HPP

#include<vector>
#include<tuple>

#include "assert.hpp"
#include "tmp.hpp"
#include "fast_op.hpp"
#include "fast_expr.hpp"
#include "integer_sequence.hpp"

namespace etl {

namespace dyn_detail {

template<std::size_t N, typename... T>
struct nth_type {
    using type = typename std::tuple_element<N, std::tuple<T...>>::type;
};

template<typename... T>
struct last_type {
    using type = typename nth_type<sizeof...(T)-1, T...>::type;
};

template<int I, typename T1, typename... T>
auto nth_value(T1&& t, T&&... /*args*/) -> typename std::enable_if<(I == 0), decltype(std::forward<T1>(t))>::type{
    return std::forward<T1>(t);
}

// Induction step
template<int I, typename T1, typename... T>
auto nth_value(T1&& /*t*/, T&&... args) ->
    typename std::enable_if<(I > 0), decltype(
        std::forward<typename nth_type<I, T1, T...>::type>(
            std::declval<typename nth_type<I, T1, T...>::type>()
            )
        )>::type
{
    using return_type = typename nth_type<I, T1, T...>::type;
    return std::forward<return_type>(nth_value<I - 1>((std::forward<T>(args))...));
}

template<typename... T>
auto last_value(T&&... args){
    return nth_value<sizeof...(T) - 1>(args...);
}

inline std::size_t size(std::size_t first){
    return first;
}

template<typename... T>
inline std::size_t size(std::size_t first, T... args){
    return first * size(args...);
}

template<std::size_t... I, typename... T>
inline std::size_t size(const index_sequence<I...>& /*i*/, const T&... args){
    return size((nth_value<I>(args...))...);
}

template<std::size_t... I, typename... T>
inline std::vector<std::size_t> sizes(const index_sequence<I...>& /*i*/, const T&... args){
    return {static_cast<std::size_t>(nth_value<I>(args...))...};
}

} // end of namespace dyn_detail

enum class init_flag_t { DUMMY };
constexpr const init_flag_t init_flag = init_flag_t::DUMMY;

template<typename T>
struct big_dyn_matrix {
public:
    using                value_type = T;
    using              storage_impl = std::vector<value_type>;
    using    dimension_storage_impl = std::vector<std::size_t>;
    using                  iterator = typename storage_impl::iterator;
    using            const_iterator = typename storage_impl::const_iterator;

private:
    const std::size_t _size;
    storage_impl _data;
    dimension_storage_impl _dimensions;

public:
    ///{{{ Construction

    explicit big_dyn_matrix(const big_dyn_matrix& rhs) : _size(rhs._size), _data(rhs._data), _dimensions(rhs._dimensions) {
        //Nothing to init
    }

    //Normal constructor with only sizes
    template<typename... S, enable_if_u<and_u<(sizeof...(S) > 0), all_convertible_to<std::size_t, S...>::value>::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(sizes...)), 
            _data(_size), 
            _dimensions({static_cast<std::size_t>(sizes)...}) {
        //Nothing to init
    }

    //Sizes followed by an initializer list
    template<typename... S, enable_if_u<
        and_u<
            (sizeof...(S) > 1),
            is_specialization_of<std::initializer_list, typename dyn_detail::last_type<S...>::type>::value
        >::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(make_index_sequence<(sizeof...(S)-1)>(), sizes...)), 
            _data(_size), 
            _dimensions(dyn_detail::sizes(make_index_sequence<(sizeof...(S)-1)>(), sizes...)) {
        //Nothing to init
    }

    //Sizes followed by an init flag followed by the value
    template<typename... S, enable_if_u<
        and_u<
            (sizeof...(S) > 2),
            std::is_same<init_flag_t, typename dyn_detail::nth_type<sizeof...(S) - 2, S...>::type>::value
        >::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(make_index_sequence<(sizeof...(S)-2)>(), sizes...)), 
            _data(_size, dyn_detail::last_value(sizes...)), 
            _dimensions(dyn_detail::sizes(make_index_sequence<(sizeof...(S)-2)>(), sizes...)) {
        //Nothing to init
    }

    //template<typename... S>
    //big_dyn_matrix(S... sizes) : _size(dyn_detail::size(sizes...)), _data(_size), _dimensions({static_cast<std::size_t>(sizes)...}) {
        //static_assert(all_convertible_to<std::size_t, S...>::value, "Invalid sizes");
    //}
<commit_msg>Fix constructor<commit_after>//=======================================================================
// Copyright (c) 2014 <NAME>
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#ifndef ETL_DYN_MATRIX_HPP
#define ETL_DYN_MATRIX_HPP

#include<vector>
#include<tuple>

#include "assert.hpp"
#include "tmp.hpp"
#include "fast_op.hpp"
#include "fast_expr.hpp"
#include "integer_sequence.hpp"

namespace etl {

namespace dyn_detail {

template<std::size_t N, typename... T>
struct nth_type {
    using type = typename std::tuple_element<N, std::tuple<T...>>::type;
};

template<typename... T>
struct last_type {
    using type = typename nth_type<sizeof...(T)-1, T...>::type;
};

template<int I, typename T1, typename... T>
auto nth_value(T1&& t, T&&... /*args*/) -> typename std::enable_if<(I == 0), decltype(std::forward<T1>(t))>::type{
    return std::forward<T1>(t);
}

// Induction step
template<int I, typename T1, typename... T>
auto nth_value(T1&& /*t*/, T&&... args) ->
    typename std::enable_if<(I > 0), decltype(
        std::forward<typename nth_type<I, T1, T...>::type>(
            std::declval<typename nth_type<I, T1, T...>::type>()
            )
        )>::type
{
    using return_type = typename nth_type<I, T1, T...>::type;
    return std::forward<return_type>(nth_value<I - 1>((std::forward<T>(args))...));
}

template<typename... T>
auto last_value(T&&... args){
    return nth_value<sizeof...(T) - 1>(args...);
}

inline std::size_t size(std::size_t first){
    return first;
}

template<typename... T>
inline std::size_t size(std::size_t first, T... args){
    return first * size(args...);
}

template<std::size_t... I, typename... T>
inline std::size_t size(const index_sequence<I...>& /*i*/, const T&... args){
    return size((nth_value<I>(args...))...);
}

template<std::size_t... I, typename... T>
inline std::vector<std::size_t> sizes(const index_sequence<I...>& /*i*/, const T&... args){
    return {static_cast<std::size_t>(nth_value<I>(args...))...};
}

} // end of namespace dyn_detail

enum class init_flag_t { DUMMY };
constexpr const init_flag_t init_flag = init_flag_t::DUMMY;

template<typename T>
struct big_dyn_matrix {
public:
    using                value_type = T;
    using              storage_impl = std::vector<value_type>;
    using    dimension_storage_impl = std::vector<std::size_t>;
    using                  iterator = typename storage_impl::iterator;
    using            const_iterator = typename storage_impl::const_iterator;

private:
    const std::size_t _size;
    storage_impl _data;
    dimension_storage_impl _dimensions;

public:
    ///{{{ Construction

    explicit big_dyn_matrix(const big_dyn_matrix& rhs) : _size(rhs._size), _data(rhs._data), _dimensions(rhs._dimensions) {
        //Nothing to init
    }

    //Normal constructor with only sizes
    template<typename... S, enable_if_u<and_u<(sizeof...(S) > 0), all_convertible_to<std::size_t, S...>::value>::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(sizes...)), 
            _data(_size), 
            _dimensions({static_cast<std::size_t>(sizes)...}) {
        //Nothing to init
    }

    //Sizes followed by an initializer list
    template<typename... S, enable_if_u<
        and_u<
            (sizeof...(S) > 1),
            is_specialization_of<std::initializer_list, typename dyn_detail::last_type<S...>::type>::value
        >::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(make_index_sequence<(sizeof...(S)-1)>(), sizes...)), 
            _data(dyn_detail::last_value(sizes...)), 
            _dimensions(dyn_detail::sizes(make_index_sequence<(sizeof...(S)-1)>(), sizes...)) {
        //Nothing to init
    }

    //Sizes followed by an init flag followed by the value
    template<typename... S, enable_if_u<
        and_u<
            (sizeof...(S) > 2),
            std::is_same<init_flag_t, typename dyn_detail::nth_type<sizeof...(S) - 2, S...>::type>::value
        >::value> = detail::dummy>
    big_dyn_matrix(S... sizes) : 
            _size(dyn_detail::size(make_index_sequence<(sizeof...(S)-2)>(), sizes...)), 
            _data(_size, dyn_detail::last_value(sizes...)), 
            _dimensions(dyn_detail::sizes(make_index_sequence<(sizeof...(S)-2)>(), sizes...)) {
        //Nothing to init
    }

    //template<typename... S>
    //big_dyn_matrix(S... sizes) : _size(dyn_detail::size(sizes...)), _data(_size), _dimensions({static_cast<std::size_t>(sizes)...}) {
        //static_assert(all_convertible_to<std::size_t, S...>::value, "Invalid sizes");
    //}

{'fraction_non_alphanumeric': 0.20853927857818907, 'fraction_numerical': 0.0054685035229782315, 'mean_word_length': 3.1510257529463117, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 131, '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': '6313547', 'n_tokens_mistral': 3244, 'n_tokens_neox': 3137, 'n_words': 627}