MCPcopy Create free account
hub / github.com/ImageEngine/cortex / constructFromSequence

Function constructFromSequence

src/IECorePython/ObjectMatrixBinding.cpp:50–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48{
49
50ObjectMatrixPtr constructFromSequence( object o )
51{
52 const size_t rows = boost::python::len( o );
53 size_t columns = 0;
54 for( size_t i = 0; i < rows; ++i )
55 {
56 object row = o[i];
57 if( !PyList_Check( row.ptr() ) )
58 {
59 PyErr_SetString( PyExc_ValueError, "Each element must be a list" );
60 throw_error_already_set();
61 }
62 size_t rowLength = boost::python::len( row );
63 if( rowLength > columns )
64 {
65 columns = rowLength;
66 }
67 }
68
69 ObjectMatrixPtr result = new ObjectMatrix( rows, columns );
70 ObjectMatrix *m = result.get();
71 for( size_t i = 0; i < rows; ++i )
72 {
73 for( size_t j = 0; j < columns; ++j )
74 {
75 if( j < (size_t)boost::python::len( o[i] ) )
76 {
77 (*m)[i][j] = extract<IECore::ObjectPtr>( o[i][j] );
78 }
79 }
80 }
81
82 return result;
83}
84
85std::string repr( const ObjectMatrix &m )
86{

Callers

nothing calls this directly

Calls 2

lenFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected