Exemple #1
0
void Tree4::_ComputeSize( const Configuration& config )
{
  int h;

  _k = config.GetInt( "k" );
  _n = config.GetInt( "n" );

  assert( _k == 4 && _n == 3 );
  
  gK = _k; gN = _n;
  
  _sources = powi( _k, _n );
  _dests   = powi( _k, _n );
  
  _speedup = new int[_n];
  _speedup[0] = _k;
  _speedup[1] = _k / 2;
  _speedup[2] = _k / 4;

  _size = 0;
  for ( h = 0; h < _n; ++h ) 
    _size += _speedup[h] * powi( _k, h );

  _channels = 2                  // Two Channels per Connection
    * _speedup[1] * powi( _k, 1) // Number of Middle Routers
    * ( 2 * _k );                // Connectivity of Middle Routers
}
void BezierBoundarySolver::Solve(BoundaryProblem *pProblem)
{
    //double time = Tic();
    BezierBoundaryProblem* bezierProblem = (BezierBoundaryProblem*)pProblem;

    //find the distance between the start and finish
    double dist = sqrt(powi(pProblem->m_dGoalPose[0],2) + powi(pProblem->m_dGoalPose[1],2));
    bezierProblem->m_dSegLength = dist/g_nAggressivenessDivisor;
    //first get the guess bezier
    if(bezierProblem->m_bSolved == false){

    }

    bezierProblem->m_dSegLength = std::max(1e-2,std::min(bezierProblem->m_dSegLength,dist/2));

    bezierProblem->m_dParams = Eigen::Vector4d(bezierProblem->m_dSegLength,bezierProblem->m_dSegLength,bezierProblem->m_dSegLength,bezierProblem->m_dSegLength);
    _Get5thOrderBezier(bezierProblem,bezierProblem->m_dParams);

    //and now sample it
    _Sample5thOrderBezier(bezierProblem);

    //now iterate to reduce curvature
    if(bezierProblem->m_bSolved == false){
        //_IterateCurvatureReduction(bezierProblem,bezierProblem->m_dParams);
        //_IterateCurvatureReduction(bezierProblem,bezierProblem->m_dParams);
    }

    //indicate that the problem has been solved
    bezierProblem->m_bSolved = true;

    //dout("2D solve with goal " << bezierProblem->m_dGoalPose.transpose() <<" took " << Toc(time) << " seconds.");
}
Exemple #3
0
/**
 * Alloue l'espace mémoire nécessaire à la matrice.
 * Initialise toutes les cases à 0 sauf la plaque interne.
 * */
