###################
### WARNING!!! ###
###################
# This file has been autogenerated
# Cython imports
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
from cpython.version cimport PY_MAJOR_VERSION
from cpython.ref cimport PyTypeObject
from cpython.type cimport PyType_Ready
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
# Python Imports
import collections
cimport numpy as np
import numpy as np
np.import_array()
cimport mypack_extra_types
# Cython imports for types
from libcpp.string cimport string as std_string
# imports for types
dtypes = {}
if PY_MAJOR_VERSION >= 3:
basestring = str
# Dirty ifdef, else, else preprocessor hack
# see http://comments.gmane.org/gmane.comp.python.cython.user/4080
cdef extern from *:
cdef void emit_ifpy2k "#if PY_MAJOR_VERSION == 2 //" ()
cdef void emit_ifpy3k "#if PY_MAJOR_VERSION == 3 //" ()
cdef void emit_else "#else //" ()
cdef void emit_endif "#endif //" ()
# std_string dtype
cdef MemoryKnight[std_string] mk_str = MemoryKnight[std_string]()
cdef MemoryKnight[PyXDStr_Type] mk_str_type = MemoryKnight[PyXDStr_Type]()
cdef object pyxd_str_getitem(void * data, void * arr):
pyval = bytes(<char *> (<std_string *> data)[0].c_str()).decode()
return pyval
cdef int pyxd_str_setitem(object value, void * data, void * arr):
cdef std_string * new_data
cdef char * value_proxy
if isinstance(value, basestring):
value_bytes = value.encode()
new_data = mk_str.renew(data)
new_data[0] = std_string(<char *> value_bytes)
return 0
else:
return -1
cdef void pyxd_str_copyswapn(void * dest, np.npy_intp dstride, void * src, np.npy_intp sstride, np.npy_intp n, int swap, void * arr):
cdef np.npy_intp i
cdef char * a
cdef char * b
cdef char c = 0
cdef int j
cdef int m
cdef std_string * new_dest
if src != NULL:
if (sstride == sizeof(std_string) and dstride == sizeof(std_string)):
new_dest = mk_str.renew(dest)
new_dest[0] = deref(<std_string *> src)
else:
a = <char *> dest
b = <char *> src
for i in range(n):
new_dest = mk_str.renew(<void *> a)
new_dest[0] = deref(<std_string *> b)
a += dstride
b += sstride
if swap:
m = sizeof(std_string) / 2
a = <char *> dest
for i in range(n, 0, -1):
b = a + (sizeof(std_string) - 1);
for j in range(m):
c = a[0]
a[0] = b[0]
a += 1
b[0] = c
b -= 1
a += dstride - m
cdef void pyxd_str_copyswap(void * dest, void * src, int swap, void * arr):
cdef char * a
cdef char * b
cdef char c = 0
cdef int j
cdef int m
cdef std_string * new_dest
if src != NULL:
new_dest = mk_str.renew(dest)
new_dest[0] = (<std_string *> src)[0]
if swap:
m = sizeof(std_string) / 2
a = <char *> dest
b = a + (sizeof(std_string) - 1);
for j in range(m):
c = a[0]
a[0] = b[0]
a += 1
b[0] = c
b -= 1
cdef np.npy_bool pyxd_str_nonzero(void * data, void * arr):
return (data != NULL)
# FIXME comparisons not defined for arbitrary types
#cdef std_string zero = std_string()
#return ((<std_string *> data)[0] != zero)
cdef int pyxd_str_compare(const void * d1, const void * d2, void * arr):
return (d1 == d2) - 1
# FIXME comparisons not defined for arbitrary types
#if deref(<std_string *> d1) == deref(<std_string *> d2):
# return 0
#else:
# return -1
cdef PyArray_ArrFuncs PyXD_Str_ArrFuncs
PyArray_InitArrFuncs(&PyXD_Str_ArrFuncs)
PyXD_Str_ArrFuncs.getitem = <PyArray_GetItemFunc *> (&pyxd_str_getitem)
PyXD_Str_ArrFuncs.setitem = <PyArray_SetItemFunc *> (&pyxd_str_setitem)
PyXD_Str_ArrFuncs.copyswapn = <PyArray_CopySwapNFunc *> (&pyxd_str_copyswapn)
PyXD_Str_ArrFuncs.copyswap = <PyArray_CopySwapFunc *> (&pyxd_str_copyswap)
PyXD_Str_ArrFuncs.nonzero = <PyArray_NonzeroFunc *> (&pyxd_str_nonzero)
PyXD_Str_ArrFuncs.compare = <PyArray_CompareFunc *> (&pyxd_str_compare)
cdef object pyxd_str_type_alloc(PyTypeObject * self, Py_ssize_t nitems):
cdef PyXDStr_Type * cval
cdef object pyval
cval = mk_str_type.defnew()
cval.ob_typ = self
pyval = <object> cval
return pyval
cdef void pyxd_str_type_dealloc(object self):
cdef PyXDStr_Type * cself = <PyXDStr_Type *> self
mk_str_type.deall(cself)
return
cdef object pyxd_str_type_new(PyTypeObject * subtype, object args, object kwds):
return pyxd_str_type_alloc(subtype, 0)
cdef void pyxd_str_type_free(void * self):
return
cdef object pyxd_str_type_str(object self):
cdef PyXDStr_Type * cself = <PyXDStr_Type *> self
pyval = bytes(<char *> (cself.obval).c_str()).decode()
s = str(pyval)
return s
cdef object pyxd_str_type_repr(object self):
cdef PyXDStr_Type * cself = <PyXDStr_Type *> self
pyval = bytes(<char *> (cself.obval).c_str()).decode()
s = repr(pyval)
return s
cdef int pyxd_str_type_compare(object a, object b):
return (a is b) - 1
# FIXME comparisons not defined for arbitrary types
#cdef PyXDStr_Type * x
#cdef PyXDStr_Type * y
#if type(a) is not type(b):
# raise NotImplementedError
#x = <PyXDStr_Type *> a
#y = <PyXDStr_Type *> b
#if (x.obval == y.obval):
# return 0
#elif (x.obval < y.obval):
# return -1
#elif (x.obval > y.obval):
# return 1
#else:
# raise NotImplementedError
cdef object pyxd_str_type_richcompare(object a, object b, int op):
if op == Py_EQ:
return (a is b)
elif op == Py_NE:
return (a is not b)
else:
return NotImplemented
# FIXME comparisons not defined for arbitrary types
#cdef PyXDStr_Type * x
#cdef PyXDStr_Type * y
#if type(a) is not type(b):
# return NotImplemented
#x = <PyXDStr_Type *> a
#y = <PyXDStr_Type *> b
#if op == Py_LT:
# return (x.obval < y.obval)
#elif op == Py_LE:
# return (x.obval <= y.obval)
#elif op == Py_EQ:
# return (x.obval == y.obval)
#elif op == Py_NE:
# return (x.obval != y.obval)
#elif op == Py_GT:
# return (x.obval > y.obval)
#elif op == Py_GE:
# return (x.obval >= y.obval)
#else:
# return NotImplemented
cdef long pyxd_str_type_hash(object self):
return id(self)
cdef PyMemberDef pyxd_str_type_members[1]
pyxd_str_type_members[0] = PyMemberDef(NULL, 0, 0, 0, NULL)
cdef PyGetSetDef pyxd_str_type_getset[1]
pyxd_str_type_getset[0] = PyGetSetDef(NULL)
cdef bint pyxd_str_is_ready
cdef type PyXD_Str = type("xd_str", ((<object> PyArray_API[10]),), {})
pyxd_str_is_ready = PyType_Ready(<object> PyXD_Str)
(<PyTypeObject *> PyXD_Str).tp_basicsize = sizeof(PyXDStr_Type)
(<PyTypeObject *> PyXD_Str).tp_itemsize = 0
(<PyTypeObject *> PyXD_Str).tp_doc = "Python scalar type for std_string"
(<PyTypeObject *> PyXD_Str).tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_HEAPTYPE
(<PyTypeObject *> PyXD_Str).tp_alloc = pyxd_str_type_alloc
(<PyTypeObject *> PyXD_Str).tp_dealloc = pyxd_str_type_dealloc
(<PyTypeObject *> PyXD_Str).tp_new = pyxd_str_type_new
(<PyTypeObject *> PyXD_Str).tp_free = pyxd_str_type_free
(<PyTypeObject *> PyXD_Str).tp_str = pyxd_str_type_str
(<PyTypeObject *> PyXD_Str).tp_repr = pyxd_str_type_repr
(<PyTypeObject *> PyXD_Str).tp_base = (<PyTypeObject *> PyArray_API[10]) # PyGenericArrType_Type
(<PyTypeObject *> PyXD_Str).tp_hash = pyxd_str_type_hash
emit_ifpy2k()
(<PyTypeObject *> PyXD_Str).tp_compare = &pyxd_str_type_compare
emit_endif()
(<PyTypeObject *> PyXD_Str).tp_richcompare = pyxd_str_type_richcompare
(<PyTypeObject *> PyXD_Str).tp_members = pyxd_str_type_members
(<PyTypeObject *> PyXD_Str).tp_getset = pyxd_str_type_getset
pyxd_str_is_ready = PyType_Ready(<object> PyXD_Str)
Py_INCREF(PyXD_Str)
XDStr = PyXD_Str
cdef PyArray_Descr * c_xd_str_descr = <PyArray_Descr *> malloc(sizeof(PyArray_Descr))
(<PyObject *> c_xd_str_descr).ob_refcnt = 0 # ob_refcnt
(<PyObject *> c_xd_str_descr).ob_type = <PyTypeObject *> PyArray_API[3]
c_xd_str_descr.typeobj = <PyTypeObject *> PyXD_Str # typeobj
c_xd_str_descr.kind = 'x' # kind, for xdress
c_xd_str_descr.type = 'x' # type
c_xd_str_descr.byteorder = '=' # byteorder
c_xd_str_descr.flags = 0 # flags
c_xd_str_descr.type_num = 0 # type_num, assigned at registration
c_xd_str_descr.elsize = sizeof(std_string) # elsize,
c_xd_str_descr.alignment = 8 # alignment
c_xd_str_descr.subarray = NULL # subarray
c_xd_str_descr.fields = NULL # fields
c_xd_str_descr.names = NULL
(<PyArray_Descr *> c_xd_str_descr).f = <PyArray_ArrFuncs *> &PyXD_Str_ArrFuncs # f == PyArray_ArrFuncs
cdef object xd_str_descr = <object> (<void *> c_xd_str_descr)
Py_INCREF(<object> xd_str_descr)
xd_str = xd_str_descr
cdef int xd_str_num = PyArray_RegisterDataType(c_xd_str_descr)
dtypes['str'] = xd_str
dtypes['xd_str'] = xd_str
dtypes[xd_str_num] = xd_str