<commit_before>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/algorithms/lifting-container-base.h
 * Copyright (C) 2004 <NAME>, <NAME>
 *
 * Written by <NAME> <<EMAIL>>
 * Modified by <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __LINBOXX__RECONSTRUCTION_H__
#define __LINBOXX__RECONSTRUCTION_H__

#include <linbox/util/debug.h>

//#define DEBUG_RR
//#define DEBUG_RR_BOUNDACCURACY
#define DEF_THRESH 50

namespace LinBox {

	

	/// @memo Limited doc so far.  Used, for instance, after LiftingContainer.
template< class _LiftingContainer >
class RationalReconstruction {
		
public:
	typedef _LiftingContainer                  LiftingContainer;
	typedef typename LiftingContainer::Ring                Ring;
	typedef typename Ring::Element                      Integer;
	typedef typename LiftingContainer::IVector           Vector;		
	typedef typename LiftingContainer::Field              Field;		
	typedef typename Field::Element                     Element;
	  
#ifdef RSTIMING
	mutable Timer tRecon, ttRecon;	
	mutable int _num_rec;
#endif	
		
	// data
protected:
		
	// pointer to digit generator
	const LiftingContainer& _lcontainer;
		
	// Ring
	Ring _r;
		
	// store early termination threshold.
	int _threshold;
	
public:
			
	/** @memo Constructor 
	 *  maybe use different ring than the ring in lcontainer
	 */
	RationalReconstruction (const LiftingContainer& lcontainer, const Ring& r = Ring(), int THRESHOLD =DEF_THRESH) : 
		_lcontainer(lcontainer), _r(r), _threshold(THRESHOLD) {
			
		//if ( THRESHOLD < DEF_THRESH) _threshold = DEF_THRESH;
	}

	/** @memo Get the LiftingContainer
	 */
	const LiftingContainer& getContainer() const {
		return _lcontainer;
	}
		

	/** @memo  Handler to switch between different rational reconstruction strategy.
	 *  Allow  early termination and direct fast method
	 *  Switch is made by using a threshold as the third argument 
	 *  (default is set to that of constructor THRESHOLD
	 * 0    -> direct method
	 * > 0  -> early termination with 
	 */ 
	template <class Vector>
	bool getRational(Vector& num, Integer& den, int switcher) const { 
		if ( switcher > 0)
			return getRational1(num,den);
		else
			return getRational1(num,den);
	}

	template <class Vector>
	bool getRational(Vector& num, Integer& den) const { 
		if ( _threshold > 0)
			return getRational2(num,den);
		else
			return getRational3(num,den);
	}
	
	template <class InVect1, class InVect2>
	Integer dot (Integer d, const InVect1& v1, const InVect2& v2) const {
		typename InVect1::const_iterator v1_p;
		typename InVect2::const_iterator v2_p;
		_r. init (d, 0);
		for (v1_p = v1. begin(), v2_p = v2. begin(); v1_p != v1. end(); ++ v1_p, ++ v2_p)
			_r. axpyin (d, *v1_p, *v2_p);

		return d;
	}
	/** @memo Reconstruct a vector of rational numbers
	 *  from p-adic digit vector sequence.
	 *  An early termination technique is used.
	 *  Answer is a pair (numerator, common denominator)<commit_msg>2004-04-01 <NAME> 	* linbox/algorithms/rational-reconstruction.h : dont use early termination with threshold=0<commit_after>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/algorithms/lifting-container-base.h
 * Copyright (C) 2004 <NAME>, <NAME>
 *
 * Written by <NAME> <<EMAIL>>
 * Modified by <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __LINBOXX__RECONSTRUCTION_H__
#define __LINBOXX__RECONSTRUCTION_H__

#include <linbox/util/debug.h>

//#define DEBUG_RR
//#define DEBUG_RR_BOUNDACCURACY
#define DEF_THRESH 50

namespace LinBox {

	

	/// @memo Limited doc so far.  Used, for instance, after LiftingContainer.
template< class _LiftingContainer >
class RationalReconstruction {
		
public:
	typedef _LiftingContainer                  LiftingContainer;
	typedef typename LiftingContainer::Ring                Ring;
	typedef typename Ring::Element                      Integer;
	typedef typename LiftingContainer::IVector           Vector;		
	typedef typename LiftingContainer::Field              Field;		
	typedef typename Field::Element                     Element;
	  
#ifdef RSTIMING
	mutable Timer tRecon, ttRecon;	
	mutable int _num_rec;
#endif	
		
	// data
protected:
		
	// pointer to digit generator
	const LiftingContainer& _lcontainer;
		
	// Ring
	Ring _r;
		
	// store early termination threshold.
	int _threshold;
	
public:
			
	/** @memo Constructor 
	 *  maybe use different ring than the ring in lcontainer
	 */
	RationalReconstruction (const LiftingContainer& lcontainer, const Ring& r = Ring(), int THRESHOLD =DEF_THRESH) : 
		_lcontainer(lcontainer), _r(r), _threshold(THRESHOLD) {
			
		//if ( THRESHOLD < DEF_THRESH) _threshold = DEF_THRESH;
	}

	/** @memo Get the LiftingContainer
	 */
	const LiftingContainer& getContainer() const {
		return _lcontainer;
	}
		

	/** @memo  Handler to switch between different rational reconstruction strategy.
	 *  Allow  early termination and direct fast method
	 *  Switch is made by using a threshold as the third argument 
	 *  (default is set to that of constructor THRESHOLD
	 * 0    -> direct method
	 * > 0  -> early termination with 
	 */ 
	template <class Vector>
	bool getRational(Vector& num, Integer& den, int switcher) const { 
		if ( switcher > 0)
			return getRational1(num,den);
		else
			return getRational3(num,den);
	}

	template <class Vector>
	bool getRational(Vector& num, Integer& den) const { 
		if ( _threshold > 0)
			return getRational2(num,den);
		else
			return getRational3(num,den);
	}
	
	template <class InVect1, class InVect2>
	Integer dot (Integer d, const InVect1& v1, const InVect2& v2) const {
		typename InVect1::const_iterator v1_p;
		typename InVect2::const_iterator v2_p;
		_r. init (d, 0);
		for (v1_p = v1. begin(), v2_p = v2. begin(); v1_p != v1. end(); ++ v1_p, ++ v2_p)
			_r. axpyin (d, *v1_p, *v2_p);

		return d;
	}
	/** @memo Reconstruct a vector of rational numbers
	 *  from p-adic digit vector sequence.
	 *  An early termination technique is used.
	 *  Answer is a pair (numerator, common denominator)
{'fraction_non_alphanumeric': 0.09071419000401983, 'fraction_numerical': 0.015141364062709366, 'mean_word_length': 3.406139315230224, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 40, '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': '409293', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2264, 'n_words': 827}