Пример #1
0
int compareSections(std::shared_ptr<OsmAnd::RoutePlannerContext::RoutingSubsectionContext> o1,
                    std::shared_ptr<OsmAnd::RoutePlannerContext::RoutingSubsectionContext> o2) {
    int v1 = (o1->getAccessCounter() + 1) * intpow(10, o1->getLoadsCounter() -1);
    int v2 = (o2->getAccessCounter() + 1) * intpow(10, o1->getLoadsCounter() -1);
    //return v1 < v2 ? -1 : (v1 == v2 ? 0 : 1);
    return v1 < v2;
}
Пример #2
0
int main() {
    printf("Please enter your x value: ");
    int x;
    scanf("%d", &x);

    int answer = (3 * intpow(x, 5)) + (2 * intpow(x, 4)) - (5 * intpow(x, 3))
                 - intpow(x, 3) + (7 * x) - 6;
    printf("\nAnswer: %d\n", answer);

    return 0;
}
inline float diff_Weickert
(
	float s2,
	float lambda
)
{
	return s2==0.0f ? 1.0f : 1.0f-expf(-3.31488/intpow(s2/(lambda*lambda),4));
}
Пример #4
0
//a function for computing powers of integers
unsigned long int intpow(int x, int p)
{
  if (p == 0) return 1;
  if (p == 1) return x;

  unsigned long int tmp = intpow(x, p/2);
  if (p%2 == 0) return tmp * tmp;
  else return x * tmp * tmp;
}
Пример #5
0
/* Working from the finest lattice, smear the links at each level of
   coarseness and multiply to form the links on the next higher
   level.  Results in rg_link. */
void RG_gauge(QDP_ColorMatrix *rg_link[NRG][RG_Nd], 
	      QDP_ColorMatrix *link_qdp[RG_Nd], 
	      QDP_Sub_Block s[NRG+1])
{
  int i,j,len;
  QDP_ColorMatrix *pr_sm_link[RG_Nd];
  
  // node0_printf("Smearing links with Degrand trick........\n"); fflush(stdout);
  
  for(i=0; i< RG_Nd; ++i)
    pr_sm_link[i] = QDP_create_M();
  
  
#ifdef CHECK_DEGRAND_WO_SMEAR
  for(i=0; i< RG_Nd; ++i)
    SQDP_M_eq_M(rg_link[nrg-1][i],link_qdp[i],s[nrg]);
#else
  RG_smearing(rg_link[nrg-1],link_qdp,s[nrg],1);
#ifdef CHECK_DEGRAND_W_SMEAR
  SQDP_M_eq_M(rg_link[nrg-1][3],link_qdp[3],s[nrg]);
#endif
#endif
  
  
  /* Work from the finest to the coarsest level */
  for (i=1;i<nrg;i++)
    {
      len = intpow(2,i-1);
      
      //  printf("node %d: Smear links of length %d x a'\n",this_node,len); fflush(stdout);
      //  printf("node %d: rg_links of length %d x a'\n",this_node,2*len); fflush(stdout);
      
      /* Smear the links */
#ifdef CHECK_DEGRAND_WO_SMEAR
      for(j=0; j< RG_Nd; ++j)
	SQDP_M_eq_M(pr_sm_link[j],rg_link[nrg-i][j],s[nrg-i+1]);
#else
      RG_smearing(pr_sm_link,rg_link[nrg-i],s[nrg-i+1],len);
#ifdef CHECK_DEGRAND_W_SMEAR
      SQDP_M_eq_M(pr_sm_link[3],rg_link[nrg-i][3],s[nrg-i+1]);
#endif
#endif
      
      /* Multiply the links */
      RG_create_gauge(rg_link[nrg-i-1],pr_sm_link,s[nrg-i],len);
    }
  
  
  //  node0_printf(".......................done\n"); fflush(stdout);
  for(i=0; i< RG_Nd; ++i)
    QDP_destroy_M(pr_sm_link[i]);

return;

}
Пример #6
0
int main() {
  // confirm intpow
  printf("2^0 = %ld; 2^1 = %ld; 2^2 = %ld; 2^3 = %ld; 2^5 = %ld; 2^8 = %ld;\n", intpow(2,0), intpow(2,1), intpow(2,2), intpow(2,3), intpow(2,5), intpow(2,8));

  // confirm minimum
  printf("Minimum of 1, 4, -8, 1, 2 is: %d (-8)\n", minimum(5, 1, 4, -8, 1, 2));
  // confirm maximum  
  printf("Maximum of 1, 4, -8, 1, 2 is: %d (4)\n", maximum(5, 1, 4, -8, 1, 2));
    // confirm maximum  
  printf("Maximum of 1 is: %d (1)\n", maximum(1, 1));

  return 0;
}
Пример #7
0
/**
 * fpllstring: Floating point lat/lon to string.
 */
