<commit_before>#include <iostream>

#include "linbox-config.h"

#include "linbox/integer.h"
#include "givaro/givpoly1.h"

#ifndef LINBOX_ring_givaro_poly_H
#define LINBOX_ring_givaro_poly_H

namespace LinBox
{
	template<class Field>
	class GivaroPolyRandIter;
	
	template<class Domain, class StorageTag = Givaro::Dense>
	class GivaroPoly {
		Domain _pd;
	public:
		typedef Domain Domain_t;
		typedef typename Domain::Element Element;
		typedef typename Domain::Type_t Scalar_t;
		
		typedef GivaroPolyRandIter<GivaroPoly<Domain,StorageTag>> RandIter;
		
		Element zero, one, mOne;
		
		GivaroPoly(){}
		
		GivaroPoly(Domain pd) {
			_pd = pd;
			
			_pd.assign(zero, _pd.zero);
			_pd.assign(one, _pd.one);
			_pd.assign(mOne, _pd.mOne);
		}
		
		GivaroPoly(const GivaroPoly &P)
			: _pd(P._pd), zero(P.zero), one(P.one), mOne(P.mOne) {}
		
		GivaroPoly &operator=(const GivaroPoly &F) {
			return *this;
		}
		
		const Domain_t domain() const {
			return _pd;
		}
		
		const typename Domain_t::Domain_t &subdomain() const {
			return _pd.subdomain();
		}
		
		Element &init(Element &x) const {
			_pd.init(x, Givaro::Degree(0), 0);
			return x;
		}
		
		//template<class XXX>
		Element &init(Element &x, const integer &y) const {
			typedef integer XXX;
			
			_pd.init(x, Givaro::Degree(0), 0);
			
			XXX p = _pd.subdomain().cardinality();
			
			XXX i = 0;
			XXX tmp = y;
			
			while (tmp != 0)
			{
				Element xi;
				_pd.init(xi, Givaro::Degree(i), tmp % p);
				_pd.addin(x, xi);
				
				i++;
				tmp /= p;
			}
			
			return x;
		}
		
		/*
		Element &init(Element &x, const float &y) const {
			integer a = y;
			return init(x, a);
		}
		
		Element &init(Element &x, const double &y) const {
			integer a = y;
			return init(x, a);
		}
		*/
		
		template<class XXX>
		XXX &convert(XXX &x, Element y) {
			x = 0;
			Givaro::Degree d = _pd.degree(y);
			
			while (d >= 0) {
				XXX tmp;
				Scalar_t e;
				
				x *= _pd.characteristic();
				_pd.getEntry(e, d, y);
				x += _pd.subdomain().convert(tmp, e);
				
				d--;
			}
			
			return x;
		}
		
		Element &assign(Element &x, const Element y) const {
			return _pd.assign(x, y);
		}
		
		integer &cardinality(integer &c) const {
			return c = -1;
		}
		
		integer &characteristic(integer &c) const {
			return c = _pd.characteristic(c);
		}
		
		bool areEqual(Element x, Element y) const {
			return _pd.areEqual(x, y);
		}
		
		bool isZero(Element x) const {
			return _pd.isZero(x);<commit_msg>Bug fixes in givaro poly init/convert<commit_after>#include <iostream>

#include "linbox-config.h"

#include "linbox/integer.h"
#include "givaro/givpoly1.h"

#ifndef LINBOX_ring_givaro_poly_H
#define LINBOX_ring_givaro_poly_H

namespace LinBox
{
	template<class Field>
	class GivaroPolyRandIter;
	
	template<class Domain, class StorageTag = Givaro::Dense>
	class GivaroPoly {
		Domain _pd;
	public:
		typedef Domain Domain_t;
		typedef typename Domain::Element Element;
		typedef typename Domain::Type_t Scalar_t;
		
		typedef GivaroPolyRandIter<GivaroPoly<Domain,StorageTag>> RandIter;
		
		Element zero, one, mOne;
		
		GivaroPoly(){}
		
		GivaroPoly(Domain pd) {
			_pd = pd;
			
			_pd.assign(zero, _pd.zero);
			_pd.assign(one, _pd.one);
			_pd.assign(mOne, _pd.mOne);
		}
		
		GivaroPoly(const GivaroPoly &P)
			: _pd(P._pd), zero(P.zero), one(P.one), mOne(P.mOne) {}
		
		GivaroPoly &operator=(const GivaroPoly &F) {
			return *this;
		}
		
		const Domain_t domain() const {
			return _pd;
		}
		
		const typename Domain_t::Domain_t &subdomain() const {
			return _pd.subdomain();
		}
		
		Element &init(Element &x) const {
			_pd.init(x, Givaro::Degree(0), 0);
			return x;
		}
		
		Element &init(Element &x, const integer &y) const {
			_pd.init(x, Givaro::Degree(0), 0);
			
			integer q = _pd.characteristic();
			
			integer i = 0;
			integer tmp = y;
			
			while (tmp != 0)
			{
				Element xi;
				_pd.init(xi, Givaro::Degree(i), tmp % q);
				_pd.addin(x, xi);
				
				i++;
				tmp /= q;
			}
			
			return x;
		}
		
		integer &convert(integer &x, Element y) {
			x = 0;
			integer q = _pd.characteristic();
			Givaro::Degree d = _pd.degree(y);
			
			while (d >= 0) {
				integer tmp;
				Scalar_t e;
				
				x *= q;
				_pd.getEntry(e, d, y);
				x += _pd.subdomain().convert(tmp, e);
				
				d--;
			}
			
			return x;
		}
		
		Element &assign(Element &x, const Element y) const {
			return _pd.assign(x, y);
		}
		
		integer &cardinality(integer &c) const {
			return c = -1;
		}
		
		integer &characteristic(integer &c) const {
			return c = _pd.characteristic(c);
		}
		
		bool areEqual(Element x, Element y) const {
			return _pd.areEqual(x, y);
		}
		
		bool isZero(Element x) const {
			return _pd.isZero(x);
{'fraction_non_alphanumeric': 0.13686675180928054, 'fraction_numerical': 0.004257130693912303, 'mean_word_length': 2.8110300081103, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '6865788', 'n_tokens_mistral': 2305, 'n_tokens_neox': 1795, 'n_words': 428}