<commit_before>#include <mantella_bits/helper/assert.hpp>

// C++ standard library
#include <cstdlib>

namespace mant {
  void verify(
      const bool expression,
      const std::string& errorMessage) {
    if(!expression) {
      throw std::logic_error(errorMessage);
    }   
  }

  bool isRotationMatrix(
      const arma::Mat<double>& rotationMatrixCandidate) {
    // Is the rotation matrix square?
    if (!rotationMatrixCandidate.is_square()) {
      return false;
    }
      
    // Is its determinant either 1 or -1?
    if(std::abs(std::abs(arma::det(rotationMatrixCandidate)) - 1.0) > 1.0e-12) {
      return false;
    }
      
    // Is its transpose also its inverse?
    // For (nearly) singular matrices, the inversion might throw an exception.
    try {
      if(arma::any(arma::vectorise(arma::abs(parameter.i() - parameter.t()) > 1.0e-12 * std::max(1.0, std::abs(arma::median(arma::vectorise(parameter))))))) {
        return false;
      }
    } catch (...) {
      return false;
    }

    return true;
  }

  bool isPermutation(
      const arma::Col<arma::uword>& permutationCandidate,
      const arma::uword numberOfPermutations,
      const arma::uword numberOfElements) {
    // Are there as many permutations as expected?
    if (permutationCandidate.n_elem != numberOfPermutations) {
      return false;
    }
    
    // Are all elements within [0, numberOfElements - 1]?
    if (arma::any(permutationCandidate < 0) || arma::any(permutationCandidate > numberOfElements - 1)) {
      return false;
    }
    
    // Are all elements unique?
    if (static_cast<arma::Col<arma::uword>>(arma::unique(permutationCandidate)).n_elem != permutationCandidate.n_elem) {
      return false;
    }
    
    return true;
  }
  
  bool isDimensionallyConsistent(
      const std::unordered_map<arma::Col<double>, double, Hash, IsEqual>& samples) {
    const arma::uword numberOfDimensions = samples.cbegin()->first.n_elem;
    for (const auto& sample : samples) {
      if (sample.first.n_elem != numberOfDimensions) {
        return false;
      }
    }
    
    return true;
  }
}
<commit_msg>Added (redundant) precheck, to improve some corner cases<commit_after>#include <mantella_bits/helper/assert.hpp>

// C++ standard library
#include <cstdlib>

namespace mant {
  void verify(
      const bool expression,
      const std::string& errorMessage) {
    if(!expression) {
      throw std::logic_error(errorMessage);
    }   
  }

  bool isRotationMatrix(
      const arma::Mat<double>& rotationMatrixCandidate) {
    // Is the rotation matrix square?
    if (!rotationMatrixCandidate.is_square()) {
      return false;
    }
      
    // Is its determinant either 1 or -1?
    if(std::abs(std::abs(arma::det(rotationMatrixCandidate)) - 1.0) > 1.0e-12) {
      return false;
    }
      
    // Is its transpose also its inverse?
    // For (nearly) singular matrices, the inversion might throw an exception.
    try {
      if(arma::any(arma::vectorise(arma::abs(parameter.i() - parameter.t()) > 1.0e-12 * std::max(1.0, std::abs(arma::median(arma::vectorise(parameter))))))) {
        return false;
      }
    } catch (...) {
      return false;
    }

    return true;
  }

  bool isPermutation(
      const arma::Col<arma::uword>& permutationCandidate,
      const arma::uword numberOfPermutations,
      const arma::uword numberOfElements) {
    // Are there as more permutations than elements?
    if (numberOfPermutations > numberOfElements) {
      return false;
    }
    
    // Are there as many permutations as expected?
    if (permutationCandidate.n_elem != numberOfPermutations) {
      return false;
    }
    
    // Are all elements within [0, numberOfElements - 1]?
    if (arma::any(permutationCandidate < 0) || arma::any(permutationCandidate > numberOfElements - 1)) {
      return false;
    }
    
    // Are all elements unique?
    if (static_cast<arma::Col<arma::uword>>(arma::unique(permutationCandidate)).n_elem != permutationCandidate.n_elem) {
      return false;
    }
    
    return true;
  }
  
  bool isDimensionallyConsistent(
      const std::unordered_map<arma::Col<double>, double, Hash, IsEqual>& samples) {
    const arma::uword numberOfDimensions = samples.cbegin()->first.n_elem;
    for (const auto& sample : samples) {
      if (sample.first.n_elem != numberOfDimensions) {
        return false;
      }
    }
    
    return true;
  }
}

{'fraction_non_alphanumeric': 0.12568058076225044, 'fraction_numerical': 0.008166969147005444, 'mean_word_length': 2.864154250657318, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 28, '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': '5772535', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1370, 'n_words': 315}