示例#1
0
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
operator()(Block* b, const diy::ReduceProxy& srp, const KDTreePartners& partners) const
{
    int dim;
    if (srp.round() < partners.rounds())
        dim = partners.dim(srp.round());
    else
        dim = partners.dim(srp.round() - 1);

    if (srp.round() == partners.rounds())
        update_links(b, srp, dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain); // -1 would be the "uninformative" link round
    else if (partners.swap_round(srp.round()) && partners.sub_round(srp.round()) < 0)       // link round
    {
        dequeue_exchange(b, srp, dim);         // from the swap round
        split_to_neighbors(b, srp, dim);
    }
    else if (partners.swap_round(srp.round()))
    {
        Samples samples;
        receive_samples(b, srp, samples);
        enqueue_exchange(b, srp, dim, samples);
    } else if (partners.sub_round(srp.round()) == 0)
    {
        if (srp.round() > 0)
        {
            int prev_dim = dim - 1;
            if (prev_dim < 0)
                prev_dim += dim_;
            update_links(b, srp, prev_dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain);    // -1 would be the "uninformative" link round
        }

        compute_local_samples(b, srp, dim);
    } else if (partners.sub_round(srp.round()) < (int) partners.histogram.rounds()/2)     // we are reusing partners class, so really we are talking about the samples rounds here
    {
        Samples samples;
        add_samples(b, srp, samples);
        srp.enqueue(srp.out_link().target(0), samples);
    } else
    {
        Samples samples;
        add_samples(b, srp, samples);
        if (samples.size() != 1)
        {
            // pick the median
            std::nth_element(samples.begin(), samples.begin() + samples.size()/2, samples.end());
            std::swap(samples[0], samples[samples.size()/2]);
            //std::sort(samples.begin(), samples.end());
            //samples[0] = (samples[samples.size()/2] + samples[samples.size()/2 + 1])/2;
            samples.resize(1);
        }
        forward_samples(b, srp, samples);
    }
}
示例#2
0
void decimate_data(FILE *input, FILE *output) /*includefile*/
{ 
  char string[80];
  float *fblock,min,max,realtime,fsaved[2];
  unsigned short *sblock;
  unsigned char  *cblock;
  int nsaved=0,ns,nsblk,opened=0,nout;

  nsblk=nchans*nifs*naddt;
  fblock=(float *) malloc(nsblk*sizeof(float));
  sblock=(unsigned short *) malloc(nsblk*sizeof(unsigned short));
  cblock=(unsigned char *) malloc(nsblk*sizeof(unsigned short));
  realtime=min=0.0;
  max=(float) pow(2.0,(double)obits) -1.0;

  /* main decimation loop */
  while ((ns=read_block(input,nbits,fblock,nsblk))>0) {
    add_channels(fblock,ns,naddc);
    add_samples(fblock,nifs,nchans/naddc,naddt);
    if (!opened) {
      /* open up logfile */
      open_log("decimate.monitor");
      opened=1;
    }
    nout=ns/naddt/naddc;
    switch (obits) {
    case 32:
      fwrite(fblock,sizeof(float),nout,output);
      break;
    case 16:
      float2short(fblock,nout,min,max,sblock);
      fwrite(sblock,sizeof(unsigned short),nout,output);
      break;
    case 8:
      float2char(fblock,nout,min,max,cblock);
      fwrite(cblock,sizeof(unsigned char),nout,output);
      break;
    case 4:
      if (nout==1) {
	/* must have at least two samples for four-bit packing save this one */
	fsaved[nsaved]=fblock[0];
	nsaved++;
	if (nsaved==2) {
	  /* we have 2 saved! write out */
	  float2four(fsaved,nsaved,min,max,cblock);
	  fwrite(cblock,sizeof(unsigned char),1,output);
	  nsaved=0;
	}
      } else {
	/* normal case */
	float2four(fblock,nout,min,max,cblock);
	fwrite(cblock,sizeof(unsigned char),nout/2,output);
      }
      break;
    case 2:
      float2two(fblock,nout,min,max,cblock);
      fwrite(cblock,sizeof(unsigned char),nout/4,output);
      break;
    }
    realtime+=(float) tsamp * (float) ns/(float) nchans/(float) nifs;
    sprintf(string,"time:%.1fs",realtime);
    update_log(string);
  }
  update_log("finished");
  close_log();
}