<commit_before>using qif::rat;
using qif::uint;

// armadillo internal voodoo to make it play well with rat
//
namespace arma {
	// make armadillo support mpq_class as element type
	template<>
	struct is_supported_elem_type<mpq_class> {
		static const bool value = true;
	};

	// pretend that rat is a real type. Thus might cause issues...
	// needed for specializing op_dot::direct_dot below
	template<> struct arma_real_only<rat> {
		typedef rat result;
	};

	// armadillo's memory::acquire/release uses malloc/free for speed, which overrides the constructor
	// and causes segfaults when used with rat. We override it to use C++'s new/delete
	//
	template<>
	inline
	arma_malloc
	rat*
	memory::acquire<rat>(const uword n_elem) {
//		std::cout << "ACQUIRE\n";
		arma_debug_check(
			( size_t(n_elem) > (std::numeric_limits<size_t>::max() / sizeof(rat)) ),
			"arma::memory::acquire(): requested size is too large"
		);
		return ( new(std::nothrow) rat[n_elem] );
	}

	template<>
	arma_inline
	void
	memory::release<rat>(rat* mem) {
//		std::cout << "RELEASE\n";
		delete [] mem;
	}

	template<>
	arma_inline
	void
	memory::release<const rat>(const rat* mem) {
//		std::cout << "CONST RELEASE\n";
		delete [] mem;
	}

	// armadillo uses memcpy to copy memory, can't do that with rat
	//
	template<>
	arma_hot
	arma_inline
	void
	arrayops::copy<rat>(rat* dest, const rat* src, const uword n_elem) {
		for(uint i = 0; i < n_elem; i++)
			dest[i] = src[i];
	}

	// use direct_dot_arma (generic dot product implementation) for direct_dot<rat>
	//
	template<>
	arma_hot
	inline
	typename arma_real_only<rat>::result
	op_dot::direct_dot<rat>(const uword n_elem, const rat* const A, const rat* const B) {
		return op_dot::direct_dot_arma<rat>(n_elem, A, B);
	}

	// for abs
	//
	template<>
	arma_inline
	typename arma_real_only<rat>::result
	eop_aux::arma_abs<rat>(const rat x) {
		return x < rat(0) ? -x : x;
	}

	// in clang the cxx98 rng is used, and randn fails for rats
	// recent armadillo renamed ARMA_USE_CXX11_RNG to ARMA_USE_EXTERN_CXX11_RNG
	#if !defined(ARMA_RNG_ALT) && !defined(ARMA_USE_CXX11_RNG) && !defined(ARMA_USE_EXTERN_CXX11_RNG)
	template<>
	inline
	void
	arma_rng_cxx98::randn_dual_val(rat&, rat&) {
		throw std::runtime_error("randn not implemented for rat");
	}
	#endif
}
<commit_msg>fix rat parsing in arma 8.400<commit_after>using qif::rat;
using qif::uint;

// armadillo internal voodoo to make it play well with rat
//
namespace arma {
	// make armadillo support mpq_class as element type
	template<>
	struct is_supported_elem_type<mpq_class> {
		static const bool value = true;
	};

	// pretend that rat is a real type. Thus might cause issues...
	// needed for specializing op_dot::direct_dot below
	template<> struct arma_real_only<rat> {
		typedef rat result;
	};

	// armadillo's memory::acquire/release uses malloc/free for speed, which overrides the constructor
	// and causes segfaults when used with rat. We override it to use C++'s new/delete
	//
	template<>
	inline
	arma_malloc
	rat*
	memory::acquire<rat>(const uword n_elem) {
//		std::cout << "ACQUIRE\n";
		arma_debug_check(
			( size_t(n_elem) > (std::numeric_limits<size_t>::max() / sizeof(rat)) ),
			"arma::memory::acquire(): requested size is too large"
		);
		return ( new(std::nothrow) rat[n_elem] );
	}

	template<>
	arma_inline
	void
	memory::release<rat>(rat* mem) {
//		std::cout << "RELEASE\n";
		delete [] mem;
	}

	template<>
	arma_inline
	void
	memory::release<const rat>(const rat* mem) {
//		std::cout << "CONST RELEASE\n";
		delete [] mem;
	}

	// armadillo uses memcpy to copy memory, can't do that with rat
	//
	template<>
	arma_hot
	arma_inline
	void
	arrayops::copy<rat>(rat* dest, const rat* src, const uword n_elem) {
		for(uint i = 0; i < n_elem; i++)
			dest[i] = src[i];
	}

	// use direct_dot_arma (generic dot product implementation) for direct_dot<rat>
	//
	template<>
	arma_hot
	inline
	typename arma_real_only<rat>::result
	op_dot::direct_dot<rat>(const uword n_elem, const rat* const A, const rat* const B) {
		return op_dot::direct_dot_arma<rat>(n_elem, A, B);
	}

	// for abs
	//
	template<>
	arma_inline
	typename arma_real_only<rat>::result
	eop_aux::arma_abs<rat>(const rat x) {
		return x < rat(0) ? -x : x;
	}

	// in clang the cxx98 rng is used, and randn fails for rats
	// recent armadillo renamed ARMA_USE_CXX11_RNG to ARMA_USE_EXTERN_CXX11_RNG
	#if !defined(ARMA_RNG_ALT) && !defined(ARMA_USE_CXX11_RNG) && !defined(ARMA_USE_EXTERN_CXX11_RNG)
	template<>
	inline
	void
	arma_rng_cxx98::randn_dual_val(rat&, rat&) {
		throw std::runtime_error("randn not implemented for rat");
	}
	#endif

	// for parsing rats from strings 
	//
	#if ARMA_VERSION_MAJOR > 8 || (ARMA_VERSION_MAJOR == 8 && ARMA_VERSION_MINOR >= 400)
	template<>
	inline
	bool
	diskio::convert_token(rat& val, const std::string& token) {
		std::istringstream iss(token);
		iss >> val;
		return true;
	}
	#endif
}

{'fraction_non_alphanumeric': 0.13121434392828035, 'fraction_numerical': 0.007538712306438468, 'mean_word_length': 4.194708994708995, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 54, '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': '330529', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1834, 'n_words': 486}