Exemple #1
0
int fb(int n)
{
	if (n == 1 || n == 2) {
		return 1;
	}

	return fb(n - 1) + fb(n - 2);
}
Exemple #2
0
// MultipleCopyNodes
//------------------------------------------------------------------------------
void TestCopy::MultipleCopyNodes() const
{
	const AStackString<> srcFile( "Data/TestGraph/library.cpp" );
	const AStackString<> dstFileA( "../../../../tmp/Test/Graph/library.multiplecopynodes1.cpp" );
	const AStackString<> dstFileB( "../../../../tmp/Test/Graph/library.multiplecopynodes2.cpp" );
	const AStackString<> dstFileC( "../../../../tmp/Test/Graph/library.multiplecopynodes3.cpp" );

	// check files are as expected before starting test
	EnsureFileDoesNotExist( dstFileA );
	EnsureFileDoesNotExist( dstFileB );
	EnsureFileDoesNotExist( dstFileC );
	EnsureFileExists( srcFile );

	FBuildOptions options;
	options.m_ShowSummary = true; // required to generate stats for node count checks

	// build
	{
		FBuild fb( options );
		NodeGraph & ng = fb.GetDependencyGraph();

		// make a fileNode for the source
		FileNode * srcNode = ng.CreateFileNode( srcFile );

		Dependencies empty;
		Node * copyA = ng.CreateCopyNode( dstFileA, srcNode, empty );
		Node * copyB = ng.CreateCopyNode( dstFileB, (FileNode *)copyA, empty );
		Node * copyC = ng.CreateCopyNode( dstFileC, (FileNode *)copyB, empty );

		TEST_ASSERT( fb.Build( copyC ) );
		TEST_ASSERT( fb.SaveDependencyGraph( "../../../../tmp/Test/Graph/multiplecopynode.fdb" ) );

		EnsureFileExists( dstFileA );
		EnsureFileExists( dstFileB );
		EnsureFileExists( dstFileC );

		// Check stats
		//				 Seen,	Built,	Type
		CheckStatsNode ( 1,		1,		Node::FILE_NODE );
		CheckStatsNode ( 3,		3,		Node::COPY_NODE );
		CheckStatsTotal( 4,		4 );
	}

	// check no rebuild
	{
		FBuild fb( options );
		fb.Initialize( "../../../../tmp/Test/Graph/multiplecopynode.fdb" );

		TEST_ASSERT( fb.Build( dstFileC ) );

		// Check stats
		//				 Seen,	Built,	Type
		CheckStatsNode ( 1,		1,		Node::FILE_NODE );
		CheckStatsNode ( 3,		0,		Node::COPY_NODE );
		CheckStatsTotal( 4,		1 );
	}
}
static bool
preprocess (const std::string &filename,
            const std::string &stdinclude,
            const std::string &options,
            std::string &result)
{
#ifdef _MSC_VER
#define popen _popen
#define pclose _pclose
#endif

    std::string cppcommand = "/usr/bin/cpp";
#ifdef __APPLE__
    // Default /usr/bin/cpp on pre-Lion Apple is very bare bones,
    // doesn't seem to support all the preprocessor directives (like #
    // and ##), but the explicit gcc 4.2 one does.
    if (OIIO::Filesystem::exists ("/usr/bin/cpp-4.2"))
        cppcommand = "/usr/bin/cpp-4.2";
#endif

    cppcommand += std::string (" -xc -nostdinc ");
    cppcommand += options;

    if (! stdinclude.empty())
        cppcommand += std::string("-include \"") + stdinclude + "\" ";

    cppcommand += "\"";
    cppcommand += filename;
    cppcommand += "\" ";

    // std::cout << "cpp command:\n>" << cppcommand << "<\n";
    FILE *cpppipe = popen (cppcommand.c_str(), "r");

#if defined(__GNUC__) && !defined(_LIBCPP_VERSION)
    __gnu_cxx::stdio_filebuf<char> fb (cpppipe, std::ios::in);
#else
    std::filebuf fb (cpppipe);
#endif

    if (! cpppipe || ! fb.is_open()) {
        // File didn't open
        std::cerr << "Could not run '" << cppcommand.c_str() << "'\n";
        return false;
    } else {
        std::istream in (&fb);

        std::ostringstream ss;
        ss << in.rdbuf();
        result = ss.str();

        fb.close ();
    }

    // Test for error in exit status
    return (pclose(cpppipe) == 0);
}
Exemple #4
0
REGISTER_TESTS_END

