python_shared.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <pybind/pybind.h>
  3. #include <pybind/operators.h>
  4. #include <pybind/complex.h>
  5. #include <pybind/numpy.h>
  6. #include <pybind/stl.h>
  7. #include <pybind/functional.h>
  8. #include "py_doc.h"
  9. #include <Eigen/Dense>
  10. template<typename Scalar>
  11. void assert_is_VectorX(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  12. {
  13. if (v.size() == 0)
  14. return;
  15. if (v.cols() != 1)
  16. throw std::runtime_error(name + " must be a column vector.");
  17. }
  18. template<typename Scalar>
  19. void assert_is_RowVectorX(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  20. {
  21. if (v.size() == 0)
  22. return;
  23. if (v.rows() != 1)
  24. throw std::runtime_error(name + " must be a row vector.");
  25. }
  26. template<typename Scalar>
  27. void assert_is_Vector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  28. {
  29. if (v.size() == 0)
  30. return;
  31. if ((v.cols() != 1) || (v.rows() != 3))
  32. throw std::runtime_error(name + " must be a column vector with 3 entries.");
  33. }
  34. template<typename Scalar>
  35. void assert_is_RowVector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  36. {
  37. if (v.size() == 0)
  38. return;
  39. if ((v.cols() != 3) || (v.rows() != 1))
  40. throw std::runtime_error(name + " must be a row vector with 3 entries.");
  41. }
  42. template<typename Scalar>
  43. void assert_is_Vector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  44. {
  45. if (v.size() == 0)
  46. return;
  47. if ((v.cols() != 1) || (v.rows() != 4))
  48. throw std::runtime_error(name + " must be a column vector with 4 entries.");
  49. }
  50. template<typename Scalar>
  51. void assert_is_RowVector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  52. {
  53. if (v.size() == 0)
  54. return;
  55. if ((v.cols() != 4) || (v.rows() != 1))
  56. throw std::runtime_error(name + " must be a row vector with 4 entries.");
  57. }
  58. template<typename Scalar>
  59. void assert_is_Matrix4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  60. {
  61. if (v.size() == 0)
  62. return;
  63. if ((v.cols() != 4) || (v.rows() != 4))
  64. throw std::runtime_error(name + " must be a 4x4 matrix.");
  65. }
  66. namespace py = pybind;