<commit_before>/*============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

===============================================================================*/
/****************************************************************************

   Copyright (C) 2008, 2009 <NAME>
   
*****************************************************************************/

#include <mpir.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"

void _fmpz_poly_mul(fmpz * res, const fmpz * poly1, 
				   ulong len1, const fmpz * poly2, ulong len2)
{
   if (len2 == 1)
   {
      _fmpz_poly_mul_classical(res, poly1, len1, poly2, len2);
	  return;
   }

   ulong len_out = len1 + len2 - 1;
   ulong limbs1 = _fmpz_vec_max_limbs(poly1, len1);
   ulong limbs2 = _fmpz_vec_max_limbs(poly2, len2);
   ulong max_limbs = FLINT_MAX(limbs1, limbs2);

   if ((max_limbs > 4) && (len_out < 16))
      _fmpz_poly_mul_karatsuba(res, poly1, len1, poly2, len2);
   else
      _fmpz_poly_mul_KS(res, poly1, len1, poly2, len2);

}

void fmpz_poly_mul(fmpz_poly_t res, 
                    const fmpz_poly_t poly1, const fmpz_poly_t poly2)
{
   ulong len_out;
   
   if ((poly1->length == 0) || (poly2->length == 0))  
   {
      fmpz_poly_zero(res);
      return;
   }

   len_out = poly1->length + poly2->length - 1;

   if (res == poly1 || res == poly2)
   {
	   fmpz_poly_t temp;
	   fmpz_poly_init(temp);
	   fmpz_poly_fit_length(temp, len_out);
       if (poly1->length >= poly2->length)
		  _fmpz_poly_mul(temp->coeffs, poly1->coeffs, poly1->length,
		                              poly2->coeffs, poly2->length);
	   else
		  _fmpz_poly_mul(temp->coeffs, poly2->coeffs, poly2->length,
		                              poly1->coeffs, poly1->length);
	   fmpz_poly_swap(res, temp);
	   fmpz_poly_clear(temp);
   } else
   {
	   fmpz_poly_fit_length(res, len_out);
       if (poly1->length >= poly2->length)
		  _fmpz_poly_mul(res->coeffs, poly1->coeffs, poly1->length,
		                              poly2->coeffs, poly2->length);
	   else
		  _fmpz_poly_mul(res->coeffs, poly2->coeffs, poly2->length,
		                              poly1->coeffs, poly1->length);
   }

   _fmpz_poly_set_length(res, len_out);
   _fmpz_poly_normalise(res);
}<commit_msg>Changed way to choose algorithm in fmpz_poly_mul<commit_after>/*=============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

=============================================================================*/
/******************************************************************************

   Copyright (C) 2008, 2009 <NAME>

******************************************************************************/

#include <mpir.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"

void _fmpz_poly_mul(fmpz * res, const fmpz * poly1, ulong len1, 
                                const fmpz * poly2, ulong len2)
{
    ulong len, limbs1, limbs2, limbsx;
    
    if (len1 < 5)
    {
        _fmpz_poly_mul_classical(res, poly1, len1, poly2, len2);
	    return;
    }

    len    = len1 + len2 - 1;
    limbs1 = _fmpz_vec_max_limbs(poly1, len1);
    limbs2 = _fmpz_vec_max_limbs(poly2, len2);
    limbsx = FLINT_MAX(limbs1, limbs2);

    if (len < 16)
    {
        if (limbsx <= 5)
            _fmpz_poly_mul_classical(res, poly1, len1, poly2, len2);
        else
            _fmpz_poly_mul_karatsuba(res, poly1, len1, poly2, len2);
    }
    else
        _fmpz_poly_mul_KS(res, poly1, len1, poly2, len2);
}

void fmpz_poly_mul(fmpz_poly_t res, 
                   const fmpz_poly_t poly1, const fmpz_poly_t poly2)
{
    ulong rlen;
    ulong len1 = poly1->length;
    ulong len2 = poly2->length;

    if ((len1 == 0) | (len2 == 0))
    {
        fmpz_poly_zero(res);
        return;
    }

    rlen = len1 + len2 - 1;

    if (res == poly1 | res == poly2)
    {
        fmpz_poly_t t;
        fmpz_poly_init(t);
        fmpz_poly_fit_length(t, rlen);
        if (len1 >= len2)
            _fmpz_poly_mul(t->coeffs, poly1->coeffs, len1,
                                      poly2->coeffs, len2);
        else
            _fmpz_poly_mul(t->coeffs, poly2->coeffs, len2,
                                      poly1->coeffs, len1);
        fmpz_poly_swap(res, t);
        fmpz_poly_clear(t);
    }
    else
    {
        fmpz_poly_fit_length(res, rlen);
        if (len1 >= len2)
            _fmpz_poly_mul(res->coeffs, poly1->coeffs, len1,
                                        poly2->coeffs, len2);
        else
        _fmpz_poly_mul(res->coeffs, poly2->coeffs, len2,
                                    poly1->coeffs, len1);
    }

    _fmpz_poly_set_length(res, rlen);
    _fmpz_poly_normalise(res);
}
{'fraction_non_alphanumeric': 0.18845033969589128, 'fraction_numerical': 0.028469750889679714, 'mean_word_length': 2.693548387096774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6910329', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2031, 'n_words': 532}