<commit_before>// Catch
#include <catch.hpp>

// C++ Standard Library
#include <cstdlib>
#include <cmath>

// Mantella
#include <mantella>

TEST_CASE("random: getRandomRotationMatrix", "") {
  SECTION("Generates uniform distributed 2-dimensional rotation.") {
    arma::Col<double>::fixed<10000> angles;
    for (std::size_t n = 0; n < angles.n_elem; ++n) {
      arma::Col<double>::fixed<2> rotatedUnitVector = mant::getRandomRotationMatrix(2) * arma::Col<double>::fixed<2>({-2, 1});
      angles.at(n) = std::atan2(rotatedUnitVector.at(1), rotatedUnitVector.at(0));
    }

    arma::Col<unsigned int> histogram = arma::histc(angles, arma::linspace<arma::Col<double>>(-arma::datum::pi, arma::datum::pi, 10));
    CHECK(0.05 > static_cast<double>(histogram.max() - histogram.min()) / angles.n_elem);
  }

  SECTION("Generates uniform distributed 3-dimensional rotation.") {
    arma::Col<double>::fixed<10000> rollAngles;
    arma::Col<double>::fixed<10000> pitchAngles;
    arma::Col<double>::fixed<10000> yawAngles;
    for (std::size_t n = 0; n < rollAngles.n_elem; ++n) {
      arma::Col<double>::fixed<3> rotatedUnitVector = mant::getRandomRotationMatrix(3) * arma::Col<double>::fixed<3>({-2, 1, 3});
      rollAngles.at(n) = std::atan2(rotatedUnitVector.at(1), rotatedUnitVector.at(0));
      pitchAngles.at(n) = std::atan2(rotatedUnitVector.at(2), rotatedUnitVector.at(1));
      yawAngles.at(n) = std::atan2(rotatedUnitVector.at(0), rotatedUnitVector.at(2));
    }

    arma::Col<unsigned int> histogram;

    histogram = arma::histc(rollAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi, arma::datum::pi, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / rollAngles.n_elem);

    histogram = arma::histc(pitchAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi, arma::datum::pi, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / pitchAngles.n_elem);

    histogram = arma::histc(yawAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi, arma::datum::pi, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / yawAngles.n_elem);
  }
}

TEST_CASE("random: getRandomPermutation(unsigned int, unsigned int)", "") {
  SECTION("Generates uniform distributed partitial permutations.") {
    arma::Mat<unsigned int>::fixed<10, 40000> permutations;
    for (std::size_t n = 0; n < permutations.n_cols; ++n) {
      permutations.col(n) = mant::getRandomPermutation(static_cast<unsigned int>(permutations.n_rows) + 1, static_cast<unsigned int>(permutations.n_rows));
    }

    arma::Col<unsigned int> centers(permutations.n_rows);
    for (std::size_t n = 0; n < permutations.n_rows; ++n) {
      centers.at(n) = n;
    }

    for (std::size_t n = 0; n < permutations.n_rows; ++n) {
      arma::Row<unsigned int> histogram = arma::hist(permutations.row(n), centers);
      CHECK(0.1 > static_cast<double>(histogram.max() - histogram.min()) / permutations.n_cols);
    }
  }<commit_msg>test: Fixed the histogram used in testRandom<commit_after>// Catch
#include <catch.hpp>

// C++ Standard Library
#include <cstdlib>
#include <cmath>

// Mantella
#include <mantella>

TEST_CASE("random: getRandomRotationMatrix", "") {
  SECTION("Generates uniform distributed 2-dimensional rotation.") {
    arma::Col<double>::fixed<10000> angles;
    for (std::size_t n = 0; n < angles.n_elem; ++n) {
      arma::Col<double>::fixed<2> rotatedUnitVector = mant::getRandomRotationMatrix(2) * arma::Col<double>::fixed<2>({-2.0, 1.0});
      angles.at(n) = std::atan2(rotatedUnitVector.at(1), rotatedUnitVector.at(0));
    }

    arma::Col<unsigned int> histogram = arma::hist(angles, arma::linspace<arma::Col<double>>(-arma::datum::pi + arma::datum::pi/10.0, arma::datum::pi - arma::datum::pi/10.0, 10));
    CHECK(0.05 > static_cast<double>(histogram.max() - histogram.min()) / angles.n_elem);
  }

  SECTION("Generates uniform distributed 3-dimensional rotation.") {
    arma::Col<double>::fixed<10000> rollAngles;
    arma::Col<double>::fixed<10000> pitchAngles;
    arma::Col<double>::fixed<10000> yawAngles;
    for (std::size_t n = 0; n < rollAngles.n_elem; ++n) {
      arma::Col<double>::fixed<3> rotatedUnitVector = mant::getRandomRotationMatrix(3) * arma::Col<double>::fixed<3>({-2.0, 1.0, 3.0});
      rollAngles.at(n) = std::atan2(rotatedUnitVector.at(1), rotatedUnitVector.at(0));
      pitchAngles.at(n) = std::atan2(rotatedUnitVector.at(2), rotatedUnitVector.at(1));
      yawAngles.at(n) = std::atan2(rotatedUnitVector.at(0), rotatedUnitVector.at(2));
    }

    arma::Col<unsigned int> histogram;

    histogram = arma::hist(rollAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi + arma::datum::pi/10.0, arma::datum::pi - arma::datum::pi/10.0, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / rollAngles.n_elem);

    histogram = arma::hist(pitchAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi + arma::datum::pi/10.0, arma::datum::pi - arma::datum::pi/10.0, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / pitchAngles.n_elem);

    histogram = arma::hist(yawAngles, arma::linspace<arma::Col<double>>(-arma::datum::pi + arma::datum::pi/10.0, arma::datum::pi - arma::datum::pi/10.0, 10));
    CHECK(0.02 > static_cast<double>(histogram.max() - histogram.min()) / yawAngles.n_elem);
  }
}

TEST_CASE("random: getRandomPermutation(unsigned int, unsigned int)", "") {
  SECTION("Generates uniform distributed partitial permutations.") {
    arma::Mat<unsigned int>::fixed<10, 40000> permutations;
    for (std::size_t n = 0; n < permutations.n_cols; ++n) {
      permutations.col(n) = mant::getRandomPermutation(static_cast<unsigned int>(permutations.n_rows) + 1, static_cast<unsigned int>(permutations.n_rows));
    }

    arma::Col<unsigned int> centers(permutations.n_rows);
    for (std::size_t n = 0; n < permutations.n_rows; ++n) {
      centers.at(n) = n;
    }

    for (std::size_t n = 0; n < permutations.n_rows; ++n) {
      arma::Row<unsigned int> histogram = arma::hist(permutations.row(n), centers);
      CHECK(0.1 > static_cast<double>(histogram.max() - histogram.min()) / permutations.n_cols);
    }
  }
{'fraction_non_alphanumeric': 0.1912594742783422, 'fraction_numerical': 0.030478955007256895, 'mean_word_length': 5.092337917485265, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 95, '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': '6314435', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2221, 'n_words': 348}