Ejemplo n.º 1
0
void
test_field_surface_area_planar(void)
{
    enum { max_size = 76 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 50;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        gdouble alpha = g_rand_double_range(rng, -5.0, 5.0);
        gdouble beta = g_rand_double_range(rng, -5.0, 5.0);
        GwyField *field = field_make_planar(xres, yres, alpha, beta);
        gdouble area, area_expected;
        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        area = gwy_field_surface_area(field, NULL, NULL, GWY_MASK_IGNORE);
        area_expected = planar_field_surface_area(field);
        g_assert_cmpfloat(fabs(area - area_expected)/area_expected, <=, 1e-9);

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        area = gwy_field_surface_area(field, NULL, NULL, GWY_MASK_IGNORE);
        area_expected = planar_field_surface_area(field);
        g_assert_cmpfloat(fabs(area - area_expected)/area_expected, <=, 1e-9);

        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 2
0
static void
gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
{
  GeglOperationClass               *operation_class;
  GeglOperationPointComposer3Class *point_composer_class;
  GRand                            *gr;
  gint                              i;

  operation_class      = GEGL_OPERATION_CLASS (klass);
  point_composer_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);

  gegl_operation_class_set_keys (operation_class,
                                 "name",        "gimp:dissolve-mode",
                                 "description", "GIMP dissolve mode operation",
                                 "categories",  "compositors",
                                 NULL);

  operation_class->prepare      = gimp_operation_dissolve_mode_prepare;
  point_composer_class->process = gimp_operation_dissolve_mode_process;

  /* generate a table of random seeds */
  gr = g_rand_new_with_seed (314159265);
  for (i = 0; i < RANDOM_TABLE_SIZE; i++)
    random_table[i] = g_rand_int (gr);

  g_rand_free (gr);
}
Ejemplo n.º 3
0
void
test_field_process_quarters_unmasked_border(void)
{
    enum { max_size = 15, niter = 100 };
    gdouble eps = 1e-12;
    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };
        GwyField *field = gwy_field_new_sized(xres, yres, FALSE);
        gboolean useallfunc = g_rand_boolean(rng);
        field_randomize(field, rng);
        gdouble result = 0.0;
        gwy_field_process_quarters(field, &fpart, NULL, 0, TRUE,
                                   sum_quarters,
                                   useallfunc ? sum_allquarters : NULL,
                                   &result);
        gdouble reference = 0.0;
        for (guint i = 0; i < height; i++) {
            for (guint j = 0; j < width; j++) {
                reference += 4.0*gwy_field_index(field, col + j, row + i);
            }
        }
        gwy_assert_floatval(result, reference, eps);

        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 4
0
static gboolean
gimp_operation_dissolve_mode_process (GeglOperation       *operation,
                                      void                *in_buf,
                                      void                *aux_buf,
                                      void                *aux2_buf,
                                      void                *out_buf,
                                      glong                samples,
                                      const GeglRectangle *result,
                                      gint                 level)
{
  gdouble         opacity  = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
  gfloat         *in       = in_buf;
  gfloat         *out      = out_buf;
  gfloat         *aux      = aux_buf;
  gfloat         *mask     = aux2_buf;
  const gboolean  has_mask = mask != NULL;
  gint            x, y;

  for (y = result->y; y < result->y + result->height; y++)
    {
      GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);

      /* fast forward through the rows pseudo random sequence */
      for (x = 0; x < result->x; x++)
        g_rand_int (gr);

      for (x = result->x; x < result->x + result->width; x++)
        {
          gfloat value = aux[ALPHA] * opacity * 255;

          if (has_mask)
            value *= *mask;

          if (g_rand_int_range (gr, 0, 255) >= value)
            {
              out[0] = in[0];
              out[1] = in[1];
              out[2] = in[2];
              out[3] = in[3];
            }
          else
            {
              out[0] = aux[0];
              out[1] = aux[1];
              out[2] = aux[2];
              out[3] = 1.0;
            }

          in   += 4;
          out  += 4;
          aux  += 4;

          if (has_mask)
            mask ++;
        }
      g_rand_free (gr);
    }

  return TRUE;
}
Ejemplo n.º 5
0
static rt_pattern* rt_pattern_new(void)
{
    rt_pattern* rtpat = malloc(sizeof(*rtpat));

    MESSAGE("new rt_pattern...\n");

    if (!rtpat)
        goto fail0;

    rtpat->rnd = g_rand_new_with_seed((guint32)time(NULL));

    if (!rtpat->rnd)
        goto fail1;

    rtpat->playing = 0;
    rtpat->triggered = 0;

/*    rtpat->seedtype = SEED_TIME_SYS;*/

    rtpat->start_tick = rtpat->end_tick = 0;
    rtpat->index = rtpat->loop_length = 0;

    rtpat->width_min = rtpat->width_max = 0;
    rtpat->height_min = rtpat->height_max = 0;

    rtpat->events = 0;
    rtpat->evlast = 0;
    rtpat->evout = 0;

    return rtpat;

fail1:  free(rtpat);
fail0:  MESSAGE("out of memory for rt_pattern\n");
    return 0;
}
Ejemplo n.º 6
0
static void _random2_distribution (GPtrArray *points,
				  AranSolver2d *solver)
{
  guint i;
  PointAccum *point;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i<np; i++)
    {

#ifdef VSG_HAVE_MPI
      if (i%_flush_interval == 0)
        {
          aran_solver2d_migrate_flush (solver);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);

              aran_solver2d_distribute_contiguous_leaves (solver);
            }
        }
