m2p.m 786 B

12345678910111213141516171819
  1. % Converts a Matlab matrix to a python-wrapped Eigen Matrix
  2. function [ P ] = m2p( M )
  3. if (isa(M, 'double'))
  4. % Convert the matrix to a python 1D array
  5. a = py.array.array('d',reshape(M,1,numel(M)));
  6. % Then convert it to a eigen type
  7. t = py.igl.eigen.MatrixXd(a.tolist());
  8. % Finally reshape it back
  9. P = t.MapMatrix(uint16(size(M,1)),uint16(size(M,2)));
  10. elseif (isa(M, 'integer'))
  11. % Convert the matrix to a python 1D array
  12. a = py.array.array('i',reshape(M,1,numel(M)));
  13. % Then convert it to a eigen type
  14. t = py.igl.eigen.MatrixXi(a.tolist());
  15. % Finally reshape it back
  16. P = t.MapMatrix(uint16(size(M,1)),uint16(size(M,2)));
  17. else
  18. error('Unsupported numerical type.');
  19. end