wrapArray.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_VT_WRAP_ARRAY_H
25 #define PXR_BASE_VT_WRAP_ARRAY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/vt/api.h"
29 #include "pxr/base/vt/array.h"
30 #include "pxr/base/vt/types.h"
31 #include "pxr/base/vt/value.h"
32 #include "pxr/base/vt/pyOperators.h"
33 #include "pxr/base/vt/functions.h"
34 
35 #include "pxr/base/arch/math.h"
36 #include "pxr/base/arch/inttypes.h"
37 #include "pxr/base/arch/pragmas.h"
38 #include "pxr/base/gf/half.h"
40 #include "pxr/base/tf/pyFunction.h"
41 #include "pxr/base/tf/pyLock.h"
42 #include "pxr/base/tf/pyObjWrapper.h"
43 #include "pxr/base/tf/pyResultConversions.h"
44 #include "pxr/base/tf/pyUtils.h"
45 #include "pxr/base/tf/iterator.h"
46 #include "pxr/base/tf/span.h"
48 #include "pxr/base/tf/tf.h"
49 #include "pxr/base/tf/wrapTypeHelpers.h"
50 
51 #include <boost/preprocessor/facilities/empty.hpp>
52 #include <boost/preprocessor/punctuation/comma_if.hpp>
53 #include <boost/preprocessor/repetition/repeat.hpp>
54 #include <boost/preprocessor/seq/for_each.hpp>
55 
56 #include <boost/python/class.hpp>
57 #include <boost/python/copy_const_reference.hpp>
58 #include <boost/python/def.hpp>
59 #include <boost/python/detail/api_placeholder.hpp>
60 #include <boost/python/extract.hpp>
61 #include <boost/python/implicit.hpp>
62 #include <boost/python/iterator.hpp>
63 #include <boost/python/make_constructor.hpp>
64 #include <boost/python/object.hpp>
65 #include <boost/python/operators.hpp>
66 #include <boost/python/return_arg.hpp>
67 #include <boost/python/slice.hpp>
68 #include <boost/python/type_id.hpp>
69 #include <boost/python/overloads.hpp>
70 
71 #include <algorithm>
72 #include <numeric>
73 #include <ostream>
74 #include <string>
75 #include <memory>
76 #include <vector>
77 
78 PXR_NAMESPACE_OPEN_SCOPE
79 
80 namespace Vt_WrapArray {
81 
82 using namespace boost::python;
83 
84 using std::unique_ptr;
85 using std::vector;
86 using std::string;
87 
88 template <typename T>
89 object
90 getitem_ellipsis(VtArray<T> const &self, object idx)
91 {
92  object ellipsis = object(handle<>(borrowed(Py_Ellipsis)));
93  if (idx != ellipsis) {
94  PyErr_SetString(PyExc_TypeError, "unsupported index type");
95  throw_error_already_set();
96  }
97  return object(self);
98 }
99 
100 template <typename T>
101 object
102 getitem_index(VtArray<T> const &self, int64_t idx)
103 {
104  static const bool throwError = true;
105  idx = TfPyNormalizeIndex(idx, self.size(), throwError);
106  return object(self[idx]);
107 }
108 
109 template <typename T>
110 object
111 getitem_slice(VtArray<T> const &self, slice idx)
112 {
113  try {
114  slice::range<typename VtArray<T>::const_iterator> range =
115  idx.get_indices(self.begin(), self.end());
116  const size_t setSize = 1 + (range.stop - range.start) / range.step;
117  VtArray<T> result(setSize);
118  size_t i = 0;
119  for (; range.start != range.stop; range.start += range.step, ++i) {
120  result[i] = *range.start;
121  }
122  result[i] = *range.start;
123  return object(result);
124  }
125  catch (std::invalid_argument) {
126  return object();
127  }
128 }
129 
130 template <typename T, typename S>
131 void
132 setArraySlice(VtArray<T> &self, S value,
133  slice::range<T*>& range, size_t setSize, bool tile = false)
134 {
135  // Check size.
136  const size_t length = len(value);
137  if (length == 0)
138  TfPyThrowValueError("No values with which to set array slice.");
139  if (!tile && length < setSize) {
140  string msg = TfStringPrintf
141  ("Not enough values to set slice. Expected %zu, got %zu.",
142  setSize, length);
143  TfPyThrowValueError(msg);
144  }
145 
146  // Extract the values before setting any. If we can extract the
147  // whole vector at once then do that since it should be faster.
148  std::vector<T> extracted;
149  extract<std::vector<T> > vectorExtraction(value);
150  if (vectorExtraction.check()) {
151  std::vector<T> tmp = vectorExtraction();
152  extracted.swap(tmp);
153  }
154  else {
155  extracted.reserve(length);
156  for (size_t i = 0; i != length; ++i) {
157  extracted.push_back(extract<T>(value[i]));
158  }
159  }
160 
161  // We're fine, go through and set them. Handle common case as a fast
162  // path.
163  if (range.step == 1 && length >= setSize) {
164  std::copy(extracted.begin(), extracted.begin() + setSize, range.start);
165  }
166  else {
167  for (size_t i = 0; i != setSize; range.start += range.step, ++i) {
168  *range.start = extracted[i % length];
169  }
170  }
171 }
172 
173 template <typename T>
174 void
175 setArraySlice(VtArray<T> &self, slice idx, object value, bool tile = false)
176 {
177  // Get the range.
178  slice::range<T*> range;
179  try {
180  T* data = self.data();
181  range = idx.get_indices(data, data + self.size());
182  }
183  catch (std::invalid_argument) {
184  // Do nothing
185  return;
186  }
187 
188  // Get the number of items to be set.
189  const size_t setSize = 1 + (range.stop - range.start) / range.step;
190 
191  // Copy from VtArray. We only want to take this path if the passed value is
192  // *exactly* a VtArray. That is, we don't want to take this path if it can
193  // merely *convert* to a VtArray, so we check that we can extract a mutable
194  // lvalue reference from the python object, which requires that there be a
195  // real VtArray there.
196  if (extract< VtArray<T> &>(value).check()) {
197  const VtArray<T> val = extract< VtArray<T> >(value);
198  const size_t length = val.size();
199  if (length == 0)
200  TfPyThrowValueError("No values with which to set array slice.");
201  if (!tile && length < setSize) {
202  string msg = TfStringPrintf
203  ("Not enough values to set slice. Expected %zu, got %zu.",
204  setSize, length);
205  TfPyThrowValueError(msg);
206  }
207 
208  // We're fine, go through and set them.
209  for (size_t i = 0; i != setSize; range.start += range.step, ++i) {
210  *range.start = val[i % length];
211  }
212  }
213 
214  // Copy from scalar.
215  else if (extract<T>(value).check()) {
216  if (!tile) {
217  // XXX -- We're allowing implicit tiling; do we want to?
218  //TfPyThrowValueError("can only assign an iterable.");
219  }
220 
221  // Use scalar to fill entire slice.
222  const T val = extract<T>(value);
223  for (size_t i = 0; i != setSize; range.start += range.step, ++i) {
224  *range.start = val;
225  }
226  }
227 
228  // Copy from list.
229  else if (extract<list>(value).check()) {
230  setArraySlice(self, extract<list>(value)(), range, setSize, tile);
231  }
232 
233  // Copy from tuple.
234  else if (extract<tuple>(value).check()) {
235  setArraySlice(self, extract<tuple>(value)(), range, setSize, tile);
236  }
237 
238  // Copy from iterable.
239  else {
240  setArraySlice(self, list(value), range, setSize, tile);
241  }
242 }
243 
244 
245 template <typename T>
246 void
247 setitem_ellipsis(VtArray<T> &self, object idx, object value)
248 {
249  object ellipsis = object(handle<>(borrowed(Py_Ellipsis)));
250  if (idx != ellipsis) {
251  PyErr_SetString(PyExc_TypeError, "unsupported index type");
252  throw_error_already_set();
253  }
254  setArraySlice(self, slice(0, self.size()), value);
255 }
256 
257 template <typename T>
258 void
259 setitem_index(VtArray<T> &self, int64_t idx, object value)
260 {
261  static const bool tile = true;
262  setArraySlice(self, slice(idx, idx + 1), value, tile);
263 }
264 
265 template <typename T>
266 void
267 setitem_slice(VtArray<T> &self, slice idx, object value)
268 {
269  setArraySlice(self, idx, value);
270 }
271 
272 
273 template <class T>
274 VT_API string GetVtArrayName();
275 
276 
277 // To avoid overhead we stream out certain builtin types directly
278 // without calling TfPyRepr().
279 template <typename T>
280 static void streamValue(std::ostringstream &stream, T const &value) {
281  stream << TfPyRepr(value);
282 }
283 
284 // This is the same types as in VT_INTEGRAL_BUILTIN_VALUE_TYPES with char
285 // and bool types removed.
286 #define _OPTIMIZED_STREAM_INTEGRAL_TYPES \
287  (short) \
288  (unsigned short) \
289  (int) \
290  (unsigned int) \
291  (long) \
292  (unsigned long) \
293  (long long) \
294  (unsigned long long)
295 
296 #define MAKE_STREAM_FUNC(r, unused, type) \
297 static inline void \
298 streamValue(std::ostringstream &stream, type const &value) { \
299  stream << value; \
300 }
301 BOOST_PP_SEQ_FOR_EACH(MAKE_STREAM_FUNC, ~, _OPTIMIZED_STREAM_INTEGRAL_TYPES)
302 #undef MAKE_STREAM_FUNC
303 #undef _OPTIMIZED_STREAM_INTEGRAL_TYPES
304 
305 // Explicitly convert half to float here instead of relying on implicit
306 // conversion to float to work around the fact that libc++ only provides
307 // implementations of std::isfinite for types where std::is_arithmetic
308 // is true.
309 template <typename T>
310 static bool _IsFinite(T const &value) {
311  return std::isfinite(value);
312 }
313 static bool _IsFinite(GfHalf const &value) {
314  return std::isfinite(static_cast<float>(value));
315 }
316 
317 // For float types we need to be make sure to represent infs and nans correctly.
318 #define MAKE_STREAM_FUNC(r, unused, elem) \
319 static inline void \
320 streamValue(std::ostringstream &stream, VT_TYPE(elem) const &value) { \
321  if (_IsFinite(value)) { \
322  stream << value; \
323  } else { \
324  stream << TfPyRepr(value); \
325  } \
326 }
327 BOOST_PP_SEQ_FOR_EACH(
328  MAKE_STREAM_FUNC, ~, VT_FLOATING_POINT_BUILTIN_VALUE_TYPES)
329 #undef MAKE_STREAM_FUNC
330 
331 static unsigned int
332 Vt_ComputeEffectiveRankAndLastDimSize(
333  Vt_ShapeData const *sd, size_t *lastDimSize)
334 {
335  unsigned int rank = sd->GetRank();
336  if (rank == 1)
337  return rank;
338 
339  size_t divisor = std::accumulate(
340  sd->otherDims, sd->otherDims + rank-1,
341  1, [](size_t x, size_t y) { return x * y; });
342 
343  size_t remainder = divisor ? sd->totalSize % divisor : 0;
344  *lastDimSize = divisor ? sd->totalSize / divisor : 0;
345 
346  if (remainder)
347  rank = 1;
348 
349  return rank;
350 }
351 
352 template <typename T>
353 string __repr__(VtArray<T> const &self)
354 {
355  if (self.empty())
356  return TF_PY_REPR_PREFIX +
357  TfStringPrintf("%s()", GetVtArrayName<VtArray<T> >().c_str());
358 
359  std::ostringstream stream;
360  stream.precision(17);
361  stream << "(";
362  for (size_t i = 0; i < self.size(); ++i) {
363  stream << (i ? ", " : "");
364  streamValue(stream, self[i]);
365  }
366  stream << (self.size() == 1 ? ",)" : ")");
367 
368  const std::string repr = TF_PY_REPR_PREFIX +
369  TfStringPrintf("%s(%zd, %s)",
370  GetVtArrayName<VtArray<T> >().c_str(),
371  self.size(), stream.str().c_str());
372 
373  // XXX: This is to deal with legacy shaped arrays and should be removed
374  // once all shaped arrays have been eliminated.
375  // There is no nice way to make an eval()able __repr__ for shaped arrays
376  // that preserves the shape information, so put it in <> to make it
377  // clearly not eval()able. That has the advantage that, if somebody passes
378  // the repr into eval(), it'll raise a SyntaxError that clearly points to
379  // the beginning of the __repr__.
380  Vt_ShapeData const *shapeData = self._GetShapeData();
381  size_t lastDimSize = 0;
382  unsigned int rank =
383  Vt_ComputeEffectiveRankAndLastDimSize(shapeData, &lastDimSize);
384  if (rank > 1) {
385  std::string shapeStr = "(";
386  for (size_t i = 0; i != rank-1; ++i) {
387  shapeStr += TfStringPrintf(
388  i ? ", %d" : "%d", shapeData->otherDims[i]);
389  }
390  shapeStr += TfStringPrintf(", %zu)", lastDimSize);
391  return TfStringPrintf("<%s with shape %s>",
392  repr.c_str(), shapeStr.c_str());
393  }
394 
395  return repr;
396 }
397 
398 template <typename T>
399 VtArray<T> *VtArray__init__(object const &values)
400 {
401  // Make an array.
402  unique_ptr<VtArray<T> > ret(new VtArray<T>(len(values)));
403 
404  // Set the values. This is equivalent to saying 'ret[...] = values'
405  // in python, except that we allow tiling here.
406  static const bool tile = true;
407  setArraySlice(*ret, slice(0, ret->size()), values, tile);
408  return ret.release();
409 }
410 template <typename T>
411 VtArray<T> *VtArray__init__2(size_t size, object const &values)
412 {
413  // Make the array.
414  unique_ptr<VtArray<T> > ret(new VtArray<T>(size));
415 
416  // Set the values. This is equivalent to saying 'ret[...] = values'
417  // in python, except that we allow tiling here.
418  static const bool tile = true;
419  setArraySlice(*ret, slice(0, ret->size()), values, tile);
420 
421  return ret.release();
422 }
423 
424 // overloading for operator special methods, to allow tuple / list & array
425 // combinations
426 ARCH_PRAGMA_PUSH
427 ARCH_PRAGMA_UNSAFE_USE_OF_BOOL
428 ARCH_PRAGMA_UNARY_MINUS_ON_UNSIGNED
429 VTOPERATOR_WRAP(+,__add__,__radd__)
430 VTOPERATOR_WRAP_NONCOMM(-,__sub__,__rsub__)
431 VTOPERATOR_WRAP(*,__mul__,__rmul__)
432 VTOPERATOR_WRAP_NONCOMM(/,__div__,__rdiv__)
433 VTOPERATOR_WRAP_NONCOMM(%,__mod__,__rmod__)
434 
435 VTOPERATOR_WRAP_BOOL(Equal,==)
436 VTOPERATOR_WRAP_BOOL(NotEqual,!=)
437 VTOPERATOR_WRAP_BOOL(Greater,>)
438 VTOPERATOR_WRAP_BOOL(Less,<)
439 VTOPERATOR_WRAP_BOOL(GreaterOrEqual,>=)
440 VTOPERATOR_WRAP_BOOL(LessOrEqual,<=)
441 ARCH_PRAGMA_POP
442 }
443 
444 template <typename T>
445 static std::string _VtStr(T const &self)
446 {
447  return boost::lexical_cast<std::string>(self);
448 }
449 
450 template <typename T>
451 void VtWrapArray()
452 {
453  using namespace Vt_WrapArray;
454 
455  typedef T This;
456  typedef typename This::ElementType Type;
457 
458  string name = GetVtArrayName<This>();
459  string typeStr = ArchGetDemangled(typeid(Type));
460  string docStr = TfStringPrintf("An array of type %s.", typeStr.c_str());
461 
462  auto selfCls = class_<This>(name.c_str(), docStr.c_str(), no_init)
463  .setattr("_isVtArray", true)
464  .def(TfTypePythonClass())
465  .def(init<>())
466  .def("__init__", make_constructor(VtArray__init__<Type>),
467  (const char *)
468  "__init__(values)\n\n"
469  "values: a sequence (tuple, list, or another VtArray with "
470  "element type convertible to the new array's element type)\n\n"
471  )
472  .def("__init__", make_constructor(VtArray__init__2<Type>))
473  .def(init<unsigned int>())
474 
475  .def("__getitem__", getitem_ellipsis<Type>)
476  .def("__getitem__", getitem_slice<Type>)
477  .def("__getitem__", getitem_index<Type>)
478  .def("__setitem__", setitem_ellipsis<Type>)
479  .def("__setitem__", setitem_slice<Type>)
480  .def("__setitem__", setitem_index<Type>)
481 
482  .def("__len__", &This::size)
483  .def("__iter__", iterator<This>())
484 
485  .def("__repr__", __repr__<Type>)
486 
487 // .def(str(self))
488  .def("__str__", _VtStr<T>)
489  .def(self == self)
490  .def(self != self)
491 
492 #ifdef NUMERIC_OPERATORS
493 #define ADDITION_OPERATOR
494 #define SUBTRACTION_OPERATOR
495 #define MULTIPLICATION_OPERATOR
496 #define DIVISION_OPERATOR
497 #define UNARY_NEG_OPERATOR
498 #endif
499 
500 #ifdef ADDITION_OPERATOR
501  VTOPERATOR_WRAPDECLARE(+,__add__,__radd__)
502 #endif
503 #ifdef SUBTRACTION_OPERATOR
504  VTOPERATOR_WRAPDECLARE(-,__sub__,__rsub__)
505 #endif
506 #ifdef MULTIPLICATION_OPERATOR
507  VTOPERATOR_WRAPDECLARE(*,__mul__,__rmul__)
508 #endif
509 #ifdef DIVISION_OPERATOR
510  VTOPERATOR_WRAPDECLARE(/,__div__,__rdiv__)
511 #endif
512 #ifdef MOD_OPERATOR
513  VTOPERATOR_WRAPDECLARE(%,__mod__,__rmod__)
514 #endif
515 #ifdef DOUBLE_MULT_OPERATOR
516  .def(self * double())
517  .def(double() * self)
518 #endif
519 #ifdef DOUBLE_DIV_OPERATOR
520  .def(self / double())
521 #endif
522 #ifdef UNARY_NEG_OPERATOR
523  .def(- self)
524 #endif
525 
526  ;
527 
528 #if PY_MAJOR_VERSION == 2
529  // The above generates bindings for scalar division of arrays, but we
530  // need to explicitly add bindings for __truediv__ and __rtruediv__
531  // in Python 2 to support "from __future__ import division".
532  if (PyObject_HasAttrString(selfCls.ptr(), "__div__")) {
533  selfCls.attr("__truediv__") = selfCls.attr("__div__");
534  }
535 
536  if (PyObject_HasAttrString(selfCls.ptr(), "__rdiv__")) {
537  selfCls.attr("__rtruediv__") = selfCls.attr("__rdiv__");
538  }
539 #endif
540 
541 #define WRITE(z, n, data) BOOST_PP_COMMA_IF(n) data
542 #define VtCat_DEF(z, n, unused) \
543  def("Cat",(VtArray<Type> (*)( BOOST_PP_REPEAT(n, WRITE, VtArray<Type> const &) ))VtCat<Type>);
544  BOOST_PP_REPEAT_FROM_TO(1, VT_FUNCTIONS_MAX_ARGS, VtCat_DEF, ~)
545 #undef VtCat_DEF
546 
547  VTOPERATOR_WRAPDECLARE_BOOL(Equal)
548  VTOPERATOR_WRAPDECLARE_BOOL(NotEqual)
549 
550  // Wrap conversions from python sequences.
551  TfPyContainerConversions::from_python_sequence<
552  This,
553  TfPyContainerConversions::
554  variable_capacity_all_items_convertible_policy>();
555 
556  // Wrap implicit conversions from VtArray to TfSpan.
557  implicitly_convertible<This, TfSpan<Type> >();
558  implicitly_convertible<This, TfSpan<const Type> >();
559 }
560 
561 // wrapping for functions that work for base types that support comparisons
562 template <typename T>
563 void VtWrapComparisonFunctions()
564 {
565  using namespace Vt_WrapArray;
566 
567  typedef T This;
568  typedef typename This::ElementType Type;
569 
570  def("AnyTrue", VtAnyTrue<Type>);
571  def("AllTrue", VtAllTrue<Type>);
572 
573  VTOPERATOR_WRAPDECLARE_BOOL(Greater)
574  VTOPERATOR_WRAPDECLARE_BOOL(Less)
575  VTOPERATOR_WRAPDECLARE_BOOL(GreaterOrEqual)
576  VTOPERATOR_WRAPDECLARE_BOOL(LessOrEqual)
577 }
578 
579 template <class Array>
580 VtValue
581 Vt_ConvertFromPySequenceOrIter(TfPyObjWrapper const &obj)
582 {
583  typedef typename Array::ElementType ElemType;
584  TfPyLock lock;
585  if (PySequence_Check(obj.ptr())) {
586  Py_ssize_t len = PySequence_Length(obj.ptr());
587  Array result(len);
588  ElemType *elem = result.data();
589  for (Py_ssize_t i = 0; i != len; ++i) {
590  boost::python::handle<> h(PySequence_ITEM(obj.ptr(), i));
591  if (!h) {
592  if (PyErr_Occurred())
593  PyErr_Clear();
594  return VtValue();
595  }
596  boost::python::extract<ElemType> e(h.get());
597  if (!e.check())
598  return VtValue();
599  *elem++ = e();
600  }
601  return VtValue(result);
602  } else if (PyIter_Check(obj.ptr())) {
603  Array result;
604  while (PyObject *item = PyIter_Next(obj.ptr())) {
605  boost::python::handle<> h(item);
606  if (!h) {
607  if (PyErr_Occurred())
608  PyErr_Clear();
609  return VtValue();
610  }
611  boost::python::extract<ElemType> e(h.get());
612  if (!e.check())
613  return VtValue();
614  result.push_back(e());
615  }
616  return VtValue(result);
617  }
618  return VtValue();
619 }
620 
621 template <class Array, class Iter>
622 VtValue
623 Vt_ConvertFromRange(Iter begin, Iter end)
624 {
625  typedef typename Array::ElementType ElemType;
626  Array result(distance(begin, end));
627  for (ElemType *e = result.data(); begin != end; ++begin) {
628  VtValue cast = VtValue::Cast<ElemType>(*begin);
629  if (cast.IsEmpty())
630  return cast;
631  cast.Swap(*e++);
632  }
633  return VtValue(result);
634 }
635 
636 template <class T>
637 VtValue
638 Vt_CastToArray(VtValue const &v) {
639  VtValue ret;
640  TfPyObjWrapper obj;
641  // Attempt to convert from either python sequence or vector<VtValue>.
642  if (v.IsHolding<TfPyObjWrapper>()) {
643  ret = Vt_ConvertFromPySequenceOrIter<T>(v.UncheckedGet<TfPyObjWrapper>());
644  } else if (v.IsHolding<std::vector<VtValue> >()) {
645  std::vector<VtValue> const &vec = v.UncheckedGet<std::vector<VtValue> >();
646  ret = Vt_ConvertFromRange<T>(vec.begin(), vec.end());
647  }
648  return ret;
649 }
650 
652 template <class Elem>
653 void VtRegisterValueCastsFromPythonSequencesToArray()
654 {
655  typedef VtArray<Elem> Array;
656  VtValue::RegisterCast<TfPyObjWrapper, Array>(Vt_CastToArray<Array>);
657  VtValue::RegisterCast<std::vector<VtValue>, Array>(Vt_CastToArray<Array>);
658 }
659 
660 #define VT_WRAP_ARRAY(r, unused, elem) \
661  VtWrapArray< VtArray< VT_TYPE(elem) > >();
662 #define VT_WRAP_COMPARISON(r, unused, elem) \
663  VtWrapComparisonFunctions< VtArray< VT_TYPE(elem) > >();
664 
665 PXR_NAMESPACE_CLOSE_SCOPE
666 
667 #endif // PXR_BASE_VT_WRAP_ARRAY_H
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.
Pragmas for controlling compiler-specific behaviors.
Architecture-specific math function calls.
A simple iterator adapter for STL containers.
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:43
This header serves to simply bring in the half float datatype and provide a hash_value function.
size_t size() const
Return the total number of elements in this array.
Definition: array.h:505
A boost.python visitor that associates the Python class object created by the wrapping with the TfTyp...
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
Return demangled RTTI-generated type name.
TF_API void TfPyThrowValueError(std::string const &msg)
Raises a python ValueError and throws a C++ exception.
Definitions of basic string utilities in tf.
Miscellaneous Utilities for dealing with script.
std::string TfPyRepr(T const &t)
Return repr(t).
Definition: pyUtils.h:138
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1234
T const & UncheckedGet() const
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1077
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:229
Utilities for providing C++ <-> Python container support.
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
Define integral types.
Boost Python object wrapper.
Definition: pyObjWrapper.h:161
VtValue & Swap(VtValue &rhs) noexcept
Swap this with rhs.
Definition: value.h:970
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
Return a positive index in the range [0,size).
#define TF_PY_REPR_PREFIX
A macro which expands to the proper repr prefix for a library.
Definition: pyUtils.h:59
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1049
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
A file containing basic constants and definitions.