Esempio n. 1
0
TEST(Json, Parser)
{
    const std::string jd("{\"a\":\"123\",\"b\":678,\"90\":[\"jj\",\"kk\",\"ll\",\"mm\"],\"m78\":{\"xx\":\"用户名不能为空\",\"yy\":1,\"zz\":1,\"uu\":[1,2,3,4,\"bool\"]}}");
    comm::library::JsonPath jp;
    jp.Append("m78").Append("uu").Append(4);
    //printf("%s\n", jp.GetHumanPath().c_str());

    comm::library::JsonParser jx(jd);
    std::string tt;
    ASSERT_EQ(0, jx.GetValueByPath(jp, tt));
    EXPECT_EQ("bool", tt);

    jp.Retain(1);
    jp.Append("xx");
    //printf("%s\n", jp.GetHumanPath().c_str());
    ASSERT_EQ(0, jx.GetValueByPath(jp, tt));
    EXPECT_EQ("用户名不能为空", tt);
    
    jp.Retain(0);
    jp.Append("b");
    //printf("%s\n", jp.GetHumanPath().c_str());
    int64_t ut;
    ASSERT_EQ(0, jx.GetValueByPath(jp, ut));
    EXPECT_EQ(678, ut);
    //printf("%s\n", tt.c_str());
}
Esempio n. 2
0
void guardaTeste()
{
	FILE *p;
	p = fopen ("teste.txt", "w+");

	//vai ate o final do arquivo - nao esta funcionando!
	char c = getc(p);
	while(c != EOF)
		c = getc(p);
	
	fprintf(p, "\nlambida = %f\nTeta:\n", lamb);
	for(int i = 0; i < 14; i++)
		fprintf (p, "%f;",teta[i]);

	defineRange(0,105); //valores de treinamento
	fprintf(p, "\nJ(x) de valores de treinamento = %f\n", jx());
	//printf("Erro de valores de treinamento = %f\n", jx());

	defineRange(105,142); //valores de teste1
	fprintf(p, "J(x) de valores de teste 1 = %f\n", jx());
	//printf("Erro de valores de teste 1 = %f\n", jx());

	defineRange(142,178); //valores de teste2
	fprintf(p,"J(x) de valores de teste 2 = %f\n\n", jx());
	//printf("Erro de valores de teste 2 = %f\n\n", jx());

	//casos em que o erro gera decisao errada
	fprintf(p, "Valores com erro inaceitavel:\n");
	int errado, inaceitavel;
	errado = inaceitavel = 0;

	for(int i = 0; i < 178; i++)
	{
		float erro = hx(i)-x[0][i];
		if(erro > 0.5 || erro < -0.5)
		{
			errado ++;
			if(erro > 1.0 || erro < -1.0)
				inaceitavel ++;
			printf("i = %d\tesperado = %f\tobtido = %f\terro = %f\n",i, x[0][i], hx(i), erro);

		}
	}
	fprintf(p, "Erros acima de 0.5 = %d\tErros acima de 1.0 = %d\n", errado-inaceitavel, inaceitavel);

	fclose(p);
}
Esempio n. 3
0
int confereErro(double *ultimo_erro, int count)
{
	double erro = 0;

    erro = jx();

	if(count%100000 == 0)
	{
		printf("J(x) = %f \tDeltaJ(x) = %.12f\tCount = %d\n", erro, (*ultimo_erro - erro), count);
		//guardaTeta(erro, count);
	}

	//confere se o erro ainda esta diminuindo
	if((*ultimo_erro - erro) < 0.0000000000005 && (*ultimo_erro - erro) > 0.0)
		return 2;

	*ultimo_erro = erro;

	if(erro > 0.02)
		return 1; //erro inaceitavel
	else
		return 0;//erro aceitavel
}
Esempio n. 4
0
void cnbint(
		int i,
		const double pos[][3],
		const double vel[][3],
		const double mass[],
		int nnb,
		int list[],
		double f[3],
		double fdot[3]){
	const int NBMAX = 512;
	assert(nnb <= NBMAX);

	float xbuf[NBMAX] __attribute__ ((aligned(16)));
	float ybuf[NBMAX] __attribute__ ((aligned(16)));
	float zbuf[NBMAX] __attribute__ ((aligned(16)));
	float vxbuf[NBMAX] __attribute__ ((aligned(16)));
	float vybuf[NBMAX] __attribute__ ((aligned(16)));
	float vzbuf[NBMAX] __attribute__ ((aligned(16)));
	float mbuf[NBMAX] __attribute__ ((aligned(16)));
	assert((unsigned long)xbuf % 16 == 0);

	double xi = pos[i][0];
	double yi = pos[i][1];
	double zi = pos[i][2];
	float vxi = vel[i][0];
	float vyi = vel[i][1];
	float vzi = vel[i][2];
	for(int k=0; k<nnb; k++){
		int j = list[k];
#if 1
		int jj = list[k+4];
		__builtin_prefetch(pos[jj]);
		__builtin_prefetch(pos[jj]+2);
		__builtin_prefetch(vel[jj]);
		__builtin_prefetch(vel[jj]+2);
		__builtin_prefetch(&mass[jj]);
#endif
#if 0
		xbuf[k] = pos[j][0] - xi;
		ybuf[k] = pos[j][1] - yi;
		zbuf[k] = pos[j][2] - zi;
		vxbuf[k] = vel[j][0] - vxi;
		vybuf[k] = vel[j][1] - vyi;
		vzbuf[k] = vel[j][2] - vzi;
		mbuf[k] = mass[j];
#else
		double xj = pos[j][0];
		double yj = pos[j][1];
		double zj = pos[j][2];
		float vxj = vel[j][0];
		float vyj = vel[j][1];
		float vzj = vel[j][2];
		float mj = mass[j];
		xj -= xi;
		yj -= yi;
		zj -= zi;
		vxj -= vxi;
		vyj -= vyi;
		vzj -= vzi;
		xbuf[k] = xj;
		ybuf[k] = yj;
		zbuf[k] = zj;
		vxbuf[k] = vxj;
		vybuf[k] = vyj;
		vzbuf[k] = vzj;
		mbuf[k] = mj;
#endif
	}
	for(int k=nnb; k%4; k++){
		xbuf[k] = 16.0f;
		ybuf[k] = 16.0f;
		zbuf[k] = 16.0f;
		vxbuf[k] = 0.0f;
		vybuf[k] = 0.0f;
		vzbuf[k] = 0.0f;
		mbuf[k] = 0.0f;
	}

	v4df ax(0.0), ay(0.0), az(0.0);
	v4sf jx(0.0), jy(0.0), jz(0.0);

	for(int k=0; k<nnb; k+=4){
		v4sf dx(xbuf + k);
		v4sf dy(ybuf + k);
		v4sf dz(zbuf + k);
		v4sf dvx(vxbuf + k);
		v4sf dvy(vybuf + k);
		v4sf dvz(vzbuf + k);
		v4sf mj(mbuf + k);

		v4sf r2 = dx*dx + dy*dy + dz*dz;
		v4sf rv = dx*dvx + dy*dvy + dz*dvz;
		rv *= v4sf(-3.0f);
		// v4sf rinv1 = r2.rsqrt() & v4sf(mask);
#if 1
		v4sf rinv1 = r2.rsqrt();
#else
		v4sf rinv1 = v4sf(v4df(1.0) / v4df(r2).sqrt());
#endif
		v4sf rinv2 = rinv1 * rinv1;
		rv *= rinv2;
		v4sf rinv3 = mj * rinv1 * rinv2;
		 
		dx *= rinv3; ax += v4df(dx);
		dy *= rinv3; ay += v4df(dy);
		dz *= rinv3; az += v4df(dz);
		dvx *= rinv3; jx += dvx;
		dvy *= rinv3; jy += dvy;
		dvz *= rinv3; jz += dvz;
		dx *= rv; jx += dx;
		dy *= rv; jy += dy;
		dz *= rv; jz += dz;
	}
	f[0] = ax.sum();
	f[1] = ay.sum();
	f[2] = az.sum();
	fdot[0] = (v4df(jx)).sum();
	fdot[1] = (v4df(jy)).sum();
	fdot[2] = (v4df(jz)).sum();
	assert(f[0] == f[0]);
	assert(f[1] == f[1]);
	assert(f[2] == f[2]);
	assert(fdot[0] == fdot[0]);
	assert(fdot[1] == fdot[1]);
	assert(fdot[2] == fdot[2]);
}
Esempio n. 5
0
void cnbint(
		int i,
		const double pos[][3],
		const double vel[][3],
		const double mass[],
		int nnb,
		int list[],
		double f[3],
		double fdot[3]){
	const int NBMAX = 512;
	assert(nnb <= NBMAX);

	double xbuf[NBMAX] __attribute__ ((aligned(16)));
	double ybuf[NBMAX] __attribute__ ((aligned(16)));
	double zbuf[NBMAX] __attribute__ ((aligned(16)));
	float vxbuf[NBMAX] __attribute__ ((aligned(16)));
	float vybuf[NBMAX] __attribute__ ((aligned(16)));
	float vzbuf[NBMAX] __attribute__ ((aligned(16)));
	float mbuf[NBMAX] __attribute__ ((aligned(16)));
	for(int k=0; k<nnb; k++){
		int j = list[k];
		xbuf[k] = pos[j][0];
		ybuf[k] = pos[j][1];
		zbuf[k] = pos[j][2];
		vxbuf[k] = vel[j][0];
		vybuf[k] = vel[j][1];
		vzbuf[k] = vel[j][2];
		mbuf[k] = mass[j];
	}
	for(int k=nnb; k%4; k++){
		xbuf[k] = 16.0;
		ybuf[k] = 16.0;
		zbuf[k] = 16.0;
		vxbuf[k] = 0.0f;
		vybuf[k] = 0.0f;
		vzbuf[k] = 0.0f;
		mbuf[k] = 0.0f;
	}

	v4df xi(pos[i][0]);
	v4df yi(pos[i][1]);
	v4df zi(pos[i][2]);
	v4sf vxi(vel[i][0]);
	v4sf vyi(vel[i][1]);
	v4sf vzi(vel[i][2]);
	v4df ax(0.0), ay(0.0), az(0.0);
	v4sf jx(0.0), jy(0.0), jz(0.0);

	for(int k=0; k<nnb; k+=4){
		v4df xj(xbuf + k);
		v4df yj(ybuf + k);
		v4df zj(zbuf + k);
		v4sf vxj(vxbuf + k);
		v4sf vyj(vybuf + k);
		v4sf vzj(vzbuf + k);
		v4sf mj(mbuf + k);

		v4sf dx = v4sf::_v4sf(xj - xi);
		v4sf dy = v4sf::_v4sf(yj - yi);
		v4sf dz = v4sf::_v4sf(zj - zi);
		v4sf dvx = vxj - vxi;
		v4sf dvy = vyj - vyi;
		v4sf dvz = vzj - vzi;

		v4sf r2 = dx*dx + dy*dy + dz*dz;
		v4sf rv = dx*dvx + dy*dvy + dz*dvz;
		rv *= v4sf(-3.0f);
		// v4sf rinv1 = r2.rsqrt() & v4sf(mask);
		v4sf rinv1 = r2.rsqrt();
		v4sf rinv2 = rinv1 * rinv1;
		rv *= rinv2;
		v4sf rinv3 = mj * rinv1 * rinv2;
		 
		dx *= rinv3; ax += v4df(dx);
		dy *= rinv3; ay += v4df(dy);
		dz *= rinv3; az += v4df(dz);
		dvx *= rinv3; jx += dvx;
		dvy *= rinv3; jy += dvy;
		dvz *= rinv3; jz += dvz;
		dx *= rv; jx += dx;
		dy *= rv; jy += dy;
		dz *= rv; jz += dz;
	}
	f[0] = ax.sum();
	f[1] = ay.sum();
	f[2] = az.sum();
	fdot[0] = (v4df(jx)).sum();
	fdot[1] = (v4df(jy)).sum();
	fdot[2] = (v4df(jz)).sum();
	assert(f[0] == f[0]);
	assert(f[1] == f[1]);
	assert(f[2] == f[2]);
	assert(fdot[0] == fdot[0]);
	assert(fdot[1] == fdot[1]);
	assert(fdot[2] == fdot[2]);
}
Esempio n. 6
0
namespace nMech
{
  StringID g_Current_LogLevel_jStringID = jx(MSG_presence_dummy);
}
Esempio n. 7
0
visit_handle Simulation:: get_curve( const string &name ) const
{
    visit_handle h = VISIT_INVALID_HANDLE;
    
    if( strncmp(name.c_str(),"bubble",6) == 0 )
    {
        const size_t  id = strconv::to_size( name.c_str()+6, "bubble id");
        assert(id>0);
        assert(id<=bubbles.count());
        const Bubble *b  = bubbles.first();
        for(size_t iter=1;iter<id;++iter) b=b->next;
        assert(b);
        if( VisIt_CurveData_alloc(&h) == VISIT_OKAY )
        {
            // copy bubble spots coordinates
            const size_t bn = b->size+1;
            vector<Real> bx(bn,0);
            vector<Real> by(bn,0);
            const Tracer *p = b->root;
            
            
            for( size_t i=1; i <= bn; ++i,p=p->next)
            {
                bx[i] = p->vertex.x;
                by[i] = p->vertex.y;
            }
            
            
            // make a curve
            visit_handle hcx,hcy;
            VisIt_VariableData_alloc( &hcx );
            VisIt_VariableData_alloc( &hcy );
            VisIt_VariableData_setDataD(hcx, VISIT_OWNER_COPY, 1, bn, bx());
            VisIt_VariableData_setDataD(hcy, VISIT_OWNER_COPY, 1, bn, by());
            VisIt_CurveData_setCoordsXY(h, hcx, hcy);
            
        }
    }
    
    if( name == "junctions" )
    {
        if( VisIt_CurveData_alloc(&h) == VISIT_OKAY )
        {
            // copy juntions coordinates
            const size_t nj = segmenter.num_junctions();
            vector<Real> jx(nj,0);
            vector<Real> jy(nj,0);
            const Segments &segments = segmenter();
            for( size_t i=segments.size(),j=1;i>0;--i)
            {
                const Segment &seg = *segments[i];
                for( const Junction *J = seg.head;J;J=J->next)
                {
                    assert(j<=nj);
                    jx[j] = J->vertex.x;
                    jy[j] = J->vertex.y;
                    ++j;
                }
            }
            
            // make a curve
            visit_handle hcx,hcy;
            VisIt_VariableData_alloc( &hcx );
            VisIt_VariableData_alloc( &hcy );
            VisIt_VariableData_setDataD(hcx, VISIT_OWNER_COPY, 1, nj, jx());
            VisIt_VariableData_setDataD(hcy, VISIT_OWNER_COPY, 1, nj, jy());
            VisIt_CurveData_setCoordsXY(h, hcx, hcy);

        }

    }
    
    return h;
}