Exemple #1
0
void FastMul(const BigInt &A,const BigInt &B, BigInt &C) {
	ulong Len = 2;
	while ( Len <  A.Size + B.Size ) Len *=2;

	if ( Len < 40 ) {
		BigInt Atmp(A), Btmp(B);
		Mul(Atmp,Btmp,C);
		return;
	}

	ulong x;
	const ushort *a=A.Coef, *b=B.Coef;

	for (x = 0; x < A.Size; x++)    LongNum1[x] = a[x];
	for (; x < Len; x++) 		LongNum1[x] = 0.0;

	FHT_F(LongNum1,Len);

	if (a == b) {
		FHTConvolution(LongNum1,LongNum1,Len);
	} else {
		for (x = 0; x < B.Size; x++)    LongNum2[x] = b[x];
		for (; x < Len; x++) 		LongNum2[x] = 0.0;
		FHT_F(LongNum2,Len);
		FHTConvolution(LongNum1,LongNum2,Len);
	 }

	FHT_T(LongNum1,Len);

	CarryNormalize(LongNum1, Len, C);
}
void BlockMatrixTest::testAssignment()
{
  std::cout << "--> Test: assignment." <<std::endl;
  SP::SiconosMatrix Btmp(new SimpleMatrix(2, 2));
  SP::SiconosMatrix Ctmp(new SimpleMatrix(2, 5));
  SP::SiconosMatrix Dtmp(new SimpleMatrix(3, 2));
  SP::SiconosMatrix Etmp(new SimpleMatrix(3, 5));

  SP::SiconosMatrix test(new BlockMatrix(Btmp, Ctmp, Dtmp, Etmp));
  // Block = Siconos(Simple)
  unsigned int size0 = test->size(0), size1 = test->size(1);
  SP::SiconosMatrix ref(new SimpleMatrix(size0, size1));
  for (unsigned int i = 0; i < size0 ; ++i)
    for (unsigned int j = 0; j < size1; ++j)
      (*ref)(i, j) = i + j;
  *test = *ref;
  for (unsigned int i = 0; i < size0 ; ++i)
    for (unsigned int j = 0; j < size1; ++j)
      CPPUNIT_ASSERT_EQUAL_MESSAGE("testAssignment: ", fabs((*test)(i, j) - (*ref)(i, j)) < tol , true);

  // Block = Siconos(Block)
  test->zero();

  ref.reset(new BlockMatrix(m, 2, 3));
  *test = *ref;
  for (unsigned int i = 0; i < size0 ; ++i)
    for (unsigned int j = 0; j < size1; ++j)
      CPPUNIT_ASSERT_EQUAL_MESSAGE("testAssignment: ", fabs((*test)(i, j) - (*ref)(i, j)) < tol , true);

  // Block = Block
  test->zero();
  SP::BlockMatrix ref2(new BlockMatrix(m, 2, 3));
  *test = *ref2;
  for (unsigned int i = 0; i < size0 ; ++i)
    for (unsigned int j = 0; j < size1; ++j)
      CPPUNIT_ASSERT_EQUAL_MESSAGE("testAssignment: ", fabs((*test)(i, j) - (*ref2)(i, j)) < tol , true);
  std::cout << "-->  test assignment ended with success." <<std::endl;
}