<commit_before>#pragma once

// C++ Standard Library
#include <stdexcept>

// Armadillo
#include <armadillo>

namespace mant {
  template <typename ParameterType>
  class DistanceFunction {
    public:
      explicit DistanceFunction() = default;

      ParameterType getDistance(
          const arma::Col<ParameterType>& parameter) const noexcept;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter) const;

      arma::Col<ParameterType> getNeighbour(
          const arma::Col<ParameterType>& parameter,
          const ParameterType& minimalDistance,
          const ParameterType& maximalDistance) const;

    protected:
      virtual ParameterType getDistanceImplementation(
          const arma::Col<ParameterType>& parameter) const noexcept = 0;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter,
          std::true_type) const noexcept;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter,
          std::false_type) const noexcept;

      virtual arma::Col<ParameterType> getNeighbourImplementation(
          const arma::Col<ParameterType>& parameter,
          const ParameterType& minimalDistance,
          const ParameterType& maximalDistance) const = 0;
  };

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& parameter) const noexcept {
    return getDistanceImplementation(parameter);
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter) const {
    if(firstParameter.n_elem != secondParameter.n_elem) {
      throw std::logic_error("The number of dimensions of the first parameter (" + std::to_string(firstParameter.n_elem) + ") must match the number of dimensions of the second parameter (" + std::to_string(secondParameter.n_elem) + ").");
    }

    return getDistance(firstParameter, secondParameter, std::is_floating_point<ParameterType>());
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter,
      std::true_type) const noexcept {
    return getDistanceImplementation(secondParameter - firstParameter);
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter,
      std::false_type) const noexcept {
    return getDistanceImplementation(arma::max(firstParameter, secondParameter) - arma::min(firstParameter, secondParameter));
  }

  template <typename ParameterType>
  arma::Col<ParameterType> DistanceFunction<ParameterType>::getNeighbour(
      const arma::Col<ParameterType>& parameter,
      const ParameterType& minimalDistance,
      const ParameterType& maximalDistance) const {
    if(minimalDistance.n_elem != maximalDistance.n_elem) {
      throw std::logic_error("The number of dimensions of the minimal distance (" + std::to_string(minimalDistance.n_elem) + ") must match the number of dimensions of the maximal distance (" + std::to_string(maximalDistance.n_elem) + ").");
    } else if(parameter.n_elem != minimalDistance.n_elem) {
      throw std::logic_error("The number of dimensions of the parameter (" + std::to_string(parameter.n_elem) + ") must match the number of dimensions of the minimal/maximal distance (" + std::to_string(minimalDistance.n_elem) + ").");
    } else if(minimalDistance < 0) {
      throw std::logic_error("The minimal distance (" + std::to_string(minimalDistance) + ") must be non-negative.");
    } else if (arma::any(maximalDistance < minimalDistance)) {
      throw std::logic_error("The maximal distance (" + std::to_string(maximalDistance) + ") must be greater than or equal to the minimal distance (" + std::to_string(minimalDistance) + ").");
    }

    return getNeighbourImplementation(minimalDistance, maximalDistance);<commit_msg>devel: Removed remaining occurrences of vector distances<commit_after>#pragma once

// C++ Standard Library
#include <stdexcept>

// Armadillo
#include <armadillo>

namespace mant {
  template <typename ParameterType>
  class DistanceFunction {
    public:
      explicit DistanceFunction() = default;

      ParameterType getDistance(
          const arma::Col<ParameterType>& parameter) const noexcept;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter) const;

      arma::Col<ParameterType> getNeighbour(
          const arma::Col<ParameterType>& parameter,
          const ParameterType& minimalDistance,
          const ParameterType& maximalDistance) const;

    protected:
      virtual ParameterType getDistanceImplementation(
          const arma::Col<ParameterType>& parameter) const noexcept = 0;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter,
          std::true_type) const noexcept;

      ParameterType getDistance(
          const arma::Col<ParameterType>& firstParameter,
          const arma::Col<ParameterType>& secondParameter,
          std::false_type) const noexcept;

      virtual arma::Col<ParameterType> getNeighbourImplementation(
          const arma::Col<ParameterType>& parameter,
          const ParameterType& minimalDistance,
          const ParameterType& maximalDistance) const = 0;
  };

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& parameter) const noexcept {
    return getDistanceImplementation(parameter);
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter) const {
    if(firstParameter.n_elem != secondParameter.n_elem) {
      throw std::logic_error("The number of dimensions of the first parameter (" + std::to_string(firstParameter.n_elem) + ") must match the number of dimensions of the second parameter (" + std::to_string(secondParameter.n_elem) + ").");
    }

    return getDistance(firstParameter, secondParameter, std::is_floating_point<ParameterType>());
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter,
      std::true_type) const noexcept {
    return getDistanceImplementation(secondParameter - firstParameter);
  }

  template <typename ParameterType>
  ParameterType DistanceFunction<ParameterType>::getDistance(
      const arma::Col<ParameterType>& firstParameter,
      const arma::Col<ParameterType>& secondParameter,
      std::false_type) const noexcept {
    return getDistanceImplementation(arma::max(firstParameter, secondParameter) - arma::min(firstParameter, secondParameter));
  }

  template <typename ParameterType>
  arma::Col<ParameterType> DistanceFunction<ParameterType>::getNeighbour(
      const arma::Col<ParameterType>& parameter,
      const ParameterType& minimalDistance,
      const ParameterType& maximalDistance) const {
     if(minimalDistance < 0) {
      throw std::logic_error("The minimal distance (" + std::to_string(minimalDistance) + ") must be non-negative.");
    } else if (maximalDistance < minimalDistance) {
      throw std::logic_error("The maximal distance (" + std::to_string(maximalDistance) + ") must be greater than or equal to the minimal distance (" + std::to_string(minimalDistance) + ").");
    }

    return getNeighbourImplementation(minimalDistance, maximalDistance);
{'fraction_non_alphanumeric': 0.0988984088127295, 'fraction_numerical': 0.0007343941248470012, 'mean_word_length': 4.506064690026954, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 73, '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': '2638737', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2049, 'n_words': 512}