Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LowLevelViews.h
Go to the documentation of this file.
1#ifndef CPYRT_LOWLEVELVIEWS_H
2#define CPYRT_LOWLEVELVIEWS_H
3
4// Bindings
5#include "Dimensions.h"
6
7// Standard
8#include <complex>
9#include <cstddef>
10#include <stddef.h>
11
12namespace cppjit::cpyrt {
13
14class Converter;
15
17public:
18 enum EFlags {
19 kDefault = 0x0000,
20 kIsCppArray = 0x0001, // allocated with new[]
21 kIsFixed = 0x0002, // fixed size array (assumed flat)
22 kIsOwner = 0x0004
23 }; // Python owns
24
25public:
26 PyObject_HEAD Py_buffer fBufInfo;
27 void** fBuf;
30
31 typedef LowLevelView* (*Creator_t)(void*, cdims_t);
32 Creator_t fCreator; // for slicing, which requires copying
33
34public:
35 void* get_buf() { return fBuf ? *fBuf : fBufInfo.buf; }
36 void set_buf(void** buf) {
37 fBuf = buf;
38 fBufInfo.buf = get_buf();
39 }
40
41 bool resize(size_t sz);
42};
43
44#define CPPJIT_DECL_VIEW_CREATOR(type) \
45 PyObject* CreateLowLevelView(type*, cdims_t shape); \
46 PyObject* CreateLowLevelView(type**, cdims_t shape)
47
50CPPJIT_DECL_VIEW_CREATOR(signed char);
51CPPJIT_DECL_VIEW_CREATOR(unsigned char);
54PyObject* CreateLowLevelView_i8(int8_t**, cdims_t shape);
55PyObject* CreateLowLevelView_i8(uint8_t*, cdims_t shape);
56PyObject* CreateLowLevelView_i8(uint8_t**, cdims_t shape);
58PyObject* CreateLowLevelView_i16(int16_t**, cdims_t shape);
59PyObject* CreateLowLevelView_i16(uint16_t*, cdims_t shape);
60PyObject* CreateLowLevelView_i16(uint16_t**, cdims_t shape);
62PyObject* CreateLowLevelView_i32(int32_t**, cdims_t shape);
63PyObject* CreateLowLevelView_i32(uint32_t*, cdims_t shape);
64PyObject* CreateLowLevelView_i32(uint32_t**, cdims_t shape);
65
67CPPJIT_DECL_VIEW_CREATOR(unsigned short);
69CPPJIT_DECL_VIEW_CREATOR(unsigned int);
71CPPJIT_DECL_VIEW_CREATOR(unsigned long);
73CPPJIT_DECL_VIEW_CREATOR(unsigned long long);
76CPPJIT_DECL_VIEW_CREATOR(long double);
77CPPJIT_DECL_VIEW_CREATOR(std::complex<float>);
78CPPJIT_DECL_VIEW_CREATOR(std::complex<double>);
79CPPJIT_DECL_VIEW_CREATOR(std::complex<int>);
80CPPJIT_DECL_VIEW_CREATOR(std::complex<long>);
81
83PyObject* CreateLowLevelViewString(const char**, cdims_t shape);
84
85inline PyObject* CreatePointerView(void* ptr, cdims_t shape = 0) {
86 return CreateLowLevelView((uintptr_t*)ptr, shape);
87}
88
89//- low level view type and type verification --------------------------------
90extern PyTypeObject LowLevelView_Type;
91
92template <typename T> inline bool LowLevelView_Check(T* object) {
93 return object && PyObject_TypeCheck(object, &LowLevelView_Type);
94}
95
96template <typename T> inline bool LowLevelView_CheckExact(T* object) {
97 return object && Py_TYPE(object) == &LowLevelView_Type;
98}
99
100} // namespace cppjit::cpyrt
101
102#endif // !CPYRT_LOWLEVELVIEWS_H
#define CPPJIT_DECL_VIEW_CREATOR(type)
_object PyObject
LowLevelView *(* Creator_t)(void *, cdims_t)
PyObject_HEAD Py_buffer fBufInfo
PyObject * CreateLowLevelViewString(char **, cdims_t shape)
PyObject * CreateLowLevelView(bool *, cdims_t shape)
bool LowLevelView_Check(T *object)
bool LowLevelView_CheckExact(T *object)
PyObject * CreatePointerView(void *ptr, cdims_t shape=0)
PyTypeObject LowLevelView_Type
PyObject * CreateLowLevelView_i8(int8_t *, cdims_t shape)
PyObject * CreateLowLevelView_i32(int32_t *, cdims_t shape)
PyObject * CreateLowLevelView_i16(int16_t *, cdims_t shape)
const dims_t & cdims_t
Definition API.h:114