예제 #1
0
파일: residuedata.c 프로젝트: NyouB/4t4c
/* need to reseed because of the coarse quantization we tend to use on
   residuals (which causes lots & lots of dupes) */
void vqext_preprocess(vqgen *v){
  long i,j,k,l;
  float *test=alloca(sizeof(float)*v->elements);
  scalequant=q.quant;

  vqext_quantize(v,&q);
  vqgen_unquantize(v,&q);

  /* if there are any dupes, reseed */
  for(k=0;k<v->entries;k++){
    for(l=0;l<k;l++){
      if(memcmp(_now(v,k),_now(v,l),sizeof(float)*v->elements)==0)
        break;
    }
    if(l<k)break;
  }

  if(k<v->entries){
    fprintf(stderr,"reseeding with quantization....\n");

    /* seed the inputs to input points, but points on unit boundaries,
     ignoring quantbits for now, making sure each seed is unique */
    
    for(i=0,j=0;i<v->points && j<v->entries;i++){
      for(k=0;k<v->elements;k++){
        float val=_point(v,i)[k];
        test[k]=rint(val/scalequant)*scalequant;
      }
      
      for(l=0;l<j;l++){
        for(k=0;k<v->elements;k++)
          if(test[k]!=_now(v,l)[k])
            break;
        if(k==v->elements)break;
      }
      if(l==j){
        memcpy(_now(v,j),test,v->elements*sizeof(float));
        j++;
      }
    }
    
    if(j<v->elements){
      fprintf(stderr,"Not enough unique entries after prequantization\n");
      exit(1);
    }
  }  
  vqext_quantize(v,&q);
  quant_save=_ogg_malloc(sizeof(float)*v->elements*v->entries);
  memcpy(quant_save,_now(v,0),sizeof(float)*v->elements*v->entries);
  vqgen_unquantize(v,&q);

}
예제 #2
0
bool DirEntryList::setUidGid(const Key &key, uid_t uid, gid_t gid) {
    auto found = _find(key);
    bool changed = false;
    if (uid != (uid_t)-1) {
        found->uid = uid;
        found->lastMetadataChangeTime = _now();
        changed = true;
    }
    if (gid != (gid_t)-1) {
        found->gid = gid;
        found->lastMetadataChangeTime = _now();
        changed = true;
    }
    return changed;
}
예제 #3
0
파일: vqgen.c 프로젝트: Bobbin007/xbmc
void vqgen_cellmetric(vqgen *v){
  int j,k;
  float min=-1.f,max=-1.f,mean=0.f,acc=0.f;
  long dup=0,unused=0;
 #ifdef NOISY
  int i;
   char buff[80];
   float spacings[v->entries];
   int count=0;
   FILE *cells;
   sprintf(buff,"cellspace%d.m",v->it);
   cells=fopen(buff,"w");
#endif

  /* minimum, maximum, cell spacing */
  for(j=0;j<v->entries;j++){
    float localmin=-1.;

    for(k=0;k<v->entries;k++){
      if(j!=k){
	float this=_dist(v,_now(v,j),_now(v,k));
	if(this>0){
	  if(v->assigned[k] && (localmin==-1 || this<localmin))
	    localmin=this;
	}else{	
	  if(k<j){
	    dup++;
	    break;
	  }
	}
      }
    }
    if(k<v->entries)continue;

    if(v->assigned[j]==0){
      unused++;
      continue;
    }
    
    localmin=v->max[j]+localmin/2; /* this gives us rough diameter */
    if(min==-1 || localmin<min)min=localmin;
    if(max==-1 || localmin>max)max=localmin;
    mean+=localmin;
    acc++;
#ifdef NOISY
    spacings[count++]=localmin;
#endif
  }
void RTCTimer::update()
{
  uint32_t now = _now ? _now() : 0;
  if (now) {
    update(now);
  }
}
예제 #5
0
파일: residuedata.c 프로젝트: NyouB/4t4c
void vqext_quantize(vqgen *v,quant_meta *q){
  int j,k;
  long dim=v->elements;
  long n=v->entries;
  float max=-1;
  float *test=alloca(sizeof(float)*dim);
  int moved=0;

  
  /* allow movement only to unoccupied coordinates on the coarse grid */
  for(j=0;j<n;j++){
    for(k=0;k<dim;k++){
      float val=_now(v,j)[k];
      float norm=rint(fabs(val)/scalequant);
      if(norm>max)max=norm;
      test[k]=norm;
    }

    /* allow move only if unoccupied */
    if(quant_save){
      for(k=0;k<n;k++)
        if(j!=k && memcmp(test,quant_save+dim*k,dim*sizeof(float))==0)
          break;
      if(k==n){
        if(memcmp(test,quant_save+dim*j,dim*sizeof(float)))        
          moved++;
        memcpy(quant_save+dim*j,test,sizeof(float)*dim);
      }
    }else{
      memcpy(_now(v,j),test,sizeof(float)*dim);
    }
  }

  /* unlike the other trainers, we fill in our quantization
     information (as we know granularity beforehand and don't need to
     maximize it) */

  q->min=_float32_pack(0.f);
  q->delta=_float32_pack(scalequant);
  q->quant=_ilog(max);

  if(quant_save){
    memcpy(_now(v,0),quant_save,sizeof(float)*dim*n);
    fprintf(stderr,"cells shifted this iteration: %d\n",moved);
  }
}
예제 #6
0
void DirEntryList::add(const string &name, const Key &blobKey, fspp::Dir::EntryType entryType, mode_t mode,
                            uid_t uid, gid_t gid) {
    if (_hasChild(name)) {
        throw fspp::fuse::FuseErrnoException(EEXIST);
    }
    auto insert_pos = _findUpperBound(blobKey);
    auto now = _now();
    _entries.emplace(insert_pos, entryType, name, blobKey, mode, uid, gid, now, now, now);
}
예제 #7
0
파일: lspdata.c 프로젝트: AllardJ/Tomato
void vqext_quantize(vqgen *v,quant_meta *q){
  float delta,mindel;
  float maxquant=((1<<q->quant)-1);
  int j,k;

  /* first find the basic delta amount from the maximum span to be
     encoded.  Loosen the delta slightly to allow for additional error
     during sequence quantization */

  delta=(global_maxdel-global_mindel)/((1<<q->quant)-1.5f);
  
  q->min=_float32_pack(global_mindel);
  q->delta=_float32_pack(delta);

  mindel=_float32_unpack(q->min);
  delta=_float32_unpack(q->delta);

  for(j=0;j<v->entries;j++){
    float last=0;
    for(k=0;k<v->elements;k++){
      float val=_now(v,j)[k];
      float now=rint((val-last-mindel)/delta);
      
      _now(v,j)[k]=now;
      if(now<0){
        /* be paranoid; this should be impossible */
        fprintf(stderr,"fault; quantized value<0\n");
        exit(1);
      }

      if(now>maxquant){
        /* be paranoid; this should be impossible */
        fprintf(stderr,"fault; quantized value>max\n");
        exit(1);
      }
      last=(now*delta)+mindel+last;
    }
  }

}
예제 #8
0
파일: metrics.c 프로젝트: Chocobo1/vorbis
void cell_spacing(codebook *c){
  int j,k;
  float min=-1.f,max=-1.f,mean=0.f,meansq=0.f;
  long total=0;

  /* minimum, maximum, mean, ms cell spacing */
  for(j=0;j<c->c->entries;j++){
    if(c->c->lengthlist[j]>0){
      float localmin=-1.;
      for(k=0;k<c->c->entries;k++){
        if(c->c->lengthlist[k]>0){
          float this=_dist(c->c->dim,_now(c,j),_now(c,k));
          if(j!=k &&
             (localmin==-1 || this<localmin))
            localmin=this;
        }
      }
      
      if(min==-1 || localmin<min)min=localmin;
      if(max==-1 || localmin>max)max=localmin;
      mean+=sqrt(localmin);
      meansq+=localmin;
      total++;
    }
예제 #9
0
Display::Display ()
	: _title("simple thing"),
		_window(nullptr),
		_ctx(nullptr),
		_time(_now()), _accumulate(0), _fps(DefaultFPS),
		_quit(false)
{
	SDL_Init(SDL_INIT_VIDEO);
	//SDL_CaptureMouse(false);
	
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

	setOptions(1240, 680, false);
}
int8_t RTCTimer::every(uint32_t period, void (*callback)(uint32_t now),
    int repeatCount)
{
  int8_t i = findFreeEventIndex();
  if (i == -1)
    return -1;

  _events[i]._eventType = RTCEvent::RTCEvent_Every;
  _events[i]._period = period;
  _events[i]._repeatCount = repeatCount;
  _events[i]._callback = callback;
  _events[i]._lastEventTime = _now ? _now() : 0;
  _events[i]._count = 0;

  return i;
}
예제 #11
0
void AudioTestSource_i::_new_gst_buffer(GstElement *sink, AudioTestSource_i* comp) {
	static GstBuffer *buffer;
	static std::vector<short> packet;

    /* Retrieve the buffer */
    g_signal_emit_by_name (sink, "pull-buffer", &buffer);
    if (buffer) {
    	BULKIO::PrecisionUTCTime T;

	    /* The only thing we do in this example is print a * to indicate a received buffer */
    	if (GST_CLOCK_TIME_IS_VALID(buffer->timestamp)) {
    		T = _from_gst_timestamp(buffer->timestamp);
    	} else {
    		T = _now();
    	}

    	packet.resize(buffer->size / 2); // TODO the division should come from reading buffer->caps
    	memcpy(&packet[0], buffer->data, buffer->size);

    	comp->audio_out->pushPacket(packet, T, false, comp->stream_id);
	    gst_buffer_unref (buffer);
    }
}
예제 #12
0
파일: vqgen.c 프로젝트: Bobbin007/xbmc
/* *must* be beefed up. */
void _vqgen_seed(vqgen *v){
  long i;
  for(i=0;i<v->entries;i++)
    memcpy(_now(v,i),_point(v,i),sizeof(float)*v->elements);
  v->seeded=1;
}
예제 #13
0
END_TEST

START_TEST(test_dn_write_file)
{
	const char *tf = "/HADOOFUS_TEST_WRITE_FILE",
	      *client = "HADOOFUS_CLIENT", *err;
	bool s;

	struct hdfs_datanode *dn;
	struct hdfs_object *e = NULL, *bl, *fs, *bls;
	uint64_t begin, end;

	s = hdfs_delete(h, tf, false/*recurse*/, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));

	hdfs_create(h, tf, 0644, client, true/*overwrite*/,
	    false/*createparent*/, 1/*replication*/, blocksz, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));

	begin = _now();

	// write first block (full)
	bl = hdfs_addBlock(h, tf, client, NULL, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));

	dn = hdfs_datanode_new(bl, client, HDFS_DATANODE_AP_1_0, &err);
	ck_assert_msg((intptr_t)dn, "error connecting to datanode: %s", err);

	hdfs_object_free(bl);

	err = hdfs_datanode_write_file(dn, fd, blocksz, 0, _i/*crcs*/);
	fail_if(err, "error writing block: %s", err);

	hdfs_datanode_delete(dn);

	// write second block (partial)
	bl = hdfs_addBlock(h, tf, client, NULL, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));

	dn = hdfs_datanode_new(bl, client, HDFS_DATANODE_AP_1_0, &err);
	ck_assert_msg((intptr_t)dn, "error connecting to datanode: %s", err);

	hdfs_object_free(bl);

	err = hdfs_datanode_write_file(dn, fd, towrite-blocksz, blocksz, _i/*crcs*/);
	fail_if(err, "error writing block: %s", err);

	hdfs_datanode_delete(dn);

	end = _now();
	fprintf(stderr, "Wrote %d MB from file in %ld ms%s, %02g MB/s\n",
	    towrite/1024/1024, end - begin, _i? " (with crcs)":"",
	    (double)towrite/(end-begin)/1024*1000/1024);

	fs = hdfs_getFileInfo(h, tf, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));
	ck_assert(fs->ob_val._file_status._size == towrite);
	hdfs_object_free(fs);

	s = hdfs_complete(h, tf, client, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));
	ck_assert_msg(s, "did not complete");

	bls = hdfs_getBlockLocations(h, tf, 0, towrite, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));

	begin = _now();
	for (int i = 0; i < bls->ob_val._located_blocks._num_blocks; i++) {
		struct hdfs_object *bl =
		    bls->ob_val._located_blocks._blocks[i];
		dn = hdfs_datanode_new(bl, client, HDFS_DATANODE_AP_1_0, &err);
		ck_assert_msg((intptr_t)dn, "error connecting to datanode: %s", err);

		err = hdfs_datanode_read_file(dn, 0/*offset-in-block*/,
		    bl->ob_val._located_block._len,
		    ofd,
		    i*blocksz/*fd offset*/,
		    _i/*crcs*/);

		hdfs_datanode_delete(dn);

		if (err == HDFS_DATANODE_ERR_NO_CRCS) {
			fprintf(stderr, "Warning: test server doesn't support "
			    "CRCs, skipping validation.\n");
			_i = 0;

			// reconnect, try again without validating CRCs (for
			// isi_hdfs_d)
			dn = hdfs_datanode_new(bl, client, HDFS_DATANODE_AP_1_0, &err);
			ck_assert_msg((intptr_t)dn, "error connecting to datanode: %s", err);

			err = hdfs_datanode_read_file(dn, 0/*offset-in-block*/,
			    bl->ob_val._located_block._len,
			    ofd,
			    i*blocksz,
			    false/*crcs*/);

			hdfs_datanode_delete(dn);
		}

		fail_if(err, "error reading block: %s", err);
	}
	end = _now();
	fprintf(stderr, "Read %d MB to file in %ld ms%s, %02g MB/s\n",
	    towrite/1024/1024, end - begin, _i? " (with crcs)":"",
	    (double)towrite/(end-begin)/1024*1000/1024);

	hdfs_object_free(bls);
	fail_if(filecmp(fd, ofd, towrite), "read differed from write");

	s = hdfs_delete(h, tf, false/*recurse*/, &e);
	if (e)
		fail("exception: %s", hdfs_exception_get_message(e));
	ck_assert_msg(s, "delete returned false");
}
예제 #14
0
void DirEntryList::setMode(const Key &key, mode_t mode) {
    auto found = _find(key);
    ASSERT ((S_ISREG(mode) && S_ISREG(found->mode)) || (S_ISDIR(mode) && S_ISDIR(found->mode)) || (S_ISLNK(mode)), "Unknown mode in entry");
    found->mode = mode;
    found->lastMetadataChangeTime = _now();
}
예제 #15
0
// show the screen
bool Display::show ()
{
	if (_quit)
	{
		if (_died)
			_dump();
		return false;
	}

	if (!_window)
		return true;

	// poll events
	SDL_Event e;
	while (SDL_PollEvent(&e))
		switch (e.type)
		{
		case SDL_QUIT:
			quit();
			return false;

		case SDL_KEYDOWN:
			_pressed(e.key.keysym.sym);
			break;

		case SDL_KEYUP:
			_released(e.key.keysym.sym);
			break;
		
		default:
			break;
		}

	// get delta time
	tick_t now = _now();
	tick_t diff = now - _time;
	_time = now;

	// eliminate unusual framerate errors (dragging, etc)
	if (diff > (tick_s / MinFPS))
		diff = tick_s / MinFPS;
	else if (diff == 0)
		diff = tick_s / MaxFPS;

	if (_view != nullptr)
	{
		auto dt = diff / double(tick_s);
		_view->update(this, dt);
		_view->draw(this);
	}
	else
		color(.5f, .8f, 1.f).glApplyClear();

	SDL_GL_SwapWindow(_window);

	
	/* const double sleep_s = 1.0 / 100.0;
	const time_t sleep_t = time_t(tick_s * sleep_s);
	auto n = _now();
	while ((_now() - n) < sleep_t)
		; */

	SDL_Delay(3);

	return true;
}
예제 #16
0
파일: optime.cpp 프로젝트: Axv2/mongo
 OpTime OpTime::now(const mongo::mutex::scoped_lock&) {
     return _now();
 }