Beispiel #1
0
void SkinnedMesh::RenderSkeleton(Bone* bone, Bone *parent, D3DXMATRIX world) {
    //Temporary function to render the bony hierarchy

    if (world == NULL)return;
    if (bone == NULL)bone = (Bone*)m_pRootBone;

    //Draw line between bones
    if (parent != NULL && bone->Name != NULL && parent->Name != NULL) {
        //Draw Sphere
        g_pDevice->SetRenderState(D3DRS_LIGHTING, true);
        g_pDevice->SetTransform(D3DTS_WORLD, &(bone->CombinedTransformationMatrix * world));
        m_pSphereMesh->DrawSubset(0);

        D3DXMATRIX w1 = bone->CombinedTransformationMatrix;
        D3DXMATRIX w2 = parent->CombinedTransformationMatrix;

        //Extract translation
        D3DXVECTOR3 thisBone = D3DXVECTOR3(w1(3, 0), w1(3, 1), w1(3, 2));
        D3DXVECTOR3 ParentBone = D3DXVECTOR3(w2(3, 0), w2(3, 1), w2(3, 2));

        if (D3DXVec3Length(&(thisBone - ParentBone)) < 2.0f) {
            g_pDevice->SetTransform(D3DTS_WORLD, &world);
            VERTEX vert[] = {VERTEX(ParentBone, 0xffff0000), VERTEX(thisBone, 0xff00ff00)};
            g_pDevice->SetRenderState(D3DRS_LIGHTING, false);
            g_pDevice->SetFVF(VERTEX::FVF);
            g_pDevice->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, &vert[0], sizeof(VERTEX));
        }
    }

    if (bone->pFrameSibling)RenderSkeleton((Bone*)bone->pFrameSibling, parent, world);
    if (bone->pFrameFirstChild)RenderSkeleton((Bone*)bone->pFrameFirstChild, bone, world);
}
Beispiel #2
0
void quadSYSspline::calculateNNWeightParameters(){
	w1 = Eigen::MatrixXf(nn,3);
	w2 = Eigen::MatrixXf(nn,3);

	//Populating w1 and w2 matricies from the vectors
	for(int i=0;i<nn;i++){
		w1(i,1) = w1col(i);
		w1(i,2) = w1col(nn+i);
		w1(i,3) = w1col((2*nn)+i);
		w2(i,1) = w2col(i);
		w2(i,2) = w2col(nn+i);
		w2(i,3) = w2col((2*nn)+i);
	}
}
  void runRoadsTest()
  {
    //test highway (linestring)
    shared_ptr<OsmMap> map(new OsmMap());
    _map = map;

    shared_ptr<Way> w1(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w1->setTag("highway", "track");
    w1->setTag("name", "w1");
    w1->addNode(createNode(0, 0)->getId());
    w1->addNode(createNode(10, 0)->getId());
    _map->addWay(w1);

    shared_ptr<Way> w2(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w2->setTag("highway", "road");
    w2->setTag("name", "w2");
    w2->addNode(createNode(-1, 1)->getId());
    w2->addNode(createNode(9, 0)->getId());
    _map->addWay(w2);

    HausdorffDistanceExtractor uut;
    const OsmMap* constMap = const_cast<const OsmMap*>(_map.get());
    CPPUNIT_ASSERT_DOUBLES_EQUAL(
      sqrt(2.0),
      uut.distance(*constMap, boost::const_pointer_cast<const Way>(w1),
        boost::const_pointer_cast<const Way>(w2)),
      0.000001);
  }
Beispiel #4
0
//! \brief calculates the coefficients for lowpass FIR based on Remez
// constraints
void create_remez_lpfir(fir_coeff<float_type>& remezfir, float_type pass_edge, float_type stop_edge,
                        float_type stop_weight) {
  bool ok = true;
  std::vector<float_type> e1(4);
  std::vector<float_type> f1(4);
  std::vector<float_type> w1(4);
  long nfilt = remezfir.num_taps;
  remez_fir Remz;
  w1[0] = 1.0;
  w1[1] = stop_weight;
  e1[0] = 0;
  e1[1] = pass_edge / 2.0;
  e1[2] = stop_edge / 2.0;
  e1[3] = 0.5;
  f1[0] = 1.0;
  f1[1] = 0.0;
  std::vector<float_type> fir_coef(nfilt);
  ok = Remz.remez(fir_coef, nfilt, 2, e1, f1, w1, 1);
  if (ok) {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, fir_coef[i]);
  } else {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, 0);
    remezfir.settap(0, 1);
  }
}
Beispiel #5
0
double angleBetweenVectors(const Vector& v, const Vector& w)
{
    Vector v1 (v), w1(w);
    v1.normalize();
    w1.normalize();
    return acos(v1.dotProduct(w1));
}
Beispiel #6
0
// nand gate sizing calculation
void Htree2::input_nand(double s1, double s2, double l_eff)
{
  Wire w1(wt, l_eff);
  double pton_size = deviceType->n_to_p_eff_curr_drv_ratio;
  // input capacitance of a repeater  = input capacitance of nand.
  double nsize = s1*(1 + pton_size)/(2 + pton_size);
  nsize = (nsize < 1) ? 1 : nsize;

  double tc = 2*tr_R_on(nsize*min_w_nmos, NCH, 1) *
    (drain_C_(nsize*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)*2 +
     2 * gate_C(s2*(min_w_nmos + min_w_pmos), 0));
  delay+= horowitz (w1.out_rise_time, tc,
      deviceType->Vth/deviceType->Vdd, deviceType->Vth/deviceType->Vdd, RISE);
  power.readOp.dynamic += 0.5 *
    (2*drain_C_(pton_size * nsize*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
     + drain_C_(nsize*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)
     + 2*gate_C(s2*(min_w_nmos + min_w_pmos), 0)) *
    deviceType->Vdd * deviceType->Vdd;

    power.searchOp.dynamic += 0.5 *
    (2*drain_C_(pton_size * nsize*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
     + drain_C_(nsize*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)
     + 2*gate_C(s2*(min_w_nmos + min_w_pmos), 0)) *
    deviceType->Vdd * deviceType->Vdd * wire_bw ;
  power.readOp.leakage += (wire_bw*cmos_Isub_leakage(min_w_nmos*(nsize*2), min_w_pmos * nsize * 2, 2, nand))*deviceType->Vdd;
  power.readOp.gate_leakage += (wire_bw*cmos_Ig_leakage(min_w_nmos*(nsize*2), min_w_pmos * nsize * 2, 2, nand))*deviceType->Vdd;
}
Beispiel #7
0
int main()
{
	EXECUTOR::Executor * ex = EXECUTOR::ExecutorFactory::instance().createUnorderedExecution();
	WORK::Work<void,int,int> w([] (int a,int b) -> void { std::cout << a << b << std::endl; },12,15);

	Test t;
	WORK::Work<void> w1(std::bind(&Test::print,t,"hola"));

	std::future<bool> fut = ex->addWork(&w);
	std::future<bool> fut2 = ex->addWork(&w1);
	std::future<bool> fut3 = ex->addWork(&w);

	std::function<void()> workFinished = [&fut] () {
		if(fut.get()) { std::cout << "work finished" << std::endl; }
	};

	std::function<void()> workFinished2 = [&fut2] () {
		if(fut2.get()) { std::cout << "work finished 2" << std::endl; }
	};

	std::function<void()> workFinished3 = [&fut3] () {
		if(fut3.get()) { std::cout << "work finished 3" << std::endl; }
	};

	std::thread(workFinished).detach();
	std::thread(workFinished2).detach();
	std::thread(workFinished3).detach();

	EXECUTOR::ExecutorFactory::instance().removeExecutorNoWaiting(ex);

	usleep(10000);

}
Beispiel #8
0
    // Decrement weak count
    void weak_6()
    {
        assert_ck(0, 0);

        {
            shared_test s0(test_behavior::init());
            assert_ck(1, 0);

            assert(s0.use_count() == 1);

            weak_test w0(s0);

            assert(s0.use_count() == 1);
            assert(!w0.expired());

            {
                weak_test w1(w0);
                assert(s0.use_count() == 1);
                assert(!w0.expired());
                assert(!w1.expired());
            }

            assert(s0.use_count() == 1);
            assert(!w0.expired());
        }

        assert_ck(1, 1);
    }
Beispiel #9
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);

  auto_ptr<Widget> w1 (Widget_Factory::create_widget ());
  w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part1", 1));
  w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part2", 2));
  w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part3", 3));

  w1->list_parts ();

  auto_ptr<Widget_Part> p1 (w1->remove_part ());
  p1->print_info ();
  auto_ptr<Widget_Part> p2 (w1->remove_part ());

  w1->list_parts ();

  auto_ptr<Widget> w2 (Widget_Factory::create_widget ());
  w2->add_part (Widget_Part_Factory::create_widget_part (w2.get(), "part4", 4));
  Widget_Part *p3 = Widget_Part_Factory::create_widget_part (w2.get(), "part5", 5);
  w2->add_part (p3);
  p3->remove_from_owner ();

  w2->list_parts ();

  return 0;
}
Beispiel #10
0
CORBA::WChar * GoodDay_i::hello_wide (const CORBA::WChar * msg)
{
  ACE_WString w1( CORBA::wstring_dup( msg ));
  cout << w1 << endl;
  ACE_WString w(ACE_TEXT_ALWAYS_WCHAR ("aaaa"));
  return CORBA::wstring_dup( w.c_str() );
}
  void runTestMulti()
  {
    TranslatedTagDifferencer uut;
    Settings s;
    s.set(ConfigOptions::getTranslatedTagDifferencerScriptKey(),
          "translations/HootTest.js");
    // ignore the UFI
    s.set(ConfigOptions::getTranslatedTagDifferencerIgnoreListKey(), "UFI");
    uut.setConfiguration(s);

    shared_ptr<OsmMap> map(new OsmMap());
    WayPtr w1(new Way(Status::Unknown1, -1, 0));
    w1->getTags()["name"] = "foo";
    w1->getTags()["highway"] = "road";

    WayPtr w2(new Way(Status::Unknown1, -1, 0));
    w2->getTags()["name"] = "foo";
    w2->getTags()["highway"] = "road";
    w2->getTags()["bridge"] = "yes";

    // creates one record in w1 and two in w2.
    CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0 / 11.0, uut.diff(map, w1, w2), 1e-5);

    WayPtr w3(new Way(Status::Unknown1, -1, 0));
    w3->getTags()["name"] = "foo";
    w3->getTags()["highway"] = "road";
    w3->getTags()["bridge"] = "yes";

    WayPtr w4(new Way(Status::Unknown1, -1, 0));
    w4->getTags()["name"] = "bar";
    w4->getTags()["highway"] = "road";
    w4->getTags()["bridge"] = "yes";

    CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 / 11.0, uut.diff(map, w3, w4), 1e-5);
  }
