Skip to content

Commit

Permalink
fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Dielen committed May 15, 2018
1 parent 97f1a61 commit 3d6daaf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/MeshTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public:
const auto prop = py_prop_on_demand<Handle, PropHandle>(_name);

if (_list.size() != n) {
return;
PyErr_SetString(PyExc_RuntimeError, "List must have length n.");
throw py::error_already_set();
}
for (size_t i = 0; i < n; ++i) {
Mesh::property(prop, Handle(i)) = py::object(_list[i]);
Expand Down Expand Up @@ -150,9 +151,15 @@ public:
const size_t n = py_n_items(Handle());
const auto prop = py_prop_on_demand<Handle, PropHandle>(_name);

// array cannot be empty and its shape has to be (_n, m,...)
if (_arr.size() == 0 || _arr.ndim() < 2 || _arr.shape(0) != n) {
return;
// array cannot be empty and its shape has to be (n, ...)
if (_arr.size() == 0 || _arr.ndim() < 1 || _arr.shape(0) != n) {
PyErr_SetString(PyExc_RuntimeError, "Array must have shape (n, ...).");
throw py::error_already_set();
}

// reshape to (n, 1) if necessary
if (_arr.ndim() == 1) {
_arr.resize({n, size_t(1)});
}

// copy one array at a time
Expand Down

0 comments on commit 3d6daaf

Please sign in to comment.