Exemplo n.º 1
0
void ProofNode::NotInfer(ProofNode& node,shared_ptr<BoolExp> value)
{
    //the expression inside the not
    BoolReturn innerexp = value->Infer();
    switch (innerexp.op1->Type())
    {
    case OR_EXP:
    {
        shared_ptr<BoolExp> tmp1(new NotExp(innerexp.op1->Infer().op1->Copy()));
        shared_ptr<BoolExp> tmp2(new NotExp(innerexp.op2->Infer().op2->Copy()));
        if(!_left)_left.reset(new ProofNode);
        //_right = nullptr;
        _left->PassToLeaves(tmp1);
        _left->PassToLeaves(tmp2);
        break;
    }
    case AND_EXP:
    {
        shared_ptr<BoolExp> tmp1(new NotExp(innerexp.op1->Infer().op1->Copy()));
        shared_ptr<BoolExp> tmp2(new NotExp(innerexp.op2->Infer().op2->Copy()));
        BoolReturn tmpinfer(tmp1,tmp2);
        PassToLeavesSplit(tmpinfer);
        break;
    }
    case COND_EXP:
    {
        shared_ptr<BoolExp> tmp1(innerexp.op1->Infer().op1->Copy());
        shared_ptr<BoolExp> tmp2(new NotExp(innerexp.op1->Infer().op2->Copy()));
        if(!_left)_left.reset(new ProofNode);
        _left->PassToLeaves(tmp1);
        _left->PassToLeaves(tmp2);
        if(_right)_right->PassToLeaves(tmp1);
        if(_right)_right->PassToLeaves(tmp2);
        break;
    }
    case NOT_EXP: //nested not expressions become un-negated
    {
        if(!_left)_left.reset(new ProofNode);
        _right = nullptr;
        _left->PassToLeaves(innerexp.op1->Copy());
        break;
    }
    case VAR_EXP: //variables inside a not expression do nothing
    {
        break;
    }
    default:
    {
        cout << "ERROR: void ProofNode::NotInfer(ProofNode& node,shared_ptr<BoolExp> value): default inference case" << endl;
        exit(EXIT_FAILURE);
    }
    }
}
Exemplo n.º 2
0
void model_parameters::initialization(void)
{
	NAreaAge.initialize();
 	CatchAreaAge.initialize();
 	CatchNatAge.initialize();
	Nage(1,1) = So*Bo/(1+beta*Bo);
	for(int i=sage+1 ; i <= nage ; i++)
	{
		Nage(1,i) = Nage(1,i-1) * mfexp(-za(i-1));
	}
	VulB(1) = elem_prod(elem_prod(Nage(1),va),wa);
	SB(1) = elem_prod(Nage(1),fa)*wa/2;
	tBo = Nage(1)*wa;
	calcmaxpos(tBo);
	varPos = maxPos*cvPos;
	PosX(1) = minPos + (maxPos - minPos) * (0.5+0.5*sin(indmonth(1)*PI/6 - mo*PI/6)); 
	VBarea(1,sarea) = VulB(1)* (cnorm(areas(sarea)+0.5,PosX(1),varPos));
	for(int r=sarea+1 ; r <= narea-1 ; r++)
	{
		VBarea(1,r) = VulB(1)* (cnorm(areas(r)+0.5,PosX(1),varPos)-cnorm(areas(r)-0.5,PosX(1),varPos));
		NAreaAge(1)(r) = elem_prod(Nage(1)(sage,nage),(cnorm(areas(r)+0.5,PosX(1),varPos)-cnorm(areas(r)-0.5,PosX(1),varPos)));
	}
	//VBarea(1,narea) = VulB(1)* (1.0-cnorm(areas(narea)-0.5,PosX(1),varPos));
	NationVulB(1,1) = sum(VBarea(1)(sarea,sarea+nationareas(1)-1)); 
	NationVulB(1,2) = sum(VBarea(1)(sarea+nationareas(1),narea)); 
	dvar_vector tmp1(sarea,narea);
	dvar_vector tmp2(sarea,narea);
	dvar_vector tmp3(sarea,narea);
	for(int rr= sarea; rr<=narea; rr++)
	{
		tmp1(rr)= VBarea(1)(rr)/ (NationVulB(1)(indnatarea(rr)) + 0.0001);
		tmp2(rr) = tmp1(rr)*TotEffyear(indnatarea(rr))(indyr(1));
		Effarea(1)(rr) = tmp2(rr)*TotEffmonth(indnatarea(rr))(indmonth(1));
	}
	for(int a= sage; a<= nage;a++)
	{
		dvar_vector propVBarea(sarea,narea);
		for(int rr =sarea; rr<=narea; rr++)
		{
			propVBarea(rr) = (cnorm(areas(rr)+0.5,PosX(1),varPos)-cnorm(areas(rr)-0.5,PosX(1),varPos))(a-sage+1);
			CatchAreaAge(1)(rr)(a) = q*Effarea(1)(rr)*va(a)/(q*Effarea(1)(rr)*va(a)+m)*(1-mfexp(-(q*Effarea(1)(rr)*va(a)+m)))*NAreaAge(1)(rr)(a);
			CatchNatAge(1)(indnatarea(rr))(a) += CatchAreaAge(1)(rr)(a);
			EffNatAge(indnatarea(rr))(1)(sage-2) = 1;
			EffNatAge(indnatarea(rr))(1)(sage-1) = indnatarea(rr);
			EffNatAge(indnatarea(rr))(1)(a) += Effarea(1)(rr)*propVBarea(rr);
		}
		//cout<<"propVBarea "<<propVBarea<<endl;
		//cout<<"Effarea(1) "<<Effarea(1)<<endl;
		Effage(1)(a) = Effarea(1)* propVBarea;
	}
}
std::vector< DTV > Ni( const std::vector<Basis> &Bases,
  const DTV &Vec, Hamiltonian<DT> &ham ){
  std::vector< DTV > out;
  DTV tmp1 = DTV::Zero(Bases.at(0).getL());//(Bases.at(0).getL(), 0.0e0);
  DTV tmp2 = DTV::Zero(Bases.at(1).getL());//(Bases.at(1).getL(), 0.0e0);
  std::vector< int > f1 = Bases.at(0).getFStates();
  std::vector< int > f2 = Bases.at(1).getFStates();
  size_t f1id = 0, f2id = 0;
  for ( int &nf2 : f2 ){
    std::vector<size_t> ids(2,f2id);
    f1id = 0;
    for ( int &nf1 : f1 ){
      ids.at(0) = f1id;
      size_t id = ham.DetermineTotalIndex(ids);
      for (size_t cnt = 0; cnt < Bases.at(0).getL(); cnt++) {
        if ( btest(nf1, cnt) ) tmp1(cnt) += std::pow(std::abs(Vec(id)), 2);//Vec(id) * std::conj( Vec(id) );
      }
      for (size_t cnt = 0; cnt < Bases.at(1).getL(); cnt++) {
        if ( btest(nf2, cnt) ) tmp2(cnt) += std::pow(std::abs(Vec(id)), 2);//Vec(id) * std::conj( Vec(id) );
      }
      f1id++;
    }
    f2id++;
  }
  out.push_back(tmp1);
  out.push_back(tmp2);
  return out;
}
void test_eigensolver_selfadjoint()
{
  int s = 0;
  for(int i = 0; i < g_repeat; i++) {
    // very important to test 3x3 and 2x2 matrices since we provide special paths for them
    CALL_SUBTEST_1( selfadjointeigensolver(Matrix2f()) );
    CALL_SUBTEST_1( selfadjointeigensolver(Matrix2d()) );
    CALL_SUBTEST_1( selfadjointeigensolver(Matrix3f()) );
    CALL_SUBTEST_1( selfadjointeigensolver(Matrix3d()) );
    CALL_SUBTEST_2( selfadjointeigensolver(Matrix4d()) );
    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_3( selfadjointeigensolver(MatrixXf(s,s)) );
    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_4( selfadjointeigensolver(MatrixXd(s,s)) );
    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_5( selfadjointeigensolver(MatrixXcd(s,s)) );

    s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
    CALL_SUBTEST_9( selfadjointeigensolver(Matrix<std::complex<double>,Dynamic,Dynamic,RowMajor>(s,s)) );

    // some trivial but implementation-wise tricky cases
    CALL_SUBTEST_4( selfadjointeigensolver(MatrixXd(1,1)) );
    CALL_SUBTEST_4( selfadjointeigensolver(MatrixXd(2,2)) );
    CALL_SUBTEST_6( selfadjointeigensolver(Matrix<double,1,1>()) );
    CALL_SUBTEST_7( selfadjointeigensolver(Matrix<double,2,2>()) );
  }

  // Test problem size constructors
  s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
  CALL_SUBTEST_8(SelfAdjointEigenSolver<MatrixXf> tmp1(s));
  CALL_SUBTEST_8(Tridiagonalization<MatrixXf> tmp2(s));

  TEST_SET_BUT_UNUSED_VARIABLE(s)
}
Exemplo n.º 5
0
BoundingBox GlNode::getBoundingBox(GlGraphInputData* data) {
  node n=node(id);

  if(data->getElementRotation()->getNodeValue(n)==0) {
    BoundingBox box;
    box.expand(data->getElementLayout()->getNodeValue(n)-data->getElementSize()->getNodeValue(n)/2.f);
    box.expand(data->getElementLayout()->getNodeValue(n)+data->getElementSize()->getNodeValue(n)/2.f);
    assert(box.isValid());
    return box;
  }
  else {
    float cosAngle=static_cast<float>(cos(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
    float sinAngle=static_cast<float>(sin(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
    Coord tmp1(data->getElementSize()->getNodeValue(n)/2.f);
    Coord tmp2(tmp1[0] ,-tmp1[1], tmp1[2]);
    Coord tmp3(-tmp1[0],-tmp1[1],-tmp1[2]);
    Coord tmp4(-tmp1[0], tmp1[1],-tmp1[2]);
    tmp1=Coord(tmp1[0]*cosAngle-tmp1[1]*sinAngle,tmp1[0]*sinAngle+tmp1[1]*cosAngle,tmp1[2]);
    tmp2=Coord(tmp2[0]*cosAngle-tmp2[1]*sinAngle,tmp2[0]*sinAngle+tmp2[1]*cosAngle,tmp2[2]);
    tmp3=Coord(tmp3[0]*cosAngle-tmp3[1]*sinAngle,tmp3[0]*sinAngle+tmp3[1]*cosAngle,tmp3[2]);
    tmp4=Coord(tmp4[0]*cosAngle-tmp4[1]*sinAngle,tmp4[0]*sinAngle+tmp4[1]*cosAngle,tmp4[2]);
    BoundingBox bb;
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp1);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp2);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp3);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp4);
    return bb;
  }
}
Exemplo n.º 6
0
/**
 * @brief Compute the right-hand side.
 */
