Debian Codegraph @

src/python/PyImath/PyImathMatrix22.cpp

raw
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5
6 // clang-format off
7
8 #define BOOST_PYTHON_MAX_ARITY 17
9
10 #include <Python.h>
11 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
12 #include <boost/python.hpp>
13 #include <boost/python/make_constructor.hpp>
14 #include <boost/format.hpp>
15 #include <boost/python/tuple.hpp>
16 #include <boost/python/dict.hpp>
17 #include <boost/python/raw_function.hpp>
18 #include <ImathVec.h>
19 #include <ImathMatrixAlgo.h>
20 #include "PyImath.h"
21 #include "PyImathVec.h"
22 #include "PyImathMathExc.h"
23 #include "PyImathMatrix.h"
24 #include "PyImathExport.h"
25 #include "PyImathDecorators.h"
26
27 namespace PyImath {
28
29 template<> const char *PyImath::M22fArray::name() { return "M22fArray"; }
30 template<> const char *PyImath::M22dArray::name() { return "M22dArray"; }
31
32 using namespace boost::python;
33 using namespace IMATH_NAMESPACE;
34
35 template <class T, int len>
36 struct MatrixRow {
37 explicit MatrixRow(T *data) : _data(data) {}
38 T & operator [] (int i) { return _data[i]; }
39 T *_data;
40
41 static const char *name;
42 static void register_class()
43 {
44 typedef PyImath::StaticFixedArray<MatrixRow,T,len> MatrixRow_helper;
45 class_<MatrixRow> matrixRow_class(name,no_init);
46 matrixRow_class
47 .def("__len__", MatrixRow_helper::len)
48 .def("__getitem__", MatrixRow_helper::getitem,return_value_policy<copy_non_const_reference>())
49 .def("__setitem__", MatrixRow_helper::setitem)
50 ;
51 }
52 };
53
54 template <> const char *MatrixRow<float,2>::name = "M22fRow";
55 template <> const char *MatrixRow<double,2>::name = "M22dRow";
56
57
58 template <class Container, class Data, int len>
59 struct IndexAccessMatrixRow {
60 typedef MatrixRow<Data,len> result_type;
61 static MatrixRow<Data,len> apply(Container &c, int i) { return MatrixRow<Data,len>(c[i]); }
62 };
63
64 template <class T> struct Matrix22Name { static const char *value; };
65 template<> const char *Matrix22Name<float>::value = "M22f";
66 template<> const char *Matrix22Name<double>::value = "M22d";
67
68 template <class T>
69 static std::string Matrix22_str(const Matrix22<T> &v)
70 {
71 std::stringstream stream;
72 stream << Matrix22Name<T>::value << "(";
73 for (int row = 0; row < 2; row++)
74 {
75 stream << "(";
76 for (int col = 0; col < 2; col++)
77 {
78 stream << v[row][col];
79 stream << (col != 1 ? ", " : "");
80 }
81 stream << ")" << (row != 1 ? ", " : "");
82 }
83 stream << ")";
84 return stream.str();
85 }
86
87 // Non-specialized repr is same as str
88 template <class T>
89 static std::string Matrix22_repr(const Matrix22<T> &v)
90 {
91 return Matrix22_str(v);
92 }
93
94 // Specialization for float to full precision
95 template <>
96 std::string Matrix22_repr(const Matrix22<float> &v)
97 {
98 return (boost::format("%s((%.9g, %.9g), (%.9g, %.9g))")
99 % Matrix22Name<float>::value
100 % v[0][0] % v[0][1]
101 % v[1][0] % v[1][1]).str();
102 }
103
104 // Specialization for double to full precision
105 template <>
106 std::string Matrix22_repr(const Matrix22<double> &v)
107 {
108 return (boost::format("%s((%.17g, %.17g), (%.17g, %.17g))")
109 % Matrix22Name<double>::value
110 % v[0][0] % v[0][1]
111 % v[1][0] % v[1][1]).str();
112 }
113
114 template <class T>
115 static const Matrix22<T> &
116 invert22 (Matrix22<T> &m, bool singExc = true)
117 {
118 MATH_EXC_ON;
119 return m.invert(singExc);
120 }
121
122 template <class T>
123 static Matrix22<T>
124 inverse22 (Matrix22<T> &m, bool singExc = true)
125 {
126 MATH_EXC_ON;
127 return m.inverse(singExc);
128 }
129
130 template <class T, class U>
131 static const Matrix22<T> &
132 iadd22(Matrix22<T> &m, const Matrix22<U> &m2)
133 {
134 MATH_EXC_ON;
135 Matrix22<T> m3;
136 m3.setValue (m2);
137 return m += m3;
138 }
139
140 template <class T>
141 static const Matrix22<T> &
142 iadd22T(Matrix22<T> &mat, T a)
143 {
144 MATH_EXC_ON;
145 return mat += a;
146 }
147
148 template <class T>
149 static Matrix22<T>
150 add22(Matrix22<T> &m, const Matrix22<T> &m2)
151 {
152 MATH_EXC_ON;
153 return m + m2;
154 }
155
156 template <class T, class U>
157 static const Matrix22<T> &
158 isub22(Matrix22<T> &m, const Matrix22<U> &m2)
159 {
160 MATH_EXC_ON;
161 Matrix22<T> m3;
162 m3.setValue (m2);
163 return m -= m3;
164 }
165
166 template <class T>
167 static const Matrix22<T> &
168 isub22T(Matrix22<T> &mat, T a)
169 {
170 MATH_EXC_ON;
171 return mat -= a;
172 }
173
174 template <class T>
175 static Matrix22<T>
176 sub22(Matrix22<T> &m, const Matrix22<T> &m2)
177 {
178 MATH_EXC_ON;
179 return m - m2;
180 }
181
182 template <class T>
183 static const Matrix22<T> &
184 negate22 (Matrix22<T> &m)
185 {
186 MATH_EXC_ON;
187 return m.negate();
188 }
189
190 template <class T>
191 static Matrix22<T>
192 neg22 (Matrix22<T> &m)
193 {
194 MATH_EXC_ON;
195 return -m;
196 }
197
198 template <class T>
199 static const Matrix22<T> &
200 imul22T(Matrix22<T> &m, const T &t)
201 {
202 MATH_EXC_ON;
203 return m *= t;
204 }
205
206 template <class T>
207 static Matrix22<T>
208 mul22T(Matrix22<T> &m, const T &t)
209 {
210 MATH_EXC_ON;
211 return m * t;
212 }
213
214 template <class T>
215 static Matrix22<T>
216 rmul22T(Matrix22<T> &m, const T &t)
217 {
218 MATH_EXC_ON;
219 return t * m;
220 }
221
222 template <class T>
223 static const Matrix22<T> &
224 idiv22T(Matrix22<T> &m, const T &t)
225 {
226 MATH_EXC_ON;
227 return m /= t;
228 }
229
230 template <class T>
231 static Matrix22<T>
232 div22T(Matrix22<T> &m, const T &t)
233 {
234 MATH_EXC_ON;
235 return m / t;
236 }
237
238 template <class T>
239 void
240 outerProduct22(Matrix22<T> &mat, const Vec2<T> &a, const Vec2<T> &b)
241 {
242 MATH_EXC_ON;
243 mat = IMATH_NAMESPACE::outerProduct(a,b);
244 }
245
246 template <class TV,class TM>
247 static void
248 multDirMatrix22(Matrix22<TM> &mat, const Vec2<TV> &src, Vec2<TV> &dst)
249 {
250 MATH_EXC_ON;
251 mat.multDirMatrix(src, dst);
252 }
253
254 template <class TV,class TM>
255 static Vec2<TV>
256 multDirMatrix22_return_value(Matrix22<TM> &mat, const Vec2<TV> &src)
257 {
258 MATH_EXC_ON;
259 Vec2<TV> dst;
260 mat.multDirMatrix(src, dst);
261 return dst;
262 }
263
264 template <class TV,class TM>
265 static FixedArray<Vec2<TV> >
266 multDirMatrix22_array(Matrix22<TM> &mat, const FixedArray<Vec2<TV> >&src)
267 {
268 MATH_EXC_ON;
269 size_t len = src.len();
270 FixedArray<Vec2<TV> > dst(len);
271 for (size_t i=0; i<len; ++i) mat.multDirMatrix(src[i], dst[i]);
272 return dst;
273 }
274
275 template <class T>
276 static const Matrix22<T> &
277 rotate22(Matrix22<T> &mat, const T &r)
278 {
279 MATH_EXC_ON;
280 return mat.rotate(r);
281 }
282
283 template <class T>
284 static void
285 extractEuler(Matrix22<T> &mat, Vec2<T> &dstObj)
286 {
287 MATH_EXC_ON;
288 T dst;
289 IMATH_NAMESPACE::extractEuler(mat, dst);
290 dstObj.setValue(dst, T (0));
291 }
292
293 template <class T>
294 static const Matrix22<T> &
295 scaleSc22(Matrix22<T> &mat, const T &s)
296 {
297 MATH_EXC_ON;
298 Vec2<T> sVec(s, s);
299 return mat.scale(sVec);
300 }
301
302 template <class T>
303 static const Matrix22<T> &
304 scaleV22(Matrix22<T> &mat, const Vec2<T> &s)
305 {
306 MATH_EXC_ON;
307 return mat.scale(s);
308 }
309
310 template <class T>
311 static const Matrix22<T> &
312 scale22Tuple(Matrix22<T> &mat, const tuple &t)
313 {
314 MATH_EXC_ON;
315 if(t.attr("__len__")() == 2)
316 {
317 Vec2<T> s;
318 s.x = extract<T>(t[0]);
319 s.y = extract<T>(t[1]);
320
321 return mat.scale(s);
322 }
323 else
324 throw std::invalid_argument ( "m.scale needs tuple of length 2");
325 }
326
327 template <class T>
328 static const Matrix22<T> &
329 setRotation22(Matrix22<T> &mat, const T &r)
330 {
331 MATH_EXC_ON;
332 return mat.setRotation(r);
333 }
334
335 template <class T>
336 static const Matrix22<T> &
337 setScaleSc22(Matrix22<T> &mat, const T &s)
338 {
339 MATH_EXC_ON;
340 return mat.setScale(s);
341 }
342
343 template <class T>
344 static const Matrix22<T> &
345 setScaleV22(Matrix22<T> &mat, const Vec2<T> &s)
346 {
347 MATH_EXC_ON;
348 return mat.setScale(s);
349 }
350
351 template <class T>
352 static const Matrix22<T> &
353 setScale22Tuple(Matrix22<T> &mat, const tuple &t)
354 {
355 MATH_EXC_ON;
356 if(t.attr("__len__")() == 2)
357 {
358 Vec2<T> s;
359 s.x = extract<T>(t[0]);
360 s.y = extract<T>(t[1]);
361
362 return mat.setScale(s);
363 }
364 else
365 throw std::invalid_argument ( "m.setScale needs tuple of length 2");
366 }
367
368 template <class T>
369 static void
370 setValue22(Matrix22<T> &mat, const Matrix22<T> &value)
371 {
372 MATH_EXC_ON;
373 mat.setValue(value);
374 }
375
376 template <class T>
377 static Matrix22<T>
378 subtractTL22(Matrix22<T> &mat, T a)
379 {
380 MATH_EXC_ON;
381 Matrix22<T> m(mat.x);
382 for(int i = 0; i < 2; ++i)
383 for(int j = 0; j < 2; ++j)
384 m.x[i][j] -= a;
385
386 return m;
387 }
388
389 template <class T>
390 static Matrix22<T>
391 subtractTR22(Matrix22<T> &mat, T a)
392 {
393 MATH_EXC_ON;
394 Matrix22<T> m(mat.x);
395 for(int i = 0; i < 2; ++i)
396 for(int j = 0; j < 2; ++j)
397 m.x[i][j] = a - m.x[i][j];
398
399 return m;
400 }
401
402
403 template <class T>
404 static Matrix22<T>
405 add22T(Matrix22<T> &mat, T a)
406 {
407 MATH_EXC_ON;
408 Matrix22<T> m(mat.x);
409 for(int i = 0; i < 2; ++i)
410 for(int j = 0; j < 2; ++j)
411 m.x[i][j] += a;
412
413 return m;
414 }
415
416 template <class S, class T>
417 static Matrix22<T>
418 mul22(Matrix22<T> &mat1, Matrix22<S> &mat2)
419 {
420 MATH_EXC_ON;
421 Matrix22<T> mat2T;
422 mat2T.setValue (mat2);
423 return mat1 * mat2T;
424 }
425
426 template <class S, class T>
427 static Matrix22<T>
428 rmul22(Matrix22<T> &mat2, Matrix22<S> &mat1)
429 {
430 MATH_EXC_ON;
431 Matrix22<T> mat1T;
432 mat1T.setValue (mat1);
433 return mat1T * mat2;
434 }
435
436 template <class S, class T>
437 static const Matrix22<T> &
438 imul22(Matrix22<T> &mat1, Matrix22<S> &mat2)
439 {
440 MATH_EXC_ON;
441 Matrix22<T> mat2T;
442 mat2T.setValue (mat2);
443 return mat1 *= mat2T;
444 }
445
446 template <class T>
447 static bool
448 lessThan22(Matrix22<T> &mat1, const Matrix22<T> &mat2)
449 {
450 for(int i = 0; i < 2; ++i){
451 for(int j = 0; j < 2; ++j){
452 if(mat1[i][j] > mat2[i][j]){
453 return false;
454 }
455 }
456 }
457
458 return (mat1 != mat2);
459 }
460
461 template <class T>
462 static bool
463 lessThanEqual22(Matrix22<T> &mat1, const Matrix22<T> &mat2)
464 {
465 for(int i = 0; i < 2; ++i){
466 for(int j = 0; j < 2; ++j){
467 if(mat1[i][j] > mat2[i][j]){
468 return false;
469 }
470 }
471 }
472
473 return true;
474 }
475
476 template <class T>
477 static bool
478 greaterThan22(Matrix22<T> &mat1, const Matrix22<T> &mat2)
479 {
480 for(int i = 0; i < 2; ++i){
481 for(int j = 0; j < 2; ++j){
482 if(mat1[i][j] < mat2[i][j]){
483 std::cout << mat1[i][j] << " " << mat2[i][j] << std::endl;
484 return false;
485 }
486 }
487 }
488
489 return (mat1 != mat2);
490 }
491
492 template <class T>
493 static bool
494 greaterThanEqual22(Matrix22<T> &mat1, const Matrix22<T> &mat2)
495 {
496 for(int i = 0; i < 2; ++i){
497 for(int j = 0; j < 2; ++j){
498 if(mat1[i][j] < mat2[i][j]){
499 return false;
500 }
501 }
502 }
503
504 return true;
505 }
506
507 BOOST_PYTHON_FUNCTION_OVERLOADS(invert22_overloads, invert22, 1, 2);
508 BOOST_PYTHON_FUNCTION_OVERLOADS(inverse22_overloads, inverse22, 1, 2);
509 BOOST_PYTHON_FUNCTION_OVERLOADS(outerProduct22_overloads, outerProduct22, 3, 3);
510
511 template <class T>
512 static Matrix22<T> * Matrix2_tuple_constructor(const tuple &t0, const tuple &t1)
513 {
514 if(t0.attr("__len__")() == 2 && t1.attr("__len__")() == 2)
515 {
516 return new Matrix22<T>(extract<T>(t0[0]), extract<T>(t0[1]),
517 extract<T>(t1[0]), extract<T>(t1[1]));
518 }
519 else
520 throw std::invalid_argument ("Matrix22 takes 2 tuples of length 2");
521 }
522
523 template <class T, class S>
524 static Matrix22<T> *Matrix2_matrix_constructor(const Matrix22<S> &mat)
525 {
526 Matrix22<T> *m = new Matrix22<T>;
527
528 for(int i = 0; i < 2; ++i)
529 for(int j = 0; j < 2; ++j)
530 m->x[i][j] = T (mat.x[i][j]);
531
532 return m;
533 }
534
535 template <class T>
536 class_<Matrix22<T> >
537 register_Matrix22()
538 {
539 typedef PyImath::StaticFixedArray<Matrix22<T>,T,2,IndexAccessMatrixRow<Matrix22<T>,T,2> > Matrix22_helper;
540
541 MatrixRow<T,2>::register_class();
542 class_<Matrix22<T> > matrix22_class(Matrix22Name<T>::value, Matrix22Name<T>::value,init<Matrix22<T> >("copy construction"));
543 matrix22_class
544 .def(init<>("initialize to identity"))
545 .def(init<T>("initialize all entries to a single value"))
546 .def(init<T,T,T,T>("make from components"))
547 .def("__init__", make_constructor(Matrix2_tuple_constructor<T>))
548 .def("__init__", make_constructor(Matrix2_matrix_constructor<T,float>))
549 .def("__init__", make_constructor(Matrix2_matrix_constructor<T,double>))
550
551 //.def_readwrite("x00", &Matrix22<T>::x[0][0])
552 //.def_readwrite("x01", &Matrix22<T>::x[0][1])
553 //.def_readwrite("x02", &Matrix22<T>::x[0][2])
554 //.def_readwrite("x10", &Matrix22<T>::x[1][0])
555 //.def_readwrite("x11", &Matrix22<T>::x[1][1])
556 //.def_readwrite("x12", &Matrix22<T>::x[1][2])
557 //.def_readwrite("x20", &Matrix22<T>::x[2][0])
558 //.def_readwrite("x21", &Matrix22<T>::x[2][1])
559 //.def_readwrite("x22", &Matrix22<T>::x[2][2])
560 .def("baseTypeEpsilon", &Matrix22<T>::baseTypeEpsilon,"baseTypeEpsilon() epsilon value of the base type of the vector")
561 .staticmethod("baseTypeEpsilon")
562 .def("baseTypeMax", &Matrix22<T>::baseTypeMax,"baseTypeMax() max value of the base type of the vector")
563 .staticmethod("baseTypeMax")
564 .def("baseTypeLowest", &Matrix22<T>::baseTypeLowest,"baseTypeLowest() largest negative value of the base type of the vector")
565 .staticmethod("baseTypeLowest")
566 .def("baseTypeSmallest", &Matrix22<T>::baseTypeSmallest,"baseTypeSmallest() smallest value of the base type of the vector")
567 .staticmethod("baseTypeSmallest")
568 .def("equalWithAbsError", &Matrix22<T>::equalWithAbsError,"m1.equalWithAbsError(m2,e) true if the elements "
569 "of v1 and v2 are the same with an absolute error of no more than e, "
570 "i.e., abs(m1[i] - m2[i]) <= e")
571 .def("equalWithRelError", &Matrix22<T>::equalWithRelError,"m1.equalWithAbsError(m2,e) true if the elements "
572 "of m1 and m2 are the same with an absolute error of no more than e, "
573 "i.e., abs(m1[i] - m2[i]) <= e * abs(m1[i])")
574 // need a different version for matrix data access
575 .def("__len__", Matrix22_helper::len)
576 .def("__getitem__", Matrix22_helper::getitem)
577 //.def("__setitem__", Matrix22_helper::setitem)
578 .def("makeIdentity",&Matrix22<T>::makeIdentity,"makeIdentity() make this matrix the identity matrix")
579 .def("transpose",&Matrix22<T>::transpose,return_internal_reference<>(),"transpose() transpose this matrix")
580 .def("transposed",&Matrix22<T>::transposed,"transposed() return a transposed copy of this matrix")
581 .def("invert",&invert22<T>,invert22_overloads("invert() invert this matrix")[return_internal_reference<>()])
582 .def("inverse",&inverse22<T>,inverse22_overloads("inverse() return an inverted copy of this matrix"))
583 .def("determinant",&Matrix22<T>::determinant,"determinant() return the determinant of this matrix")
584 .def(self == self) // NOSONAR - suppress SonarCloud bug report.
585 .def(self != self) // NOSONAR - suppress SonarCloud bug report.
586 .def("__iadd__", &iadd22<T, float>,return_internal_reference<>())
587 .def("__iadd__", &iadd22<T, double>,return_internal_reference<>())
588 .def("__iadd__", &iadd22T<T>,return_internal_reference<>())
589 .def("__add__", &add22<T>)
590 .def("__isub__", &isub22<T, float>,return_internal_reference<>())
591 .def("__isub__", &isub22<T, double>,return_internal_reference<>())
592 .def("__isub__", &isub22T<T>,return_internal_reference<>())
593 .def("__sub__", &sub22<T>)
594 .def("negate",&negate22<T>,return_internal_reference<>(),"negate() negate all entries in this matrix")
595 .def("__neg__", &neg22<T>)
596 .def("__imul__", &imul22T<T>,return_internal_reference<>())
597 .def("__mul__", &mul22T<T>)
598 .def("__rmul__", &rmul22T<T>)
599 .def("__idiv__", &idiv22T<T>,return_internal_reference<>())
600 .def("__itruediv__", &idiv22T<T>,return_internal_reference<>())
601 .def("__div__", &div22T<T>)
602 .def("__truediv__", &div22T<T>)
603 .def("__add__", &add22T<T>)
604 .def("__radd__", &add22T<T>)
605 .def("__sub__", &subtractTL22<T>)
606 .def("__rsub__", &subtractTR22<T>)
607 .def("__mul__", &mul22<float, T>)
608 .def("__mul__", &mul22<double, T>)
609 .def("__rmul__", &rmul22<float, T>)
610 .def("__rmul__", &rmul22<double, T>)
611 .def("__imul__", &imul22<float, T>,return_internal_reference<>())
612 .def("__imul__", &imul22<double, T>,return_internal_reference<>())
613 .def("__lt__", &lessThan22<T>)
614 .def("__le__", &lessThanEqual22<T>)
615 .def("__gt__", &greaterThan22<T>)
616 .def("__ge__", &greaterThanEqual22<T>)
617 //.def(self_ns::str(self))
618 .def("__str__",&Matrix22_str<T>)
619 .def("__repr__",&Matrix22_repr<T>)
620
621 .def("extractEuler", &extractEuler<T>,
622 "M.extractEuler(r) -- extracts the "
623 "rotation component of M into r. "
624 "Assumes that M contains no shear or "
625 "non-uniform scaling; results are "
626 "meaningless if it does.")
627
628 .def("multDirMatrix", &multDirMatrix22<double,T>, "mult matrix")
629 .def("multDirMatrix", &multDirMatrix22_return_value<double,T>, "mult matrix")
630 .def("multDirMatrix", &multDirMatrix22_array<double,T>, "mult matrix")
631 .def("multDirMatrix", &multDirMatrix22<float,T>, "mult matrix")
632 .def("multDirMatrix", &multDirMatrix22_return_value<float,T>, "mult matrix")
633 .def("multDirMatrix", &multDirMatrix22_array<float,T>, "mult matrix")
634
635 .def("rotate", &rotate22<T>, return_internal_reference<>(),"rotate matrix")
636
637 .def("scale", &scaleSc22<T>, return_internal_reference<>(),"scale matrix")
638 .def("scale", &scaleV22<T>, return_internal_reference<>(),"scale matrix")
639 .def("scale", &scale22Tuple<T>, return_internal_reference<>(),"scale matrix")
640
641 .def("setRotation", &setRotation22<T>, return_internal_reference<>(),"setRotation()")
642 .def("setScale", &setScaleSc22<T>, return_internal_reference<>(),"setScale()")
643 .def("setScale", &setScaleV22<T>, return_internal_reference<>(),"setScale()")
644 .def("setScale", &setScale22Tuple<T>, return_internal_reference<>(),"setScale()")
645
646 .def("setValue", &setValue22<T>, "setValue()")
647 ;
648
649 decoratecopy(matrix22_class);
650
651 return matrix22_class;
652 /*
653 const Matrix22 & operator = (const Matrix22 &v);
654 const Matrix22 & operator = (T a);
655 T * getValue ();
656 const T * getValue () const;
657 template <class S> void getValue (Matrix22<S> &v) const;
658 template <class S> Matrix22 & setValue (const Matrix22<S> &v);
659 template <class S> Matrix22 & setTheMatrix (const Matrix22<S> &v);
660 template <class S> void multVecMatrix(const Vec2<S> &src, Vec2<S> &dst) const;
661 template <class S> void multDirMatrix(const Vec2<S> &src, Vec2<S> &dst) const;
662 template <class S> const Matrix22 & setRotation (S r);
663 template <class S> const Matrix22 & rotate (S r);
664 const Matrix22 & setScale (T s);
665 template <class S> const Matrix22 & setScale (const Vec2<S> &s);
666 template <class S> const Matrix22 & scale (const Vec2<S> &s);
667 template <class S> const Matrix22 & setTranslation (const Vec2<S> &t);
668 Vec2<T> translation () const;
669 template <class S> const Matrix22 & translate (const Vec2<S> &t);
670 template <class S> const Matrix22 & setShear (const S &h);
671 template <class S> const Matrix22 & setShear (const Vec2<S> &h);
672 template <class S> const Matrix22 & shear (const S &xy);
673 template <class S> const Matrix22 & shear (const Vec2<S> &h);
674 */
675 }
676
677 template <class T>
678 static void
679 setM22ArrayItem(FixedArray<IMATH_NAMESPACE::Matrix22<T> > &ma,
680 Py_ssize_t index,
681 const IMATH_NAMESPACE::Matrix22<T> &m)
682 {
683 ma[ma.canonical_index(index)] = m;
684 }
685
686 template <class T>
687 static FixedArray<IMATH_NAMESPACE::Matrix22<T> >
688 inverse22_array(FixedArray<IMATH_NAMESPACE::Matrix22<T> >&ma, bool singExc = true)
689 {
690 MATH_EXC_ON;
691 size_t len = ma.len();
692 FixedArray<IMATH_NAMESPACE::Matrix22<T> > dst(len);
693 for (size_t i=0; i<len; ++i) dst[i] = ma[i].inverse(singExc);
694 return dst;
695 }
696
697 template <class T>
698 static FixedArray<IMATH_NAMESPACE::Matrix22<T> > &
699 invert22_array(FixedArray<IMATH_NAMESPACE::Matrix22<T> >&ma, bool singExc = true)
700 {
701 MATH_EXC_ON;
702 size_t len = ma.len();
703 for (size_t i=0; i<len; ++i) ma[i].invert(singExc);
704 return ma;
705 }
706
707 BOOST_PYTHON_FUNCTION_OVERLOADS(invert22_array_overloads, invert22_array, 1, 2);
708 BOOST_PYTHON_FUNCTION_OVERLOADS(inverse22_array_overloads, inverse22_array, 1, 2);
709
710 template <class T>
711 class_<FixedArray<IMATH_NAMESPACE::Matrix22<T> > >
712 register_M22Array()
713 {
714 class_<FixedArray<IMATH_NAMESPACE::Matrix22<T> > > matrixArray_class = FixedArray<IMATH_NAMESPACE::Matrix22<T> >::register_("Fixed length array of IMATH_NAMESPACE::Matrix22");
715 matrixArray_class
716 .def("__setitem__", &setM22ArrayItem<T>)
717 .def("inverse",&inverse22_array<T>,inverse22_array_overloads("inverse() return an inverted copy of this matrix"))
718 .def("invert",&invert22_array<T>,invert22_array_overloads("invert() invert these matricies")[return_internal_reference<>()])
719 ;
720
721 add_comparison_functions(matrixArray_class);
722
723 return matrixArray_class;
724 }
725
726 template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix22<float> > register_Matrix22<float>();
727 template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix22<double> > register_Matrix22<double>();
728
729 template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix22<float> > > register_M22Array<float>();
730 template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix22<double> > > register_M22Array<double>();
731
732
733 template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix22<float> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix22<float> >::value() { return IMATH_NAMESPACE::Matrix22<float>(); }
734 template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix22<double> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix22<double> >::value() { return IMATH_NAMESPACE::Matrix22<double>(); }
735 }