| 48 | { |
| 49 | |
| 50 | ObjectMatrixPtr 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 | |
| 85 | std::string repr( const ObjectMatrix &m ) |
| 86 | { |