22 #include "pybind11/pybind11.h" 36 Vector3d getRow(Matrix3d
const &
self, py::int_
row) {
37 return self.getRow(static_cast<int>(python::convertIndex(3, row)));
41 py::module::import(
"lsst.sphgeom.vector3d");
43 py::class_<Matrix3d, std::shared_ptr<Matrix3d>>
cls(mod,
"Matrix3d");
45 cls.def(py::init<>());
46 cls.def(
py::init<
double,
double,
double,
double,
double,
double,
double,
48 "m00"_a,
"m01"_a,
"m02"_a,
"m10"_a,
"m11"_a,
"m12"_a,
"m20"_a,
50 cls.def(py::init<Vector3d const &>(),
"diagonal"_a);
51 cls.def(py::init<double>(),
"scale"_a);
52 cls.def(py::init<Matrix3d const &>(),
"matrix"_a);
54 cls.def(
"__eq__", &Matrix3d::operator==, py::is_operator());
55 cls.def(
"__ne__", &Matrix3d::operator!=, py::is_operator());
58 cls.def(
"getRow", &getRow,
"row"_a);
60 [](Matrix3d
const &
self, py::int_
col) {
61 return self.getColumn(
62 static_cast<int>(python::convertIndex(3, col)));
66 cls.def(
"__len__", [](Matrix3d
const &
self) {
return py::int_(3); });
67 cls.def(
"__getitem__", &getRow, py::is_operator());
68 cls.def(
"__getitem__",
69 [](Matrix3d
const &
self, py::tuple t) {
71 throw py::index_error(
"Too many indexes for Matrix3d");
72 }
else if (t.size() == 0) {
73 return py::cast(
self);
74 }
else if (t.size() == 1) {
75 return py::cast(getRow(
self, t[0].cast<py::int_>()));
78 self(python::convertIndex(3, t[0].cast<py::int_>()),
79 python::convertIndex(3, t[1].cast<py::int_>())));
83 cls.def(
"inner", &Matrix3d::inner,
"matrix"_a);
84 cls.def(
"getSquaredNorm", &Matrix3d::getSquaredNorm);
85 cls.def(
"getNorm", &Matrix3d::getNorm);
88 (Vector3d(Matrix3d::*)(Vector3d
const &)
const) &
90 "vector"_a, py::is_operator());
92 (Matrix3d(Matrix3d::*)(Matrix3d
const &)
const) &
94 "matrix"_a, py::is_operator());
95 cls.def(
"__add__", &Matrix3d::operator+, py::is_operator());
96 cls.def(
"__sub__", &Matrix3d::operator-, py::is_operator());
98 cls.def(
"cwiseProduct", &Matrix3d::cwiseProduct);
99 cls.def(
"transpose", &Matrix3d::transpose);
100 cls.def(
"inverse", &Matrix3d::inverse);
102 cls.def(
"__str__", [](Matrix3d
const &
self) {
103 return py::str(
"[[{!s}, {!s}, {!s}],\n" 104 " [{!s}, {!s}, {!s}],\n" 105 " [{!s}, {!s}, {!s}]]")
106 .format(
self(0, 0),
self(0, 1),
self(0, 2),
self(1, 0),
107 self(1, 1),
self(1, 2),
self(2, 0),
self(2, 1),
110 cls.def(
"__repr__", [](Matrix3d
const &
self) {
111 return py::str(
"Matrix3d({!r}, {!r}, {!r},\n" 112 " {!r}, {!r}, {!r},\n" 113 " {!r}, {!r}, {!r})")
114 .format(
self(0, 0),
self(0, 1),
self(0, 2),
self(1, 0),
115 self(1, 1),
self(1, 2),
self(2, 0),
self(2, 1),
118 cls.def(
"__reduce__", [
cls](Matrix3d
const &
self) {
119 auto args = py::make_tuple(
self(0, 0),
self(0, 1),
self(0, 2),
120 self(1, 0),
self(1, 1),
self(1, 2),
121 self(2, 0),
self(2, 1),
self(2, 2));
122 return py::make_tuple(
cls,
args);
PYBIND11_MODULE(camera, mod)
A base class for image defects.
This file contains a class representing 3x3 real matrices.