<commit_before>
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/givaro-rational.h
 * Copyright (C) 2004 <NAME>
 *
 * Created  <NAME> < <EMAIL>> 
 * ven oct  8 13:30:05 CEST 2004
 */


#ifndef __GIVARO_RATIONAL_H
#define __GIVARO_RATIONAL_H


#include "linbox/integer.h"
#include "linbox/field/unparametric.h"
#include <linbox/field/field-traits.h>


//------------------------------------
// Files of Givaro library

#include "givaro/givrational.h"
//------------------------------------


namespace LinBox 
{ 

	template <class Ring>
    struct ClassifyRing;

	class GivaroRational; 
	
	template<> 
	struct ClassifyRing<GivaroRational> {
		typedef RingCategories::RationalTag categoryTag;
	}; 

 class GivaroRational : public UnparametricField<Rational>
  {
 
  public:

    /** Element type.
     *  
     */
    typedef  Rational Element;
    

    Element& init(Element& x , const integer& y) const
	  { return x=Rational(y);}

    template<class XX>
    Element& init(Element& x , const XX& y) const
	  { return x=Rational(y);}

    Element& assign(Element& x , const Rational& y) const
          { return x=y;}

    // x = numerator of y
    integer& get_num (integer& x, const Element& y)  const
	  { return x = y.nume(); }

    // x = denominator of y
    integer& get_den (integer& x, const Element& y) const 
          { return x = y.deno(); }


  }; // class 
 


} // namespace LinBox


// Specialization of homomorphism for basefield
#include "linbox/field/hom.h"
namespace LinBox 
{
	template <class _Target>
	class Hom<GivaroRational, _Target> {

	public:
		typedef GivaroRational Source;
		typedef _Target Target;
		typedef typename Source::Element SrcElt;
		typedef typename Target::Element Elt;
	
            Hom(const Source& S, const Target& T) : _source (S), _target(T){ }
            Elt& image(Elt& t, const SrcElt& s) {
                _source. get_num (num, s);
                _source. get_den (den, s);
                if (den == 1) {
                    return _target.init(t,num);
                } else if (num == 1) {
                    _target.init(t,den);
                    return _target.invin(t);
                } else {
                    _target. init (tmp, den);
                    _target. init (t, num);
                    return _target. divin (t, tmp);
                }
// 			_target. init (t, den);
// 			return _target. invin (t);
            }
            SrcElt& preimage(SrcElt& s, const Elt& t) {
                _target. convert (num, t);
                _source. init (s, num);
                return s;
            }
            const Source& source() { return _source;}
            const Target& target() { return _target;}
            
	protected:
		integer num, den;
		Elt tmp;
		Source _source;
		Target _target;
	}; // end Hom 

	template <>
	class Hom<GivaroRational,GivaroRational> {

	public:
		typedef GivaroRational Source;
		typedef Source Target;
		typedef Source::Element SrcElt;
		typedef Target::Element Elt;
	
		Hom(const Source& S, const Target& T) : _source (S), _target(T){}
		Elt& image(Elt& t, const SrcElt& s) {
			_target.assign(t, s);
			return t;
		}
		SrcElt& preimage(SrcElt& s, const Elt& t) {
			_source.assign(s, t);
			return s;
		}
		const Source& source() { return _source;}
		const Target& target() { return _target;}

	protected:
		Source _source;
		Target _target;
	}; // end Hom 
}

#endif // __GIVARO_RATIONAL_H
<commit_msg>added init and convert<commit_after>
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/givaro-rational.h
 * Copyright (C) 2004 <NAME>
 *
 * Created  <NAME> < <EMAIL>> 
 * ven oct  8 13:30:05 CEST 2004
 */


#ifndef __GIVARO_RATIONAL_H
#define __GIVARO_RATIONAL_H


#include "linbox/integer.h"
#include "linbox/field/unparametric.h"
#include <linbox/field/field-traits.h>


//------------------------------------
// Files of Givaro library

#include "givaro/givrational.h"
//------------------------------------


namespace LinBox 
{ 

	template <class Ring>
    struct ClassifyRing;

	class GivaroRational; 
	
	template<> 
	struct ClassifyRing<GivaroRational> {
		typedef RingCategories::RationalTag categoryTag;
	}; 

 class GivaroRational : public UnparametricField<Rational>
  {
 
  public:

    /** Element type.
     *  
     */
    typedef  Rational Element;
    

    Element& init(Element& x , const integer& y) const
	  { return x=Rational(y);}

    Element& init(Element& x , const integer& n,const integer& d) const
	  { return x=Rational(n,d);}

    template<class XX>
    Element& init(Element& x , const XX& y) const
	  { return x=Rational(y);}

    integer& convert(integer& i, const Element& r) const 
          { return i=r.nume(); }
      

    Element& assign(Element& x , const Rational& y) const
          { return x=y;}

    // x = numerator of y
    integer& get_num (integer& x, const Element& y)  const
	  { return x = y.nume(); }

    // x = denominator of y
    integer& get_den (integer& x, const Element& y) const 
          { return x = y.deno(); }


  }; // class 
 


} // namespace LinBox


// Specialization of homomorphism for basefield
#include "linbox/field/hom.h"
namespace LinBox 
{
	template <class _Target>
	class Hom<GivaroRational, _Target> {

	public:
		typedef GivaroRational Source;
		typedef _Target Target;
		typedef typename Source::Element SrcElt;
		typedef typename Target::Element Elt;
	
            Hom(const Source& S, const Target& T) : _source (S), _target(T){ }
            Elt& image(Elt& t, const SrcElt& s) {
                _source. get_num (num, s);
                _source. get_den (den, s);
                if (den == 1) {
                    return _target.init(t,num);
                } else if (num == 1) {
                    _target.init(t,den);
                    return _target.invin(t);
                } else {
                    _target. init (tmp, den);
                    _target. init (t, num);
                    return _target. divin (t, tmp);
                }
// 			_target. init (t, den);
// 			return _target. invin (t);
            }
            SrcElt& preimage(SrcElt& s, const Elt& t) {
                _target. convert (num, t);
                _source. init (s, num);
                return s;
            }
            const Source& source() { return _source;}
            const Target& target() { return _target;}
            
	protected:
		integer num, den;
		Elt tmp;
		Source _source;
		Target _target;
	}; // end Hom 

	template <>
	class Hom<GivaroRational,GivaroRational> {

	public:
		typedef GivaroRational Source;
		typedef Source Target;
		typedef Source::Element SrcElt;
		typedef Target::Element Elt;
	
		Hom(const Source& S, const Target& T) : _source (S), _target(T){}
		Elt& image(Elt& t, const SrcElt& s) {
			_target.assign(t, s);
			return t;
		}
		SrcElt& preimage(SrcElt& s, const Elt& t) {
			_source.assign(s, t);
			return s;
		}
		const Source& source() { return _source;}
		const Target& target() { return _target;}

	protected:
		Source _source;
		Target _target;
	}; // end Hom 
}

#endif // __GIVARO_RATIONAL_H

{'fraction_non_alphanumeric': 0.14047852245697495, 'fraction_numerical': 0.005316916188610606, 'mean_word_length': 2.065180102915952, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '4424555', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2320, 'n_words': 653}