Exemplo n.º 1
0
    samplerate_converter(sample_rate_conversion_quality quality, itype interpolation_factor,
                         itype decimation_factor, ftype scale = ftype(1), ftype cutoff = 0.5f)
        : kaiser_beta(window_param(quality)), depth(static_cast<itype>(filter_order(quality))),
          input_position(0), output_position(0)
    {
        const i64 gcf = gcd(interpolation_factor, decimation_factor);
        interpolation_factor /= gcf;
        decimation_factor /= gcf;

        taps  = depth * interpolation_factor;
        order = size_t(depth * interpolation_factor - 1);

        this->interpolation_factor = interpolation_factor;
        this->decimation_factor    = decimation_factor;

        const itype halftaps = taps / 2;
        filter               = univector<T>(size_t(taps), T());
        delay                = univector<T>(size_t(depth), T());

        cutoff = cutoff - transition_width() / c_pi<ftype, 4>;

        cutoff = cutoff / std::max(decimation_factor, interpolation_factor);

        for (itype j = 0, jj = 0; j < taps; j++)
        {
            filter[size_t(j)] =
                sinc((jj - halftaps) * cutoff * c_pi<ftype, 2>) * window(ftype(jj) / ftype(taps - 1));
            jj += size_t(interpolation_factor);
            if (jj >= taps)
                jj = jj - taps + 1;
        }

        const T s = reciprocal(sum(filter)) * interpolation_factor * scale;
        filter    = filter * s;
    }
Exemplo n.º 2
0
ftype BasisFn_spline::f_s( const ftype& s_, const std::vector<ftype>& params ) const
{
  const int& nbins = num_params();
  ftype s = ftype(nbins) * s_ord.ordinal( s_ );
  int i = Util::intf( s );
  ftype ds = s - ftype(i) - 0.5;
  i = Util::bound( 0, i, nbins-1 );
  return ( params[Util::max(i-1,0)]*0.5*(ds-0.5)*(ds-0.5) + params[i]*(0.75-ds*ds) + params[Util::min(i+1,nbins-1)]*0.5*(ds+0.5)*(ds+0.5) );
}
Exemplo n.º 3
0
 static KFR_MEM_INTRINSIC ftype window_param(sample_rate_conversion_quality quality)
 {
     const ftype att = sidelobe_attenuation(quality);
     if (att > 50)
         return ftype(0.1102) * (att - ftype(8.7));
     if (att >= 21)
         return ftype(0.5842) * pow(att - 21, ftype(0.4)) + ftype(0.07886) * (att - 21);
     return 0;
 }
