<commit_before>/* linbox/algorithms/block-wiedemann.h
 * Copyright (C) 2004 <NAME>
 *
 * Written by <NAME> <EMAIL>
 * modified by <NAME> (<EMAIL>) 2011
 * ========LICENCE========
 * This file is part of the library LinBox.
 *
 * LinBox 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ========LICENCE========
 */


#ifndef __LINBOX_block_wiedemann_H
#define __LINBOX_block_wiedemann_H

#include <vector>
#include <iostream>


#include "linbox/integer.h"
#include "linbox/matrix/dense-matrix.h"
#include "linbox/matrix/matrix-domain.h"
#include "linbox/algorithms/blackbox-block-container.h"
#include "linbox/algorithms/block-massey-domain.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/blackbox/transpose.h"
#include "linbox/util/commentator.h"

#include "linbox/util/error.h"
//#include "linbox/util/debug.h"

namespace LinBox
{

	template <class Context_>
	class BlockWiedemannSolver{

	public:
		typedef typename Context_::Field                 Field;
		typedef typename Field::Element       Element;
		typedef typename Field::RandIter     RandIter;
		typedef BlasVector<Field>           Vector;
		typedef BlasMatrix<Field>               Block;

	protected:
		Context_                    _BMD;
		VectorDomain<Field>         _VDF;
                RandIter                   _rand;
                size_t                 _left_blockdim;
                size_t                 _right_blockdim; 


#define BW_BLOCK_DEFAULT 8UL
#define BW_MAX_TRY 100               
	public:
		const Field & field() const { return _BMD.field(); }

		BlockWiedemannSolver (const Context_ &C, size_t lblock=BW_BLOCK_DEFAULT, size_t rblock=BW_BLOCK_DEFAULT+1) :
			_BMD(C.field()), _VDF(C.field()), _rand(const_cast<Field&>(C.field())), _left_blockdim(lblock), _right_blockdim(rblock)
		{
                        if (_left_blockdim ==0) _left_blockdim=BW_BLOCK_DEFAULT;
                        if (_right_blockdim ==0) _right_blockdim=BW_BLOCK_DEFAULT;
                }

		BlockWiedemannSolver (const Field &F, RandIter &rand, size_t lblock=BW_BLOCK_DEFAULT, size_t rblock=BW_BLOCK_DEFAULT+1) :
			_BMD(F), _VDF(F), _rand(rand) , _left_blockdim(lblock), _right_blockdim(rblock)
		{
                        if (_left_blockdim ==0) _left_blockdim=BW_BLOCK_DEFAULT;
                        if (_right_blockdim ==0) _right_blockdim=BW_BLOCK_DEFAULT;
                }

		template <class Blackbox>
		Vector &solve (Vector &x, const Blackbox &B, const Vector &y) const {
                        try {
                                solveNonSingular(x,B,y);
                        }
                        catch (LinboxError e) {
                                std::cerr<<e<<std::endl;
                        }
                        return x;
                }
                
		template <class Blackbox>
		Vector &solveNonSingular (Vector &x, const Blackbox &B, const Vector &y) const
		{
			Transpose<Blackbox> A(B);

			size_t m,n,bw_try=0;
			m = A.rowdim();
			n = A.coldim();
                        Vector z(field(),y.size());
                        
                        if (_left_blockdim >m/2 || _right_blockdim >n/2) 
                                std::cerr<<"BlockWiedemannSolver (Warning) : block size too large, number of tries might be large"<<std::endl;
                        
			//std::cout<<"row block: "<<_left_blockdim<<std::endl;<commit_msg>error as ref<commit_after>/* linbox/algorithms/block-wiedemann.h
 * Copyright (C) 2004 <NAME>
 *
 * Written by <NAME> <EMAIL>
 * modified by <NAME> (<EMAIL>) 2011
 * ========LICENCE========
 * This file is part of the library LinBox.
 *
 * LinBox 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ========LICENCE========
 */


#ifndef __LINBOX_block_wiedemann_H
#define __LINBOX_block_wiedemann_H

#include <vector>
#include <iostream>


#include "linbox/integer.h"
#include "linbox/matrix/dense-matrix.h"
#include "linbox/matrix/matrix-domain.h"
#include "linbox/algorithms/blackbox-block-container.h"
#include "linbox/algorithms/block-massey-domain.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/blackbox/transpose.h"
#include "linbox/util/commentator.h"

#include "linbox/util/error.h"
//#include "linbox/util/debug.h"

namespace LinBox
{

	template <class Context_>
	class BlockWiedemannSolver{

	public:
		typedef typename Context_::Field                 Field;
		typedef typename Field::Element       Element;
		typedef typename Field::RandIter     RandIter;
		typedef BlasVector<Field>           Vector;
		typedef BlasMatrix<Field>               Block;

	protected:
		Context_                    _BMD;
		VectorDomain<Field>         _VDF;
                RandIter                   _rand;
                size_t                 _left_blockdim;
                size_t                 _right_blockdim; 


#define BW_BLOCK_DEFAULT 8UL
#define BW_MAX_TRY 100               
	public:
		const Field & field() const { return _BMD.field(); }

		BlockWiedemannSolver (const Context_ &C, size_t lblock=BW_BLOCK_DEFAULT, size_t rblock=BW_BLOCK_DEFAULT+1) :
			_BMD(C.field()), _VDF(C.field()), _rand(const_cast<Field&>(C.field())), _left_blockdim(lblock), _right_blockdim(rblock)
		{
                        if (_left_blockdim ==0) _left_blockdim=BW_BLOCK_DEFAULT;
                        if (_right_blockdim ==0) _right_blockdim=BW_BLOCK_DEFAULT;
                }

		BlockWiedemannSolver (const Field &F, RandIter &rand, size_t lblock=BW_BLOCK_DEFAULT, size_t rblock=BW_BLOCK_DEFAULT+1) :
			_BMD(F), _VDF(F), _rand(rand) , _left_blockdim(lblock), _right_blockdim(rblock)
		{
                        if (_left_blockdim ==0) _left_blockdim=BW_BLOCK_DEFAULT;
                        if (_right_blockdim ==0) _right_blockdim=BW_BLOCK_DEFAULT;
                }

		template <class Blackbox>
		Vector &solve (Vector &x, const Blackbox &B, const Vector &y) const {
                        try {
                                solveNonSingular(x,B,y);
                        }
                        catch (const LinboxError& e) {
                                std::cerr<<e<<std::endl;
                        }
                        return x;
                }
                
		template <class Blackbox>
		Vector &solveNonSingular (Vector &x, const Blackbox &B, const Vector &y) const
		{
			Transpose<Blackbox> A(B);

			size_t m,n,bw_try=0;
			m = A.rowdim();
			n = A.coldim();
                        Vector z(field(),y.size());
                        
                        if (_left_blockdim >m/2 || _right_blockdim >n/2) 
                                std::cerr<<"BlockWiedemannSolver (Warning) : block size too large, number of tries might be large"<<std::endl;
                        
			//std::cout<<"row block: "<<_left_blockdim<<std::endl;
{'fraction_non_alphanumeric': 0.10316283666913763, 'fraction_numerical': 0.008401284902396838, 'mean_word_length': 2.358921161825726, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 37, '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': '5431847', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2381, 'n_words': 658}