#endif /* VSG_HAVE_MPI */

      point->vector.x = g_rand_double_range (rand, -R, R);;
      point->vector.y = g_rand_double_range (rand, -R, R);;
      point->density = 1.;
      point->accum = 0.;
      point->id = i;

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver2d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %dth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

#ifdef VSG_HAVE_MPI
      if (i%(_flush_interval*10) == 0)
        {
          if (_verbose && rk == 0)
            g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
          aran_solver2d_distribute_contiguous_leaves (solver);
        }
#endif /* VSG_HAVE_MPI */
    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver2d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
Ejemplo n.º 7
0
void
test_int_set_assign(void)
{
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 20;

    for (guint iter = 0; iter < niter; iter++) {
        GwyIntSet *original = gwy_int_set_new(), *copy = gwy_int_set_new();
        int_set_randomize(original, rng);

        guint counter = 0, xcounter = 0;
        g_signal_connect_swapped(copy, "assigned",
                                 G_CALLBACK(record_signal), &counter);
        g_signal_connect_swapped(copy, "added",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(copy, "removed",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "added",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "removed",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "assigned",
                                 G_CALLBACK(record_signal), &xcounter);
        gwy_int_set_assign(copy, original);
        int_set_assert_order(copy);
        int_set_assert_equal(copy, original);
        g_assert_cmpuint(counter, ==, 1);
        g_assert_cmpuint(xcounter, ==, 0);

        g_object_unref(copy);
        g_object_unref(original);
    }
    g_rand_free(rng);
}
Ejemplo n.º 8
0
void
test_field_volume_voids_planar(void)
{
    enum { max_size = 66 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 100;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 3, max_size);
        guint yres = g_rand_int_range(rng, 3, max_size);
        gdouble alpha = g_rand_double_range(rng, -5.0, 5.0);
        gdouble beta = g_rand_double_range(rng, -5.0, 5.0);
        gdouble base = g_rand_double_range(rng, -5.0, 5.0);
        GwyField *field = field_make_planar(xres, yres, alpha, beta);
        GwyFieldPart fpart = { 1, 1, xres-2, yres-2 };
        gdouble volume, volume_expected;
        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        volume = gwy_field_material_volume(field, &fpart,
                                           NULL, GWY_MASK_IGNORE, FALSE, base);
        volume_expected = planar_field_material_volume(field, base, FALSE);
        gwy_assert_floatval(volume, volume_expected, 1e-9*fabs(volume_expected));

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        volume_expected = planar_field_material_volume(field, base, FALSE);
        volume = gwy_field_material_volume(field, &fpart,
                                           NULL, GWY_MASK_IGNORE, FALSE, base);
        gwy_assert_floatval(volume, volume_expected, 1e-9*fabs(volume_expected));

        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 9
0
void
test_surface_set(void)
{
    enum { max_size = 255, niter = 40 };

    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        guint res = g_rand_int_range(rng, 1, max_size);
        GwySurface *surface = gwy_surface_new_sized(res);

        for (guint i = 0; i < res; i++) {
            GwyXYZ pt = { i, G_PI/(i + 1), -0.5*i*i };
            gwy_surface_set(surface, i, pt);
        }

        for (guint k = 0; k < res; k++) {
            GwyXYZ pt = gwy_surface_get(surface, k);
            g_assert_cmpfloat(pt.x, ==, k);
            g_assert_cmpfloat(pt.y, ==, G_PI/(k + 1));
            g_assert_cmpfloat(pt.z, ==, -0.5*k*k);
        }
        g_object_unref(surface);
    }

    g_rand_free(rng);
}
Ejemplo n.º 10
0
static void _random2_fill (AranSolver3d *solver)
{
  guint64 i;
  PointAccum *point;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i<np; i++)
    {

#ifdef VSG_HAVE_MPI
      if (i%_flush_interval == 0)
        {
          aran_solver3d_migrate_flush (solver);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %luth point\n", rk, i);

              aran_solver3d_distribute_contiguous_leaves (solver);
              _flush_interval *=2;
            }
        }
#endif /* VSG_HAVE_MPI */

      point->vector.x = g_rand_double_range (rand, -R, R);;
      point->vector.y = g_rand_double_range (rand, -R, R);;
      point->vector.z = g_rand_double_range (rand, -R, R);;
      point->density = 1./np;
      point->field = VSG_V3D_ZERO;
      point->id = i;

      /* if (i == 3) point->density = 0.; */
      /* if (i == 4) point->density = 0.; */
      /* if (i == 5) point->density = 0.; */

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver3d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %luth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver3d_migrate_flush (solver);
  aran_solver3d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
Ejemplo n.º 11
0
void
setup (void)
{
	factory = goo_ti_component_factory_get_instance ();
	component = goo_component_factory_get_component (factory, GOO_TI_H263_DECODER);
	rnd = g_rand_new_with_seed (time (0));

	return;
}
/* UV sphere fill */
static void _uvsphere_fill (AranSolver3d *solver)
{
  gint i;
  PointAccum *point;
  VsgVector3d lb, ub;
  GRand *rand = g_rand_new_with_seed (_random_seed);
  gdouble r;

  aran_solver3d_get_bounds (solver, &lb, &ub);
  r = MIN (lb.x, ub.x);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i< np; i++)
    {
      gdouble theta, phi;

      theta = g_rand_double_range (rand, 0.01 * G_PI, 0.99 * G_PI);
      phi = g_rand_double_range (rand, 0., 2.*G_PI);

      vsg_vector3d_from_spherical (&point->vector, r, theta, phi);
      point->density = 1.;
      point->field = VSG_V3D_ZERO;
      point->id = i;

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver3d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %dth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

#ifdef VSG_HAVE_MPI
      if (i%(_flush_interval*10) == 0)
        {
          if (_verbose && rk == 0)
            g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
          aran_solver3d_distribute_contiguous_leaves (solver);

          _flush_interval *=2;
        }
#endif /* VSG_HAVE_MPI */
    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver3d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
Ejemplo n.º 13
0
gboolean
gimp_operation_dissolve_mode_process_pixels (gfloat              *in,
                                             gfloat              *aux,
                                             gfloat              *mask,
                                             gfloat              *out,
                                             gfloat               opacity,
                                             glong                samples,
                                             const GeglRectangle *result,
                                             gint                 level)
{
  const gboolean has_mask = mask != NULL;
  gint           x, y;

  for (y = result->y; y < result->y + result->height; y++)
    {
      GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);

      /* fast forward through the rows pseudo random sequence */
      for (x = 0; x < result->x; x++)
        g_rand_int (gr);

      for (x = result->x; x < result->x + result->width; x++)
        {
          gfloat value = aux[ALPHA] * opacity * 255;

          if (has_mask)
            value *= *mask;

          if (g_rand_int_range (gr, 0, 255) >= value)
            {
              out[0] = in[0];
              out[1] = in[1];
              out[2] = in[2];
              out[3] = in[3];
            }
          else
            {
              out[0] = aux[0];
              out[1] = aux[1];
              out[2] = aux[2];
              out[3] = 1.0;
            }

          in   += 4;
          out  += 4;
          aux  += 4;

          if (has_mask)
            mask ++;
        }
      g_rand_free (gr);
    }

  return TRUE;
}
Ejemplo n.º 14
0
void
test_field_process_quarters_masked_noborder(void)
{
    enum { max_size = 15, niter = 100 };
    gdouble eps = 1e-12;
    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };
        GwyField *field = gwy_field_new_sized(xres, yres, FALSE);
        gboolean useallfunc = g_rand_boolean(rng);
        field_randomize(field, rng);
        GwyMaskField *mask = random_mask_field_prob(xres, yres, rng, 0.5);
        gdouble result = 0.0, result0 = 0.0, result1 = 0.0;
        gwy_field_process_quarters(field, &fpart, mask, GWY_MASK_IGNORE, FALSE,
                                   sum_quarters,
                                   useallfunc ? sum_allquarters : NULL,
                                   &result);
        gwy_field_process_quarters(field, &fpart, mask, GWY_MASK_EXCLUDE, FALSE,
                                   sum_quarters,
                                   useallfunc ? sum_allquarters : NULL,
                                   &result0);
        gwy_field_process_quarters(field, &fpart, mask, GWY_MASK_INCLUDE, FALSE,
                                   sum_quarters,
                                   useallfunc ? sum_allquarters : NULL,
                                   &result1);
        gdouble reference = 0.0, reference0 = 0.0, reference1 = 0.0;
        for (guint i = 0; i < height; i++) {
            for (guint j = 0; j < width; j++) {
                guint wh = (col + j > 0) + (col + j < xres-1);
                guint wv = (row + i > 0) + (row + i < yres-1);
                gdouble v = wh*wv*gwy_field_index(field, col + j, row + i);
                reference += v;
                if (gwy_mask_field_get(mask, col + j, row + i))
                    reference1 += v;
                else
                    reference0 += v;
            }
        }
        gwy_assert_floatval(result, reference, eps);
        gwy_assert_floatval(result0, reference0, eps);
        gwy_assert_floatval(result1, reference1, eps);

        g_object_unref(mask);
        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 15
0
END_TEST

START_TEST(test_atree_max_value)
{
    ATree *at;
    gint   result;
    gint   key_a;
    gint   data_a;
    gint   key_b;
    gint   data_b;
    gint  *max;
    GRand *random;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        random = g_rand_new_with_seed( (guint32) at );
        key_a  = g_rand_int( random );
        data_a = g_rand_int( random );
        key_b  = g_rand_int( random );
        data_b = g_rand_int( random );
        
        result = atree_insert( at, GINT_TO_POINTER(&key_a), GINT_TO_POINTER(&data_a) );
        ck_assert_int_eq( result, 0 );
        
        result = atree_insert( at, GINT_TO_POINTER(&key_b), GINT_TO_POINTER(&data_b) );
        ck_assert_int_eq( result, 0 );
        
        max    = atree_max_value( at );
        
        if (max == NULL)
        {
            ck_abort_msg ("maximum values is NULL\n");
        }
        else
        {   
            if (key_a > key_b)
            {
                ck_assert_int_eq( *max, data_a );
            }
            else
            {
                ck_assert_int_eq( *max, data_b );
            }
        }
        
        a_tree_destroy( at );
    }
}
static void _random_fill (AranSolver3d *solver)
{
  guint i;
  PointAccum *point;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  for (i=0; i<np; i++)
    {
      PointAccum tmp;

#ifdef VSG_HAVE_MPI
      if (i%_flush_interval == 0)
        {
          aran_solver3d_migrate_flush (solver);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);

              aran_solver3d_distribute_contiguous_leaves (solver);
              _flush_interval *=2;
            }
        }
