<commit_before>/**
 * $Id$
 *
 * Copyright (C)
 * 2014 - $Date$
 *     <NAME> <<EMAIL>>
 *
 * This file is distributed under the BSD 2-Clause Open Source License
 * (See LICENSE file).
 *
 */
#ifndef NDHIST_AXES_CONSTANT_BIN_WIDTH_AXIS_HPP_INCLUDED
#define NDHIST_AXES_CONSTANT_BIN_WIDTH_AXIS_HPP_INCLUDED 1

#include <cmath>
#include <string>
#include <sstream>

#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/shared_ptr.hpp>

#include <boost/numpy/iterators/flat_iterator.hpp>

#include <ndhist/type_support.hpp>
#include <ndhist/axis.hpp>
#include <ndhist/axes/generic_axis.hpp>
#include <ndhist/error.hpp>

namespace bn = boost::numpy;

namespace ndhist {
namespace axes {

template <typename AxisValueType>
class ConstantBinWidthAxis
  : public Axis
{
  public:
    typedef AxisValueType
            axis_value_type;

    typedef bn::iterators::single_value<axis_value_type>
            axis_value_type_traits;

    typedef Axis
            base;

    typedef ConstantBinWidthAxis<axis_value_type>
            type;

  protected:
    /// The number of bins, including the possible under- and overflow bins.
    intptr_t n_bins_;

    /// The constant width of the bins. Remember, that the widths of the
    /// possible under- and overflow bins could be different from this value.
    axis_value_type bin_width_;

    /// The lower edge of the first bin with constant bin width, i.e. excluding
    /// the underflow bin.
    axis_value_type min_;

    /// The lower edge of the underflow bin.
    axis_value_type underflow_edge_;

    /// The upper edge of the overflow bin.
    axis_value_type overflow_edge_;

    /// The axis value type traits object, needed as temporary storage for
    /// dereferencing value pointers.
    axis_value_type_traits mutable avtt_;

  public:
    ConstantBinWidthAxis(
        bn::ndarray const & edges
      , std::string const & label
      , std::string const & name
      , bool has_underflow_bin
      , bool has_overflow_bin
      , bool is_extendable
      , intptr_t extension_max_fcap
      , intptr_t extension_max_bcap
    )
      : Axis(
            edges.get_size()-1
          , edges.get_dtype()
          , label
          , name
          , has_underflow_bin
          , has_overflow_bin
          , is_extendable
          , extension_max_fcap
          , extension_max_bcap
        )
    {
        // Set up the axis's function pointers.
        create_fct_                     = &type::create;
        get_bin_index_fct_              = &type::get_bin_index;
        get_binedges_ndarray_fct_       = &type::get_binedges_ndarray;
        get_lower_binedges_ndarray_fct_ = &base::get_lower_binedges_ndarray<type>;
        get_upper_binedges_ndarray_fct_ = &base::get_upper_binedges_ndarray<type>;
        get_bincenters_ndarray_fct_     = &base::get_bincenters_ndarray<type>;
        get_binwidths_ndarray_fct_      = &base::get_binwidths_ndarray<type>;
        get_n_bins_fct_                 = &type::get_n_bins;
        request_extension_fct_          = &type::request_extension;
        extend_fct_                     = &type::extend;
        create_axis_slice_fct_          = &base::create_axis_slice<type>;
        deepcopy_fct_                   = &type::deepcopy;

        std::cout << "edges.shape(0): "<< edges.shape(0)<<std::endl;
        n_bins_ = edges.shape(0) - 1;
        std::cout << "n_bins_: "<< n_bins_<<std::endl;
        if(n_bins_ <= 0)
        {
            std::stringstream ss;
            ss << "The edges array does not contain enough edges! Remember "
               << "that the edges of the out-or-range bins, need to be "
               << "specified as well, when the axis is not extendable.";
            throw ValueError(ss.str());
        }

        bn::iterators::flat_iterator< axis_value_type_traits > edges_iter(edges);

        // Set and skip the underflow edge.
        if(has_underflow_bin_)<commit_msg>comment typo fix<commit_after>/**
 * $Id$
 *
 * Copyright (C)
 * 2014 - $Date$
 *     <NAME> <<EMAIL>>
 *
 * This file is distributed under the BSD 2-Clause Open Source License
 * (See LICENSE file).
 *
 */
#ifndef NDHIST_AXES_CONSTANT_BIN_WIDTH_AXIS_HPP_INCLUDED
#define NDHIST_AXES_CONSTANT_BIN_WIDTH_AXIS_HPP_INCLUDED 1

#include <cmath>
#include <string>
#include <sstream>

#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/shared_ptr.hpp>

#include <boost/numpy/iterators/flat_iterator.hpp>

#include <ndhist/type_support.hpp>
#include <ndhist/axis.hpp>
#include <ndhist/axes/generic_axis.hpp>
#include <ndhist/error.hpp>

namespace bn = boost::numpy;

namespace ndhist {
namespace axes {

template <typename AxisValueType>
class ConstantBinWidthAxis
  : public Axis
{
  public:
    typedef AxisValueType
            axis_value_type;

    typedef bn::iterators::single_value<axis_value_type>
            axis_value_type_traits;

    typedef Axis
            base;

    typedef ConstantBinWidthAxis<axis_value_type>
            type;

  protected:
    /// The number of bins, including the possible under- and overflow bins.
    intptr_t n_bins_;

    /// The constant width of the bins. Remember, that the widths of the
    /// possible under- and overflow bins could be different from this value.
    axis_value_type bin_width_;

    /// The lower edge of the first bin with constant bin width, i.e. excluding
    /// the underflow bin.
    axis_value_type min_;

    /// The lower edge of the underflow bin.
    axis_value_type underflow_edge_;

    /// The upper edge of the overflow bin.
    axis_value_type overflow_edge_;

    /// The axis value type traits object, needed as temporary storage for
    /// dereferencing value pointers.
    axis_value_type_traits mutable avtt_;

  public:
    ConstantBinWidthAxis(
        bn::ndarray const & edges
      , std::string const & label
      , std::string const & name
      , bool has_underflow_bin
      , bool has_overflow_bin
      , bool is_extendable
      , intptr_t extension_max_fcap
      , intptr_t extension_max_bcap
    )
      : Axis(
            edges.get_size()-1
          , edges.get_dtype()
          , label
          , name
          , has_underflow_bin
          , has_overflow_bin
          , is_extendable
          , extension_max_fcap
          , extension_max_bcap
        )
    {
        // Set up the axis's function pointers.
        create_fct_                     = &type::create;
        get_bin_index_fct_              = &type::get_bin_index;
        get_binedges_ndarray_fct_       = &type::get_binedges_ndarray;
        get_lower_binedges_ndarray_fct_ = &base::get_lower_binedges_ndarray<type>;
        get_upper_binedges_ndarray_fct_ = &base::get_upper_binedges_ndarray<type>;
        get_bincenters_ndarray_fct_     = &base::get_bincenters_ndarray<type>;
        get_binwidths_ndarray_fct_      = &base::get_binwidths_ndarray<type>;
        get_n_bins_fct_                 = &type::get_n_bins;
        request_extension_fct_          = &type::request_extension;
        extend_fct_                     = &type::extend;
        create_axis_slice_fct_          = &base::create_axis_slice<type>;
        deepcopy_fct_                   = &type::deepcopy;

        std::cout << "edges.shape(0): "<< edges.shape(0)<<std::endl;
        n_bins_ = edges.shape(0) - 1;
        std::cout << "n_bins_: "<< n_bins_<<std::endl;
        if(n_bins_ <= 0)
        {
            std::stringstream ss;
            ss << "The edges array does not contain enough edges! Remember "
               << "that the edges of the out-of-range bins, need to be "
               << "specified as well, when the axis is not extendable.";
            throw ValueError(ss.str());
        }

        bn::iterators::flat_iterator< axis_value_type_traits > edges_iter(edges);

        // Set and skip the underflow edge.
        if(has_underflow_bin_)
{'fraction_non_alphanumeric': 0.09099018733273863, 'fraction_numerical': 0.0030584936918567605, 'mean_word_length': 2.464900662251656, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 47, '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': '3513125', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2451, 'n_words': 563}