Пример #1
0
void F_mpzmod_mat_clear(F_mpzmod_mat_t mat)
{
   for (ulong i = 0; i < mat->r*mat->c; i++)
		F_mpz_clear(mat->entries + i);
	flint_heap_free(mat->rows);
   flint_heap_free(mat->entries);
}
Пример #2
0
Файл: fmpz.c Проект: hperl/flint
void fmpz_comb_temp_clear(fmpz_t ** temp, fmpz_comb_t comb)
{
   ulong i;
   ulong n = comb->n;
   // free temp
	for (i = 0; i < n; i++)
   {
      flint_heap_free(temp[i][0]);
      flint_heap_free(temp[i]);
	}
	flint_heap_free(temp);
}
Пример #3
0
void F_mpz_mod_poly_clear(F_mpz_mod_poly_t poly)
{
   for (ulong i = 0; i < poly->alloc; i++) // Clean up any mpz_t's
		_F_mpz_demote(poly->coeffs + i);
	if (poly->coeffs) 
      flint_heap_free(poly->coeffs); // clean up ordinary coeffs
   F_mpz_clear(poly->P);
}
Пример #4
0
void mpq_mat_clear(mpq_mat_t mat)
{
   long i;
   for (i = 0; i < mat->r*mat->c; i++)
      mpq_clear(mat->entries[i]);

   if (mat->entries) flint_heap_free(mat->entries);
	mat->entries = NULL;
	mat->r = 0;
	mat->c = 0;
}
Пример #5
0
void flint_stack_release_small(void)
{
   if (block_left == FLINT_SMALL_BLOCK_SIZE - 2)
   {
      block_ptr -= 2;
      block_left = block_ptr[0];
      mp_limb_t * temp = block_ptr;
      block_ptr = (mp_limb_t *) block_ptr[1]; 
      flint_heap_free(temp);           
   } 
   
   block_ptr--;
   unsigned long temp = (*block_ptr);
   block_left += (temp+1);
   block_ptr -= temp;
}
Пример #6
0
void F_mpzmod_mat_mul_classical(F_mpzmod_mat_t res, F_mpzmod_mat_t mat1, F_mpzmod_mat_t mat2)
{
   ulong c1 = mat1->c;
	ulong r2 = mat2->r;
   
	if ((c1 != r2) || (c1 == 0))
	{
		printf("FLINT exception : invalid matrix multiplication!\n");
		abort();
	}

	ulong r1 = mat1->r;
   ulong c2 = mat2->c;

	if ((r1 == 0) || (c2 == 0)) return; // no work to do

	F_mpz * temp = (F_mpz *) flint_heap_alloc(c2);

	for (ulong i = 0; i < c2; i++)
		F_mpz_init(temp + i);
	
   for (ulong i = 0; i < r1; i++) // for each row of mat1
	{
		F_mpz * c = mat1->rows[i];

		for (ulong k = 0; k < c2; k++) // do initial scalar product of row 1 of mat2 by c
		   F_mpz_mul2(temp + k, mat2->rows[0] + k, c);

		for (ulong j = 1; j < c1; j++) // compute scalar product for rows 1 to c1 of mat2
		{
         for (ulong k = 0; k < c2; k++) // do scalar product of row j of mat2 by c
		   {
            F_mpz_addmul(temp + k, mat2->rows[j] + k, c + j);
         }
		}
			   
		for (ulong k = 0; k < c2; k++) // do reduction mod p and store in result
	   {
		   F_mpz_mod(res->rows[i] + k, temp + k, mat1->p);
		}
	}

	for (ulong i = 0; i < c2; i++)
		F_mpz_clear(temp + i);

	flint_heap_free(temp);
}
Пример #7
0
Файл: fmpz.c Проект: hperl/flint
void fmpz_comb_clear(fmpz_comb_t comb)
{
   unsigned long n = comb->n;

   for (unsigned i = 0; i < n; i++)
   {
      flint_heap_free(comb->comb[i][0]);
      flint_heap_free(comb->comb[i]);
      flint_heap_free(comb->res[i][0]);
      flint_heap_free(comb->res[i]);
   }
	if (n)
	{
		flint_heap_free(comb->res);
      flint_heap_free(comb->comb);
	}

   flint_heap_free(comb->mod);
}
Пример #8
0
void flint_stack_cleanup()
{
   limb_mem_t* curr = head_mpn;
   limb_mem_t* temp;
   
   if (curr != NULL)
   {
      do 
      {
         if (curr->allocated) 
         {
            printf("Warning: FLINT stack memory allocation cleanup detected mismatched allocation/releases\n"); 
         } 
         free(curr->point);
         if (curr==last_mpn) last_mpn = curr->prev;
         else curr->next->prev = curr->prev;
         if (curr==head_mpn) head_mpn=curr->next;
         else (curr->prev->next = curr->next);
         temp=curr;
         curr = curr->next;
         free(temp);
      } while (curr != NULL);
      free(reservoir_mpn);
   }
   
   if (block_ptr != NULL)
   {
      if (block_left != FLINT_SMALL_BLOCK_SIZE - 2)
      {
         printf("Warning: FLINT small stack memory allocator detected mismatched alloc/release\n");
         while (block_left != FLINT_SMALL_BLOCK_SIZE - 2) flint_stack_release_small();
      }  
      
      block_ptr -= 2;
      flint_heap_free(block_ptr);           
   } 
}
Пример #9
0
Файл: fmpz.c Проект: hperl/flint
void fmpz_multi_CRT_ui(fmpz_t output, unsigned long * residues, fmpz_comb_t comb, fmpz_t ** comb_temp)
{
   ulong i, j, k;

   ulong n = comb->n;
   ulong num;
   ulong log_res;
	mp_limb_t * ptr;
	ulong size;
   ulong num_primes = comb->num_primes;

   if (num_primes == 1) // the output is less than a single prime, so just output the result
   {
	   unsigned long p = comb->primes[0];
	   if ((p - residues[0]) < residues[0]) fmpz_set_si(output, (long) (residues[0] - p));
	   else fmpz_set_ui(output, residues[0]);
	   return;
	}

	// first layer of reconstruction
	num = (1L<<n);
   mp_limb_t temps[3];
   mp_limb_t temp2s[3];
   for (i = 0, j = 0; i + 2 <= num_primes; i += 2, j++)
   {
      fmpz_set_ui(temps, residues[i]);
      fmpz_set_ui(temp2s, fmpz_mod_ui(temps, comb->primes[i+1]));
      fmpz_sub_ui_inplace(temp2s, residues[i + 1]);
      temp2s[0] = -temp2s[0];
      fmpz_mul(temps, temp2s, comb->res[0][j]);
      fmpz_set_ui(temp2s, fmpz_mod_ui(temps, comb->primes[i+1]));
      fmpz_mul_ui(temps, temp2s, comb->primes[i]); 
      fmpz_add_ui(comb_temp[0][j], temps, residues[i]);
   }
   if (i < num_primes) fmpz_set_ui(comb_temp[0][j], residues[i]);
   
   // compute other layers of reconstruction
	fmpz_t temp = (fmpz_t) flint_heap_alloc(2*num + 1); 
   fmpz_t temp2 = (fmpz_t) flint_heap_alloc(2*num + 1); 
   num /= 2;
   log_res = 1;
   while (log_res < n)
   {
      for (i = 0, j = 0; i < num; i += 2, j++)
      {
         if (fmpz_is_one(comb->comb[log_res-1][i+1]))
		   {
		      if (!fmpz_is_one(comb->comb[log_res-1][i])) fmpz_set(comb_temp[log_res][j], comb_temp[log_res-1][i]);
		   } else
		   {
			   fmpz_mod(temp2, comb_temp[log_res-1][i], comb->comb[log_res-1][i+1]);
            fmpz_sub(temp, temp2, comb_temp[log_res-1][i+1]);
            temp[0] = -temp[0];
            fmpz_mul(temp2, temp, comb->res[log_res][j]);
            fmpz_mod(temp, temp2, comb->comb[log_res-1][i+1]);
            fmpz_mul(temp2, temp, comb->comb[log_res-1][i]);
            fmpz_add(comb_temp[log_res][j], temp2, comb_temp[log_res-1][i]);
		   }
      }     
      log_res++;
      num /= 2; 
   }

   // write out the output
	__fmpz_multi_CRT_sign(comb_temp[log_res - 1][0], comb_temp[log_res - 1][0], comb);
	fmpz_set(output, comb_temp[log_res - 1][0]);

   flint_heap_free(temp2); //temp2
   flint_heap_free(temp); //temp 
}