sbknumpyview.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2022 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. #ifndef SBKNUMPYVIEW_H
  4. #define SBKNUMPYVIEW_H
  5. #include <sbkpython.h>
  6. #include <shibokenmacros.h>
  7. #include <iosfwd>
  8. namespace Shiboken::Numpy
  9. {
  10. /// Check whether the object is a PyArrayObject
  11. /// \param pyIn object
  12. /// \return Whether it is a PyArrayObject
  13. LIBSHIBOKEN_API bool check(PyObject *pyIn);
  14. /// A simple view of an up to 2 dimensional, C-contiguous array of a standard
  15. /// type. It can be passed to compilation units that do not include the
  16. /// numpy headers.
  17. struct LIBSHIBOKEN_API View
  18. {
  19. enum Type { Int, Unsigned, Float, Double, Int16, Unsigned16, Int64, Unsigned64 };
  20. static View fromPyObject(PyObject *pyIn);
  21. operator bool() const { return ndim > 0; }
  22. /// Return whether rhs is of the same type and dimensionality
  23. bool sameLayout(const View &rhs) const;
  24. /// Return whether rhs is of the same type dimensionality and size
  25. bool sameSize(const View &rhs) const;
  26. int ndim = 0;
  27. Py_ssize_t dimensions[2];
  28. Py_ssize_t stride[2];
  29. void *data = nullptr;
  30. Type type = Int;
  31. };
  32. LIBSHIBOKEN_API std::ostream &operator<<(std::ostream &, const View &v);
  33. } //namespace Shiboken::Numpy
  34. #endif // SBKNUMPYVIEW_H