void APE::DoOdeRhs(const Array<OneD, const Array<OneD, NekDouble> >&inarray,
                         Array<OneD,       Array<OneD, NekDouble> >&outarray,
                   const NekDouble time)
{
    int nVariables = inarray.num_elements();
    int nq = GetTotPoints();
    Array<OneD, NekDouble> tmp1(nq);

    // WeakDG does not use advVel, so we only provide a dummy array
    Array<OneD, Array<OneD, NekDouble> > advVel(m_spacedim);
    m_advection->Advect(nVariables, m_fields, advVel, inarray, outarray, time);

    for (int i = 0; i < nVariables; ++i)
    {
        if (i ==  0)
        {
            // c^2 = gamma*p0/rho0
            Vmath::Vdiv(nq, m_basefield[0], 1, m_basefield[1], 1, tmp1, 1);
            Vmath::Smul(nq, m_gamma, tmp1, 1, tmp1, 1);
            Vmath::Vmul(nq, tmp1, 1, outarray[i], 1, outarray[i], 1);
        }

        Vmath::Neg(nq, outarray[i], 1);
    }

    AddSource(outarray);
}
Exemplo n.º 7
0
MyString 
MyString::operator + ( const unsigned src ) const {
   MyString tmp = *this; 
   MyString tmp1(src);
   tmp += src;
   return tmp;
}
Exemplo n.º 8
0
SEXP updateFaceNormals(SEXP vb_, SEXP it_) {
  try {
    NumericMatrix vb(vb_);
    IntegerMatrix it(it_);
    mat vbA(vb.begin(),vb.nrow(),vb.ncol());
    mat normals(it.nrow(), it.ncol()); normals.fill(0.0);
    imat itA(it.begin(),it.nrow(),it.ncol());
    int nit = it.ncol();
    colvec tmp0(3), tmp1(3), ntmp(3);
    for (int i=0; i < nit; ++i) {
      tmp0 = vbA.col(itA(1,i))-vbA.col(itA(0,i));
      tmp1 = vbA.col(itA(2,i))-vbA.col(itA(0,i));
    
      crosspArma(tmp0,tmp1,ntmp);
      double nlen = norm(ntmp,2);
      if (nlen > 0)
	ntmp /= nlen; 
      normals.col(i) = ntmp;
    
    }
    return Rcpp::wrap(normals);
  } catch (std::exception& e) {
    ::Rf_error( e.what());
  } catch (...) {
    ::Rf_error("unknown exception");
  }
}
Exemplo n.º 9
0
/* Takes a permutation pi over an m-dimensional cube C=Z_{n1} x ... x Z_{nm}
 * and expresses pi as a product pi = rho_{2m-1} o ... o rho_2 o rho_1 where
 * each rho_i is a column permutation along one dimension. Specifically for
 * i<m, the permutations rho_i and rho_{2(m-1)-i} permute the i'th dimension
 ************************************************************************/
