MCPcopy Create free account
hub / github.com/davisking/dlib / from_object

Function from_object

tools/python/src/matrix.cpp:51–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51std::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
74std::shared_ptr<matrix<double> > from_list(py::list l)
75{

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
make_tupleFunction · 0.85
attrMethod · 0.80

Tested by

no test coverage detected