Exemplo n.º 4
0
CBaseDec::RetCode CBaseDec::DecoderBase(CAudiofile* const in,
										const int OutputFd, State* const state,
										time_t* const t,
										unsigned int* const secondsToSkip)
{
	RetCode Status = OK;

	FILE* fp = fopen( in->Filename.c_str(), "r" );
	if ( fp == NULL )
	{
		fprintf( stderr, "Error opening file %s for decoding.\n",
				 in->Filename.c_str() );
		Status = INTERNAL_ERR;
	}
	/* jump to first audio frame; audio_start_pos is only set for FILE_MP3 */
	else if ( in->MetaData.audio_start_pos &&
			  fseek( fp, in->MetaData.audio_start_pos, SEEK_SET ) == -1 )
	{
		fprintf( stderr, "fseek() failed.\n" );
		Status = INTERNAL_ERR;
	}

	if ( Status == OK )
	{
		CFile::FileType ft = in->FileType;
		if( in->FileType == CFile::STREAM_AUDIO )
		{
			if ( fstatus( fp, ShoutcastCallback ) < 0 )
				fprintf( stderr, "Error adding shoutcast callback: %s", err_txt );

			if (ftype(fp, "ogg"))
				ft = CFile::FILE_OGG;
			else if (ftype(fp, "mpeg"))
				ft = CFile::FILE_MP3;
			else
				ft = CFile::FILE_UNKNOWN;
		}
		else
		{
			struct stat st;
			if (!fstat(fileno(fp), &st))
						in->MetaData.filesize = st.st_size;

		}
		in->MetaData.type = ft;

		Status = CFfmpegDec::getInstance()->Decoder(fp, OutputFd, state, &in->MetaData, t, secondsToSkip );

		if ( fclose( fp ) == EOF )
		{
			fprintf( stderr, "Could not close file %s.\n", in->Filename.c_str() );
		}
	}

	return Status;
}
Exemplo n.º 5
0
//Circular generator
GridItemPtr Grid::circular_generator::operator()()
{
    //TODO Possible optimization: instead of skipping the cells that are too far,
    //     enumerate only cells that are near enough. This would require more 
    //     computations though.
    BEGIN_RESTORE_STATE;
    RESTORE_STATE( state1 );
    END_RESTORE_STATE;

    BEGIN_GENERATOR;
    //first determine rectangle, where to search for
    ix0 = limit( (int)floor((center.x-r)*grid->cellScale.x), 0, grid->numCols );
    iy0 = limit( (int)floor((center.y-r)*grid->cellScale.y), 0, grid->numRows );

    ix1 = limit( (int)ceil((center.x+r)*grid->cellScale.x), 0, grid->numCols );
    iy1 = limit( (int)ceil((center.y+r)*grid->cellScale.y), 0, grid->numRows );

    max_cell_radius = grid->cellSize.norm()*0.5; //maxi
	
    //now enumerate all cells inside this rectangular area
    for ( iy = iy0; iy<iy1; ++iy ){
	for ( ix = ix0; ix < ix1; ++ix ){
	    //determine, whether this cell can be displayed at all
		{
		    vec2 c((ix+ftype(0.5))*grid->cellSize.x,
			   (iy+ftype(0.5))*grid->cellSize.y);
		    //distance from the cell center to the circle center
		    ftype d = (c - center).norm();
		    if ( d > r + max_cell_radius )
			continue;//skip this cell - it is too far from center.
		}
		//iterate items inside cell
		curCell = &(grid->cellRef( ix, iy ));
		iItem = curCell->items.begin();
		iItemEnd = curCell->items.end();
		while (iItem != iItemEnd){
//		for ( iItem = curCell->items.begin(); iItem != curCell->items.end(); ++iItem){
		    //determine, whether this located item lays inside the circle
		    if ( dist((*iItem)->getPos(), center) <= r ){
			YIELD( *iItem, state1 );
		    }
		    ++iItem;
		}
	}
    }
	
    END_GENERATOR;
    return GridItemPtr();//Dummy
}
Exemplo n.º 6
0
void				init_cfg(t_cfg *cfg, int argc, char **argv)
{
	cfg->mlx = mlx_init();
	cfg->win = mlx_new_window(cfg->mlx, WIDTH, HEIGHT, "Fractol");
	cfg->img.img = mlx_new_image(cfg->mlx, WIDTH, HEIGHT);
	cfg->img.data = mlx_get_data_addr(cfg->img.img, &cfg->img.bpp,
		&cfg->img.sl, &cfg->img.endian);
	cfg->type = ftype(argc, argv);
	cfg->iter = 50;
	cfg->cr = -0.75;
	cfg->ci = 0.27015;
	cfg->zoom = 1.0;
	cfg->theme = 0;
	cfg->themev = 0;
	cfg->offset = (t_dvec2){.x = 0.0, .y = 0.0};
	cfg->color = (t_color){.r = 0.0, .g = 0.0, .b = 0.0};
	init_sval(cfg);
}

