<commit_before>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/*
 * Copyright (C) 2014 FFLAS-FFACK group
 *
 * Written by <NAME> <<EMAIL>>
 * <NAME> (briceboyer) <<EMAIL>>
 *
 *
 * ========LICENCE========
 * This file is part of the library FFLAS-FFPACK.
 *
 * FFLAS-FFPACK 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 __FFLASFFPACK_ffpack_invert_INL
#define __FFLASFFPACK_ffpack_invert_INL


namespace FFPACK {
template <class Field>
	typename Field::Element_ptr
	Invert (const Field& F, const size_t M,
		typename Field::Element_ptr A, const size_t lda,
		int& nullity)
	{
		FFLASFFPACK_check(lda >= M);

		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}

		size_t * P = FFLAS::fflas_new<size_t>(M);
		size_t * Q = FFLAS::fflas_new<size_t>(M);
		size_t R =  ReducedColumnEchelonForm (F, M, M, A, lda, P, Q, true);
		nullity = (int)(M - R);
		applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans,
			M, 0, (int)R, A, lda, P);
		delete [] P;
		delete [] Q;
		return A;
	}

	template <class Field>
	typename Field::Element_ptr
	Invert (const Field& F, const size_t M,
		typename Field::ConstElement_ptr A, const size_t lda,
		typename Field::Element_ptr X, const size_t ldx,
		int& nullity)
	{
		FFLASFFPACK_check(lda >= M);
		FFLASFFPACK_check(ldx >= M);
		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}


		FFLAS::fassign(F,M,M,A,lda,X,ldx);
		Invert (F,  M, X, lda, nullity);
		return X;
	}

	template <class Field>
	typename Field::Element_ptr
	Invert2( const Field& F, const size_t M,
		 typename Field::Element_ptr A, const size_t lda,
		 typename Field::Element_ptr X, const size_t ldx,
		 int& nullity)
	{
		FFLASFFPACK_check(lda >= M);
		FFLASFFPACK_check(ldx >= M);

		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}

		size_t *P = FFLAS::fflas_new<size_t>(M);
		size_t *rowP = FFLAS::fflas_new<size_t>(M);


		nullity = int(M - LUdivine( F, FFLAS::FflasNonUnit, FFLAS::FflasNoTrans, M, M, A, lda, P, rowP));

		if (nullity > 0){
			FFLAS::fflas_delete( P);
			FFLAS::fflas_delete( rowP);<commit_msg>fix a bug<commit_after>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/*
 * Copyright (C) 2014 FFLAS-FFACK group
 *
 * Written by <NAME> <<EMAIL>>
 * <NAME> (briceboyer) <<EMAIL>>
 *
 *
 * ========LICENCE========
 * This file is part of the library FFLAS-FFPACK.
 *
 * FFLAS-FFPACK 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 __FFLASFFPACK_ffpack_invert_INL
#define __FFLASFFPACK_ffpack_invert_INL


namespace FFPACK {
template <class Field>
	typename Field::Element_ptr
	Invert (const Field& F, const size_t M,
		typename Field::Element_ptr A, const size_t lda,
		int& nullity)
	{
		FFLASFFPACK_check(lda >= M);

		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}
		size_t * P = FFLAS::fflas_new<size_t>(M);
		size_t * Q = FFLAS::fflas_new<size_t>(M);
		size_t R =  ReducedColumnEchelonForm (F, M, M, A, lda, P, Q, true);
		nullity = (int)(M - R);
		applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans,
			M, 0, (int)R, A, lda, P);
		delete [] P;
		delete [] Q;
		return A;
	}

	template <class Field>
	typename Field::Element_ptr
	Invert (const Field& F, const size_t M,
		typename Field::ConstElement_ptr A, const size_t lda,
		typename Field::Element_ptr X, const size_t ldx,
		int& nullity)
	{
		FFLASFFPACK_check(lda >= M);
		FFLASFFPACK_check(ldx >= M);
		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}
		FFLAS::fassign(F,M,M,A,lda,X,ldx);
		Invert (F, M, X, ldx, nullity);
		return X;
	}

	template <class Field>
	typename Field::Element_ptr
	Invert2( const Field& F, const size_t M,
		 typename Field::Element_ptr A, const size_t lda,
		 typename Field::Element_ptr X, const size_t ldx,
		 int& nullity)
	{
		FFLASFFPACK_check(lda >= M);
		FFLASFFPACK_check(ldx >= M);

		if (M == 0) {
			nullity = 0 ;
			return NULL ;
		}

		size_t *P = FFLAS::fflas_new<size_t>(M);
		size_t *rowP = FFLAS::fflas_new<size_t>(M);


		nullity = int(M - LUdivine( F, FFLAS::FflasNonUnit, FFLAS::FflasNoTrans, M, M, A, lda, P, rowP));

		if (nullity > 0){
			FFLAS::fflas_delete( P);
			FFLAS::fflas_delete( rowP);
{'fraction_non_alphanumeric': 0.13983050847457626, 'fraction_numerical': 0.013418079096045197, 'mean_word_length': 3.854327335047129, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 43, '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': '2632807', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2140, 'n_words': 653}