Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LowLevelViews.cxx File Reference
#include "cpyrt.h"
#include "Converters.h"
#include "CustomPyTypes.h"
#include "LowLevelViews.h"
#include "PyStrings.h"
#include <assert.h>
#include <limits.h>
#include <map>
#include <string.h>
Include dependency graph for LowLevelViews.cxx:

Namespaces

namespace  cppjit
 
namespace  cppjit::cpyrt
 

Macros

#define ADJUST_PTR(ptr, suboffsets, dim)    (HAVE_PTR(suboffsets, dim) ? *((char**)ptr) + suboffsets[dim] : ptr)
 
#define CPPJIT_IMPL_VIEW_CREATOR(type)
 
#define CPPJIT_RET_W_CREATOR(type, fname)
 
#define CPYRT_LL_FLAG_GETSET(name, flag, doc)
 
#define HAVE_PTR(suboffsets, dim)   (suboffsets && suboffsets[dim] >= 0)
 
#define HAVE_SUBOFFSETS_IN_LAST_DIM(view)    (view->suboffsets && view->suboffsets[dest->ndim - 1] >= 0)
 

Functions

static void copy_base (const Py_ssize_t *shape, Py_ssize_t itemsize, char *dptr, const Py_ssize_t *dstrides, const Py_ssize_t *dsuboffsets, char *sptr, const Py_ssize_t *sstrides, const Py_ssize_t *ssuboffsets, char *mem)
 
static int copy_single (Py_buffer *dest, Py_buffer *src)
 
template<typename T >
static cpyrt::LowLevelView * CreateLowLevelViewT (T **address, cpyrt::cdims_t shape, const char *format=nullptr, const char *name=nullptr)
 
template<typename T >
static cpyrt::LowLevelView * CreateLowLevelViewT (T *address, cpyrt::cdims_t shape, const char *format=nullptr, const char *name=nullptr, Py_ssize_t itemsize=-1)
 
static bool equiv_shape (const Py_buffer *dest, const Py_buffer *src)
 
static bool equiv_structure (const Py_buffer *dest, const Py_buffer *src)
 
static Py_ssize_t fake_max (size_t elemsize)
 
static int init_slice (Py_buffer *base, PyObject *_key, int dim)
 
static Py_ssize_t is_multiindex (PyObject *key)
 
static bool is_multislice (PyObject *key)
 
static int last_dim_is_contiguous (const Py_buffer *dest, const Py_buffer *src)
 
static PyObject * ll_array (cpyrt::LowLevelView *self, PyObject *args, PyObject *kwds)
 
static PyObject * ll_as_string (cpyrt::LowLevelView *self)
 
static int ll_ass_sub (cpyrt::LowLevelView *self, PyObject *key, PyObject *value)
 
static void ll_dealloc (cpyrt::LowLevelView *pyobj)
 
static int ll_getbuf (cpyrt::LowLevelView *self, Py_buffer *view, int flags)
 
static PyObject * ll_getcpparray (cpyrt::LowLevelView *pyobj)
 
static PyObject * ll_getownership (cpyrt::LowLevelView *pyobj)
 
static PyObject * ll_item (cpyrt::LowLevelView *self, Py_ssize_t index)
 
static PyObject * ll_item_multi (cpyrt::LowLevelView *self, PyObject *tup)
 
static PyObject * ll_iter (PyObject *self)
 
static Py_ssize_t ll_length (cpyrt::LowLevelView *self)
 
static cpyrt::LowLevelView * ll_new (PyTypeObject *subtype, PyObject *, PyObject *)
 
static PyObject * ll_reshape (cpyrt::LowLevelView *self, PyObject *shape)
 
static PyObject * ll_reshape_error (cpyrt::LowLevelView *self, PyObject *shape, const char *why)
 
static int ll_setcpparray (cpyrt::LowLevelView *pyobj, PyObject *value, void *)
 
static int ll_setownership (cpyrt::LowLevelView *pyobj, PyObject *value, void *)
 
static int ll_setshape (cpyrt::LowLevelView *self, PyObject *value, void *)
 
static PyObject * ll_shape (cpyrt::LowLevelView *self)
 
static PyObject * ll_subscript (cpyrt::LowLevelView *self, PyObject *key)
 
static PyObject * ll_typecode (cpyrt::LowLevelView *self, void *)
 
static char * lookup_dimension (Py_buffer &view, char *ptr, int dim, Py_ssize_t index)
 
static void * ptr_from_index (cpyrt::LowLevelView *llview, Py_ssize_t index)
 
static void * ptr_from_tuple (cpyrt::LowLevelView *llview, PyObject *tup)
 
static void set_strides (Py_buffer &view, size_t itemsize, bool isfix)
 