int					main(int argc, char **argv)
{
	t_cfg			cfg;

	init_cfg(&cfg, argc, argv);
	mlx_put_image_to_window(cfg.mlx, cfg.win, cfg.img.img, 0, 0);
	mlx_hook(cfg.win, 2, 1, key_hook, &cfg);
	mlx_hook(cfg.win, 6, 64, &mouse, &cfg);
	mlx_expose_hook(cfg.win, expose_hook, &cfg);
	mlx_loop(cfg.mlx);
	return (0);
}
Exemplo n.º 7
0
Arquivo: stab.c Projeto: bhanug/cdb
/* stabinit - initialize for symbol table emission */
static void stabinit(char *file, int argc, char *argv[]) {
	extern Interface sparcIR, solarisIR, x86IR;
	extern int getpid(void);

	if (IR == &solarisIR || IR == &sparcIR)
		leader = "!";
	else if (IR == &x86IR)
		leader = ";";
	else
		leader = " #";  /* it's a MIPS or ALPHA */
	uname = time(NULL)<<7|getpid();
	pickle = sym_module(file ? file : string(""), uname, 1, Seq_new(0), 0, Seq_new(0));
	locals = Seq_new(0);
	statics = Seq_new(0);
	uidTable = Table_new(0, 0, 0);
	module = mksymbol(AUTO,	stringf("_module_V%x", uname), array(unsignedtype, 0, 0));
	module->generated = 1;
	nub_bpflags = mksymbol(EXTERN, "_Nub_bpflags", array(chartype, 1, 0));
	nub_bpflags->defined = 0;
	attach((Apply) entry_hook, NULL, &events.entry);
	attach((Apply) block_hook, NULL, &events.blockentry);
	attach((Apply) point_hook, NULL, &events.points);
	attach((Apply)  call_hook, NULL, &events.calls);
	attach((Apply)return_hook, NULL, &events.returns);
	nub_bp = mksymbol(EXTERN, "_Nub_bp", ftype(voidtype, inttype));
	nub_bp->defined = 0;
	nub_tos = mksymbol(EXTERN, "_Nub_tos", voidptype);
	nub_tos->defined = 0;
}
Exemplo n.º 8
0
void
afsnode::mkfattr (fattr *f, sfs_aid aid)
{
  static const int modes[] = {
    0, NFSMODE_REG, NFSMODE_DIR, NFSMODE_BLK, NFSMODE_CHR,
    NFSMODE_LNK, NFSMODE_SOCK, NFSMODE_FIFO
  };
  static const int nmodes = sizeof (modes) / sizeof (modes[0]);

  fattr3 f3;
  mkfattr3 (&f3, aid);
  bzero (f, sizeof (*f));
  f->type = f3.type == NF3FIFO ? NFFIFO : ftype (f3.type);
  f->mode = f3.mode;
  if (f3.type < nmodes)
    f->mode |= modes[f3.type];
  f->nlink = f3.nlink;
  f->uid = f3.uid;
  f->gid = f3.gid;
  f->size = f3.size;
  f->blocksize = 512;
#ifndef __linux__		// XXX
  f->rdev = makedev (f3.rdev.major, f3.rdev.minor);
#endif /* !__linux__ */
  f->blocks = f3.used >> 9;
  f->fsid = f3.fsid;
  f->fileid = f3.fileid;
  f->atime.seconds = f3.atime.seconds;
  f->atime.useconds = f3.atime.nseconds / 1000;
  f->mtime.seconds = f3.mtime.seconds;
  f->mtime.useconds = f3.mtime.nseconds / 1000;
  f->ctime.seconds = f3.ctime.seconds;
  f->ctime.useconds = f3.ctime.nseconds / 1000;
}
Exemplo n.º 9
0
void Generic_ordinal::init( const Range<ftype>& range, const int num_ranges )
{
  nranges = ftype( num_ranges );
  hist.clear();
  hist.resize( num_ranges + 1, 0.0 );
  range_ = range;
}
DynamicFinfo::~DynamicFinfo()
{
	if ( generalIndex_ != 0 ) {
		// Assume that the ftype knows what to do here.
		ftype()->destroyIndex( generalIndex_ );
	}
}
Exemplo n.º 11
0
ftype BasisFn_binner::f_s( const ftype& s, const std::vector<ftype>& params ) const
{
  const int& nbins = num_params();
  // convert reso to int
  int bin = Util::bound( 0, Util::intf( ftype(nbins) * s_ord.ordinal( s ) ), nbins-1 );
  return params[bin];
}
Exemplo n.º 12
0
/**
 * For now we just require that the name be followed immediately
 * by square braces, and that there is a single index in there.
 * Later may consider wildcards.
 */
