コード例 #1
0
void sample_ZmodF_mul_plain(unsigned long n, void* arg, unsigned long count)
{
   ZmodF_mul_info_t info;
   ZmodF_mul_info_init_plain(info, n, 0);
   sample_ZmodF_mul_helper(info, n, count);
   ZmodF_mul_info_clear(info);
}
コード例 #2
0
void sample_ZmodF_sqr_auto(unsigned long n, void* arg, unsigned long count)
{
   ZmodF_mul_info_t info;
   ZmodF_mul_info_init(info, n, 1);
   sample_ZmodF_sqr_helper(info, n, count);
   ZmodF_mul_info_clear(info);
}
コード例 #3
0
ファイル: ZmodF_mul-test.c プロジェクト: hperl/flint
int test_ZmodF_mul_info_mul_fft()
{
   int success = 1;

   mp_limb_t in1[1000];
   mp_limb_t in2[1000];
   mp_limb_t out_plain[1000];
   mp_limb_t out_fft[1000];

   mpz_t x;
   mpz_init(x);

   for (unsigned long n = 1; n < 300 && success; n++)
   {
      for (unsigned long depth = 1;
           (n*FLINT_BITS) % (1 << depth) == 0
           && (depth <= FLINT_LG_BITS_PER_LIMB + 4)
           && success; depth++)
      {
         unsigned long input_bits = (n*FLINT_BITS) >> depth;
         unsigned long output_bits = 2*input_bits + 1 + depth;
         unsigned long target_m =
                            ((output_bits - 1) >> FLINT_LG_BITS_PER_LIMB) + 1;
      
         for (unsigned long m = target_m - 2; m <= target_m + 3 && success; m++)
         {
            if ((m*FLINT_BITS) % (1 << depth) != 0)
               continue;

            for (unsigned long k = 0; k <= 2 && success; k++)
            {
               if (m + k < target_m)
                  continue;
			   if (m + k > n)
			      continue;
               if (k > m)
                  continue;
            
#if DEBUG
               printf("n = %ld, depth = %ld, m = %ld, k = %ld\n", n, depth, m, k);
#endif

               ZmodF_mul_info_t info_plain, info_fft;
               ZmodF_mul_info_init_plain(info_plain, n, 0);
               ZmodF_mul_info_init_fft(info_fft, n, depth, m, k, 0);

               for (unsigned long trial = 0; trial < 10 && success; trial++)
               {
                  if (random_ulong(4) == 0)
                  {
                     // put in -1 mod p every now and then
                     ZmodF_zero(in1, n);
                     in1[n] = 1;
                  }
                  else
                  {
                     random_limbs(in1, n);
                     in1[n] = 0;
                  }

                  if (random_ulong(4) == 0)
                  {
                     // put in -1 mod p every now and then
                     ZmodF_zero(in2, n);
                     in2[n] = 1;
                  }
                  else
                  {
                     random_limbs(in2, n);
                     in2[n] = 0;
                  }

                  // test multiplication

                  ZmodF_mul_info_mul(info_plain, out_plain, in1, in2);
                  ZmodF_mul_info_mul(info_fft, out_fft, in1, in2);

                  ZmodF_normalise(out_plain, n);
                  ZmodF_normalise(out_fft, n);

                  if (mpn_cmp(out_plain, out_fft, n+1))
                     success = 0;

                  // test squaring
         
                  ZmodF_mul_info_mul(info_plain, out_plain, in1, in1);
                  ZmodF_mul_info_mul(info_fft, out_fft, in1, in1);

                  ZmodF_normalise(out_plain, n);
                  ZmodF_normalise(out_fft, n);

                  if (mpn_cmp(out_plain, out_fft, n+1))
                     success = 0;
               }

               ZmodF_mul_info_clear(info_fft);
               ZmodF_mul_info_clear(info_plain);
            }
         }
      }
   }

   mpz_clear(x);

   return success;
}
コード例 #4
0
ファイル: ZmodF_mul-test.c プロジェクト: hperl/flint
int test_ZmodF_mul_info_mul_threeway()
{
   int success = 1;

   mp_limb_t in1[2000];
   mp_limb_t in2[2000];
   mp_limb_t out_plain[2000];
   mp_limb_t out_threeway[2000];

   mpz_t x;
   mpz_init(x);

   for (unsigned long n = 3; n < 100 && success; n += 3)
   {
#if DEBUG
      printf("n = %d\n", n);
#endif

      ZmodF_mul_info_t info_plain, info_threeway;
      ZmodF_mul_info_init_threeway(info_threeway, n, 0);
      ZmodF_mul_info_init_plain(info_plain, n, 0);

      for (unsigned long trial = 0; trial < 50000 && success; trial++)
      {
         if (random_ulong(4) == 0)
         {
            // put in -1 mod p every now and then
            ZmodF_zero(in1, n);
            in1[n] = 1;
         }
         else
         {
            random_limbs(in1, n);
            in1[n] = 0;
         }

         if (random_ulong(4) == 0)
         {
            // put in -1 mod p every now and then
            ZmodF_zero(in2, n);
            in2[n] = 1;
         }
         else
         {
            random_limbs(in2, n);
            in2[n] = 0;
         }

         // test multiplication
         
         ZmodF_mul_info_mul(info_plain, out_plain, in1, in2);
         ZmodF_mul_info_mul(info_threeway, out_threeway, in1, in2);
         
         ZmodF_normalise(out_plain, n);
         ZmodF_normalise(out_threeway, n);
         
         if (mpn_cmp(out_plain, out_threeway, n+1))
            success = 0;

         // test squaring
         
         ZmodF_mul_info_mul(info_plain, out_plain, in1, in1);
         ZmodF_mul_info_mul(info_threeway, out_threeway, in1, in1);
         
         ZmodF_normalise(out_plain, n);
         ZmodF_normalise(out_threeway, n);
         
         if (mpn_cmp(out_plain, out_threeway, n+1))
            success = 0;
      }
      
      ZmodF_mul_info_clear(info_plain);
      ZmodF_mul_info_clear(info_threeway);
   }

   mpz_clear(x);

   return success;
}
コード例 #5
0
ファイル: ZmodF_mul-test.c プロジェクト: hperl/flint
int test_ZmodF_mul_info_mul_plain()
{
   int success = 1;

   mp_limb_t in1[2000];
   mp_limb_t in2[2000];
   mp_limb_t out[2000];

   mpz_t x1, x2, y, z, p;
   mpz_init(x1);
   mpz_init(x2);
   mpz_init(y);
   mpz_init(z);
   mpz_init(p);

   for (unsigned long n = 1; n < 100 && success; n++)
   {
#if DEBUG
      printf("n = %d\n", n);
#endif

      // p = B^n + 1
      mpz_set_ui(p, 1);
      mpz_mul_2exp(p, p, n*FLINT_BITS);
      mpz_add_ui(p, p, 1);

      ZmodF_mul_info_t info;
      ZmodF_mul_info_init_plain(info, n, 0);

      for (unsigned long trial = 0; trial < 1000 && success; trial++)
      {
         if (random_ulong(4) == 0)
         {
            // put in -1 mod p every now and then
            ZmodF_zero(in1, n);
            in1[n] = 1;
         }
         else
         {
            random_limbs(in1, n);
            in1[n] = 0;
         }

         if (random_ulong(4) == 0)
         {
            // put in -1 mod p every now and then
            ZmodF_zero(in2, n);
            in2[n] = 1;
         }
         else
         {
            random_limbs(in2, n);
            in2[n] = 0;
         }

         // test multiplication
         
         mpn_to_mpz(x1, in1, n+1);
         mpn_to_mpz(x2, in2, n+1);
         mpz_mul(z, x1, x2);
         mpz_mod(z, z, p);
         
         ZmodF_mul_info_mul(info, out, in1, in2);
         ZmodF_normalise(out, n);
         mpn_to_mpz(y, out, n+1);
         
         if (mpz_cmp(y, z))
            success = 0;
            
         // test squaring
         
         mpz_mul(z, x1, x1);
         mpz_mod(z, z, p);
         
         ZmodF_mul_info_mul(info, out, in1, in1);
         ZmodF_normalise(out, n);
         mpn_to_mpz(y, out, n+1);
         
         if (mpz_cmp(y, z))
            success = 0;
      }
      
      ZmodF_mul_info_clear(info);
   }

   mpz_clear(x1);
   mpz_clear(x2);
   mpz_clear(y);
   mpz_clear(z);
   mpz_clear(p);

   return success;
}