コード例 #1
0
ファイル: CCostTest.cpp プロジェクト: b-xiang/gporca
//---------------------------------------------------------------------------
//	@function:
//		CCostTest::EresUnittest_Arithmetic
//
//	@doc:
//		Test arithmetic operations
//
//---------------------------------------------------------------------------
GPOS_RESULT
CCostTest::EresUnittest_Arithmetic()
{
	CAutoMemoryPool amp;
	IMemoryPool *mp = amp.Pmp();

	CCost cost1(2.5);
	CCost cost2(3.0);
	CCost cost3(5.49);
	CCost cost4(5.51);
	CCost cost5(7.49);
	CCost cost6(7.51);

	CCost costAdd(cost1 + cost2);
	CCost costMultiply(cost1 * cost2);

	GPOS_ASSERT(costAdd > cost3);
	GPOS_ASSERT(costAdd < cost4);

	GPOS_ASSERT(costMultiply > cost5);
	GPOS_ASSERT(costMultiply < cost6);

	CAutoTrace at(mp);
	IOstream &os(at.Os());

	os << "Arithmetic operations: " << std::endl
	   << cost1 << " + " << cost2 << " = " << costAdd << std::endl
	   << cost1 << " * " << cost2 << " = " << costMultiply << std::endl;

	return GPOS_OK;
}
コード例 #2
0
ファイル: 1dc1.c プロジェクト: 3ki5tj/scinotes
int main(void)
{
  double *in, *in2, *out, *out2;
  fftw_plan p, q;
  int i, n = 12;

  in = (double *) fftw_malloc(sizeof(*in) * (n + 1));
  in2 = (double *) fftw_malloc(sizeof(*in2) * (n + 1));
  out = (double *) fftw_malloc(sizeof(*out2) * (n + 1));
  out2 = (double *) fftw_malloc(sizeof(*out2) * (n + 1));
  p = fftw_plan_r2r_1d(n + 1, in, out, FFTW_REDFT00, FFTW_ESTIMATE);

  // for n = 3: in[0] = 1; in[1] = 2; in[2] = 3; in[3] = 5;
  for (i = 0; i <= n; i++) in[i] = cos(2*M_PI*3*i/n);

  fftw_execute(p);
  cost1(n, in, out2);

  for (i = 0; i <= n; i++)
    printf("%6d %20.10f |  %20.10f\n", i, out[i], out2[i]);

  printf("\nApplying the inverse transform:\n");
  q = fftw_plan_r2r_1d(n + 1, out, in2, FFTW_REDFT00, FFTW_ESTIMATE);
  fftw_execute(q);
  for (i = 0; i <= n; i++)
    printf("%6d %20.10f |  %20.10f\n", i, in[i], in2[i]/(2*n));

  fftw_destroy_plan(p); fftw_destroy_plan(q); fftw_cleanup();
  fftw_free(in); fftw_free(in2); fftw_free(out); fftw_free(out2);
  return 0;
}
コード例 #3
0
ファイル: CCostTest.cpp プロジェクト: b-xiang/gporca
//---------------------------------------------------------------------------
//	@function:
//		CCostTest::EresUnittest_Bool
//
//	@doc:
//		Test comparison operations
//
//---------------------------------------------------------------------------
GPOS_RESULT
CCostTest::EresUnittest_Bool()
{
	CAutoMemoryPool amp;
	IMemoryPool *mp = amp.Pmp();

	CCost cost1(2.5);
	CCost cost2(3.5);

	GPOS_ASSERT(cost1 < cost2);
	GPOS_ASSERT(cost2 > cost1);

	CAutoTrace at(mp);
	IOstream &os(at.Os());

	os << "Boolean operations: " << std::endl
	   << cost1 << " < " << cost2 << " = " << (cost1 < cost2) << std::endl
	   << cost2 << " > " << cost1 << " = " << (cost2 > cost1) << std::endl;

	return GPOS_OK;
}