python_shared.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <pybind11/pybind11.h>
  3. #include <pybind11/operators.h>
  4. #include <pybind11/complex.h>
  5. #include <pybind11/numpy.h>
  6. #include <pybind11/stl.h>
  7. #include <pybind11/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_Vector2(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  28. {
  29. if (v.size() == 0)
  30. return;
  31. if ((v.cols() != 1) || (v.rows() != 2))
  32. throw std::runtime_error(name + " must be a column vector with 2 entries.");
  33. }
  34. template<typename Scalar>
  35. void assert_is_RowVector2(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  36. {
  37. if (v.size() == 0)
  38. return;
  39. if ((v.cols() != 2) || (v.rows() != 1))
  40. throw std::runtime_error(name + " must be a row vector with 2 entries.");
  41. }
  42. template<typename Scalar>
  43. void assert_is_Vector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  44. {
  45. if (v.size() == 0)
  46. return;
  47. if ((v.cols() != 1) || (v.rows() != 3))
  48. throw std::runtime_error(name + " must be a column vector with 3 entries.");
  49. }
  50. template<typename Scalar>
  51. void assert_is_RowVector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  52. {
  53. if (v.size() == 0)
  54. return;
  55. if ((v.cols() != 3) || (v.rows() != 1))
  56. throw std::runtime_error(name + " must be a row vector with 3 entries.");
  57. }
  58. template<typename Scalar>
  59. void assert_is_Vector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  60. {
  61. if (v.size() == 0)
  62. return;
  63. if ((v.cols() != 1) || (v.rows() != 4))
  64. throw std::runtime_error(name + " must be a column vector with 4 entries.");
  65. }
  66. template<typename Scalar>
  67. void assert_is_RowVector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  68. {
  69. if (v.size() == 0)
  70. return;
  71. if ((v.cols() != 4) || (v.rows() != 1))
  72. throw std::runtime_error(name + " must be a row vector with 4 entries.");
  73. }
  74. template<typename Scalar>
  75. void assert_is_Matrix4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  76. {
  77. if (v.size() == 0)
  78. return;
  79. if ((v.cols() != 4) || (v.rows() != 4))
  80. throw std::runtime_error(name + " must be a 4x4 matrix.");
  81. }
  82. namespace py = pybind11;