Ejemplo n.º 1
0
/* Resets the state for all the aggregate functions. */
static void
initialize_aggregate_info (struct agr_proc *agr)
{
  struct agr_var *iter;

  for (iter = agr->agr_vars; iter; iter = iter->next)
    {
      iter->saw_missing = false;
      iter->dbl[0] = iter->dbl[1] = iter->dbl[2] = 0.0;
      iter->int1 = iter->int2 = 0;
      switch (iter->function)
	{
	case MIN:
	  iter->dbl[0] = DBL_MAX;
	  break;
	case MIN | FSTRING:
	  memset (iter->string, 255, var_get_width (iter->src));
	  break;
	case MAX:
	  iter->dbl[0] = -DBL_MAX;
	  break;
	case MAX | FSTRING:
	  memset (iter->string, 0, var_get_width (iter->src));
	  break;
	case MEDIAN:
	  {
            struct caseproto *proto;
            struct subcase ordering;

            proto = caseproto_create ();
            proto = caseproto_add_width (proto, 0);
            proto = caseproto_add_width (proto, 0);

	    if ( ! iter->subject)
	      iter->subject = dict_create_internal_var (0, 0);

	    if ( ! iter->weight)
	      iter->weight = dict_create_internal_var (1, 0);

            subcase_init_var (&ordering, iter->subject, SC_ASCEND);
	    iter->writer = sort_create_writer (&ordering, proto);
            subcase_destroy (&ordering);
            caseproto_unref (proto);

	    iter->cc = 0;
	  }
	  break;
        case SD:
          if (iter->moments == NULL)
            iter->moments = moments1_create (MOMENT_VARIANCE);
          else
            moments1_clear (iter->moments);
          break;
        default:
          break;
	}
    }
}
Ejemplo n.º 2
0
/* Initializes one-pass moments M for calculating moment
   MAX_MOMENT and lower moments. */
static void
init_moments1 (struct moments1 *m, enum moment max_moment)
{
  assert (m != NULL);
  assert (max_moment == MOMENT_MEAN || max_moment == MOMENT_VARIANCE
          || max_moment == MOMENT_SKEWNESS || max_moment == MOMENT_KURTOSIS);
  m->max_moment = max_moment;
  moments1_clear (m);
}