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

Namespaces

namespace  CPyCppyy
 

Macros

#define ADJUST_PTR(ptr, suboffsets, dim)    (HAVE_PTR(suboffsets, dim) ? *((char**)ptr) + suboffsets[dim] : ptr)
 
#define CPPYY_IMPL_VIEW_CREATOR(type)
 
#define CPPYY_RET_W_CREATOR(type, fname)
 
#define CPYCPPYY_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 CPyCppyy::LowLevelViewCreateLowLevelViewT (T **address, CPyCppyy::cdims_t shape, const char *format=nullptr, const char *name=nullptr)
 
template<typename T >
static CPyCppyy::LowLevelViewCreateLowLevelViewT (T *address, CPyCppyy::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 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 PyObjectll_array (CPyCppyy::LowLevelView *self, PyObject *args, PyObject *)
 
static PyObjectll_as_string (CPyCppyy::LowLevelView *self)
 
static int ll_ass_sub (CPyCppyy::LowLevelView *self, PyObject *key, PyObject *value)
 
static void ll_dealloc (CPyCppyy::LowLevelView *pyobj)
 
static int ll_getbuf (CPyCppyy::LowLevelView *self, Py_buffer *view, int flags)
 
static PyObjectll_getcpparray (CPyCppyy::LowLevelView *pyobj)
 
static PyObjectll_getownership (CPyCppyy::LowLevelView *pyobj)
 
static Py_ssize_t ll_getsegcount (PyObject *, Py_ssize_t *lenp)
 
static PyObjectll_item (CPyCppyy::LowLevelView *self, Py_ssize_t index)
 
static PyObjectll_item_multi (CPyCppyy::LowLevelView *self, PyObject *tup)
 
static PyObjectll_iter (PyObject *self)
 
static Py_ssize_t ll_length (CPyCppyy::LowLevelView *self)
 
static CPyCppyy::LowLevelViewll_new (PyTypeObject *subtype, PyObject *, PyObject *)
 
static Py_ssize_t ll_oldgetbuf (CPyCppyy::LowLevelView *self, Py_ssize_t seg, void **pptr)
 
static PyObjectll_reshape (CPyCppyy::LowLevelView *self, PyObject *shape)
 
static int ll_setcpparray (CPyCppyy::LowLevelView *pyobj, PyObject *value, void *)
 
static int ll_setownership (CPyCppyy::LowLevelView *pyobj, PyObject *value, void *)
 
static PyObjectll_shape (CPyCppyy::LowLevelView *self)
 
static PyObjectll_subscript (CPyCppyy::LowLevelView *self, PyObject *key)
 
static PyObjectll_typecode (CPyCppyy::LowLevelView *self, void *)
 
static char * lookup_dimension (Py_buffer &view, char *ptr, int dim, Py_ssize_t index)
 
static void * ptr_from_index (CPyCppyy::LowLevelView *llview, Py_ssize_t index)
 
static void * ptr_from_tuple (CPyCppyy::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 CPyCppyy::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 122 of file LowLevelViews.cxx.

◆ CPPYY_IMPL_VIEW_CREATOR

#define CPPYY_IMPL_VIEW_CREATOR (   type)
Value:
PyObject* CPyCppyy::CreateLowLevelView(type* address, cdims_t shape) { \
LowLevelView* ll = CreateLowLevelViewT<type>(address, shape); \
CPPYY_RET_W_CREATOR(type*, CreateLowLevelView); \
} \
PyObject* CPyCppyy::CreateLowLevelView(type** address, cdims_t shape) { \
LowLevelView* ll = CreateLowLevelViewT<type>(address, shape); \
CPPYY_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 1105 of file LowLevelViews.cxx.

◆ CPPYY_RET_W_CREATOR

#define CPPYY_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 1100 of file LowLevelViews.cxx.

◆ CPYCPPYY_LL_FLAG_GETSET

#define CPYCPPYY_LL_FLAG_GETSET (   name,
  flag,
  doc 
)
Value:
static PyObject* ll_get##name(CPyCppyy::LowLevelView* pyobj) \
{ \
return PyBool_FromLong((long)((intptr_t)pyobj->fBufInfo.internal & flag));\
} \
\
static int ll_set##name(CPyCppyy::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; \
}
#define PyBool_FromLong
Definition CPyCppyy.h:251
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110

Definition at line 81 of file LowLevelViews.cxx.

◆ HAVE_PTR

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

Definition at line 120 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 127 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 175 of file LowLevelViews.cxx.

◆ copy_single()

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

Definition at line 206 of file LowLevelViews.cxx.

◆ CreateLowLevelViewT() [1/2]

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

Definition at line 1090 of file LowLevelViews.cxx.

◆ CreateLowLevelViewT() [2/2]

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

Definition at line 1034 of file LowLevelViews.cxx.

◆ equiv_shape()

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

Definition at line 141 of file LowLevelViews.cxx.

◆ equiv_structure()

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

Definition at line 160 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 372 of file LowLevelViews.cxx.

◆ is_multislice()

static bool is_multislice ( PyObject key)
static

Definition at line 354 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 131 of file LowLevelViews.cxx.

◆ ll_array()

static PyObject * ll_array ( CPyCppyy::LowLevelView self,
PyObject args,
PyObject  
)
static

Definition at line 820 of file LowLevelViews.cxx.

◆ ll_as_string()

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

Definition at line 856 of file LowLevelViews.cxx.

◆ ll_ass_sub()

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

Definition at line 517 of file LowLevelViews.cxx.

◆ ll_dealloc()

static void ll_dealloc ( CPyCppyy::LowLevelView pyobj)
static

Definition at line 57 of file LowLevelViews.cxx.

◆ ll_getbuf()

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

Definition at line 635 of file LowLevelViews.cxx.

◆ ll_getcpparray()

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

Definition at line 104 of file LowLevelViews.cxx.

◆ ll_getownership()

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

Definition at line 103 of file LowLevelViews.cxx.

◆ ll_getsegcount()

static Py_ssize_t ll_getsegcount ( PyObject ,
Py_ssize_t lenp 
)
static

Definition at line 627 of file LowLevelViews.cxx.

◆ ll_item()

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

Definition at line 391 of file LowLevelViews.cxx.

◆ ll_item_multi()

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

Definition at line 418 of file LowLevelViews.cxx.

◆ ll_iter()

static PyObject * ll_iter ( PyObject self)
static

Definition at line 681 of file LowLevelViews.cxx.

◆ ll_length()

static Py_ssize_t ll_length ( CPyCppyy::LowLevelView self)
static

Definition at line 314 of file LowLevelViews.cxx.

◆ ll_new()

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

Definition at line 40 of file LowLevelViews.cxx.

◆ ll_oldgetbuf()

static Py_ssize_t ll_oldgetbuf ( CPyCppyy::LowLevelView self,
Py_ssize_t  seg,
void **  pptr 
)
static

Definition at line 615 of file LowLevelViews.cxx.

◆ ll_reshape()

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

Definition at line 749 of file LowLevelViews.cxx.

◆ ll_setcpparray()

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

Definition at line 104 of file LowLevelViews.cxx.

◆ ll_setownership()

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

Definition at line 103 of file LowLevelViews.cxx.

◆ ll_shape()

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

Definition at line 737 of file LowLevelViews.cxx.

◆ ll_subscript()

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

Definition at line 444 of file LowLevelViews.cxx.

◆ ll_typecode()

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

Definition at line 107 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 237 of file LowLevelViews.cxx.

◆ ptr_from_index()

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

Definition at line 275 of file LowLevelViews.cxx.

◆ ptr_from_tuple()

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

Definition at line 283 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:
= {
(readbufferproc)ll_oldgetbuf,
(writebufferproc)ll_oldgetbuf,
(segcountproc)ll_getsegcount,
0,
(getbufferproc)ll_getbuf,
0,
}
static Py_ssize_t ll_oldgetbuf(CPyCppyy::LowLevelView *self, Py_ssize_t seg, void **pptr)
static Py_ssize_t ll_getsegcount(PyObject *, Py_ssize_t *lenp)
static int ll_getbuf(CPyCppyy::LowLevelView *self, Py_buffer *view, int flags)

Definition at line 723 of file LowLevelViews.cxx.

◆ ll_as_mapping

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

Definition at line 702 of file LowLevelViews.cxx.

◆ ll_as_sequence

PySequenceMethods ll_as_sequence
static
Initial value:
= {
( inquiry )ll_length,
0,
0,
( intargfunc )ll_item,
0,
0,
0,
0,
0,
0,
}
static PyObject * ll_item(CPyCppyy::LowLevelView *self, Py_ssize_t index)

Definition at line 709 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_reshape, nullptr, nullptr},
{(char*)nullptr, nullptr, nullptr, nullptr, nullptr }
}
static PyObject * ll_typecode(CPyCppyy::LowLevelView *self, void *)
static PyObject * ll_reshape(CPyCppyy::LowLevelView *self, PyObject *shape)
static PyObject * ll_getcpparray(CPyCppyy::LowLevelView *pyobj)
static PyObject * ll_shape(CPyCppyy::LowLevelView *self)
static int ll_setcpparray(CPyCppyy::LowLevelView *pyobj, PyObject *value, void *)
static int ll_setownership(CPyCppyy::LowLevelView *pyobj, PyObject *value, void *)
static PyObject * ll_getownership(CPyCppyy::LowLevelView *pyobj)

Definition at line 885 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_array(CPyCppyy::LowLevelView *self, PyObject *args, PyObject *)
static PyObject * ll_as_string(CPyCppyy::LowLevelView *self)

Definition at line 874 of file LowLevelViews.cxx.