| 49 | |
| 50 | |
| 51 | std::shared_ptr<matrix<double> > from_object(py::object obj) |
| 52 | { |
| 53 | py::tuple s = obj.attr("shape").cast<py::tuple>(); |
| 54 | if (len(s) != 2) |
| 55 | { |
| 56 | PyErr_SetString( PyExc_IndexError, "Input must be a matrix or some kind of 2D array." |
| 57 | ); |
| 58 | throw py::error_already_set(); |
| 59 | } |
| 60 | |
| 61 | const long nr = s[0].cast<long>(); |
| 62 | const long nc = s[1].cast<long>(); |
| 63 | auto temp = std::make_shared<matrix<double>>(nr,nc); |
| 64 | for ( long r = 0; r < nr; ++r) |
| 65 | { |
| 66 | for (long c = 0; c < nc; ++c) |
| 67 | { |
| 68 | (*temp)(r,c) = obj[py::make_tuple(r,c)].cast<double>(); |
| 69 | } |
| 70 | } |
| 71 | return temp; |
| 72 | } |
| 73 | |
| 74 | std::shared_ptr<matrix<double> > from_list(py::list l) |
| 75 | { |
nothing calls this directly
no test coverage detected