// SingleCopyNode
//------------------------------------------------------------------------------
void TestCopy::SingleCopyNode() const
{
	const AStackString<> testFileName( "Data/TestGraph/library.cpp" );
	const AStackString<> testFileNameCopy( "../../../../tmp/Test/Graph/library.copynode.cpp" );

	// check files are in expected states
	EnsureFileExists( testFileName );
	EnsureFileDoesNotExist( testFileNameCopy );

	FBuildOptions options;
	options.m_ShowSummary = true; // required to generate stats for node count checks

	// Build
	{
		FBuild fb( options );
		NodeGraph & ng = fb.GetDependencyGraph();

		// make a fileNode for the source
		FileNode * srcNode = ng.CreateFileNode( testFileName );

		// and an ObjectNode for the output
		Dependencies empty;
		Node * dstNode = ng.CreateCopyNode( testFileNameCopy, srcNode, empty );

		TEST_ASSERT( fb.Build( dstNode ) );
		TEST_ASSERT( fb.SaveDependencyGraph( "../../../../tmp/Test/Graph/singlecopynode.fdb" ) );

		EnsureFileExists( testFileNameCopy );

		// Check stats
		//				 Seen,	Built,	Type
		CheckStatsNode ( 1,		1,		Node::FILE_NODE );
		CheckStatsNode ( 1,		1,		Node::COPY_NODE );
		CheckStatsTotal( 2,		2 );
	}

	// check no rebuild
	{
		FBuild fb( options );
		fb.Initialize( "../../../../tmp/Test/Graph/singlecopynode.fdb" );

		TEST_ASSERT( fb.Build( testFileNameCopy ) );

		// Check stats
		//				 Seen,	Built,	Type
		CheckStatsNode ( 1,		1,		Node::FILE_NODE );
		CheckStatsNode ( 1,		0,		Node::COPY_NODE );
		CheckStatsTotal( 2,		1 );
	}
}
Exemple #5
0
int main()
{
	
	int fb(int j){
		int fb1 = 1, fb2 = 2;

		if (j <= 1)
		{
			return j;
		}

		return fb(j-1) + fb(j-2);
	}
static bool
preprocess (const std::string &filename,
            const std::string &stdinclude,
            const std::string &options,
            std::string &result)
{
#ifdef _MSC_VER
#define popen _popen
#define pclose _pclose
#endif

    std::string cppcommand = "/usr/bin/cpp -xc -nostdinc ";

    cppcommand += options;

    if (! stdinclude.empty())
        cppcommand += std::string("-include ") + stdinclude + " ";

    cppcommand += "\"";
    cppcommand += filename;
    cppcommand += "\" ";

    // std::cout << "cpp command:\n>" << cppcommand << "<\n";
    FILE *cpppipe = popen (cppcommand.c_str(), "r");

#ifdef __GNUC__
    __gnu_cxx::stdio_filebuf<char> fb (cpppipe, std::ios::in);
#else
    std::filebuf fb (cpppipe);
#endif

    if (! cpppipe || ! fb.is_open()) {
        // File didn't open
        std::cerr << "Could not run '" << cppcommand.c_str() << "'\n";
        return false;
    } else {
        std::istream in (&fb);

        std::ostringstream ss;
        ss << in.rdbuf();
        result = ss.str();

        fb.close ();
    }

    if (cpppipe)
        pclose (cpppipe);

    return true;
}
int IKConstraint::copy_jacobian()
{
	if(i_const < 0) return -1;
	int n_dof = ik->NumDOF();
	int i, j, m;
	is_dropped = false;
	for(m=0; m<IK::N_PRIORITY_TYPES; m++)
	{
		if(priority == (IK::Priority)m && enabled)
		{
			fMat& targetJ = ik->J[m];
			int target_row = targetJ.row();
			int row = J.row();
			double *a, *b;
			for(i=0; i<n_const; i++)
			{
				ik->fb[m](i_const+i) = fb(i);
				if(weight.size() == n_const)
					ik->weight[m](i_const+i) = weight(i);
				else
					ik->weight[m](i_const+i) = 1.0;
				a = targetJ.data() + i_const + i;
				b = J.data() + i;
				for(j=0; j<n_dof; a+=target_row, b+=row, j++)
				{
//					targetJ(i_const+i, j) = J(i, j);
					*a = *b;
				}
			}
			break;
		}
	}
	return 0;
}
void fizzBuzzSingle1() {
	std::ostringstream out;
	{
	FizzBuzz<1> fb(out);
	}
	ASSERT_EQUAL("1",out.str());
}
Exemple #9
0
StatusCode FileMgrTest::execute() {

  MsgStream log(msgSvc(), name());

  log << MSG::INFO << "writing to " << p_fileMgr->fname((void*)fp_2) << endmsg;

  std::ofstream ofs;
  __gnu_cxx::stdio_filebuf<char> fb(fp_2, std::ios::out);

  ofs.std::ios::rdbuf(&fb);
  ofs << "Hello World!" << std::endl;


  log << MSG::INFO << "appending to " << p_fileMgr->fname((void*)fp_3) << endmsg;

  std::ofstream ofs2;
  __gnu_cxx::stdio_filebuf<char> fb2(fp_3, std::ios::out);

  ofs2.std::ios::rdbuf(&fb2);
  ofs2 << "Hello World!" << std::endl;



  return StatusCode::SUCCESS;

}
Exemple #10
0
void can_project_micropolygon() {
    MeshPoint mp1(-10, -10, 100);
    MeshPoint mp2(10, -10, 100);
    MeshPoint mp3(-10, 10, 100);
    MeshPoint mp4(10, 10, 100);
    MicroPolygon poly;
    poly.a = mp1;
    poly.b = mp2;
    poly.c = mp3;
    poly.d = mp4;

    FrameBuffer fb(500, 500);
    fb.projectMicroPolygon(poly);

    ASSERT_EQUAL_FLOAT(poly.a.getX(), 206.699, 0.1);
    ASSERT_EQUAL_FLOAT(poly.a.getY(), 206.699, 0.1);

    ASSERT_EQUAL_FLOAT(poly.b.getX(), 293.301, 0.1);
    ASSERT_EQUAL_FLOAT(poly.b.getY(), 206.699, 0.1);

    ASSERT_EQUAL_FLOAT(poly.c.getX(), 206.699, 0.1);
    ASSERT_EQUAL_FLOAT(poly.c.getY(), 293.301, 0.1);

    ASSERT_EQUAL_FLOAT(poly.d.getX(), 293.301, 0.1);
    ASSERT_EQUAL_FLOAT(poly.d.getY(), 293.301, 0.1);
}
Exemple #11
0
void can_project_and_scale_points() {
    FrameBuffer fb(500, 500);
    Vect v = Vect(0, 0, 100);
    fb.projectAndScalePoint(v);
    ASSERT_EQUAL_FLOAT(v.getX(), 250, 0.1);
    ASSERT_EQUAL_FLOAT(v.getY(), 250, 0.1);
}
Exemple #12
0
void draw_simple_spheres() {
    FrameBuffer fb(500, 500, 2, 2);

    RiSphere s(10, 16);
    s.translate(-10, -10, 50);
    fb.addMesh(s);

    RiSphere s1(10, 16);
    s1.rotate('x', 90);
    s1.translate(10, -10, 50);
    fb.addMesh(s1);

    RiSphere s2(10, 16);
    s2.rotate('x', 180);
    s2.translate(-10, 10, 50);
    fb.addMesh(s2);

    RiSphere s3(10, 16);
    s3.rotate('x', 270);
    s3.translate(10, 10, 50);
    fb.addMesh(s3);

    fb.drawShapes("./imgs/fb_test_simple.jpg");
    ASSERT_EQUAL_INT(0, 0);
}
void FizzBuzzSingleBuzz(){
	std::ostringstream out;
	{
	FizzBuzz<5> fb(out);
	}
	ASSERT_EQUAL("Buzz",out.str());
}
void FizzBuzzSequenceToBuzz(){
	std::ostringstream out;
	{
	FizzBuzz<1,2,3,4,5> fb(out);
	}
	ASSERT_EQUAL("12Fizz4Buzz",out.str());
}
Exemple #15
0
Fichier : a.cpp Projet : filaPro/my
void multiply_vec(const std::vector<int> &aarr, const std::vector<int> &barr, 
    std::vector<int> &res) {
    std::vector<base> fa(aarr.begin(), aarr.end()),  fb(barr.begin(), barr.end());
    size_t cnt = 1;
    while (cnt < std::max(aarr.size(), barr.size())) {
        cnt <<= 1;
    }
    cnt <<= 1;
    fa.resize(cnt);
    fb.resize(cnt);

    fft(fa, false);
    fft(fb, false);
    for (size_t i = 0; i < cnt; ++i) {
        fa[i] *= fb[i];
    }
    fft(fa, true);

    res.resize(cnt);
    for (size_t i = 0; i < cnt; ++i) {
        res[i] = int (fa[i].re + 0.5);
    }
    // delete [] fa;
    // delete [] fb;
}
Exemple #16
0
	void Core::FullScreenFrame(ax::Window::Ptr frame)
	{
		_instance->BringToFront(frame);
		std::shared_ptr<eos::Frame> fb(std::static_pointer_cast<eos::Frame>(frame->backbone));
		fb->SetFullScreen(
			ax::Rect(ax::Point(0, 0), _desktop->GetWindow()->dimension.GetSize() - ax::Size(0, 0)));
	}
Exemple #17
0
    vector<int64_t> multiply(const vector<int64_t>& a, const vector<int64_t>& b) {
        int n1 = a.size(), n2 = b.size();
        int m = 1;
        while (m < n1 || m < n2) m <<= 1;
        m <<= 1;

        vector<Complex> fa(m, 0), fb(m, 0);
        for (int i = 0; i < n1; ++i) {
            fa[i] = a[i];
        }
        for (int i = 0; i < n2; ++i) {
            fb[i] = b[i];
        }
        fft(fa, false);
        fft(fb, false);
        for (int i = 0; i < m; ++i) {
            fa[i] *= fb[i];
        }
        fft(fa, true);
        vector<int64_t> res(m);
        for (int i = 0; i < m; ++i) {
            res[i] = (int64_t) (fa[i].real + 0.5);
        }
        return res;
    }
Exemple #18
0
TEST(box_test_fbtest, construct)
{
    std::weak_ptr<petro::box::box> parent;
    auto type = "fbtest";
    petro::box::full_box fb(type, parent);
    EXPECT_EQ(type, fb.type());
}
void BigIntegerStrassen::Multiply(const BigIntegerStrassen &right_number){
    vcomp fa(number.begin(), number.end());
    auto right_arr = right_number.ToArray();
    vcomp fb(right_arr.begin(), right_arr.end());

    ll n = 1;
    while (n < std::max(number.size(), right_arr.size())) n <<= 1;
    n <<= 1;

    fa.resize(n);
    fb.resize(n);

    FastFourierTransform(fa, false);
    FastFourierTransform(fb, false);

    for (ll i = 0; i < n; i++) fa[i] *= fb[i];
    FastFourierTransform(fa, true);
    
    number.resize(n);
    ll carry = 0;
    for (ll i = 0; i < n; i++){
        carry += ll(fa[i].real() + 0.5);
        number[i] = carry % base;
        carry /= base;
    }

    while (number.size() && number.back() == 0) number.pop_back();

}
Exemple #20
0
QEglFSKmsGbmScreen::FrameBuffer *QEglFSKmsGbmScreen::framebufferForBufferObject(gbm_bo *bo)
{
    {
        FrameBuffer *fb = static_cast<FrameBuffer *>(gbm_bo_get_user_data(bo));
        if (fb)
            return fb;
    }

    uint32_t width = gbm_bo_get_width(bo);
    uint32_t height = gbm_bo_get_height(bo);
    uint32_t stride = gbm_bo_get_stride(bo);
    uint32_t handle = gbm_bo_get_handle(bo).u32;

    QScopedPointer<FrameBuffer> fb(new FrameBuffer);

    int ret = drmModeAddFB(device()->fd(), width, height, 24, 32,
                           stride, handle, &fb->fb);

    if (ret) {
        qWarning("Failed to create KMS FB!");
        return Q_NULLPTR;
    }

    gbm_bo_set_user_data(bo, fb.data(), bufferDestroyedHandler);
    return fb.take();
}
Exemple #21
0
int main(int argc, char **argv) {
    int a;
    switch (a) {
        case 0:
            return 0;
        default:
            return 1;
    }
    for (int i = 0; i < 10; i++) {
        a = i;
    }
    while (!a) {
        a++;
    }
    do {
        --a;
    } while (a);
    if (fa(a)) {
        a = 1;
    } else if (fb(b)) {
        a = 2;
    } else {
        a = 3;
    }

}
Exemple #22
0
int main()
{
	try
	{
		boost::barrier tb( 2);
		boost::fibers::spin::barrier fb( 2);

		std::cout << "start" << std::endl;

		boost::thread th1( boost::bind( & f, boost::ref( tb), boost::ref( fb) ) );
		boost::thread th2( boost::bind( & g, boost::ref( tb), boost::ref( fb) ) );

		th1.join();
		th2.join();

		std::cout << "finish" << std::endl;

		return EXIT_SUCCESS;
	}
	catch ( boost::system::system_error const& e)
	{ std::cerr << "system_error: " << e.code().value() << std::endl; }
	catch ( boost::fibers::scheduler_error const& e)
	{ std::cerr << "scheduler_error: " << e.what() << std::endl; }
	catch ( std::exception const& e)
	{ std::cerr << "exception: " << e.what() << std::endl; }
	catch (...)
	{ std::cerr << "unhandled exception" << std::endl; }
	return EXIT_FAILURE;
}
Exemple #23
0
int IKHandle::calc_feedback()
{
	// compute feedback velocity
	if(n_const > 0)
	{
		static fVec3 fb_pos, fb_att;
		static fVec3 cur_pos;
		static fMat33 cur_att;
		// absolute position / orientation
		cur_att.mul(joint->abs_att, rel_att);
		cur_pos.mul(joint->abs_att, rel_pos);
		cur_pos += joint->abs_pos;
		// relative position / orientation wrt other_joint
		if(other_joint)
		{
			static fVec3 pp;
			static fMat33 rt, catt;
			rt.tran(other_joint->abs_att);
			catt.set(cur_att);
			pp.sub(cur_pos, other_joint->abs_pos);
			cur_pos.mul(rt, pp);
			cur_att.mul(rt, catt);
		}
		fb_pos.sub(abs_pos, cur_pos);
		fb_pos *= gain;
		fb_att.rotation(abs_att, cur_att);
		fb_att *= gain;
		int i, count = 0;
		for(i=0; i<3; i++)
		{
			if(const_index[i] == IK::HAVE_CONSTRAINT)
			{
				fb(count) = fb_pos(i);
				count++;
			}
		}
		for(i=0; i<3; i++)
		{
			if(const_index[i+3] == IK::HAVE_CONSTRAINT)
			{
				fb(count) = fb_att(i);
				count++;
			}
		}
	}
	return 0;
}
 void main()
 {
   int n=1;
   printf("在主程中,调用函数fa之前:n=%d\n",n);
   fa(n);
   printf("在主程中,调用函数fa之后,调用函数fb之前:n=%d\n",n);
   fb(&n); /* 实参为n的地址 */
   printf("在主程中,调用函数fb之后:n=%d\n",n);
 }
Exemple #25
0
    double computeVolume( const QUAD& quadrature )
    {
        double volume = 0.;
        FieldBinder fb( mesh_, field_ );
        base::asmb::simplyIntegrate<UU>( quadrature, volume, fb, 
                                         base::kernel::Measure<typename UU::Tuple>() );

        return volume;
    }
Exemple #26
0
void plot_image() {
    FrameBuffer fb(500, 500);

    RiSphere s(20, 128);
    fb.addMesh(s);

    fb.plotPoints("fb_test_plot.jpg");
    ASSERT_EQUAL_INT(4, 4);
}
Exemple #27
0
 void f_main()
 {
   int n=1;
   printf("在主程中,调用函数fa之前:n=%d\n",n);
   fa(n);
   printf("在主程中,调用函数fa之后,调用函数fb之前:n=%d\n",n);
   fb(n);
   printf("在主程中,调用函数fb之后:n=%d\n",n);
 }
Exemple #28
0
frame_buffer_t
FrameBuffer::Create(uint32_t width,
                    uint32_t height,
                    uint32_t bpp,
                    uint32_t stride)
{
    frame_buffer_t fb(new FrameBuffer(width, height, bpp, stride));
    return fb;
}
Exemple #29
0
void draw_simple_sphere() {
    FrameBuffer fb(500, 500, 2, 2);

    RiSphere s(10, 4);
    s.translate(0, 0, 50);
    fb.addMesh(s);

    fb.drawShapes("./imgs/fb_test_simple.jpg");
    ASSERT_EQUAL_INT(0, 0);
}
Exemple #30
0
FlatBoundingBox
FlatProjection::Project(const GeoBounds &bb) const
{
    assert(IsValid());

    FlatBoundingBox fb(ProjectInteger(bb.GetSouthWest()),
                       ProjectInteger(bb.GetNorthEast()));
    fb.ExpandByOne(); // prevent rounding
    return fb;
}