コード例 #1
0
local void lo_randomize_coords(double *coords) {
  int i;

  for (i = 2*lo_dim_square-1;  i >= 0;  --i) {
    coords[i] = wn_flat_distribution() * (lo_dim-1);
  }
} /* lo_randomize_coords */
コード例 #2
0
ファイル: examples5.c プロジェクト: ujwalramesh/VLSIPlacement
local void initialize(void)
{
  int i,j;

  wn_gpmake("no_free"); 

  wn_make_vect(&solution_vect,SIZE*SIZE);
  wn_make_vect(&grad_vect,SIZE*SIZE);

  wn_make_mat(&solution_mat,SIZE,SIZE);
  wn_make_mat(&grad_mat,SIZE,SIZE);
  wn_make_mat(&cost_mat,SIZE,SIZE);

  for(i=0;i<SIZE;++i)
  for(j=0;j<SIZE;++j)
  {
    cost_mat[i][j] = wn_flat_distribution();
  }
}
コード例 #3
0
ファイル: selftest.c プロジェクト: ujwalramesh/VLSIPlacement
local void mat_test_gramm_schmidt(void)
{
  double **mat, **mat_orig;
  int ilen, jlen, code;		/* ilen rows, jlen columns */
  int a, b;
  double *sum_vect, mul, mul2;
  int trial;

  for (trial = 0;  trial < 1000;  ++trial) {
    wn_gpmake("no_free");    /* temp memory group */

      jlen = (unsigned) wn_random_int() % 20    +  1;
      ilen = (unsigned) wn_random_int() % jlen  +  1;

      wn_make_mat(&mat_orig, ilen, jlen);
      wn_random_mat(mat_orig, ilen, jlen);

      wn_make_mat(&mat, ilen, jlen);
      for (a = 0;  a < ilen;  ++a) {
	for (b = 0;  b < jlen;  ++b) {
	  mat[a][b] = mat_orig[a][b];
	}
      }

      wn_gramm_schmidt(&code, mat, ilen, jlen);
      wn_assert(WN_SUCCESS == code);

      /* first ilen vects should be orthogonal */
      for (a = 0;  a < ilen;  ++a) {
	for (b = a+1;  b < ilen;  ++b) {
	  wn_assert(LO_ALMOST_EQUAL(0.0, wn_dot_vects(mat[a], mat[b], jlen)));
	}
      }

      /* let's make the gramm_schmidt be unit vectors, to be simple */
      for (a = 0;  a < ilen;  ++a) {
	mul2 = wn_dot_vects(mat[a], mat[a], jlen);
	mul = 1/sqrt(mul2);
	for (b = 0;  b < jlen;  ++b) {
	  mat[a][b] *= mul;
	}
	wn_assert(LO_ALMOST_EQUAL(1.0, wn_dot_vects(mat[a], mat[a], jlen)));
      }

      /* check again orthogonality */
      for (a = 0;  a < ilen;  ++a) {
	for (b = a+1;  b < ilen;  ++b) {
	  wn_assert(LO_ALMOST_EQUAL(0.0, wn_dot_vects(mat[a], mat[b], jlen)));
	}
      }

      /* make a vector in the space spanned by the original vectors */
      wn_make_vect(&sum_vect, jlen);
      wn_zero_vect(sum_vect, jlen);
      for (a = 0;  a < ilen;  ++a) {
	wn_add_scaled_vect(sum_vect, mat_orig[a], wn_flat_distribution(),
	/**/							jlen);
      }

      /* OK, sum_vect is reached from the original matrix of vectors */
      /* can we reach it from mat? */
      for (a = 0;  a < ilen;  ++a) {
	mul = wn_dot_vects(sum_vect, mat[a], jlen);
	wn_add_scaled_vect(sum_vect, mat[a], -mul, jlen);
      }
      wn_assert(LO_ALMOST_EQUAL(0.0, wn_dot_vects(sum_vect, sum_vect, jlen)));

    wn_gpfree();
  } /* for trial */
} /* mat_test_gramm_schmidt */
コード例 #4
0
ファイル: wnrdb.c プロジェクト: AlexVSharp/TreeMaker
double wn_random_double_between(double low,double high)
{
  return((high-low)*wn_flat_distribution()+low);
}