void breakPermByDim(vector<ColPerm>& out, 
		    const Permut &pi, const CubeSignature& sig)
{
  assert(sig.getSize()==pi.length());

  HyperCube<long> tmp1(sig);  
  tmp1.getData() = pi;

  HyperCube<long> tmp2(sig);  

  HyperCube<long>* tp1 = &tmp1;
  HyperCube<long>* tp2 = &tmp2;

  // Allocate the output permutations
  long m = sig.getNumDims();
  ColPerm dummy(sig);
  out.assign(2*m-1, dummy); // allocate space and initialize

  if (m == 1) { // special case, no need to break
    HyperCube<long>& out0 = out[0];
    out0 = tmp1;
    out[0].setPermDim(0);
    return;
  }

  for (long i=0; i<m-2; i++) {
    breakPermTo3(*tp1, i, out[i], *tp2, out[2*m-i-2]);
    std::swap(tp1,tp2);
  }

  breakPermTo3(*tp1, m-2, out[m-2], out[m-1], out[m]);
  out[m-1].setPermDim(m-1);
}
Exemplo n.º 10
0
texture_2d tangent_flow_map(const texture_2d& src, float sigma) {
    texture_2d tmp0(src.clone_format());
    texture_2d tmp1(src.clone_format());
    texture_2d dst(src.clone_format());
    
    glsl_program sst("sst_fs.glsl");
    sst.use();
    sst.bind_sampler("img", src);
    sst.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    sst.draw(&tmp0);

    glsl_program gauss("gauss_fs.glsl");
    gauss.use();
    gauss.bind_sampler("img", tmp0);
    gauss.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    gauss.set_uniform_1f("sigma", sigma);
    gauss.draw(&tmp1);                  

    glsl_program tfm("tfm_fs.glsl");
    tfm.use();
    tfm.bind_sampler("img", tmp1);
    tfm.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    tfm.draw(&dst);

    return dst;
}
Exemplo n.º 11
0
VectorXf EMclustering::logsumexp(MatrixXf x, int dim)
{
	int r = x.rows();
	int c = x.cols();

	VectorXf y(r);
	MatrixXf tmp1(r,c);
	VectorXf tmp2(r);
	VectorXf s(r);

	y = x.rowwise().maxCoeff();//cerr<<"y"<<y<<endl<<endl;
	x = x.colwise() - y;	
	//cerr<<"x"<<x<<endl<<endl;
	tmp1 = x.array().exp();	
	//cerr<<"t"<<tmp1<<endl<<endl;
	tmp2 = tmp1.rowwise().sum();	
	//cerr<<"t"<<tmp2<<endl<<endl;
	s = y.array() + tmp2.array().log();

	for(int i=0;i<s.size();i++)
	{
		if(!isfinite(s(i)))
		{
			s(i) = y(i);
		}
	}

	y.resize(0);
	tmp1.resize(0,0);
	tmp2.resize(0);
	
	return s;
}
Exemplo n.º 12
0
Arquivo: PBC.cpp Projeto: cran/PBC
// Initialization of algorithm
void PBC::algoInit(vector <bool> isLeaf_v) {
  // Initialisation for mu and lamda functions
  vf_mu_.resize(binMat_.size());
  gra_vf_mu_.resize(binMat_.size());
  vector <double> tmp(binMat_[0].size());
  vector < vector <double> > tmp1(binMat_[0].size());
  vector <double> tmp2(theta_.size());
  for (unsigned i = 0; i < binMat_.size(); i++) {
    vf_mu_[i] = tmp;
    for (unsigned j = 0; j < binMat_[i].size(); j++) {	
	  tmp1[j] = tmp2;
	}
	gra_vf_mu_[i] = tmp1;
  }
  vf_la_ = vf_mu_;
  fv_mu_ = vf_mu_;
  fv_la_ = vf_mu_;
  gra_vf_la_ = gra_vf_mu_;
  gra_fv_mu_ = gra_vf_mu_;
  gra_fv_la_ = gra_vf_mu_;
  vector<double>().swap(tmp); // Free memory
  vector < vector <double> >().swap(tmp1); // Free memory
  vector<double>().swap(tmp2); // Free memory
  for (unsigned i = 0; i < binMat_.size(); i++)
    for (unsigned j = 0; j < binMat_[i].size(); j++)
      if ((isLeaf_v[i])&&(binMat_[i][j] == 1))
        vf_mu_[i][j] = 1.0;
}
Exemplo n.º 13
0
void ProsilicaCapture::run() {
    // main function of the thread
    // read a frame from the Prosilica camera,
    // convert to IplImage and store it to the global pool.

    if( camera != NULL ) {


		//declerations for old code
        //IplImage *cvimg;
        //IplImage *scaled_cvimg, *chn_cvimg;

        do{
            image = (Image*) camera->grabFrame();
            if(image == NULL) {
                readpool->clear();
                continue;
            }
			//this is our original image
			cv::Mat tmp1(cv::Size(image->width(), image->height()),CV_8UC4);
			//copy the data from the frame we just pulled
			tmp1.data = image->data();
			//reshape it to give it 3 channels
			//tmp1.reshape(3);
			cv::Mat tmp2;
			cv::cvtColor(tmp1, tmp2, CV_BGRA2BGR);
			//make a scaled copy of the image
			cv::Mat tmp3(cv::Size(480,360),CV_8UC3);
			cv::resize(tmp2,tmp3,cv::Size(480,360));
			//begin old code
			/*
            cvimg = cvCreateImage( cvSize(image->width(), image->height()), IPL_DEPTH_8U, 4 );
            cvimg->imageData = (char*)image->data();    // share buffers btw/ image and cvimg

            chn_cvimg = cvCreateImage( cvSize(image->width(), image->height()), IPL_DEPTH_8U, 3);
            cvConvertImage(cvimg, chn_cvimg);

            scaled_cvimg = cvCreateImage( cvSize(480, 360), IPL_DEPTH_8U, 3);
            cvResize(chn_cvimg, scaled_cvimg);
			*/
			//end old code
            // put the image to the pool

			/*
                    ID_image *id_image = new ID_image;
                    id_image->image = tmp2;
                    id_image->orig_image = tmp1;
            readpool->storeIDImage(id_image);
			*/
			readpool->storeImage(tmp2);

            //cvReleaseImage(&cvimg);
            //cvReleaseImage(&chn_cvimg);

                    QThread::usleep(1000000 / fps);
        } while (image != NULL && !stopped);

    }
}
Exemplo n.º 14
0
void DumpUnfreed()
{
	AllocList::iterator i;
	unsigned int totalSize = 0;

	if(!allocList)
		return;

	CFile f("/tmp/enigma2_mem.out", "w");
	if (!f)
		return;
	size_t len = 1024;
	char *buffer = (char*)malloc(1024);
	for(i = allocList->begin(); i != allocList->end(); i++)
	{
		unsigned int tmp;
		fprintf(f, "%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
			i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount);
		totalSize += i->second.size;

		char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount );
		for ( tmp=0; tmp < i->second.btcount; tmp++ )
		{
			if ( bt_string[tmp] )
			{
				char *beg = strchr(bt_string[tmp], '(');
				if ( beg )
				{
					std::string tmp1(beg+1);
					int pos1=tmp1.find('+'), pos2=tmp1.find(')');
					if ( pos1 != std::string::npos && pos2 != std::string::npos )
					{
						std::string tmp2(tmp1.substr(pos1,(pos2-pos1)));
						tmp1.erase(pos1);
						if (tmp1.length())
						{
							int state;
							abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state);
							if (!state)
								fprintf(f, "%d %s%s\n", tmp, buffer,tmp2.c_str());
							else
								fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
						}
					}
				}
				else
					fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
			}
		}
		free(bt_string);
		if (i->second.btcount)
			fprintf(f, "\n");
	}
	free(buffer);

	fprintf(f, "-----------------------------------------------------------\n");
	fprintf(f, "Total Unfreed: %d bytes\n", totalSize);
	fflush(f);
};
Exemplo n.º 15
0
void wxStatusBarBeOS::SetStatusBufferText(const wxString& text, int number)
{
    wxListString* st = GetOrCreateStatusBuffer(number);

    wxString tmp1(text);
    wxString* tmp = new wxString(tmp1);
    st->Insert(tmp);
}
Exemplo n.º 16
0
void ompl::base::ProjectionMatrix::project(const double *from, EuclideanProjection &to) const
{
    namespace nu = boost::numeric::ublas;
    // create a temporary uBLAS vector from a C-style array without copying data
    nu::shallow_array_adaptor<const double> tmp1(mat.size2(), from);
    nu::vector<double, nu::shallow_array_adaptor<const double>> tmp2(mat.size2(), tmp1);
    to = prod(mat, tmp2);
}
Exemplo n.º 17
0
void findPairTree(message &M1, message &M2, const difference &D, const DifferentialPath &P, int max_clique_size, ofstream& changes, int counter, message &M1_old, message &M2_old){
	if (counter > 10)
		return;
	vector<vector<int>> neutral_vectors;
	vector<vector<int>> tmp_neutral_vectors;
	vector<vector<int>> first_level, second_level;
	construct_neutral_set(M1, M2, D, P);
	read(neutral_vectors);
	set<int> clique;
	vector<vector<int>> best_bits;
	for (auto i = neutral_vectors.begin(); i != neutral_vectors.end(); i++){
		message tmp1(M1);
		message tmp2(M2);
		xor(tmp1.W, *i);
		xor(tmp2.W, *i);
		D.modify(tmp1, tmp2);
		construct_neutral_set(tmp1, tmp2, D, P);
		read(tmp_neutral_vectors);
		adj_matrix adj(tmp_neutral_vectors.size());
		adj.fill(tmp_neutral_vectors, tmp1, tmp2, D, P);
		kerbosh(adj.adj, adj.adj[1].size(), clique, tmp_neutral_vectors);
		if (clique.size() == max_clique_size){
			first_level.push_back({ (*i)[0], (*i)[1], (*i)[2], (*i)[3], (*i)[4] });
		}
		if (clique.size() > max_clique_size){
			max_clique_size = clique.size();
			first_level.clear();
			first_level.push_back({ (*i)[0], (*i)[1], (*i)[2], (*i)[3], (*i)[4] });
			if (clique.size() >= 35){
				printGoodBits(M1_old, tmp1, changes);
			}
		}
		tmp_neutral_vectors.clear();
		clique.clear();
	}

	for (auto i = first_level.begin(); i != first_level.end(); i++){
		message tmp1(M1);
		message tmp2(M2);
		xor(tmp1.W, *i);
		xor(tmp2.W, *i);
		D.modify(tmp1, tmp2);
		findPairTree(tmp1, tmp2, D, P, max_clique_size, changes, ++counter, M1_old, M2_old);
	}
	return;
}
Exemplo n.º 18
0
void stimulus::entry() {

    reset.write(true);
    wait();
    reset.write(false);

    sc_signed       tmp1(8);
    sc_signed       tmp2(8);
    long            tmp3;
    int             tmp4;
    short           tmp5;
    char            tmp6;
    char            tmp7;
    bool            tmp8;
    sc_unsigned     tmp9(4);
    sc_unsigned     tmp10(4);

    tmp1 = "0b01010101";
    tmp2 = "0b00000010";
    tmp3 = 12345678;
    tmp4 = -123456;
    tmp5 = 20000;
    tmp6 = '$'; 
    tmp7 = 'A';
    tmp8 = "0";
    tmp9 = "0b0001";
    tmp10 = "0b0010";

    while(true){
       out_valid.write(true);
       out_value1.write(tmp1);
       out_value2.write(tmp2);
       out_value3.write(tmp3);
       out_value4.write(tmp4);
       out_value5.write(tmp5);
       out_value6.write(tmp6);
       out_value7.write(tmp7);
       out_value8.write(tmp8);
       out_value9.write(tmp9);
       out_value10.write(tmp10);
       cout << "Stimuli: " << tmp1 << " " << tmp2 << " " << tmp3 << " " << tmp4 << " "
	    << tmp5 << " " << tmp6 << " " << tmp7 << " " << tmp8 << " " << tmp9  << " " << tmp10 <<endl;
       tmp1 = tmp1 + 2;
       tmp2 = tmp2 + 1;
       tmp3 = tmp3 + 5;
       tmp4 = tmp4 + 3;
       tmp5 = tmp5 + 6;
       tmp7 = tmp7 + 1;
       tmp8 = !tmp8;
       tmp9 = tmp9 + 1;
       tmp10 = tmp10 + 1;
       do { wait(); } while (in_ack==false);
       out_valid.write(false);
       wait();
    }
}
Exemplo n.º 19
0
void wxStatusBarBase::PushStatusText(const wxString& text, int number)
{
    wxListString* st = GetOrCreateStatusStack(number);
    // This long-winded way around avoids an internal compiler error
    // in VC++ 6 with RTTI enabled
    wxString tmp1(GetStatusText(number));
    wxString* tmp = new wxString(tmp1);
    st->Insert(tmp);
    SetStatusText(text, number);
}
Exemplo n.º 20
0
Expression NonsmoothOperator::operator*( const Operator& arg ) const{

    Expression tmp2(arg);


    Expression tmp1(*this);


    return tmp1*tmp2;
}
Exemplo n.º 21
0
	bool operator()(std::string const& s1, std::string const& s2)
	{
		std::string tmp1(s1);
		std::sort(tmp1.begin(), tmp1.end());
		
		std::string tmp2(s2);
		std::sort(tmp2.begin(), tmp2.end());

		return tmp1 < tmp2;
	}
Exemplo n.º 22
0
void P_graded(vector<double> &P, const vector<double> &par,
    const NumericMatrix &Theta, const NumericVector &ot, const int &N,
    const int &nfact, const int &nint, const int &itemexp, const int &israting)
{
    const int parsize = par.size();
    vector<double> a(nfact);
    for(int i = 0; i < nfact; ++i) a[i] = par[i];
    vector<double> d(nint, 0.0);
    if(israting){
        const double t = par[parsize-1];
        for(int i = nfact; i < parsize - 1; ++i)
            d[i - nfact] = par[i] + t;
    } else {
        for(int i = nfact; i < parsize; ++i)
            d[i - nfact] = par[i];
    }
    int notordered = 0;
    for(int i = 1; i < nint; ++i)
        notordered += d[i-1] <= d[i]; 
    if(notordered){
        for(int i = 0; i < P.size(); ++i)
            P[i] = 0.0;
    } else {        
        const double nullzero = 0.0, nullone = 1.0;
        NumericMatrix Pk(N, nint + 2);
    
        for(int i = 0; i < N; ++i)
            Pk(i,0) = 1.0;
        for(int i = 0; i < nint; ++i){
            vector<double> tmp1(N), tmp2(N);
            itemTrace(tmp1, tmp2, a, &d[i], Theta, &nullzero, &nullone, ot);
            for(int j = 0; j < N; ++j)
                Pk(j,i+1) = tmp2[j];
        }
        if(itemexp){
            int which = N * (nint + 1) - 1;
            for(int i = (Pk.ncol()-2); i >= 0; --i){
                for(int j = (N-1); j >= 0; --j){
                    P[which] = Pk(j,i) - Pk(j,i+1);
                    if(P[which] < 1e-20) P[which] = 1e-20;
                    else if((1.0 - P[which]) < 1e-20) P[which] = 1.0 - 1e-20;
                    --which;
                }
            }
        } else {
            int which = 0;
            for(int i = 0; i < Pk.ncol(); ++i){
                for(int j = 0; j < Pk.nrow(); ++j){
                    P[which] = Pk(j,i);
                    ++which;
                }
            }
        }
    }
}
Exemplo n.º 23
0
LinearProblem LinearProblem::dualize(LinearProblem::Type t){
	LinearProblem dual;
	dual.isDual = true;
	dual.type = t;
	dual.nbConstraints = this->constraints.cols() - 1;
	dual.nbVars = this->nbConstraints ; // on ne recupere pas les contraitnes de type x>=0 car les variables vont changer
	// nb ligne : nb contraintes + nb contraintes sur les var ( type x >= 0 ) | nb colonnes : nb vars + nb contraintes + 1 pour la partie droite de l'inégalité */
	dual.constraints.resize(dual.nbConstraints,dual.nbVars+1);
	dual.objective = this->constraints.col(0);
	int cpt=0;

	/* On remplit les premières lignes de la matrices avec les nouvelles contraintes*/
	for(int i=0; i< this->objective.rows() ; i++)
	{
		Eigen::VectorXf tmp(dual.nbVars+1);
		tmp(0) =  this->objective(i);
		for (int j=0; j< dual.nbVars ; j++)
		{
			tmp(j+1)=  this->constraints(j,i+1) ;
		}
		dual.constraints.row(cpt) = tmp;
		cpt++;
	}

	/* On remplit les dernière lignes avec les contraintes de type x >= 0*/

	dual.constraints.conservativeResize(dual.nbConstraints+dual.nbVars,dual.nbVars+1);
	for(int k = 0 ; k < dual.nbVars ; k++){
		Eigen::VectorXf tmp1(dual.nbVars+1);
		int j(0);
		tmp1(j++) = 0;
		for(int l = 0 ; l< dual.nbVars ; l++){
			if(dual.constraints(l) == dual.constraints(k))
				tmp1(j++) = 1;
			else
				tmp1(j++) = 0;
		}
		dual.constraints.row(cpt++) = tmp1;
	}
	return dual;
}
 int rob(vector<int>& nums) {
     if(nums.empty())
         return 0;
     if (nums.size() < 4)
         return *(max_element(nums.begin(), nums.end()));
     vector<int> tmp1(nums.begin() + 1, nums.end());
     int max1 = Sol(tmp1);
     vector<int> tmp2(nums.begin() + 2, nums.end() - 1);
     int max2 = nums[0] + Sol(tmp2);
     return max(max1, max2);
         
 }
Exemplo n.º 25
0
SEXP updateVertexNormals(SEXP vb_, SEXP it_,SEXP angweight_) {
  try {
    typedef unsigned int uint;
    bool angweight = Rcpp::as<bool>(angweight_);
    NumericMatrix vb(vb_);
    IntegerMatrix it(it_);
    mat vbA(vb.begin(),vb.nrow(),vb.ncol());
    mat normals = vbA*0;
    imat itA(it.begin(),it.nrow(),it.ncol());
    //setup vectors to store temporary data
    colvec tmp0(3), tmp1(3), tmp2(3), angtmp(3), ntmp(3);
    int nit = it.ncol();
    for (int i=0; i < nit; ++i) {
      tmp0 = vbA.col(itA(1,i))-vbA.col(itA(0,i));
      tmp1 = vbA.col(itA(2,i))-vbA.col(itA(0,i));
      if (angweight) {
	tmp2 = vbA.col(itA(1,i))-vbA.col(itA(2,i));
	angtmp(0) = angcalcArma(tmp0,tmp1);
	angtmp(1) = angcalcArma(tmp0, tmp2);
	angtmp(2) = angcalcArma(-tmp1, tmp2);
      }
      crosspArma(tmp0,tmp1,ntmp);
      for (int j=0; j < 3; ++j) {
	double co = dot(normals.col(itA(j,i)),ntmp);
      
	if (co < 0)  {
	  if (!angweight) {
	    normals.col(itA(j,i)) -= ntmp;
	  } else {
	    normals.col(itA(j,i)) -= ntmp*angtmp(j);
	  }
	} else {
	  if (! angweight) {
	    normals.col(itA(j,i)) += ntmp;
	  } else {
	    normals.col(itA(j,i)) += ntmp*angtmp(j);
	  }
	}
      }
    }
    for (uint i=0; i < normals.n_cols; ++i) {
      double nlen = norm(normals.col(i),2);
      if (nlen > 0)
	normals.col(i) /= nlen;
    }
		       
    return Rcpp::wrap(normals);
  } catch (std::exception& e) {
    ::Rf_error( e.what());
  } catch (...) {
    ::Rf_error("unknown exception");
  }
}
Exemplo n.º 26
0
/**
 * Description not yet available.
 * \param
 */
