Commit dbcca72f authored by Alexander Dielen's avatar Alexander Dielen

make sure arrays are dense and c style

parent bdf547ac
......@@ -1361,16 +1361,16 @@ void expose_mesh(py::module& m, const char *_name) {
// set_property_array
//======================================================================
.def("set_property_array", [] (Mesh& _self, OM::VPropHandleT<py::none> _ph, py::array_t<double> _arr) {
.def("set_property_array", [] (Mesh& _self, OM::VPropHandleT<py::none> _ph, py::array_t<double, py::array::c_style | py::array::forcecast> _arr) {
return set_property_array<Mesh, OM::VPropHandleT<py::none>, OM::VertexHandle>(_self, _ph, _arr, _self.n_vertices());
})
.def("set_property_array", [] (Mesh& _self, OM::HPropHandleT<py::none> _ph, py::array_t<double> _arr) {
.def("set_property_array", [] (Mesh& _self, OM::HPropHandleT<py::none> _ph, py::array_t<double, py::array::c_style | py::array::forcecast> _arr) {
return set_property_array<Mesh, OM::HPropHandleT<py::none>, OM::HalfedgeHandle>(_self, _ph, _arr, _self.n_halfedges());
})
.def("set_property_array", [] (Mesh& _self, OM::EPropHandleT<py::none> _ph, py::array_t<double> _arr) {
.def("set_property_array", [] (Mesh& _self, OM::EPropHandleT<py::none> _ph, py::array_t<double, py::array::c_style | py::array::forcecast> _arr) {
return set_property_array<Mesh, OM::EPropHandleT<py::none>, OM::EdgeHandle>(_self, _ph, _arr, _self.n_edges());
})
.def("set_property_array", [] (Mesh& _self, OM::FPropHandleT<py::none> _ph, py::array_t<double> _arr) {
.def("set_property_array", [] (Mesh& _self, OM::FPropHandleT<py::none> _ph, py::array_t<double, py::array::c_style | py::array::forcecast> _arr) {
return set_property_array<Mesh, OM::FPropHandleT<py::none>, OM::FaceHandle>(_self, _ph, _arr, _self.n_faces());
})
;
......
......@@ -12,34 +12,82 @@ class Python(unittest.TestCase):
def test_vertex_property_array(self):
prop = openmesh.VPropHandle()
self.mesh.add_property(prop)
# c_contiguous
arr1 = np.random.rand(self.mesh.n_vertices(), 10)
self.mesh.set_property_array(prop, arr1)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1, arr2))
for vh in self.mesh.vertices():
arr3 = self.mesh.property(prop, vh)
self.assertTrue(np.allclose(arr1[vh.idx()], arr3))
# f_contiguous
arr1 = np.random.rand(10, self.mesh.n_vertices())
self.mesh.set_property_array(prop, arr1.T)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1.T, arr2))
for vh in self.mesh.vertices():
arr3 = self.mesh.property(prop, vh)
self.assertTrue(np.allclose(arr1.T[vh.idx()], arr3))
def test_halfedge_property_array(self):
prop = openmesh.HPropHandle()
self.mesh.add_property(prop)
# c_contiguous
arr1 = np.random.rand(self.mesh.n_halfedges(), 10)
self.mesh.set_property_array(prop, arr1)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1, arr2))
for hh in self.mesh.halfedges():
arr3 = self.mesh.property(prop, hh)
self.assertTrue(np.allclose(arr1[hh.idx()], arr3))
# f_contiguous
arr1 = np.random.rand(10, self.mesh.n_halfedges())
self.mesh.set_property_array(prop, arr1.T)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1.T, arr2))
for hh in self.mesh.halfedges():
arr3 = self.mesh.property(prop, hh)
self.assertTrue(np.allclose(arr1.T[hh.idx()], arr3))
def test_edge_property_array(self):
prop = openmesh.EPropHandle()
self.mesh.add_property(prop)
# c_contiguous
arr1 = np.random.rand(self.mesh.n_edges(), 10)
self.mesh.set_property_array(prop, arr1)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1, arr2))
for eh in self.mesh.edges():
arr3 = self.mesh.property(prop, eh)
self.assertTrue(np.allclose(arr1[eh.idx()], arr3))
# f_contiguous
arr1 = np.random.rand(10, self.mesh.n_edges())
self.mesh.set_property_array(prop, arr1.T)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1.T, arr2))
for eh in self.mesh.edges():
arr3 = self.mesh.property(prop, eh)
self.assertTrue(np.allclose(arr1.T[eh.idx()], arr3))
def test_face_property_array(self):
prop = openmesh.FPropHandle()
self.mesh.add_property(prop)
# c_contiguous
arr1 = np.random.rand(self.mesh.n_faces(), 10)
self.mesh.set_property_array(prop, arr1)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1, arr2))
for fh in self.mesh.faces():
arr3 = self.mesh.property(prop, fh)
self.assertTrue(np.allclose(arr1[fh.idx()], arr3))
# f_contiguous
arr1 = np.random.rand(10, self.mesh.n_faces())
self.mesh.set_property_array(prop, arr1.T)
arr2 = self.mesh.property_array(prop)
self.assertTrue(np.allclose(arr1.T, arr2))
for fh in self.mesh.faces():
arr3 = self.mesh.property(prop, fh)
self.assertTrue(np.allclose(arr1.T[fh.idx()], arr3))
if __name__ == '__main__':
......
Markdown is supported
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