Variables

static PyBufferProcs ll_as_buffer
 
static PyMappingMethods ll_as_mapping
 
static PySequenceMethods ll_as_sequence
 
static PyGetSetDef ll_getset []
 
static PyMethodDef ll_methods []
 
PyTypeObject cppjit::cpyrt::LowLevelView_Type
 

Macro Definition Documentation

◆ ADJUST_PTR

#define ADJUST_PTR ( ptr,
suboffsets,
dim )    (HAVE_PTR(suboffsets, dim) ? *((char**)ptr) + suboffsets[dim] : ptr)

Definition at line 126 of file LowLevelViews.cxx.

◆ CPPJIT_IMPL_VIEW_CREATOR

#define CPPJIT_IMPL_VIEW_CREATOR ( type)
Value:
PyObject* cpyrt::CreateLowLevelView(type* address, cdims_t shape) { \
LowLevelView* ll = CreateLowLevelViewT<type>(address, shape); \
CPPJIT_RET_W_CREATOR(type*, CreateLowLevelView); \
} \
PyObject* cpyrt::CreateLowLevelView(type** address, cdims_t shape) { \
LowLevelView* ll = CreateLowLevelViewT<type>(address, shape); \
CPPJIT_RET_W_CREATOR(type**, CreateLowLevelView); \
}
_object PyObject
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
PyObject * CreateLowLevelView(bool *, cdims_t shape)

Definition at line 1163 of file LowLevelViews.cxx.

◆ CPPJIT_RET_W_CREATOR

#define CPPJIT_RET_W_CREATOR ( type,
fname )
Value:
PyObject* (*c)(type, cdims_t) = &fname; \
ll->fCreator = (LowLevelView::Creator_t)c; \
return (PyObject*)ll
#define c(i)
Definition RSha256.hxx:101

Definition at line 1158 of file LowLevelViews.cxx.

◆ CPYRT_LL_FLAG_GETSET