void lvector::fill_multinomial(const int& seed, const dvector& p)
  // Fils a dvector with random numbers drawn from a multinomial distribution
  {
    double sum=mean(p)*p.size();
    int pmin=p.indexmin();
    int pmax=p.indexmax();
    dvector tmp(pmin,pmax);
    dvector tmp1(pmin,pmax);
    dvector choose(indexmin(),indexmax());
    choose.fill_randu(seed);
    tmp=p/sum;
    tmp1(pmin)=tmp(pmin);
    for (int j=pmin+1;j<=pmax-1;j++)
    {
      tmp1(j)=tmp1(j-1)+tmp(j);
    }
    tmp1(pmax)=1.0;

    for (int i=indexmin();i<=indexmax();i++)
    {
      int j=pmin;
      while (choose(i)>tmp1(j))
      {
        j++;
      }
      (*this)(i)=j;
    }
  }
Exemplo n.º 27
0
    int ZmqEnd::startMsgLoop() {

        std::unique_ptr<std::thread> tmp1(new std::thread(std::mem_fn(&ZmqEnd::frontThreadFunc), this));
        mPtrMsgRThread = std::move(tmp1);

        std::unique_ptr<std::thread> tmp2(new std::thread(std::mem_fn(&ZmqEnd::backThreadFunc), this));
        mPtrMsgDThread = std::move(tmp2);
       
       mQuerySock.setsockopt(ZMQ_IDENTITY, mQuerySockID.c_str(), mQuerySockID.size()); 
       mQuerySock.connect(mExternUri);

        return 0;    
    }