void fpllstring(float ll, int digits, char *s)
{
	long int ipart = ll;
	long int fpart = fabs((ll - ipart) * intpow(10, digits - 1));
	my_itoa(ipart, s);
	strcat(s, ".");
	my_itoa(fpart, temp_buff);
	// pad out if less than 10^d.
	int pad = digits - strlen(temp_buff);
	while(pad > 0)
	{
		strcat(s, "0");
		pad--;
	}
	strcat(s, temp_buff);
}
Пример #8
0
void RadixSort::SortBits (int bits)
{
	// pass current bit shift to the shader programs
	glProgramUniform1i (counting.get (), counting_bitshift, bits);
	glProgramUniform1i (globalsort.get (), globalsort_bitshift, bits);

	// set buffer bindings
	{
		GLuint bufs[4] = { buffer, prefixsums, blocksums.front (), result };
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 4, bufs);
	}

	// counting
	counting.Use ();
	glDispatchCompute (numblocks, 1, 1);
	glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);

	// create block sums level by level
	blockscan.Use ();
	uint32_t numblocksums = (4 * numblocks) / blocksize;
	for (int i = 0; i < blocksums.size () - 1; i++)
	{
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, &blocksums[i]);
		glDispatchCompute (numblocksums > 0 ? numblocksums : 1, 1, 1);
		numblocksums /= blocksize;
		glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
	}

	// add block sums level by level (in reversed order)
	addblocksum.Use ();
	for (int i = blocksums.size () - 3; i >= 0; i--)
	{
		uint32_t numblocksums = (4 * numblocks) / intpow (blocksize, i + 1);
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, &blocksums[i]);
		glDispatchCompute (numblocksums > 0 ? numblocksums : 1, 1, 1);
		glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
	}

	// map values to their global position in the output buffer
	{
		GLuint bufs[2] = { buffer, prefixsums };
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, bufs);
	}
	globalsort.Use ();
	glDispatchCompute (numblocks, 1, 1);
	glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
}
Пример #9
0
void parse_ss (BNTree *bntree, char *ss_filename, char **tuple_arr, 
	       double *count_arr, double *background_probs) {
  char nseqs_str[STRLEN], 
    length_str[STRLEN], 
    tuple_size_str[STRLEN], 
    ntuples_str[STRLEN],
    names_str[STRLEN], 
    alphabet_str[STRLEN], 
    ncats_str[STRLEN];
  int i, j, k;
  int num_tuples;
  int tuple_size;
  int num_seqs;
  double background_total;
  FILE *fp;

  fp = fopen(ss_filename, "r");
  fscanf (fp, "NSEQS = %s\n", nseqs_str);
  fscanf (fp, "LENGTH = %s\n", length_str);
  fscanf (fp, "TUPLE_SIZE = %s\n", tuple_size_str);
  fscanf (fp, "NTUPLES = %s\n", ntuples_str);
  fscanf (fp, "NAMES = %s\n", names_str);
  fscanf (fp, "ALPHABET = %s\n", alphabet_str);
  fscanf (fp, "NCATS = %s\n", ncats_str);

  num_tuples = atoi (ntuples_str);
  tuple_size = atoi (tuple_size_str);
  num_seqs = atoi (nseqs_str);

  if (tuple_size != bntree->order + 1) {
    printf ("Error, model order is %d but tuple size is %d\n", bntree->order, tuple_size);
    exit (-1);
  }
 
  for (i=0; i<bntree->num_states; i++)
    background_probs[i] = 0;

  for (i=0; i<num_tuples; i++) {
    if (fscanf (fp, "%*d\t%[ACGT_. ]\t%lf\n", tuple_arr[i], &(count_arr[i])) != 2) {
      fprintf (stderr, "Could not read tuple and count for tuple number %d\n", i);
      exit (-1);
    }

    for (j=0; j<num_seqs; j++) {
      char state[STRLEN];
      int state_num;

      for (k=0; k<tuple_size; k++) {
	state[k] = tuple_arr[i][k * (num_seqs + 1) + j];
      }
      state[tuple_size] = '\0';
      state_num = 0;
      for (k=0; k<tuple_size; k++)
	state_num += intpow (ALPHABET_SIZE, (tuple_size - k - 1)) * bntree->symbol_map[(int)state[k]];
      background_probs[state_num] += count_arr[i];
    }
  }

  fclose (fp);

  /* normalize the background prob distribution */
  background_total = 0;
  for (i=0; i<bntree->num_states; i++)
    background_total += background_probs[i];

  for (i=0; i<bntree->num_states; i++)
    background_probs[i] /= background_total;
}
Пример #10
0
#ifdef EEFFT_TIMMING
#include <sys/time.h>
#endif

#define sa16 static __attribute__ ((aligned(16)))

