File: CFloat32CustomPython.h

package info (click to toggle)
astra-toolbox 2.3.0-4
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 4,972 kB
  • sloc: cpp: 24,378; python: 5,048; sh: 3,514; ansic: 1,181; makefile: 518
file content (33 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (2)
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
class GILHelper {
public:
    GILHelper() {
        state = PyGILState_Ensure();
    }
    ~GILHelper() {
        PyGILState_Release(state);
    }
private:
    PyGILState_STATE state;
};

class CFloat32CustomPython : public astra::CFloat32CustomMemory {
public:
    CFloat32CustomPython(PyArrayObject * arrIn)
    {
        GILHelper gil; // hold GIL during this function

        arr = arrIn;
        // Set pointer to numpy data pointer
        m_fPtr = (float *)PyArray_DATA(arr);
        // Increase reference count since ASTRA has a reference
        Py_INCREF(arr);
    }
    virtual ~CFloat32CustomPython() {
        GILHelper gil; // hold GIL during this function

        // Decrease reference count since ASTRA object is destroyed
        Py_DECREF(arr);
    }
private:
    PyArrayObject* arr;
};