Exemplo n.º 28
0
bool checkEqual(Queue *queue, Buf *buf1, Buf *buf2, int size) {
  std::unique_ptr<int[]> tmp1(new int[size]);
  std::unique_ptr<int[]> tmp2(new int[size]);
  queue->readBlocking(buf1, 0, sizeof(int) * size, tmp1.get());
  queue->readBlocking(buf2, 0, sizeof(int) * size, tmp2.get());
  int err = 0;
  for (int i = 0; i < size; ++i) {
    if (tmp1[i] != tmp2[i]) {
      printf("%d %d %d\n", i, tmp1[i], tmp2[i]);
      if (++err >= 10) { return false; }
    }
  }
  return true;
}
Exemplo n.º 29
0
Arquivo: Dip2.cpp Projeto: kziel1/dip
/*
fname:   path to input image
*/
void Dip2::generateNoisyImages(string fname){
 
   // load image, force gray-scale
   cout << "load original image" << endl;
   Mat img = imread(fname, 0);
   if (!img.data){
      cerr << "ERROR: file " << fname << " not found" << endl;
      cout << "Press enter to exit"  << endl;
      cin.get();
      exit(-3);
   }

   // convert to floating point precision
   img.convertTo(img,CV_32FC1);
   cout << "done" << endl;

   // save original
   imwrite("original.jpg", img);
	  
   // generate images with different types of noise
   cout << "generate noisy images" << endl;

   // some temporary images
   Mat tmp1(img.rows, img.cols, CV_32FC1);
   Mat tmp2(img.rows, img.cols, CV_32FC1);
   // first noise operation
   float noiseLevel = 0.15;
   randu(tmp1, 0, 1);
   threshold(tmp1, tmp2, noiseLevel, 1, CV_THRESH_BINARY);
   multiply(tmp2,img,tmp2);
   threshold(tmp1, tmp1, 1-noiseLevel, 1, CV_THRESH_BINARY);
   tmp1 *= 255;
   tmp1 = tmp2 + tmp1;
   threshold(tmp1, tmp1, 255, 255, CV_THRESH_TRUNC);
   // save image
   imwrite("noiseType_1.jpg", tmp1);
    
   // second noise operation
   noiseLevel = 50;
   randn(tmp1, 0, noiseLevel);
   tmp1 = img + tmp1;
   threshold(tmp1,tmp1,255,255,CV_THRESH_TRUNC);
   threshold(tmp1,tmp1,0,0,CV_THRESH_TOZERO);
   // save image
   imwrite("noiseType_2.jpg", tmp1);

	cout << "done" << endl;
	cout << "Please run now: dip2 restorate" << endl;

}
Exemplo n.º 30
0
//复数类的四则运算
int main()
{
	Fushu a(10);
	Fushu b(20);
	Fushu tmp1(a+b);
	tmp1.Show();
	Fushu tmp2(a-b);
	tmp2.Show();
	Fushu tmp3(a*b);
	tmp3.Show();
	Fushu tmp4(a/b);
	tmp4.Show();
	return 0;
}