示例#1
0
文件: util.cpp 项目: akumar14/ccnn
void defineUtil() {
	// NOTE: This file has a ton of macros and templates, so it's going to take a while to compile ...
	init_numpy();
	boost::python::numeric::array::set_module_and_type("numpy", "ndarray");
	
	register_exception_translator<AssertException>(&translateAssertException);
	
	ADD_MODULE(util);
	
	// NOTE: When overloading functions always make sure to put the array/matrix function before the vector one
	MAT_CONV( MatrixX );
	MAT_CONV( RMatrixX );
	MAT_CONV( VectorX );
	MAT_CONV( ArrayXX );
	MAT_CONV( RArrayXX );
	MAT_CONV( ArrayX );
	
	// Define some std::vectors
	MAT_VEC( RMatrixX );
	MAT_VEC( VectorX );
	
	// Datastructures
	class_< std::vector<int> >("VecInt").def( vector_indexing_suite< std::vector<int> >() ).def( VectorInitSuite< std::vector<int> >() );
	class_< std::vector<float> >("VecFloat").def( vector_indexing_suite< std::vector<float> >() ).def( VectorInitSuite< std::vector<float> >() );
}
示例#2
0
void defineUtil() {
    // NOTE: This file has a ton of macros and templates, so it's going to take a while to compile ...
    init_numpy();
    boost::python::numeric::array::set_module_and_type("numpy", "ndarray");

    register_exception_translator<AssertException>(&translateAssertException);

    ADD_MODULE(util);
    class_<Edge>("Edge")
    .def(init<int,int>())
    .def_readonly( "a", &Edge::a )
    .def_readonly( "b", &Edge::b )
    .def_pickle(Edge_pickle());

    class_< Edges >("Edges")
    .def(init<Edges>())
    .def(vector_indexing_suite<Edges>());

    def("qp",static_cast<VectorXf(*)(const RMatrixXf &, const VectorXf &, const RMatrixXf &, const VectorXf &)>(&qp));
    def("qp",static_cast<VectorXd(*)(const RMatrixXd &, const VectorXd &, const RMatrixXd &, const VectorXd &)>(&qp));

    // NOTE: When overloading functions always make sure to put the array/matrix function before the vector one
    MAT_CONV( MatrixX );
    MAT_CONV( RMatrixX );
    MAT_CONV( VectorX );
    MAT_CONV( ArrayXX );
    MAT_CONV( RArrayXX );
    MAT_CONV( ArrayX );

    // Defien some std::vectors
    MAT_VEC( RMatrixX );
    MAT_VEC( VectorX );

    class_< std::vector< std::vector<RMatrixXb> > >("VecVecRMatrixXb")
    .def( vector_indexing_suite< std::vector< std::vector<RMatrixXb> >, true >() )
    .def( VectorInitSuite< std::vector< std::vector<RMatrixXb> > >() );

    // Datastructures
    class_< std::vector<int> >("VecInt").def( vector_indexing_suite< std::vector<int> >() ).def( VectorInitSuite< std::vector<int> >() );
    class_< std::vector<float> >("VecFloat").def( vector_indexing_suite< std::vector<float> >() ).def( VectorInitSuite< std::vector<float> >() );
    class_< std::vector<std::string> >("VecStr").def( vector_indexing_suite< std::vector<std::string> >() ).def( VectorInitSuite< std::vector<std::string> >() );

//	class_<Polygons>("Polygons").def( vector_indexing_suite<Polygons,true >() );
    class_< std::vector<Polygons> >("VecPolygons").def( vector_indexing_suite< std::vector<Polygons> >() )
    .def_pickle(VecPolygons_pickle_suite());

    // Rasterize
    def("rasterize",static_cast<RMatrixXf(*)(const Polygon &,int)>(&rasterize),rasterize1());
    def("rasterize",static_cast<RMatrixXf(*)(const Polygons &,int)>(&rasterize),rasterize2());

    // Facility location
    class_<Floc>("Floc")
    .def("energy",Floc::energy)
    .staticmethod("energy")
    .def("greedy",Floc::greedy)
    .staticmethod("greedy")
    .def("jms",Floc::jms)
    .staticmethod("jms")
    .def("myz",Floc::myz)
    .staticmethod("myz")
    .def("local",Floc::local)
    .staticmethod("local")
    .def("scaledLocal",Floc::scaledLocal)
    .staticmethod("scaledLocal")
    .def("tabu",Floc::tabu)
    .staticmethod("tabu");

    // Geodesic distance
    class_<GeodesicDistance>("GeodesicDistance",init<Edges,VectorXf>())
    .def("compute",static_cast<VectorXf (GeodesicDistance::*)(int)const>( &GeodesicDistance::compute ))
    .def("compute",static_cast<VectorXf (GeodesicDistance::*)(const VectorXf &)const>( &GeodesicDistance::compute ))
    .add_property("N",&GeodesicDistance::N);
}