Exemplo n.º 1
0
int AllSubsetsMetaAnalysis(gsl_vector * esVector, gsl_vector * varVector,
	gsl_vector * metaResultsVector, ST_uint4 from, ST_uint4 to ) {
	ST_retcode	rc;
	ST_uint4 	i, nStudies;
	ST_long		j, nSubsets;
	char 		buf[80];
	
	gsl_combination * comb;

	nStudies = esVector->size;
	nSubsets = gsl_pow_int(2, nStudies)-1 ;


	j=1;
	//for(i=1; i <= nStudies; i++) { 
	for(i=from; i <= to; i++) {
		comb = 	gsl_combination_calloc(nStudies, i);
		
		do { 
			if(j == nSubsets+1) {
				snprintf(buf, 80,"combLength %u Obs %u\n",i,  j);
				SF_error(buf);
				SF_error("Exceeded the maximum number of subsets!!!\n");
				return(-2);
			}
			if ((rc = MetaAnalysis(esVector, varVector, metaResultsVector, comb) )) return(rc);
			if ((rc = WriteOut(metaResultsVector, j, comb) )) return(rc);
			j += 1;
		} while (gsl_combination_next(comb) == GSL_SUCCESS);
	}

	gsl_combination_free(comb);
	return(0);
}
Exemplo n.º 2
0
static void GslComb_free(CTX ctx, kRawPtr *po)
{
	if (po->rawptr != NULL) {
		gsl_combination_free((gsl_combination *)po->rawptr);
		po->rawptr = NULL;
	}
}
Exemplo n.º 3
0
int 
main (void)
{
  size_t i, j;
  int status = 0;
  gsl_combination * c ;

  c = gsl_combination_alloc (6,3);

  gsl_combination_init_first (c);
  
  i = 0;

  do 
    {
      if ( i >= 20 )
        {
	  status = 1;
          break;
	}
      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }
      i++;
    }
  while (gsl_combination_next(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_combination_next, 6 choose 3 combination, 20 steps");

  gsl_combination_next(c);
  gsl_combination_next(c);
  gsl_combination_next(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[19][j]);
    }
  gsl_test(status, "gsl_combination_next on the last combination");


  gsl_combination_init_last (c);

  i = 20;
  do 
    {
      if ( i == 0 )
        {
	  status = 1;
          break;
	}

      i--;

      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }
    }
  while (gsl_combination_prev(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_combination_prev, 6 choose 3 combination, 20 steps");

  gsl_combination_prev(c);
  gsl_combination_prev(c);
  gsl_combination_prev(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[0][j]);
    }
  gsl_test(status, "gsl_combination_prev on the first combination");
  gsl_combination_free (c);

  c = gsl_combination_calloc(7, 0);
  /* should return GSL_FAILURE every time */
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  gsl_test(status, "gsl_combination 7 choose 0");
  gsl_combination_free (c);

  c = gsl_combination_calloc(7, 7);
  /* should return GSL_FAILURE every time */
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  gsl_test(status, "gsl_combination 7 choose 7");
  gsl_combination_free (c);

  exit (gsl_test_summary());
}
Exemplo n.º 4
0
Arquivo: test.c Projeto: lemahdi/mglib
int 
main (void)
{
  size_t i, j;
  int status = 0, s;
  gsl_combination * c ;

  gsl_ieee_env_setup ();

  c = gsl_combination_alloc (6,3);

  /* Test combinations in forward order */

  gsl_combination_init_first (c);
  
  i = 0;

  do 
    {
      if ( i >= 20 )
        {
          status = 1;
          break;
        }
      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }

      {
        int s1 = gsl_combination_valid (c);
        gsl_test (s1, "gsl_combination_valid (%u)", i);
      }

      i++;
    }
  while (gsl_combination_next(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_combination_next, 6 choose 3 combination, 20 steps");

  gsl_combination_next(c);
  gsl_combination_next(c);
  gsl_combination_next(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[19][j]);
    }
  gsl_test(status, "gsl_combination_next on the last combination");

  {
    int s1 = gsl_combination_valid (c);
    gsl_test (s1, "gsl_combination_valid on the last combination");
  }

  {
    gsl_combination * d = gsl_combination_alloc (6,3);
    gsl_combination_memcpy (d, c);

    status = 0;

    for (j = 0; j < 3; j++)
      {
        status |= (d->data[j] != c->data[j]);
      }

    gsl_test (status, "gsl_combination_memcpy, 6 choose 3 combination");
    gsl_combination_free(d);
  }


  /* Now test combinations in reverse order */

  gsl_combination_init_last (c);

  i = 20;
  do 
    {
      if ( i == 0 )
        {
          status = 1;
          break;
        }

      i--;

      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }

      {
        int s1 = gsl_combination_valid (c);
        gsl_test (s1, "gsl_combination_valid (%u)", i);
      }
    }
  while (gsl_combination_prev(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_combination_prev, 6 choose 3 combination, 20 steps");

  gsl_combination_prev(c);
  gsl_combination_prev(c);
  gsl_combination_prev(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[0][j]);
    }
  gsl_test(status, "gsl_combination_prev on the first combination");

  {
    int s1 = gsl_combination_valid (c);
    gsl_test (s1, "gsl_combination_valid on the first combination");
  }

  {
    gsl_combination * d = gsl_combination_alloc (6,3);
    gsl_combination_memcpy (d, c);

    status = 0;

    for (j = 0; j < 3; j++)
      {
        status |= (d->data[j] != c->data[j]);
      }

    gsl_test (status, "gsl_combination_memcpy, 6 choose 3 combination");
    gsl_combination_free(d);
  }

  gsl_combination_free (c);

  c = gsl_combination_calloc(7, 0);
  /* should return GSL_FAILURE every time */
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  gsl_test(status, "gsl_combination 7 choose 0");
  gsl_combination_free (c);

  c = gsl_combination_calloc(7, 7);
  /* should return GSL_FAILURE every time */
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_next(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  status |= (gsl_combination_prev(c) != GSL_FAILURE);
  for(j = 0; j < 7; j++)
  {
    status |= (gsl_combination_get(c, j) != j);
  }
  gsl_test(status, "gsl_combination 7 choose 7");
  gsl_combination_free (c);

  c = gsl_combination_calloc(6, 3);

  gsl_set_error_handler (&my_error_handler);

  c->data[0] = 1;
  c->data[1] = 1;
  c->data[2] = 2;
  s = gsl_combination_valid (c);
  gsl_test (!s, "gsl_combination_valid on an invalid combination (1,1,2)");

  c->data[0] = 2;
  c->data[1] = 1;
  c->data[2] = 0;
  s = gsl_combination_valid (c);
  gsl_test (!s, "gsl_combination_valid on an invalid combination (2,1,0)");

  c->data[0] = 1;
  c->data[1] = 2;
  c->data[2] = 0;
  s = gsl_combination_valid (c);
  gsl_test (!s, "gsl_combination_valid on an invalid combination (1,2,0)");

  {
    gsl_combination * d = gsl_combination_alloc (6,4);
    int s = gsl_combination_memcpy (d, c);
    gsl_test (!s, "gsl_combination_memcpy, (6,4) vs (6,3)");
    gsl_combination_free(d);
  }

  {
    gsl_combination * d = gsl_combination_alloc (7,3);
    int s = gsl_combination_memcpy (d, c);
    gsl_test (!s, "gsl_combination_memcpy, (7,3) vs (6,3)");
    gsl_combination_free(d);
  }

  {
    gsl_combination * d = gsl_combination_alloc (7,2);
    int s = gsl_combination_memcpy (d, c);
    gsl_test (!s, "gsl_combination_memcpy, (7,2) vs (6,3)");
    gsl_combination_free(d);
  }


  gsl_combination_free (c);

  exit (gsl_test_summary());
}