float sa16 PNNN[4] = {-1.0, -1.0, -1.0,  1.0};
float sa16 NPNP[4] = { 1.0, -1.0,  1.0, -1.0};
float sa16 PNNP[4] = { 1.0, -1.0, -1.0,  1.0};
float sa16 NNPP[4] = { 1.0,  1.0, -1.0, -1.0};
float sa16 NPNN[4] = {-1.0, -1.0,  1.0, -1.0};
float sa16 PPNP[4] = { 1.0, -1.0,  1.0,  1.0};
float sa16 PPPN[4] = {-1.0,  1.0,  1.0,  1.0};
float sa16 VECN[4];

float sa16 buf_re[intpow(21)];
float sa16 buf_im[intpow(21)];

#define make_w(power) \
    float sa16 w_##power##_re[intpow(power) / 4]; \
    float sa16 w_##power##_im[intpow(power) / 4]; \
    float sa16 w_##power##_3re[intpow(power) / 4]; \
    float sa16 w_##power##_3im[intpow(power) / 4]

#define init_w(power) \
    genw(w_##power##_re, w_##power##_im, w_##power##_3re, w_##power##_3im, \
        intpow(power))

#define loopcall(func) \
    func(4); func(5); func(6); func(7); \
    func(8); func(9); func(10); func(11); \
Пример #11
0
int
main (int argc, char **argv)
{
  settings conf;
  double beta_step, beta_start, beta;
  datapoint data;
  double c0, cl1, cl2, cr1, cr2;

  const gsl_rng_type * RngType;

  gsl_rng_env_setup();
  RngType = gsl_rng_default;
  conf.rng = gsl_rng_alloc (RngType);

  lattice_site * lattice   = NULL;
  gsl_vector * mag_vector  = NULL ;


  /************
   * SETTINGS *
   ************/
  conf.spindims   = 2;
  conf.spacedims  = 2;
  conf.sidelength = 32;
  conf.max_settle = 1000;
  conf.block_size = 1000;
  conf.blocks     = 20;
  conf.verbose_flag = 0;


  /*************************************
   * ALLOCATION OF LATTICE AND VECTORS *
   *************************************/
  //Store Element number for future use
  conf.elements = intpow(conf.sidelength,conf.spacedims);

  printf("#Allocating\n");


  int * location = (int *) malloc(conf.spacedims*sizeof(int));
  int * neigh    = (int *) malloc(conf.spacedims*sizeof(int));
  
  lattice = allocate_lattice(conf);

  if(conf.verbose_flag)
    fprintf(stderr,"#Allocated %d points on the lattice\n",conf.elements);
  
  
  randomize_spins(lattice,conf);

  /* if(conf.verbose_flag) 
    print_lattice (lattice,sidelength,conf.spacedims,conf.spindims); */

  mag_vector = gsl_vector_calloc(conf.spindims);
  
  /**********************
   * Running Simulation *
   **********************/
  double err = 100;
  double firstd, secondd;
  beta_start      = 0.45;
  beta_step       = 0.001;
  double dbeta;
  beta = beta_start;
  while(err > 0.01)
  {
    //Calculate values of specific heat
    //c(beta)
    clusterupdatebatch(lattice,conf,beta,&data);
    c0 = data.c;
    //Left and Right one step
    clusterupdatebatch(lattice,conf,beta-beta_step,&data);
    cl1 = data.c;
    clusterupdatebatch(lattice,conf,beta+beta_step,&data);
    cr1 = data.c;
    //Left and Right one step
    clusterupdatebatch(lattice,conf,beta-2*beta_step,&data);
    cl2 = data.c;
    clusterupdatebatch(lattice,conf,beta+2*beta_step,&data);
    cr2 = data.c;

    //Find first derivative
    firstd  = ( ((cl2-cr2)/12) +(2*(-cl1+cr1)/3) )/beta_step;
    //Find second derivative
    secondd = ( ((-cl2-cr2)/12) +(4*(cl1+cr1)/3) - (5*c0/2) )/pow(beta_step,2);
    
    dbeta = firstd/secondd;
    err = fabs(firstd);
    beta = beta - dbeta;
    printf("Beta Est = %g  delta= %g firstd= %g secondd= %g\n",beta,dbeta,firstd,secondd);
  }

  /***********
   * CLEANUP *
   ***********/
  printf("#Cleaning Up\n");
  free_lattice(lattice,conf);
  free(location);
  location = NULL;
  free(neigh);
  neigh = NULL;

  /* Free GSL Random Num Generator*/
  gsl_rng_free (conf.rng);
  

  printf("#Done\n");

  return EXIT_SUCCESS;
}
Пример #12
0
Vec2 calc_dir(int d, int orient) {
    return
        Vec2(
            intpow(2, d)*((orient & 1) ? 1.0f : -1.0f),
            intpow(2, d)*((orient & 2) ? 1.0f : -1.0f));
}