Beispiel #1
0
Float MicrofacetDistribution::Pdf(const Vector3f &wo,
                                  const Vector3f &wh) const {
    if (sampleVisibleArea)
        return D(wh) * G1(wo) * AbsDot(wo, wh) / AbsCosTheta(wo);
    else
        return D(wh) * AbsCosTheta(wh);
}
Beispiel #2
0
	void EpsilonVor::WriteIt(std::ofstream & fout) const {
		if(!Parallel::comm->Get_Rank()){
			fout.write((char *) &nnx, sizeof nnx);
			fout.write((char *) &nny, sizeof nny);
			fout.write((char *) &nnz, sizeof nnz);
			fout.write((char *) &co, sizeof co);
			fout.write((char *) &co, sizeof oc);
			fout.write((char *) &nresid, sizeof nresid);
			stringstream iss;
			for(int i=0;i<ResLabel.size();i++)
				i==ResLabel.size()?iss << ResLabel[i]:iss << ResLabel[i] << " ";

			string token=iss.str();
			int ntoken=token.size();
			const char * css=new char [ntoken];
			css=token.c_str();
			fout.write((char *) &ntoken, sizeof ntoken);
			fout.write(css, (sizeof css[0])*ntoken);
		}
		Parallel::comm->Barrier();
		vector<Matrix> D1(D);
		vector<Matrix> G1(G);
		vector<Dvect>  M1(M);
		vector<Dvect>  E1(E);
		vector<double> Vols(VoroVol);
		vector<string> lab(ResLabel);
		Dvect M1_avg=M_avg;

		int Tcount=TotalCount;
		Parallel::comm->ReduceSum(&Tcount,1);
		if(!Parallel::comm->Get_Rank())	fout.write((char *) &Tcount, sizeof Tcount);
		Parallel::comm->ReduceSum(&M1_avg[0],DIM);
		Parallel::comm->ReduceSum(&Vols[0],nresid);
		Parallel::comm->ReduceSum(&D1[0][0][0],DIM*DIM*nresid);
		Parallel::comm->ReduceSum(&G1[0][0][0],DIM*DIM*nresid);
		Parallel::comm->ReduceSum(&M1[0][0],DIM*nresid);
		Parallel::comm->ReduceSum(&E1[0][0],DIM*nresid);
		if(!Parallel::comm->Get_Rank())	{
			double fact0=1.0/static_cast<double> (Tcount);
			M1_avg*=fact0;
			for(int i=0;i<nresid;i++){
				double fact1=1.0/static_cast<double> (Tcount);
				Vols[i]*=fact1;
				D1[i]*=fact1;
				G1[i]*=fact1;
				M1[i]*=fact1;
				E1[i]*=fact1;
			}

			fout.write((char *) &M1_avg[0], (sizeof M1_avg[0])*DIM);
			fout.write((char *) &Vols[0], (sizeof Vols[0])*nresid);
			fout.write((char *) &D1[0][0][0], (sizeof D1[0][0][0])*DIM*DIM*nresid);
			fout.write((char *) &G1[0][0][0], (sizeof G1[0][0][0])*DIM*DIM*nresid);
			fout.write((char *) &M1[0][0], (sizeof M1[0][0])*DIM*nresid);
			fout.write((char *) &E1[0][0], (sizeof E1[0][0])*DIM*nresid);
		}
		Parallel::comm->Barrier();
	}
Beispiel #3
0
static bool evalLocalAxes (const Vec3& dX, const Vec3& ddX,
                           Vec3& B, Vec3& N, double& B_len, double& N_len)
{
  B.cross(dX,ddX); // {B} = d{X} x dd{X}
  B_len = B.length();
  if (B_len < 1.0e-12)
  {
    // The cable is straigth, need to modify vector ddX

    Vec3 G1(dX);
    double normG1 = dX.length();
    G1 *= 1.0/(normG1*normG1); // Contra-variant basis vector

    B.cross(dX, ddX - (ddX*G1) * G1);
    B_len = B.length();
    if (B_len < 1.0e-10)
    {
      B.cross(dX, Vec3(-dX.y,dX.x,0.0));
      B_len = B.length();
      if (B_len < 1.0e-10)
      {
        // Last resort: Use algorithm from Tensor(const Vec3&) constructor
        if (fabs(dX.y) < fabs(dX.z))
        {
          // Define the normal vector, N, by projecting the global Y-axis
          // onto the normal plane of the tangent direction, dX
          N.x = -dX.y*dX.x;
          N.y =  dX.x*dX.x + dX.z*dX.z;
          N.z = -dX.y*dX.z;
          // Define the binormal vector B as the cross product of dX and N
          B.cross(dX,N);
        }
        else
        {
          // Define the binormal vector by projecting the global Z-axis
          // onto the normal plane of the tangent direction, dX
          B.x = -dX.z*dX.x;
          B.y = -dX.z*dX.y;
          B.z =  dX.x*dX.x + dX.y*dX.y;
        }
        B_len = B.length();
        if (B_len < 1.0e-10)
        {
          std::cerr <<" *** ElasticCable: Degenerated element, dX="<< dX
                    << std::endl;
          return false;
        }
      }
    }
  }

  B *= 1.0/B_len; // Unit binormal vector: {B}
  N.cross(B,dX);  // {N} = {B} x d{X}
  N_len = N.normalize(); // Unit normal vector: {N}

  return true;
}
Beispiel #4
0
int main(int argc, char** argv) {
	Giornale G1(12.50, "Titolo1", false);
	Giornale G2(1.50, "Titolo2", true);
	Giornale G3(2.00, "Titolo3", false);
	Rivista R4(22.70, "Titolo4", false, "Editore4", "Periodo4");
	Rivista R5(11.50, "Titolo5", true, "Editore5", "Periodo5");
	Rivista R6(6.00, "Titolo6", false,  "Editore6", "Periodo6");
	Quotidiano Q7(6.35, "Titolo7", false, "Direttore7", true);
	Quotidiano Q8(9.99, "Titolo8", true, "Direttore8", false);
	Quotidiano Q9(5, "Titolo9", false, "Direttore9", true);
	
	cout<<"Polimorfismo:\n";
	Giornale * vett[9];
	vett[0] = &G1;
	vett[1] = &G2;
	vett[2] = &G3;
	vett[3] = &R4;
	vett[4] = &R5;
	vett[5] = &R6;
	vett[6] = &Q7;
	vett[7] = &Q8;
	vett[8] = &Q9;
	
	for(int i=0; i<9; i++) {
		cout << *vett[i] << "\n\n";
	}
	
	cout<<"\n\nPila:\n";
	Pila P;
	for(int i=0; i<9; i++) {
		P.push(vett[i]);
	}
	cout<<P;
	
	ofstream file;
	file.open("./test.txt", ios::out);
	if(!file) {
		cout<<"Errore apertura file.";
	} else {
		file << P;
	}
	file.close();
	
	Rivista R10(1.00, "Titolo10", false,  "Editore10", "Periodo10");
	Quotidiano Q11(1.35, "Titolo11", false, "Direttore11", true);
	
	P.push(&R10);
	
	cout<<"\n\nEccezione:\n";
	try {
		P.push(&Q11);
	} catch(SpaceOverflow e) {
		cout<<e.errorLog();
	}
	return 0;
}
int test_string_cast_vector()
{
	int Error = 0;
	
	glm::vec2 A1(1, 2);
	std::string A2 = glm::to_string(A1);
	Error += A2 != std::string("fvec2(1.000000, 2.000000)") ? 1 : 0;
	
	glm::vec3 B1(1, 2, 3);
	std::string B2 = glm::to_string(B1);
	Error += B2 != std::string("fvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;

	glm::vec4 C1(1, 2, 3, 4);
	std::string C2 = glm::to_string(C1);
	Error += C2 != std::string("fvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
	
	glm::ivec2 D1(1, 2);
	std::string D2 = glm::to_string(D1);
	Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
	
	glm::ivec3 E1(1, 2, 3);
	std::string E2 = glm::to_string(E1);
	Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
	
	glm::ivec4 F1(1, 2, 3, 4);
	std::string F2 = glm::to_string(F1);
	Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
	
	glm::hvec2 G1(1, 2);
	std::string G2 = glm::to_string(G1);
	Error += G2 != std::string("hvec2(1.0000, 2.0000)") ? 1 : 0;
	
	glm::hvec3 H1(1, 2, 3);
	std::string H2 = glm::to_string(H1);
	Error += H2 != std::string("hvec3(1.0000, 2.0000, 3.0000)") ? 1 : 0;
	
	glm::hvec4 I1(1, 2, 3, 4);
	std::string I2 = glm::to_string(I1);
	Error += I2 != std::string("hvec4(1.0000, 2.0000, 3.0000, 4.0000)") ? 1 : 0;
	
	glm::dvec2 J1(1, 2);
	std::string J2 = glm::to_string(J1);
	Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
	
	glm::dvec3 K1(1, 2, 3);
	std::string K2 = glm::to_string(K1);
	Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
	
	glm::dvec4 L1(1, 2, 3, 4);
	std::string L2 = glm::to_string(L1);
	Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
	
	return Error;
}
Beispiel #6
0
static
V
calc_edge_score(const boost::multi_array<V,2>& si_subst,
		const std::vector<V>& gap,
		const Data& xx, const Data& yy,
		uint x_i, uint x_j, uint y_i, uint y_j)
{
  typedef V value_type;
  typedef typename Data::Seq Seq;
  typedef boost::multi_array<value_type,2> dp_type;
  const Seq& x(xx.seq);
  const Seq& y(yy.seq);
  const std::vector<float>& w_x(xx.weight);
  const std::vector<float>& w_y(yy.weight);
  uint sz_x = x_i<=x_j ? x_j-x_i+1 : 0;
  uint sz_y = y_i<=y_j ? y_j-y_i+1 : 0;

  if (sz_x==0) { return gap[sz_y]; }
  if (sz_y==0) { return gap[sz_x]; }

  dp_type K0(boost::extents[sz_x+1][sz_y+1]);
  dp_type G0(boost::extents[sz_x+1][sz_y+1]);
  std::vector<value_type> K1(sz_y+1);
  std::vector<value_type> G1(sz_y+1);

  K0[0][0] = G0[0][0] = 1.0;
  for (uint i=1; i!=sz_x+1; ++i) {
    K0[i][0] = 1.0;
    G0[i][0] = G0[i-1][0]*gap[1];
  }
  for (uint j=1; j!=sz_y+1; ++j) {
    K0[0][j] = 1.0;
    G0[0][j] = G0[0][j-1]*gap[1];
  }

  for (uint i=1; i!=sz_x+1; ++i) {
    K1[0] = G1[0] = 0.0;
    uint ii=x_i+i;
    for (uint j=1; j!=sz_y+1; ++j) {
      uint jj=y_i+j;
      value_type v = G0[i-1][j-1];
      v *= subst_score(si_subst,x[ii-1],y[jj-1]);
      v *= w_x[ii-1]*w_y[jj-1];
      K1[j] = v + K1[j-1];
      G1[j] = v + G1[j-1]*gap[1];
      K0[i][j] = K1[j] + K0[i-1][j];
      G0[i][j] = G1[j] + G0[i-1][j]*gap[1];
    }
  }

  return K0[sz_x][sz_y];
}
AbelianEquationsSolver::AbelianEquationsSolver( const AbelianGroup& a , 
						const VectorOf<Word>& v ,
						int numOfVar )
  : rawA( a ),
    A( FPGroup() ),
    rawSystem( v ),
    system( v.length() ),
    b( v.length() ),
    x( numOfVar ),
    torsion( numOfVar ),
    params( numOfVar ),
    numberOfVariables( numOfVar ),
    sysRank( 0 ),
    haveSol( -1 )
{
  FPGroup G( a.getFPGroup() );
  VectorOf<Chars> q( G.numberOfGenerators() - numberOfVariables );
  
  for( int i = numberOfVariables ; i < G.numberOfGenerators() ; i++ )
    q[ i - numberOfVariables ] = (G.namesOfGenerators())[i];
  
  if( G.getRelators().cardinality() )
    {
      SetOf<Word> s = G.getRelators();
      SetIterator<Word> I(s);
      SetOf<Word> news;
      
      while( !I.done() )
	{
	  Word w = I.value();
	  for( int j = 0 ; j < w.length() ; j++ )
	    {
	      int p = Generator( w[j] ).hash();
	      if( p > 0 )
		w[j] = Generator( p - numberOfVariables );
	      else
		w[j] = Generator( p + numberOfVariables );
	    }
	  
	  news.adjoinElement( w );
	  I.next();
	}
      
      FPGroup G1( q , news );
      
      A = AbelianGroup( G1 );
    }
  else
    A = AbelianGroup( FPGroup(q) );
  
}
Beispiel #8
0
    /* Nullify row k of L using the first rows as a lower triangle, supposing that 
     * LX = [ L ; X ], L of size MxM and lower triangular and k>M. */
    void leftGivens( const int k )
    {
      for( int j=rank-1; j>=0; --j )
	{
	  Givens G1(L.col(j),j,k);
	  G1.transpose() >> L;
	  if( m_computeFullU || m_computeThinU )
	    {
	      U << G1;
	    }
	  sotDEBUG(5) << "LX"<<j<<" = "<< (MATLAB)L << std::endl<< std::endl;
	}

    }
Beispiel #9
0
bool test(accelerator_view &rv)
{
    const int size = 100;

    vector<int> A(size);
    vector<s> G1(size);
    vector<int> G2(size);
    vector<double> G3(size);

    for(int i = 0; i < size; i++)
    {
        A[i] = INIT_VALUE;
        G1[i].i = 2;
        G1[i].d = 2;
        G1[i].ul = 2;
        G1[i].f = 2;
    }

    extent<1> e(size);

    array<int, 1> aA(e, A.begin(), rv);
    array<s, 1> aG1(e, G1.begin(), rv);
    array<int, 1> aG2(e, G2.begin(), rv);
    array<double, 1> aG3(e, G3.begin(), rv);

    parallel_for_each(aA.get_extent(), [&](index<1>idx) __GPU
    {
        s o;

        o.i = 2;
        o.d = 2;
        o.ul = 2;
        o.f = 2;

        const s o2 = o;

        const s* ps = 0;
        ps = &o2;

        if (!Equal(ps->i, 2) || !Equal(ps->d, (double)2) || !Equal(ps->ul, (unsigned long)2) || !Equal(ps->f, (float)2))
            aA[idx] = 1;

        const int i1 = 1;
        const int *pi1 = &i1;
        const double d1 = 1;
        const double *pd1 = &d1;

        if (!Equal(*pi1, (int)1) || !Equal(*pd1, (double)1))
            aA[idx] = 1;
    });
Beispiel #10
0
PetscReal ct_function(PetscReal theta_local, void * int_params)
{
	struct int_params * iparams = (struct int_params *)int_params;
	h_params hparams;	
	PetscReal result;
	PetscReal mu1,mu2,th1,x1,x2,k1,k2,aa;
	PetscReal mf2;
	PetscReal denom;
	PetscReal p_b3;

	mu1 = iparams->mu1;
	th1 = theta_local;
	mu2 = iparams->mu2;
	mf2 = iparams->mf*iparams->mf;
	p_b3=iparams->p_bohr[0]*iparams->p_bohr[0]*iparams->p_bohr[0]*8.0;//Should this be /8 or times 8?

	result = 0.0;
	
	x1 = (1.0 + mu1*th1/sqrt(mf2 + mu1*mu1))/2.0;	
	k1 = mu1*sqrt(1.0-th1*th1);
	x2 = iparams->x2;	
	k2 = iparams->k2;
	if (( std::fabs(x1-x2) >= 1e-8 || std::fabs(k1-k2) >= 1e-8 ) )
	{
	        aa = (x1-x2)*(x1-x2)*mf2/2.0*(1.0/(1.0-x2)/(1.0-x1)+1.0/x1/x2) + k1*k1 + k2*k2+ (x1-x2)/2.0*(k1*k1*(1.0/(1.0-x1)-1.0/x1)-k2*k2*(1.0/(1.0-x2)-1.0/x2));
        	denom = aa*aa-4.0*k1*k1*k2*k2;
	
		if( denom > 0.0 )
		{
			hparams.flag_asy=iparams->flag_asy;
			hparams.flag_perm=0;
			hparams.x1=x1;
			hparams.k1=k1;
			hparams.x2=x2;
			hparams.k2=k2;
			hparams.Jz=iparams->Jzc;
			hparams.m1=iparams->mf;
			hparams.m2=iparams->mf;
			hparams.A  = 1.0/sqrt(denom);
       			hparams.B  = (1.0-aa*hparams.A)/2.0;

			if (iparams->index_s==0 || iparams->index_s==3)   result = G1(&hparams);
			else		       result = G2(&hparams);
			result *= 2.0*mu1*mu1*x1*(1.0-x1)/sqrt(mf2 + mu1*mu1)/sqrt(mf2 + mu1*mu1)/sqrt(mf2 + mu1*mu1)*(1.0+mu2*mu2*mu2/p_b3)/(1.0+mu1*mu1*mu1/p_b3)/M_PI;
		}
	}
	return result;
}
Beispiel #11
0
int main(int argc, char* argv[]) {

  CGAL_assertion(argc==2);
  std::ifstream in1(argv[1]);
  
  Polyhedron P1;
  in1 >> P1;

  std::transform( P1.facets_begin(), P1.facets_end(), P1.planes_begin(),
		  Plane_equation());

  CGAL_assertion(is_strongly_convex_3(P1));

  Gausian_map G1(P1);
  G1.visualize();
}
Beispiel #12
0
int main()
{
    std_setup();
    
    ml_random rng;
    
    
    
    {
		// output analytic solution
		
        grid2D<double, double > F1( 500, -10.0, 10.0, 500, -10.0, 10.0 );
        grid2D<double, double > F2( F1 );
        grid2D<double, double > G1( F1 );
        grid2D<double, double > G2( F1 );
        
        F1 = V_1;
        F2 = V_2;
        
        laplacian_2d_hdaf Del2;
        Del2.init( F1.n1, F1.n2, F1.b1-F1.a1, F1.b2-F1.a2, 24, 24, .5, .5 );
        
        Del2.execute( F1.array, G1.array );
        Del2.execute( F2.array, G2.array );
        
        
        plotGrid2D_1( F1,  "/workspace/output/scratch/F1.png", color_map_green );
        plotGrid2D_1( F2,  "/workspace/output/scratch/F2.png", color_map_green );
        plotGrid2D_1( G1,  "/workspace/output/scratch/G1.png", color_map_error );
        plotGrid2D_1( G2,  "/workspace/output/scratch/G2.png", color_map_error );
	}
    
    
    
    
    
    
    std_exit();
}
Beispiel #13
0
/**
  * D = pathLength(G);

  * The distance matrix contains lengths of shortest paths between all
  * pairs of nodes. An entry (u,v) represents the length of shortest path
  * from node u to node v. The average shortest path length is the
  * characteristic path length of the network.

  *     Input:      G,      weighted directed/undirected connection matrix
  *     Output:     D,      distance matrix

  * The input matrix must be a mapping from weight to distance. For
  * instance, in a weighted correlation network, higher correlations are
  * more naturally interpreted as shorter distances, and the input matrix
  * should consequently be some inverse of the connectivity matrix.
  *    Lengths between disconnected nodes are set to Inf.
  *    Lengths on the main diagonal are set to 0.
  * Algorithm: Dijkstra's algorithm.
*/
mat Connectome::pathLength(const mat &G)
{
    uint n = G.n_rows,v=0;
    mat D = mat(n,n).fill(datum::inf), G1, t;
    D.diag().fill(0);
    uvec S, V, W, tt;
    for (uint u=0;u<n;++u) {
        S = linspace<uvec>(0,n-1,n);
        G1 = G;
        V = uvec(1).fill(u);

        while (true) {
            // instead of replacing indices by 0 like S(V)=0;
            // we declare all indices then remove the V indeces
            // from S. Notice that it is assured that tt should
            // be one element since indices don't repeat
            for (int i=0;i<V.n_elem;++i) {
                tt = find(S == V(i),1);
                if (!tt.is_empty())
                    S.shed_row(tt(0));
            }
            G1.cols(V).fill(0);
            for (uint j = 0;j<V.n_elem;++j) {
                v = V(j);
                W = find(G1.row(v)>0);
                D(uvec(1).fill(u),W) = arma::min(D(uvec(1).fill(u),W),
                                                 D(u,v)+G1(uvec(1).fill(v),W));
            }
            t = D(uvec(1).fill(u),S);
            if (t.is_empty() || !is_finite(t.min()))
                break;
            V = find( D.row(u) == t.min());
        }
    }
    return D;
}
Beispiel #14
0
void 
CAST5decrypt(const PGPUInt8 *in, PGPUInt8 *out, const PGPUInt32 *xkey)
{
	PGPUInt32 l, r, t;

	r = (PGPUInt32) in[0]<<24 | (PGPUInt32) in[1]<<16 | 
		(PGPUInt32) in[2]<<8 | in[3];

	l = (PGPUInt32) in[4]<<24 | (PGPUInt32) in[5]<<16 | 
		(PGPUInt32) in[6]<<8 | in[7];

	t = F1(l, xkey, 15); r ^= G1(t);
	t = F3(r, xkey, 14); l ^= G3(t);
	t = F2(l, xkey, 13); r ^= G2(t);
	t = F1(r, xkey, 12); l ^= G1(t);
	// Start here if only doing 12 rounds
	t = F3(l, xkey, 11); r ^= G3(t);
	t = F2(r, xkey, 10); l ^= G2(t);
	t = F1(l, xkey,  9); r ^= G1(t);
	t = F3(r, xkey,  8); l ^= G3(t);
	t = F2(l, xkey,  7); r ^= G2(t);
	t = F1(r, xkey,  6); l ^= G1(t);
	t = F3(l, xkey,  5); r ^= G3(t);
	t = F2(r, xkey,  4); l ^= G2(t);
	t = F1(l, xkey,  3); r ^= G1(t);
	t = F3(r, xkey,  2); l ^= G3(t);
	t = F2(l, xkey,  1); r ^= G2(t);
	t = F1(r, xkey,  0); l ^= G1(t);

	out[0]	= (PGPUInt8) B0(l);
	out[1]	= (PGPUInt8) B1(l);
	out[2]	= (PGPUInt8) B2(l);
	out[3]	= (PGPUInt8) B3(l);
	out[4]	= (PGPUInt8) B0(r);
	out[5]	= (PGPUInt8) B1(r);
	out[6]	= (PGPUInt8) B2(r);
	out[7]	= (PGPUInt8) B3(r);
}
Beispiel #15
0
/*
 * Encrypt the 8 bytes at *in into the 8 bytes at *out using the expanded
 * key schedule from *xkey.
 */
static void
CAST5encrypt(PGPByte const *in, PGPByte *out, PGPUInt32 const *xkey)
{
	PGPUInt32 l, r, t;

	l = (PGPUInt32)
		in[0]<<24 | (PGPUInt32)in[1]<<16 | (PGPUInt32)in[2]<<8 | in[3];
	r = (PGPUInt32)
		in[4]<<24 | (PGPUInt32)in[5]<<16 | (PGPUInt32)in[6]<<8 | in[7];

	t = F1(r, xkey,  0); l ^= G1(t);
	t = F2(l, xkey,  1); r ^= G2(t);
	t = F3(r, xkey,  2); l ^= G3(t);
	t = F1(l, xkey,  3); r ^= G1(t);
	t = F2(r, xkey,  4); l ^= G2(t);
	t = F3(l, xkey,  5); r ^= G3(t);
	t = F1(r, xkey,  6); l ^= G1(t);
	t = F2(l, xkey,  7); r ^= G2(t);
	t = F3(r, xkey,  8); l ^= G3(t);
	t = F1(l, xkey,  9); r ^= G1(t);
	t = F2(r, xkey, 10); l ^= G2(t);
	t = F3(l, xkey, 11); r ^= G3(t);
	/* Stop here if only doing 12 rounds */
	t = F1(r, xkey, 12); l ^= G1(t);
	t = F2(l, xkey, 13); r ^= G2(t);
	t = F3(r, xkey, 14); l ^= G3(t);
	t = F1(l, xkey, 15); r ^= G1(t);

	out[0] = B0(r);
	out[1] = B1(r);
	out[2] = B2(r);
	out[3] = B3(r);
	out[4] = B0(l);
	out[5] = B1(l);
	out[6] = B2(l);
	out[7] = B3(l);
}
  void SurfaceVectorGradient<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    for (std::size_t cell=0; cell < workset.numCells; ++cell) {
      for (std::size_t pt=0; pt < numQPs; ++pt) {
        Intrepid::Vector<ScalarT> g_0(3, &currentBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> g_1(3, &currentBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> g_2(3, &currentBasis(cell, pt, 2, 0));
        Intrepid::Vector<ScalarT> G_2(3, &refNormal(cell, pt, 0));
        Intrepid::Vector<ScalarT> d(3, &jump(cell, pt, 0));
        Intrepid::Vector<ScalarT> G0(3, &refDualBasis(cell, pt, 0, 0));
        Intrepid::Vector<ScalarT> G1(3, &refDualBasis(cell, pt, 1, 0));
        Intrepid::Vector<ScalarT> G2(3, &refDualBasis(cell, pt, 2, 0));

        Intrepid::Tensor<ScalarT>
        Fpar(Intrepid::bun(g_0, G0) +
            Intrepid::bun(g_1, G1) +
            Intrepid::bun(g_2, G2));
        // for Jay: bun()
        Intrepid::Tensor<ScalarT> Fper((1 / thickness) * Intrepid::bun(d, G_2));

        Intrepid::Tensor<ScalarT> F = Fpar + Fper;

        defGrad(cell, pt, 0, 0) = F(0, 0);
        defGrad(cell, pt, 0, 1) = F(0, 1);
        defGrad(cell, pt, 0, 2) = F(0, 2);
        defGrad(cell, pt, 1, 0) = F(1, 0);
        defGrad(cell, pt, 1, 1) = F(1, 1);
        defGrad(cell, pt, 1, 2) = F(1, 2);
        defGrad(cell, pt, 2, 0) = F(2, 0);
        defGrad(cell, pt, 2, 1) = F(2, 1);
        defGrad(cell, pt, 2, 2) = F(2, 2);

        J(cell,pt) = Intrepid::det(F);
      }
    }

    if (weightedAverage)
    {
      ScalarT Jbar, wJbar, vol;
      for (std::size_t cell=0; cell < workset.numCells; ++cell)
      {
        Jbar = 0.0;
        vol = 0.0;
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          Jbar += weights(cell,qp) * std::log( J(cell,qp) );
          vol  += weights(cell,qp);
        }
        Jbar /= vol;

        // Jbar = std::exp(Jbar);
        for (std::size_t qp=0; qp < numQPs; ++qp)
        {
          for (std::size_t i=0; i < numDims; ++i)
          {
            for (std::size_t j=0; j < numDims; ++j)
            {
              wJbar = std::exp( (1-alpha) * Jbar + alpha * std::log( J(cell,qp) ) );
              defGrad(cell,qp,i,j) *= std::pow( wJbar / J(cell,qp) ,1./3. );
            }
          }
          J(cell,qp) = wJbar;
        }
      }
    }

  }
// Assumes symbol-spaced sampling!!!
// Based upon paper by Al-Dhahir and Cioffi
bool designDFE(signalVector &channelResponse,
	       float SNRestimate,
	       int Nf,
	       signalVector **feedForwardFilter,
	       signalVector **feedbackFilter)
{
  
  signalVector G0(Nf);
  signalVector G1(Nf);
  signalVector::iterator G0ptr = G0.begin();
  signalVector::iterator G1ptr = G1.begin();
  signalVector::iterator chanPtr = channelResponse.begin();

  int nu = channelResponse.size()-1;

  *G0ptr = 1.0/sqrtf(SNRestimate);
  for(int j = 0; j <= nu; j++) {
    *G1ptr = chanPtr->conj();
    G1ptr++; chanPtr++;
  }

  signalVector *L[Nf];
  signalVector::iterator Lptr;
  float d;
  for(int i = 0; i < Nf; i++) {
    d = G0.begin()->norm2() + G1.begin()->norm2();
    L[i] = new signalVector(Nf+nu);
    Lptr = L[i]->begin()+i;
    G0ptr = G0.begin(); G1ptr = G1.begin();
    while ((G0ptr < G0.end()) &&  (Lptr < L[i]->end())) {
      *Lptr = (*G0ptr*(G0.begin()->conj()) + *G1ptr*(G1.begin()->conj()) )/d;
      Lptr++;
      G0ptr++;
      G1ptr++;
    }
    complex k = (*G1.begin())/(*G0.begin());

    if (i != Nf-1) {
      signalVector G0new = G1;
      scaleVector(G0new,k.conj());
      addVector(G0new,G0);

      signalVector G1new = G0;
      scaleVector(G1new,k*(-1.0));
      addVector(G1new,G1);
      delayVector(G1new,-1.0);

      scaleVector(G0new,1.0/sqrtf(1.0+k.norm2()));
      scaleVector(G1new,1.0/sqrtf(1.0+k.norm2()));
      G0 = G0new;
      G1 = G1new;
    }
  }

  *feedbackFilter = new signalVector(nu);
  L[Nf-1]->segmentCopyTo(**feedbackFilter,Nf,nu);
  scaleVector(**feedbackFilter,(complex) -1.0);
  conjugateVector(**feedbackFilter);

  signalVector v(Nf);
  signalVector::iterator vStart = v.begin();
  signalVector::iterator vPtr;
  *(vStart+Nf-1) = (complex) 1.0;
  for(int k = Nf-2; k >= 0; k--) {
    Lptr = L[k]->begin()+k+1;
    vPtr = vStart + k+1;
    complex v_k = 0.0;
    for (int j = k+1; j < Nf; j++) {
      v_k -= (*vPtr)*(*Lptr);
      vPtr++; Lptr++;
    }
     *(vStart + k) = v_k;
  }

  *feedForwardFilter = new signalVector(Nf);
  signalVector::iterator w = (*feedForwardFilter)->begin();
  for (int i = 0; i < Nf; i++) {
    delete L[i];
    complex w_i = 0.0;
    int endPt = ( nu < (Nf-1-i) ) ? nu : (Nf-1-i);
    vPtr = vStart+i;
    chanPtr = channelResponse.begin();
    for (int k = 0; k < endPt+1; k++) {
      w_i += (*vPtr)*(chanPtr->conj());
      vPtr++; chanPtr++;
    }
    *w = w_i/d;
    w++;
  }


  return true;
  
}
Beispiel #18
0
float beckmann::G(const vec3& wo, const vec3& wi, const vec3& wh) const {
    return G1(wo, wh) * G1(wi, wh);
}
Beispiel #19
0
ValueType
StringKernel<ValueType>::
operator()(const std::string& x, const std::string& y) const
{
  const value_type& g=gap_;
  value_type g2=g*g;
  typedef boost::multi_array<value_type,2> dp_type;
#if 1

  dp_type K0(boost::extents[x.size()+1][y.size()+1]);
  dp_type G0(boost::extents[x.size()+1][y.size()+1]);
  std::vector<value_type> K1(y.size()+1);
  std::vector<value_type> G1(y.size()+1);

  K0[0][0]=G0[0][0]=1.0;
  for (uint i=1; i!=x.size()+1; ++i) {
    K0[i][0]=1.0;
    G0[i][0]=G0[i-1][0]*g;
  }
  for (uint j=1; j!=y.size()+1; ++j) {
    K0[0][j]=1.0;
    G0[0][j]=G0[0][j-1]*g;
  }

  for (uint i=1; i!=x.size()+1; ++i) {
    K1[0]=G1[0]=0.0;
    for (uint j=1; j!=y.size()+1; ++j) {
      K1[j] = K1[j-1];
      G1[j] = G1[j-1]*g;
      if (x[i-1]==y[j-1]) {
	K1[j] += G0[i-1][j-1]*g2;
	G1[j] += G0[i-1][j-1]*g2;
      }
      K0[i][j] = K0[i-1][j] + K1[j];
      G0[i][j] = G0[i-1][j]*g + G1[j];
    }
  }

  return K0[x.size()][y.size()];

#else

  dp_type K0(boost::extents[x.size()+1][y.size()+1]);
  dp_type G0(boost::extents[x.size()+1][y.size()+1]);
  dp_type K1(boost::extents[x.size()+1][y.size()+1]);
  dp_type G1(boost::extents[x.size()+1][y.size()+1]);

  K0[0][0]=G0[0][0]=1.0;
  for (uint i=1; i!=x.size()+1; ++i) {
    K0[i][0]=1.0;
    G0[i][0]=G0[i-1][0]*g;
  }
  for (uint j=1; j!=y.size()+1; ++j) {
    K0[0][j]=1.0;
    G0[0][j]=G0[0][j-1]*g;
  }

  for (uint i=1; i!=x.size()+1; ++i) {
    K1[i][0]=G1[i][0]=0.0;
    for (uint j=1; j!=y.size()+1; ++j) {
      K1[i][j] = K1[i][j-1];
      G1[i][j] = G1[i][j-1]*g;
      if (x[i-1]==y[j-1]) {
	K1[i][j] += G0[i-1][j-1]*g2;
	G1[i][j] += G0[i-1][j-1]*g2;
      }
      K0[i][j] = K0[i-1][j] + K1[i][j];
      G0[i][j] = G0[i-1][j]*g + G1[i][j];
    }
  }

  return K0[x.size()][y.size()];
#endif
}
Beispiel #20
0
void raazHashBlake256PortableCompress(Hash hash, Salt salt, uint64_t counter, int nblocks, Block *mesg)
{

    Word t0,t1;  /* Counter variables */

    /* Message variables */
    Word m0;    
    Word m1;
    Word m2;
    Word m3;
    Word m4;    
    Word m5;
    Word m6;
    Word m7;
    Word m8;
    Word m9;
    Word m10;
    Word m11;
    Word m12;
    Word m13;
    Word m14;
    Word m15;
    
    /* State variables - stored in registers so as to make the code faster */
    register Word v0;
    register Word v1;
    register Word v2;
    register Word v3;
    register Word v4;
    register Word v5;
    register Word v6;
    register Word v7;
    register Word v8;
    register Word v9;
    register Word v10;
    register Word v11;
    register Word v12;
    register Word v13;
    register Word v14;
    register Word v15;


    while(nblocks > 0)
    {
        /* Incrementing counter by message bits */
        counter = counter + 512;  
    
        t0 = (Word)counter;                    
        t1 = (Word)(counter >> 32);
                
        /* Initialization of the state consisting of 16 words */                
        v0 = hash[0];
        v1 = hash[1];
        v2 = hash[2];
        v3 = hash[3];
        v4 = hash[4];
        v5 = hash[5];
        v6 = hash[6];
        v7 = hash[7];
        v8 = salt[0] ^ c0;
        v9 = salt[1] ^ c1;
        v10 = salt[2] ^ c2; 
        v11 = salt[3] ^ c3;
        v12 = t0 ^ c4; 
        v13 = t0 ^ c5; 
        v14 = t1 ^ c6; 
        v15 = t1 ^ c7;

        /* Loading the message into 16 words */     
        m0 = raazLoad32BE((Word *)mesg,0);
        m1 = raazLoad32BE((Word *)mesg,1);
        m2 = raazLoad32BE((Word *)mesg,2);
        m3 = raazLoad32BE((Word *)mesg,3);
        m4 = raazLoad32BE((Word *)mesg,4);
        m5 = raazLoad32BE((Word *)mesg,5);
        m6 = raazLoad32BE((Word *)mesg,6);
        m7 = raazLoad32BE((Word *)mesg,7);
        m8 = raazLoad32BE((Word *)mesg,8);
        m9 = raazLoad32BE((Word *)mesg,9);
        m10 = raazLoad32BE((Word *)mesg,10); 
        m11 = raazLoad32BE((Word *)mesg,11); 
        m12 = raazLoad32BE((Word *)mesg,12); 
        m13 = raazLoad32BE((Word *)mesg,13); 
        m14 = raazLoad32BE((Word *)mesg,14); 
        m15 = raazLoad32BE((Word *)mesg,15);
        
        /* End of reading the message block */


        /*
        Loop unrollings are being done after every round so as to improve the 
        performance. 
        */

        /* Round 1 */
        /* Column Steps 0-3 */
        G0( m0, m1, c0, c1 );
        G1( m2, m3, c2, c3 );
        G2( m4, m5, c4, c5 );
        G3( m6, m7, c6, c7 );

        /* Diagonal-Step 4-7 */  
        G4( m8 , m9 , c8 , c9  );
        G5( m10, m11, c10, c11 );
        G6( m12, m13, c12, c13 );
        G7( m14, m15, c14, c15 );


        /* Round 2 */
        /* Column Step 0-3 */
        G0( m14, m10, c14, c10 );
        G1( m4 , m8 , c4 , c8  );
        G2( m9 , m15, c9 , c15 );
        G3( m13, m6 , c13, c6  );

        /* Diagonal Step 4-7 */
        G4( m1 , m12, c1 , c12 );
        G5( m0 , m2 , c0 , c2  );
        G6( m11, m7 , c11, c7  );
        G7( m5 , m3 , c5 , c3  );


        /* Round 3 */
        /* Column Step 0-3 */
        G0( m11, m8 , c11, c8  );
        G1( m12, m0 , c12, c0  );
        G2( m5 , m2 , c5 , c2  );
        G3( m15, m13, c15, c13 );

        /* Diagonal Step 4-7 */
        G4( m10, m14, c10, c14 );
        G5( m3 , m6 , c3 , c6  );
        G6( m7 , m1 , c7 , c1  );
        G7( m9 , m4 , c9 , c4  );


        /* Round 4 */
        /* Column Step 0-3 */
        G0( m7 , m9 , c7 , c9  );
        G1( m3 , m1 , c3 , c1  );
        G2( m13, m12, c13, c12 );
        G3( m11, m14, c11, c14 );

        /* Diagonal Step 4-7 */
        G4( m2 , m6 , c2 , c6  );
        G5( m5 , m10, c5 , c10 );
        G6( m4 , m0 , c4 , c0  );
        G7( m15, m8 , c15, c8  );


        /* Round 5 */
        /* Column Step 0-3 */
        G0( m9 , m0 , c9 , c0  );
        G1( m5 , m7 , c5 , c7  );
        G2( m2 , m4 , c2 , c4  );
        G3( m10, m15, c10, c15 );

        /* Diagonal Step 4-7 */
        G4( m14, m1 , c14, c1  );
        G5( m11, m12, c11, c12 );
        G6( m6 , m8 , c6 , c8  );
        G7( m3 , m13, c3 , c13 );


        /* Round 6 */
        /* Column Step 0-3 */
        G0( m2, m12, c2, c12 );
        G1( m6, m10, c6, c10 );
        G2( m0, m11, c0, c11 );
        G3( m8, m3 , c8, c3  );

        /* Diagonal Step 4-7 */
        G4( m4 , m13, c4 , c13 );
        G5( m7 , m5 , c7 , c5  );
        G6( m15, m14, c15, c14 );
        G7( m1 , m9 , c1 , c9  );


        /* Round 7 */
        /* Column Step 0-3 */
        G0( m12, m5 , c12, c5 );
        G1( m1 , m15, c1 , c15 );
        G2( m14, m13, c14, c13 );
        G3( m4 , m10, c4 , c10 );

        /* Diagonal Step 4-7 */
        G4( m0, m7 , c0, c7  );
        G5( m6, m3 , c6, c3  );
        G6( m9, m2 , c9, c2  ); 
        G7( m8, m11, c8, c11 );


        /* Round 8 */
        /* Column Step 0-3 */
        G0( m13, m11, c13, c11 );
        G1( m7 , m14, c7 , c14 );
        G2( m12, m1 , c12, c1  );
        G3( m3 , m9 , c3 , c9  );

        /* Diagonal Step 4-7 */
        G4( m5 , m0 , c5 , c0  );
        G5( m15, m4 , c15, c4  );
        G6( m8 , m6 , c8 , c6  );
        G7( m2 , m10, c2 , c10 );


        /* Round 9 */
        /* Column Step 0-3 */
        G0( m6 , m15, c6 , c15 );
        G1( m14, m9 , c14, c9  );
        G2( m11, m3 , c11, c3  );
        G3( m0 , m8 , c0 , c8  );

        /* Diagonal Step 4-7 */
        G4( m12, m2, c12, c2 );
        G5( m13, m7, c13, c7 );
        G6( m1 , m4, c1 , c4 );
        G7( m10, m5, c10, c5 );


        /* Round 10 */
        /* Column Step 0-3 */
        G0( m10, m2, c10, c2 );
        G1( m8 , m4, c8 , c4 );
        G2( m7 , m6, c7 , c6 );
        G3( m1 , m5, c1 , c5 );

        /* Diagonal Step 4-7 */
        G4( m15, m11, c15, c11 );
        G5( m9 , m14, c9 , c14 );
        G6( m3 , m12, c3 , c12 );
        G7( m13, m0 , c13, c0  );


        /* Round 11 */
        /* Column Steps 0-3 */
        G0( m0, m1, c0, c1 );
        G1( m2, m3, c2, c3 );
        G2( m4, m5, c4, c5 );
        G3( m6, m7, c6, c7 );

        /* Diagonal-Step 4-7 */  
        G4( m8 , m9 , c8 , c9  );
        G5( m10, m11, c10, c11 );
        G6( m12, m13, c12, c13 );
        G7( m14, m15, c14, c15 );
        

        /* Round 12 */
        /* Column Step 0-3 */
        G0( m14, m10, c14, c10 );
        G1( m4 , m8 , c4 , c8  );
        G2( m9 , m15, c9 , c15 );
        G3( m13, m6 , c13, c6  );

        /* Diagonal Step 4-7 */
        G4( m1 , m12, c1 , c12 );
        G5( m0 , m2 , c0 , c2  );
        G6( m11, m7 , c11, c7  );
        G7( m5 , m3 , c5 , c3  );


        /* Round 13 */
        /* Column Step 0-3 */
        G0( m11, m8 , c11, c8  );
        G1( m12, m0 , c12, c0  );
        G2( m5 , m2 , c5 , c2  );
        G3( m15, m13, c15, c13 );
  
        /* Diagonal Step 4-7 */
        G4( m10, m14, c10, c14 );
        G5( m3 , m6 , c3 , c6  );
        G6( m7 , m1 , c7 , c1  );
        G7( m9 , m4 , c9 , c4  );


        /* Round 14 */
        /* Column Step 0-3 */
        G0( m7 , m9 , c7 , c9  );
        G1( m3 , m1 , c3 , c1  );
        G2( m13, m12, c13, c12 );
        G3( m11, m14, c11, c14 );

        /* Diagonal Step 4-7 */
        G4( m2 , m6 , c2 , c6  );
        G5( m5 , m10, c5 , c10 );
        G6( m4 , m0 , c4 , c0  );
        G7( m15, m8 , c15, c8  );



        /* Updation of hash variables with the new chain value */
        hash[0] = hash[0] ^ salt[0] ^ v0 ^ v8;
        hash[1] = hash[1] ^ salt[1] ^ v1 ^ v9;
        hash[2] = hash[2] ^ salt[2] ^ v2 ^ v10;
        hash[3] = hash[3] ^ salt[3] ^ v3 ^ v11;
        hash[4] = hash[4] ^ salt[0] ^ v4 ^ v12;     
        hash[5] = hash[5] ^ salt[1] ^ v5 ^ v13;     
        hash[6] = hash[6] ^ salt[2] ^ v6 ^ v14; 
        hash[7] = hash[7] ^ salt[3] ^ v7 ^ v15;     
        
        ++mesg; /* Incrementing to the next block */
        --nblocks;
    }   
}
Beispiel #21
0
Datei: luit.c Projekt: aosm/X11
static int
parseOptions(int argc, char **argv)
{
    int i = 1;
    while(i < argc) {
        if(argv[i][0] != '-' && argv[i][0] != '+') {
            break;
        } else if(!strcmp(argv[i], "--")) {
            i++;
            break;
        } else if(!strcmp(argv[i], "-v")) {
            verbose++;
            i++;
        } else if(!strcmp(argv[i], "-h")) {
            help();
            exit(0);
        } else if(!strcmp(argv[i], "-list")) {
            reportCharsets();
            exit(0);
        } else if(!strcmp(argv[i], "+oss")) {
            outputState->outputFlags &= ~OF_SS;
            i++;
        } else if(!strcmp(argv[i], "+ols")) {
            outputState->outputFlags &= ~OF_LS;
            i++;
        } else if(!strcmp(argv[i], "+osl")) {
            outputState->outputFlags &= ~OF_SELECT;
            i++;
        } else if(!strcmp(argv[i], "+ot")) {
            outputState->outputFlags = OF_PASSTHRU;
            i++;
        } else if(!strcmp(argv[i], "-k7")) {
            inputState->inputFlags &= ~IF_EIGHTBIT;
            i++;
        } else if(!strcmp(argv[i], "+kss")) {
            inputState->inputFlags &= ~IF_SS;
            i++;
        } else if(!strcmp(argv[1], "+kssgr")) {
            inputState->inputFlags &= ~IF_SSGR;
            i++;
        } else if(!strcmp(argv[i], "-kls")) {
            inputState->inputFlags |= IF_LS;
            i++;
        } else if(!strcmp(argv[i], "-g0")) {
            if(i + 1 >= argc)
                FatalError("-g0 requires an argument\n");
            G0(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g1")) {
            if(i + 1 >= argc)
                FatalError("-g1 requires an argument\n");
            G1(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g2")) {
            if(i + 1 >= argc)
                FatalError("-g2 requires an argument\n");
            G2(outputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-g3")) {
            if(i + 1 >= argc)
                FatalError("-g3 requires an argument\n");
            G3(outputState) = getCharsetByName(argv[i + 1]);

            i += 2;
        } else if(!strcmp(argv[i], "-gl")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-gl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -gl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                outputState->glp = &outputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-gr")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-gr requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -gl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                outputState->grp = &outputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-kg0")) {
            if(i + 1 >= argc)
                FatalError("-kg0 requires an argument\n");
            G0(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg1")) {
            if(i + 1 >= argc)
                FatalError("-kg1 requires an argument\n");
            G1(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg2")) {
            if(i + 1 >= argc)
                FatalError("-kg2 requires an argument\n");
            G2(inputState) = getCharsetByName(argv[i + 1]);
            i += 2;
        } else if(!strcmp(argv[i], "-kg3")) {
            if(i + 1 >= argc)
                FatalError("-kg3 requires an argument\n");
            G3(inputState) = getCharsetByName(argv[i + 1]);

            i += 2;
        } else if(!strcmp(argv[i], "-kgl")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-kgl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -kgl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                inputState->glp = &inputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-kgr")) {
            int j;
            if(i + 1 >= argc)
                FatalError("-kgl requires an argument\n");
            if(strlen(argv[i + 1]) != 2 ||
               argv[i + 1][0] != 'g')
                j = -1;
            else 
                j = argv[i + 1][1] - '0';
            if(j < 0 || j > 3)
                FatalError("The argument of -kgl "
                           "should be one of g0 through g3,\n"
                           "not %s\n", argv[i + 1]);
            else
                inputState->grp = &inputState->g[j];
            i += 2;
        } else if(!strcmp(argv[i], "-argv0")) {
            if(i + 1 >= argc)
                FatalError("-argv0 requires an argument\n");
            child_argv0 = argv[i + 1];
            i += 2;
        } else if(!strcmp(argv[i], "-x")) {
            exitOnChild = 1;
            i++;
        } else if(!strcmp(argv[i], "-c")) {
            converter = 1;
            i++;
        } else if(!strcmp(argv[i], "-ilog")) {
            if(i + 1 >= argc)
                FatalError("-ilog requires an argument\n");
            ilog = open(argv[i + 1], O_WRONLY | O_CREAT | O_TRUNC, 0777);
            if(ilog < 0) {
                perror("Couldn't open input log");
                exit(1);
            }
            i += 2;
        } else if(!strcmp(argv[i], "-olog")) {
            if(i + 1 >= argc)
                FatalError("-olog requires an argument\n");
            olog = open(argv[i + 1], O_WRONLY | O_CREAT | O_TRUNC, 0777);
            if(olog < 0) {
                perror("Couldn't open output log");
                exit(1);
            }
            i += 2;
        } else if(!strcmp(argv[i], "-encoding")) {
            int rc;
            if(i + 1 >= argc)
                FatalError("-encoding requires an argument\n");
            rc = initIso2022(NULL, argv[i + 1], outputState);
            if(rc < 0)
                FatalError("Couldn't init output state\n");
            i += 2;
        } else {
            FatalError("Unknown option %s\n", argv[i]);
        }
    }
    return i;
}
Beispiel #22
0
/*-----------------------------------------------------------------------------
	List of supported games
-----------------------------------------------------------------------------*/

#define G1(name)		{ name, NULL, GAME_UE1 }
#define G2(name)		{ name, NULL, GAME_UE2 }
#define G3(name)		{ name, NULL, GAME_UE3 }
#define G(name,s,e)		{ name, #s,   e        }
#define TABLE_END		{ NULL, NULL, 0        }


const GameInfo GListOfGames[] = {
	// Unreal engine 1
#if UNREAL1
		G("Unreal engine 1", ue1, GAME_UE1),
		G1("Unreal 1"),
		G1("Unreal Tournament 1 (UT99)"),
		G1("The Wheel of Time"),
	#if DEUS_EX
		G1("DeusEx"),
	#endif
	#if RUNE
		G1("Rune"),
	#endif
	#if UNDYING
		G("Undying", undying, GAME_Undying),
	#endif
#endif // UNREAL1

	// Unreal Engine 2
		G("Unreal engine 2", ue2, GAME_UE2),
Beispiel #23
0
/**
  * Node betweenness centrality is the fraction of all shortest paths in
  * the network that contain a given node. Nodes with high values of
  * betweenness centrality participate in a large number of shortest paths.
  *
  *     Input:      G,      weighted (directed/undirected) connection matrix.
  *     Output:     BC,     node betweenness centrality vector.
  *                 EBC,    edge betweenness centrality matrix.
  *
  * Notes:
  *    The input matrix must be a mapping from weight to distance. For
  * instance, in a weighted correlation network, higher correlations are
  * more naturally interpreted as shorter distances, and the input matrix
  * should consequently be some inverse of the connectivity matrix.
  *    Betweenness centrality may be normalised to [0,1] via BC/[(N-1)(N-2)]
  *
  * Reference: Brandes (2001) J Math Sociol 25:163-177.
  */
rowvec Connectome::betweenessCentrality(const mat &G, mat &EBC)
{
    uint n = G.n_rows,q = n-1,v=0,w=0;
    double Duw,DPvw;
    vec t;
    rowvec BC = zeros(1,n),D,NP,DP;
    uvec S,Q,V,tt,W;
    mat G1;
    umat P;
    EBC = zeros<mat>(n,n);

    for (uint u = 0; u<n;++u) {
        D = rowvec(1,n).fill(datum::inf); D(u) = 0;
        NP = zeros(1,n); NP(u) = 1;
        S = linspace<uvec>(0,n-1,n);
        P = zeros<umat>(n,n);
        Q = zeros<uvec>(n);
        q = n-1;
        G1 = G;
        V = uvec(1).fill(u);
        while (true) {
            // instead of replacing indices by 0 like S(V)=0;
            // we declare all indices then remove the V indeces
            // from S. Notice that it is assured that tt should
            // be one element since indices don't repeat
            for (int i=0;i<V.n_elem;++i) {
                tt = find(S == V(i),1);
                if (!tt.is_empty())
                    S.shed_row(tt(0));
            }
            G1.cols(V).fill(0);
            for (uint i=0; i<V.n_elem;++i) {
                v = V(i);
                Q(q) = v; --q;
                W = find( G1.row(v) != 0);
                for (uint j = 0;j<W.n_elem;++j) {
                    w = W(j);
                    Duw = D(v)+G1(v,w);
                    if (Duw<D(w)) {
                        D(w) = Duw;
                        NP(w) = NP(v);
                        P.row(w).fill(0);
                        P(w,v) = 1;
                    }
                    else if (Duw == D(w)) {
                        NP(w) += NP(v);
                        P(w,v) = 1;
                    }
                }
            }

            if (S.is_empty())
                break;
            t = D(S);
            if ( !is_finite(t.min()) ){
                // the number of inf elements is assumed to be always = q
                Q.subvec(0,q) = find(D == datum::inf);
                break;
            }
            V = find(D == t.min());
        }
        DP = zeros(1,n);
        for (uint i=0; i<Q.n_elem-1;++i) {
            w = Q(i);
            BC(w) += DP(w);
            tt = find(P.row(w) != 0);
            for (uint j=0; j<tt.n_elem;++j) {
                v = tt(j);
                DPvw = (1+DP(w))*NP(v)/NP(w);
                DP(v) += DPvw;
                EBC(v,w) += DPvw;
            }
        }
    }
    return BC;
}