MAT init() {
    // Allouer la place pour la matrice
	mat =  malloc(sizeof(float) * TAILLE_MATRICE * TAILLE_MATRICE);
    // Initialisation de la matrice à 0 partout
    for (int i =0; i<TAILLE_MATRICE; i++) {
        for (int j=0; j<TAILLE_MATRICE; j++) {
            mat[i] = (float *) malloc(sizeof(float) * TAILLE_MATRICE);
            mat[i][j] = 0;
        }
    }
    
    // Initialisation de la zone chauffée initialement
    int idMin =  powi(2,n-1) - powi(2,n-4);
    int idMax = powi(2,n-1) + powi(2,n-4);
    /*printf("id min : %d,  ",idMin);
    printf("id max : %d\n",idMax);*/
    for (int i =  idMin ; i < idMax  ; i++) {
        for (int j =  idMin  ; j <  idMax ; j++) {
            mat[i][j] = TEMP_CHAUD;
        }
    }
    
    //~ mat[TAILLE_MATRICE/2][TAILLE_MATRICE/2] = TEMP_CHAUD;
    current = mat;

	return mat;
}
Exemple #4
0
bool itstr(char *buffer, int buffer_len, int n, int z, int lz) {
    if (z > 1 && z <= sizeof(tokenChars)) {
        int k;
        int size, i, s;
        int pointer = 0;

        s = logi(n, z);

        if (lz > s)
            size = lz;
        else
            size = s;

        if (buffer_len < size) {
            return false;
        }

        for (i = lz - s; i > 0; i--) {
            buffer[pointer++] = '0';
        }

        for (i = s - 1; i >= 0; i--) {
            k = n / powi(z, i);
            buffer[pointer++] = tokenChars[k];
            n -= k * powi(z, i);
        }

        buffer[pointer] = 0;

        return true;
    }

    return false;
}
void FlatFlyOnChip::_ComputeSize( const Configuration &config )
{
  _k = config.GetInt( "k" );	// # of routers per dimension
  _n = config.GetInt( "n" );	// dimension
  _c = config.GetInt( "c" );    //concentration, may be different from k
  _r = _c + (_k-1)*_n ;		// total radix of the switch  ( # of inputs/outputs)

  //how many routers in the x or y direction
  _xcount = config.GetInt("x");
  _ycount = config.GetInt("y");
  assert(_xcount == _ycount);
  //configuration of hohw many clients in X and Y per router
  _xrouter = config.GetInt("xr");
  _yrouter = config.GetInt("yr");
  assert(_xrouter == _yrouter);
  gK = _k; 
  gN = _n;
  gC = _c;
  
  assert(_c == _xrouter*_yrouter);

  _sources = powi( _k, _n )*_c;   //network size
  _dests   = powi( _k, _n )*_c;

  _num_of_switch = _sources / _c;
  _channels = _num_of_switch * (_r - _c); 
  _size = _num_of_switch;

}
void badd(int b, int x)
{
	int m=0;
	//printf("%f", pow (t,d));
	
	while ( powi(b,m) <= x) //x<(int)pow(b,n+1))
	{
		m++;
		//printf("%i %li\n",m, powi(b,m));
	}
	int N=m-1;
	
	while (N>=0)
	{
		//printf("\nN=%i\n",N);
		if (powi(b,N)<=x)
		{
			int s=0;
			while ( s*powi(b,N) <= x) //x<(int)pow(b,n+1))
			{
				s++;
				//printf("%i %li\n",m, powi(b,m));
			}
			printf("%i", s-1);
			x=x-(s-1)*powi(b,N);
			N--;
		}
		else
		{
			printf("0");
			N--;
		
		}
	}
}
void BezierBoundarySolver::_Get5thOrderBezier(BezierBoundaryProblem *pProblem,const Eigen::Vector4d& params)
{
    //the order of the bezier
    const double n = 5.0;

    //calculate the offsets
    const double a1 = params[0];
    const double b1 = params[1];
    const double a2 = params[2];
    const double b2 = params[3];

    //create the handle x and y arrays

    pProblem->m_xVals = Eigen::VectorXd(n+1);
    pProblem->m_yVals = Eigen::VectorXd(n+1);

    const double kInit = pProblem->m_dStartPose[3] / pProblem->m_dAggressiveness;
    const double tGoal = pProblem->m_dGoalPose[2];
    const double kGoal = pProblem->m_dGoalPose[3] / pProblem->m_dAggressiveness;
    //dout("Getting b-curve with goal curvature of " << kGoal);

    //here we're assuming that tInit is always 0
    //so create a rotation matrix for the end goal
    Eigen::Matrix2d Rgoal;
    const double ct = cos(tGoal);
    const double st = sin(tGoal);
    Rgoal << ct, -st,
             st, ct;

    //set the starting point
    pProblem->m_xVals[0] = pProblem->m_yVals[0] = 0;

    //offset the second point knowing that tInit = 0
    pProblem->m_xVals[1] = a1;
    pProblem->m_yVals[1] = 0;

    //offset the third point using the initial curvature
    double h = kInit*powi(a1,2)*(n/(n+1));
    pProblem->m_xVals[2] = pProblem->m_xVals[1] + b1;
    pProblem->m_yVals[2] = pProblem->m_yVals[1] + h;

    //and now set the end points
    pProblem->m_xVals[5] = pProblem->m_dGoalPose[0];
    pProblem->m_yVals[5] = pProblem->m_dGoalPose[1];

    //calculate the offset
    Eigen::Vector2d offset(-a2,0);
    offset = Rgoal * offset;
    pProblem->m_xVals[4] = pProblem->m_xVals[5] + offset[0];
    pProblem->m_yVals[4] = pProblem->m_yVals[5] + offset[1];

    //calculate the final point using last curvature
    h = kGoal*powi(a2,2)*(n/(n+1.0));
    offset << -b2, -h;
    offset = Rgoal * offset;
    pProblem->m_xVals[3] = pProblem->m_xVals[4] + offset[0];
    pProblem->m_yVals[3] = pProblem->m_yVals[4] + offset[1];

}
Exemple #8
0
int QTree::_OutputIndex( int height, int pos, int port )
{
  assert( height >= 0 && height < powi( _k,_n-1 ) );
  int c = _channels / 2;
  for ( int h = 0; h < height; h++) 
    c += powi( _k, h+1 );
  return ( c + _k * pos + port );
}
Exemple #9
0
CMeshX2::CMeshX2( const Configuration &config, const string & name )
    : Network( config, name )
{

    _subMesh[0] = new CMesh( config, name );
    _subMesh[1] = new CMesh( config, name );

    int k = config.GetInt( "k" ) ;
    int n = config.GetInt( "n" ) ;
    int c = config.GetInt( "c" ) ;


    gK = _k = k ;
    gN = _n = n ;
    gC = _c = c ;

    _sources  = _c * powi( _k, _n); // Source nodes in network
    _dests    = _c * powi( _k, _n); // Destination nodes in network
    _size     = powi( _k, _n);      // Number of routers in network
    _channels = 0;

    _f_read_history = new int[_sources];
    _c_read_history = new int[_dests];

    for (int i = 0; i < _size; i++) {
        _f_read_history[i] = 0;
        _c_read_history[i] = 0;
    }

    _subNetAssignment[Flit::READ_REQUEST]
        = config.GetInt( "read_request_subnet" );
    assert( _subNetAssignment[Flit::READ_REQUEST] == 0 ||
            _subNetAssignment[Flit::READ_REQUEST] == 1);

    _subNetAssignment[Flit::READ_REPLY]
        = config.GetInt( "read_reply_subnet" );
    assert( _subNetAssignment[Flit::READ_REPLY] == 0 ||
            _subNetAssignment[Flit::READ_REPLY] == 1 );

    _subNetAssignment[Flit::WRITE_REQUEST]
        = config.GetInt( "write_request_subnet" );
    assert( _subNetAssignment[Flit::WRITE_REQUEST] == 0 ||
            _subNetAssignment[Flit::WRITE_REQUEST] == 1);

    _subNetAssignment[Flit::WRITE_REPLY]
        = config.GetInt( "write_reply_subnet" );
    assert( _subNetAssignment[Flit::WRITE_REPLY] == 0 ||
            _subNetAssignment[Flit::WRITE_REPLY] == 1 );

}
Exemple #10
0
void MECS::_ComputeSize( const Configuration &config ) {
  _k = config.GetInt( "k" );	// # of routers per dimension
  _n = config.GetInt( "n" );	// dimension
  _c = config.GetInt( "c" );    //concentration, may be different from k

  xcount = config.GetInt("x");  //how many routers in the x or y direction
  ycount = config.GetInt("y");

  xrouter = config.GetInt("xr");  //configuration of hohw many clients in X and Y per router
  yrouter = config.GetInt("yr");


  //only support this configuration right now
  //need to extend to 256 nodes
  assert(_k ==4 && _n ==2 && _c == 4);

  _r = _c+4; //, chanenls are combined pior to entering the router
  gK = _k; 
  gN = _n;
  gC = _c;

  //standard traffic pattern shennanigin
  string fn;
  config.GetStr( "traffic", fn, "none" );
  if(fn.compare("neighbor")==0 || fn.compare("tornado")==0){
    realgk = 8;
    realgn = 2;
  } else {
    realgk = _k;
    realgn = _n;
  }

  _sources = powi( _k, _n )*_c;   //network size
  _dests   = powi( _k, _n )*_c;

  _num_of_switch = _sources / _c;
  //k-1 channels  per dimension per router, 
  //add 4 channels go from forwarder to the routers
  //yes, some of the channels will be forever idle in the corner routers
  _channels = _num_of_switch * ((_k-1)*_n+4);
  _channels_per_router =  ((_k-1)*_n+4);
  _size = _num_of_switch;

  cout<<"MECS"<<endl;
  cout<<"Number of sources "<<_sources<<endl;
  cout<<"Number of routers "<<_num_of_switch<<endl;
  cout<<"NUmber of channels "<<_channels<<endl;

}
void KNFly::_ComputeSize( const Configuration &config )
{
  _k = config.GetInt( "k" );
  _n = config.GetInt( "n" );

  gK = _k; gN = _n;

  _nodes = powi( _k, _n );

  // n stages of k^(n-1) k x k switches
  _size     = _n*powi( _k, _n-1 );

  // n-1 sets of wiring between the stages
  _channels = (_n-1)*_nodes;
}
Exemple #12
0
int QTree::_RouterIndex( int height, int pos ) 
{
  int r = 0;
  for ( int h = 0; h < height; h++ ) 
    r += powi( _k, h );
  return (r + pos);
}
long long int powi(long long int basis, long long int exp)
{
	if (exp>0)
		return powi(basis,exp-1)*basis;
	else
		return 1;
}
Exemple #14
0
int main(int argc, char *argv[]) {
	FILE *fp;
	char c;
	int j, n[13];

	if (argc != 2) {
		printf("Usage: %s [FILE]\n", argv[0]);
		return 1;
	}
	fp = fopen(*++argv, "r");
	while ((c = getc(fp)) != EOF) {
		int i = 0, u = 0;
		while (c != '\n' && c != EOF) {
			n[i++] = c - '0';
			c = getc(fp);
		}
		for (j = 0; j < powi(3, i - 1); j++) {
			if (ugly(j, i, n))
				u++;
		}

		printf("%d\n", u);
	}
	return 0;
}
Exemple #15
0
void findNandK(){
    countAidx = countBidx = 1;
    for(T = B,i = 0; T != 1; i++)
        if(!(T%primes[i])){
            countB[countBidx] = 0;
            while(!(T%primes[i])){
                T/=primes[i];
                countB[countBidx]++;
            }
            factB[countBidx++] = primes[i];
        }
    if(countBidx-1){ 
        for(T = A,i = 0; T != 1; i++)
            if(!(T%primes[i])){
                countA[countAidx] = 0;
                while(!(T%primes[i])){
                    T/=primes[i];
                    countA[countAidx]++;
                }
                factA[countAidx++] = primes[i];
            }    
        k = countA[1];
        for(i = countAidx-1; i; i--) k = gcdT[k][countA[i]];
        for(i = countBidx-1; i; i--) k = gcdT[k][countB[i]];
    }
    N = 1;
    for(i = countBidx-1; i; i--) N *= powi(factB[i], countB[i] / k);
}
Exemple #16
0
void shadowInit(BoardData3d *bd3d, renderdata *prd)
{
	int i;
	GLint stencilBits;

	if (bd3d->shadowsInitialised)
		return;

	/* Darkness as percentage of ambient light */
	prd->dimness = ((prd->lightLevels[1] / 100.0f) * (100 - prd->shadowDarkness)) / 100;

	for (i = 0; i < NUM_OCC; i++)
		bd3d->Occluders[i].handle = 0;

	/* Check the stencil buffer is present */
	glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
	if (!stencilBits)
	{
		g_print("No stencil buffer - no shadows\n");
		return;
	}
	midStencilVal = powi(2, stencilBits - 1);
	glClearStencil(midStencilVal);

	bd3d->shadowsInitialised = TRUE;
}
Exemple #17
0
//=============================================================^M
// UGAL : find random node for load balancing
//=============================================================^M
int find_ran_intm (int src, int dest) {
  int _dim   = gN;
  int _dim_size;
  int _ran_dest = 0;
  int debug = 0;
  
  if (debug) 
    cout << " INTM node for  src: " << src << " dest: " <<dest << endl;
  
  src = (int) (src / gC);
  dest = (int) (dest / gC);
  
  _ran_dest = RandomInt(gC - 1);
  if (debug) cout << " ............ _ran_dest : " << _ran_dest << endl;
  for (int d=0;d < _dim; d++) {
    
    _dim_size = powi(gK, d)*gC;
    if ((src % gK) ==  (dest % gK)) {
      _ran_dest += (src % gK) * _dim_size;
      if (debug) 
	cout << "    share same dimension : " << d << " int node : " << _ran_dest << " src ID : " << src % gK << endl;
    } else {
      // src and dest are in the same dimension "d" + 1
      // ==> thus generate a random destination within
      _ran_dest += RandomInt(gK - 1) * _dim_size;
      if (debug) 
	cout << "    different  dimension : " << d << " int node : " << _ran_dest << " _dim_size: " << _dim_size << endl;
    }
    src = (int) (src / gK);
    dest = (int) (dest / gK);
  }
  
  if (debug) cout << " intermediate destination NODE: " << _ran_dest << endl;
  return _ran_dest;
}
void KNFly::_BuildNet( const Configuration &config )
{
  ostringstream router_name;

  int per_stage = powi( _k, _n-1 );

  int node = 0;
  int c;

  for ( int stage = 0; stage < _n; ++stage ) {
    for ( int addr = 0; addr < per_stage; ++addr ) {

      router_name << "router_" << stage << "_" << addr;
      _routers[node] = Router::NewRouter( config, this, router_name.str( ), 
					  node, _k, _k );
      _timed_modules.push_back(_routers[node]);
      router_name.str("");

#ifdef DEBUG_FLY
      cout << "connecting node " << node << " to:" << endl;
#endif 

      for ( int port = 0; port < _k; ++port ) {
	// Input connections
	if ( stage == 0 ) {
	  c = addr*_k + port;
	  _routers[node]->AddInputChannel( _inject[c], _inject_cred[c] );
#ifdef DEBUG_FLY	  
	  cout << "  injection channel " << c << endl;
#endif 
	} else {
	  c = _InChannel( stage, addr, port );
	  _routers[node]->AddInputChannel( _chan[c], _chan_cred[c] );
	  _chan[c]->SetLatency( 1 );

#ifdef DEBUG_FLY
	  cout << "  input channel " << c << endl;
#endif 
	}

	// Output connections
	if ( stage == _n - 1 ) {
	  c = addr*_k + port;
	  _routers[node]->AddOutputChannel( _eject[c], _eject_cred[c] );
#ifdef DEBUG_FLY
	  cout << "  ejection channel " << c << endl;
#endif 
	} else {
	  c = _OutChannel( stage, addr, port );
	  _routers[node]->AddOutputChannel( _chan[c], _chan_cred[c] );
#ifdef DEBUG_FLY
	  cout << "  output channel " << c << endl;
#endif 
	}
      }

      ++node;
    }
  }
}
Exemple #19
0
//=============================================================^M
// UGAL : calculate distance (hop cnt)  between src and destination
//=============================================================^M
int find_distance (int src, int dest) {
  int dist = 0;
  int _dim   = gN;
  int _dim_size;
  
  int src_tmp= (int) src / gC;
  int dest_tmp = (int) dest / gC;
  int src_id, dest_id;
  
  //  cout << " HOP CNT between  src: " << src << " dest: " << dest;
  for (int d=0;d < _dim; d++) {
    _dim_size = powi(gK, d )*gC;
    //if ((int)(src / _dim_size) !=  (int)(dest / _dim_size))
    //   dist++;
    src_id = src_tmp % gK;
    dest_id = dest_tmp % gK;
    if (src_id !=  dest_id)
      dist++;
    src_tmp = (int) (src_tmp / gK);
    dest_tmp = (int) (dest_tmp / gK);
  }
  
  //  cout << " : " << dist << endl;
  
  return dist;
}
Exemple #20
0
int flatfly_outport_yx(int dest, int rID) {
  int dest_rID;
  int _dim   = gN;
  int output = -1, dID, sID;
  
  dest_rID = (int) (dest / gC);
  
  if(dest_rID==rID){
    return dest  - rID*gC;
  }

  for (int d=_dim-1;d >= 0; d--) {
    int power = powi(gK,d);
    dID = int(dest_rID / power);
    sID = int(rID / power);
    if ( dID != sID ) {
      output = gC + ((gK-1)*d) - 1;
      if (dID > sID) {
	output += dID;
      } else {
	output += dID + 1;
      }
      return output;
    }
    dest_rID = (int) (dest_rID %power);
    rID      = (int) (rID %power);
  }
  if (output == -1) {
    cout << " ERROR ---- FLATFLY_OUTPORT function : output not found yx" << endl;
    exit(-1);
  }
  return -1;
}
void FatTree::_ComputeSize(const Configuration& config) {

  _k = config.GetInt("k");
  _n = config.GetInt("n");

  gK = _k;
  gN = _n;

  _nodes = powi(_k, _n);

  //levels * routers_per_level
  _size = _n * powi(_k, _n - 1);

  //(channels per level = k*routers_per_level* up/down) * (levels-1)
  _channels = (2 * _k * powi(_k, _n - 1)) * (_n - 1);

}
Exemple #22
0
double Kernel::k_function(const svm_node *x, const svm_node *y,
			  const svm_parameter& param)
{
  switch(param.kernel_type)
    {
    case LINEAR:
      return dot(x,y);
    case POLY:
      return powi(param.gamma*dot(x,y)+param.coef0,param.degree);
    case RBF:
      {
	double sum = 0;
	while(x->index != -1 && y->index !=-1)
	  {
	    if(x->index == y->index)
	      {
		double d = x->value - y->value;
		sum += d*d;
		++x;
		++y;
	      }
	    else
	      {
		if(x->index > y->index)
		  {	
		    sum += y->value * y->value;
		    ++y;
		  }
		else
		  {
		    sum += x->value * x->value;
		    ++x;
		  }
	      }
	  }

	while(x->index != -1)
	  {
	    sum += x->value * x->value;
	    ++x;
	  }

	while(y->index != -1)
	  {
	    sum += y->value * y->value;
	    ++y;
	  }
			
	return exp(-param.gamma*sum);
      }
    case SIGMOID:
      return tanh(param.gamma*dot(x,y)+param.coef0);
    case PRECOMPUTED:  //x: test (validation), y: SV
      return x[(int)(y->value)].value;
    default:
      return 0;  // Unreachable 
    }
}
void DragonFlyNew::_ComputeSize( const Configuration &config )
{

  // LIMITATION
  //  -- only one dimension between the group
  // _n == # of dimensions within a group
  // _p == # of processors within a router
  // inter-group ports : _p
  // terminal ports : _p
  // intra-group ports : 2*_p - 1
  _p = config.GetInt( "k" );	// # of ports in each switch
  _n = config.GetInt( "n" );


  assert(_n==1);
  // dimension

  if (_n == 1)
    _k = _p + _p + 2*_p  - 1;
  else
    _k = _p + _p + 2*_p;

  
  // FIX...
  gK = _p; gN = _n;

  // with 1 dimension, total of 2p routers per group
  // N = 2p * p * (2p^2 + 1)
  // a = # of routers per group
  //   = 2p (if n = 1)
  //   = p^(n) (if n > 2)
  //  g = # of groups
  //    = a * p + 1
  // N = a * p * g;
  
  if (_n == 1)
    _a = 2 * _p;
  else
    _a = powi(_p, _n);

  _g = _a * _p + 1;
  _nodes   = _a * _p * _g;

  _num_of_switch = _nodes / _p;
  _channels = _num_of_switch * (_k - _p); 
  _size = _num_of_switch;


  
  gG = _g;
  gP = _p;
  gA = _a;
  _grp_num_routers = gA;
  _grp_num_nodes =_grp_num_routers*gP;

}
Exemple #24
0
void KNCube::_ComputeSize( const Configuration &config )
{
  _k = config.GetInt( "k" );
  _n = config.GetInt( "n" );

  gK = _k; gN = _n;
  _size     = powi( _k, _n );
  _channels = 2*_n*_size;//each node has 2  channels on every dimension, thus the result is total unidirectional channel count

  _nodes = _size;
}
Exemple #25
0
void KNCube::_ComputeSize( const Configuration &config )
{
  _k = config.GetInt( "k" );
  _n = config.GetInt( "n" );

  gK = _k; gN = _n;
  _size     = powi( _k, _n );
  _channels = 2*_n*_size;

  _nodes = _size;
}
Exemple #26
0
void QTree::_ComputeSize( const Configuration& config )
{

  _k = config.GetInt( "k" );
  _n = config.GetInt( "n" );

  assert( _k == 4 && _n == 3 );

  gK = _k; gN = _n;

  _nodes = powi( _k, _n );

  _size = 0;
  for (int i = 0; i < _n; i++)
    _size += powi( _k, i );

  _channels = 0;
  for (int j = 1; j < _n; j++)
    _channels += 2 * powi( _k, j );

}
Exemple #27
0
void butterworth_bandpass_filter_create(
        int n, double f1, double f2, double coeffs[2*n], double* mul)
{
    assert(0  < f1);
    assert(f1 < f2);
    assert(f2 < 0.5);
    assert(n > 0);
    assert(coeffs != NULL);
    assert(mul != NULL);

    //    static int created = 0;
    //    fprintf(stderr, "  %d \n", ++created);

    const double ss2 = sin(2 * PI * f1) * sin(2 * PI * f2);
    const double sp = sin(PI * (f2 + f1));
    const double sm = sin(PI * (f2 - f1));
    const double cp = cos(PI * (f2 + f1));
    const double cm = cos(PI * (f2 - f1));
    double a0 = 1.0;

    for (int i = 0; i < n / 2; i++)
    {
        const double si = sin(PI / 2 / n * (2 * i + 1));
        const double x = safe_sqrt((sp * sp) * (sp * sp) - 4 * (sm * sm) * ss2 * (si * si));
        const double y = (sm * sm + x) / ss2;
        const double z = sm * safe_sqrt(ss2 / (sp * sp + x) * 2) * si;
        const double ap = safe_sqrt((y + 1) / 2);
        const double am = safe_sqrt((y - 1) / 2);

        const double a0_1_temp =  cm * ap - cp * am + z             ;
        coeffs[0]        =       (cm * ap - cp * am - z) / a0_1_temp;
        coeffs[1]        = - 2 * (cp * ap - cm * am)     / a0_1_temp;

        const double a0_2_temp =  cm * ap + cp * am + z             ;
        coeffs[2]        =       (cm * ap + cp * am - z) / a0_2_temp;
        coeffs[3]        = - 2 * (cp * ap + cm * am)     / a0_2_temp;

        a0 *= a0_1_temp * a0_2_temp;
    }

    if ((n & 1) != 0)
    {
        const double a0_temp =  cm + sm           ;
        coeffs[2*n-2]        = (cm - sm) / a0_temp;
        coeffs[2*n-1]        = - 2 * cp  / a0_temp;
        a0 *= a0_temp;
    }

    *mul = powi(sm, n) /a0;

    return;
}
Exemple #28
0
void polynomial_fast(double *x, double *y, const int rows_x, const int rows_y, const int cols, double *out, double alpha, double c, int degree) {
    int i, j, k;
    double cur_sum, *cur_x, *cur_y;
    for (i = 0; i < rows_x; ++i)
        for (j = 0; j < rows_y; ++j) {
            cur_sum = 0.;
            cur_x = x + i * cols;
            cur_y = y + j * cols;
            for (k = 0; k < cols; ++k)
                cur_sum += cur_x[k] * cur_y[k];
            out[i * rows_y + j] = powi(alpha * cur_sum + c, degree);
        }
}
Exemple #29
0
int KNCube::_RightNode( int node, int dim )
{
  int k_to_dim = powi( _k, dim );
  int loc_in_dim = ( node / k_to_dim ) % _k;
  int right_node;
  // if at the right edge of the dimension, wraparound
  if ( loc_in_dim == ( _k-1 ) ) {
    right_node = node - (_k-1)*k_to_dim;
  } else {
    right_node = node + k_to_dim;
  }

  return right_node;
}
Exemple #30
0
int KNCube::_LeftNode( int node, int dim )
{
  int k_to_dim = powi( _k, dim );
  int loc_in_dim = ( node / k_to_dim ) % _k;
  int left_node;
  // if at the left edge of the dimension, wraparound
  if ( loc_in_dim == 0 ) {
    left_node = node + (_k-1)*k_to_dim;
  } else {
    left_node = node - k_to_dim;
  }

  return left_node;
}