22#include "pybind11/pybind11.h"
30using namespace pybind11::literals;
36Vector3d getRow(Matrix3d
const &self, py::int_
row) {
43 cls.def(py::init<>());
44 cls.def(py::init<
double,
double,
double,
double,
double,
double,
double,
46 "m00"_a,
"m01"_a,
"m02"_a,
"m10"_a,
"m11"_a,
"m12"_a,
"m20"_a,
48 cls.def(py::init<Vector3d const &>(),
"diagonal"_a);
49 cls.def(py::init<double>(),
"scale"_a);
50 cls.def(py::init<Matrix3d const &>(),
"matrix"_a);
52 cls.def(
"__eq__", &Matrix3d::operator==, py::is_operator());
53 cls.def(
"__ne__", &Matrix3d::operator!=, py::is_operator());
56 cls.def(
"getRow", &getRow,
"row"_a);
64 cls.def(
"__len__", [](
Matrix3d const &self) {
return py::int_(3); });
65 cls.def(
"__getitem__", &getRow, py::is_operator());
66 cls.def(
"__getitem__",
67 [](
Matrix3d const &self, py::tuple t) {
69 throw py::index_error(
"Too many indexes for Matrix3d");
70 }
else if (t.size() == 0) {
71 return py::cast(self);
72 }
else if (t.size() == 1) {
73 return py::cast(getRow(self, t[0].cast<py::int_>()));
88 "vector"_a, py::is_operator());
92 "matrix"_a, py::is_operator());
93 cls.def(
"__add__", &Matrix3d::operator+, py::is_operator());
94 cls.def(
"__sub__", &Matrix3d::operator-, py::is_operator());
100 cls.def(
"__str__", [](
Matrix3d const &self) {
101 return py::str(
"[[{!s}, {!s}, {!s}],\n"
102 " [{!s}, {!s}, {!s}],\n"
103 " [{!s}, {!s}, {!s}]]")
104 .format(self(0, 0), self(0, 1), self(0, 2), self(1, 0),
105 self(1, 1), self(1, 2), self(2, 0), self(2, 1),
108 cls.def(
"__repr__", [](
Matrix3d const &self) {
109 return py::str(
"Matrix3d({!r}, {!r}, {!r},\n"
110 " {!r}, {!r}, {!r},\n"
111 " {!r}, {!r}, {!r})")
112 .format(self(0, 0), self(0, 1), self(0, 2), self(1, 0),
113 self(1, 1), self(1, 2), self(2, 0), self(2, 1),
116 cls.def(
"__reduce__", [cls](
Matrix3d const &self) {
117 auto args = py::make_tuple(self(0, 0), self(0, 1), self(0, 2),
118 self(1, 0), self(1, 1), self(1, 2),
119 self(2, 0), self(2, 1), self(2, 2));
120 return py::make_tuple(cls, args);
This file contains a class representing 3x3 real matrices.
A 3x3 matrix with real entries stored in double precision.
Matrix3d inverse() const
inverse returns the inverse of this matrix.
Vector3d const & getColumn(int c) const
getColumn returns the c-th matrix column. Bounds are not checked.
double getNorm() const
getNorm returns the L2 (Frobenius) norm of this matrix.
double inner(Matrix3d const &m) const
inner returns the Frobenius inner product of this matrix with m.
Matrix3d transpose() const
transpose returns the transpose of this matrix.
Matrix3d cwiseProduct(Matrix3d const &m) const
cwiseProduct returns the component-wise product of this matrix and m.
double getSquaredNorm() const
getSquaredNorm returns the Frobenius inner product of this matrix with itself.
Vector3d is a vector in ℝ³ with components stored in double precision.
ptrdiff_t convertIndex(ptrdiff_t len, pybind11::int_ i)
Convert a Python index i over a sequence with length len to a non-negative (C++ style) index,...
void defineClass(Pybind11Class &cls)