Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __CPLUSPLUS__
- extern "C" {
- #endif
- #ifndef __GNUC__
- #pragma warning(disable: 4275)
- #pragma warning(disable: 4101)
- #endif
- #include "Python.h"
- #include "compile.h"
- #include "frameobject.h"
- #include <complex>
- #include <math.h>
- #include <string>
- #include "scxx/object.h"
- #include "scxx/list.h"
- #include "scxx/tuple.h"
- #include "scxx/dict.h"
- #include <iostream>
- #include <stdio.h>
- #include "numpy/arrayobject.h"
- // global None value for use in functions.
- namespace py {
- object None = object(Py_None);
- }
- const char* find_type(PyObject* py_obj)
- {
- if(py_obj == NULL) return "C NULL value";
- if(PyCallable_Check(py_obj)) return "callable";
- if(PyString_Check(py_obj)) return "string";
- if(PyInt_Check(py_obj)) return "int";
- if(PyFloat_Check(py_obj)) return "float";
- if(PyDict_Check(py_obj)) return "dict";
- if(PyList_Check(py_obj)) return "list";
- if(PyTuple_Check(py_obj)) return "tuple";
- if(PyFile_Check(py_obj)) return "file";
- if(PyModule_Check(py_obj)) return "module";
- //should probably do more intergation (and thinking) on these.
- if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return "callable";
- if(PyInstance_Check(py_obj)) return "instance";
- if(PyCallable_Check(py_obj)) return "callable";
- return "unkown type";
- }
- void throw_error(PyObject* exc, const char* msg)
- {
- //printf("setting python error: %s\n",msg);
- PyErr_SetString(exc, msg);
- //printf("throwing error\n");
- throw 1;
- }
- void handle_bad_type(PyObject* py_obj, const char* good_type, const char* var_name)
- {
- char msg[500];
- sprintf(msg,"received '%s' type instead of '%s' for variable '%s'",
- find_type(py_obj),good_type,var_name);
- throw_error(PyExc_TypeError,msg);
- }
- void handle_conversion_error(PyObject* py_obj, const char* good_type, const char* var_name)
- {
- char msg[500];
- sprintf(msg,"Conversion Error:, received '%s' type instead of '%s' for variable '%s'",
- find_type(py_obj),good_type,var_name);
- throw_error(PyExc_TypeError,msg);
- }
- class int_handler
- {
- public:
- int convert_to_int(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyInt_Check(py_obj))
- handle_conversion_error(py_obj,"int", name);
- return (int) PyInt_AsLong(py_obj);
- }
- int py_to_int(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyInt_Check(py_obj))
- handle_bad_type(py_obj,"int", name);
- return (int) PyInt_AsLong(py_obj);
- }
- };
- int_handler x__int_handler = int_handler();
- #define convert_to_int(py_obj,name) \
- x__int_handler.convert_to_int(py_obj,name)
- #define py_to_int(py_obj,name) \
- x__int_handler.py_to_int(py_obj,name)
- PyObject* int_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class float_handler
- {
- public:
- double convert_to_float(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyFloat_Check(py_obj))
- handle_conversion_error(py_obj,"float", name);
- return PyFloat_AsDouble(py_obj);
- }
- double py_to_float(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyFloat_Check(py_obj))
- handle_bad_type(py_obj,"float", name);
- return PyFloat_AsDouble(py_obj);
- }
- };
- float_handler x__float_handler = float_handler();
- #define convert_to_float(py_obj,name) \
- x__float_handler.convert_to_float(py_obj,name)
- #define py_to_float(py_obj,name) \
- x__float_handler.py_to_float(py_obj,name)
- PyObject* float_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class complex_handler
- {
- public:
- std::complex<double> convert_to_complex(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyComplex_Check(py_obj))
- handle_conversion_error(py_obj,"complex", name);
- return std::complex<double>(PyComplex_RealAsDouble(py_obj),PyComplex_ImagAsDouble(py_obj));
- }
- std::complex<double> py_to_complex(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyComplex_Check(py_obj))
- handle_bad_type(py_obj,"complex", name);
- return std::complex<double>(PyComplex_RealAsDouble(py_obj),PyComplex_ImagAsDouble(py_obj));
- }
- };
- complex_handler x__complex_handler = complex_handler();
- #define convert_to_complex(py_obj,name) \
- x__complex_handler.convert_to_complex(py_obj,name)
- #define py_to_complex(py_obj,name) \
- x__complex_handler.py_to_complex(py_obj,name)
- PyObject* complex_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class unicode_handler
- {
- public:
- Py_UNICODE* convert_to_unicode(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- Py_XINCREF(py_obj);
- if (!py_obj || !PyUnicode_Check(py_obj))
- handle_conversion_error(py_obj,"unicode", name);
- return PyUnicode_AS_UNICODE(py_obj);
- }
- Py_UNICODE* py_to_unicode(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyUnicode_Check(py_obj))
- handle_bad_type(py_obj,"unicode", name);
- Py_XINCREF(py_obj);
- return PyUnicode_AS_UNICODE(py_obj);
- }
- };
- unicode_handler x__unicode_handler = unicode_handler();
- #define convert_to_unicode(py_obj,name) \
- x__unicode_handler.convert_to_unicode(py_obj,name)
- #define py_to_unicode(py_obj,name) \
- x__unicode_handler.py_to_unicode(py_obj,name)
- PyObject* unicode_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class string_handler
- {
- public:
- std::string convert_to_string(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- Py_XINCREF(py_obj);
- if (!py_obj || !PyString_Check(py_obj))
- handle_conversion_error(py_obj,"string", name);
- return std::string(PyString_AsString(py_obj));
- }
- std::string py_to_string(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyString_Check(py_obj))
- handle_bad_type(py_obj,"string", name);
- Py_XINCREF(py_obj);
- return std::string(PyString_AsString(py_obj));
- }
- };
- string_handler x__string_handler = string_handler();
- #define convert_to_string(py_obj,name) \
- x__string_handler.convert_to_string(py_obj,name)
- #define py_to_string(py_obj,name) \
- x__string_handler.py_to_string(py_obj,name)
- PyObject* string_to_py(std::string s)
- {
- return PyString_FromString(s.c_str());
- }
- class list_handler
- {
- public:
- py::list convert_to_list(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyList_Check(py_obj))
- handle_conversion_error(py_obj,"list", name);
- return py::list(py_obj);
- }
- py::list py_to_list(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyList_Check(py_obj))
- handle_bad_type(py_obj,"list", name);
- return py::list(py_obj);
- }
- };
- list_handler x__list_handler = list_handler();
- #define convert_to_list(py_obj,name) \
- x__list_handler.convert_to_list(py_obj,name)
- #define py_to_list(py_obj,name) \
- x__list_handler.py_to_list(py_obj,name)
- PyObject* list_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class dict_handler
- {
- public:
- py::dict convert_to_dict(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyDict_Check(py_obj))
- handle_conversion_error(py_obj,"dict", name);
- return py::dict(py_obj);
- }
- py::dict py_to_dict(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyDict_Check(py_obj))
- handle_bad_type(py_obj,"dict", name);
- return py::dict(py_obj);
- }
- };
- dict_handler x__dict_handler = dict_handler();
- #define convert_to_dict(py_obj,name) \
- x__dict_handler.convert_to_dict(py_obj,name)
- #define py_to_dict(py_obj,name) \
- x__dict_handler.py_to_dict(py_obj,name)
- PyObject* dict_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class tuple_handler
- {
- public:
- py::tuple convert_to_tuple(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyTuple_Check(py_obj))
- handle_conversion_error(py_obj,"tuple", name);
- return py::tuple(py_obj);
- }
- py::tuple py_to_tuple(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyTuple_Check(py_obj))
- handle_bad_type(py_obj,"tuple", name);
- return py::tuple(py_obj);
- }
- };
- tuple_handler x__tuple_handler = tuple_handler();
- #define convert_to_tuple(py_obj,name) \
- x__tuple_handler.convert_to_tuple(py_obj,name)
- #define py_to_tuple(py_obj,name) \
- x__tuple_handler.py_to_tuple(py_obj,name)
- PyObject* tuple_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class file_handler
- {
- public:
- FILE* convert_to_file(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- Py_XINCREF(py_obj);
- if (!py_obj || !PyFile_Check(py_obj))
- handle_conversion_error(py_obj,"file", name);
- return PyFile_AsFile(py_obj);
- }
- FILE* py_to_file(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyFile_Check(py_obj))
- handle_bad_type(py_obj,"file", name);
- Py_XINCREF(py_obj);
- return PyFile_AsFile(py_obj);
- }
- };
- file_handler x__file_handler = file_handler();
- #define convert_to_file(py_obj,name) \
- x__file_handler.convert_to_file(py_obj,name)
- #define py_to_file(py_obj,name) \
- x__file_handler.py_to_file(py_obj,name)
- PyObject* file_to_py(FILE* file, const char* name,
- const char* mode)
- {
- return (PyObject*) PyFile_FromFile(file,
- const_cast<char*>(name),
- const_cast<char*>(mode), fclose);
- }
- class instance_handler
- {
- public:
- py::object convert_to_instance(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !PyInstance_Check(py_obj))
- handle_conversion_error(py_obj,"instance", name);
- return py::object(py_obj);
- }
- py::object py_to_instance(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyInstance_Check(py_obj))
- handle_bad_type(py_obj,"instance", name);
- return py::object(py_obj);
- }
- };
- instance_handler x__instance_handler = instance_handler();
- #define convert_to_instance(py_obj,name) \
- x__instance_handler.convert_to_instance(py_obj,name)
- #define py_to_instance(py_obj,name) \
- x__instance_handler.py_to_instance(py_obj,name)
- PyObject* instance_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class numpy_size_handler
- {
- public:
- void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims,
- const char* name)
- {
- if (arr_obj->nd != Ndims)
- {
- char msg[500];
- sprintf(msg,"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'",
- arr_obj->nd,Ndims,name);
- throw_error(PyExc_TypeError,msg);
- }
- }
- void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)
- {
- if (arr_obj->nd != Ndims)
- {
- char msg[500];
- sprintf(msg,"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'",
- arr_obj->nd,Ndims,name);
- throw_error(PyExc_TypeError,msg);
- }
- }
- };
- numpy_size_handler x__numpy_size_handler = numpy_size_handler();
- #define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size
- #define numpy_check_size x__numpy_size_handler.numpy_check_size
- class numpy_type_handler
- {
- public:
- void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,
- const char* name)
- {
- // Make sure input has correct numeric type.
- int arr_type = arr_obj->descr->type_num;
- if (PyTypeNum_ISEXTENDED(numeric_type))
- {
- char msg[80];
- sprintf(msg, "Conversion Error: extended types not supported for variable '%s'",
- name);
- throw_error(PyExc_TypeError, msg);
- }
- if (!PyArray_EquivTypenums(arr_type, numeric_type))
- {
- const char* type_names[23] = {"bool", "byte", "ubyte","short", "ushort",
- "int", "uint", "long", "ulong", "longlong", "ulonglong",
- "float", "double", "longdouble", "cfloat", "cdouble",
- "clongdouble", "object", "string", "unicode", "void", "ntype",
- "unknown"};
- char msg[500];
- sprintf(msg,"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'",
- type_names[arr_type],type_names[numeric_type],name);
- throw_error(PyExc_TypeError,msg);
- }
- }
- void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)
- {
- // Make sure input has correct numeric type.
- int arr_type = arr_obj->descr->type_num;
- if (PyTypeNum_ISEXTENDED(numeric_type))
- {
- char msg[80];
- sprintf(msg, "Conversion Error: extended types not supported for variable '%s'",
- name);
- throw_error(PyExc_TypeError, msg);
- }
- if (!PyArray_EquivTypenums(arr_type, numeric_type))
- {
- const char* type_names[23] = {"bool", "byte", "ubyte","short", "ushort",
- "int", "uint", "long", "ulong", "longlong", "ulonglong",
- "float", "double", "longdouble", "cfloat", "cdouble",
- "clongdouble", "object", "string", "unicode", "void", "ntype",
- "unknown"};
- char msg[500];
- sprintf(msg,"received '%s' typed array instead of '%s' typed array for variable '%s'",
- type_names[arr_type],type_names[numeric_type],name);
- throw_error(PyExc_TypeError,msg);
- }
- }
- };
- numpy_type_handler x__numpy_type_handler = numpy_type_handler();
- #define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type
- #define numpy_check_type x__numpy_type_handler.numpy_check_type
- class numpy_handler
- {
- public:
- PyArrayObject* convert_to_numpy(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- Py_XINCREF(py_obj);
- if (!py_obj || !PyArray_Check(py_obj))
- handle_conversion_error(py_obj,"numpy", name);
- return (PyArrayObject*) py_obj;
- }
- PyArrayObject* py_to_numpy(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !PyArray_Check(py_obj))
- handle_bad_type(py_obj,"numpy", name);
- Py_XINCREF(py_obj);
- return (PyArrayObject*) py_obj;
- }
- };
- numpy_handler x__numpy_handler = numpy_handler();
- #define convert_to_numpy(py_obj,name) \
- x__numpy_handler.convert_to_numpy(py_obj,name)
- #define py_to_numpy(py_obj,name) \
- x__numpy_handler.py_to_numpy(py_obj,name)
- PyObject* numpy_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- class catchall_handler
- {
- public:
- py::object convert_to_catchall(PyObject* py_obj, const char* name)
- {
- // Incref occurs even if conversion fails so that
- // the decref in cleanup_code has a matching incref.
- if (!py_obj || !(py_obj))
- handle_conversion_error(py_obj,"catchall", name);
- return py::object(py_obj);
- }
- py::object py_to_catchall(PyObject* py_obj, const char* name)
- {
- // !! Pretty sure INCREF should only be called on success since
- // !! py_to_xxx is used by the user -- not the code generator.
- if (!py_obj || !(py_obj))
- handle_bad_type(py_obj,"catchall", name);
- return py::object(py_obj);
- }
- };
- catchall_handler x__catchall_handler = catchall_handler();
- #define convert_to_catchall(py_obj,name) \
- x__catchall_handler.convert_to_catchall(py_obj,name)
- #define py_to_catchall(py_obj,name) \
- x__catchall_handler.py_to_catchall(py_obj,name)
- PyObject* catchall_to_py(PyObject* obj)
- {
- return (PyObject*) obj;
- }
- void handle_variable_not_found(const char* var_name)
- {
- char msg[500];
- sprintf(msg,"Conversion Error: variable '%s' not found in local or global scope.",var_name);
- throw_error(PyExc_NameError,msg);
- }
- PyObject* get_variable(const char* name,PyObject* locals, PyObject* globals)
- {
- // no checking done for error -- locals and globals should
- // already be validated as dictionaries. If var is NULL, the
- // function calling this should handle it.
- PyObject* var = NULL;
- var = PyDict_GetItemString(locals,name);
- if (!var)
- {
- var = PyDict_GetItemString(globals,name);
- }
- if (!var)
- handle_variable_not_found(name);
- return var;
- }
- PyObject* py_to_raw_dict(PyObject* py_obj, const char* name)
- {
- // simply check that the value is a valid dictionary pointer.
- if(!py_obj || !PyDict_Check(py_obj))
- handle_bad_type(py_obj, "dictionary", name);
- return py_obj;
- }
- #include <boost/graph/adjacency_list.hpp>
- #include <boost/graph/depth_first_search.hpp>
- #include <boost/graph/visitors.hpp>
- typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS> Graph;
- typedef Graph::vertex_descriptor Vertex;
- class MyVisitor : public boost::default_dfs_visitor
- {
- public:
- void discover_vertex(Vertex v, Graph& g)
- {
- std::cout << v << std::endl;
- return;
- }
- };
- // Copyright (C) 2008 Tiago de Paula Peixoto <tiago@skewed.de>
- //
- // This program is free software; you can redistribute it and/or
- // modify it under the terms of the GNU General Public License
- // as published by the Free Software Foundation; either version 3
- // of the License, or (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- #include <map>
- #include <set>
- #include <list>
- #include <tr1/unordered_set>
- #include <tr1/unordered_map>
- #include <tr1/tuple>
- #include "graph.hh"
- #include "graph_wrap.hh"
- #include "graph_filtering.hh"
- #include "graph_properties.hh"
- #include "histogram.hh"
- #include <boost/bind.hpp>
- #include <boost/python.hpp>
- using namespace boost;
- using namespace std;
- using namespace graph_tool;
- namespace graph_tool
- {
- // metafunction to get the correct property map
- template <class IndexMap>
- struct prop_bind_t
- {
- template <class Value>
- struct as
- {
- typedef typename mpl::if_<is_same<Value,bool>,
- uint8_t, Value>::type val_t;
- typedef typename property_map_type::apply<val_t,IndexMap>::type type;
- };
- };
- // utility template function to extract the correct property map
- template <class PropertyMap>
- PropertyMap get_prop(py::object& map)
- {
- try
- {
- python::object pmap(python::handle<>
- (python::borrowed((PyObject*)(map))));
- python::object opmap = pmap.attr("_PropertyMap__map").attr("get_map")();
- return any_cast<PropertyMap>(python::extract<boost::any>(opmap)());
- }
- catch (bad_any_cast&)
- {
- throw GraphException("could not convert property map as requested");
- }
- }
- }
- static PyObject* compiled_func(PyObject*self, PyObject* args)
- {
- py::object return_val;
- int exception_occured = 0;
- PyObject *py__locals = NULL;
- PyObject *py__globals = NULL;
- PyObject *py___gt__graph;
- py___gt__graph = NULL;
- if(!PyArg_ParseTuple(args,"OO:compiled_func",&py__locals,&py__globals))
- return NULL;
- try
- {
- #if defined(__GNUC__) || defined(__ICC)
- PyObject* raw_locals __attribute__ ((unused));
- PyObject* raw_globals __attribute__ ((unused));
- #else
- PyObject* raw_locals;
- PyObject* raw_globals;
- #endif
- raw_locals = py_to_raw_dict(py__locals,"_locals");
- raw_globals = py_to_raw_dict(py__globals,"_globals");
- /* argument conversion code */
- py___gt__graph = get_variable("__gt__graph",raw_locals,raw_globals);
- py::object __gt__graph = convert_to_catchall(py___gt__graph,"__gt__graph");
- /* inline code */
- /* NDARRAY API VERSION 1000009 */
- bool __exception_thrown = false;
- string __exception_error;
- //variable definitions
- typedef GraphInterface::vertex_index_map_t vertex_index_t;
- typedef GraphInterface::edge_index_map_t edge_index_t;
- typedef prop_bind_t<GraphInterface::vertex_index_map_t> vertex_prop_t;
- typedef prop_bind_t<GraphInterface::edge_index_map_t> edge_prop_t;
- typedef prop_bind_t<ConstantPropertyMap<size_t,graph_property_tag> > graph_prop_t;
- typedef vertex_prop_t::as<uint8_t >::type vprop_bool_t;
- typedef vertex_prop_t::as<int32_t >::type vprop_int32_t_t;
- typedef vertex_prop_t::as<int64_t >::type vprop_int64_t_t;
- typedef vertex_prop_t::as<double >::type vprop_double_t;
- typedef vertex_prop_t::as<long double >::type vprop_long_double_t;
- typedef vertex_prop_t::as<string >::type vprop_string_t;
- typedef vertex_prop_t::as<vector<uint8_t> >::type vprop_vector_bool__t;
- typedef vertex_prop_t::as<vector<int32_t> >::type vprop_vector_int32_t__t;
- typedef vertex_prop_t::as<vector<int64_t> >::type vprop_vector_int64_t__t;
- typedef vertex_prop_t::as<vector<double> >::type vprop_vector_double__t;
- typedef vertex_prop_t::as<vector<long double> >::type vprop_vector_long_double__t;
- typedef vertex_prop_t::as<vector<string> >::type vprop_vector_string__t;
- typedef vertex_prop_t::as<python::object >::type vprop_python_object_t;
- typedef edge_prop_t::as<uint8_t >::type eprop_bool_t;
- typedef edge_prop_t::as<int32_t >::type eprop_int32_t_t;
- typedef edge_prop_t::as<int64_t >::type eprop_int64_t_t;
- typedef edge_prop_t::as<double >::type eprop_double_t;
- typedef edge_prop_t::as<long double >::type eprop_long_double_t;
- typedef edge_prop_t::as<string >::type eprop_string_t;
- typedef edge_prop_t::as<vector<uint8_t> >::type eprop_vector_bool__t;
- typedef edge_prop_t::as<vector<int32_t> >::type eprop_vector_int32_t__t;
- typedef edge_prop_t::as<vector<int64_t> >::type eprop_vector_int64_t__t;
- typedef edge_prop_t::as<vector<double> >::type eprop_vector_double__t;
- typedef edge_prop_t::as<vector<long double> >::type eprop_vector_long_double__t;
- typedef edge_prop_t::as<vector<string> >::type eprop_vector_string__t;
- typedef edge_prop_t::as<python::object >::type eprop_python_object_t;
- typedef graph_prop_t::as<uint8_t >::type gprop_bool_t;
- typedef graph_prop_t::as<int32_t >::type gprop_int32_t_t;
- typedef graph_prop_t::as<int64_t >::type gprop_int64_t_t;
- typedef graph_prop_t::as<double >::type gprop_double_t;
- typedef graph_prop_t::as<long double >::type gprop_long_double_t;
- typedef graph_prop_t::as<string >::type gprop_string_t;
- typedef graph_prop_t::as<vector<uint8_t> >::type gprop_vector_bool__t;
- typedef graph_prop_t::as<vector<int32_t> >::type gprop_vector_int32_t__t;
- typedef graph_prop_t::as<vector<int64_t> >::type gprop_vector_int64_t__t;
- typedef graph_prop_t::as<vector<double> >::type gprop_vector_double__t;
- typedef graph_prop_t::as<vector<long double> >::type gprop_vector_long_double__t;
- typedef graph_prop_t::as<vector<string> >::type gprop_vector_string__t;
- typedef graph_prop_t::as<python::object >::type gprop_python_object_t;
- typedef GraphWrap<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, boost::no_property, boost::property<boost::edge_index_t, unsigned int, boost::no_property>, boost::no_property, boost::listS> > graph_graph_t;
- GraphInterface& __gt__graph__gi = python::extract<GraphInterface&>(__gt__graph);
- graph_graph_t graph = graph_wrap(*boost::any_cast<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, boost::no_property, boost::property<boost::edge_index_t, unsigned int, boost::no_property>, boost::no_property, boost::listS>*>(__gt__graph__gi.GetGraphView()), __gt__graph__gi);
- try
- {
- //variable extraction
- // where the actual code is included
- MyVisitor vis;
- boost::depth_first_search(graph, boost::visitor(vis));
- // support code hash: 01eb075b3a12ba408e6be8eafcad9587
- }
- catch (const GraphException& e)
- {
- __exception_error = e.what();
- __exception_thrown = true;
- }
- catch (const bad_any_cast& e)
- {
- __exception_error = e.what();
- __exception_error += " (wrong property map type?)";
- __exception_thrown = true;
- }
- catch (const std::exception& e)
- {
- __exception_error = "unknown exception thrown: ";
- __exception_error += e.what();
- __exception_thrown = true;
- }
- python::dict return_vals;
- return_vals["__exception_error"] = __exception_error;
- return_vals["__exception_thrown"] = __exception_thrown;
- // updated values will be inserted in return_vals below
- return_val = py::object(return_vals.ptr());
- /*I would like to fill in changed locals and globals here...*/
- }
- catch(...)
- {
- return_val = py::object();
- exception_occured = 1;
- }
- /* cleanup code */
- if(!(PyObject*)return_val && !exception_occured)
- {
- return_val = Py_None;
- }
- return return_val.disown();
- }
- static PyMethodDef compiled_methods[] =
- {
- {"compiled_func",(PyCFunction)compiled_func , METH_VARARGS},
- {NULL, NULL} /* Sentinel */
- };
- PyMODINIT_FUNC initsc_1eb3d88edcf7778c711b07a78faac5ed0(void)
- {
- Py_Initialize();
- import_array();
- PyImport_ImportModule("numpy");
- (void) Py_InitModule("sc_1eb3d88edcf7778c711b07a78faac5ed0", compiled_methods);
- }
- #ifdef __CPLUSCPLUS__
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement