aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/sbknumpyview.h
blob: 918913b7881a672f4eaeb38646357fd7abd01592 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef SBKNUMPYVIEW_H
#define SBKNUMPYVIEW_H

#include <sbkpython.h>
#include <shibokenmacros.h>

#include <iosfwd>

namespace Shiboken::Numpy
{

/// Check whether the object is a PyArrayObject
/// \param pyIn object
/// \return Whether it is a PyArrayObject
LIBSHIBOKEN_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 LIBSHIBOKEN_API View
{
    enum Type { Int, Unsigned, Float, Double, Int16, Unsigned16, Int64, Unsigned64 };

    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;
    Py_ssize_t dimensions[2];
    Py_ssize_t stride[2];
    void *data = nullptr;
    Type type = Int;
};

LIBSHIBOKEN_API std::ostream &operator<<(std::ostream &, const View &v);

} //namespace Shiboken::Numpy

#endif // SBKNUMPYVIEW_H