const Finfo* LookupFinfo::match( Element* e, const string& s ) const
{
	if ( s == name() )
		return this;
	// Check that the base name matches.
	std::string::size_type openpos = name().length();
	if ( s.substr( 0, openpos ) != name() )
		return 0;

	if ( s.length() < name().length() + 3 ) {
		cout << "Error: LookupFinfo::match: bad indexing: " <<
				s << endl;
		return 0;
	}

	std::string::size_type closepos = s.length() - 1;

	if ( s[openpos] == '[' && s[closepos] == ']' ) {
		string indexStr = 
			s.substr( openpos + 1, closepos - openpos - 1 );

		void* index = ftype()->strToIndexPtr( indexStr );
		string n = name() + "[" + indexStr + "]";
		DynamicFinfo* ret = 
				DynamicFinfo::setupDynamicFinfo(
					e, n, this, 
					get_,
					index
				);
		return ret;
	}
	return 0;
}
Exemplo n.º 13
0
bool M2I::sendListing(ISendLine &cb)
{
    m_status = NOT_READY;
    // disk title
    QString parsed;
    // Reseek from beginning of M2I.
    if(!m_hostFile.seek(0) or !readFirstLine(&parsed)) {
        cb.send(0, strError1);
        return false;
    }

    // First line is disk title
    QString line = QString("\x12\x22%1\x22%2").arg(parsed, strID);
    cb.send(0, line);

    while(!m_hostFile.atEnd()) {
        // Write lines
        uchar ftype(parseLine(0, &parsed));

        if('P' == ftype or 'D' == ftype) {
            line = QString("  \x22%1\x22 %2").arg(parsed, 'p' == ftype ? strDotPRG : strDEL);
            cb.send(0, line);
        }
    }
    return true;
} // sendListing
Exemplo n.º 14
0
const BasisFn_base::Fderiv& BasisFn_spline::fderiv_s( const ftype& s_, const std::vector<ftype>& params ) const
{
  const int& nbins = num_params();
  for ( int i = 0; i < nbins; i++ ) result().df[i] = 0.0;

  ftype s = ftype(nbins) * s_ord.ordinal( s_ );
  int i1 = Util::intf( s );
  ftype ds = s - ftype(i1) - 0.5;
  i1 = Util::bound( 0, i1, nbins-1 );
  int i0 = Util::max(i1-1,0);
  int i2 = Util::min(i1+1,nbins-1);
  result().f = params[i0]*0.5*(ds-0.5)*(ds-0.5) + params[i1]*(0.75-ds*ds) + params[i2]*0.5*(ds+0.5)*(ds+0.5);
  result().df[i0] += 0.5*(ds-0.5)*(ds-0.5);
  result().df[i1] += 0.75-ds*ds;
  result().df[i2] += 0.5*(ds+0.5)*(ds+0.5);
  return result();
}
Exemplo n.º 15
0
void LookupFinfo::addFuncVec( const string& cname )
{
	fv_ = new FuncVec( cname, name() );
	fv_->addFunc( set_, ftype() );
	fv_->setDest();
	fv_->makeTrig(); // Make a trigger funcVec
	fv_->makeLookup(); // Make a Lookup funcVec to deal with indexing
}
Exemplo n.º 16
0
bool isValidFile(CBuffer& file, int type)
{
	for ( int i = 0; i < folderConfig.count(); ++i )
	{
		folderConfig[i].setRead(0);
		CString ftype( folderConfig[i].readString( " " ) );
		CString fmask = CBuffer() << dataDir <<
			CBuffer(folderConfig[i].readString( "" )).trim().text();
		folderConfig[i].setRead(0);

		switch ( type )
		{
			case 11:	// HEADGIF
				if ( ftype == "head" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 35:	// BODYIMG
				if ( ftype == "body" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 8:		// SWORDPOWER
				if ( ftype == "sword" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 9:		// SHIELDPOWER
				if ( ftype == "shield" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 1:		// level
				if ( ftype == "level" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case -1:	// Any
				if ( file.match( fmask.text() ) )
					return true;
			break;

			default:
			case 0:		// file
				if ( ftype == "file" )
					if ( file.match( fmask.text() ) )
						return true;
			break;
		}
	}

	return false;
}
/**
 * The DynamicFinfo, if it exists, must intercept operations directed
 * toward the original ValueFinfo. In this case it is able to
 * deal with message requests.
 * This Finfo must handle three kinds of requests:
 * - To assign a value: a set
 * - A request to extract a value: a trigger to send back values to
 *   the destinations from this DynamicFinfo.
 * - A sharedFinfo request: Set up both the trigger and the return.
 */
bool DynamicFinfo::respondToAdd(
					Eref e, Eref src, const Ftype *srcType,
					unsigned int& srcFuncId, unsigned int& returnFuncId,
					int& destMsg, unsigned int& destIndex
) const
{
	assert ( src.e != 0 && e.e != 0 );

	// Handle assignment message inputs when ftype is the same
	// as the original Finfo
	const FuncVec* fv = FuncVec::getFuncVec( srcFuncId );
	if ( srcType->isSameType( ftype() ) && fv->size() == 0 ) {
		unsigned int lookupId = origFinfo_->funcId();
		if ( generalIndex_ != 0 ) { 
		// Check if we handle a LookupFinfo or similar.
			lookupId = 
				FuncVec::getFuncVec( origFinfo_->funcId() )->lookupId();
			assert( lookupId != 0 );
		}
		returnFuncId = lookupId;
		destMsg = msg_;
		destIndex = e.e->numTargets( msg_ );
		return 1;
	}

	unsigned int trigId = 
		FuncVec::getFuncVec( origFinfo_->funcId() )->trigId();
	/*
	 * Disable the capability for independent trigger.
	// Handle trigger message when ftype is an Ftype0 and original
	// object was a ValueFinfo or related.
	if ( fv->size() == 0 && srcType->isSameType( Ftype0::global() ) && 
		ftype()->nValues() == 1 &&
		trigId != 0 )
		{
		returnFuncId = trigId;
		destIndex = msg_;
		numDest = 1;
		return 1;
	}
	*/

	// Handle SharedFinfo requests. The srcFl should have one
	// RecvFunc designed to handle the returned value. The
	// src Ftype is a SharedFtype that we will have to match.
	// Here we make a SharedFtype on the fly for comparing with the
	// incoming ftype.
	Finfo* shared[] = { &trigFinfo, const_cast< Finfo* >( origFinfo_ ) };
	SharedFtype sf ( shared, 2 );
	if ( fv->size() == 1  && trigId != 0 && sf.isSameType( srcType ) )
	{
		returnFuncId = trigId;
		destMsg = msg_;
		destIndex = e.e->numTargets( msg_ );
		return 1;
	}
	return 0;
}
Exemplo n.º 18
0
/* traceInit - initialize for tracing */
void traceInit(char *arg) {
	if (strncmp(arg, "-t", 2) == 0 && strchr(arg, '=') == NULL) {
		Symbol printer = mksymbol(EXTERN, arg[2] ? &arg[2] : "printf",
			ftype(inttype, ptr(qual(CONST, chartype)), voidtype, NULL));
		printer->defined = 0;
		attach((Apply)tracecall,   printer, &events.entry);
		attach((Apply)tracereturn, printer, &events.returns);
	}
}
Exemplo n.º 19
0
ftype Histogram::y( const ftype& x ) const
{
  ftype xi = indexf( truncate( x ) ) - 0.5;
  int i = Util::intf( xi );
  ftype xf = xi - ftype( i );
  ftype y0 = ( i   >= 0     ) ? data[i  ] : -data.front();
  ftype y1 = ( i+1 < size() ) ? data[i+1] : -data.back();
  return ( (1.0-xf)*y0 + xf*y1 );
}
Exemplo n.º 20
0
/* bbexit - return tree for _epilogue(&afunc)' */
static void bbexit(Symbol yylink, Symbol f, Tree e) {
    static Symbol epilogue;

    if (epilogue == 0) {
        epilogue = mksymbol(EXTERN, "_epilogue", ftype(inttype, voidptype));
        epilogue->defined = 0;
    }
    walk(vcall(epilogue, voidtype, pointer(idtree(afunc)), NULL), 0, 0);
}
Finfo* DynamicFinfo::copy() const
{
	void* ge = 0;
	if ( generalIndex_ != 0 ) {
		ge = ftype()->copyIndex( generalIndex_ );
	}
	DynamicFinfo* ret = new DynamicFinfo( *this );
	ret->generalIndex_ = ge;
	return ret;
}
Exemplo n.º 22
0
void Mobile::simFriction( ftype dt )
{
    ftype movementFrictionForce = speed.norm()*movementFriction*world->getViskosity();
    ftype rotationFrictionForce = sqr(rotationSpeed)*rotationFriction*world->getViskosity();
    //TODO uneffective computation, rotation speed can increase for big gaps
    //apply friction forces
    //speed -= speed/speed.norm() * movementFrictionForce / mass * dt;
    speed *= max(ftype(0), ( 1 - movementFrictionForce / mass * dt));
    rotationSpeed -= sign(rotationSpeed)*rotationFrictionForce / inertion * dt;
}
Exemplo n.º 23
0
void Mobile::tryEatFood()
{
    //TODO: instead of eating constantly, make some pause? Food searching may be slow.
    FoodPtr pFood = world->findNearestFood( getPos(), /*FOOD_EATING_RADIUS*/1 );
    if (pFood){//some food found
	energy = min( ftype(1), energy + pFood->getValue() );
	world->foodEaten( pFood, *this);
	foodEaten ++;
    }
}
Exemplo n.º 24
0
static int
dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode,
		char **rt_start, size_t *rt_len)
{
	DIR *dp;
	struct dirent *dirent;
	int len;
	open_directory_t *the_dir;
	const char *ftstr;
#ifdef ZOS_USS
	unsigned long ino;
#else
	unsigned long long ino;
#endif

	/*
	 * The caller sets *errcode to 0, so we should set it only if an
	 * error occurs.
	 */

	if (out == NULL || iobuf == NULL || iobuf->opaque == NULL)
		return EOF;

	the_dir = (open_directory_t *) iobuf->opaque;
	dp = the_dir->dp;

	/*
	 * Initialize errno, since readdir does not set it to zero on EOF.
	 */
	errno = 0;
	dirent = readdir(dp);
	if (dirent == NULL) {
		*errcode = errno;	/* in case there was an error */
		return EOF;
	}

	ino = get_inode (dirent, iobuf->name);

#if defined(ZOS_USS)
	len = sprintf(the_dir->buf, "%lu/%s", ino, dirent->d_name);
#elif __MINGW32__
	len = sprintf(the_dir->buf, "%I64u/%s", ino, dirent->d_name);
#else
	len = sprintf(the_dir->buf, "%llu/%s", ino, dirent->d_name);
#endif

	ftstr = ftype(dirent, iobuf->name);
	len += sprintf(the_dir->buf + len, "/%s", ftstr);

	*out = the_dir->buf;

	*rt_start = NULL;
	*rt_len = 0;	/* set RT to "" */
	return len;
}
Exemplo n.º 25
0
TSMWarning *initNITF20ISD (NITF_2_0_ISD *isd, std::string fname)
  throw (TSMError)
{
  std::string ftype ("NITF20");
  TSMWarning *warn = NULL;

  try {
    fillBuff(fname);
  } catch (TSMError err) {
    switch (err.getError())
    { 
      case TSMError::FILE_READ:
	std::cerr << "Unable to open " << ftype << fname << '\n';
	break;
      case TSMError::MEMORY:
	std::cerr << "Unable to Allocate memory for " 
		  << ftype << " ISD\n";
	break;
      case TSMError::ISD_NOT_SUPPORTED:
	std::cerr << "Failure parsing " 
		  << ftype << " file " 
		  << fname << '\n';
	break;
      default:
	break;
    }
    return NULL;
  }
  try 
  {
    warn = parseFile(isd);
  } 
  catch (TSMError err) 
  {
    switch (err.getError())
    { 
		case TSMError::FILE_READ:
			std::cerr << "Unable to open " << ftype << " file " << fname << '\n';
			break;
		case TSMError::MEMORY:
			std::cerr << "Unable to Allocate memory for " << ftype << " ISD\n";
			break;
		case TSMError::ISD_NOT_SUPPORTED:
			std::cerr << "Failure parsing " << ftype << " file " << fname << '\n';
			break;
		default:
			break;
    }
  }
  if (warn->getMessage().length() > 0) 
    return warn;
  else
    return NULL;
};
Exemplo n.º 26
0
/* bbentry - return tree for _prologue(&afunc, &YYlink)' */
static void bbentry(Symbol yylink, Symbol f) {
    static Symbol prologue;

    afunc = genident(STATIC, array(voidptype, 4, 0), GLOBAL);
    if (prologue == 0) {
        prologue = mksymbol(EXTERN, "_prologue", ftype(inttype, voidptype));
        prologue->defined = 0;
    }
    walk(vcall(prologue, voidtype, pointer(idtree(afunc)), pointer(idtree(yylink)), NULL), 0, 0);

}
Exemplo n.º 27
0
const BasisFn_base::Fderiv& BasisFn_binner::fderiv_s( const ftype& s, const std::vector<ftype>& params ) const
{
  const int& nbins = num_params();
  for ( int i = 0; i < nbins; i++ ) result().df[i] = 0.0;

  // convert reso to int
  int bin = Util::bound( 0, Util::intf( ftype(nbins) * s_ord.ordinal( s ) ), nbins-1 );
  // make vector of derivatives
  result().f = params[bin];
  result().df[bin] = 1.0;
  return result();
}
Exemplo n.º 28
0
static void
shownode(NODE *n, int f, char const *path)
{
        struct group *gr;
        struct passwd *pw;

        printf("%s%s %s", path, n->name, ftype(n->type));
        if (f & F_CKSUM)
                printf(" cksum=%lu", n->cksum);
        if (f & F_GID)
                printf(" gid=%d", n->st_gid);
        if (f & F_GNAME) {
                gr = getgrgid(n->st_gid);
                if (gr == NULL)
                        printf(" gid=%d", n->st_gid);
                else
                        printf(" gname=%s", gr->gr_name);
        }
        if (f & F_MODE)
                printf(" mode=%o", n->st_mode);
        if (f & F_NLINK)
                printf(" nlink=%d", (int)n->st_nlink);
        if (f & F_SLINK)
                printf(" link=%s", n->slink);
        if (f & F_SIZE)
                printf(" size=%jd", (intmax_t)n->st_size);
        if (f & F_TIME)
                printf(" time=%ld.%09ld", (long)n->st_mtimespec.tv_sec, n->st_mtimespec.tv_nsec);
        if (f & F_UID)
                printf(" uid=%d", n->st_uid);
        if (f & F_UNAME) {
                pw = getpwuid(n->st_uid);
                if (pw == NULL)
                        printf(" uid=%d", n->st_uid);
                else
                        printf(" uname=%s", pw->pw_name);
        }
        if (f & F_MD5)
                printf(" md5digest=%s", n->md5digest);
        if (f & F_SHA1)
                printf(" sha1digest=%s", n->sha1digest);
        if (f & F_RMD160)
                printf(" rmd160digest=%s", n->rmd160digest);
        if (f & F_SHA256)
                printf(" sha256digest=%s", n->sha256digest);
        if (f & F_SHA384)
                printf(" sha384digest=%s", n->sha384digest);
        if (f & F_SHA512)
                printf(" sha512digest=%s", n->sha512digest);
        if (f & F_FLAGS)
                printf(" flags=%s", flags_to_string(n->st_flags));
        printf("\n");
}
Exemplo n.º 29
0
PhraseSegmentation BeamSearchAdapter::search(boost::shared_ptr<const PhrasePairCollection> ppairs, const std::vector<Word> &sentence) const {
    if(sentence.empty())
        return PhraseSegmentation();

    std::stringstream sntstream;
    std::copy(sentence.begin(), sentence.end() - 1, std::ostream_iterator<Word>(sntstream, " "));
    sntstream << sentence.back();

    boost::scoped_ptr<Moses::Sentence> msent(new Moses::Sentence());
    std::vector<Moses::FactorType> ftype(1, 0);
    //msent.Read(sntstream, ftype);
    msent->CreateFromString(ftype, sntstream.str(), "|");

    const Moses::TranslationSystem &system =
        Moses::StaticData::Instance().GetTranslationSystem(Moses::TranslationSystem::DEFAULT);
    boost::scoped_ptr<Moses::Manager> manager(new Moses::Manager(0, *msent, Moses::StaticData::Instance().GetSearchAlgorithm(), &system));
    manager->ProcessSentence();
    const Moses::Hypothesis *hypo = manager->GetBestHypothesis();

    CompareAnchoredPhrasePairs comparePhrasePairs;
    typedef std::vector<AnchoredPhrasePair> PPVector;
    PPVector ppvec;
    ppairs->copyPhrasePairs(std::back_inserter(ppvec));
    std::sort(ppvec.begin(), ppvec.end(), comparePhrasePairs);
    PhraseSegmentation seg;
    if(hypo == NULL)
        LOG(logger_, error, "No answer from moses.");
    while(hypo && hypo->GetPrevHypo() != NULL) {
        CoverageBitmap cov(sentence.size());
        const Moses::WordsRange &mrange = hypo->GetCurrSourceWordsRange();
        for(uint i = mrange.GetStartPos(); i <= mrange.GetEndPos(); i++)
            cov.set(i);

        PhraseData srcpd;
        const Moses::Phrase *msrcphr = hypo->GetSourcePhrase();
        for(uint i = 0; i < msrcphr->GetSize(); i++)
            srcpd.push_back(msrcphr->GetFactor(i, 0)->GetString());

        PhraseData tgtpd;
        const Moses::Phrase &mtgtphr = hypo->GetCurrTargetPhrase();
        for(uint i = 0; i < mtgtphr.GetSize(); i++)
            tgtpd.push_back(mtgtphr.GetFactor(i, 0)->GetString());

        PPVector::const_iterator it = std::lower_bound(ppvec.begin(), ppvec.end(),
                                      CompareAnchoredPhrasePairs::PhrasePairKey(cov, srcpd, tgtpd),
                                      comparePhrasePairs);
        seg.push_front(*it);

        hypo = hypo->GetPrevHypo();
    }

    return seg;
}
Exemplo n.º 30
0
/* Compare two leaf-names, ignoring their suffix. */
static int
SameTypeless(char *a, char *b)
{
    int result = FALSE;
    char *type_a = ftype(a);
    char *type_b = ftype(b);
    if ((type_a - a) == (type_b - b)) {
	if (type_a == a) {
	    result = SameString(a, b);
	} else {
	    if (caseless) {
		if (!strncasecmp(a, b, (size_t) (type_a - a)))
		    result = TRUE;
	    } else {
		if (!strncmp(a, b, (size_t) (type_a - a)))
		    result = TRUE;
	    }
	}
    }
    return result;
}