Commit a5d75e84 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Add numpy.array access to vector types of property maps

Now vector types of property maps can be accessed as arrays with the
get_array() and 'a' property, just like scalar property maps.
parent 7d0b68ec
......@@ -127,12 +127,24 @@ struct export_vector_types
if (type_name == "long double")
type_name = "long_double";
string name = "Vector_" + type_name;
class_<vector<ValueType> >(name.c_str())
.def(vector_indexing_suite<vector<ValueType> >())
class_<vector<ValueType> > vc(name.c_str());
vc.def(vector_indexing_suite<vector<ValueType> >())
.def("__eq__", &vector_equal_compare<ValueType>)
.def("__ne__", &vector_nequal_compare<ValueType>);
wrap_array(vc, typename mpl::has_key<numpy_types,ValueType>::type());
template <class ValueType>
void wrap_array(class_<vector<ValueType> >& vc, mpl::true_) const
vc.def("get_array", &wrap_vector_not_owned<ValueType>);
template <class ValueType>
void wrap_array(class_<vector<ValueType> >& vc, mpl::false_) const
// exception translation
......@@ -1099,3 +1099,16 @@ def init_edge_classes():
e.__class__.__iter__ = _edge_iter
# Add convenience function to vector classes
def _get_array_view(self):
return self.get_array()[:]
vector_types = [Vector_bool, Vector_int32_t, Vector_int64_t, Vector_double,
for vt in vector_types:
vt.a = property(_get_array_view)
Vector_string.a = None
Vector_string.get_array = lambda self: None
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment