8 #ifndef _PyImathFixedArray2D_h_
9 #define _PyImathFixedArray2D_h_
11 #define HBOOST_BIND_GLOBAL_PLACEHOLDERS
12 #include <hboost/python.hpp>
13 #include <hboost/operators.hpp>
14 #include <hboost/shared_array.hpp>
15 #include <hboost/any.hpp>
27 IMATH_NAMESPACE::Vec2<size_t> _length;
28 IMATH_NAMESPACE::Vec2<size_t> _stride;
37 FixedArray2D(T *
ptr, Py_ssize_t lengthX, Py_ssize_t lengthY, Py_ssize_t strideX = 1)
38 : _ptr(ptr), _length(lengthX, lengthY), _stride(strideX, lengthX), _handle()
40 if (lengthX < 0 || lengthY < 0)
41 throw std::domain_error(
"Fixed array 2d lengths must be non-negative");
43 throw std::domain_error(
"Fixed array 2d strides must be positive");
49 FixedArray2D(T *
ptr, Py_ssize_t lengthX, Py_ssize_t lengthY, Py_ssize_t strideX, Py_ssize_t strideY)
50 : _ptr(ptr), _length(lengthX, lengthY), _stride(strideX, strideY), _handle()
52 if (lengthX < 0 || lengthY < 0)
53 throw std::domain_error(
"Fixed array 2d lengths must be non-negative");
54 if (strideX <= 0 || strideY < 0)
55 throw std::domain_error(
"Fixed array 2d strides must be positive");
62 : _ptr(ptr), _length(lengthX, lengthY), _stride(strideX, strideY), _handle(handle)
70 : _ptr(0), _length(lengthX, lengthY), _stride(1, lengthX), _handle()
72 if (lengthX < 0 || lengthY < 0)
73 throw std::domain_error(
"Fixed array 2d lengths must be non-negative");
76 hboost::shared_array<T>
a(
new T[_size]);
77 for (
size_t i=0; i<_size; ++i) a[i] = tmp;
83 : _ptr(0), _length(length), _stride(1, length.
x), _handle()
85 if (length.x < 0 || length.y < 0)
86 throw std::domain_error(
"Fixed array 2d lengths must be non-negative");
89 hboost::shared_array<T>
a(
new T[_size]);
90 for (
size_t i=0; i<_size; ++i) a[i] = tmp;
95 FixedArray2D(
const T &initialValue, Py_ssize_t lengthX, Py_ssize_t lengthY)
96 : _ptr(0), _length(lengthX, lengthY), _stride(1, lengthX), _handle()
98 if (lengthX < 0 || lengthY < 0)
99 throw std::domain_error(
"Fixed array 2d lengths must be non-negative");
101 hboost::shared_array<T>
a(
new T[_size]);
102 for (
size_t i=0; i<_size; ++i) a[i] = initialValue;
108 _size = _length.x*_length.y;
113 : _ptr(0), _length(other.
len()), _stride(1, other.
len().
x), _handle()
116 hboost::shared_array<T>
a(
new T[_size]);
118 for (
size_t j = 0;
j < _length.y; ++
j)
119 for (
size_t i = 0; i < _length.x; ++i)
120 a[z++] =
T(other(i,
j));
126 : _ptr(other._ptr), _length(other._length), _stride(other._stride), _size(other._size), _handle(other._handle)
135 if (&other ==
this)
return *
this;
140 _length = other._length;
141 _stride = other._stride;
142 _handle = other._handle;
144 _size = _length.x*_length.y;
158 if (index < 0) index +=
length;
159 if ((
size_t) index >= length || index < 0) {
160 PyErr_SetString(PyExc_IndexError,
"Index out of range");
161 hboost::python::throw_error_already_set();
168 if (PySlice_Check(index)) {
169 #if PY_MAJOR_VERSION > 2
170 PyObject *slice = index;
172 PySliceObject *slice =
reinterpret_cast<PySliceObject *
>(index);
175 if (PySlice_GetIndicesEx(slice,length,&s,&e,&step,&sl) == -1) {
176 hboost::python::throw_error_already_set();
178 if (s < 0 || e < 0 || sl < 0) {
179 throw std::domain_error(
"Slice extraction produced invalid start, end, or length indices");
184 }
else if (PyInt_Check(index)) {
186 start = i; end = i+1; step = 1; slicelength = 1;
188 PyErr_SetString(PyExc_TypeError,
"Object is not a slice");
189 hboost::python::throw_error_already_set();
206 if (PyTuple_Check(index) && PyTuple_Size(index) == 2)
208 size_t startx=0, endx=0, slicelengthx=0;
209 size_t starty=0, endy=0, slicelengthy=0;
215 for (
size_t j=0,
z=0;
j<slicelengthy;
j++)
216 for (
size_t i=0; i<slicelengthx; ++i)
217 f._ptr[
z++] = (*
this)(startx+i*stepx, starty+
j*stepy);
222 PyErr_SetString(PyExc_TypeError,
"Slice syntax error");
223 hboost::python::throw_error_already_set();
244 for (
size_t j=0;
j<len.y;
j++)
245 for (
size_t i=0; i<len.x; i++)
247 f(i,
j) = (*this)(i,
j);
260 if (!PyTuple_Check(index) || PyTuple_Size(index) != 2)
262 PyErr_SetString(PyExc_TypeError,
"Slice syntax error");
263 hboost::python::throw_error_already_set();
266 size_t startx=0, endx=0, slicelengthx=0;
267 size_t starty=0, endy=0, slicelengthy=0;
272 for (
size_t j=0;
j<slicelengthy;
j++)
273 for (
size_t i=0; i<slicelengthx; ++i)
274 (*
this)(startx+i*stepx, starty+
j*stepy) = data;
281 for (
size_t j = 0;
j < len.y;
j++)
282 for (
size_t i=0; i<len.x; ++i)
291 size_t startx=0, endx=0, slicelengthx=0;
292 size_t starty=0, endy=0, slicelengthy=0;
298 if (data.
len() != IMATH_NAMESPACE::Vec2<size_t>(slicelengthx, slicelengthy)) {
299 PyErr_SetString(PyExc_IndexError,
"Dimensions of source do not match destination");
300 hboost::python::throw_error_already_set();
302 for (
size_t i=0; i<slicelengthx; ++i)
303 for (
size_t j=0;
j<slicelengthy; ++
j)
304 (*
this)(startx+i*stepx, starty+
j*stepy) =
data(i,
j);
312 for (
size_t j = 0;
j < len.y;
j++)
313 for (
size_t i=0; i<len.x; ++i)
317 PyErr_SetString(PyExc_IndexError,
"Dimensions of source data do not match destination");
318 hboost::python::throw_error_already_set();
326 if ((
size_t) data.
len() == len.x*len.y) {
327 for (
size_t j = 0,
z = 0;
j < len.y;
j++)
328 for (
size_t i=0; i<len.x; ++i, ++
z)
330 (*
this)(i,
j) = data[
z];
333 for (
size_t j = 0,
z = 0;
j < len.y;
j++)
334 for (
size_t i=0; i<len.x; ++i, ++
z)
335 if (
mask(i,
j)) count++;
337 if ((
size_t) data.
len() != count) {
338 PyErr_SetString(PyExc_IndexError,
"Dimensions of source data do not match destination either masked or unmasked");
339 hboost::python::throw_error_already_set();
342 for (
size_t j = 0,
z = 0;
j < len.y;
j++)
343 for (
size_t i=0; i<len.x; ++i)
345 (*this)(i,
j) = data[
z++];
353 size_t startx=0, endx=0, slicelengthx=0;
354 size_t starty=0, endy=0, slicelengthy=0;
360 if ((
size_t) data.
len() != slicelengthx*slicelengthy) {
361 PyErr_SetString(PyExc_IndexError,
"Dimensions of source data do not match destination");
362 hboost::python::throw_error_already_set();
364 for (
size_t j=0,
z=0;
j<slicelengthy; ++
j)
365 for (
size_t i=0; i<slicelengthx; ++i, ++
z)
366 (*
this)(startx+i*stepx, starty+
j*stepy) = data[
z];
369 IMATH_NAMESPACE::Vec2<size_t>
len()
const {
return _length; }
370 IMATH_NAMESPACE::Vec2<size_t>
stride()
const {
return _stride; }
371 T &
operator () (
size_t i,
size_t j) {
return _ptr[_stride.x*(j*_stride.y + i)]; }
372 const T &
operator () (
size_t i,
size_t j)
const {
return _ptr[_stride.x*(j*_stride.y + i)]; }
374 hboost::python::tuple
size()
const
376 return hboost::python::make_tuple(_length.x, _length.y);
379 static hboost::python::class_<FixedArray2D<T> >
register_(
const char *
name,
const char *doc)
384 typedef typename hboost::mpl::if_<
386 hboost::python::return_internal_reference<>,
387 hboost::python::default_call_policies>
::type call_policy;
389 hboost::python::class_<FixedArray2D<T> >
c(name,doc, hboost::python::init<size_t, size_t>(
390 "construct an array of the specified length initialized to the default value for the type"));
392 .def(hboost::python::init<
const FixedArray2D<T> &>(
"construct an array with the same values as the given array"))
393 .def(hboost::python::init<const T &,size_t,size_t>(
"construct an array of the specified length initialized to the specified default value"))
427 PyErr_SetString(PyExc_IndexError,
"Dimensions of source do not match destination");
428 hboost::python::throw_error_already_set();
437 for (
size_t j = 0;
j < len.y; ++
j)
438 for (
size_t i = 0; i < len.x; ++i)
439 tmp(i,
j) = choice(i,
j) ? (*this)(i,
j) : other(i,
j);
446 for (
size_t j = 0;
j < len.y; ++
j)
447 for (
size_t i = 0; i < len.x; ++i)
448 tmp(i,
j) = choice(i,
j) ? (*this)(i,
j) : other;
455 template <
template <
class,
class>
class Op,
class T1,
class Ret>
458 IMATH_NAMESPACE::Vec2<size_t> len = a1.
len();
460 for (
size_t j=0;
j<len.y; ++
j) {
461 for (
size_t i=0;i<len.x;++i) {
462 retval(i,
j) = Op<T1,Ret>::apply(a1(i,
j));
469 template <
template <
class,
class,
class>
class Op,
class T1,
class T2,
class Ret>
474 for (
size_t j=0;
j<len.y; ++
j) {
475 for (
size_t i=0;i<len.x;++i) {
476 retval(i,
j) = Op<T1,T2,Ret>::apply(a1(i,
j),a2(i,
j));
482 template <
template <
class,
class,
class>
class Op,
class T1,
class T2,
class Ret>
485 IMATH_NAMESPACE::Vec2<size_t> len = a1.
len();
487 for (
size_t j=0;
j<len.y; ++
j) {
488 for (
size_t i=0;i<len.x;++i) {
489 retval(i,
j) = Op<T1,T2,Ret>::apply(a1(i,
j),a2);
495 template <
template <
class,
class,
class>
class Op,
class T1,
class T2,
class Ret>
498 IMATH_NAMESPACE::Vec2<size_t> len = a1.
len();
500 for (
size_t j=0;
j<len.y; ++
j) {
501 for (
size_t i=0;i<len.x;++i) {
502 retval(i,
j) = Op<T2,T1,Ret>::apply(a2,a1(i,
j));
509 template <
template <
class,
class>
class Op,
class T1,
class T2>
513 for (
size_t j=0;
j<len.y; ++
j) {
514 for (
size_t i=0;i<len.x;++i) {
515 Op<T1,T2>::apply(a1(i,
j),a2(i,
j));
522 template <
template <
class,
class>
class Op,
class T1,
class T2>
525 IMATH_NAMESPACE::Vec2<size_t> len = a1.
len();
526 for (
size_t j=0;
j<len.y; ++
j) {
527 for (
size_t i=0;i<len.x;++i) {
528 Op<T1,T2>::apply(a1(i,
j),a2);
536 template <
class T>
static FixedArray2D<T> operator + (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_add,T,T,T>(a0,a1); }
537 template <
class T>
static FixedArray2D<T> operator + (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_add,T,T,T>(a0,
v1); }
538 template <
class T>
static FixedArray2D<T> operator + (
const T &
v1,
const FixedArray2D<T> &a0) {
return a0+
v1; }
541 template <
class T>
static FixedArray2D<T> operator - (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_sub,T,T,T>(a0,a1); }
542 template <
class T>
static FixedArray2D<T> operator - (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_sub,T,T,T>(a0,
v1); }
543 template <
class T>
static FixedArray2D<T> operator - (
const T &
v1,
const FixedArray2D<T> &a0) {
return apply_array2d_scalar_binary_op<op_rsub,T,T,T>(a0,
v1); }
546 template <
class T>
static FixedArray2D<T> operator * (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_mul,T,T,T>(a0,a1); }
547 template <
class T>
static FixedArray2D<T> operator * (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_mul,T,T,T>(a0,
v1); }
548 template <
class T>
static FixedArray2D<T> operator * (
const T &
v1,
const FixedArray2D<T> &a0) {
return a0*
v1; }
551 template <
class T>
static FixedArray2D<T> operator / (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_div,T,T,T>(a0,a1); }
552 template <
class T>
static FixedArray2D<T> operator / (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_div,T,T,T>(a0,
v1); }
558 template <
class T>
static FixedArray2D<T> operator % (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_mod,T,T,T>(a0,a1); }
559 template <
class T>
static FixedArray2D<T> operator % (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_mod,T,T,T>(a0,
v1); }
565 template <
class T>
static FixedArray2D<T> pow_array2d_array2d (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_pow,T,T,T>(a0,a1); }
566 template <
class T>
static FixedArray2D<T> pow_array2d_scalar (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_pow,T,T,T>(a0,
v1); }
570 template <
class T>
static FixedArray2D<T> operator - (
const FixedArray2D<T> &a0) {
return apply_array2d_unary_op<op_neg,T,T>(a0); }
575 template <
class T>
static FixedArray2D<T>
abs (
const FixedArray2D<T> &a0) {
return apply_array2d_unary_op<op_abs,T,T>(a0); }
578 template <
class T>
static FixedArray2D<T> operator ~ (
const FixedArray2D<T> &a0) {
return apply_array2d_unary_op<op_inverse,T,T>(a0); }
581 template <
class T>
static FixedArray2D<T> operator << (const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_lshift,T,T,T>(a0,a1); }
582 template <
class T>
static FixedArray2D<T> operator << (const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_lshift,T,T,T>(a0,
v1); }
586 template <
class T>
static FixedArray2D<T> operator >> (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_rshift,T,T,T>(a0,a1); }
587 template <
class T>
static FixedArray2D<T> operator >> (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_rshift,T,T,T>(a0,
v1); }
591 template <
class T>
static FixedArray2D<T> operator & (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_bitand,T,T,T>(a0,a1); }
592 template <
class T>
static FixedArray2D<T> operator & (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_bitand,T,T,T>(a0,
v1); }
593 template <
class T>
static FixedArray2D<T> operator & (
const T &
v1,
const FixedArray2D<T> &a0) {
return a0&
v1; }
596 template <
class T>
static FixedArray2D<T> operator ^ (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_xor,T,T,T>(a0,a1); }
597 template <
class T>
static FixedArray2D<T> operator ^ (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_xor,T,T,T>(a0,
v1); }
598 template <
class T>
static FixedArray2D<T> operator ^ (
const T &
v1,
const FixedArray2D<T> &a0) {
return a0^
v1; }
601 template <
class T>
static FixedArray2D<T> operator | (
const FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_binary_op<op_bitor,T,T,T>(a0,a1); }
602 template <
class T>
static FixedArray2D<T> operator | (
const FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_binary_op<op_bitor,T,T,T>(a0,
v1); }
603 template <
class T>
static FixedArray2D<T> operator | (
const T &
v1,
const FixedArray2D<T> &a0) {
return a0|
v1; }
607 template <
class T>
static FixedArray2D<T> & operator += (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_iadd,T,T>(a0,a1); }
608 template <
class T>
static FixedArray2D<T> & operator += (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_iadd,T,T>(a0,
v1); }
611 template <
class T>
static FixedArray2D<T> & operator -= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_isub,T,T>(a0,a1); }
612 template <
class T>
static FixedArray2D<T> & operator -= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_isub,T,T>(a0,
v1); }
615 template <
class T>
static FixedArray2D<T> & operator *= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_imul,T,T>(a0,a1); }
616 template <
class T>
static FixedArray2D<T> & operator *= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_imul,T,T>(a0,
v1); }
619 template <
class T>
static FixedArray2D<T> & operator /= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_idiv,T,T>(a0,a1); }
620 template <
class T>
static FixedArray2D<T> & operator /= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_idiv,T,T>(a0,
v1); }
629 template <
class T>
static FixedArray2D<T> & operator %= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_imod,T,T>(a0,a1); }
630 template <
class T>
static FixedArray2D<T> & operator %= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_imod,T,T>(a0,
v1); }
633 template <
class T>
static FixedArray2D<T> & ipow_array2d_array2d (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_ipow,T,T>(a0,a1); }
634 template <
class T>
static FixedArray2D<T> & ipow_array2d_scalar (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_ipow,T,T>(a0,
v1); }
637 template <
class T>
static FixedArray2D<T> & operator <<= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_ilshift,T,T>(a0,a1); }
638 template <
class T>
static FixedArray2D<T> & operator <<= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_ilshift,T,T>(a0,
v1); }
641 template <
class T>
static FixedArray2D<T> & operator >>= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_irshift,T,T>(a0,a1); }
642 template <
class T>
static FixedArray2D<T> & operator >>= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_irshift,T,T>(a0,
v1); }
645 template <
class T>
static FixedArray2D<T> & operator &= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_ibitand,T,T>(a0,a1); }
646 template <
class T>
static FixedArray2D<T> & operator &= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_ibitand,T,T>(a0,
v1); }
649 template <
class T>
static FixedArray2D<T> & operator ^= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_ixor,T,T>(a0,a1); }
650 template <
class T>
static FixedArray2D<T> & operator ^= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_ixor,T,T>(a0,
v1); }
653 template <
class T>
static FixedArray2D<T> & operator |= (FixedArray2D<T> &a0,
const FixedArray2D<T> &a1) {
return apply_array2d_array2d_ibinary_op<op_ibitor,T,T>(a0,a1); }
654 template <
class T>
static FixedArray2D<T> & operator |= (FixedArray2D<T> &a0,
const T &
v1) {
return apply_array2d_scalar_ibinary_op<op_ibitor,T,T>(a0,
v1); }
657 static void add_arithmetic_math_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
658 using namespace hboost::python;
660 .def(
"__add__",&apply_array2d_array2d_binary_op<op_add,T,T,T>)
661 .def(
"__add__",&apply_array2d_scalar_binary_op<op_add,T,T,T>)
662 .def(
"__radd__",&apply_array2d_scalar_binary_rop<op_add,T,T,T>)
663 .def(
"__sub__",&apply_array2d_array2d_binary_op<op_sub,T,T,T>)
664 .def(
"__sub__",&apply_array2d_scalar_binary_op<op_sub,T,T,T>)
665 .def(
"__rsub__",&apply_array2d_scalar_binary_op<op_rsub,T,T,T>)
666 .def(
"__mul__",&apply_array2d_array2d_binary_op<op_mul,T,T,T>)
667 .def(
"__mul__",&apply_array2d_scalar_binary_op<op_mul,T,T,T>)
668 .def(
"__rmul__",&apply_array2d_scalar_binary_rop<op_mul,T,T,T>)
669 .def(
"__div__",&apply_array2d_array2d_binary_op<op_div,T,T,T>)
670 .def(
"__div__",&apply_array2d_scalar_binary_op<op_div,T,T,T>)
671 .def(
"__truediv__",&apply_array2d_array2d_binary_op<op_div,T,T,T>)
672 .def(
"__truediv__",&apply_array2d_scalar_binary_op<op_div,T,T,T>)
673 .def(
"__neg__",&apply_array2d_unary_op<op_neg,T,T>)
674 .def(
"__iadd__",&apply_array2d_array2d_ibinary_op<op_iadd,T,T>,return_internal_reference<>())
675 .def(
"__iadd__",&apply_array2d_scalar_ibinary_op<op_iadd,T,T>,return_internal_reference<>())
676 .def(
"__isub__",&apply_array2d_array2d_ibinary_op<op_isub,T,T>,return_internal_reference<>())
677 .def(
"__isub__",&apply_array2d_scalar_ibinary_op<op_isub,T,T>,return_internal_reference<>())
678 .def(
"__imul__",&apply_array2d_array2d_ibinary_op<op_imul,T,T>,return_internal_reference<>())
679 .def(
"__imul__",&apply_array2d_scalar_ibinary_op<op_imul,T,T>,return_internal_reference<>())
680 .def(
"__idiv__",&apply_array2d_array2d_ibinary_op<op_idiv,T,T>,return_internal_reference<>())
681 .def(
"__idiv__",&apply_array2d_scalar_ibinary_op<op_idiv,T,T>,return_internal_reference<>())
682 .def(
"__itruediv__",&apply_array2d_array2d_ibinary_op<op_idiv,T,T>,return_internal_reference<>())
683 .def(
"__itruediv__",&apply_array2d_scalar_ibinary_op<op_idiv,T,T>,return_internal_reference<>())
689 static void add_pow_math_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
690 using namespace hboost::python;
692 .def(
"__pow__",&apply_array2d_array2d_binary_op<op_pow,T,T,T>)
693 .def(
"__pow__",&apply_array2d_scalar_binary_op<op_pow,T,T,T>)
694 .def(
"__rpow__",&apply_array2d_scalar_binary_rop<op_rpow,T,T,T>)
695 .def(
"__ipow__",&apply_array2d_array2d_ibinary_op<op_ipow,T,T>,return_internal_reference<>())
696 .def(
"__ipow__",&apply_array2d_scalar_ibinary_op<op_ipow,T,T>,return_internal_reference<>())
701 static void add_mod_math_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
702 using namespace hboost::python;
704 .def(
"__mod__",&apply_array2d_array2d_binary_op<op_mod,T,T,T>)
705 .def(
"__mod__",&apply_array2d_scalar_binary_op<op_mod,T,T,T>)
706 .def(
"__imod__",&apply_array2d_array2d_ibinary_op<op_imod,T,T>,return_internal_reference<>())
707 .def(
"__imod__",&apply_array2d_scalar_ibinary_op<op_imod,T,T>,return_internal_reference<>())
712 static void add_shift_math_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
713 using namespace hboost::python;
715 .def(
"__lshift__",&apply_array2d_array2d_binary_op<op_lshift,T,T,T>)
716 .def(
"__lshift__",&apply_array2d_scalar_binary_op<op_lshift,T,T,T>)
717 .def(
"__ilshift__",&apply_array2d_array2d_ibinary_op<op_ilshift,T,T>,return_internal_reference<>())
718 .def(
"__ilshift__",&apply_array2d_scalar_ibinary_op<op_ilshift,T,T>,return_internal_reference<>())
719 .def(
"__rshift__",&apply_array2d_array2d_binary_op<op_rshift,T,T,T>)
720 .def(
"__rshift__",&apply_array2d_scalar_binary_op<op_rshift,T,T,T>)
721 .def(
"__irshift__",&apply_array2d_array2d_ibinary_op<op_irshift,T,T>,return_internal_reference<>())
722 .def(
"__irshift__",&apply_array2d_scalar_ibinary_op<op_irshift,T,T>,return_internal_reference<>())
727 static void add_bitwise_math_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
728 using namespace hboost::python;
730 .def(
"__and__",&apply_array2d_array2d_binary_op<op_bitand,T,T,T>)
731 .def(
"__and__",&apply_array2d_scalar_binary_op<op_bitand,T,T,T>)
732 .def(
"__iand__",&apply_array2d_array2d_ibinary_op<op_ibitand,T,T>,return_internal_reference<>())
733 .def(
"__iand__",&apply_array2d_scalar_ibinary_op<op_ibitand,T,T>,return_internal_reference<>())
734 .def(
"__or__",&apply_array2d_array2d_binary_op<op_bitor,T,T,T>)
735 .def(
"__or__",&apply_array2d_scalar_binary_op<op_bitor,T,T,T>)
736 .def(
"__ior__",&apply_array2d_array2d_ibinary_op<op_ibitor,T,T>,return_internal_reference<>())
737 .def(
"__ior__",&apply_array2d_scalar_ibinary_op<op_ibitor,T,T>,return_internal_reference<>())
738 .def(
"__xor__",&apply_array2d_array2d_binary_op<op_xor,T,T,T>)
739 .def(
"__xor__",&apply_array2d_scalar_binary_op<op_xor,T,T,T>)
740 .def(
"__ixor__",&apply_array2d_array2d_ibinary_op<op_ixor,T,T>,return_internal_reference<>())
741 .def(
"__ixor__",&apply_array2d_scalar_ibinary_op<op_ixor,T,T>,return_internal_reference<>())
746 static void add_comparison_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
747 using namespace hboost::python;
749 .def(
"__eq__",&apply_array2d_array2d_binary_op<op_eq,T,T,int>)
750 .def(
"__eq__",&apply_array2d_scalar_binary_op<op_eq,T,T,int>)
751 .def(
"__ne__",&apply_array2d_array2d_binary_op<op_ne,T,T,int>)
752 .def(
"__ne__",&apply_array2d_scalar_binary_op<op_ne,T,T,int>)
757 static void add_ordered_comparison_functions(hboost::python::class_<FixedArray2D<T> > &
c) {
758 using namespace hboost::python;
760 .def(
"__lt__",&apply_array2d_array2d_binary_op<op_lt,T,T,int>)
761 .def(
"__lt__",&apply_array2d_scalar_binary_op<op_lt,T,T,int>)
762 .def(
"__gt__",&apply_array2d_array2d_binary_op<op_gt,T,T,int>)
763 .def(
"__gt__",&apply_array2d_scalar_binary_op<op_gt,T,T,int>)
764 .def(
"__le__",&apply_array2d_array2d_binary_op<op_le,T,T,int>)
765 .def(
"__le__",&apply_array2d_scalar_binary_op<op_le,T,T,int>)
766 .def(
"__ge__",&apply_array2d_array2d_binary_op<op_ge,T,T,int>)
767 .def(
"__ge__",&apply_array2d_scalar_binary_op<op_ge,T,T,int>)
771 template <
class S,
class T>
772 static void add_explicit_construction_from_type(hboost::python::class_<FixedArray2D<T> > &
c) {
773 using namespace hboost::python;
774 c.def(hboost::python::init<FixedArray2D<S> >(
"copy contents of other array into this one"));
const FixedArray2D & operator=(const FixedArray2D &other)
const hboost::any & handle()
FixedArray2D(T *ptr, Py_ssize_t lengthX, Py_ssize_t lengthY, Py_ssize_t strideX, Py_ssize_t strideY, hboost::any handle)
FixedArray2D(T *ptr, Py_ssize_t lengthX, Py_ssize_t lengthY, Py_ssize_t strideX=1)
GLdouble GLdouble GLdouble z
Vec2< int > V2i
Vec2 of integer.
GLboolean GLboolean GLboolean GLboolean a
GLuint GLsizei GLsizei * length
FixedArray2D< Ret > apply_array2d_scalar_binary_rop(const FixedArray2D< T1 > &a1, const T2 &a2)
void setitem_array1d_mask(const FixedArray2D< int > &mask, const FixedArray< T > &data)
FixedArray2D(const FixedArray2D< S > &other)
FixedArray2D(T *ptr, Py_ssize_t lengthX, Py_ssize_t lengthY, Py_ssize_t strideX, Py_ssize_t strideY)
FixedArray2D(const T &initialValue, Py_ssize_t lengthX, Py_ssize_t lengthY)
FixedArray2D< Ret > apply_array2d_scalar_binary_op(const FixedArray2D< T1 > &a1, const T2 &a2)
GLint GLint GLsizei GLint GLenum GLenum type
T & operator()(size_t i, size_t j)
FixedArray2D< Ret > apply_array2d_array2d_binary_op(const FixedArray2D< T1 > &a1, const FixedArray2D< T2 > &a2)
bool any(const vbool4 &v)
FixedArray2D< T1 > & apply_array2d_scalar_ibinary_op(FixedArray2D< T1 > &a1, const T2 &a2)
FixedArray2D getslice_mask(const FixedArray2D< int > &mask) const
void setitem_scalar_mask(const FixedArray2D< int > &mask, const T &data)
hboost::python::tuple size() const
GLuint const GLchar * name
static hboost::python::class_< FixedArray2D< T > > register_(const char *name, const char *doc)
size_t canonical_index(Py_ssize_t index, size_t length) const
hboost::mpl::if_< hboost::is_class< T >, T &, T >::type get_type
FixedArray2D< T1 > & apply_array2d_array2d_ibinary_op(FixedArray2D< T1 > &a1, const FixedArray2D< T2 > &a2)
void setitem_scalar(PyObject *index, const T &data)
FixedArray2D< T > ifelse_vector(const FixedArray2D< int > &choice, const FixedArray2D< T > &other)
FixedArray2D(const IMATH_NAMESPACE::V2i &length)
IMATH_NAMESPACE::Vec2< size_t > stride() const
IMATH_NAMESPACE::Vec2< size_t > match_dimension(const FixedArray2D< T2 > &a1) const
get_type getitem(Py_ssize_t i, Py_ssize_t j)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
void extract_slice_indices(PyObject *index, size_t length, size_t &start, size_t &end, Py_ssize_t &step, size_t &slicelength) const
FixedArray2D(Py_ssize_t lengthX, Py_ssize_t lengthY)
void setitem_array1d(PyObject *index, const FixedArray< T > &data)
IMATH_NAMESPACE::Vec2< size_t > len() const
FixedArray2D< Ret > apply_array2d_unary_op(const FixedArray2D< T1 > &a1)
FixedArray2D(const FixedArray2D &other)
void setitem_vector(PyObject *index, const FixedArray2D &data)
void setitem_vector_mask(const FixedArray2D< int > &mask, const FixedArray2D &data)
FixedArray2D< T > ifelse_scalar(const FixedArray2D< int > &choice, const T &other)
FixedArray2D getslice(PyObject *index) const