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

Function from_list

tools/python/src/matrix.cpp:74–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74std::shared_ptr<matrix<double> > from_list(py::list l)
75{
76 const long nr = py::len(l);
77 if (py::isinstance<py::list>(l[0]))
78 {
79 const long nc = py::len(l[0]);
80 // make sure all the other rows have the same length
81 for (long r = 1; r < nr; ++r)
82 pyassert(py::len(l[r]) == nc, "All rows of a matrix must have the same number of columns.");
83
84 auto temp = std::make_shared<matrix<double>>(nr,nc);
85 for ( long r = 0; r < nr; ++r)
86 {
87 for (long c = 0; c < nc; ++c)
88 {
89 (*temp)(r,c) = l[r].cast<py::list>()[c].cast<double>();
90 }
91 }
92 return temp;
93 }
94 else
95 {
96 // In this case we treat it like a column vector
97 auto temp = std::make_shared<matrix<double>>(nr,1);
98 for ( long r = 0; r < nr; ++r)
99 {
100 (*temp)(r) = l[r].cast<double>();
101 }
102 return temp;
103 }
104}
105
106long matrix_double__len__(matrix<double>& c)
107{

Callers

nothing calls this directly

Calls 1

lenFunction · 0.85

Tested by

no test coverage detected