<commit_before>//---------------------------------------------------------------------------//
//!
//! \file   GeneralEstimatorDimensionDiscretization.hpp
//! \author <NAME>
//! \brief  General estimator dimension discretization class specialization
//!         declarations
//!
//---------------------------------------------------------------------------//

// FACEMC Includes
#include "GeneralEstimatorDimensionDiscretization.hpp"

namespace FACEMC{

// Constructor
GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::GeneralEstimatorDimensionDiscretization( const Teuchos::Array<typename DT::dimensionType>& dimension_bin_boundaries )
  : EstimatorDimensionDiscretization( COLLISION_NUMBER_DIMENSION ),
    d_dimension_bin_boundaries( dimension_bin_boundaries )
{
  // Make sure there is at least one bin
  testPrecondition( dimension_bin_boundaries.size() >= 1 );
  // Make sure the bins are valid
  testPrecondition( dimension_bin_boundaries.front() >= DT::lowerBound() );
  testPrecondition( dimension_bin_boundaries.back() <= DT::upperBound() );
  // Make sure the bins are sorted
  //testPrecondition( false );
}

// Return the dimension name that has been discretized
inline std::string GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::getDimensionName() const
{
  return DT::name();
}

inline unsigned GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::getNumberOfBins() const
{
  return d_dimension_bin_boundaries.size();
}

inline bool GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::isValueInDiscretization( const Teuchos::any& any_container ) const
{
  typename DT::dimensionType value = DT::clarifyValue( any_container );

  return value <= d_dimension_bin_boundaries.back();
}

// Calculate the index of the bin that the value falls in
unsigned GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::calculateBinIndex( const Teuchos::any& any_container ) const
{
  // Make sure the value is in the dimension discretization
  testPrecondition( isValueInDiscretization( any_container ) );
  
  typename DT::dimensionType value = DT::clarifyValue( any_container );
  
  typename Teuchos::Array<typename DT::dimensionType>::const_iterator 
    start, end, upper_bin_boundary;
  <commit_msg>Added a constructor precondition to the GeneralEstimatorDimensionDiscretization class that check that the bin boundaries are sorted.<commit_after>//---------------------------------------------------------------------------//
//!
//! \file   GeneralEstimatorDimensionDiscretization.hpp
//! \author <NAME>
//! \brief  General estimator dimension discretization class specialization
//!         declarations
//!
//---------------------------------------------------------------------------//

// FACEMC Includes
#include "GeneralEstimatorDimensionDiscretization.hpp"
#include "SortAlgorithms.hpp"

namespace FACEMC{

// Constructor
GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::GeneralEstimatorDimensionDiscretization( const Teuchos::Array<typename DT::dimensionType>& dimension_bin_boundaries )
  : EstimatorDimensionDiscretization( COLLISION_NUMBER_DIMENSION ),
    d_dimension_bin_boundaries( dimension_bin_boundaries )
{
  // Make sure there is at least one bin
  testPrecondition( dimension_bin_boundaries.size() >= 1 );
  // Make sure the bins are valid
  testPrecondition( dimension_bin_boundaries.front() >= DT::lowerBound() );
  testPrecondition( dimension_bin_boundaries.back() <= DT::upperBound() );
  // Make sure the bins are sorted
  testPrecondition( Sort::isSortedAscending( dimension_bin_boundaries.begin(),
					     dimension_bin_boundaries.end() ));
}

// Return the dimension name that has been discretized
inline std::string GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::getDimensionName() const
{
  return DT::name();
}

inline unsigned GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::getNumberOfBins() const
{
  return d_dimension_bin_boundaries.size();
}

inline bool GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::isValueInDiscretization( const Teuchos::any& any_container ) const
{
  typename DT::dimensionType value = DT::clarifyValue( any_container );

  return value <= d_dimension_bin_boundaries.back();
}

// Calculate the index of the bin that the value falls in
unsigned GeneralEstimatorDimensionDiscretization<COLLISION_NUMBER_DIMENSION>::calculateBinIndex( const Teuchos::any& any_container ) const
{
  // Make sure the value is in the dimension discretization
  testPrecondition( isValueInDiscretization( any_container ) );
  
  typename DT::dimensionType value = DT::clarifyValue( any_container );
  
  typename Teuchos::Array<typename DT::dimensionType>::const_iterator 
    start, end, upper_bin_boundary;
  
{'fraction_non_alphanumeric': 0.14788732394366197, 'fraction_numerical': 0.00041425020712510354, 'mean_word_length': 4.237527114967462, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5555818', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1298, 'n_words': 289}