All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 VT_WRAP_ARRAY_H
25 #define 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"
39 #include "pxr/base/tf/pyContainerConversions.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"
47 #include "pxr/base/tf/stringUtils.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, int 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.
192  if (extract< VtArray<T> >(value).check()) {
193  const VtArray<T> val = extract< VtArray<T> >(value);
194  const size_t length = val.size();
195  if (length == 0)
196  TfPyThrowValueError("No values with which to set array slice.");
197  if (!tile && length < setSize) {
198  string msg = TfStringPrintf
199  ("Not enough values to set slice. Expected %zu, got %zu.",
200  setSize, length);
201  TfPyThrowValueError(msg);
202  }
203 
204  // We're fine, go through and set them.
205  for (size_t i = 0; i != setSize; range.start += range.step, ++i) {
206  *range.start = val[i % length];
207  }
208  }
209 
210  // Copy from scalar.
211  else if (extract<T>(value).check()) {
212  if (!tile) {
213  // XXX -- We're allowing implicit tiling; do we want to?
214  //TfPyThrowValueError("can only assign an iterable.");
215  }
216 
217  // Use scalar to fill entire slice.
218  const T val = extract<T>(value);
219  for (size_t i = 0; i != setSize; range.start += range.step, ++i) {
220  *range.start = val;
221  }
222  }
223 
224  // Copy from list.
225  else if (extract<list>(value).check()) {
226  setArraySlice(self, extract<list>(value)(), range, setSize, tile);
227  }
228 
229  // Copy from tuple.
230  else if (extract<tuple>(value).check()) {
231  setArraySlice(self, extract<tuple>(value)(), range, setSize, tile);
232  }
233 
234  // Copy from iterable.
235  else {
236  setArraySlice(self, list(value), range, setSize, tile);
237  }
238 }
239 
240 
241 template <typename T>
242 void
243 setitem_ellipsis(VtArray<T> &self, object idx, object value)
244 {
245  object ellipsis = object(handle<>(borrowed(Py_Ellipsis)));
246  if (idx != ellipsis) {
247  PyErr_SetString(PyExc_TypeError, "unsupported index type");
248  throw_error_already_set();
249  }
250  setArraySlice(self, slice(0, self.size()), value);
251 }
252 
253 template <typename T>
254 void
255 setitem_index(VtArray<T> &self, int idx, object value)
256 {
257  static const bool tile = true;
258  setArraySlice(self, slice(idx, idx + 1), value, tile);
259 }
260 
261 template <typename T>
262 void
263 setitem_slice(VtArray<T> &self, slice idx, object value)
264 {
265  setArraySlice(self, idx, value);
266 }
267 
268 
269 template <class T>
270 VT_API string GetVtArrayName();
271 
272 
273 // To avoid overhead we stream out certain builtin types directly
274 // without calling TfPyRepr().
275 template <typename T>
276 static void streamValue(std::ostringstream &stream, T const &value) {
277  stream << TfPyRepr(value);
278 }
279 
280 // This is the same types as in VT_INTEGRAL_BUILTIN_VALUE_TYPES with char
281 // and bool types removed.
282 #define _OPTIMIZED_STREAM_INTEGRAL_TYPES \
283  (short) \
284  (unsigned short) \
285  (int) \
286  (unsigned int) \
287  (long) \
288  (unsigned long) \
289  (long long) \
290  (unsigned long long)
291 
292 #define MAKE_STREAM_FUNC(r, unused, type) \
293 static inline void \
294 streamValue(std::ostringstream &stream, type const &value) { \
295  stream << value; \
296 }
297 BOOST_PP_SEQ_FOR_EACH(MAKE_STREAM_FUNC, ~, _OPTIMIZED_STREAM_INTEGRAL_TYPES)
298 #undef MAKE_STREAM_FUNC
299 #undef _OPTIMIZED_STREAM_INTEGRAL_TYPES
300 
301 // Explicitly convert half to float here instead of relying on implicit
302 // conversion to float to work around the fact that libc++ only provides
303 // implementations of std::isfinite for types where std::is_arithmetic
304 // is true.
305 template <typename T>
306 static bool _IsFinite(T const &value) {
307  return std::isfinite(value);
308 }
309 static bool _IsFinite(GfHalf const &value) {
310  return std::isfinite(static_cast<float>(value));
311 }
312 
313 // For float types we need to be make sure to represent infs and nans correctly.
314 #define MAKE_STREAM_FUNC(r, unused, elem) \
315 static inline void \
316 streamValue(std::ostringstream &stream, VT_TYPE(elem) const &value) { \
317  if (_IsFinite(value)) { \
318  stream << value; \
319  } else { \
320  stream << TfPyRepr(value); \
321  } \
322 }
323 BOOST_PP_SEQ_FOR_EACH(
324  MAKE_STREAM_FUNC, ~, VT_FLOATING_POINT_BUILTIN_VALUE_TYPES)
325 #undef MAKE_STREAM_FUNC
326 
327 static unsigned int
328 Vt_ComputeEffectiveRankAndLastDimSize(
329  Vt_ShapeData const *sd, size_t *lastDimSize)
330 {
331  unsigned int rank = sd->GetRank();
332  if (rank == 1)
333  return rank;
334 
335  size_t divisor = std::accumulate(
336  sd->otherDims, sd->otherDims + rank-1,
337  1, [](size_t x, size_t y) { return x * y; });
338 
339  size_t remainder = divisor ? sd->totalSize % divisor : 0;
340  *lastDimSize = divisor ? sd->totalSize / divisor : 0;
341 
342  if (remainder)
343  rank = 1;
344 
345  return rank;
346 }
347 
348 template <typename T>
349 string __repr__(VtArray<T> const &self)
350 {
351  if (self.empty())
352  return TF_PY_REPR_PREFIX +
353  TfStringPrintf("%s()", GetVtArrayName<VtArray<T> >().c_str());
354 
355  std::ostringstream stream;
356  stream.precision(17);
357  stream << "(";
358  for (size_t i = 0; i < self.size(); ++i) {
359  stream << (i ? ", " : "");
360  streamValue(stream, self[i]);
361  }
362  stream << (self.size() == 1 ? ",)" : ")");
363 
364  const std::string repr = TF_PY_REPR_PREFIX +
365  TfStringPrintf("%s(%zd, %s)",
366  GetVtArrayName<VtArray<T> >().c_str(),
367  self.size(), stream.str().c_str());
368 
369  // XXX: This is to deal with legacy shaped arrays and should be removed
370  // once all shaped arrays have been eliminated.
371  // There is no nice way to make an eval()able __repr__ for shaped arrays
372  // that preserves the shape information, so put it in <> to make it
373  // clearly not eval()able. That has the advantage that, if somebody passes
374  // the repr into eval(), it'll raise a SyntaxError that clearly points to
375  // the beginning of the __repr__.
376  Vt_ShapeData const *shapeData = self._GetShapeData();
377  size_t lastDimSize = 0;
378  unsigned int rank =
379  Vt_ComputeEffectiveRankAndLastDimSize(shapeData, &lastDimSize);
380  if (rank > 1) {
381  std::string shapeStr = "(";
382  for (size_t i = 0; i != rank-1; ++i) {
383  shapeStr += TfStringPrintf(
384  i ? ", %d" : "%d", shapeData->otherDims[i]);
385  }
386  shapeStr += TfStringPrintf(", %zu)", lastDimSize);
387  return TfStringPrintf("<%s with shape %s>",
388  repr.c_str(), shapeStr.c_str());
389  }
390 
391  return repr;
392 }
393 
394 template <typename T>
395 VtArray<T> *VtArray__init__(object const &values)
396 {
397  // Make an array.
398  unique_ptr<VtArray<T> > ret(new VtArray<T>(len(values)));
399 
400  // Set the values. This is equivalent to saying 'ret[...] = values'
401  // in python, except that we allow tiling here.
402  static const bool tile = true;
403  setArraySlice(*ret, slice(0, ret->size()), values, tile);
404  return ret.release();
405 }
406 template <typename T>
407 VtArray<T> *VtArray__init__2(unsigned int size, object const &values)
408 {
409  // Make the array.
410  unique_ptr<VtArray<T> > ret(new VtArray<T>(size));
411 
412  // Set the values. This is equivalent to saying 'ret[...] = values'
413  // in python, except that we allow tiling here.
414  static const bool tile = true;
415  setArraySlice(*ret, slice(0, ret->size()), values, tile);
416 
417  return ret.release();
418 }
419 
420 // overloading for operator special methods, to allow tuple / list & array
421 // combinations
422 ARCH_PRAGMA_PUSH
423 ARCH_PRAGMA_UNSAFE_USE_OF_BOOL
424 ARCH_PRAGMA_UNARY_MINUS_ON_UNSIGNED
425 VTOPERATOR_WRAP(+,__add__,__radd__)
426 VTOPERATOR_WRAP_NONCOMM(-,__sub__,__rsub__)
427 VTOPERATOR_WRAP(*,__mul__,__rmul__)
428 VTOPERATOR_WRAP_NONCOMM(/,__div__,__rdiv__)
429 VTOPERATOR_WRAP_NONCOMM(%,__mod__,__rmod__)
430 
431 VTOPERATOR_WRAP_BOOL(Equal,==)
432 VTOPERATOR_WRAP_BOOL(NotEqual,!=)
433 VTOPERATOR_WRAP_BOOL(Greater,>)
434 VTOPERATOR_WRAP_BOOL(Less,<)
435 VTOPERATOR_WRAP_BOOL(GreaterOrEqual,>=)
436 VTOPERATOR_WRAP_BOOL(LessOrEqual,<=)
437 ARCH_PRAGMA_POP
438 }
439 
440 template <typename T>
441 static std::string _VtStr(T const &self)
442 {
443  return boost::lexical_cast<std::string>(self);
444 }
445 
446 template <typename T>
447 void VtWrapArray()
448 {
449  using namespace Vt_WrapArray;
450 
451  typedef T This;
452  typedef typename This::ElementType Type;
453 
454  string name = GetVtArrayName<This>();
455  string typeStr = ArchGetDemangled(typeid(Type));
456  string docStr = TfStringPrintf("An array of type %s.", typeStr.c_str());
457 
458  class_<This>(name.c_str(), docStr.c_str(), no_init)
459  .setattr("_isVtArray", true)
460  .def(TfTypePythonClass())
461  .def(init<>())
462  .def("__init__", make_constructor(VtArray__init__<Type>),
463  (const char *)
464  "__init__(values)\n\n"
465  "values: a sequence (tuple, list, or another VtArray with "
466  "element type convertible to the new array's element type)\n\n"
467  )
468  .def("__init__", make_constructor(VtArray__init__2<Type>))
469  .def(init<unsigned int>())
470 
471  .def("__getitem__", getitem_ellipsis<Type>)
472  .def("__getitem__", getitem_slice<Type>)
473  .def("__getitem__", getitem_index<Type>)
474  .def("__setitem__", setitem_ellipsis<Type>)
475  .def("__setitem__", setitem_slice<Type>)
476  .def("__setitem__", setitem_index<Type>)
477 
478  .def("__len__", &This::size)
479  .def("__iter__", iterator<This>())
480 
481  .def("__repr__", __repr__<Type>)
482 
483 // .def(str(self))
484  .def("__str__", _VtStr<T>)
485  .def(self == self)
486  .def(self != self)
487 
488 #ifdef NUMERIC_OPERATORS
489 #define ADDITION_OPERATOR
490 #define SUBTRACTION_OPERATOR
491 #define MULTIPLICATION_OPERATOR
492 #define DIVISION_OPERATOR
493 #define UNARY_NEG_OPERATOR
494 #endif
495 
496 #ifdef ADDITION_OPERATOR
497  VTOPERATOR_WRAPDECLARE(+,__add__,__radd__)
498 #endif
499 #ifdef SUBTRACTION_OPERATOR
500  VTOPERATOR_WRAPDECLARE(-,__sub__,__rsub__)
501 #endif
502 #ifdef MULTIPLICATION_OPERATOR
503  VTOPERATOR_WRAPDECLARE(*,__mul__,__rmul__)
504 #endif
505 #ifdef DIVISION_OPERATOR
506  VTOPERATOR_WRAPDECLARE(/,__div__,__rdiv__)
507 #endif
508 #ifdef MOD_OPERATOR
509  VTOPERATOR_WRAPDECLARE(%,__mod__,__rmod__)
510 #endif
511 #ifdef DOUBLE_MULT_OPERATOR
512  .def(self * double())
513  .def(double() * self)
514 #endif
515 #ifdef DOUBLE_DIV_OPERATOR
516  .def(self / double())
517 #endif
518 #ifdef UNARY_NEG_OPERATOR
519  .def(- self)
520 #endif
521 
522  ;
523 
524 #define WRITE(z, n, data) BOOST_PP_COMMA_IF(n) data
525 #define VtCat_DEF(z, n, unused) \
526  def("Cat",(VtArray<Type> (*)( BOOST_PP_REPEAT(n, WRITE, VtArray<Type> const &) ))VtCat<Type>);
527  BOOST_PP_REPEAT_FROM_TO(1, VT_FUNCTIONS_MAX_ARGS, VtCat_DEF, ~)
528 #undef VtCat_DEF
529 
530  VTOPERATOR_WRAPDECLARE_BOOL(Equal)
531  VTOPERATOR_WRAPDECLARE_BOOL(NotEqual)
532 
533  // Wrap implicit conversions from VtArray to TfSpan.
534  implicitly_convertible<This, TfSpan<Type> >();
535  implicitly_convertible<This, TfSpan<const Type> >();
536 }
537 
538 // wrapping for functions that work for base types that support comparisons
539 template <typename T>
540 void VtWrapComparisonFunctions()
541 {
542  using namespace Vt_WrapArray;
543 
544  typedef T This;
545  typedef typename This::ElementType Type;
546 
547  def("AnyTrue", VtAnyTrue<Type>);
548  def("AllTrue", VtAllTrue<Type>);
549 
550  VTOPERATOR_WRAPDECLARE_BOOL(Greater)
551  VTOPERATOR_WRAPDECLARE_BOOL(Less)
552  VTOPERATOR_WRAPDECLARE_BOOL(GreaterOrEqual)
553  VTOPERATOR_WRAPDECLARE_BOOL(LessOrEqual)
554 }
555 
556 template <class Array>
557 VtValue
558 Vt_ConvertFromPySequence(TfPyObjWrapper const &obj)
559 {
560  typedef typename Array::ElementType ElemType;
561  TfPyLock lock;
562  if (PySequence_Check(obj.ptr())) {
563  Py_ssize_t len = PySequence_Length(obj.ptr());
564  Array result(len);
565  ElemType *elem = result.data();
566  for (Py_ssize_t i = 0; i != len; ++i) {
567  boost::python::handle<> h(PySequence_ITEM(obj.ptr(), i));
568  if (!h) {
569  if (PyErr_Occurred())
570  PyErr_Clear();
571  return VtValue();
572  }
573  boost::python::extract<ElemType> e(h.get());
574  if (!e.check())
575  return VtValue();
576  *elem++ = e();
577  }
578  return VtValue(result);
579  }
580  return VtValue();
581 }
582 
583 template <class Array, class Iter>
584 VtValue
585 Vt_ConvertFromRange(Iter begin, Iter end)
586 {
587  typedef typename Array::ElementType ElemType;
588  Array result(distance(begin, end));
589  for (ElemType *e = result.data(); begin != end; ++begin) {
590  VtValue cast = VtValue::Cast<ElemType>(*begin);
591  if (cast.IsEmpty())
592  return cast;
593  cast.Swap(*e++);
594  }
595  return VtValue(result);
596 }
597 
598 template <class T>
599 VtValue
600 Vt_CastToArray(VtValue const &v) {
601  VtValue ret;
602  TfPyObjWrapper obj;
603  // Attempt to convert from either python sequence or vector<VtValue>.
604  if (v.IsHolding<TfPyObjWrapper>()) {
605  ret = Vt_ConvertFromPySequence<T>(v.UncheckedGet<TfPyObjWrapper>());
606  } else if (v.IsHolding<std::vector<VtValue> >()) {
607  std::vector<VtValue> const &vec = v.UncheckedGet<std::vector<VtValue> >();
608  ret = Vt_ConvertFromRange<T>(vec.begin(), vec.end());
609  }
610  return ret;
611 }
612 
614 template <class Elem>
615 void VtRegisterValueCastsFromPythonSequencesToArray()
616 {
617  typedef VtArray<Elem> Array;
618  VtValue::RegisterCast<TfPyObjWrapper, Array>(Vt_CastToArray<Array>);
619  VtValue::RegisterCast<std::vector<VtValue>, Array>(Vt_CastToArray<Array>);
620 }
621 
622 #define VT_WRAP_ARRAY(r, unused, elem) \
623  VtWrapArray< VtArray< VT_TYPE(elem) > >();
624 #define VT_WRAP_COMPARISON(r, unused, elem) \
625  VtWrapComparisonFunctions< VtArray< VT_TYPE(elem) > >();
626 
627 PXR_NAMESPACE_CLOSE_SCOPE
628 
629 #endif // VT_WRAP_ARRAY_H
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.
T const & UncheckedGet() const
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:836
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:42
void if(!TfPyIsInitialized())
Invokes wrapFunc to wrap type T if T is not already wrapped.
Definition: pyUtils.h:210
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.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:808
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
Return a positive index in the range [0,size).
Represents a range of contiguous elements.
Definition: span.h:87
size_t size() const
Return the total number of elements in this array.
Definition: array.h:428
Boost Python object wrapper.
Definition: pyObjWrapper.h:66
VtValue & Swap(VtValue &rhs) noexcept
Swap this with rhs.
Definition: value.h:741
#define TF_PY_REPR_PREFIX
A macro which expands to the proper repr prefix for a library.
Definition: pyUtils.h:57
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:990
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
std::string TfPyRepr(T const &t)
Return repr(t).
Definition: pyUtils.h:136
TF_API void TfPyThrowValueError(std::string const &msg)
Raises a python ValueError and throws a C++ exception.