diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-27 13:01:05 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-29 13:47:34 +0200 |
| commit | de61e2344c7ff0fe329023f7b2498d0ded9cbe5d (patch) | |
| tree | 710456896e7b1b5250eaa027a94d805b54e0e7bf /sources/pyside6/libpyside/pyside_numpy.h | |
| parent | e64a515c2195eb945264d5d4321a1aaf3bf09a3f (diff) | |
libpyside: Add a simple view into a numpy array
Add a simple view struct of an up to 2 dimensional, C-contiguous array
of a standard types. It can be passed to compilation units that do not
include the numpy headers.
Task-number: PYSIDE-1880
Change-Id: I59b7ddf928f817889d9b0731ab5977d55a82e96a
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside/pyside_numpy.h')
| -rw-r--r-- | sources/pyside6/libpyside/pyside_numpy.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sources/pyside6/libpyside/pyside_numpy.h b/sources/pyside6/libpyside/pyside_numpy.h index 689d64cfa..b012fa5f7 100644 --- a/sources/pyside6/libpyside/pyside_numpy.h +++ b/sources/pyside6/libpyside/pyside_numpy.h @@ -65,6 +65,29 @@ bool init(); /// \return Whether it is a PyArrayObject PYSIDE_API bool check(PyObject *pyIn); +/// A simple view of an up to 2 dimensional, C-contiguous array of a standard +/// type. It can be passed to compilation units that do not include the +/// numpy headers. +struct PYSIDE_API View +{ + enum Type { Int, Unsigned, Float, Double}; + + static View fromPyObject(PyObject *pyIn); + + operator bool() const { return ndim > 0; } + + /// Return whether rhs is of the same type and dimensionality + bool sameLayout(const View &rhs) const; + /// Return whether rhs is of the same type dimensionality and size + bool sameSize(const View &rhs) const; + + int ndim = 0; + qsizetype dimensions[2]; + qsizetype stride[2]; + void *data = nullptr; + Type type = Int; +}; + /// Create a list of QPointF from 2 equally sized numpy array of x and y data /// (float,double). /// \param pyXIn X data array @@ -89,6 +112,7 @@ struct debugPyArrayObject }; PYSIDE_API QDebug operator<<(QDebug debug, const debugPyArrayObject &a); +PYSIDE_API QDebug operator<<(QDebug debug, const View &v); } //namespace PySide::Numpy |