Beispiel #12
0
/////////////////////MAIN////////////////////////
int main(int argc, char** argv) {

  load_geom(argc, argv);

  QApplication app(argc, argv);
  glutInit(&argc, argv);

  if ( !QGLFormat::hasOpenGL() ) {
    qWarning( "This system has no OpenGL support. Exiting." );
    return EXIT_FAILURE;
  }

  QMainWindow main;

  SketchSample* sketch = new SketchSample(&m_mesh, &ppal_data);
  Observer* obs = new Observer(sketch);

  GLWidget w1(&main, "OpenGL", obs);
  main.setCentralWidget( &w1 );
  main.resize( 500, 500 );
  app.setMainWidget(&main);

  main.show();

  return app.exec();
}
Beispiel #13
0
//______________________________________________________________________________
void WriteARCalibration()
{
    // load CaLib
    gSystem->Load("libCaLib.so");
    
    // write tagger calibration file
    TCWriteARCalib w(kDETECTOR_TAGG, "FP.dat");
    w.Write("new_FP.dat", "LD2_Dec_07", 13840);

    // write CB calibration file
    TCWriteARCalib w1(kDETECTOR_CB, "NaI.dat");
    w1.Write("new_NaI.dat", "LD2_Dec_07", 13840);

    // write TAPS calibration file
    TCWriteARCalib w2(kDETECTOR_TAPS, "BaF2.dat");
    w2.Write("new_BaF2.dat", "LD2_Dec_07", 13090);

    // write PID calibration file
    TCWriteARCalib w3(kDETECTOR_PID, "PID.dat");
    w3.Write("new_PID.dat", "LD2_Dec_07", 13840);

    // write Veto calibration file
    TCWriteARCalib w4(kDETECTOR_VETO, "Veto.dat");
    w4.Write("new_Veto.dat", "LD2_Dec_07", 13840);

    gSystem->Exit(0);
}
Beispiel #14
0
void CategoryTest::TestRandomWord()
{
	Word w1("cat"), w2("cow"), w3("dog");
	TWordVec returned;

	m_DefaultCategory.AddWord(w1);
	m_DefaultCategory.AddWord(w2);
	m_DefaultCategory.AddWord(w3);

	Word w = m_DefaultCategory.GetRandomWord();
	CPPUNIT_ASSERT(find(returned.begin(), returned.end(), w) == returned.end());

	returned.push_back(w);
	w = m_DefaultCategory.GetRandomWord();
	CPPUNIT_ASSERT(find(returned.begin(), returned.end(), w) == returned.end());

	returned.push_back(w);
	w = m_DefaultCategory.GetRandomWord();
	CPPUNIT_ASSERT(find(returned.begin(), returned.end(), w) == returned.end());

	returned.push_back(w);
	w = m_DefaultCategory.GetRandomWord();
	CPPUNIT_ASSERT(find(returned.begin(), returned.end(), w) != returned.end());
	CPPUNIT_ASSERT(w != InvalidWord);

	// Clear the category and try to retrieve
	// a random word to see if the class has
	// cleared the random index vector
	m_DefaultCategory.Clear();
	CPPUNIT_ASSERT(m_DefaultCategory.GetRandomWord() == InvalidWord);
}
	void testInternationalizedEmail_folding()
	{
		vmime::generationContext ctx(vmime::generationContext::getDefaultContext());
		ctx.setInternationalizedEmailSupport(true);

		vmime::generationContext::switcher <vmime::generationContext> contextSwitcher(ctx);

		// RFC-2047 encoding must be performed, as line folding is needed
		vmime::word w1("01234567890123456789\xc3\xa0x012345678901234567890123456789"
		               "01234567890123456789\xc3\xa0x012345678901234567890123456789", vmime::charset("utf-8"));

		VASSERT_EQ("1",
			"=?utf-8?Q?01234567890123456789=C3=A0x01234567890?=\r\n"
			" =?utf-8?Q?1234567890123456789012345678901234567?=\r\n"
			" =?utf-8?Q?89=C3=A0x0123456789012345678901234567?=\r\n"
			" =?utf-8?Q?89?=", w1.generate(50));

		// RFC-2047 encoding will not be forced, as words can be wrapped in a new line
		vmime::word w2("bla bla bla This is some '\xc3\xa0\xc3\xa7' UTF-8 encoded text", vmime::charset("utf-8"));

		VASSERT_EQ("2",
			"bla bla bla This is\r\n"
			" some '\xc3\xa0\xc3\xa7' UTF-8\r\n"
			" encoded text", w2.generate(20));
	}
bool TestParserStmt::TestYieldStatement() {

  WithOpt w0(RuntimeOption::EnableHipHopSyntax);
  WithOpt w1(Option::EnableHipHopSyntax);

  V("<?php function foo() { yield break;}",
    "function foo() {\n"
    "return;\n"
    "}\n");

  V("<?php function foo() { yield 123;}",
    "function foo() {\n"
    "yield 123;\n"
    "}\n");

  V("<?php class bar { function foo() { yield 123; yield 456;} }",
    "class bar {\n"
    "public function foo() {\n"
    "yield 123;\n"
    "yield 456;\n"
    "}\n"
    "}\n");

  return true;
}
Beispiel #17
0
bool TestCodeError::Verify(Compiler::ErrorType type, const char *src,
                           const char *file, int line, bool exists) {
  WithOpt w0(Option::RecordErrors);
  WithOpt w1(Option::WholeProgram);
  WithOpt w2(Option::ParseTimeOpts);

  Compiler::ClearErrors();

  Type::ResetTypeHintTypes();
  Type::InitTypeHintMap();
  BuiltinSymbols::LoadSuperGlobals();

  AnalysisResultPtr ar(new AnalysisResult());
  // for TestPHPIncludeFileNotInLib
  Compiler::Parser::ParseString("<?php ", ar, "f2");
  Compiler::Parser::ParseString(src, ar, "f1");
  BuiltinSymbols::Load(ar);
  ar->analyzeProgram();
  ar->inferTypes();
  ar->analyzeProgramFinal();
  if (Compiler::HasError(type) != exists) {
    std::ostringstream error;
    JSON::CodeError::OutputStream out(error, ar);
    Compiler::SaveErrors(out);
    printf("%s:%d: parsing %s\ncode error missing\n%s\n", file, line, src,
           error.str().c_str());
    return false;
  }
  return true;
}
  void runRoadsTest()
  {
    //test highway (linestring)
    OsmMapPtr map(new OsmMap());
    _map = map;

    WayPtr w1(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w1->setTag("highway", "track");
    w1->setTag("name", "w1");
    w1->addNode(createNode(-104.9, 38.855)->getId());
    w1->addNode(createNode(-104.899, 38.8549)->getId());
    _map->addWay(w1);

    WayPtr w2(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w2->setTag("highway", "road");
    w2->setTag("name", "w2");
    w2->addNode(createNode(-104.91, 38.8548)->getId());
    w2->addNode(createNode(-104.8993, 38.8548)->getId());
    _map->addWay(w2);

    CentroidDistanceExtractor uut;
    const OsmMap* constMap = const_cast<const OsmMap*>(_map.get());
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.00515218,
                                 uut.distance(*constMap, boost::const_pointer_cast<const Way>(w1), boost::const_pointer_cast<const Way>(w2)),
                                 0.000001);
  }
Beispiel #19
0
bool loadJVM(){
	if (_libInst!=NULL)return false;
	char* pPath = getenv("JAVA_HOME");
	std::string jvmdll ;
	if (pPath==NULL) jvmdll=".\\jre";
	else jvmdll=pPath;
	//Util::Logger::globalLog->log("java home=%s", jvmdll.c_str());
	if (file_exists((jvmdll + "\\bin\\client\\jvm.dll").c_str())) {
		jvmdll += "\\bin\\client\\ .dll";
	} else if (file_exists((jvmdll + "\\jre\\bin\\client\\jvm.dll").c_str())) {
		//prolly a JDK
		jvmdll += "\\jre\\bin\\client\\jvm.dll";
	} else {
		//Util::Logger::globalLog->log("jvm.dll not found");
		error( TEXT("Could not find Java, Did you set JAVA_HOME correctly?"));   
		return false;
	}
	//Util::Logger::globalLog->log("jvm.dll is %s", jvmdll.c_str());
	std::wstring w1 (jvmdll.begin(), jvmdll.end());
	if ( (_libInst = LoadLibrary(w1.c_str())) == NULL) {
		std::wstring m = TEXT("Can't load "); m=m+w1;
		error(m.c_str());
		return false;
	}

	//Util::Logger::globalLog->log("dll loaded");
	return true;
}
Beispiel #20
0
//A triangular prism (no boundary edges)
void SubdivScene::scenario3() {

  VertexData w1(5,0,0);
  w1.colour(1,0,0);
  VertexData w2(0,0,10);
  w2.colour(1,1,0);
  VertexData w3(-5,0,0);
  w3.colour(0,0,1);
  VertexData w4(0,10,0);
  
  HDS.beginPolygon(w1);
  HDS.nextVertex(w2);
  Edge& e = HDS.nextVertex(w3); //edge from w3 to w1
  e.vertex->print();
  Face& f = HDS.endPolygon();

  HDS.beginPolygon(e);
  HDS.nextVertex(w4);
  HDS.endPolygon(); 
  const std::vector<Vertex*>& vList = HDS.getVertexList();
  Vertex* list[3] = { vList[2], vList[1], vList[3] };
  HDS.makePolygon(3, list);
  Vertex* list2[3] = { vList[1], vList[0], vList[3] };
  HDS.makePolygon(3, list2);

  const std::vector<Face*> fList = HDS.getFaceList();

  for(unsigned int i=0; i< fList.size(); i++) {
    HDS.checkConsistency(*fList[i]);
  }
}
Beispiel #21
0
int main(int argc, const char **argv) {
  std::shared_ptr<test_shared> p1 = std::make_shared<test_shared>(0), p2;
  std::weak_ptr<test_shared> w1(p1->shared_from_this());
  
  p2 = w1.lock();

  return (p1==p2)?p1->value:1;
}
Beispiel #22
0
int main()
{
    sem_init(&f,0,10);
    sem_init(&s,0,10);
    w1();
    w2();
 //   pthread_mutex_init(&f,NULL);
 //   pthread_mutex_init(&s,NULL);
}
Beispiel #23
0
	void testVecDot() {
		glam::vec4 v1(1, 2, 3.5, 100);
		glam::vec4 w1(0.5, 80, 20, 0.1);
		float u1 = glam::dot(v1, w1);
		TS_ASSERT_EQUALS(u1, 240.5f);
		glam::Vector<double, 7> v2(1, 2, 3, 4, 5, 6, 0);
		glam::Vector<double, 7> w2(0, 6, 5, 4, 3, 2, 1);
		TS_ASSERT_EQUALS(glam::dot(v2, w2), 70);
	}
void main()
{	
	int i,j,m=2;
	double y[50],y1[5];
	srand((unsigned)time(NULL));
	FILE *fp;
	fp=fopen("filter.xls","w+");
	for(N=1;N<=N1;N++)
	{
		for(i=0;i<n;i++)
		{
			z[i]=0;
			z[i]=w1();
		}
		w3();
		w4();
		y[N-1]=asd;
		fprintf(fp,"%d\t%lf\n",N,y[N-1]);
	}
	//
	for(i=m;i<N1-m;i++)
	{
		y1[0]=(1.0/5.0)*(3*y[i-2]+2*y[i-1]+y[i]-y[i+2]);
		y1[1]=(1.0/10.0)*(4*y[i-2]+3*y[i-1]+2*y[i]+y[i+1]);
		y1[2]=(1.0/5.0)*(y[i-2]+y[i-1]+y[i]+y[i+1]+y[i+2]);
		y1[3]=(1.0/10.0)*(y[i-1]+2*y[i]+3*y[i+1]+4*y[i+2]);
		y1[4]=(1.0/5.0)*(-y[i-2]+y[i]+2*y[i+1]+3*y[i+2]);
		for(j=0;j<(2*m+1);j++)
		{
			y[i-m+j]=y1[j];
		}
	}
	fprintf(fp,"\n");
	for(N=1;N<=N1;N++)
	{
		fprintf(fp,"%d\t%f\n",N,y[N-1]+0.0003);// 0.0003 for better presentation
	}
	//
	for(i=m;i<N1-m;i++)
	{
		y1[0]=(1.0/70.0)*(69*y[i-2]+4*y[i-1]-6*y[i]+4*y[i+1]-y[i+2]);
		y1[1]=(1.0/35.0)*(2*y[i-2]+27*y[i-1]+12*y[i]-8*y[i+1]+2*y[i+2]);
		y1[2]=(1.0/35.0)*(-3*y[i-2]+12*y[i-1]+17*y[i]+12*y[i+1]-3*y[i+2]);
		y1[3]=(1.0/35.0)*(2*y[i-2]-8*y[i-1]+12*y[i]+27*y[i+1]+2*y[i+2]);
		y1[4]=(1.0/70.0)*(-y[i-2]+4*y[i-1]-6*y[i]+4*y[i+1]+69*y[i+2]);
		for(j=0;j<(2*m+1);j++)
		{
			y[i-m+j]=y1[j];
		}
	}
	fprintf(fp,"\n");
	for(N=1;N<=N1;N++)
	{
		fprintf(fp,"%d\t%f\n",N,y[N-1]+0.0006);//0.0006 for plotting
	}
	fclose(fp);
}
void Circuit::createWire(string a, int b)
{
	Wire w(a, b, INPUT);
	while (wires.size < b) {
		Wire w1("", wires.size, INTERNAL);
		wires.push_back(&w1);
	}
	wires.push_back(&w);
}
Beispiel #26
0
  shared_ptr<OsmMap> createTestMap()
  {
    shared_ptr<OsmMap> map(new OsmMap());
    _map = map;

    shared_ptr<Node> n1 = createNode(0.0, 0.0);
    n1->setTag("building", "yes");
    n1->setTag("name", "n1");

    shared_ptr<Way> w1(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w1->setTag("area", "yes");
    w1->setTag("building", "yes");
    w1->setTag("name", "w1");
    w1->addNode(createNode(0.1, 0.0)->getId());
    w1->addNode(createNode(0.2, 0.0)->getId());
    w1->addNode(createNode(0.2, 0.1)->getId());
    w1->addNode(w1->getNodeId(0));
    map->addWay(w1);

    shared_ptr<Way> w2(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w2->setTag("highway", "track");
    w2->setTag("name", "w2");
    w2->addNode(createNode(0.3, 0.0)->getId());
    w2->addNode(createNode(0.3, 0.1)->getId());
    map->addWay(w2);

    shared_ptr<Way> w3(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w3->setTag("highway", "road");
    w3->setTag("name", "w3");
    w3->addNode(createNode(0.4, 0.0)->getId());
    w3->addNode(createNode(0.4, 0.1)->getId());
    map->addWay(w3);

    shared_ptr<Way> w4(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w4->addNode(createNode(0.5, 0.0)->getId());
    w4->addNode(createNode(0.7, 0.0)->getId());
    w4->addNode(createNode(0.6, 0.1)->getId());
    w4->addNode(w4->getNodeId(0));
    map->addWay(w4);

    shared_ptr<Way> w5(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w5->addNode(createNode(0.55, 0.01)->getId());
    w5->addNode(createNode(0.65, 0.01)->getId());
    w5->addNode(createNode(0.6, 0.05)->getId());
    w5->addNode(w5->getNodeId(0));
    map->addWay(w5);

    shared_ptr<Relation> r1(new Relation(Status::Unknown1, 1, 15.0, "multipolygon"));
    r1->setTag("building", "yes");
    r1->setTag("name", "r1");
    r1->addElement("outer", w4->getElementId());
    r1->addElement("inner", w5->getElementId());
    map->addRelation(r1);

    return map;
  }
Beispiel #27
0
/*
  Draws from the distribution

              p( b(idx), ... b(n-1) | b(0), ... b(idx-1), Y ).

  See Waggoner and Zha (JEDC, 2003) for notation and details.

  For idx <= j < n, parameters(begin_b[j]:begin_b[j]+dim_b[j]-1) is set to b(j) 
  and A0(j,:) is set to U[j]*b(j).
  
  Notes:
   Only the value of A0 is used.  Both A0 and parameters are modified.  If 
   idx = 0, the default value, then the draw is from the distribution p(b|Y).
*/
void SBVAR_symmetric_linear::SimulateA0(int idx)
{
  if ((idx < 0) || (idx >= n_vars))
    throw dw_exception("SimulateA0():  index out of range");

  int m;
  TDenseVector w1, b, g;
  double c0, c1, scale;

  if (!simulation_info_set) SetSimulationInfo();

  for (int k=idx; k < n_vars; k++)
    {
      // w is a non-zero vector that is perpendicular to all columns of A0 except the kth
      // w1 = T'(k)*U'(k)*w / ||T'(k)*U'(k)*w||
      w1=GetNullVector(A0,k)*Simulate_USqrtS[k];
      w1=(1.0/w1.Norm())*w1;

      // Draw univariate Wishard component
      b=dw_univariate_wishard_rnd(lambda_T,0.0)*w1;

      // Find largest element of w1
      scale=fabs(w1(m=0));
      for (int i=dim_b[k]-1; i > 0; i--)
	if (fabs(w1.vector[i]) > scale) scale=fabs(w1.vector[m=i]);
      c0=scale*scale;

      // Draw Gaussian component
      b.UniqueMemory();
      for (int j=0; j < m; j++)
	{
	  c1=c0+w1.vector[j]*w1.vector[j];
	  scale=dw_gaussian_rnd()/sqrt(lambda_T*c0*c1);
	  b.vector[j]-=scale*c0;
	  scale*=w1.vector[j];
	  for (int i=0; i < j; i++) b.vector[i]+=scale*w1.vector[i];
	  b.vector[m]+=scale*w1.vector[m];
	  c0=c1;
	}
      for (int j=m+1; j < dim_b[k]; j++)
	{
	  c1=c0+w1.vector[j]*w1.vector[j];
	  scale=dw_gaussian_rnd()/sqrt(lambda_T*c0*c1);
	  b.vector[j]-=scale*c0;
	  scale*=w1.vector[j];
	  for (int i=0; i < j; i++) b.vector[i]+=scale*w1.vector[i];
	  c0=c1;
	}

      // A(k,:) = U[k]*T(k)*b
      A0.InsertRowMatrix(k,0,Simulate_USqrtS[k]*b);

      /// Insert into parameters
      parameters.Insert(begin_b[k],Simulate_SqrtS[k]*b);
    }
}
Beispiel #28
0
/*
  reference counting having cyclic dependencies (widget implementation)
//*/
void testRCIPtr()
{
    RCWidget w1(10);
    RCWidget w2(w1);

    w2.doThis();

    std::cout << w1.showThat() << '\n';       // prints 10
    std::cout << w2.showThat() << '\n';       // prints -1
}
Beispiel #29
0
void test1() {
    worker<int> w1(boost::bind<int>(&calculatefib, 7));
    worker<int> w2(boost::bind<int>(&calculatefib, 8));
    
    worker<int> w3(boost::bind<int>(&fib_job::calc, boost::shared_ptr<fib_job>(new fib_job(11))));
    
    int sum = w1.get() + w2.get() + w3.get();
    
    std::cout << "Done, sum=" << sum << std::endl;
}
int main()
{
  {
    Widget w1(10, true);  // uses parens, still calls first ctor

    Widget w2{10, true};  // uses braces, now calls first ctor

    Widget w3(10, 5.0);   // uses parens, still calls second ctor

    Widget w4{10, 5.0};   // uses braces, now calls second ctor
  }
}