#endif /* VSG_HAVE_MPI */

      tmp.vector.x = g_rand_double_range (rand, -R, R);;
      tmp.vector.y = g_rand_double_range (rand, -R, R);;
      tmp.vector.z = g_rand_double_range (rand, -R, R);;
      tmp.density = 1.;
      tmp.field = VSG_V3D_ZERO;
      tmp.id = i;

      if (check) memcpy (&check_points[i], &tmp, sizeof (PointAccum));

      if (i%sz != rk) continue;

      if (i % 10000 == 0 && _verbose)
        g_printerr ("%d: insert %dth point\n", rk, i);

      point = point_accum_alloc (TRUE, NULL);

      memcpy (point, &tmp, sizeof (PointAccum));

      aran_solver3d_insert_point (solver, point);
    }

#ifdef VSG_HAVE_MPI
  aran_solver3d_migrate_flush (solver);
  aran_solver3d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
Ejemplo n.º 17
0
void _random_fill (VsgPRTree2d *tree, guint np)
{
  gint i;
  Pt *pt;
  VsgVector2d lb, ub;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  vsg_prtree2d_get_bounds (tree, &lb, &ub);

  _ref_count = 0;

  for (i=0; i< np; i++)
    {
      gdouble x1, y1;
      gint c;

      x1 = g_rand_double_range (rand, lb.x, ub.x);
      y1 = g_rand_double_range (rand, lb.y, ub.y);

      c = i+1;

      _ref_count += c;

      if (i%_flush_interval == 0)
        {
          vsg_prtree2d_migrate_flush (tree);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
              _distribute (tree);
            }
        }

      if (i%sz != rk) continue;

      if (i % 10000 == 0 && _verbose)
        g_printerr ("%d: insert %dth point\n", rk, i);

      pt = pt_alloc (TRUE, NULL);
      pt->vector.x = x1;
      pt->vector.y = y1;
      pt->weight = c;

      vsg_prtree2d_insert_point (tree, pt);
    }

  vsg_prtree2d_migrate_flush (tree);

  _distribute (tree);

  g_rand_free (rand);
}
Ejemplo n.º 18
0
static void random_fill (VsgPRTree3d *tree, guint np)
{
  gint i;
  VsgVector3d *pt;
  Sphere *c;
  VsgVector3d lb, ub;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  vsg_prtree3d_get_bounds (tree, &lb, &ub);

  for (i=0; i< np; i++)
    {
      gdouble x1, x2, y1, y2, z1, z2, r;

      x1 = g_rand_double_range (rand, lb.x, ub.x);
      y1 = g_rand_double_range (rand, lb.y, ub.y);
      z1 = g_rand_double_range (rand, lb.z, ub.z);
      x2 = g_rand_double_range (rand, lb.x, ub.x);
      y2 = g_rand_double_range (rand, lb.y, ub.y);
      z2 = g_rand_double_range (rand, lb.z, ub.z);
      r = g_rand_double_range (rand, 0., 0.1);

      if (i%_flush_interval == 0) vsg_prtree3d_migrate_flush (tree);

      if (i%sz != rk) continue;

      if (i % 10000 == 0 && _verbose) g_printerr ("%d: insert %dth point\n", rk, i);

      pt = pt_alloc (TRUE, NULL);
      pt->x = x1;
      pt->y = y1;
      pt->z = z1;
      vsg_prtree3d_insert_point (tree, pt);

      if (_put_regions)
        {
          c = rg_alloc (TRUE, NULL);
          c->center.x = x2;
          c->center.y = y2;
          c->center.z = z2;
          c->radius = r;
          vsg_prtree3d_insert_region (tree, c);
        }
/*       g_printerr ("%d: %d\n", rk, i); */
    }

  vsg_prtree3d_migrate_flush (tree);

  g_rand_free (rand);
}
char get_rand_ascii_print(void) {

   GRand *rand ;

   struct timeval tv ;

   gettimeofday(&tv, NULL) ;

   g_usleep(tv.tv_usec % 256) ;

   rand = g_rand_new_with_seed((guint32) tv.tv_usec);

   return  (char) ((g_rand_int(rand) % 26) + 97) ;

}
Ejemplo n.º 20
0
void
field_volume_masked_one(GwyFieldVolumeMethod method)
{
    enum { max_size = 76 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 50;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        GwyField *field = gwy_field_new_sized(xres, yres, FALSE);

        field_randomize(field, rng);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };

        GwyMaskField *mask = random_mask_field(xres, yres, rng);

        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        gdouble volume_include, volume_exclude, volume_ignore;
        volume_include = gwy_field_volume(field, &fpart,
                                          mask, GWY_MASK_INCLUDE, method);
        volume_exclude = gwy_field_volume(field, &fpart,
                                          mask, GWY_MASK_EXCLUDE, method);
        volume_ignore = gwy_field_volume(field, &fpart,
                                         mask, GWY_MASK_IGNORE, method);
        gwy_assert_floatval(volume_include + volume_exclude, volume_ignore,
                            1e-9*volume_ignore);

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        volume_include = gwy_field_volume(field, &fpart,
                                          mask, GWY_MASK_INCLUDE, method);
        volume_exclude = gwy_field_volume(field, &fpart,
                                          mask, GWY_MASK_EXCLUDE, method);
        volume_ignore = gwy_field_volume(field, &fpart,
                                         mask, GWY_MASK_IGNORE, method);
        gwy_assert_floatval(volume_include + volume_exclude, volume_ignore,
                            1e-9*volume_ignore);
        g_object_unref(mask);
        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 21
0
int SSproblem_definition(
    SS *problem,
    int b1,
    int b2,
    double timelimit,
    int combine_method,
    int njobs,
    int nmachines,
    Job *jobarray,
    int lowerbound) {
    int i, val         = 0;
    REFSET *temp_rs = NULL;
    P *temp_p       = NULL;
    /*initialize scatter search data structure */
    SS_init(problem, b1, b2, timelimit);
    problem->combine_method = combine_method;
    problem->nmachines = nmachines;
    problem->njobs = njobs;
    problem->lowerbound = lowerbound;
    problem->upperbound = INT_MAX;
    /* Initialize pool */
    problem->p = CC_SAFE_MALLOC(1, P);
    CCcheck_NULL_2(problem->p, "Failed to allocate memory to problem->p");
    temp_p  = problem->p;
    P_init(temp_p);
    /* Initialize refset */
    problem->rs         = CC_SAFE_MALLOC(1, REFSET);
    CCcheck_NULL_2(problem->rs, "Failed to allocate memory to problem->rs");
    temp_rs             = problem->rs;
    REFSET_init(temp_rs);
    /* Initialize Jobarray of scatter search data structure */
    problem->jobarray = CC_SAFE_MALLOC(njobs, Job *);
    CCcheck_NULL_2(problem->jobarray, "Failed to allocate memory");

    for (i = 0; i < njobs; i++) {
        problem->jobarray[i] = jobarray + i ;
    }

    problem->random = g_rand_new_with_seed(48654642);
    CCcheck_NULL_2(problem->random, "Failed in g_rand_new_with_seed");
CLEAN:

    if (val) {
        SS_free(problem);
    }

    return val;
}
Ejemplo n.º 22
0
void
test_field_surface_area_masked(void)
{
    enum { max_size = 76 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 50;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        GwyField *field = gwy_field_new_sized(xres, yres, FALSE);

        field_randomize(field, rng);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };

        GwyMaskField *mask = random_mask_field(xres, yres, rng);

        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        gdouble area_include, area_exclude, area_ignore;
        area_include = gwy_field_surface_area(field, &fpart,
                                              mask, GWY_MASK_INCLUDE);
        area_exclude = gwy_field_surface_area(field, &fpart,
                                              mask, GWY_MASK_EXCLUDE);
        area_ignore = gwy_field_surface_area(field, &fpart,
                                             mask, GWY_MASK_IGNORE);
        g_assert_cmpfloat(fabs(area_include + area_exclude
                               - area_ignore)/area_ignore, <=, 1e-9);

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        area_include = gwy_field_surface_area(field, &fpart,
                                              mask, GWY_MASK_INCLUDE);
        area_exclude = gwy_field_surface_area(field, &fpart,
                                              mask, GWY_MASK_EXCLUDE);
        area_ignore = gwy_field_surface_area(field, &fpart,
                                             mask, GWY_MASK_IGNORE);
        g_assert_cmpfloat(fabs(area_include + area_exclude
                               - area_ignore)/area_ignore, <=, 1e-9);
        g_object_unref(mask);
        g_object_unref(field);
    }
    g_rand_free(rng);
}
Ejemplo n.º 23
0
void
test_field_mean(void)
{
    enum { max_size = 76 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 50;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        gdouble alpha = g_rand_double_range(rng, -5.0, 5.0);
        gdouble beta = g_rand_double_range(rng, -5.0, 5.0);
        GwyField *field = field_make_planar(xres, yres, alpha, beta);

        gdouble mean, mean_expected;
        mean = gwy_field_mean_full(field);
        mean_expected = 0.5*(alpha + beta);
        gwy_assert_floatval(mean, mean_expected, 1e-9*fabs(mean_expected));

        field_randomize(field, rng);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };

        GwyMaskField *mask = random_mask_field(xres, yres, rng);
        guint m = gwy_mask_field_part_count(mask, &fpart, TRUE);
        guint n = gwy_mask_field_part_count(mask, &fpart, FALSE);
        gdouble mean_include = gwy_field_mean(field, &fpart,
                                              mask, GWY_MASK_INCLUDE);
        gdouble mean_exclude = gwy_field_mean(field, &fpart,
                                              mask, GWY_MASK_EXCLUDE);
        gdouble mean_ignore = gwy_field_mean(field, &fpart,
                                             mask, GWY_MASK_IGNORE);

        if (isnan(mean_include)) {
            g_assert_cmpuint(m, ==, 0);
            gwy_assert_floatval(mean_exclude, mean_ignore,
                                1e-9*fabs(mean_ignore));
        }
        else if (isnan(mean_exclude)) {
            g_assert_cmpuint(n, ==, 0);
            gwy_assert_floatval(mean_include, mean_ignore,
                                1e-9*fabs(mean_ignore));
        }
        else {
Ejemplo n.º 24
0
static void
_zmq2agent_worker (struct _zmq2agent_ctx_s *ctx)
{
	/* XXX(jfs): a dedicated PRNG avoids locking the glib's PRNG for each call
	   (such global locks are present in the GLib) and opening it with a seed
	   from the glib's PRNG avoids syscalls to the special file /dev/urandom */
	GRand *r = g_rand_new_with_seed (g_random_int ());

	gint64 last_debug = oio_ext_monotonic_time ();

	zmq_pollitem_t pi[2] = {
		{ctx->zpull, -1, ZMQ_POLLIN, 0},
		{ctx->zagent, -1, ZMQ_POLLIN, 0},
	};

	for (gboolean run = TRUE; run ;) {
		int rc = zmq_poll (pi, 2, 1000);
		if (rc < 0) {
			int err = zmq_errno();
			if (err != ETERM && err != EINTR)
				GRID_WARN("ZMQ poll error : (%d) %s", err, zmq_strerror(err));
			if (err != EINTR)
				break;
		}
		if (pi[1].revents)
			_zmq2agent_receive_acks (ctx);
		_retry_events (ctx);
		if (pi[0].revents)
			run = _zmq2agent_receive_events (r, ctx);

		/* Periodically write stats in the log */
		gint64 now = oio_ext_monotonic_time ();
		if ((now - last_debug) > 2 * G_TIME_SPAN_MINUTE) {
			GRID_INFO("ZMQ2AGENT recv=%"G_GINT64_FORMAT" sent=%"G_GINT64_FORMAT
					" ack=%"G_GINT64_FORMAT"+%"G_GINT64_FORMAT" queue=%u",
					ctx->q->counter_received, ctx->q->counter_sent,
					ctx->q->counter_ack, ctx->q->counter_ack_notfound,
					ctx->q->gauge_pending);
			last_debug = now;
		}
	}

	g_rand_free (r);
	GRID_INFO ("Thread stopping [NOTIFY-ZMQ2AGENT]");
}
Ejemplo n.º 25
0
static GstStateChangeReturn
gst_rnd_buffer_size_change_state (GstElement * element,
    GstStateChange transition)
{
  GstRndBufferSize *self = GST_RND_BUFFER_SIZE (element);
  GstStateChangeReturn ret;

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      break;
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      self->offset = 0;
      if (!self->rand) {
        self->rand = g_rand_new_with_seed (self->seed);
      }
      break;
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
      break;
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      if (self->rand) {
        g_rand_free (self->rand);
        self->rand = NULL;
      }
      break;
    case GST_STATE_CHANGE_READY_TO_NULL:
      if (self->adapter) {
        g_object_unref (self->adapter);
        self->adapter = NULL;
      }
      break;
    default:
      break;
  }

  return ret;
}
Ejemplo n.º 26
0
static gboolean
on_window_draw (GtkWidget *widget,
                cairo_t   *cr)

{
  GRand *rand = g_rand_new_with_seed(0);
  int i;
  int width, height;

  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  ensure_resources (cairo_get_target (cr));

  cairo_set_source_rgb(cr, 1, 1, 1);
  cairo_paint(cr);

  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_set_line_width(cr, 1.0);
  cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
  cairo_stroke (cr);

  for(i = 0; i < load_factor * 150; i++)
    {
      int source = g_rand_int_range(rand, 0, 255);
      double phi = g_rand_double_range(rand, 0, 2 * M_PI) + angle;
      double r = g_rand_double_range(rand, 0, width / 2 - RADIUS);
      int x, y;

      int source_x = (source % 16) * DIAMETER;
      int source_y = (source / 16) * DIAMETER;

      x = round(width / 2 + r * cos(phi) - RADIUS);
      y = round(height / 2 - r * sin(phi) - RADIUS);

      cairo_set_source_surface(cr, source_surface,
                               x - source_x, y - source_y);
      cairo_rectangle(cr, x, y, DIAMETER, DIAMETER);
      cairo_fill(cr);
    }

  g_rand_free(rand);

  return FALSE;
}
Ejemplo n.º 27
0
static void
on_monitors_changed (MetaScreen *screen,
                     MetaPlugin *plugin)
{
  MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin);
  int i, n;
  GRand *rand = g_rand_new_with_seed (123456);

  clutter_actor_destroy_all_children (self->priv->background_group);

  n = meta_screen_get_n_monitors (screen);
  for (i = 0; i < n; i++)
    {
      MetaRectangle rect;
      ClutterActor *background_actor;
      MetaBackground *background;
      ClutterColor color;

      meta_screen_get_monitor_geometry (screen, i, &rect);

      background_actor = meta_background_actor_new (screen, i);

      clutter_actor_set_position (background_actor, rect.x, rect.y);
      clutter_actor_set_size (background_actor, rect.width, rect.height);

      /* Don't use rand() here, mesa calls srand() internally when
         parsing the driconf XML, but it's nice if the colors are
         reproducible.
      */
      clutter_color_init (&color,
                          g_rand_int_range (rand, 0, 255),
                          g_rand_int_range (rand, 0, 255),
                          g_rand_int_range (rand, 0, 255),
                          255);

      background = meta_background_new (screen);
      meta_background_set_color (background, &color);
      meta_background_actor_set_background (META_BACKGROUND_ACTOR (background_actor), background);
      g_object_unref (background);

      clutter_actor_add_child (self->priv->background_group, background_actor);
    }

  g_rand_free (rand);
}
Ejemplo n.º 28
0
void
test_field_part_intersect(void)
{
    enum { max_size = 40, niter = 500, n = 10000 };
    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        GwyFieldPart result = {
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
        };
        GwyFieldPart otherpart = {
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
        };
        GwyFieldPart fpart = result;
        gboolean intersecting = gwy_field_part_intersect(&result, &otherpart);

        for (guint k = 0; k < n; k++) {
            guint j = g_rand_int_range(rng, 0, 2*max_size);
            guint i = g_rand_int_range(rng, 0, 2*max_size);
            gboolean in_fpart = (j >= fpart.col
                                 && j - fpart.col < fpart.width
                                 && i >= fpart.row
                                 && i - fpart.row < fpart.height);
            gboolean in_otherpart = (j >= otherpart.col
                                     && j - otherpart.col < otherpart.width
                                     && i >= otherpart.row
                                     && i - otherpart.row < otherpart.height);
            gboolean in_result = (j >= result.col
                                  && j - result.col < result.width
                                  && i >= result.row
                                  && i - result.row < result.height);

            g_assert_cmpuint(in_result, ==, in_fpart && in_otherpart);
            g_assert(intersecting || !in_result);
        }
    }

    g_rand_free(rng);
}
Ejemplo n.º 29
0
void
test_field_part_union(void)
{
    enum { max_size = 40, niter = 500, n = 10000 };
    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        GwyFieldPart result = {
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
        };
        GwyFieldPart otherpart = {
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
            g_rand_int_range(rng, 0, max_size),
        };
        GwyFieldPart fpart = result;
        gwy_field_part_union(&result, &otherpart);

        for (guint k = 0; k < n; k++) {
            guint j = g_rand_int_range(rng, 0, 2*max_size);
            guint i = g_rand_int_range(rng, 0, 2*max_size);
            gboolean in_x = ((j >= fpart.col
                              || j >= otherpart.col)
                             && (j < fpart.col + fpart.width
                                 || j < otherpart.col + otherpart.width));
            gboolean in_y = ((i >= fpart.row
                              || i >= otherpart.row)
                             && (i < fpart.row + fpart.height
                                 || i < otherpart.row + otherpart.height));
            gboolean in_result = (j >= result.col
                                  && j - result.col < result.width
                                  && i >= result.row
                                  && i - result.row < result.height);

            g_assert_cmpuint(in_result, ==, in_x && in_y);
        }
    }

    g_rand_free(rng);
}
Ejemplo n.º 30
0
BMI_Model *
avulsion_set_variance (BMI_Model * self, double variance)
{
  BMI_Model *p = (BMI_Model *) self;
  p->variance = variance;

  {
    Sed_riv r = sed_cube_borrow_nth_river (p->p, 0);
    Avulsion_st* data;

    data = avulsion_new (
             (p->seed==0)?g_rand_new():g_rand_new_with_seed(p->seed),
             variance);
    eh_require (data);
    sed_river_set_avulsion_data (r, data);
    //sed_river_avulsion_data (r)->std_dev = variance;
  }
  return self;
}