#define CPYRT_LL_FLAG_GETSET ( name,
flag,
doc )
Value:
static PyObject* ll_get##name(cpyrt::LowLevelView* pyobj) { \
return PyBool_FromLong((long)((intptr_t)pyobj->fBufInfo.internal & flag)); \
} \
\
static int ll_set##name(cpyrt::LowLevelView* pyobj, PyObject* value, \
void*) { \
long settrue = PyLong_AsLong(value); \
if (settrue == -1 && PyErr_Occurred()) { \
PyErr_SetString(PyExc_ValueError, \
#doc " should be either True or False"); \
return -1; \
} \
\
if ((bool)settrue) \
(intptr_t&)pyobj->fBufInfo.internal |= flag; \
else \
(intptr_t&)pyobj->fBufInfo.internal &= ~flag; \
\
return 0; \
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:142
PyObject_HEAD Py_buffer fBufInfo

Definition at line 85 of file LowLevelViews.cxx.

◆ HAVE_PTR

#define HAVE_PTR ( suboffsets,
dim )   (suboffsets && suboffsets[dim] >= 0)

Definition at line 124 of file LowLevelViews.cxx.

◆ HAVE_SUBOFFSETS_IN_LAST_DIM

#define HAVE_SUBOFFSETS_IN_LAST_DIM ( view)     (view->suboffsets && view->suboffsets[dest->ndim - 1] >= 0)

Definition at line 131 of file LowLevelViews.cxx.

Function Documentation

◆ copy_base()

static void copy_base ( const Py_ssize_t * shape,
Py_ssize_t itemsize,
char * dptr,
const Py_ssize_t * dstrides,
const Py_ssize_t * dsuboffsets,
char * sptr,
const Py_ssize_t * sstrides,
const Py_ssize_t * ssuboffsets,
char * mem )
static

Definition at line 177 of file LowLevelViews.cxx.

◆ copy_single()

static int copy_single ( Py_buffer * dest,
Py_buffer * src )
static

Definition at line 207 of file LowLevelViews.cxx.

◆ CreateLowLevelViewT() [1/2]

template<typename T >
static cpyrt::LowLevelView * CreateLowLevelViewT ( T ** address,
cpyrt::cdims_t shape,
const char * format = nullptr,
const char * name = nullptr )
inlinestatic

Definition at line 1148 of file LowLevelViews.cxx.

◆ CreateLowLevelViewT() [2/2]

template<typename T >
static cpyrt::LowLevelView * CreateLowLevelViewT ( T * address,
cpyrt::cdims_t shape,
const char * format = nullptr,
const char * name = nullptr,
Py_ssize_t itemsize = -1 )
inlinestatic

Definition at line 1087 of file LowLevelViews.cxx.

◆ equiv_shape()

static bool equiv_shape ( const Py_buffer * dest,
const Py_buffer * src )
inlinestatic

Definition at line 145 of file LowLevelViews.cxx.

◆ equiv_structure()

static bool equiv_structure ( const Py_buffer * dest,
const Py_buffer * src )
static

Definition at line 163 of file LowLevelViews.cxx.

◆ fake_max()

static Py_ssize_t fake_max ( size_t elemsize)
inlinestatic

Definition at line 40 of file LowLevelViews.cxx.

◆ init_slice()

static int init_slice ( Py_buffer * base,
PyObject * _key,
int dim )
inlinestatic

Definition at line 322 of file LowLevelViews.cxx.

◆ is_multiindex()

static Py_ssize_t is_multiindex ( PyObject * key)
static

Definition at line 366 of file LowLevelViews.cxx.

◆ is_multislice()

static bool is_multislice ( PyObject * key)
static

Definition at line 349 of file LowLevelViews.cxx.

◆ last_dim_is_contiguous()

static int last_dim_is_contiguous ( const Py_buffer * dest,
const Py_buffer * src )
inlinestatic

Definition at line 135 of file LowLevelViews.cxx.

◆ ll_array()

static PyObject * ll_array ( cpyrt::LowLevelView * self,
PyObject * args,
PyObject * kwds )
static

Definition at line 818 of file LowLevelViews.cxx.

◆ ll_as_string()

static PyObject * ll_as_string ( cpyrt::LowLevelView * self)
static

Definition at line 882 of file LowLevelViews.cxx.

◆ ll_ass_sub()

static int ll_ass_sub ( cpyrt::LowLevelView * self,
PyObject * key,
PyObject * value )
static

Definition at line 498 of file LowLevelViews.cxx.

◆ ll_dealloc()

static void ll_dealloc ( cpyrt::LowLevelView * pyobj)
static

Definition at line 63 of file LowLevelViews.cxx.

◆ ll_getbuf()

static int ll_getbuf ( cpyrt::LowLevelView * self,
Py_buffer * view,
int flags )
static

Definition at line 597 of file LowLevelViews.cxx.

◆ ll_getcpparray()

static PyObject * ll_getcpparray ( cpyrt::LowLevelView * pyobj)
static

Definition at line 109 of file LowLevelViews.cxx.

◆ ll_getownership()

static PyObject * ll_getownership ( cpyrt::LowLevelView * pyobj)
static

Definition at line 108 of file LowLevelViews.cxx.

◆ ll_item()

static PyObject * ll_item ( cpyrt::LowLevelView * self,
Py_ssize_t index )
static

Definition at line 383 of file LowLevelViews.cxx.

◆ ll_item_multi()

static PyObject * ll_item_multi ( cpyrt::LowLevelView * self,
PyObject * tup )
static

Definition at line 409 of file LowLevelViews.cxx.

◆ ll_iter()

static PyObject * ll_iter ( PyObject * self)
static

Definition at line 642 of file LowLevelViews.cxx.

◆ ll_length()

static Py_ssize_t ll_length ( cpyrt::LowLevelView * self)
static

Definition at line 315 of file LowLevelViews.cxx.

◆ ll_new()

static cpyrt::LowLevelView * ll_new ( PyTypeObject * subtype,
PyObject * ,
PyObject *  )
static

Definition at line 45 of file LowLevelViews.cxx.

◆ ll_reshape()

static PyObject * ll_reshape ( cpyrt::LowLevelView * self,
PyObject * shape )
static

Definition at line 722 of file LowLevelViews.cxx.

◆ ll_reshape_error()

static PyObject * ll_reshape_error ( cpyrt::LowLevelView * self,
PyObject * shape,
const char * why )
static

Definition at line 709 of file LowLevelViews.cxx.

◆ ll_setcpparray()

static int ll_setcpparray ( cpyrt::LowLevelView * pyobj,
PyObject * value,
void *  )
static

Definition at line 109 of file LowLevelViews.cxx.

◆ ll_setownership()

static int ll_setownership ( cpyrt::LowLevelView * pyobj,
PyObject * value,
void *  )
static

Definition at line 108 of file LowLevelViews.cxx.

◆ ll_setshape()

static int ll_setshape ( cpyrt::LowLevelView * self,
PyObject * value,
void *  )
static

Definition at line 804 of file LowLevelViews.cxx.

◆ ll_shape()

static PyObject * ll_shape ( cpyrt::LowLevelView * self)
static

Definition at line 690 of file LowLevelViews.cxx.

◆ ll_subscript()

static PyObject * ll_subscript ( cpyrt::LowLevelView * self,
PyObject * key )
static

Definition at line 432 of file LowLevelViews.cxx.

◆ ll_typecode()

static PyObject * ll_typecode ( cpyrt::LowLevelView * self,
void *  )
static

Definition at line 113 of file LowLevelViews.cxx.

◆ lookup_dimension()

static char * lookup_dimension ( Py_buffer & view,
char * ptr,
int dim,
Py_ssize_t index )
static

Definition at line 235 of file LowLevelViews.cxx.

◆ ptr_from_index()

static void * ptr_from_index ( cpyrt::LowLevelView * llview,
Py_ssize_t index )
inlinestatic

Definition at line 277 of file LowLevelViews.cxx.

◆ ptr_from_tuple()

static void * ptr_from_tuple ( cpyrt::LowLevelView * llview,
PyObject * tup )
static

Definition at line 285 of file LowLevelViews.cxx.

◆ set_strides()

static void set_strides ( Py_buffer & view,
size_t itemsize,
bool isfix )
inlinestatic

Definition at line 24 of file LowLevelViews.cxx.

Variable Documentation

◆ ll_as_buffer

PyBufferProcs ll_as_buffer
static
Initial value:
= {
(getbufferproc)ll_getbuf,
0,
}
static int ll_getbuf(cpyrt::LowLevelView *self, Py_buffer *view, int flags)

Definition at line 684 of file LowLevelViews.cxx.

◆ ll_as_mapping

PyMappingMethods ll_as_mapping
static
Initial value:
= {
(lenfunc)ll_length,
(binaryfunc)ll_subscript,
(objobjargproc)ll_ass_sub,
}
static Py_ssize_t ll_length(cpyrt::LowLevelView *self)
static PyObject * ll_subscript(cpyrt::LowLevelView *self, PyObject *key)
static int ll_ass_sub(cpyrt::LowLevelView *self, PyObject *key, PyObject *value)

Definition at line 663 of file LowLevelViews.cxx.

◆ ll_as_sequence

PySequenceMethods ll_as_sequence
static
Initial value:
= {
(lenfunc)ll_length,
0,
0,
(ssizeargfunc)ll_item,
0,
0,
0,
0,
0,
0,
}
static PyObject * ll_item(cpyrt::LowLevelView *self, Py_ssize_t index)

Definition at line 670 of file LowLevelViews.cxx.

◆ ll_getset

PyGetSetDef ll_getset[]
static
Initial value:
= {
{(char*)"__python_owns__", (getter)ll_getownership, (setter)ll_setownership,
(char*)"If true, python manages the life time of this buffer", nullptr},
{(char*)"__cpp_array__", (getter)ll_getcpparray, (setter)ll_setcpparray,
(char*)"If true, this array was allocated with C++\'s new[]", nullptr},
{(char*)"format", (getter)ll_typecode, nullptr, nullptr, nullptr},
{(char*)"typecode", (getter)ll_typecode, nullptr, nullptr, nullptr},
{(char*)"shape", (getter)ll_shape, (setter)ll_setshape, nullptr, nullptr},
{(char*)nullptr, nullptr, nullptr, nullptr, nullptr}}
static PyObject * ll_shape(cpyrt::LowLevelView *self)
static int ll_setcpparray(cpyrt::LowLevelView *pyobj, PyObject *value, void *)
static PyObject * ll_getcpparray(cpyrt::LowLevelView *pyobj)
static int ll_setshape(cpyrt::LowLevelView *self, PyObject *value, void *)
static int ll_setownership(cpyrt::LowLevelView *pyobj, PyObject *value, void *)
static PyObject * ll_getownership(cpyrt::LowLevelView *pyobj)
static PyObject * ll_typecode(cpyrt::LowLevelView *self, void *)

Definition at line 911 of file LowLevelViews.cxx.

◆ ll_methods

PyMethodDef ll_methods[]
static
Initial value:
= {
{(char*)"reshape", (PyCFunction)ll_reshape, METH_O,
(char*)"change the shape (not layout) of the low level view"},
{(char*)"as_string", (PyCFunction)ll_as_string, METH_NOARGS,
(char*)"interpret memory as a null-terminated char string and return "
"Python str"},
{(char*)"__array__", (PyCFunction)ll_array, METH_VARARGS | METH_KEYWORDS,
(char*)"return a numpy array from the low level view"},
{(char*)nullptr, nullptr, 0, nullptr}}
static PyObject * ll_reshape(cpyrt::LowLevelView *self, PyObject *shape)
static PyObject * ll_array(cpyrt::LowLevelView *self, PyObject *args, PyObject *kwds)
static PyObject * ll_as_string(cpyrt::LowLevelView *self)

Definition at line 900 of file LowLevelViews.cxx.