diff --git a/pymolfile/molfile/1 b/pymolfile/molfile/1 new file mode 100644 index 0000000000000000000000000000000000000000..a20e02af96712d71037c23c3101e1f830c376acc --- /dev/null +++ b/pymolfile/molfile/1 @@ -0,0 +1,174 @@ +import numpy +import ctypes +import _libpymolfile + +class molatom_t(ctypes.Structure): + _fields_ = [ + ('name', ctypes.c_char * 16), + ('type', ctypes.c_char * 16), + ('resname', ctypes.c_char * 8), + ('resid', ctypes.c_uint8), + ('segid', ctypes.c_char * 8), + ('chain', ctypes.c_char * 2), + ('altloc', ctypes.c_char * 2), + ('insertion', ctypes.c_char *2), + ('occupancy', ctypes.c_float), + ('bfactor', ctypes.c_float), + ('mass', ctypes.c_float), + ('charge', ctypes.c_float), + ('radius', ctypes.c_float), + ('atomicnumber', ctypes.c_uint8), + ('ctnumber', ctypes.c_uint8), + ] + +class molplugin_t(ctypes.Structure): + _fields_ = [ + ('abiversion', ctypes.c_uint8), + ('type', ctypes.c_char_p), + ('name', ctypes.c_char_p), + ('prettyname', ctypes.c_char_p), + ('author', ctypes.c_char_p), + ('majorv', ctypes.c_uint8), + ('minorv', ctypes.c_uint8), + ('is_reentrant', ctypes.c_uint8), + ('filename_extension', ctypes.c_char_p), + ('open_file_read', ctypes.CFUNCTYPE(ctypes.c_char_p, + ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8))), + ('read_structure', ctypes.CFUNCTYPE(ctypes.c_void_p, + ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(molatom_t))), + ('read_bonds', ctypes.CFUNCTYPE(ctypes.c_void_p, + ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), + ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), + ctypes.c_char_p)), + ('read_next_timestep', ctypes.c_int8), + ('close_file_read', ctypes.c_void_p), + ('open_file_write', ctypes.c_void_p), + ('write_structure', ctypes.c_int8), + ('write_timestep', ctypes.c_int8), + ('close_file_write', ctypes.c_void_p), + ('read_volumetric_metadata', ctypes.c_int8), + ('read_volumetric_data', ctypes.c_int8), + ('read_volumetric_data_ex', ctypes.c_int8), + ('read_rawgraphics', ctypes.c_int8), + ('read_molecule_metadata', ctypes.c_int8), + ('write_bonds', ctypes.c_int8), + ('write_volumetric_data', ctypes.c_int8), + ('write_volumetric_data_ex', ctypes.c_int8), + ('read_angles', ctypes.c_int8), + ('write_angles', ctypes.c_int8), + ('read_qm_metadata', ctypes.c_int8), + ('read_qm_rundata', ctypes.c_int8), + ('read_timestep', ctypes.c_int8), + ('read_timestep_metadata', ctypes.c_int8), + ('read_qm_timestep_metadata', ctypes.c_int8), + ('read_timestep2', ctypes.c_int8), + ('read_times', ctypes.c_ssize_t), + ('cons_fputs', ctypes.c_uint8) + ] + +class moltimestep_t(ctypes.Structure): + _fields_ = [ + ('coords', ctypes.POINTER(ctypes.c_float)), + ('velocities', ctypes.POINTER(ctypes.c_float)), + ('A', ctypes.c_float), + ('B', ctypes.c_float), + ('C', ctypes.c_float), + ('alpha', ctypes.c_float), + ('beta', ctypes.c_float), + ('gamma', ctypes.c_float), + ('physical_time', ctypes.c_double), + ('total_energy', ctypes.c_double), + ('potential_energy', ctypes.c_double), + ('kinetic_energy', ctypes.c_double), + ('extended_energy', ctypes.c_double), + ('force_energy', ctypes.c_double), + ('total_pressure', ctypes.c_double) + ] + +class molhandle_t(ctypes.Structure): + _fields_ = [ + ('plugin', ctypes.POINTER(molplugin_t)), + ('file_handle', ctypes.c_void_p), + ('natoms', ctypes.c_int) + ] + +class molnatoms(ctypes.Structure): + _fields_ = [ + ('natoms', ctypes.c_int) + ] + +#callback_t = ctypes.CFUNCTYPE(None, ctypes.POINTER(molatom_t)) + +def get_open_file_read(output): + ctypes.open_file_read.restype = ctypes.POINTER(molhandle_t) + ctypes.open_file_read.argtypes = [ctypes.POINTER(molplugin_t), ctypes.c_void_p, ctypes.c_uint8] + return ctypes.pythonapi.PyCapsule_GetPointer(output, "plugin") + +def get_capsule(capsule): + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + return ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + +def get_plugincapsule(capsule): + data = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + data = ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + return data + +def get_plugindata(capsule): + data = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + data = ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + return data + +mylib = _libpymolfile +mylist = mylib.molfile_plugin_list(200) +numlist = mylib.molfile_init() +print(numlist) +for i in range(numlist): + testplugin = mylib.molfile_plugin_info(mylist, i) + print(i, testplugin) + +plugin = mylib.get_plugin(mylist, 81) +print(plugin) +natoms=0 +numatoms=molnatoms(natoms) +fname="../../test/md.gro" +ftype="gro" + +pluginhandle = mylib.open_file_read(plugin, fname, ftype, natoms) +print("This passed") +print(pluginhandle) +print("This passed too") +print(pluginhandle.natoms) +print("Here") + +x = numpy.array([ + ('C1','C','ACE',0,'','','','',1.0,1.0,12.011,6,1.0,6), + ('C2','C','ACE',0,'','','','',1.0,1.0,12.011,6,1.0,6) + ], + dtype=[ + ('name', 'S16'), ('type', 'S16'), ('resname', 'S8'), + ('resid', 'i4'), ('segid', 'S8'), ('chain', 'S2'), + ('altloc', 'S2'), ('insertion', 'S2'), ('occupancy', 'f8'), + ('bfactor', 'f8'), ('mass', 'f8'), ('charge', 'f8'), + ('radius', 'f8'), ('atomicnumber', 'i4') + ] + ) +print(x) +print(x.__array_interface__) +print(x.__array_interface__["descr"]) +print(x.__array_struct__) +#y = mylib.read_fill_structure(pluginhandle, x) +y = mylib.print_array_struct(x) +print('Test') +print(y) +#outarray = mylib.get_structure(pluginhandle) +#print(outarray) +#print(type(outarray)) +#for i in outarray: +# print(i) + + diff --git a/pymolfile/molfile/_libpymolfile.so b/pymolfile/molfile/_libpymolfile.so index afa3e0a62a50fd7b2efa0c76eae1d2fedf08d253..26d6964a955d12f5da6de48551627239aeb0e3f0 100755 Binary files a/pymolfile/molfile/_libpymolfile.so and b/pymolfile/molfile/_libpymolfile.so differ diff --git a/pymolfile/molfile/_libpymolfile.so.dSYM/Contents/Resources/DWARF/_libpymolfile.so b/pymolfile/molfile/_libpymolfile.so.dSYM/Contents/Resources/DWARF/_libpymolfile.so index d66b822ee7cd1186e842d1ef8fbd9025fe68b6cb..2cf277f2af4c15b5ae011b054defceabfd4abbcc 100644 Binary files a/pymolfile/molfile/_libpymolfile.so.dSYM/Contents/Resources/DWARF/_libpymolfile.so and b/pymolfile/molfile/_libpymolfile.so.dSYM/Contents/Resources/DWARF/_libpymolfile.so differ diff --git a/pymolfile/molfile/_numpy_swig.so b/pymolfile/molfile/_numpy_swig.so new file mode 100755 index 0000000000000000000000000000000000000000..e5907947a6fe702d7cf89b0bce5fbfeaa9ae1da5 Binary files /dev/null and b/pymolfile/molfile/_numpy_swig.so differ diff --git a/pymolfile/molfile/compile-numind.sh b/pymolfile/molfile/compile-numind.sh new file mode 100644 index 0000000000000000000000000000000000000000..680fa4e374146e23eaab3a4e15e25c120176b42a --- /dev/null +++ b/pymolfile/molfile/compile-numind.sh @@ -0,0 +1,2 @@ +Cython -a numind.pyx --cplus +g++ -fPIC -Wall -Wextra -Wunused-function -shared -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ numind.cpp -o numind.so -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 diff --git a/pymolfile/molfile/compile-signedintbuf.sh b/pymolfile/molfile/compile-signedintbuf.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f50f7763eddada6c420b8db79e195be290d4c4c --- /dev/null +++ b/pymolfile/molfile/compile-signedintbuf.sh @@ -0,0 +1,2 @@ +swig -py3 -Wall -c++ -python numpy_swig.i +g++ -fPIC -Wall -Wextra -Wunused-function -shared -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ -I. numpy_swig_wrap.cxx -o _numpy_swig.so -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 diff --git a/pymolfile/molfile/compile.sh b/pymolfile/molfile/compile.sh index f25b34aa0c231d999945e434aee1d9029f22b487..dd69ffe6f6f83e075e01fc39e101ccd2558e9a7d 100644 --- a/pymolfile/molfile/compile.sh +++ b/pymolfile/molfile/compile.sh @@ -1,2 +1,2 @@ swig -py3 -Wall -c++ -python libpymolfile.i -g++ -fPIC -Wall -Wextra -Wunused-function -shared -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ -I. libpymolfile_wrap.cxx pymolfile.c -o _libpymolfile.so -Ivmd_molfile_plugins/include/ -Ilib/ -L. lib/libmolfile_plugin.a -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 +g++ -fPIC -Wall -Wextra -Wunused-function -shared -g -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ -I. libpymolfile_wrap.cxx pymolfile.c -o _libpymolfile.so -Ivmd_molfile_plugins/include/ -Ilib/ -L. lib/libmolfile_plugin.a -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 diff --git a/pymolfile/molfile/libpymolfile-backup2.i b/pymolfile/molfile/libpymolfile-backup2.i new file mode 100644 index 0000000000000000000000000000000000000000..52b95f6bdf79a1c87b59f123937173415421c80c --- /dev/null +++ b/pymolfile/molfile/libpymolfile-backup2.i @@ -0,0 +1,576 @@ +/* -*- C -*- (not really, but good for syntax highlighting) */ +/* SWIG interface for libpymolfile of VMD molfile_plugins + Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk> + Published under UIUC LICENSE + + swig -c++ -python -outdir . molfile/libpymolfile.i +*/ +%define DOCSTRING +" +:Author: Berk Onat <b.onat@warwick.ac.uk> +:Year: 2017 +:Licence: UIUC LICENSE + + +" +%enddef + +%module(docstring=DOCSTRING) libpymolfile + + +%{ +/* Python SWIG interface to libpymolfile + Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk> + Published under BSD LICENSE + */ +#define SWIG_FILE_WITH_INIT +#define __STDC_FORMAT_MACROS +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <inttypes.h> +#include "molfile_plugin.h" +#include "libmolfile_plugin.h" +#include "vmdplugin.h" +#include "pymolfile.h" +%} + +%include "numpy.i" + +%init %{ +Py_Initialize(); +import_array(); +%} + + +/* + Wrapping only high-level plugin functions to register VMD + plugins and to retrive the data through molfile_plugin interface. + + Only modifing call signatures. This will help one to access functions + without dealing with pointers from python. +*/ + + +/* plugin status codes for error handling */ +enum { pluginOK, pluginNOINIT, pluginCLOSE, pluginNOMEM, + pluginENDOFFILE, pluginFILENOTFOUND, pluginFORMATERROR }; + + +/* Definition of molfile_atoms_t from molfile_plugin.h */ +%inline %{ + +/* +struct MolAtoms { + char name[16]; + char type[16]; + char resname[8]; + int resid; + char segid[8]; + char chain[2]; + char altloc[2]; + char insertion[2]; + float occupancy; + float bfactor; + float mass; + float charge; + float radius; + float atomicnumber; + float ctnumber; +}; + +void del_plugin_structure(PyObject* pymolfile_atoms){ + delete (MolAtoms*)PyCapsule_GetPointer(pymolfile_atoms, "plugin_structure"); +} + +static PyObject* alloc_plugin_structure(PyObject *self, PyObject *args) { + return PyCapsule_New((void*)new MolAtoms(), "plugin_structure", del_plugin_structure); +} +*/ +void del_plugin(PyObject* pymolfile_plugin){ + delete (MolObject*)PyCapsule_GetPointer(pymolfile_plugin, "plugin"); +} + +void del_atoms(PyObject* pymolfile_atoms){ + delete (PyObject*)PyCapsule_GetPointer(pymolfile_atoms, "atoms"); +} + +void del_atomname(PyObject* pymolfile_atoms){ + delete (PyObject*)PyCapsule_GetPointer(pymolfile_atoms, "atomname"); +} + + +static PyObject* alloc_plugin(PyObject *self, PyObject *args) { + return PyCapsule_New((void*)new MolObject(), "plugin_handle", del_plugin); +} + +%} + + +/* pymolfile.c + initialize and finalize molfile plugins +*/ +%feature("autodoc", "0") molfile_plugin_list; +extern molfile_plugin_t** molfile_plugin_list(int maxsize); + +%feature("autodoc", "0") molfile_init; +extern int molfile_init(void); + +%feature("autodoc", "0") molfile_finish; +extern int molfile_finish(void); + +%feature("autodoc", "0") get_plugin; +extern molfile_plugin_t* get_plugin(molfile_plugin_t** plugin_list, int plugin_no); + +%feature("autodoc", "0") molfile_plugin_info; +%exception molfile_plugin_info { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * molfile_plugin_info(molfile_plugin_t** plugin_list, int plugin_no) { + molfile_plugin_t *plugin; + int *plugno = &plugin_no; + int has_readstructure = 0; + int has_readbonds = 0; + int has_readangles = 0; + int has_writestructure = 0; + int has_writebonds = 0; + int has_writeangles = 0; + int has_readnexttimestep = 0; + int has_writetimestep = 0; + int plugin_list_size = sizeof(plugin_list) / sizeof(molfile_plugin_t**); + if (plugno==NULL || plugin_no<0){ + PyErr_Format(PyExc_IOError, "[%d] Error: molfile plugin handle no should be given, be positive value and should not exceed the list length'%d'. You set '%d'", pluginNOINIT, plugin_list_size, plugin_no); + return 0; + } + plugin = plugin_list[plugin_no]; + if(plugin==NULL || !plugin->open_file_read){ + PyErr_Format(PyExc_IOError, "[%d] Error: molfile plugin '%d' is not initialized.", pluginNOINIT, plugin_no); + return 0; + } + if (plugin->read_structure) has_readstructure = 1; + if (plugin->read_bonds) has_readbonds = 1; + if (plugin->read_angles) has_readangles = 1; + if (plugin->read_next_timestep) has_readnexttimestep = 1; + if (plugin->write_structure) has_writestructure = 1; + if (plugin->write_bonds) has_writebonds = 1; + if (plugin->write_angles) has_writeangles = 1; + if (plugin->write_timestep) has_writetimestep = 1; + PyObject *tuple = PyTuple_New(17); + PyTuple_SET_ITEM(tuple, 0, PyString_FromString(plugin->filename_extension)); + PyTuple_SET_ITEM(tuple, 1, PyString_FromString(plugin->name)); + PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong((long)has_readstructure)); + PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong((long)has_readbonds)); + PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong((long)has_readangles)); + PyTuple_SET_ITEM(tuple, 5, PyInt_FromLong((long)has_readnexttimestep)); + PyTuple_SET_ITEM(tuple, 6, PyInt_FromLong((long)has_writestructure)); + PyTuple_SET_ITEM(tuple, 7, PyInt_FromLong((long)has_writebonds)); + PyTuple_SET_ITEM(tuple, 8, PyInt_FromLong((long)has_writeangles)); + PyTuple_SET_ITEM(tuple, 9, PyInt_FromLong((long)has_writetimestep)); + PyTuple_SET_ITEM(tuple, 10, PyString_FromString(plugin->prettyname)); + PyTuple_SET_ITEM(tuple, 11, PyString_FromString(plugin->type)); + PyTuple_SET_ITEM(tuple, 12, PyString_FromString(plugin->author)); + PyTuple_SET_ITEM(tuple, 13, PyInt_FromLong((long)plugin->majorv)); + PyTuple_SET_ITEM(tuple, 14, PyInt_FromLong((long)plugin->minorv)); + PyTuple_SET_ITEM(tuple, 15, PyInt_FromLong((long)plugin->abiversion)); + PyTuple_SET_ITEM(tuple, 16, PyInt_FromLong((long)plugin->is_reentrant)); + return tuple; + } +%} + + +%feature("autodoc", "0") my_open_file_read; +%rename (open_file_read) my_open_file_read; +%exception my_open_file_read { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * my_open_file_read(molfile_plugin_t* plugin, char* fname, char* ftype, int natoms) { + if (PyType_Ready(&MolObjectType) < 0) + return NULL; + PyTypeObject *type = &MolObjectType; + /*plugin_handle = PyCapsule_New((void*)new MolObject(), "plugin", del_plugin); */ + /*MolObject* plugin_c = new MolObject;*/ + MolObject *plugin_c; + plugin_c = (MolObject *)type->tp_alloc(type, 0); + /*PyObject * plugin_c = MolObject_new(&MolObjectType, args, kwds);*/ + plugin_c->plugin = plugin; + plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms); + plugin_c->natoms = natoms; + /* PyCapsule_SetPointer(plugin_handle, &plugin_c); */ + /* PyObject* plugin_handle = PyCapsule_New((void*)plugin_c, "plugin", del_plugin); */ + PyObject* plugin_handle = (PyObject *)plugin_c; + /*if(!plugin_handle) printf("Not assigned\n");*/ + /*PyObject *tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms)); + PyTuple_SET_ITEM(tuple, 1, plugin_handle);*/ + return plugin_handle; + } +%} + +/* +%typemap( argout ) ( char **MolfileAtomT_CharArray ) +{ + // The result variable is the return value from + // c_ephcom_read_constants, the number of actual values that are + // defined for cnames/values. + npy_intp dims[] = { result }; + PyArray_Dims newshape_location; + PyArray_Dims * newshape = &newshape_location; + PyObject * status_check; + newshape->len = 1; + newshape->ptr = dims; + + // resize array$argnum to actual size needed. + // Follow directions at http://www.mail-archive.com/numpy-discussion@scipy.org/msg13013.html + status_check = PyArray_Resize( (PyArrayObject *) array$argnum, newshape, 0, NPY_CORDER ); + if ( !status_check ) + SWIG_fail; + Py_DECREF( status_check ); + $result = SWIG_Python_AppendOutput( $result, array$argnum ); +} +%typemap( freearg ) ( char **MolfileAtomT_CharArray ) +{ + free( $1 ); +} +*/ + +/* +#define DIM 3 +typedef int imatrix[DIM][DIM]; +typedef int ivec[DIM]; +typedef float fmatrix[DIM][DIM]; +typedef float fvec[DIM]; +*/ + +/* Reading from xdr files */ +/* +%apply (float INPLACE_ARRAY2[ANY][ANY]) {(matrix box)} +%apply (int DIM1, int DIM2, float* INPLACE_ARRAY2) {(int natoms, int _DIM, float *x), + (int vnatoms, int v_DIM, float *v), + (int fnatoms, int f_DIM, float *f)} +*/ +/* +%apply (int INPLACE_IARRAY2[ANY][ANY]) {(imatrix intdata)} +%apply (float INPLACE_FARRAY2[ANY][ANY]) {(fmatrix floatdata)} +%apply (int DIM1, int* INPLACE_IARRAY2) {(int rnatoms, int* MolAtom_resid)} +%apply (int DIM1, float* INPLACE_FARRAY2) {(int mnatoms, float* MolAtom_mass), + (int anatoms, float* MolAtom_atomicnumber)} +*/ +/* +%inline %{ +int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options, + int* natoms, char** MolAtom_name, + int* natoms, char** MolAtom_type, + int* natoms, char** MolAtom_resname, + int* natoms, int** MolAtom_resid, + int* natoms, char** MolAtom_segid, + int* natoms, char** MolAtom_chain, + int* natoms, char** MolAtom_altloc, + int* natoms, char** MolAtom_insertion, + int* natoms, float** MolAtom_occupancy, + int* natoms, float** MolAtom_bfactor, + int* natoms, float** MolAtom_mass, + int* natoms, float** MolAtom_charge, + int* natoms, float** MolAtom_radius, + int* natoms, float** MolAtom_atomicnumber, + int* natoms, float** MolAtom_ctnumber) { + molfile_atom_t* atoms; + atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t)); + plugin->read_structure(fhandle, options, atoms); + MolAtom_name = (char **)malloc(natoms,sizeof(char*)); + MolAtom_type = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resname = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resid = (int **)malloc(natoms,sizeof(int*)); +%} +*/ +/* +%inline %{ +int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options, + int natoms, char** MolAtom_name, + int tnatoms, char** MolAtom_type, + int rnatoms, int* MolAtom_resid, + int mnatoms, float* MolAtom_mass, + int anatoms, float* MolAtom_atomicnumber) { + int i; + molfile_atom_t* atoms; + molfile_atom_t atm; + atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t)); + plugin->read_structure(fhandle, options, atoms); + if(atoms == NULL) { free(atoms); return 1; } + if(atoms->type == NULL || atoms->name == NULL){ free(atoms); return 1; } + MolAtom_name = (char **)malloc(natoms,sizeof(char*)); + MolAtom_type = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resid = (int *)malloc(natoms,sizeof(int)); + MolAtom_mass = (float *)malloc(natoms,sizeof(float)); + MolAtom_atomicnumber = (float *)malloc(natoms,sizeof(float)); + for (i=0;i<natoms;i++){ + atm = atoms[i]; + MolAtom_name[i] = atm.name; + MolAtom_type[i] = atm.type; + MolAtom_resid[i] = atm.resid; + MolAtom_mass[i] = atm.mass; + MolAtom_atomicnumber[i] = atm.atomicnumber; + } + return 0; + } +%} +*/ + +%feature("autodoc", "0") my_read_structure; +%rename (read_structure) my_read_structure; +extern PyObject * my_read_structure(PyObject* molpack); + +%feature("autodoc", "0") get_structure; +extern PyObject * get_structure(PyObject* molpack); + +/* +%feature("autodoc", "0") my_read_structure; +%rename (read_structure) my_read_structure; +%exception my_read_structure { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * my_read_structure(PyObject* molpack) { + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* atoms; + int numatoms, status; + char** atom_names; + char** atom_types; + PyObject *npatoms = NULL; */ + /*MolObject* plugin_handle = (MolObject*)PyCapsule_GetPointer(molpack, "plugin");*/ +/* MolObject* plugin_handle = (MolObject*)molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + printf("Test1\n"); + status = plugin->read_structure(file_handle, &options, atoms); + printf("Test2 %d\n",status); + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python."); + return NULL; + } + printf("Test3\n"); + npy_intp natoms[1] = { numatoms }; + + PyArrayObject* oresid; + int64_t* cresid; + + int typenum; + int nd = 1; + npy_intp dims[1] = { numatoms }; */ + /*dims[0] = numatoms;*/ +/* oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); + npy_intp* n = PyArray_DIMS(oresid); + printf("dimensions %ld\n", n[0]); + cresid = (int64_t*) PyArray_DATA(oresid); + + PyObject* npatomresid = NULL; + char** MolAtom_name = (char **)malloc(numatoms*sizeof(char*)); + char** MolAtom_type = (char **)malloc(numatoms*sizeof(char*)); + int64_t* MolAtom_resid = NULL; */ + /*int64_t* MolAtom_resid = (int64_t *)malloc(numatoms*sizeof(int64_t));*/ +/* float* MolAtom_mass = (float *)malloc(numatoms*sizeof(float)); + float* MolAtom_atomicnumber = (float *)malloc(numatoms*sizeof(float)); + for (i=0;i<numatoms;i++){ + MolAtom_name[i] = atoms[i].name; + MolAtom_type[i] = atoms[i].type; + cresid[i] = (int64_t) atoms[i].resid; + MolAtom_mass[i] = atoms[i].mass; + MolAtom_atomicnumber[i] = atoms[i].atomicnumber; + } */ + /*Py_DECREF( obj );*/ + /*npy_intp dims[3];*/ /* PyArray_AsCArray is for ndim <= 3 */ +/* PyArray_Descr *descr; + npatoms = PyArray_SimpleNewFromData(1, natoms, NPY_USERDEF, atoms); + printf("Test4 numatoms=%d\n", numatoms); + PyObject* npatomname = NULL; + npatomname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_name[0]); + PyObject* npatomtype = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_type); */ + /*PyObject* npatomresname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->resname);*/ + /*PyObject* npatomsegid = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->segid);*/ + /*PyObject* npatomchain = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->chain);*/ + /*PyObject* npatomaltloc = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->altloc);*/ + /*PyObject* npatominsert = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->insertion);*/ + /*PyObject* npatomoccup = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->occupancy);*/ + /*PyObject* npatombfact = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->bfactor);*/ +/* PyObject* npatommass = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, MolAtom_mass); */ + /*PyObject* npatomcharge = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->charge);*/ + /*PyObject* npatomradius = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->radius);*/ +/* PyObject* npatomicnumber = PyArray_SimpleNewFromData(1, natoms, NPY_INT64, MolAtom_atomicnumber); */ + /*if (npatomname==NULL || npatomtype==NULL || npatomresname==NULL || + npatomresid==NULL || npatomsegid==NULL || npatomchain==NULL ) + { + free(atoms); + Py_XDECREF(npatomname); Py_XDECREF(npatomtype); + Py_XDECREF(npatomresname); Py_XDECREF(npatomresid); Py_XDECREF(npatomsegid); + Py_XDECREF(npatomchain); Py_XDECREF(npatomaltloc); Py_XDECREF(npatominsert); + Py_XDECREF(npatomoccup); Py_XDECREF(npatombfact); Py_XDECREF(npatommass); + Py_XDECREF(npatomcharge); Py_XDECREF(npatomradius); Py_XDECREF(npatomicnumber); + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python."); + return 0; + } + PyArray_BASE(npatomname) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomtype) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomresname) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomresid) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomsegid) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomchain) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomaltloc) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatominsert) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomoccup) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatombfact) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatommass) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomcharge) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomradius) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomicnumber) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatoms) = PyCObject_FromVoidPtr(atoms, free); + PyArray_BASE((PyArrayObject *)npatoms) = PyCapsule_New(atoms, "atoms", del_atoms);*/ + /*PyArray_BASE((PyArrayObject *)npatoms); */ +/* printf("Test4-2\n"); */ + /*PyObject* Py_MolAtom_name = PyCapsule_New((void*)MolAtom_name, "atomname", del_atomname);*/ + /*PyObject* Py_MolAtom_name; + Py_INCREF(Py_MolAtom_name);*/ +/* printf("Test4-3\n"); */ + /*PyArray_SetBaseObject((PyArrayObject *)npatomname, Py_MolAtom_name);*/ + /*PyArray_SetBaseObject((PyArrayObject *)npatomtype, MolAtom_type); + PyArray_SetBaseObject((PyArrayObject *)npatomresid, MolAtom_resid); + PyArray_SetBaseObject((PyArrayObject *)npatommass, MolAtom_mass); + PyArray_SetBaseObject((PyArrayObject *)npatomicnumber, MolAtom_atomicnumber); */ +/* printf("Test5\n"); + PyObject *tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms)); + printf("Test6\n"); + PyTuple_SET_ITEM(tuple, 1, npatomname); */ + /*PyTuple_SET_ITEM(tuple, 2, npatomtype); + PyTuple_SET_ITEM(tuple, 3, npatomresid); + PyTuple_SET_ITEM(tuple, 4, npatommass); + PyTuple_SET_ITEM(tuple, 5, npatomicnumber); + PyObject* vars = PyDict_New(); + printf("Test7\n"); + PyDict_SetItemString( vars, "name", npatomname ); */ +/* printf("Test8\n"); */ + /*PyDict_SetItemString( vars, "resid", npatomresid ); */ + /*return Py_BuildValue("O", oresid); */ + /*return PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0);*/ +/* return 0; + } +%} +*/ + + +/* + python wrappers for functions + and structure data in molfile_plugin.h +*/ + +/* molfile_atom_t + + char name[16]; required atom name string + char type[16]; required atom type string + char resname[8]; required residue name string + int resid; required integer residue ID + char segid[8]; required segment name string, or "" + char chain[2]; required chain name, or "" + char altloc[2]; optional PDB alternate location code + char insertion[2]; optional PDB insertion code + float occupancy; optional occupancy value + float bfactor; optional B-factor value + float mass; optional mass value + float charge; optional charge value + float radius; optional radius value + int atomicnumber; optional element atomic number + int ctnumber; mae ct block, 0-based, including meta +*/ + + +/* molfile_plugin_t */ + +/* +%feature("autodoc", "0") molfile_open_file_read; +%rename (open_file_read) molfile_open_file_read; +%exception molfile_open_file_read { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * molfile_open_file_read(molfile_plugin_t* plugin, char *fname, int natoms) { + int *plugno = &plugin_no; + return plugin; + } +%} +*/ +/* + void *(* open_file_read)(const char *filepath, const char *filetype, + int *natoms); + void (* close_file_read)(void *); + int (*read_structure)(void *, int *optflags, molfile_atom_t *atoms); + int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder, + int **bondtype, int *nbondtypes, char ***bondtypename); + int (* read_next_timestep)(void *, int natoms, molfile_timestep_t *); + void *(* open_file_write)(const char *filepath, const char *filetype, + int natoms); + int (* write_structure)(void *, int optflags, const molfile_atom_t *atoms); + int (* write_timestep)(void *, const molfile_timestep_t *); + void (* close_file_write)(void *); + int (* read_molecule_metadata)(void *, molfile_metadata_t **metadata); + int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder, + int *bondtype, int nbondtypes, char **bondtypename); + int (* read_angles)(void *handle, int *numangles, int **angles, int **angletypes, + int *numangletypes, char ***angletypenames, int *numdihedrals, + int **dihedrals, int **dihedraltypes, int *numdihedraltypes, + char ***dihedraltypenames, int *numimpropers, int **impropers, + int **impropertypes, int *numimpropertypes, char ***impropertypenames, + int *numcterms, int **cterms, int *ctermcols, int *ctermrows); + int (* write_angles)(void *handle, int numangles, const int *angles, const int *angletypes, + int numangletypes, const char **angletypenames, int numdihedrals, + const int *dihedrals, const int *dihedraltypes, int numdihedraltypes, + const char **dihedraltypenames, int numimpropers, + const int *impropers, const int *impropertypes, int numimpropertypes, + const char **impropertypenames, int numcterms, const int *cterms, + int ctermcols, int ctermrows); + int (* read_timestep)(void *, int natoms, molfile_timestep_t *, + molfile_qm_metadata_t *, molfile_qm_timestep_t *); + int (* read_timestep_metadata)(void *, molfile_timestep_metadata_t *); + int (* read_timestep2)(void *, molfile_ssize_t index, molfile_timestep_t *); + molfile_ssize_t (* read_times)( void *, + molfile_ssize_t start, + molfile_ssize_t count, + double * times ); + int (* cons_fputs)(const int, const char*); +*/ + + +/* molfile_timestep_t + + float *coords; coordinates of all atoms, arranged xyzxyzxyz + float *velocities; space for velocities of all atoms; same layout + float A, B, C, alpha, beta, gamma; + double physical_time; physical time point associated with this frame + + double total_energy; + double potential_energy; + double kinetic_energy; + double extended_energy; + double force_energy; + double total_pressure; +*/ + + +/* molfile_timestep_metadata_t + + unsigned int count; total # timesteps; -1 if unknown + unsigned int avg_bytes_per_timestep; bytes per timestep + int has_velocities; if timesteps have velocities +*/ + + + diff --git a/pymolfile/molfile/libpymolfile-new.i b/pymolfile/molfile/libpymolfile-new.i new file mode 100644 index 0000000000000000000000000000000000000000..65670f340a9e40ea61838eea0bb61888aac567bf --- /dev/null +++ b/pymolfile/molfile/libpymolfile-new.i @@ -0,0 +1,578 @@ +/* -*- C -*- (not really, but good for syntax highlighting) */ +/* SWIG interface for libpymolfile of VMD molfile_plugins + Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk> + Published under UIUC LICENSE + + swig -c++ -python -outdir . molfile/libpymolfile.i +*/ +%define DOCSTRING +" +:Author: Berk Onat <b.onat@warwick.ac.uk> +:Year: 2017 +:Licence: UIUC LICENSE + + +" +%enddef + +%module(docstring=DOCSTRING) libpymolfile + + +%{ +/* Python SWIG interface to libpymolfile + Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk> + Published under BSD LICENSE + */ +#define SWIG_FILE_WITH_INIT +#define __STDC_FORMAT_MACROS +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <inttypes.h> +#include "molfile_plugin.h" +#include "libmolfile_plugin.h" +#include "vmdplugin.h" +#include "pymolfile.h" +%} + +%include "numpy.i" + +%init %{ +Py_Initialize(); +import_array(); +%} + + +/* + Wrapping only high-level plugin functions to register VMD + plugins and to retrive the data through molfile_plugin interface. + + Only modifing call signatures. This will help one to access functions + without dealing with pointers from python. +*/ + + +/* plugin status codes for error handling */ +enum { pluginOK, pluginNOINIT, pluginCLOSE, pluginNOMEM, + pluginENDOFFILE, pluginFILENOTFOUND, pluginFORMATERROR }; + + +/* Definition of molfile_atoms_t from molfile_plugin.h */ +%inline %{ + +/* +struct MolAtoms { + char name[16]; + char type[16]; + char resname[8]; + int resid; + char segid[8]; + char chain[2]; + char altloc[2]; + char insertion[2]; + float occupancy; + float bfactor; + float mass; + float charge; + float radius; + float atomicnumber; + float ctnumber; +}; + +void del_plugin_structure(PyObject* pymolfile_atoms){ + delete (MolAtoms*)PyCapsule_GetPointer(pymolfile_atoms, "plugin_structure"); +} + +static PyObject* alloc_plugin_structure(PyObject *self, PyObject *args) { + return PyCapsule_New((void*)new MolAtoms(), "plugin_structure", del_plugin_structure); +} +*/ +void del_plugin(PyObject* pymolfile_plugin){ + delete (MolObject*)PyCapsule_GetPointer(pymolfile_plugin, "plugin"); +} + +void del_atoms(PyObject* pymolfile_atoms){ + delete (PyObject*)PyCapsule_GetPointer(pymolfile_atoms, "atoms"); +} + +void del_atomname(PyObject* pymolfile_atoms){ + delete (PyObject*)PyCapsule_GetPointer(pymolfile_atoms, "atomname"); +} + + +static PyObject* alloc_plugin(PyObject *self, PyObject *args) { + return PyCapsule_New((void*)new MolObject(), "plugin_handle", del_plugin); +} + +%} + + +/* pymolfile.c + initialize and finalize molfile plugins +*/ +%feature("autodoc", "0") molfile_plugin_list; +extern molfile_plugin_t** molfile_plugin_list(int maxsize); + +%feature("autodoc", "0") molfile_init; +extern int molfile_init(void); + +%feature("autodoc", "0") molfile_finish; +extern int molfile_finish(void); + +%feature("autodoc", "0") get_plugin; +extern molfile_plugin_t* get_plugin(molfile_plugin_t** plugin_list, int plugin_no); + +%feature("autodoc", "0") molfile_plugin_info; +%exception molfile_plugin_info { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * molfile_plugin_info(molfile_plugin_t** plugin_list, int plugin_no) { + molfile_plugin_t *plugin; + int *plugno = &plugin_no; + int has_readstructure = 0; + int has_readbonds = 0; + int has_readangles = 0; + int has_writestructure = 0; + int has_writebonds = 0; + int has_writeangles = 0; + int has_readnexttimestep = 0; + int has_writetimestep = 0; + int plugin_list_size = sizeof(plugin_list) / sizeof(molfile_plugin_t**); + if (plugno==NULL || plugin_no<0){ + PyErr_Format(PyExc_IOError, "[%d] Error: molfile plugin handle no should be given, be positive value and should not exceed the list length'%d'. You set '%d'", pluginNOINIT, plugin_list_size, plugin_no); + return 0; + } + plugin = plugin_list[plugin_no]; + if(plugin==NULL || !plugin->open_file_read){ + PyErr_Format(PyExc_IOError, "[%d] Error: molfile plugin '%d' is not initialized.", pluginNOINIT, plugin_no); + return 0; + } + if (plugin->read_structure) has_readstructure = 1; + if (plugin->read_bonds) has_readbonds = 1; + if (plugin->read_angles) has_readangles = 1; + if (plugin->read_next_timestep) has_readnexttimestep = 1; + if (plugin->write_structure) has_writestructure = 1; + if (plugin->write_bonds) has_writebonds = 1; + if (plugin->write_angles) has_writeangles = 1; + if (plugin->write_timestep) has_writetimestep = 1; + PyObject *tuple = PyTuple_New(17); + PyTuple_SET_ITEM(tuple, 0, PyString_FromString(plugin->filename_extension)); + PyTuple_SET_ITEM(tuple, 1, PyString_FromString(plugin->name)); + PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong((long)has_readstructure)); + PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong((long)has_readbonds)); + PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong((long)has_readangles)); + PyTuple_SET_ITEM(tuple, 5, PyInt_FromLong((long)has_readnexttimestep)); + PyTuple_SET_ITEM(tuple, 6, PyInt_FromLong((long)has_writestructure)); + PyTuple_SET_ITEM(tuple, 7, PyInt_FromLong((long)has_writebonds)); + PyTuple_SET_ITEM(tuple, 8, PyInt_FromLong((long)has_writeangles)); + PyTuple_SET_ITEM(tuple, 9, PyInt_FromLong((long)has_writetimestep)); + PyTuple_SET_ITEM(tuple, 10, PyString_FromString(plugin->prettyname)); + PyTuple_SET_ITEM(tuple, 11, PyString_FromString(plugin->type)); + PyTuple_SET_ITEM(tuple, 12, PyString_FromString(plugin->author)); + PyTuple_SET_ITEM(tuple, 13, PyInt_FromLong((long)plugin->majorv)); + PyTuple_SET_ITEM(tuple, 14, PyInt_FromLong((long)plugin->minorv)); + PyTuple_SET_ITEM(tuple, 15, PyInt_FromLong((long)plugin->abiversion)); + PyTuple_SET_ITEM(tuple, 16, PyInt_FromLong((long)plugin->is_reentrant)); + return tuple; + } +%} + + +%feature("autodoc", "0") my_open_file_read; +%rename (open_file_read) my_open_file_read; +%exception my_open_file_read { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * my_open_file_read(molfile_plugin_t* plugin, char* fname, char* ftype, int natoms) { + if (PyType_Ready(&MolObjectType) < 0) + return NULL; + PyTypeObject *type = &MolObjectType; + /*plugin_handle = PyCapsule_New((void*)new MolObject(), "plugin", del_plugin); */ + /*MolObject* plugin_c = new MolObject;*/ + MolObject *plugin_c; + plugin_c = (MolObject *)type->tp_alloc(type, 0); + /*PyObject * plugin_c = MolObject_new(&MolObjectType, args, kwds);*/ + plugin_c->plugin = plugin; + plugin_c->file_handle = plugin->open_file_read(fname, ftype, &natoms); + plugin_c->natoms = natoms; + /* PyCapsule_SetPointer(plugin_handle, &plugin_c); */ + /* PyObject* plugin_handle = PyCapsule_New((void*)plugin_c, "plugin", del_plugin); */ + PyObject* plugin_handle = (PyObject *)plugin_c; + /*if(!plugin_handle) printf("Not assigned\n");*/ + /*PyObject *tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms)); + PyTuple_SET_ITEM(tuple, 1, plugin_handle);*/ + return plugin_handle; + } +%} + +/* +%typemap( argout ) ( char **MolfileAtomT_CharArray ) +{ + // The result variable is the return value from + // c_ephcom_read_constants, the number of actual values that are + // defined for cnames/values. + npy_intp dims[] = { result }; + PyArray_Dims newshape_location; + PyArray_Dims * newshape = &newshape_location; + PyObject * status_check; + newshape->len = 1; + newshape->ptr = dims; + + // resize array$argnum to actual size needed. + // Follow directions at http://www.mail-archive.com/numpy-discussion@scipy.org/msg13013.html + status_check = PyArray_Resize( (PyArrayObject *) array$argnum, newshape, 0, NPY_CORDER ); + if ( !status_check ) + SWIG_fail; + Py_DECREF( status_check ); + $result = SWIG_Python_AppendOutput( $result, array$argnum ); +} +%typemap( freearg ) ( char **MolfileAtomT_CharArray ) +{ + free( $1 ); +} +*/ + +/* +#define DIM 3 +typedef int imatrix[DIM][DIM]; +typedef int ivec[DIM]; +typedef float fmatrix[DIM][DIM]; +typedef float fvec[DIM]; +*/ + +/* Reading from xdr files */ +/* +%apply (float INPLACE_ARRAY2[ANY][ANY]) {(matrix box)} +%apply (int DIM1, int DIM2, float* INPLACE_ARRAY2) {(int natoms, int _DIM, float *x), + (int vnatoms, int v_DIM, float *v), + (int fnatoms, int f_DIM, float *f)} +*/ +/* +%apply (int INPLACE_IARRAY2[ANY][ANY]) {(imatrix intdata)} +%apply (float INPLACE_FARRAY2[ANY][ANY]) {(fmatrix floatdata)} +%apply (int DIM1, int* INPLACE_IARRAY2) {(int rnatoms, int* MolAtom_resid)} +%apply (int DIM1, float* INPLACE_FARRAY2) {(int mnatoms, float* MolAtom_mass), + (int anatoms, float* MolAtom_atomicnumber)} +*/ +/* +%inline %{ +int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options, + int* natoms, char** MolAtom_name, + int* natoms, char** MolAtom_type, + int* natoms, char** MolAtom_resname, + int* natoms, int** MolAtom_resid, + int* natoms, char** MolAtom_segid, + int* natoms, char** MolAtom_chain, + int* natoms, char** MolAtom_altloc, + int* natoms, char** MolAtom_insertion, + int* natoms, float** MolAtom_occupancy, + int* natoms, float** MolAtom_bfactor, + int* natoms, float** MolAtom_mass, + int* natoms, float** MolAtom_charge, + int* natoms, float** MolAtom_radius, + int* natoms, float** MolAtom_atomicnumber, + int* natoms, float** MolAtom_ctnumber) { + molfile_atom_t* atoms; + atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t)); + plugin->read_structure(fhandle, options, atoms); + MolAtom_name = (char **)malloc(natoms,sizeof(char*)); + MolAtom_type = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resname = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resid = (int **)malloc(natoms,sizeof(int*)); +%} +*/ +/* +%inline %{ +int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options, + int natoms, char** MolAtom_name, + int tnatoms, char** MolAtom_type, + int rnatoms, int* MolAtom_resid, + int mnatoms, float* MolAtom_mass, + int anatoms, float* MolAtom_atomicnumber) { + int i; + molfile_atom_t* atoms; + molfile_atom_t atm; + atoms = (molfile_atom_t *)calloc(natoms,sizeof(molfile_atom_t)); + plugin->read_structure(fhandle, options, atoms); + if(atoms == NULL) { free(atoms); return 1; } + if(atoms->type == NULL || atoms->name == NULL){ free(atoms); return 1; } + MolAtom_name = (char **)malloc(natoms,sizeof(char*)); + MolAtom_type = (char **)malloc(natoms,sizeof(char*)); + MolAtom_resid = (int *)malloc(natoms,sizeof(int)); + MolAtom_mass = (float *)malloc(natoms,sizeof(float)); + MolAtom_atomicnumber = (float *)malloc(natoms,sizeof(float)); + for (i=0;i<natoms;i++){ + atm = atoms[i]; + MolAtom_name[i] = atm.name; + MolAtom_type[i] = atm.type; + MolAtom_resid[i] = atm.resid; + MolAtom_mass[i] = atm.mass; + MolAtom_atomicnumber[i] = atm.atomicnumber; + } + return 0; + } +%} +*/ + +%feature("autodoc", "0") my_read_structure; +%rename (read_structure) my_read_structure; +extern PyObject * my_read_structure(PyObject* molpack); + +%feature("autodoc", "0") get_structure; +extern PyObject * get_structure(PyObject* molpack); + +%feature("autodoc", "0") read_fill_structure; +extern PyObject * read_fill_structure(PyObject* molpack, PyObject* prototype); +/* +%feature("autodoc", "0") my_read_structure; +%rename (read_structure) my_read_structure; +%exception my_read_structure { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * my_read_structure(PyObject* molpack) { + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* atoms; + int numatoms, status; + char** atom_names; + char** atom_types; + PyObject *npatoms = NULL; */ + /*MolObject* plugin_handle = (MolObject*)PyCapsule_GetPointer(molpack, "plugin");*/ +/* MolObject* plugin_handle = (MolObject*)molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + printf("Test1\n"); + status = plugin->read_structure(file_handle, &options, atoms); + printf("Test2 %d\n",status); + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python."); + return NULL; + } + printf("Test3\n"); + npy_intp natoms[1] = { numatoms }; + + PyArrayObject* oresid; + int64_t* cresid; + + int typenum; + int nd = 1; + npy_intp dims[1] = { numatoms }; */ + /*dims[0] = numatoms;*/ +/* oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); + npy_intp* n = PyArray_DIMS(oresid); + printf("dimensions %ld\n", n[0]); + cresid = (int64_t*) PyArray_DATA(oresid); + + PyObject* npatomresid = NULL; + char** MolAtom_name = (char **)malloc(numatoms*sizeof(char*)); + char** MolAtom_type = (char **)malloc(numatoms*sizeof(char*)); + int64_t* MolAtom_resid = NULL; */ + /*int64_t* MolAtom_resid = (int64_t *)malloc(numatoms*sizeof(int64_t));*/ +/* float* MolAtom_mass = (float *)malloc(numatoms*sizeof(float)); + float* MolAtom_atomicnumber = (float *)malloc(numatoms*sizeof(float)); + for (i=0;i<numatoms;i++){ + MolAtom_name[i] = atoms[i].name; + MolAtom_type[i] = atoms[i].type; + cresid[i] = (int64_t) atoms[i].resid; + MolAtom_mass[i] = atoms[i].mass; + MolAtom_atomicnumber[i] = atoms[i].atomicnumber; + } */ + /*Py_DECREF( obj );*/ + /*npy_intp dims[3];*/ /* PyArray_AsCArray is for ndim <= 3 */ +/* PyArray_Descr *descr; + npatoms = PyArray_SimpleNewFromData(1, natoms, NPY_USERDEF, atoms); + printf("Test4 numatoms=%d\n", numatoms); + PyObject* npatomname = NULL; + npatomname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_name[0]); + PyObject* npatomtype = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, MolAtom_type); */ + /*PyObject* npatomresname = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->resname);*/ + /*PyObject* npatomsegid = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->segid);*/ + /*PyObject* npatomchain = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->chain);*/ + /*PyObject* npatomaltloc = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->altloc);*/ + /*PyObject* npatominsert = PyArray_SimpleNewFromData(1, natoms, NPY_STRING, atoms->insertion);*/ + /*PyObject* npatomoccup = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->occupancy);*/ + /*PyObject* npatombfact = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->bfactor);*/ +/* PyObject* npatommass = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, MolAtom_mass); */ + /*PyObject* npatomcharge = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->charge);*/ + /*PyObject* npatomradius = PyArray_SimpleNewFromData(1, natoms, NPY_FLOAT64, &atoms->radius);*/ +/* PyObject* npatomicnumber = PyArray_SimpleNewFromData(1, natoms, NPY_INT64, MolAtom_atomicnumber); */ + /*if (npatomname==NULL || npatomtype==NULL || npatomresname==NULL || + npatomresid==NULL || npatomsegid==NULL || npatomchain==NULL ) + { + free(atoms); + Py_XDECREF(npatomname); Py_XDECREF(npatomtype); + Py_XDECREF(npatomresname); Py_XDECREF(npatomresid); Py_XDECREF(npatomsegid); + Py_XDECREF(npatomchain); Py_XDECREF(npatomaltloc); Py_XDECREF(npatominsert); + Py_XDECREF(npatomoccup); Py_XDECREF(npatombfact); Py_XDECREF(npatommass); + Py_XDECREF(npatomcharge); Py_XDECREF(npatomradius); Py_XDECREF(npatomicnumber); + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into Python."); + return 0; + } + PyArray_BASE(npatomname) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomtype) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomresname) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomresid) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomsegid) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomchain) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomaltloc) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatominsert) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomoccup) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatombfact) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatommass) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomcharge) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomradius) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatomicnumber) = PyCObject_FromVoidPtr(*atoms, free); + PyArray_BASE(npatoms) = PyCObject_FromVoidPtr(atoms, free); + PyArray_BASE((PyArrayObject *)npatoms) = PyCapsule_New(atoms, "atoms", del_atoms);*/ + /*PyArray_BASE((PyArrayObject *)npatoms); */ +/* printf("Test4-2\n"); */ + /*PyObject* Py_MolAtom_name = PyCapsule_New((void*)MolAtom_name, "atomname", del_atomname);*/ + /*PyObject* Py_MolAtom_name; + Py_INCREF(Py_MolAtom_name);*/ +/* printf("Test4-3\n"); */ + /*PyArray_SetBaseObject((PyArrayObject *)npatomname, Py_MolAtom_name);*/ + /*PyArray_SetBaseObject((PyArrayObject *)npatomtype, MolAtom_type); + PyArray_SetBaseObject((PyArrayObject *)npatomresid, MolAtom_resid); + PyArray_SetBaseObject((PyArrayObject *)npatommass, MolAtom_mass); + PyArray_SetBaseObject((PyArrayObject *)npatomicnumber, MolAtom_atomicnumber); */ +/* printf("Test5\n"); + PyObject *tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)natoms)); + printf("Test6\n"); + PyTuple_SET_ITEM(tuple, 1, npatomname); */ + /*PyTuple_SET_ITEM(tuple, 2, npatomtype); + PyTuple_SET_ITEM(tuple, 3, npatomresid); + PyTuple_SET_ITEM(tuple, 4, npatommass); + PyTuple_SET_ITEM(tuple, 5, npatomicnumber); + PyObject* vars = PyDict_New(); + printf("Test7\n"); + PyDict_SetItemString( vars, "name", npatomname ); */ +/* printf("Test8\n"); */ + /*PyDict_SetItemString( vars, "resid", npatomresid ); */ + /*return Py_BuildValue("O", oresid); */ + /*return PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0);*/ +/* return 0; + } +%} +*/ + + +/* + python wrappers for functions + and structure data in molfile_plugin.h +*/ + +/* molfile_atom_t + + char name[16]; required atom name string + char type[16]; required atom type string + char resname[8]; required residue name string + int resid; required integer residue ID + char segid[8]; required segment name string, or "" + char chain[2]; required chain name, or "" + char altloc[2]; optional PDB alternate location code + char insertion[2]; optional PDB insertion code + float occupancy; optional occupancy value + float bfactor; optional B-factor value + float mass; optional mass value + float charge; optional charge value + float radius; optional radius value + int atomicnumber; optional element atomic number + int ctnumber; mae ct block, 0-based, including meta +*/ + + +/* molfile_plugin_t */ + +/* +%feature("autodoc", "0") molfile_open_file_read; +%rename (open_file_read) molfile_open_file_read; +%exception molfile_open_file_read { + $action + if (PyErr_Occurred()) SWIG_fail; +} +%inline %{ +PyObject * molfile_open_file_read(molfile_plugin_t* plugin, char *fname, int natoms) { + int *plugno = &plugin_no; + return plugin; + } +%} +*/ +/* + void *(* open_file_read)(const char *filepath, const char *filetype, + int *natoms); + void (* close_file_read)(void *); + int (*read_structure)(void *, int *optflags, molfile_atom_t *atoms); + int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder, + int **bondtype, int *nbondtypes, char ***bondtypename); + int (* read_next_timestep)(void *, int natoms, molfile_timestep_t *); + void *(* open_file_write)(const char *filepath, const char *filetype, + int natoms); + int (* write_structure)(void *, int optflags, const molfile_atom_t *atoms); + int (* write_timestep)(void *, const molfile_timestep_t *); + void (* close_file_write)(void *); + int (* read_molecule_metadata)(void *, molfile_metadata_t **metadata); + int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder, + int *bondtype, int nbondtypes, char **bondtypename); + int (* read_angles)(void *handle, int *numangles, int **angles, int **angletypes, + int *numangletypes, char ***angletypenames, int *numdihedrals, + int **dihedrals, int **dihedraltypes, int *numdihedraltypes, + char ***dihedraltypenames, int *numimpropers, int **impropers, + int **impropertypes, int *numimpropertypes, char ***impropertypenames, + int *numcterms, int **cterms, int *ctermcols, int *ctermrows); + int (* write_angles)(void *handle, int numangles, const int *angles, const int *angletypes, + int numangletypes, const char **angletypenames, int numdihedrals, + const int *dihedrals, const int *dihedraltypes, int numdihedraltypes, + const char **dihedraltypenames, int numimpropers, + const int *impropers, const int *impropertypes, int numimpropertypes, + const char **impropertypenames, int numcterms, const int *cterms, + int ctermcols, int ctermrows); + int (* read_timestep)(void *, int natoms, molfile_timestep_t *, + molfile_qm_metadata_t *, molfile_qm_timestep_t *); + int (* read_timestep_metadata)(void *, molfile_timestep_metadata_t *); + int (* read_timestep2)(void *, molfile_ssize_t index, molfile_timestep_t *); + molfile_ssize_t (* read_times)( void *, + molfile_ssize_t start, + molfile_ssize_t count, + double * times ); + int (* cons_fputs)(const int, const char*); +*/ + + +/* molfile_timestep_t + + float *coords; coordinates of all atoms, arranged xyzxyzxyz + float *velocities; space for velocities of all atoms; same layout + float A, B, C, alpha, beta, gamma; + double physical_time; physical time point associated with this frame + + double total_energy; + double potential_energy; + double kinetic_energy; + double extended_energy; + double force_energy; + double total_pressure; +*/ + + +/* molfile_timestep_metadata_t + + unsigned int count; total # timesteps; -1 if unknown + unsigned int avg_bytes_per_timestep; bytes per timestep + int has_velocities; if timesteps have velocities +*/ + + + diff --git a/pymolfile/molfile/libpymolfile.i b/pymolfile/molfile/libpymolfile.i index b5027679e0b522b8f8a74398d4db4172ff9c30da..417756e0adc2b2b743d8f00a9b9253cf4c69ebf8 100644 --- a/pymolfile/molfile/libpymolfile.i +++ b/pymolfile/molfile/libpymolfile.i @@ -324,6 +324,15 @@ int structure_read(molfile_plugin_t* plugin, void* fhandle, int *options, %rename (read_structure) my_read_structure; extern PyObject * my_read_structure(PyObject* molpack); +%feature("autodoc", "0") get_structure; +extern PyObject * get_structure(PyObject* molpack); + +%feature("autodoc", "0") read_fill_structure; +extern PyObject * read_fill_structure(PyObject* molpack, PyObject* prototype); + +%feature("autodoc", "0") print_array_struct; +extern PyObject* print_array_struct(PyObject* prototype); + /* %feature("autodoc", "0") my_read_structure; %rename (read_structure) my_read_structure; diff --git a/pymolfile/molfile/libpymolfile.py b/pymolfile/molfile/libpymolfile.py index 504cde21c682b39139f1be654c5966b33f6d28d0..2d4dae89db09e9402dd5f6be677ff2960501bb90 100644 --- a/pymolfile/molfile/libpymolfile.py +++ b/pymolfile/molfile/libpymolfile.py @@ -113,92 +113,6 @@ pluginNOMEM = _libpymolfile.pluginNOMEM pluginENDOFFILE = _libpymolfile.pluginENDOFFILE pluginFILENOTFOUND = _libpymolfile.pluginFILENOTFOUND pluginFORMATERROR = _libpymolfile.pluginFORMATERROR -class MolAtoms(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MolAtoms, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MolAtoms, name) - __repr__ = _swig_repr - __swig_setmethods__["name"] = _libpymolfile.MolAtoms_name_set - __swig_getmethods__["name"] = _libpymolfile.MolAtoms_name_get - if _newclass: - name = _swig_property(_libpymolfile.MolAtoms_name_get, _libpymolfile.MolAtoms_name_set) - __swig_setmethods__["type"] = _libpymolfile.MolAtoms_type_set - __swig_getmethods__["type"] = _libpymolfile.MolAtoms_type_get - if _newclass: - type = _swig_property(_libpymolfile.MolAtoms_type_get, _libpymolfile.MolAtoms_type_set) - __swig_setmethods__["resname"] = _libpymolfile.MolAtoms_resname_set - __swig_getmethods__["resname"] = _libpymolfile.MolAtoms_resname_get - if _newclass: - resname = _swig_property(_libpymolfile.MolAtoms_resname_get, _libpymolfile.MolAtoms_resname_set) - __swig_setmethods__["resid"] = _libpymolfile.MolAtoms_resid_set - __swig_getmethods__["resid"] = _libpymolfile.MolAtoms_resid_get - if _newclass: - resid = _swig_property(_libpymolfile.MolAtoms_resid_get, _libpymolfile.MolAtoms_resid_set) - __swig_setmethods__["segid"] = _libpymolfile.MolAtoms_segid_set - __swig_getmethods__["segid"] = _libpymolfile.MolAtoms_segid_get - if _newclass: - segid = _swig_property(_libpymolfile.MolAtoms_segid_get, _libpymolfile.MolAtoms_segid_set) - __swig_setmethods__["chain"] = _libpymolfile.MolAtoms_chain_set - __swig_getmethods__["chain"] = _libpymolfile.MolAtoms_chain_get - if _newclass: - chain = _swig_property(_libpymolfile.MolAtoms_chain_get, _libpymolfile.MolAtoms_chain_set) - __swig_setmethods__["altloc"] = _libpymolfile.MolAtoms_altloc_set - __swig_getmethods__["altloc"] = _libpymolfile.MolAtoms_altloc_get - if _newclass: - altloc = _swig_property(_libpymolfile.MolAtoms_altloc_get, _libpymolfile.MolAtoms_altloc_set) - __swig_setmethods__["insertion"] = _libpymolfile.MolAtoms_insertion_set - __swig_getmethods__["insertion"] = _libpymolfile.MolAtoms_insertion_get - if _newclass: - insertion = _swig_property(_libpymolfile.MolAtoms_insertion_get, _libpymolfile.MolAtoms_insertion_set) - __swig_setmethods__["occupancy"] = _libpymolfile.MolAtoms_occupancy_set - __swig_getmethods__["occupancy"] = _libpymolfile.MolAtoms_occupancy_get - if _newclass: - occupancy = _swig_property(_libpymolfile.MolAtoms_occupancy_get, _libpymolfile.MolAtoms_occupancy_set) - __swig_setmethods__["bfactor"] = _libpymolfile.MolAtoms_bfactor_set - __swig_getmethods__["bfactor"] = _libpymolfile.MolAtoms_bfactor_get - if _newclass: - bfactor = _swig_property(_libpymolfile.MolAtoms_bfactor_get, _libpymolfile.MolAtoms_bfactor_set) - __swig_setmethods__["mass"] = _libpymolfile.MolAtoms_mass_set - __swig_getmethods__["mass"] = _libpymolfile.MolAtoms_mass_get - if _newclass: - mass = _swig_property(_libpymolfile.MolAtoms_mass_get, _libpymolfile.MolAtoms_mass_set) - __swig_setmethods__["charge"] = _libpymolfile.MolAtoms_charge_set - __swig_getmethods__["charge"] = _libpymolfile.MolAtoms_charge_get - if _newclass: - charge = _swig_property(_libpymolfile.MolAtoms_charge_get, _libpymolfile.MolAtoms_charge_set) - __swig_setmethods__["radius"] = _libpymolfile.MolAtoms_radius_set - __swig_getmethods__["radius"] = _libpymolfile.MolAtoms_radius_get - if _newclass: - radius = _swig_property(_libpymolfile.MolAtoms_radius_get, _libpymolfile.MolAtoms_radius_set) - __swig_setmethods__["atomicnumber"] = _libpymolfile.MolAtoms_atomicnumber_set - __swig_getmethods__["atomicnumber"] = _libpymolfile.MolAtoms_atomicnumber_get - if _newclass: - atomicnumber = _swig_property(_libpymolfile.MolAtoms_atomicnumber_get, _libpymolfile.MolAtoms_atomicnumber_set) - __swig_setmethods__["ctnumber"] = _libpymolfile.MolAtoms_ctnumber_set - __swig_getmethods__["ctnumber"] = _libpymolfile.MolAtoms_ctnumber_get - if _newclass: - ctnumber = _swig_property(_libpymolfile.MolAtoms_ctnumber_get, _libpymolfile.MolAtoms_ctnumber_set) - - def __init__(self): - this = _libpymolfile.new_MolAtoms() - try: - self.this.append(this) - except __builtin__.Exception: - self.this = this - __swig_destroy__ = _libpymolfile.delete_MolAtoms - __del__ = lambda self: None -MolAtoms_swigregister = _libpymolfile.MolAtoms_swigregister -MolAtoms_swigregister(MolAtoms) - - -def del_plugin_structure(pymolfile_atoms: 'PyObject *') -> "void": - return _libpymolfile.del_plugin_structure(pymolfile_atoms) -del_plugin_structure = _libpymolfile.del_plugin_structure - -def alloc_plugin_structure(arg1: 'PyObject *', args: 'PyObject *') -> "PyObject *": - return _libpymolfile.alloc_plugin_structure(arg1, args) -alloc_plugin_structure = _libpymolfile.alloc_plugin_structure def del_plugin(pymolfile_plugin: 'PyObject *') -> "void": return _libpymolfile.del_plugin(pymolfile_plugin) @@ -243,6 +157,18 @@ def open_file_read(plugin: 'molfile_plugin_t *', fname: 'char *', ftype: 'char * def read_structure(molpack: 'PyObject *') -> "PyObject *": """read_structure(molpack) -> PyObject *""" return _libpymolfile.read_structure(molpack) + +def get_structure(molpack: 'PyObject *') -> "PyObject *": + """get_structure(molpack) -> PyObject *""" + return _libpymolfile.get_structure(molpack) + +def read_fill_structure(molpack: 'PyObject *', prototype: 'PyObject *') -> "PyObject *": + """read_fill_structure(molpack, prototype) -> PyObject *""" + return _libpymolfile.read_fill_structure(molpack, prototype) + +def print_array_struct(prototype: 'PyObject *') -> "PyObject *": + """print_array_struct(prototype) -> PyObject *""" + return _libpymolfile.print_array_struct(prototype) # This file is compatible with both classic and new-style classes. diff --git a/pymolfile/molfile/libpymolfile_wrap.cxx b/pymolfile/molfile/libpymolfile_wrap.cxx index 95bdb95e9932318e5292506992be9aab7f63405f..561451bb9d9bcd393089c34e8d421b6cd05f3279 100644 --- a/pymolfile/molfile/libpymolfile_wrap.cxx +++ b/pymolfile/molfile/libpymolfile_wrap.cxx @@ -3003,12 +3003,11 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { /* -------- TYPES TABLE (BEGIN) -------- */ -#define SWIGTYPE_p_MolAtoms swig_types[0] -#define SWIGTYPE_p_char swig_types[1] -#define SWIGTYPE_p_molfile_plugin_t swig_types[2] -#define SWIGTYPE_p_p_molfile_plugin_t swig_types[3] -static swig_type_info *swig_types[5]; -static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; +#define SWIGTYPE_p_char swig_types[0] +#define SWIGTYPE_p_molfile_plugin_t swig_types[1] +#define SWIGTYPE_p_p_molfile_plugin_t swig_types[2] +static swig_type_info *swig_types[4]; +static swig_module_info swig_module = {swig_types, 3, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -3149,7 +3148,7 @@ SWIGINTERNINLINE PyObject* - +/* struct MolAtoms { char name[16]; char type[16]; @@ -3175,7 +3174,7 @@ void del_plugin_structure(PyObject* pymolfile_atoms){ static PyObject* alloc_plugin_structure(PyObject *self, PyObject *args) { return PyCapsule_New((void*)new MolAtoms(), "plugin_structure", del_plugin_structure); } - +*/ void del_plugin(PyObject* pymolfile_plugin){ delete (MolObject*)PyCapsule_GetPointer(pymolfile_plugin, "plugin"); } @@ -3195,196 +3194,6 @@ static PyObject* alloc_plugin(PyObject *self, PyObject *args) { -SWIGINTERN swig_type_info* -SWIG_pchar_descriptor(void) -{ - static int init = 0; - static swig_type_info* info = 0; - if (!init) { - info = SWIG_TypeQuery("_p_char"); - init = 1; - } - return info; -} - - -SWIGINTERN int -SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) -{ -#if PY_VERSION_HEX>=0x03000000 -#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - if (PyBytes_Check(obj)) -#else - if (PyUnicode_Check(obj)) -#endif -#else - if (PyString_Check(obj)) -#endif - { - char *cstr; Py_ssize_t len; -#if PY_VERSION_HEX>=0x03000000 -#if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - if (!alloc && cptr) { - /* We can't allow converting without allocation, since the internal - representation of string in Python 3 is UCS-2/UCS-4 but we require - a UTF-8 representation. - TODO(bhy) More detailed explanation */ - return SWIG_RuntimeError; - } - obj = PyUnicode_AsUTF8String(obj); - if(alloc) *alloc = SWIG_NEWOBJ; -#endif - PyBytes_AsStringAndSize(obj, &cstr, &len); -#else - PyString_AsStringAndSize(obj, &cstr, &len); -#endif - if (cptr) { - if (alloc) { - /* - In python the user should not be able to modify the inner - string representation. To warranty that, if you define - SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string - buffer is always returned. - - The default behavior is just to return the pointer value, - so, be careful. - */ -#if defined(SWIG_PYTHON_SAFE_CSTRINGS) - if (*alloc != SWIG_OLDOBJ) -#else - if (*alloc == SWIG_NEWOBJ) -#endif - { - *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); - *alloc = SWIG_NEWOBJ; - } else { - *cptr = cstr; - *alloc = SWIG_OLDOBJ; - } - } else { -#if PY_VERSION_HEX>=0x03000000 -#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - *cptr = PyBytes_AsString(obj); -#else - assert(0); /* Should never reach here with Unicode strings in Python 3 */ -#endif -#else - *cptr = SWIG_Python_str_AsChar(obj); -#endif - } - } - if (psize) *psize = len + 1; -#if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - Py_XDECREF(obj); -#endif - return SWIG_OK; - } else { -#if defined(SWIG_PYTHON_2_UNICODE) -#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) -#error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" -#endif -#if PY_VERSION_HEX<0x03000000 - if (PyUnicode_Check(obj)) { - char *cstr; Py_ssize_t len; - if (!alloc && cptr) { - return SWIG_RuntimeError; - } - obj = PyUnicode_AsUTF8String(obj); - if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { - if (cptr) { - if (alloc) *alloc = SWIG_NEWOBJ; - *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); - } - if (psize) *psize = len + 1; - - Py_XDECREF(obj); - return SWIG_OK; - } else { - Py_XDECREF(obj); - } - } -#endif -#endif - - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - if (pchar_descriptor) { - void* vptr = 0; - if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { - if (cptr) *cptr = (char *) vptr; - if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; - if (alloc) *alloc = SWIG_OLDOBJ; - return SWIG_OK; - } - } - } - return SWIG_TypeError; -} - - -SWIGINTERN int -SWIG_AsCharArray(PyObject * obj, char *val, size_t size) -{ - char* cptr = 0; size_t csize = 0; int alloc = SWIG_OLDOBJ; - int res = SWIG_AsCharPtrAndSize(obj, &cptr, &csize, &alloc); - if (SWIG_IsOK(res)) { - /* special case of single char conversion when we don't need space for NUL */ - if (size == 1 && csize == 2 && cptr && !cptr[1]) --csize; - if (csize <= size) { - if (val) { - if (csize) memcpy(val, cptr, csize*sizeof(char)); - if (csize < size) memset(val + csize, 0, (size - csize)*sizeof(char)); - } - if (alloc == SWIG_NEWOBJ) { - delete[] cptr; - res = SWIG_DelNewMask(res); - } - return res; - } - if (alloc == SWIG_NEWOBJ) delete[] cptr; - } - return SWIG_TypeError; -} - - -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtrAndSize(const char* carray, size_t size) -{ - if (carray) { - if (size > INT_MAX) { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - return pchar_descriptor ? - SWIG_InternalNewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : SWIG_Py_Void(); - } else { -#if PY_VERSION_HEX >= 0x03000000 -#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - return PyBytes_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); -#else -#if PY_VERSION_HEX >= 0x03010000 - return PyUnicode_DecodeUTF8(carray, static_cast< Py_ssize_t >(size), "surrogateescape"); -#else - return PyUnicode_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); -#endif -#endif -#else - return PyString_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); -#endif - } - } else { - return SWIG_Py_Void(); - } -} - - -SWIGINTERN size_t -SWIG_strnlen(const char* s, size_t maxlen) -{ - const char *p; - for (p = s; maxlen-- && *p; p++) - ; - return p - s; -} - - #include <limits.h> #if !defined(SWIG_NO_LLONG_MAX) # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) @@ -3536,70 +3345,6 @@ SWIG_AsVal_int (PyObject * obj, int *val) } -/* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ -#ifndef SWIG_isfinite -/* isfinite() is a macro for C99 */ -# if defined(isfinite) -# define SWIG_isfinite(X) (isfinite(X)) -# elif defined __cplusplus && __cplusplus >= 201103L -/* Use a template so that this works whether isfinite() is std::isfinite() or - * in the global namespace. The reality seems to vary between compiler - * versions. - * - * Make sure namespace std exists to avoid compiler warnings. - * - * extern "C++" is required as this fragment can end up inside an extern "C" { } block - */ -namespace std { } -extern "C++" template<typename T> -inline int SWIG_isfinite_func(T x) { - using namespace std; - return isfinite(x); -} -# define SWIG_isfinite(X) (SWIG_isfinite_func(X)) -# elif defined(_MSC_VER) -# define SWIG_isfinite(X) (_finite(X)) -# elif defined(__sun) && defined(__SVR4) -# include <ieeefp.h> -# define SWIG_isfinite(X) (finite(X)) -# endif -#endif - - -/* Accept infinite as a valid float value unless we are unable to check if a value is finite */ -#ifdef SWIG_isfinite -# define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX) && SWIG_isfinite(X)) -#else -# define SWIG_Float_Overflow_Check(X) ((X < -FLT_MAX || X > FLT_MAX)) -#endif - - -SWIGINTERN int -SWIG_AsVal_float (PyObject * obj, float *val) -{ - double v; - int res = SWIG_AsVal_double (obj, &v); - if (SWIG_IsOK(res)) { - if (SWIG_Float_Overflow_Check(v)) { - return SWIG_OverflowError; - } else { - if (val) *val = static_cast< float >(v); - } - } - return res; -} - - - #define SWIG_From_double PyFloat_FromDouble - - -SWIGINTERNINLINE PyObject * -SWIG_From_float (float value) -{ - return SWIG_From_double (value); -} - - PyObject * molfile_plugin_info(molfile_plugin_t** plugin_list, int plugin_no) { molfile_plugin_t *plugin; int *plugno = &plugin_no; @@ -3674,915 +3419,137 @@ PyObject * my_open_file_read(molfile_plugin_t* plugin, char* fname, char* ftype, } - - -#ifdef __cplusplus -extern "C" { -#endif -SWIGINTERN PyObject *_wrap_MolAtoms_name_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[16] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_name_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_name_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 16); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_name_set" "', argument " "2"" of type '" "char [16]""'"); +SWIGINTERN swig_type_info* +SWIG_pchar_descriptor(void) +{ + static int init = 0; + static swig_type_info* info = 0; + if (!init) { + info = SWIG_TypeQuery("_p_char"); + init = 1; } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->name,arg2,16*sizeof(char)); - else memset(arg1->name,0,16*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; + return info; } -SWIGINTERN PyObject *_wrap_MolAtoms_name_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_name_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_name_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->name); +SWIGINTERN int +SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) +{ +#if PY_VERSION_HEX>=0x03000000 +#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + if (PyBytes_Check(obj)) +#else + if (PyUnicode_Check(obj)) +#endif +#else + if (PyString_Check(obj)) +#endif { - size_t size = SWIG_strnlen(result, 16); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_type_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[16] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_type_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_type_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 16); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_type_set" "', argument " "2"" of type '" "char [16]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->type,arg2,16*sizeof(char)); - else memset(arg1->type,0,16*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_type_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_type_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_type_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->type); - { - size_t size = SWIG_strnlen(result, 16); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_resname_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[8] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_resname_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_resname_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 8); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_resname_set" "', argument " "2"" of type '" "char [8]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->resname,arg2,8*sizeof(char)); - else memset(arg1->resname,0,8*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_resname_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_resname_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_resname_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->resname); - { - size_t size = SWIG_strnlen(result, 8); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_resid_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_resid_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_resid_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_resid_set" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - if (arg1) (arg1)->resid = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_resid_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - int result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_resid_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_resid_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (int) ((arg1)->resid); - resultobj = SWIG_From_int(static_cast< int >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_segid_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[8] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_segid_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_segid_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 8); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_segid_set" "', argument " "2"" of type '" "char [8]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->segid,arg2,8*sizeof(char)); - else memset(arg1->segid,0,8*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_segid_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_segid_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_segid_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->segid); - { - size_t size = SWIG_strnlen(result, 8); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_chain_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[2] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_chain_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_chain_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_chain_set" "', argument " "2"" of type '" "char [2]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->chain,arg2,2*sizeof(char)); - else memset(arg1->chain,0,2*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_chain_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_chain_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_chain_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->chain); - { - size_t size = SWIG_strnlen(result, 2); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_altloc_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[2] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_altloc_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_altloc_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_altloc_set" "', argument " "2"" of type '" "char [2]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->altloc,arg2,2*sizeof(char)); - else memset(arg1->altloc,0,2*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_altloc_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_altloc_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_altloc_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->altloc); - { - size_t size = SWIG_strnlen(result, 2); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_insertion_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - char *arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - char temp2[2] ; - int res2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_insertion_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_insertion_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - res2 = SWIG_AsCharArray(obj1, temp2, 2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MolAtoms_insertion_set" "', argument " "2"" of type '" "char [2]""'"); - } - arg2 = reinterpret_cast< char * >(temp2); - if (arg2) memcpy(arg1->insertion,arg2,2*sizeof(char)); - else memset(arg1->insertion,0,2*sizeof(char)); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_insertion_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_insertion_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_insertion_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (char *)(char *) ((arg1)->insertion); - { - size_t size = SWIG_strnlen(result, 2); - - - - resultobj = SWIG_FromCharPtrAndSize(result, size); - } - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_occupancy_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_occupancy_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_occupancy_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_occupancy_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->occupancy = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_occupancy_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_occupancy_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_occupancy_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->occupancy); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_bfactor_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_bfactor_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_bfactor_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_bfactor_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->bfactor = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_bfactor_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_bfactor_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_bfactor_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->bfactor); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_mass_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_mass_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_mass_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_mass_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->mass = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_mass_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_mass_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_mass_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->mass); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_charge_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_charge_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_charge_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_charge_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->charge = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_charge_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_charge_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_charge_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->charge); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_radius_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_radius_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_radius_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_radius_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->radius = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_radius_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_radius_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_radius_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->radius); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_atomicnumber_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_atomicnumber_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_atomicnumber_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_atomicnumber_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->atomicnumber = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_atomicnumber_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_atomicnumber_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_atomicnumber_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->atomicnumber); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_ctnumber_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - float arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - float val2 ; - int ecode2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:MolAtoms_ctnumber_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_ctnumber_set" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - ecode2 = SWIG_AsVal_float(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MolAtoms_ctnumber_set" "', argument " "2"" of type '" "float""'"); - } - arg2 = static_cast< float >(val2); - if (arg1) (arg1)->ctnumber = arg2; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_MolAtoms_ctnumber_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - float result; - - if (!PyArg_ParseTuple(args,(char *)"O:MolAtoms_ctnumber_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MolAtoms_ctnumber_get" "', argument " "1"" of type '" "MolAtoms *""'"); - } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - result = (float) ((arg1)->ctnumber); - resultobj = SWIG_From_float(static_cast< float >(result)); - return resultobj; -fail: - return NULL; -} - + char *cstr; Py_ssize_t len; +#if PY_VERSION_HEX>=0x03000000 +#if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + if (!alloc && cptr) { + /* We can't allow converting without allocation, since the internal + representation of string in Python 3 is UCS-2/UCS-4 but we require + a UTF-8 representation. + TODO(bhy) More detailed explanation */ + return SWIG_RuntimeError; + } + obj = PyUnicode_AsUTF8String(obj); + if(alloc) *alloc = SWIG_NEWOBJ; +#endif + PyBytes_AsStringAndSize(obj, &cstr, &len); +#else + PyString_AsStringAndSize(obj, &cstr, &len); +#endif + if (cptr) { + if (alloc) { + /* + In python the user should not be able to modify the inner + string representation. To warranty that, if you define + SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string + buffer is always returned. -SWIGINTERN PyObject *_wrap_new_MolAtoms(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)":new_MolAtoms")) SWIG_fail; - result = (MolAtoms *)new MolAtoms(); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_MolAtoms, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} + The default behavior is just to return the pointer value, + so, be careful. + */ +#if defined(SWIG_PYTHON_SAFE_CSTRINGS) + if (*alloc != SWIG_OLDOBJ) +#else + if (*alloc == SWIG_NEWOBJ) +#endif + { + *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); + *alloc = SWIG_NEWOBJ; + } else { + *cptr = cstr; + *alloc = SWIG_OLDOBJ; + } + } else { +#if PY_VERSION_HEX>=0x03000000 +#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + *cptr = PyBytes_AsString(obj); +#else + assert(0); /* Should never reach here with Unicode strings in Python 3 */ +#endif +#else + *cptr = SWIG_Python_str_AsChar(obj); +#endif + } + } + if (psize) *psize = len + 1; +#if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + Py_XDECREF(obj); +#endif + return SWIG_OK; + } else { +#if defined(SWIG_PYTHON_2_UNICODE) +#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) +#error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" +#endif +#if PY_VERSION_HEX<0x03000000 + if (PyUnicode_Check(obj)) { + char *cstr; Py_ssize_t len; + if (!alloc && cptr) { + return SWIG_RuntimeError; + } + obj = PyUnicode_AsUTF8String(obj); + if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { + if (cptr) { + if (alloc) *alloc = SWIG_NEWOBJ; + *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1))); + } + if (psize) *psize = len + 1; + Py_XDECREF(obj); + return SWIG_OK; + } else { + Py_XDECREF(obj); + } + } +#endif +#endif -SWIGINTERN PyObject *_wrap_delete_MolAtoms(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - MolAtoms *arg1 = (MolAtoms *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_MolAtoms",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_MolAtoms, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_MolAtoms" "', argument " "1"" of type '" "MolAtoms *""'"); + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + if (pchar_descriptor) { + void* vptr = 0; + if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { + if (cptr) *cptr = (char *) vptr; + if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; + if (alloc) *alloc = SWIG_OLDOBJ; + return SWIG_OK; + } + } } - arg1 = reinterpret_cast< MolAtoms * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *MolAtoms_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *obj; - if (!PyArg_ParseTuple(args,(char *)"O:swigregister", &obj)) return NULL; - SWIG_TypeNewClientData(SWIGTYPE_p_MolAtoms, SWIG_NewClientData(obj)); - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject *_wrap_del_plugin_structure(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - PyObject *arg1 = (PyObject *) 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:del_plugin_structure",&obj0)) SWIG_fail; - arg1 = obj0; - del_plugin_structure(arg1); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; + return SWIG_TypeError; } -SWIGINTERN PyObject *_wrap_alloc_plugin_structure(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - PyObject *arg1 = (PyObject *) 0 ; - PyObject *arg2 = (PyObject *) 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"OO:alloc_plugin_structure",&obj0,&obj1)) SWIG_fail; - arg1 = obj0; - arg2 = obj1; - result = (PyObject *)alloc_plugin_structure(arg1,arg2); - resultobj = result; - return resultobj; -fail: - return NULL; -} +#ifdef __cplusplus +extern "C" { +#endif SWIGINTERN PyObject *_wrap_del_plugin(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; PyObject *arg1 = (PyObject *) 0 ; @@ -4834,43 +3801,59 @@ fail: } +SWIGINTERN PyObject *_wrap_get_structure(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + PyObject *arg1 = (PyObject *) 0 ; + PyObject * obj0 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:get_structure",&obj0)) SWIG_fail; + arg1 = obj0; + result = (PyObject *)get_structure(arg1); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_read_fill_structure(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + PyObject *arg1 = (PyObject *) 0 ; + PyObject *arg2 = (PyObject *) 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:read_fill_structure",&obj0,&obj1)) SWIG_fail; + arg1 = obj0; + arg2 = obj1; + result = (PyObject *)read_fill_structure(arg1,arg2); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_print_array_struct(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + PyObject *arg1 = (PyObject *) 0 ; + PyObject * obj0 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:print_array_struct",&obj0)) SWIG_fail; + arg1 = obj0; + result = (PyObject *)print_array_struct(arg1); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, - { (char *)"MolAtoms_name_set", _wrap_MolAtoms_name_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_name_get", _wrap_MolAtoms_name_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_type_set", _wrap_MolAtoms_type_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_type_get", _wrap_MolAtoms_type_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_resname_set", _wrap_MolAtoms_resname_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_resname_get", _wrap_MolAtoms_resname_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_resid_set", _wrap_MolAtoms_resid_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_resid_get", _wrap_MolAtoms_resid_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_segid_set", _wrap_MolAtoms_segid_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_segid_get", _wrap_MolAtoms_segid_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_chain_set", _wrap_MolAtoms_chain_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_chain_get", _wrap_MolAtoms_chain_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_altloc_set", _wrap_MolAtoms_altloc_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_altloc_get", _wrap_MolAtoms_altloc_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_insertion_set", _wrap_MolAtoms_insertion_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_insertion_get", _wrap_MolAtoms_insertion_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_occupancy_set", _wrap_MolAtoms_occupancy_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_occupancy_get", _wrap_MolAtoms_occupancy_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_bfactor_set", _wrap_MolAtoms_bfactor_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_bfactor_get", _wrap_MolAtoms_bfactor_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_mass_set", _wrap_MolAtoms_mass_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_mass_get", _wrap_MolAtoms_mass_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_charge_set", _wrap_MolAtoms_charge_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_charge_get", _wrap_MolAtoms_charge_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_radius_set", _wrap_MolAtoms_radius_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_radius_get", _wrap_MolAtoms_radius_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_atomicnumber_set", _wrap_MolAtoms_atomicnumber_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_atomicnumber_get", _wrap_MolAtoms_atomicnumber_get, METH_VARARGS, NULL}, - { (char *)"MolAtoms_ctnumber_set", _wrap_MolAtoms_ctnumber_set, METH_VARARGS, NULL}, - { (char *)"MolAtoms_ctnumber_get", _wrap_MolAtoms_ctnumber_get, METH_VARARGS, NULL}, - { (char *)"new_MolAtoms", _wrap_new_MolAtoms, METH_VARARGS, NULL}, - { (char *)"delete_MolAtoms", _wrap_delete_MolAtoms, METH_VARARGS, NULL}, - { (char *)"MolAtoms_swigregister", MolAtoms_swigregister, METH_VARARGS, NULL}, - { (char *)"del_plugin_structure", _wrap_del_plugin_structure, METH_VARARGS, NULL}, - { (char *)"alloc_plugin_structure", _wrap_alloc_plugin_structure, METH_VARARGS, NULL}, { (char *)"del_plugin", _wrap_del_plugin, METH_VARARGS, NULL}, { (char *)"del_atoms", _wrap_del_atoms, METH_VARARGS, NULL}, { (char *)"del_atomname", _wrap_del_atomname, METH_VARARGS, NULL}, @@ -4882,31 +3865,30 @@ static PyMethodDef SwigMethods[] = { { (char *)"molfile_plugin_info", _wrap_molfile_plugin_info, METH_VARARGS, (char *)"molfile_plugin_info(plugin_list, plugin_no) -> PyObject *"}, { (char *)"open_file_read", _wrap_open_file_read, METH_VARARGS, (char *)"open_file_read(plugin, fname, ftype, natoms) -> PyObject *"}, { (char *)"read_structure", _wrap_read_structure, METH_VARARGS, (char *)"read_structure(molpack) -> PyObject *"}, + { (char *)"get_structure", _wrap_get_structure, METH_VARARGS, (char *)"get_structure(molpack) -> PyObject *"}, + { (char *)"read_fill_structure", _wrap_read_fill_structure, METH_VARARGS, (char *)"read_fill_structure(molpack, prototype) -> PyObject *"}, + { (char *)"print_array_struct", _wrap_print_array_struct, METH_VARARGS, (char *)"print_array_struct(prototype) -> PyObject *"}, { NULL, NULL, 0, NULL } }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ -static swig_type_info _swigt__p_MolAtoms = {"_p_MolAtoms", "MolAtoms *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_molfile_plugin_t = {"_p_molfile_plugin_t", "molfile_plugin_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_molfile_plugin_t = {"_p_p_molfile_plugin_t", "molfile_plugin_t **", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { - &_swigt__p_MolAtoms, &_swigt__p_char, &_swigt__p_molfile_plugin_t, &_swigt__p_p_molfile_plugin_t, }; -static swig_cast_info _swigc__p_MolAtoms[] = { {&_swigt__p_MolAtoms, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_molfile_plugin_t[] = { {&_swigt__p_molfile_plugin_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_molfile_plugin_t[] = { {&_swigt__p_p_molfile_plugin_t, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { - _swigc__p_MolAtoms, _swigc__p_char, _swigc__p_molfile_plugin_t, _swigc__p_p_molfile_plugin_t, diff --git a/pymolfile/molfile/numind-cython/compile-numind.sh b/pymolfile/molfile/numind-cython/compile-numind.sh new file mode 100644 index 0000000000000000000000000000000000000000..680fa4e374146e23eaab3a4e15e25c120176b42a --- /dev/null +++ b/pymolfile/molfile/numind-cython/compile-numind.sh @@ -0,0 +1,2 @@ +Cython -a numind.pyx --cplus +g++ -fPIC -Wall -Wextra -Wunused-function -shared -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ numind.cpp -o numind.so -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 diff --git a/pymolfile/molfile/numind-cython/numind.cpp b/pymolfile/molfile/numind-cython/numind.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3313212c090a1abf3bc94bc3ec7a6dca11b62667 --- /dev/null +++ b/pymolfile/molfile/numind-cython/numind.cpp @@ -0,0 +1,5454 @@ +/* Generated by Cython 0.26.1 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) + #error Cython requires Python 2.6+ or Python 3.2+. +#else +#define CYTHON_ABI "0_26_1" +#include <stddef.h> +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000) + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#if PY_VERSION_HEX < 0x030700A0 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject **args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif +#else + #include <stdint.h> +#endif +#ifndef CYTHON_FALLTHROUGH + #ifdef __cplusplus + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) || (defined(__GNUC__) && defined(__attribute__)) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef __cplusplus + #error "Cython files generated with the C++ option must be compiled with a C++ compiler." +#endif +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #else + #define CYTHON_INLINE inline + #endif +#endif +template<typename T> +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template<typename T> +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { } + T *operator->() { return ptr; } + T *operator&() { return ptr; } + operator T&() { return *ptr; } + template<typename U> bool operator ==(U other) { return *ptr == other; } + template<typename U> bool operator !=(U other) { return *ptr != other; } + private: + T *ptr; +}; + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include <math.h> +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__numind +#define __PYX_HAVE_API__numind +#include "stdlib.h" +#include "numind.h" +#ifdef _OPENMP +#include <omp.h> +#endif /* _OPENMP */ + +#ifdef PYREX_WITHOUT_ASSERTIONS +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +#if defined (__cplusplus) && __cplusplus >= 201103L + #include <cstdlib> + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) && defined (_M_X64) + #define __Pyx_sst_abs(value) _abs64(value) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#if PY_MAJOR_VERSION < 3 +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) +{ + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#else +#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen +#endif +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +static PyObject *__pyx_m; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "numind.pyx", + "stringsource", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_6numind_NumInd; +struct __pyx_t_6numind_PyArrayInterface; +typedef struct __pyx_t_6numind_PyArrayInterface __pyx_t_6numind_PyArrayInterface; + +/* "numind.pyx":42 + * byteorder = {'<':'little', '>':'big'} + * + * ctypedef struct PyArrayInterface: # <<<<<<<<<<<<<< + * int version # contains the integer 2 as a sanity check + * int nd # number of dimensions + */ +struct __pyx_t_6numind_PyArrayInterface { + int version; + int nd; + char typekind; + int itemsize; + int flags; + Py_intptr_t *shape; + Py_intptr_t *strides; + void *data; +}; + +/* "numind.pyx":56 + * + * + * cdef class NumInd: # <<<<<<<<<<<<<< + * cdef void *data + * cdef int _nd + */ +struct __pyx_obj_6numind_NumInd { + PyObject_HEAD + struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtab; + void *data; + int _nd; + Py_intptr_t *_shape; + Py_intptr_t *_strides; + __pyx_t_6numind_PyArrayInterface *inter; + PyObject *_t_shape; + PyObject *_t_strides; + PyObject *_undarray; +}; + + + +struct __pyx_vtabstruct_6numind_NumInd { + __pyx_t_6numind_PyArrayInterface *(*_get_array_interface)(struct __pyx_obj_6numind_NumInd *); +}; +static struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtabptr_6numind_NumInd; + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* SliceObject.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( + PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** py_start, PyObject** py_stop, PyObject** py_slice, + int has_cstart, int has_cstop, int wraparound); + +/* SetItemInt.proto */ +#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v))) +static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v); +static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, + int is_list, int wraparound, int boundscheck); + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* UnicodeAsUCS4.proto */ +static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*); + +/* object_ord.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyObject_Ord(c)\ + (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c)) +#else +#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c) +#endif +static long __Pyx__PyObject_Ord(PyObject* c); + +/* IncludeStringH.proto */ +#include <string.h> + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + +/* GetModuleGlobalName.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = PyThreadState_GET(); +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* WriteUnraisableException.proto */ +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename, + int full_traceback, int nogil); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* SetVTable.proto */ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* CLineInTraceback.proto */ +static int __Pyx_CLineForTraceback(int c_line); + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_As_Py_intptr_t(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +static __pyx_t_6numind_PyArrayInterface *__pyx_f_6numind_6NumInd__get_array_interface(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto*/ + +/* Module declarations from 'cpython.pycapsule' */ + +/* Module declarations from 'numind' */ +static PyTypeObject *__pyx_ptype_6numind_NumInd = 0; +static void *__pyx_f_6numind_free_array_interface(PyObject *); /*proto*/ +#define __Pyx_MODULE_NAME "numind" +int __pyx_module_is_main_numind = 0; + +/* Implementation of 'numind' */ +static PyObject *__pyx_builtin_chr; +static PyObject *__pyx_builtin_MemoryError; +static PyObject *__pyx_builtin_TypeError; +static const char __pyx_k_f[] = "f"; +static const char __pyx_k_i[] = "i"; +static const char __pyx_k__3[] = "|"; +static const char __pyx_k__6[] = "<"; +static const char __pyx_k__7[] = ">"; +static const char __pyx_k_big[] = "big"; +static const char __pyx_k_chr[] = "chr"; +static const char __pyx_k_sys[] = "sys"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_shape[] = "shape"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_little[] = "little"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_ALIGNED[] = "ALIGNED"; +static const char __pyx_k_FORTRAN[] = "FORTRAN"; +static const char __pyx_k_strides[] = "strides"; +static const char __pyx_k_typestr[] = "typestr"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_readonly[] = "readonly"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_undarray[] = "undarray"; +static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_WRITEABLE[] = "WRITEABLE"; +static const char __pyx_k_byteorder[] = "byteorder"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_CONTIGUOUS[] = "CONTIGUOUS"; +static const char __pyx_k_NOTSWAPPED[] = "NOTSWAPPED"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; +static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_array_struct[] = "__array_struct__"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_array_interface[] = "__array_interface__"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_self__shape_self__strides_self_d[] = "self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling"; +static PyObject *__pyx_n_s_ALIGNED; +static PyObject *__pyx_n_s_CONTIGUOUS; +static PyObject *__pyx_n_s_FORTRAN; +static PyObject *__pyx_n_s_MemoryError; +static PyObject *__pyx_n_s_NOTSWAPPED; +static PyObject *__pyx_n_s_TypeError; +static PyObject *__pyx_n_s_WRITEABLE; +static PyObject *__pyx_kp_s__3; +static PyObject *__pyx_kp_s__6; +static PyObject *__pyx_kp_s__7; +static PyObject *__pyx_n_s_array_interface; +static PyObject *__pyx_n_s_array_struct; +static PyObject *__pyx_n_s_big; +static PyObject *__pyx_n_s_byteorder; +static PyObject *__pyx_n_s_chr; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_data; +static PyObject *__pyx_n_s_f; +static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_little; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_n_s_readonly; +static PyObject *__pyx_n_s_reduce; +static PyObject *__pyx_n_s_reduce_cython; +static PyObject *__pyx_n_s_reduce_ex; +static PyObject *__pyx_kp_s_self__shape_self__strides_self_d; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_shape; +static PyObject *__pyx_n_s_strides; +static PyObject *__pyx_n_s_sys; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_typestr; +static PyObject *__pyx_n_s_undarray; +static int __pyx_pf_6numind_6NumInd___init__(struct __pyx_obj_6numind_NumInd *__pyx_v_self, PyObject *__pyx_v_undarray); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_8undarray___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_5shape___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_7strides___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_7typestr___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_8typekind___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_8readonly___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_16__array_struct_____get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_2modify(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static void __pyx_pf_6numind_6NumInd_4__dealloc__(struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_6numind_NumInd *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_6numind_6NumInd_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_6numind_NumInd *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_6numind_NumInd(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_256; +static PyObject *__pyx_int_512; +static PyObject *__pyx_int_1024; +static PyObject *__pyx_slice_; +static PyObject *__pyx_slice__2; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; + +/* "numind.pyx":52 + * void *data # A pointer to the first element of the array + * + * cdef void* free_array_interface(object arr): # <<<<<<<<<<<<<< + * Py_DECREF(arr) + * + */ + +static void *__pyx_f_6numind_free_array_interface(PyObject *__pyx_v_arr) { + void *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("free_array_interface", 0); + + /* "numind.pyx":53 + * + * cdef void* free_array_interface(object arr): + * Py_DECREF(arr) # <<<<<<<<<<<<<< + * + * + */ + Py_DECREF(__pyx_v_arr); + + /* "numind.pyx":52 + * void *data # A pointer to the first element of the array + * + * cdef void* free_array_interface(object arr): # <<<<<<<<<<<<<< + * Py_DECREF(arr) + * + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":64 + * cdef object _t_shape, _t_strides, _undarray + * + * def __init__(self, object undarray): # <<<<<<<<<<<<<< + * cdef int i, stride + * cdef object array_shape, array_strides + */ + +/* Python wrapper */ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_undarray = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_undarray,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_undarray)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 64, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_undarray = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 64, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_6numind_6NumInd___init__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self), __pyx_v_undarray); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_6numind_6NumInd___init__(struct __pyx_obj_6numind_NumInd *__pyx_v_self, PyObject *__pyx_v_undarray) { + int __pyx_v_i; + int __pyx_v_stride; + PyObject *__pyx_v_array_shape = 0; + PyObject *__pyx_v_array_strides = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + Py_intptr_t __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "numind.pyx":69 + * + * # Keep a reference to the underlying object + * self._undarray = undarray # <<<<<<<<<<<<<< + * # Get the shape and strides C arrays + * array_shape = undarray.__array_interface__["shape"] + */ + __Pyx_INCREF(__pyx_v_undarray); + __Pyx_GIVEREF(__pyx_v_undarray); + __Pyx_GOTREF(__pyx_v_self->_undarray); + __Pyx_DECREF(__pyx_v_self->_undarray); + __pyx_v_self->_undarray = __pyx_v_undarray; + + /* "numind.pyx":71 + * self._undarray = undarray + * # Get the shape and strides C arrays + * array_shape = undarray.__array_interface__["shape"] # <<<<<<<<<<<<<< + * self._t_shape = array_shape + * # The number of dimensions + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_undarray, __pyx_n_s_array_interface); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_array_shape = __pyx_t_2; + __pyx_t_2 = 0; + + /* "numind.pyx":72 + * # Get the shape and strides C arrays + * array_shape = undarray.__array_interface__["shape"] + * self._t_shape = array_shape # <<<<<<<<<<<<<< + * # The number of dimensions + * self._nd = len(array_shape) + */ + __Pyx_INCREF(__pyx_v_array_shape); + __Pyx_GIVEREF(__pyx_v_array_shape); + __Pyx_GOTREF(__pyx_v_self->_t_shape); + __Pyx_DECREF(__pyx_v_self->_t_shape); + __pyx_v_self->_t_shape = __pyx_v_array_shape; + + /* "numind.pyx":74 + * self._t_shape = array_shape + * # The number of dimensions + * self._nd = len(array_shape) # <<<<<<<<<<<<<< + * # The shape + * self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + */ + __pyx_t_3 = PyObject_Length(__pyx_v_array_shape); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_v_self->_nd = __pyx_t_3; + + /* "numind.pyx":76 + * self._nd = len(array_shape) + * # The shape + * self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) # <<<<<<<<<<<<<< + * for i from 0 <= i < self._nd: + * self._shape[i] = self._t_shape[i] + */ + __pyx_v_self->_shape = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); + + /* "numind.pyx":77 + * # The shape + * self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * for i from 0 <= i < self._nd: # <<<<<<<<<<<<<< + * self._shape[i] = self._t_shape[i] + * # The strides (compute them if needed) + */ + __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "numind.pyx":78 + * self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * for i from 0 <= i < self._nd: + * self._shape[i] = self._t_shape[i] # <<<<<<<<<<<<<< + * # The strides (compute them if needed) + * array_strides = undarray.__array_interface__["strides"] + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_self->_t_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_PyInt_As_Py_intptr_t(__pyx_t_2); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 78, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + (__pyx_v_self->_shape[__pyx_v_i]) = __pyx_t_5; + } + + /* "numind.pyx":80 + * self._shape[i] = self._t_shape[i] + * # The strides (compute them if needed) + * array_strides = undarray.__array_interface__["strides"] # <<<<<<<<<<<<<< + * self._t_strides = array_strides + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_undarray, __pyx_n_s_array_interface); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_strides); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_array_strides = __pyx_t_1; + __pyx_t_1 = 0; + + /* "numind.pyx":81 + * # The strides (compute them if needed) + * array_strides = undarray.__array_interface__["strides"] + * self._t_strides = array_strides # <<<<<<<<<<<<<< + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * if array_strides: + */ + __Pyx_INCREF(__pyx_v_array_strides); + __Pyx_GIVEREF(__pyx_v_array_strides); + __Pyx_GOTREF(__pyx_v_self->_t_strides); + __Pyx_DECREF(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_v_array_strides; + + /* "numind.pyx":82 + * array_strides = undarray.__array_interface__["strides"] + * self._t_strides = array_strides + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) # <<<<<<<<<<<<<< + * if array_strides: + * for i from 0 <= i < self._nd: + */ + __pyx_v_self->_strides = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); + + /* "numind.pyx":83 + * self._t_strides = array_strides + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * if array_strides: # <<<<<<<<<<<<<< + * for i from 0 <= i < self._nd: + * self._strides[i] = array_strides[i] + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_array_strides); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 83, __pyx_L1_error) + if (__pyx_t_6) { + + /* "numind.pyx":84 + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * if array_strides: + * for i from 0 <= i < self._nd: # <<<<<<<<<<<<<< + * self._strides[i] = array_strides[i] + * else: + */ + __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "numind.pyx":85 + * if array_strides: + * for i from 0 <= i < self._nd: + * self._strides[i] = array_strides[i] # <<<<<<<<<<<<<< + * else: + * # strides is None. Compute them explicitely. + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_array_strides, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_As_Py_intptr_t(__pyx_t_1); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 85, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_t_5; + } + + /* "numind.pyx":83 + * self._t_strides = array_strides + * self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + * if array_strides: # <<<<<<<<<<<<<< + * for i from 0 <= i < self._nd: + * self._strides[i] = array_strides[i] + */ + goto __pyx_L5; + } + + /* "numind.pyx":88 + * else: + * # strides is None. Compute them explicitely. + * self._t_strides = [0] * self._nd # <<<<<<<<<<<<<< + * stride = int(self.typestr[2:]) + * for i from self._nd > i >= 0: + */ + /*else*/ { + __pyx_t_1 = PyList_New(1 * ((__pyx_v_self->_nd<0) ? 0:__pyx_v_self->_nd)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_self->_nd; __pyx_temp++) { + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_int_0); + } + } + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_t_strides); + __Pyx_DECREF(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_1; + __pyx_t_1 = 0; + + /* "numind.pyx":89 + * # strides is None. Compute them explicitely. + * self._t_strides = [0] * self._nd + * stride = int(self.typestr[2:]) # <<<<<<<<<<<<<< + * for i from self._nd > i >= 0: + * self._strides[i] = stride + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_typestr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 2, 0, NULL, NULL, &__pyx_slice_, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_stride = __pyx_t_4; + + /* "numind.pyx":90 + * self._t_strides = [0] * self._nd + * stride = int(self.typestr[2:]) + * for i from self._nd > i >= 0: # <<<<<<<<<<<<<< + * self._strides[i] = stride + * self._t_strides[i] = stride + */ + for (__pyx_v_i = __pyx_v_self->_nd-1; __pyx_v_i >= 0; __pyx_v_i--) { + + /* "numind.pyx":91 + * stride = int(self.typestr[2:]) + * for i from self._nd > i >= 0: + * self._strides[i] = stride # <<<<<<<<<<<<<< + * self._t_strides[i] = stride + * stride = stride * array_shape[i] + */ + (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_v_stride; + + /* "numind.pyx":92 + * for i from self._nd > i >= 0: + * self._strides[i] = stride + * self._t_strides[i] = stride # <<<<<<<<<<<<<< + * stride = stride * array_shape[i] + * self._t_strides = tuple(self._t_strides) + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_stride); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(__Pyx_SetItemInt(__pyx_v_self->_t_strides, __pyx_v_i, __pyx_t_1, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) __PYX_ERR(0, 92, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "numind.pyx":93 + * self._strides[i] = stride + * self._t_strides[i] = stride + * stride = stride * array_shape[i] # <<<<<<<<<<<<<< + * self._t_strides = tuple(self._t_strides) + * # Populate the C array interface + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_stride); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_array_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 93, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_stride = __pyx_t_4; + } + + /* "numind.pyx":94 + * self._t_strides[i] = stride + * stride = stride * array_shape[i] + * self._t_strides = tuple(self._t_strides) # <<<<<<<<<<<<<< + * # Populate the C array interface + * self.inter = self._get_array_interface() + */ + __pyx_t_7 = PySequence_Tuple(__pyx_v_self->_t_strides); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->_t_strides); + __Pyx_DECREF(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_L5:; + + /* "numind.pyx":96 + * self._t_strides = tuple(self._t_strides) + * # Populate the C array interface + * self.inter = self._get_array_interface() # <<<<<<<<<<<<<< + * + * # Properties. This are visible from Python space. + */ + __pyx_v_self->inter = ((struct __pyx_vtabstruct_6numind_NumInd *)__pyx_v_self->__pyx_vtab)->_get_array_interface(__pyx_v_self); + + /* "numind.pyx":64 + * cdef object _t_shape, _t_strides, _undarray + * + * def __init__(self, object undarray): # <<<<<<<<<<<<<< + * cdef int i, stride + * cdef object array_shape, array_strides + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_array_shape); + __Pyx_XDECREF(__pyx_v_array_strides); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":102 + * + * property undarray: # Returns the underlying array + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8undarray___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8undarray___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":103 + * property undarray: # Returns the underlying array + * def __get__(self): + * return self._undarray # <<<<<<<<<<<<<< + * + * property shape: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_undarray); + __pyx_r = __pyx_v_self->_undarray; + goto __pyx_L0; + + /* "numind.pyx":102 + * + * property undarray: # Returns the underlying array + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":106 + * + * property shape: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._t_shape + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_5shape___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_5shape___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":107 + * property shape: + * def __get__(self): + * return self._t_shape # <<<<<<<<<<<<<< + * + * property strides: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_t_shape); + __pyx_r = __pyx_v_self->_t_shape; + goto __pyx_L0; + + /* "numind.pyx":106 + * + * property shape: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._t_shape + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":110 + * + * property strides: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._t_strides + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7strides___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7strides___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":111 + * property strides: + * def __get__(self): + * return self._t_strides # <<<<<<<<<<<<<< + * + * property typestr: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_t_strides); + __pyx_r = __pyx_v_self->_t_strides; + goto __pyx_L0; + + /* "numind.pyx":110 + * + * property strides: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._t_strides + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":114 + * + * property typestr: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray.__array_interface__["typestr"] + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7typestr___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7typestr___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":115 + * property typestr: + * def __get__(self): + * return self._undarray.__array_interface__["typestr"] # <<<<<<<<<<<<<< + * + * property typekind: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_undarray, __pyx_n_s_array_interface); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_n_s_typestr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "numind.pyx":114 + * + * property typestr: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray.__array_interface__["typestr"] + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("numind.NumInd.typestr.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":118 + * + * property typekind: + * def __get__(self): # <<<<<<<<<<<<<< + * return chr(self.inter.typekind) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8typekind___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8typekind___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":119 + * property typekind: + * def __get__(self): + * return chr(self.inter.typekind) # <<<<<<<<<<<<<< + * + * property readonly: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_char(__pyx_v_self->inter->typekind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "numind.pyx":118 + * + * property typekind: + * def __get__(self): # <<<<<<<<<<<<<< + * return chr(self.inter.typekind) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("numind.NumInd.typekind.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":122 + * + * property readonly: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray.__array_interface__["data"][1] + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8readonly___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8readonly___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":123 + * property readonly: + * def __get__(self): + * return self._undarray.__array_interface__["data"][1] # <<<<<<<<<<<<<< + * + * property __array_struct__: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_undarray, __pyx_n_s_array_interface); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_n_s_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "numind.pyx":122 + * + * property readonly: + * def __get__(self): # <<<<<<<<<<<<<< + * return self._undarray.__array_interface__["data"][1] + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("numind.NumInd.readonly.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":127 + * property __array_struct__: + * "Allows other numerical packages to obtain a new object." + * def __get__(self): # <<<<<<<<<<<<<< + * if hasattr(self._undarray, "__array_struct__"): + * return self._undarray.__array_struct__ + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_16__array_struct_____get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_16__array_struct_____get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "numind.pyx":128 + * "Allows other numerical packages to obtain a new object." + * def __get__(self): + * if hasattr(self._undarray, "__array_struct__"): # <<<<<<<<<<<<<< + * return self._undarray.__array_struct__ + * else: + */ + __pyx_t_1 = __pyx_v_self->_undarray; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_HasAttr(__pyx_t_1, __pyx_n_s_array_struct); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 128, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "numind.pyx":129 + * def __get__(self): + * if hasattr(self._undarray, "__array_struct__"): + * return self._undarray.__array_struct__ # <<<<<<<<<<<<<< + * else: + * # No an underlying array with __array_struct__ + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_undarray, __pyx_n_s_array_struct); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "numind.pyx":128 + * "Allows other numerical packages to obtain a new object." + * def __get__(self): + * if hasattr(self._undarray, "__array_struct__"): # <<<<<<<<<<<<<< + * return self._undarray.__array_struct__ + * else: + */ + } + + /* "numind.pyx":133 + * # No an underlying array with __array_struct__ + * # Deliver an equivalent PyCObject. + * Py_INCREF(self) # <<<<<<<<<<<<<< + * return PyCapsule_New(<void*>self.inter, + * "struct array", + */ + /*else*/ { + Py_INCREF(((PyObject *)__pyx_v_self)); + + /* "numind.pyx":134 + * # Deliver an equivalent PyCObject. + * Py_INCREF(self) + * return PyCapsule_New(<void*>self.inter, # <<<<<<<<<<<<<< + * "struct array", + * <PyCapsule_Destructor>free_array_interface) + */ + __Pyx_XDECREF(__pyx_r); + + /* "numind.pyx":136 + * return PyCapsule_New(<void*>self.inter, + * "struct array", + * <PyCapsule_Destructor>free_array_interface) # <<<<<<<<<<<<<< + * + * cdef PyArrayInterface *_get_array_interface(self): + */ + __pyx_t_1 = PyCapsule_New(((void *)__pyx_v_self->inter), ((char *)"struct array"), ((PyCapsule_Destructor)__pyx_f_6numind_free_array_interface)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + + /* "numind.pyx":127 + * property __array_struct__: + * "Allows other numerical packages to obtain a new object." + * def __get__(self): # <<<<<<<<<<<<<< + * if hasattr(self._undarray, "__array_struct__"): + * return self._undarray.__array_struct__ + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numind.NumInd.__array_struct__.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":138 + * <PyCapsule_Destructor>free_array_interface) + * + * cdef PyArrayInterface *_get_array_interface(self): # <<<<<<<<<<<<<< + * "Populates the array interface" + * cdef PyArrayInterface *inter + */ + +static __pyx_t_6numind_PyArrayInterface *__pyx_f_6numind_6NumInd__get_array_interface(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + __pyx_t_6numind_PyArrayInterface *__pyx_v_inter; + PyObject *__pyx_v_undarray = 0; + PyObject *__pyx_v_data_address = 0; + PyObject *__pyx_v_typestr = 0; + PyObject *__pyx_v_obj = 0; + __pyx_t_6numind_PyArrayInterface *__pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + long __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + Py_intptr_t *__pyx_t_8; + __Pyx_RefNannySetupContext("_get_array_interface", 0); + + /* "numind.pyx":144 + * cdef object obj + * + * undarray = self._undarray # <<<<<<<<<<<<<< + * typestr = self.typestr + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + */ + __pyx_t_1 = __pyx_v_self->_undarray; + __Pyx_INCREF(__pyx_t_1); + __pyx_v_undarray = __pyx_t_1; + __pyx_t_1 = 0; + + /* "numind.pyx":145 + * + * undarray = self._undarray + * typestr = self.typestr # <<<<<<<<<<<<<< + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + * if inter is NULL: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_typestr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_typestr = __pyx_t_1; + __pyx_t_1 = 0; + + /* "numind.pyx":146 + * undarray = self._undarray + * typestr = self.typestr + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) # <<<<<<<<<<<<<< + * if inter is NULL: + * raise MemoryError() + */ + __pyx_v_inter = ((__pyx_t_6numind_PyArrayInterface *)malloc((sizeof(__pyx_t_6numind_PyArrayInterface)))); + + /* "numind.pyx":147 + * typestr = self.typestr + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + * if inter is NULL: # <<<<<<<<<<<<<< + * raise MemoryError() + * + */ + __pyx_t_2 = ((__pyx_v_inter == NULL) != 0); + if (__pyx_t_2) { + + /* "numind.pyx":148 + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + * if inter is NULL: + * raise MemoryError() # <<<<<<<<<<<<<< + * + * inter.version = 2 + */ + PyErr_NoMemory(); __PYX_ERR(0, 148, __pyx_L1_error) + + /* "numind.pyx":147 + * typestr = self.typestr + * inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + * if inter is NULL: # <<<<<<<<<<<<<< + * raise MemoryError() + * + */ + } + + /* "numind.pyx":150 + * raise MemoryError() + * + * inter.version = 2 # <<<<<<<<<<<<<< + * inter.nd = self._nd + * inter.typekind = ord(typestr[1]) + */ + __pyx_v_inter->version = 2; + + /* "numind.pyx":151 + * + * inter.version = 2 + * inter.nd = self._nd # <<<<<<<<<<<<<< + * inter.typekind = ord(typestr[1]) + * inter.itemsize = int(typestr[2:]) + */ + __pyx_t_3 = __pyx_v_self->_nd; + __pyx_v_inter->nd = __pyx_t_3; + + /* "numind.pyx":152 + * inter.version = 2 + * inter.nd = self._nd + * inter.typekind = ord(typestr[1]) # <<<<<<<<<<<<<< + * inter.itemsize = int(typestr[2:]) + * inter.flags = 0 # initialize flags + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_typestr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_Ord(__pyx_t_1); if (unlikely(__pyx_t_4 == (long)(Py_UCS4)-1)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->typekind = __pyx_t_4; + + /* "numind.pyx":153 + * inter.nd = self._nd + * inter.typekind = ord(typestr[1]) + * inter.itemsize = int(typestr[2:]) # <<<<<<<<<<<<<< + * inter.flags = 0 # initialize flags + * if typestr[0] == '|': + */ + __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_typestr, 2, 0, NULL, NULL, &__pyx_slice__2, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->itemsize = __pyx_t_3; + + /* "numind.pyx":154 + * inter.typekind = ord(typestr[1]) + * inter.itemsize = int(typestr[2:]) + * inter.flags = 0 # initialize flags # <<<<<<<<<<<<<< + * if typestr[0] == '|': + * inter.flags = inter.flags | NOTSWAPPED + */ + __pyx_v_inter->flags = 0; + + /* "numind.pyx":155 + * inter.itemsize = int(typestr[2:]) + * inter.flags = 0 # initialize flags + * if typestr[0] == '|': # <<<<<<<<<<<<<< + * inter.flags = inter.flags | NOTSWAPPED + * elif byteorder[typestr[0]] == sys.byteorder: + */ + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 155, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_2) { + + /* "numind.pyx":156 + * inter.flags = 0 # initialize flags + * if typestr[0] == '|': + * inter.flags = inter.flags | NOTSWAPPED # <<<<<<<<<<<<<< + * elif byteorder[typestr[0]] == sys.byteorder: + * inter.flags = inter.flags | NOTSWAPPED + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_inter->flags); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_NOTSWAPPED); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Or(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_inter->flags = __pyx_t_3; + + /* "numind.pyx":155 + * inter.itemsize = int(typestr[2:]) + * inter.flags = 0 # initialize flags + * if typestr[0] == '|': # <<<<<<<<<<<<<< + * inter.flags = inter.flags | NOTSWAPPED + * elif byteorder[typestr[0]] == sys.byteorder: + */ + goto __pyx_L4; + } + + /* "numind.pyx":157 + * if typestr[0] == '|': + * inter.flags = inter.flags | NOTSWAPPED + * elif byteorder[typestr[0]] == sys.byteorder: # <<<<<<<<<<<<<< + * inter.flags = inter.flags | NOTSWAPPED + * if not self.readonly: + */ + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_byteorder); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_GetItem(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_byteorder); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "numind.pyx":158 + * inter.flags = inter.flags | NOTSWAPPED + * elif byteorder[typestr[0]] == sys.byteorder: + * inter.flags = inter.flags | NOTSWAPPED # <<<<<<<<<<<<<< + * if not self.readonly: + * inter.flags = inter.flags | WRITEABLE + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_inter->flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_NOTSWAPPED); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyNumber_Or(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->flags = __pyx_t_3; + + /* "numind.pyx":157 + * if typestr[0] == '|': + * inter.flags = inter.flags | NOTSWAPPED + * elif byteorder[typestr[0]] == sys.byteorder: # <<<<<<<<<<<<<< + * inter.flags = inter.flags | NOTSWAPPED + * if not self.readonly: + */ + } + __pyx_L4:; + + /* "numind.pyx":159 + * elif byteorder[typestr[0]] == sys.byteorder: + * inter.flags = inter.flags | NOTSWAPPED + * if not self.readonly: # <<<<<<<<<<<<<< + * inter.flags = inter.flags | WRITEABLE + * # XXX how to determine the ALIGNED flag? + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_readonly); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_7 = ((!__pyx_t_2) != 0); + if (__pyx_t_7) { + + /* "numind.pyx":160 + * inter.flags = inter.flags | NOTSWAPPED + * if not self.readonly: + * inter.flags = inter.flags | WRITEABLE # <<<<<<<<<<<<<< + * # XXX how to determine the ALIGNED flag? + * inter.strides = self._strides + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_inter->flags); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_WRITEABLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyNumber_Or(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 160, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->flags = __pyx_t_3; + + /* "numind.pyx":159 + * elif byteorder[typestr[0]] == sys.byteorder: + * inter.flags = inter.flags | NOTSWAPPED + * if not self.readonly: # <<<<<<<<<<<<<< + * inter.flags = inter.flags | WRITEABLE + * # XXX how to determine the ALIGNED flag? + */ + } + + /* "numind.pyx":162 + * inter.flags = inter.flags | WRITEABLE + * # XXX how to determine the ALIGNED flag? + * inter.strides = self._strides # <<<<<<<<<<<<<< + * inter.shape = self._shape + * # Get the data address + */ + __pyx_t_8 = __pyx_v_self->_strides; + __pyx_v_inter->strides = __pyx_t_8; + + /* "numind.pyx":163 + * # XXX how to determine the ALIGNED flag? + * inter.strides = self._strides + * inter.shape = self._shape # <<<<<<<<<<<<<< + * # Get the data address + * obj = undarray.__array_interface__["data"] + */ + __pyx_t_8 = __pyx_v_self->_shape; + __pyx_v_inter->shape = __pyx_t_8; + + /* "numind.pyx":165 + * inter.shape = self._shape + * # Get the data address + * obj = undarray.__array_interface__["data"] # <<<<<<<<<<<<<< + * data_address = obj[0] + * inter.data = <void*>PyInt_AsLong(data_address) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_undarray, __pyx_n_s_array_interface); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_n_s_data); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_obj = __pyx_t_6; + __pyx_t_6 = 0; + + /* "numind.pyx":166 + * # Get the data address + * obj = undarray.__array_interface__["data"] + * data_address = obj[0] # <<<<<<<<<<<<<< + * inter.data = <void*>PyInt_AsLong(data_address) + * return inter + */ + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_data_address = __pyx_t_6; + __pyx_t_6 = 0; + + /* "numind.pyx":167 + * obj = undarray.__array_interface__["data"] + * data_address = obj[0] + * inter.data = <void*>PyInt_AsLong(data_address) # <<<<<<<<<<<<<< + * return inter + * + */ + __pyx_v_inter->data = ((void *)PyInt_AsLong(__pyx_v_data_address)); + + /* "numind.pyx":168 + * data_address = obj[0] + * inter.data = <void*>PyInt_AsLong(data_address) + * return inter # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_inter; + goto __pyx_L0; + + /* "numind.pyx":138 + * <PyCapsule_Destructor>free_array_interface) + * + * cdef PyArrayInterface *_get_array_interface(self): # <<<<<<<<<<<<<< + * "Populates the array interface" + * cdef PyArrayInterface *inter + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("numind.NumInd._get_array_interface", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_undarray); + __Pyx_XDECREF(__pyx_v_data_address); + __Pyx_XDECREF(__pyx_v_typestr); + __Pyx_XDECREF(__pyx_v_obj); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":173 + * # This is just an example on how to modify the data in C space + * # (and at C speed! :-) + * def modify(self): # <<<<<<<<<<<<<< + * "Modify the values of the underlying array" + * cdef long *ldata + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_6numind_6NumInd_2modify[] = "Modify the values of the underlying array"; +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("modify (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_2modify(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_2modify(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + long *__pyx_v_ldata; + double *__pyx_v_fdata; + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_intptr_t __pyx_t_4; + __Pyx_RefNannySetupContext("modify", 0); + + /* "numind.pyx":180 + * + * # Modify just the first row + * if chr(self.inter.typekind) == 'i': # <<<<<<<<<<<<<< + * ldata = <long *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + */ + __pyx_t_1 = __Pyx_PyInt_From_char(__pyx_v_self->inter->typekind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 180, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "numind.pyx":181 + * # Modify just the first row + * if chr(self.inter.typekind) == 'i': + * ldata = <long *>self.inter.data # <<<<<<<<<<<<<< + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * ldata[i] = ldata[i] + 1 + */ + __pyx_v_ldata = ((long *)__pyx_v_self->inter->data); + + /* "numind.pyx":182 + * if chr(self.inter.typekind) == 'i': + * ldata = <long *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: # <<<<<<<<<<<<<< + * ldata[i] = ldata[i] + 1 + * elif chr(self.inter.typekind) == 'f': + */ + __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "numind.pyx":183 + * ldata = <long *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * ldata[i] = ldata[i] + 1 # <<<<<<<<<<<<<< + * elif chr(self.inter.typekind) == 'f': + * fdata = <double *>self.inter.data + */ + (__pyx_v_ldata[__pyx_v_i]) = ((__pyx_v_ldata[__pyx_v_i]) + 1); + } + + /* "numind.pyx":180 + * + * # Modify just the first row + * if chr(self.inter.typekind) == 'i': # <<<<<<<<<<<<<< + * ldata = <long *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + */ + goto __pyx_L3; + } + + /* "numind.pyx":184 + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * ldata[i] = ldata[i] + 1 + * elif chr(self.inter.typekind) == 'f': # <<<<<<<<<<<<<< + * fdata = <double *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + */ + __pyx_t_1 = __Pyx_PyInt_From_char(__pyx_v_self->inter->typekind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 184, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "numind.pyx":185 + * ldata[i] = ldata[i] + 1 + * elif chr(self.inter.typekind) == 'f': + * fdata = <double *>self.inter.data # <<<<<<<<<<<<<< + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * fdata[i] = fdata[i] + 1 + */ + __pyx_v_fdata = ((double *)__pyx_v_self->inter->data); + + /* "numind.pyx":186 + * elif chr(self.inter.typekind) == 'f': + * fdata = <double *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: # <<<<<<<<<<<<<< + * fdata[i] = fdata[i] + 1 + * + */ + __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "numind.pyx":187 + * fdata = <double *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * fdata[i] = fdata[i] + 1 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + (__pyx_v_fdata[__pyx_v_i]) = ((__pyx_v_fdata[__pyx_v_i]) + 1.0); + } + + /* "numind.pyx":184 + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + * ldata[i] = ldata[i] + 1 + * elif chr(self.inter.typekind) == 'f': # <<<<<<<<<<<<<< + * fdata = <double *>self.inter.data + * for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + */ + } + __pyx_L3:; + + /* "numind.pyx":173 + * # This is just an example on how to modify the data in C space + * # (and at C speed! :-) + * def modify(self): # <<<<<<<<<<<<<< + * "Modify the values of the underlying array" + * cdef long *ldata + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("numind.NumInd.modify", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "numind.pyx":189 + * fdata[i] = fdata[i] + 1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self._shape) + * free(self._strides) + */ + +/* Python wrapper */ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_6numind_6NumInd_4__dealloc__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_6numind_6NumInd_4__dealloc__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "numind.pyx":190 + * + * def __dealloc__(self): + * free(self._shape) # <<<<<<<<<<<<<< + * free(self._strides) + * free(self.inter) + */ + free(__pyx_v_self->_shape); + + /* "numind.pyx":191 + * def __dealloc__(self): + * free(self._shape) + * free(self._strides) # <<<<<<<<<<<<<< + * free(self.inter) + */ + free(__pyx_v_self->_strides); + + /* "numind.pyx":192 + * free(self._shape) + * free(self._strides) + * free(self.inter) # <<<<<<<<<<<<<< + */ + free(__pyx_v_self->inter); + + /* "numind.pyx":189 + * fdata[i] = fdata[i] + 1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self._shape) + * free(self._strides) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_6__reduce_cython__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numind.NumInd.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8__setstate_cython__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_6numind_NumInd *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":4 + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numind.NumInd.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_6numind_NumInd __pyx_vtable_6numind_NumInd; + +static PyObject *__pyx_tp_new_6numind_NumInd(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_6numind_NumInd *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_6numind_NumInd *)o); + p->__pyx_vtab = __pyx_vtabptr_6numind_NumInd; + p->_t_shape = Py_None; Py_INCREF(Py_None); + p->_t_strides = Py_None; Py_INCREF(Py_None); + p->_undarray = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_6numind_NumInd(PyObject *o) { + struct __pyx_obj_6numind_NumInd *p = (struct __pyx_obj_6numind_NumInd *)o; + #if PY_VERSION_HEX >= 0x030400a1 + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_6numind_6NumInd_5__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->_t_shape); + Py_CLEAR(p->_t_strides); + Py_CLEAR(p->_undarray); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_6numind_NumInd(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_6numind_NumInd *p = (struct __pyx_obj_6numind_NumInd *)o; + if (p->_t_shape) { + e = (*v)(p->_t_shape, a); if (e) return e; + } + if (p->_t_strides) { + e = (*v)(p->_t_strides, a); if (e) return e; + } + if (p->_undarray) { + e = (*v)(p->_undarray, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_6numind_NumInd(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_6numind_NumInd *p = (struct __pyx_obj_6numind_NumInd *)o; + tmp = ((PyObject*)p->_t_shape); + p->_t_shape = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_t_strides); + p->_t_strides = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_undarray); + p->_undarray = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_6numind_6NumInd_undarray(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_8undarray_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd_shape(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_5shape_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd_strides(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_7strides_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd_typestr(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_7typestr_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd_typekind(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_8typekind_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd_readonly(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_8readonly_1__get__(o); +} + +static PyObject *__pyx_getprop_6numind_6NumInd___array_struct__(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_6numind_6NumInd_16__array_struct___1__get__(o); +} + +static PyMethodDef __pyx_methods_6numind_NumInd[] = { + {"modify", (PyCFunction)__pyx_pw_6numind_6NumInd_3modify, METH_NOARGS, __pyx_doc_6numind_6NumInd_2modify}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_6numind_6NumInd_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_6numind_6NumInd_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_6numind_NumInd[] = { + {(char *)"undarray", __pyx_getprop_6numind_6NumInd_undarray, 0, (char *)0, 0}, + {(char *)"shape", __pyx_getprop_6numind_6NumInd_shape, 0, (char *)0, 0}, + {(char *)"strides", __pyx_getprop_6numind_6NumInd_strides, 0, (char *)0, 0}, + {(char *)"typestr", __pyx_getprop_6numind_6NumInd_typestr, 0, (char *)0, 0}, + {(char *)"typekind", __pyx_getprop_6numind_6NumInd_typekind, 0, (char *)0, 0}, + {(char *)"readonly", __pyx_getprop_6numind_6NumInd_readonly, 0, (char *)0, 0}, + {(char *)"__array_struct__", __pyx_getprop_6numind_6NumInd___array_struct__, 0, (char *)"Allows other numerical packages to obtain a new object.", 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_6numind_NumInd = { + PyVarObject_HEAD_INIT(0, 0) + "numind.NumInd", /*tp_name*/ + sizeof(struct __pyx_obj_6numind_NumInd), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_6numind_NumInd, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_6numind_NumInd, /*tp_traverse*/ + __pyx_tp_clear_6numind_NumInd, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_6numind_NumInd, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_6numind_NumInd, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_6numind_6NumInd_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_6numind_NumInd, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + #if PY_VERSION_HEX < 0x03020000 + { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, + #else + PyModuleDef_HEAD_INIT, + #endif + "numind", + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_ALIGNED, __pyx_k_ALIGNED, sizeof(__pyx_k_ALIGNED), 0, 0, 1, 1}, + {&__pyx_n_s_CONTIGUOUS, __pyx_k_CONTIGUOUS, sizeof(__pyx_k_CONTIGUOUS), 0, 0, 1, 1}, + {&__pyx_n_s_FORTRAN, __pyx_k_FORTRAN, sizeof(__pyx_k_FORTRAN), 0, 0, 1, 1}, + {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, + {&__pyx_n_s_NOTSWAPPED, __pyx_k_NOTSWAPPED, sizeof(__pyx_k_NOTSWAPPED), 0, 0, 1, 1}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_n_s_WRITEABLE, __pyx_k_WRITEABLE, sizeof(__pyx_k_WRITEABLE), 0, 0, 1, 1}, + {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0}, + {&__pyx_kp_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 0}, + {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0}, + {&__pyx_n_s_array_interface, __pyx_k_array_interface, sizeof(__pyx_k_array_interface), 0, 0, 1, 1}, + {&__pyx_n_s_array_struct, __pyx_k_array_struct, sizeof(__pyx_k_array_struct), 0, 0, 1, 1}, + {&__pyx_n_s_big, __pyx_k_big, sizeof(__pyx_k_big), 0, 0, 1, 1}, + {&__pyx_n_s_byteorder, __pyx_k_byteorder, sizeof(__pyx_k_byteorder), 0, 0, 1, 1}, + {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_little, __pyx_k_little, sizeof(__pyx_k_little), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, + {&__pyx_n_s_readonly, __pyx_k_readonly, sizeof(__pyx_k_readonly), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_kp_s_self__shape_self__strides_self_d, __pyx_k_self__shape_self__strides_self_d, sizeof(__pyx_k_self__shape_self__strides_self_d), 0, 0, 1, 0}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, + {&__pyx_n_s_strides, __pyx_k_strides, sizeof(__pyx_k_strides), 0, 0, 1, 1}, + {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_typestr, __pyx_k_typestr, sizeof(__pyx_k_typestr), 0, 0, 1, 1}, + {&__pyx_n_s_undarray, __pyx_k_undarray, sizeof(__pyx_k_undarray), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "numind.pyx":89 + * # strides is None. Compute them explicitely. + * self._t_strides = [0] * self._nd + * stride = int(self.typestr[2:]) # <<<<<<<<<<<<<< + * for i from self._nd > i >= 0: + * self._strides[i] = stride + */ + __pyx_slice_ = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice_); + __Pyx_GIVEREF(__pyx_slice_); + + /* "numind.pyx":153 + * inter.nd = self._nd + * inter.typekind = ord(typestr[1]) + * inter.itemsize = int(typestr[2:]) # <<<<<<<<<<<<<< + * inter.flags = 0 # initialize flags + * if typestr[0] == '|': + */ + __pyx_slice__2 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__2)) __PYX_ERR(0, 153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__2); + __Pyx_GIVEREF(__pyx_slice__2); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_self__shape_self__strides_self_d); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "(tree fragment)":4 + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._shape,self._strides,self.data,self.inter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_self__shape_self__strides_self_d); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_512 = PyInt_FromLong(512); if (unlikely(!__pyx_int_512)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC initnumind(void); /*proto*/ +PyMODINIT_FUNC initnumind(void) +#else +PyMODINIT_FUNC PyInit_numind(void); /*proto*/ +PyMODINIT_FUNC PyInit_numind(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_REFNANNY + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + #endif + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_numind(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("numind", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_numind) { + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "numind")) { + if (unlikely(PyDict_SetItemString(modules, "numind", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global init code ---*/ + /*--- Variable export code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + __pyx_vtabptr_6numind_NumInd = &__pyx_vtable_6numind_NumInd; + __pyx_vtable_6numind_NumInd._get_array_interface = (__pyx_t_6numind_PyArrayInterface *(*)(struct __pyx_obj_6numind_NumInd *))__pyx_f_6numind_6NumInd__get_array_interface; + if (PyType_Ready(&__pyx_type_6numind_NumInd) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_type_6numind_NumInd.tp_print = 0; + if (__Pyx_SetVtable(__pyx_type_6numind_NumInd.tp_dict, __pyx_vtabptr_6numind_NumInd) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "NumInd", (PyObject *)&__pyx_type_6numind_NumInd) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_6numind_NumInd) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_ptype_6numind_NumInd = &__pyx_type_6numind_NumInd; + /*--- Type import code ---*/ + /*--- Variable import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "numind.pyx":13 + * # Author: Francesc Altet + * + * import sys # <<<<<<<<<<<<<< + * from cpython.pycapsule cimport * + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "numind.pyx":33 + * + * # for PyArrayInterface: + * CONTIGUOUS=0x01 # <<<<<<<<<<<<<< + * FORTRAN=0x02 + * ALIGNED=0x100 + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CONTIGUOUS, __pyx_int_1) < 0) __PYX_ERR(0, 33, __pyx_L1_error) + + /* "numind.pyx":34 + * # for PyArrayInterface: + * CONTIGUOUS=0x01 + * FORTRAN=0x02 # <<<<<<<<<<<<<< + * ALIGNED=0x100 + * NOTSWAPPED=0x200 + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_FORTRAN, __pyx_int_2) < 0) __PYX_ERR(0, 34, __pyx_L1_error) + + /* "numind.pyx":35 + * CONTIGUOUS=0x01 + * FORTRAN=0x02 + * ALIGNED=0x100 # <<<<<<<<<<<<<< + * NOTSWAPPED=0x200 + * WRITEABLE=0x400 + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ALIGNED, __pyx_int_256) < 0) __PYX_ERR(0, 35, __pyx_L1_error) + + /* "numind.pyx":36 + * FORTRAN=0x02 + * ALIGNED=0x100 + * NOTSWAPPED=0x200 # <<<<<<<<<<<<<< + * WRITEABLE=0x400 + * + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NOTSWAPPED, __pyx_int_512) < 0) __PYX_ERR(0, 36, __pyx_L1_error) + + /* "numind.pyx":37 + * ALIGNED=0x100 + * NOTSWAPPED=0x200 + * WRITEABLE=0x400 # <<<<<<<<<<<<<< + * + * # byteorder dictionary + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_WRITEABLE, __pyx_int_1024) < 0) __PYX_ERR(0, 37, __pyx_L1_error) + + /* "numind.pyx":40 + * + * # byteorder dictionary + * byteorder = {'<':'little', '>':'big'} # <<<<<<<<<<<<<< + * + * ctypedef struct PyArrayInterface: + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s__6, __pyx_n_s_little) < 0) __PYX_ERR(0, 40, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s__7, __pyx_n_s_big) < 0) __PYX_ERR(0, 40, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_byteorder, __pyx_t_1) < 0) __PYX_ERR(0, 40, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "numind.pyx":1 + * # This Pyrex extension class can take a numpy/numarray/Numeric object # <<<<<<<<<<<<<< + * # as a parameter and wrap it so that its information can be accessed + * # in a standard way, both in Python space and C space. + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init numind", 0, __pyx_lineno, __pyx_filename); + } + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init numind"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif +} + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); + if (unlikely(!result)) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* RaiseDoubleKeywords */ +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + continue; + } + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = (**name == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* GetItemInt */ +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* SliceObject */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, + Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, + int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { +#if CYTHON_USE_TYPE_SLOTS + PyMappingMethods* mp; +#if PY_MAJOR_VERSION < 3 + PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; + if (likely(ms && ms->sq_slice)) { + if (!has_cstart) { + if (_py_start && (*_py_start != Py_None)) { + cstart = __Pyx_PyIndex_AsSsize_t(*_py_start); + if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstart = 0; + } + if (!has_cstop) { + if (_py_stop && (*_py_stop != Py_None)) { + cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop); + if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstop = PY_SSIZE_T_MAX; + } + if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { + Py_ssize_t l = ms->sq_length(obj); + if (likely(l >= 0)) { + if (cstop < 0) { + cstop += l; + if (cstop < 0) cstop = 0; + } + if (cstart < 0) { + cstart += l; + if (cstart < 0) cstart = 0; + } + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + goto bad; + PyErr_Clear(); + } + } + return ms->sq_slice(obj, cstart, cstop); + } +#endif + mp = Py_TYPE(obj)->tp_as_mapping; + if (likely(mp && mp->mp_subscript)) +#endif + { + PyObject* result; + PyObject *py_slice, *py_start, *py_stop; + if (_py_slice) { + py_slice = *_py_slice; + } else { + PyObject* owned_start = NULL; + PyObject* owned_stop = NULL; + if (_py_start) { + py_start = *_py_start; + } else { + if (has_cstart) { + owned_start = py_start = PyInt_FromSsize_t(cstart); + if (unlikely(!py_start)) goto bad; + } else + py_start = Py_None; + } + if (_py_stop) { + py_stop = *_py_stop; + } else { + if (has_cstop) { + owned_stop = py_stop = PyInt_FromSsize_t(cstop); + if (unlikely(!py_stop)) { + Py_XDECREF(owned_start); + goto bad; + } + } else + py_stop = Py_None; + } + py_slice = PySlice_New(py_start, py_stop, Py_None); + Py_XDECREF(owned_start); + Py_XDECREF(owned_stop); + if (unlikely(!py_slice)) goto bad; + } +#if CYTHON_USE_TYPE_SLOTS + result = mp->mp_subscript(obj, py_slice); +#else + result = PyObject_GetItem(obj, py_slice); +#endif + if (!_py_slice) { + Py_DECREF(py_slice); + } + return result; + } + PyErr_Format(PyExc_TypeError, + "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name); +bad: + return NULL; +} + +/* SetItemInt */ +static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { + int r; + if (!j) return -1; + r = PyObject_SetItem(o, j, v); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list, + CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o)); + if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject* old = PyList_GET_ITEM(o, n); + Py_INCREF(v); + PyList_SET_ITEM(o, n, v); + Py_DECREF(old); + return 1; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_ass_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return -1; + PyErr_Clear(); + } + } + return m->sq_ass_item(o, i, v); + } + } +#else +#if CYTHON_COMPILING_IN_PYPY + if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) { +#else + if (is_list || PySequence_Check(o)) { +#endif + return PySequence_SetItem(o, i, v); + } +#endif + return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); +} + +/* PyObjectCall */ + #if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* GetAttr */ + static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_COMPILING_IN_CPYTHON +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* HasAttr */ + static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; + } + r = __Pyx_GetAttr(o, n); + if (unlikely(!r)) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; + } +} + +/* UnicodeAsUCS4 */ + static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) { + Py_ssize_t length; + #if CYTHON_PEP393_ENABLED + length = PyUnicode_GET_LENGTH(x); + if (likely(length == 1)) { + return PyUnicode_READ_CHAR(x, 0); + } + #else + length = PyUnicode_GET_SIZE(x); + if (likely(length == 1)) { + return PyUnicode_AS_UNICODE(x)[0]; + } + #if Py_UNICODE_SIZE == 2 + else if (PyUnicode_GET_SIZE(x) == 2) { + Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0]; + if (high_val >= 0xD800 && high_val <= 0xDBFF) { + Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1]; + if (low_val >= 0xDC00 && low_val <= 0xDFFF) { + return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1))); + } + } + } + #endif + #endif + PyErr_Format(PyExc_ValueError, + "only single character unicode strings can be converted to Py_UCS4, " + "got length %" CYTHON_FORMAT_SSIZE_T "d", length); + return (Py_UCS4)-1; +} + +/* object_ord */ + static long __Pyx__PyObject_Ord(PyObject* c) { + Py_ssize_t size; + if (PyBytes_Check(c)) { + size = PyBytes_GET_SIZE(c); + if (likely(size == 1)) { + return (unsigned char) PyBytes_AS_STRING(c)[0]; + } +#if PY_MAJOR_VERSION < 3 + } else if (PyUnicode_Check(c)) { + return (long)__Pyx_PyUnicode_AsPy_UCS4(c); +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + } else if (PyByteArray_Check(c)) { + size = PyByteArray_GET_SIZE(c); + if (likely(size == 1)) { + return (unsigned char) PyByteArray_AS_STRING(c)[0]; + } +#endif + } else { + PyErr_Format(PyExc_TypeError, + "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name); + return (long)(Py_UCS4)-1; + } + PyErr_Format(PyExc_TypeError, + "ord() expected a character, but string of length %zd found", size); + return (long)(Py_UCS4)-1; +} + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* GetModuleGlobalName */ + static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS + result = PyDict_GetItem(__pyx_d, name); + if (likely(result)) { + Py_INCREF(result); + } else { +#else + result = PyObject_GetItem(__pyx_d, name); + if (!result) { + PyErr_Clear(); +#endif + result = __Pyx_GetBuiltinName(name); + } + return result; +} + +/* PyErrFetchRestore */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* WriteUnraisableException */ + static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, + int full_traceback, CYTHON_UNUSED int nogil) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_PyThreadState_declare +#ifdef WITH_THREAD + PyGILState_STATE state; + if (nogil) + state = PyGILState_Ensure(); +#ifdef _MSC_VER + else state = (PyGILState_STATE)-1; +#endif +#endif + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + if (full_traceback) { + Py_XINCREF(old_exc); + Py_XINCREF(old_val); + Py_XINCREF(old_tb); + __Pyx_ErrRestore(old_exc, old_val, old_tb); + PyErr_PrintEx(1); + } + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +#ifdef WITH_THREAD + if (nogil) + PyGILState_Release(state); +#endif +} + +/* RaiseException */ + #if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } +#if PY_VERSION_HEX >= 0x03030000 + if (cause) { +#else + if (cause && cause != Py_None) { +#endif + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* SetVTable */ + static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +/* SetupReduce */ + static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; + setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto GOOD; +BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +GOOD: +#if !CYTHON_COMPILING_IN_CPYTHON + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} + +/* Import */ + static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (!py_import) + goto bad; + #endif + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_level = PyInt_FromLong(1); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + #endif + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } +bad: + #if PY_VERSION_HEX < 0x03030000 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* CLineInTraceback */ + static int __Pyx_CLineForTraceback(int c_line) { +#ifdef CYTHON_CLINE_IN_TRACEBACK + return ((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0; +#else + PyObject *use_cline; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + use_cline = PyDict_GetItem(*cython_runtime_dict, __pyx_n_s_cline_in_traceback); + } else +#endif + { + PyObject *ptype, *pvalue, *ptraceback; + PyObject *use_cline_obj; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + use_cline = NULL; + } + PyErr_Restore(ptype, pvalue, ptraceback); + } + if (!use_cline) { + c_line = 0; + PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (PyObject_Not(use_cline) != 0) { + c_line = 0; + } + return c_line; +#endif +} + +/* CodeObjectCache */ + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +/* AddTraceback */ + #include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + if (c_line) { + c_line = __Pyx_CLineForTraceback(c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + +/* CIntFromPyVerify */ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) { + const char neg_one = (char) -1, const_zero = (char) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(char) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(char) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(char) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(char), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE Py_intptr_t __Pyx_PyInt_As_Py_intptr_t(PyObject *x) { + const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = (Py_intptr_t) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(Py_intptr_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (Py_intptr_t) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (Py_intptr_t) 0; + case 1: __PYX_VERIFY_RETURN_INT(Py_intptr_t, digit, digits[0]) + case 2: + if (8 * sizeof(Py_intptr_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) >= 2 * PyLong_SHIFT) { + return (Py_intptr_t) (((((Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(Py_intptr_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) >= 3 * PyLong_SHIFT) { + return (Py_intptr_t) (((((((Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(Py_intptr_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) >= 4 * PyLong_SHIFT) { + return (Py_intptr_t) (((((((((Py_intptr_t)digits[3]) << PyLong_SHIFT) | (Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (Py_intptr_t) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(Py_intptr_t, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(Py_intptr_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (Py_intptr_t) 0; + case -1: __PYX_VERIFY_RETURN_INT(Py_intptr_t, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(Py_intptr_t, digit, +digits[0]) + case -2: + if (8 * sizeof(Py_intptr_t) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 2 * PyLong_SHIFT) { + return (Py_intptr_t) (((Py_intptr_t)-1)*(((((Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(Py_intptr_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 2 * PyLong_SHIFT) { + return (Py_intptr_t) ((((((Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(Py_intptr_t) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 3 * PyLong_SHIFT) { + return (Py_intptr_t) (((Py_intptr_t)-1)*(((((((Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(Py_intptr_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 3 * PyLong_SHIFT) { + return (Py_intptr_t) ((((((((Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(Py_intptr_t) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 4 * PyLong_SHIFT) { + return (Py_intptr_t) (((Py_intptr_t)-1)*(((((((((Py_intptr_t)digits[3]) << PyLong_SHIFT) | (Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(Py_intptr_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(Py_intptr_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(Py_intptr_t) - 1 > 4 * PyLong_SHIFT) { + return (Py_intptr_t) ((((((((((Py_intptr_t)digits[3]) << PyLong_SHIFT) | (Py_intptr_t)digits[2]) << PyLong_SHIFT) | (Py_intptr_t)digits[1]) << PyLong_SHIFT) | (Py_intptr_t)digits[0]))); + } + } + break; + } +#endif + if (sizeof(Py_intptr_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(Py_intptr_t, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(Py_intptr_t) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(Py_intptr_t, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + Py_intptr_t val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (Py_intptr_t) -1; + } + } else { + Py_intptr_t val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (Py_intptr_t) -1; + val = __Pyx_PyInt_As_Py_intptr_t(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to Py_intptr_t"); + return (Py_intptr_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to Py_intptr_t"); + return (Py_intptr_t) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CheckBinaryVersion */ + static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + return PyErr_WarnEx(NULL, message, 1); + } + return 0; +} + +/* InitStrings */ + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + PyErr_Clear(); + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { +#if PY_VERSION_HEX < 0x03030000 + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +#else + if (__Pyx_PyUnicode_READY(o) == -1) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (PyUnicode_IS_ASCII(o)) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +#endif + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } + #else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } + #endif +#else + res = PyNumber_Int(x); +#endif + if (res) { +#if PY_MAJOR_VERSION < 3 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(x); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +#endif /* Py_PYTHON_H */ diff --git a/pymolfile/molfile/numind-cython/numind.h b/pymolfile/molfile/numind-cython/numind.h new file mode 100644 index 0000000000000000000000000000000000000000..988c2c80604711a3067cf39a3976896c48867526 --- /dev/null +++ b/pymolfile/molfile/numind-cython/numind.h @@ -0,0 +1,12 @@ +#ifndef NUMIND_H +#define NUMIND_H + +typedef struct SignedIntBuf +{ + int* data; + int shape[2]; + int strides[2]; +} SignedIntBuf; + +#endif + diff --git a/pymolfile/molfile/numind-cython/numind.html b/pymolfile/molfile/numind-cython/numind.html new file mode 100644 index 0000000000000000000000000000000000000000..96768d145b96058d800f53ece01d88f4c34cb278 --- /dev/null +++ b/pymolfile/molfile/numind-cython/numind.html @@ -0,0 +1,1243 @@ +<!DOCTYPE html> +<!-- Generated by Cython 0.26.1 --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Cython: numind.pyx</title> + <style type="text/css"> + +body.cython { font-family: courier; font-size: 12; } + +.cython.tag { } +.cython.line { margin: 0em } +.cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; } + +.cython.line .run { background-color: #B0FFB0; } +.cython.line .mis { background-color: #FFB0B0; } +.cython.code.run { border-left: 8px solid #B0FFB0; } +.cython.code.mis { border-left: 8px solid #FFB0B0; } + +.cython.code .py_c_api { color: red; } +.cython.code .py_macro_api { color: #FF7000; } +.cython.code .pyx_c_api { color: #FF3000; } +.cython.code .pyx_macro_api { color: #FF7000; } +.cython.code .refnanny { color: #FFA000; } +.cython.code .trace { color: #FFA000; } +.cython.code .error_goto { color: #FFA000; } + +.cython.code .coerce { color: #008000; border: 1px dotted #008000 } +.cython.code .py_attr { color: #FF0000; font-weight: bold; } +.cython.code .c_attr { color: #0000FF; } +.cython.code .py_call { color: #FF0000; font-weight: bold; } +.cython.code .c_call { color: #0000FF; } + +.cython.score-0 {background-color: #FFFFff;} +.cython.score-1 {background-color: #FFFFe7;} +.cython.score-2 {background-color: #FFFFd4;} +.cython.score-3 {background-color: #FFFFc4;} +.cython.score-4 {background-color: #FFFFb6;} +.cython.score-5 {background-color: #FFFFaa;} +.cython.score-6 {background-color: #FFFF9f;} +.cython.score-7 {background-color: #FFFF96;} +.cython.score-8 {background-color: #FFFF8d;} +.cython.score-9 {background-color: #FFFF86;} +.cython.score-10 {background-color: #FFFF7f;} +.cython.score-11 {background-color: #FFFF79;} +.cython.score-12 {background-color: #FFFF73;} +.cython.score-13 {background-color: #FFFF6e;} +.cython.score-14 {background-color: #FFFF6a;} +.cython.score-15 {background-color: #FFFF66;} +.cython.score-16 {background-color: #FFFF62;} +.cython.score-17 {background-color: #FFFF5e;} +.cython.score-18 {background-color: #FFFF5b;} +.cython.score-19 {background-color: #FFFF57;} +.cython.score-20 {background-color: #FFFF55;} +.cython.score-21 {background-color: #FFFF52;} +.cython.score-22 {background-color: #FFFF4f;} +.cython.score-23 {background-color: #FFFF4d;} +.cython.score-24 {background-color: #FFFF4b;} +.cython.score-25 {background-color: #FFFF48;} +.cython.score-26 {background-color: #FFFF46;} +.cython.score-27 {background-color: #FFFF44;} +.cython.score-28 {background-color: #FFFF43;} +.cython.score-29 {background-color: #FFFF41;} +.cython.score-30 {background-color: #FFFF3f;} +.cython.score-31 {background-color: #FFFF3e;} +.cython.score-32 {background-color: #FFFF3c;} +.cython.score-33 {background-color: #FFFF3b;} +.cython.score-34 {background-color: #FFFF39;} +.cython.score-35 {background-color: #FFFF38;} +.cython.score-36 {background-color: #FFFF37;} +.cython.score-37 {background-color: #FFFF36;} +.cython.score-38 {background-color: #FFFF35;} +.cython.score-39 {background-color: #FFFF34;} +.cython.score-40 {background-color: #FFFF33;} +.cython.score-41 {background-color: #FFFF32;} +.cython.score-42 {background-color: #FFFF31;} +.cython.score-43 {background-color: #FFFF30;} +.cython.score-44 {background-color: #FFFF2f;} +.cython.score-45 {background-color: #FFFF2e;} +.cython.score-46 {background-color: #FFFF2d;} +.cython.score-47 {background-color: #FFFF2c;} +.cython.score-48 {background-color: #FFFF2b;} +.cython.score-49 {background-color: #FFFF2b;} +.cython.score-50 {background-color: #FFFF2a;} +.cython.score-51 {background-color: #FFFF29;} +.cython.score-52 {background-color: #FFFF29;} +.cython.score-53 {background-color: #FFFF28;} +.cython.score-54 {background-color: #FFFF27;} +.cython.score-55 {background-color: #FFFF27;} +.cython.score-56 {background-color: #FFFF26;} +.cython.score-57 {background-color: #FFFF26;} +.cython.score-58 {background-color: #FFFF25;} +.cython.score-59 {background-color: #FFFF24;} +.cython.score-60 {background-color: #FFFF24;} +.cython.score-61 {background-color: #FFFF23;} +.cython.score-62 {background-color: #FFFF23;} +.cython.score-63 {background-color: #FFFF22;} +.cython.score-64 {background-color: #FFFF22;} +.cython.score-65 {background-color: #FFFF22;} +.cython.score-66 {background-color: #FFFF21;} +.cython.score-67 {background-color: #FFFF21;} +.cython.score-68 {background-color: #FFFF20;} +.cython.score-69 {background-color: #FFFF20;} +.cython.score-70 {background-color: #FFFF1f;} +.cython.score-71 {background-color: #FFFF1f;} +.cython.score-72 {background-color: #FFFF1f;} +.cython.score-73 {background-color: #FFFF1e;} +.cython.score-74 {background-color: #FFFF1e;} +.cython.score-75 {background-color: #FFFF1e;} +.cython.score-76 {background-color: #FFFF1d;} +.cython.score-77 {background-color: #FFFF1d;} +.cython.score-78 {background-color: #FFFF1c;} +.cython.score-79 {background-color: #FFFF1c;} +.cython.score-80 {background-color: #FFFF1c;} +.cython.score-81 {background-color: #FFFF1c;} +.cython.score-82 {background-color: #FFFF1b;} +.cython.score-83 {background-color: #FFFF1b;} +.cython.score-84 {background-color: #FFFF1b;} +.cython.score-85 {background-color: #FFFF1a;} +.cython.score-86 {background-color: #FFFF1a;} +.cython.score-87 {background-color: #FFFF1a;} +.cython.score-88 {background-color: #FFFF1a;} +.cython.score-89 {background-color: #FFFF19;} +.cython.score-90 {background-color: #FFFF19;} +.cython.score-91 {background-color: #FFFF19;} +.cython.score-92 {background-color: #FFFF19;} +.cython.score-93 {background-color: #FFFF18;} +.cython.score-94 {background-color: #FFFF18;} +.cython.score-95 {background-color: #FFFF18;} +.cython.score-96 {background-color: #FFFF18;} +.cython.score-97 {background-color: #FFFF17;} +.cython.score-98 {background-color: #FFFF17;} +.cython.score-99 {background-color: #FFFF17;} +.cython.score-100 {background-color: #FFFF17;} +.cython.score-101 {background-color: #FFFF16;} +.cython.score-102 {background-color: #FFFF16;} +.cython.score-103 {background-color: #FFFF16;} +.cython.score-104 {background-color: #FFFF16;} +.cython.score-105 {background-color: #FFFF16;} +.cython.score-106 {background-color: #FFFF15;} +.cython.score-107 {background-color: #FFFF15;} +.cython.score-108 {background-color: #FFFF15;} +.cython.score-109 {background-color: #FFFF15;} +.cython.score-110 {background-color: #FFFF15;} +.cython.score-111 {background-color: #FFFF15;} +.cython.score-112 {background-color: #FFFF14;} +.cython.score-113 {background-color: #FFFF14;} +.cython.score-114 {background-color: #FFFF14;} +.cython.score-115 {background-color: #FFFF14;} +.cython.score-116 {background-color: #FFFF14;} +.cython.score-117 {background-color: #FFFF14;} +.cython.score-118 {background-color: #FFFF13;} +.cython.score-119 {background-color: #FFFF13;} +.cython.score-120 {background-color: #FFFF13;} +.cython.score-121 {background-color: #FFFF13;} +.cython.score-122 {background-color: #FFFF13;} +.cython.score-123 {background-color: #FFFF13;} +.cython.score-124 {background-color: #FFFF13;} +.cython.score-125 {background-color: #FFFF12;} +.cython.score-126 {background-color: #FFFF12;} +.cython.score-127 {background-color: #FFFF12;} +.cython.score-128 {background-color: #FFFF12;} +.cython.score-129 {background-color: #FFFF12;} +.cython.score-130 {background-color: #FFFF12;} +.cython.score-131 {background-color: #FFFF12;} +.cython.score-132 {background-color: #FFFF11;} +.cython.score-133 {background-color: #FFFF11;} +.cython.score-134 {background-color: #FFFF11;} +.cython.score-135 {background-color: #FFFF11;} +.cython.score-136 {background-color: #FFFF11;} +.cython.score-137 {background-color: #FFFF11;} +.cython.score-138 {background-color: #FFFF11;} +.cython.score-139 {background-color: #FFFF11;} +.cython.score-140 {background-color: #FFFF11;} +.cython.score-141 {background-color: #FFFF10;} +.cython.score-142 {background-color: #FFFF10;} +.cython.score-143 {background-color: #FFFF10;} +.cython.score-144 {background-color: #FFFF10;} +.cython.score-145 {background-color: #FFFF10;} +.cython.score-146 {background-color: #FFFF10;} +.cython.score-147 {background-color: #FFFF10;} +.cython.score-148 {background-color: #FFFF10;} +.cython.score-149 {background-color: #FFFF10;} +.cython.score-150 {background-color: #FFFF0f;} +.cython.score-151 {background-color: #FFFF0f;} +.cython.score-152 {background-color: #FFFF0f;} +.cython.score-153 {background-color: #FFFF0f;} +.cython.score-154 {background-color: #FFFF0f;} +.cython.score-155 {background-color: #FFFF0f;} +.cython.score-156 {background-color: #FFFF0f;} +.cython.score-157 {background-color: #FFFF0f;} +.cython.score-158 {background-color: #FFFF0f;} +.cython.score-159 {background-color: #FFFF0f;} +.cython.score-160 {background-color: #FFFF0f;} +.cython.score-161 {background-color: #FFFF0e;} +.cython.score-162 {background-color: #FFFF0e;} +.cython.score-163 {background-color: #FFFF0e;} +.cython.score-164 {background-color: #FFFF0e;} +.cython.score-165 {background-color: #FFFF0e;} +.cython.score-166 {background-color: #FFFF0e;} +.cython.score-167 {background-color: #FFFF0e;} +.cython.score-168 {background-color: #FFFF0e;} +.cython.score-169 {background-color: #FFFF0e;} +.cython.score-170 {background-color: #FFFF0e;} +.cython.score-171 {background-color: #FFFF0e;} +.cython.score-172 {background-color: #FFFF0e;} +.cython.score-173 {background-color: #FFFF0d;} +.cython.score-174 {background-color: #FFFF0d;} +.cython.score-175 {background-color: #FFFF0d;} +.cython.score-176 {background-color: #FFFF0d;} +.cython.score-177 {background-color: #FFFF0d;} +.cython.score-178 {background-color: #FFFF0d;} +.cython.score-179 {background-color: #FFFF0d;} +.cython.score-180 {background-color: #FFFF0d;} +.cython.score-181 {background-color: #FFFF0d;} +.cython.score-182 {background-color: #FFFF0d;} +.cython.score-183 {background-color: #FFFF0d;} +.cython.score-184 {background-color: #FFFF0d;} +.cython.score-185 {background-color: #FFFF0d;} +.cython.score-186 {background-color: #FFFF0d;} +.cython.score-187 {background-color: #FFFF0c;} +.cython.score-188 {background-color: #FFFF0c;} +.cython.score-189 {background-color: #FFFF0c;} +.cython.score-190 {background-color: #FFFF0c;} +.cython.score-191 {background-color: #FFFF0c;} +.cython.score-192 {background-color: #FFFF0c;} +.cython.score-193 {background-color: #FFFF0c;} +.cython.score-194 {background-color: #FFFF0c;} +.cython.score-195 {background-color: #FFFF0c;} +.cython.score-196 {background-color: #FFFF0c;} +.cython.score-197 {background-color: #FFFF0c;} +.cython.score-198 {background-color: #FFFF0c;} +.cython.score-199 {background-color: #FFFF0c;} +.cython.score-200 {background-color: #FFFF0c;} +.cython.score-201 {background-color: #FFFF0c;} +.cython.score-202 {background-color: #FFFF0c;} +.cython.score-203 {background-color: #FFFF0b;} +.cython.score-204 {background-color: #FFFF0b;} +.cython.score-205 {background-color: #FFFF0b;} +.cython.score-206 {background-color: #FFFF0b;} +.cython.score-207 {background-color: #FFFF0b;} +.cython.score-208 {background-color: #FFFF0b;} +.cython.score-209 {background-color: #FFFF0b;} +.cython.score-210 {background-color: #FFFF0b;} +.cython.score-211 {background-color: #FFFF0b;} +.cython.score-212 {background-color: #FFFF0b;} +.cython.score-213 {background-color: #FFFF0b;} +.cython.score-214 {background-color: #FFFF0b;} +.cython.score-215 {background-color: #FFFF0b;} +.cython.score-216 {background-color: #FFFF0b;} +.cython.score-217 {background-color: #FFFF0b;} +.cython.score-218 {background-color: #FFFF0b;} +.cython.score-219 {background-color: #FFFF0b;} +.cython.score-220 {background-color: #FFFF0b;} +.cython.score-221 {background-color: #FFFF0b;} +.cython.score-222 {background-color: #FFFF0a;} +.cython.score-223 {background-color: #FFFF0a;} +.cython.score-224 {background-color: #FFFF0a;} +.cython.score-225 {background-color: #FFFF0a;} +.cython.score-226 {background-color: #FFFF0a;} +.cython.score-227 {background-color: #FFFF0a;} +.cython.score-228 {background-color: #FFFF0a;} +.cython.score-229 {background-color: #FFFF0a;} +.cython.score-230 {background-color: #FFFF0a;} +.cython.score-231 {background-color: #FFFF0a;} +.cython.score-232 {background-color: #FFFF0a;} +.cython.score-233 {background-color: #FFFF0a;} +.cython.score-234 {background-color: #FFFF0a;} +.cython.score-235 {background-color: #FFFF0a;} +.cython.score-236 {background-color: #FFFF0a;} +.cython.score-237 {background-color: #FFFF0a;} +.cython.score-238 {background-color: #FFFF0a;} +.cython.score-239 {background-color: #FFFF0a;} +.cython.score-240 {background-color: #FFFF0a;} +.cython.score-241 {background-color: #FFFF0a;} +.cython.score-242 {background-color: #FFFF0a;} +.cython.score-243 {background-color: #FFFF0a;} +.cython.score-244 {background-color: #FFFF0a;} +.cython.score-245 {background-color: #FFFF0a;} +.cython.score-246 {background-color: #FFFF09;} +.cython.score-247 {background-color: #FFFF09;} +.cython.score-248 {background-color: #FFFF09;} +.cython.score-249 {background-color: #FFFF09;} +.cython.score-250 {background-color: #FFFF09;} +.cython.score-251 {background-color: #FFFF09;} +.cython.score-252 {background-color: #FFFF09;} +.cython.score-253 {background-color: #FFFF09;} +.cython.score-254 {background-color: #FFFF09;} + </style> + <script> + function toggleDiv(id) { + theDiv = id.nextElementSibling + if (theDiv.style.display != 'block') theDiv.style.display = 'block'; + else theDiv.style.display = 'none'; + } + </script> +</head> +<body class="cython"> +<p><span style="border-bottom: solid 1px grey;">Generated by Cython 0.26.1</span></p> +<p> + <span style="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br /> + Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it. +</p> +<p>Raw output: <a href="numind.cpp">numind.cpp</a></p> +<div class="cython"><pre class="cython line score-0"> <span class="">001</span>: # This Pyrex extension class can take a numpy/numarray/Numeric object</pre> +<pre class="cython line score-0"> <span class="">002</span>: # as a parameter and wrap it so that its information can be accessed</pre> +<pre class="cython line score-0"> <span class="">003</span>: # in a standard way, both in Python space and C space.</pre> +<pre class="cython line score-0"> <span class="">004</span>: #</pre> +<pre class="cython line score-0"> <span class="">005</span>: # Heavily based on an idea of Andrew Straw. See</pre> +<pre class="cython line score-0"> <span class="">006</span>: # http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex</pre> +<pre class="cython line score-0"> <span class="">007</span>: # Very inspiring! :-)</pre> +<pre class="cython line score-0"> <span class="">008</span>: #</pre> +<pre class="cython line score-0"> <span class="">009</span>: # First version: 2006-03-25</pre> +<pre class="cython line score-0"> <span class="">010</span>: # Last update: 2006-03-25</pre> +<pre class="cython line score-0"> <span class="">011</span>: # Author: Francesc Altet</pre> +<pre class="cython line score-0"> <span class="">012</span>: </pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">013</span>: import sys</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_Import</span>(__pyx_n_s_sys, 0, -1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 13, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-0"> <span class="">014</span>: from cpython.pycapsule cimport *</pre> +<pre class="cython line score-0"> <span class="">015</span>: </pre> +<pre class="cython line score-0"> <span class="">016</span>: cdef extern from "Python.h":</pre> +<pre class="cython line score-0"> <span class="">017</span>: ctypedef int Py_intptr_t</pre> +<pre class="cython line score-0"> <span class="">018</span>: ctypedef object PyObject</pre> +<pre class="cython line score-0"> <span class="">019</span>: long PyInt_AsLong(object)</pre> +<pre class="cython line score-0"> <span class="">020</span>: void Py_INCREF(object)</pre> +<pre class="cython line score-0"> <span class="">021</span>: void Py_DECREF(object)</pre> +<pre class="cython line score-0"> <span class="">022</span>: </pre> +<pre class="cython line score-0"> <span class="">023</span>: cdef extern from "stdlib.h":</pre> +<pre class="cython line score-0"> <span class="">024</span>: ctypedef long size_t</pre> +<pre class="cython line score-0"> <span class="">025</span>: ctypedef long intptr_t</pre> +<pre class="cython line score-0"> <span class="">026</span>: void *malloc(size_t size)</pre> +<pre class="cython line score-0"> <span class="">027</span>: void free(void* ptr)</pre> +<pre class="cython line score-0"> <span class="">028</span>: </pre> +<pre class="cython line score-0"> <span class="">029</span>: cdef extern from "numind.h":</pre> +<pre class="cython line score-0"> <span class="">030</span>: ctypedef struct SignedIntBuf</pre> +<pre class="cython line score-0"> <span class="">031</span>: </pre> +<pre class="cython line score-0"> <span class="">032</span>: # for PyArrayInterface:</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">033</span>: CONTIGUOUS=0x01</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_CONTIGUOUS, __pyx_int_1) < 0) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">034</span>: FORTRAN=0x02</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_FORTRAN, __pyx_int_2) < 0) <span class='error_goto'>__PYX_ERR(0, 34, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">035</span>: ALIGNED=0x100</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_ALIGNED, __pyx_int_256) < 0) <span class='error_goto'>__PYX_ERR(0, 35, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">036</span>: NOTSWAPPED=0x200</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_NOTSWAPPED, __pyx_int_512) < 0) <span class='error_goto'>__PYX_ERR(0, 36, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">037</span>: WRITEABLE=0x400</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_WRITEABLE, __pyx_int_1024) < 0) <span class='error_goto'>__PYX_ERR(0, 37, __pyx_L1_error)</span> +</pre><pre class="cython line score-0"> <span class="">038</span>: </pre> +<pre class="cython line score-0"> <span class="">039</span>: # byteorder dictionary</pre> +<pre class="cython line score-21" onclick='toggleDiv(this)'>+<span class="">040</span>: byteorder = {'<':'little', '>':'big'}</pre> +<pre class='cython code score-21 '> __pyx_t_1 = <span class='py_c_api'>PyDict_New</span>();<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_t_1, __pyx_kp_s__6, __pyx_n_s_little) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_t_1, __pyx_kp_s__7, __pyx_n_s_big) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_byteorder, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-0"> <span class="">041</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">042</span>: ctypedef struct PyArrayInterface:</pre> +<pre class='cython code score-0 '>struct __pyx_t_6numind_PyArrayInterface { + int version; + int nd; + char typekind; + int itemsize; + int flags; + Py_intptr_t *shape; + Py_intptr_t *strides; + void *data; +}; +</pre><pre class="cython line score-0"> <span class="">043</span>: int version # contains the integer 2 as a sanity check</pre> +<pre class="cython line score-0"> <span class="">044</span>: int nd # number of dimensions</pre> +<pre class="cython line score-0"> <span class="">045</span>: char typekind # kind in array --- character code of typestr</pre> +<pre class="cython line score-0"> <span class="">046</span>: int itemsize # size of each element</pre> +<pre class="cython line score-0"> <span class="">047</span>: int flags # flags indicating how the data should be interpreted</pre> +<pre class="cython line score-0"> <span class="">048</span>: Py_intptr_t *shape # A length-nd array of shape information</pre> +<pre class="cython line score-0"> <span class="">049</span>: Py_intptr_t *strides # A length-nd array of stride information</pre> +<pre class="cython line score-0"> <span class="">050</span>: void *data # A pointer to the first element of the array</pre> +<pre class="cython line score-0"> <span class="">051</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">052</span>: cdef void* free_array_interface(object arr):</pre> +<pre class='cython code score-0 '>static void *__pyx_f_6numind_free_array_interface(PyObject *__pyx_v_arr) { + void *__pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("free_array_interface", 0); +/* … */ + /* function exit code */ + __pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">053</span>: Py_DECREF(arr)</pre> +<pre class='cython code score-0 '> Py_DECREF(__pyx_v_arr); +</pre><pre class="cython line score-0"> <span class="">054</span>: </pre> +<pre class="cython line score-0"> <span class="">055</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">056</span>: cdef class NumInd:</pre> +<pre class='cython code score-0 '>struct __pyx_obj_6numind_NumInd { + PyObject_HEAD + struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtab; + void *data; + int _nd; + Py_intptr_t *_shape; + Py_intptr_t *_strides; + __pyx_t_6numind_PyArrayInterface *inter; + PyObject *_t_shape; + PyObject *_t_strides; + PyObject *_undarray; +}; + + + +struct __pyx_vtabstruct_6numind_NumInd { + __pyx_t_6numind_PyArrayInterface *(*_get_array_interface)(struct __pyx_obj_6numind_NumInd *); +}; +static struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtabptr_6numind_NumInd; +</pre><pre class="cython line score-0"> <span class="">057</span>: cdef void *data</pre> +<pre class="cython line score-0"> <span class="">058</span>: cdef int _nd</pre> +<pre class="cython line score-0"> <span class="">059</span>: cdef Py_intptr_t *_shape</pre> +<pre class="cython line score-0"> <span class="">060</span>: cdef Py_intptr_t *_strides</pre> +<pre class="cython line score-0"> <span class="">061</span>: cdef PyArrayInterface *inter</pre> +<pre class="cython line score-0"> <span class="">062</span>: cdef object _t_shape, _t_strides, _undarray</pre> +<pre class="cython line score-0"> <span class="">063</span>: </pre> +<pre class="cython line score-28" onclick='toggleDiv(this)'>+<span class="">064</span>: def __init__(self, object undarray):</pre> +<pre class='cython code score-28 '>/* Python wrapper */ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_undarray = 0; + int __pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_undarray,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args); + switch (pos_args) { + case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_undarray)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) <span class='error_goto'>__PYX_ERR(0, 64, __pyx_L3_error)</span> + } + } else if (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0); + } + __pyx_v_undarray = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("__init__", 1, 1, 1, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>__PYX_ERR(0, 64, __pyx_L3_error)</span> + __pyx_L3_error:; + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_6numind_6NumInd___init__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self), __pyx_v_undarray); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static int __pyx_pf_6numind_6NumInd___init__(struct __pyx_obj_6numind_NumInd *__pyx_v_self, PyObject *__pyx_v_undarray) { + int __pyx_v_i; + int __pyx_v_stride; + PyObject *__pyx_v_array_shape = 0; + PyObject *__pyx_v_array_strides = 0; + int __pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__init__", 0); +/* … */ + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_7); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_array_shape); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">065</span>: cdef int i, stride</pre> +<pre class="cython line score-0"> <span class="">066</span>: cdef object array_shape, array_strides</pre> +<pre class="cython line score-0"> <span class="">067</span>: </pre> +<pre class="cython line score-0"> <span class="">068</span>: # Keep a reference to the underlying object</pre> +<pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">069</span>: self._undarray = undarray</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_undarray); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_undarray); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_undarray); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_undarray); + __pyx_v_self->_undarray = __pyx_v_undarray; +</pre><pre class="cython line score-0"> <span class="">070</span>: # Get the shape and strides C arrays</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">071</span>: array_shape = undarray.__array_interface__["shape"]</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_shape);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_array_shape = __pyx_t_2; + __pyx_t_2 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">072</span>: self._t_shape = array_shape</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_array_shape); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_array_shape); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_shape); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_shape); + __pyx_v_self->_t_shape = __pyx_v_array_shape; +</pre><pre class="cython line score-0"> <span class="">073</span>: # The number of dimensions</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">074</span>: self._nd = len(array_shape)</pre> +<pre class='cython code score-5 '> __pyx_t_3 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_array_shape);<span class='error_goto'> if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 74, __pyx_L1_error)</span> + __pyx_v_self->_nd = __pyx_t_3; +</pre><pre class="cython line score-0"> <span class="">075</span>: # The shape</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">076</span>: self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t))</pre> +<pre class='cython code score-0 '> __pyx_v_self->_shape = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">077</span>: for i from 0 <= i < self._nd:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-10" onclick='toggleDiv(this)'>+<span class="">078</span>: self._shape[i] = self._t_shape[i]</pre> +<pre class='cython code score-10 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_self->_t_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_As_Py_intptr_t</span>(__pyx_t_2); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 78, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + (__pyx_v_self->_shape[__pyx_v_i]) = __pyx_t_5; + } +</pre><pre class="cython line score-0"> <span class="">079</span>: # The strides (compute them if needed)</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">080</span>: array_strides = undarray.__array_interface__["strides"]</pre> +<pre class='cython code score-8 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_1 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_2, __pyx_n_s_strides);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_array_strides = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">081</span>: self._t_strides = array_strides</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_v_array_strides; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">082</span>: self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t))</pre> +<pre class='cython code score-0 '> __pyx_v_self->_strides = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">083</span>: if array_strides:</pre> +<pre class='cython code score-2 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_v_array_strides); if (unlikely(__pyx_t_6 < 0)) <span class='error_goto'>__PYX_ERR(0, 83, __pyx_L1_error)</span> + if (__pyx_t_6) { +/* … */ + goto __pyx_L5; + } +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">084</span>: for i from 0 <= i < self._nd:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-10" onclick='toggleDiv(this)'>+<span class="">085</span>: self._strides[i] = array_strides[i]</pre> +<pre class='cython code score-10 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_array_strides, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_As_Py_intptr_t</span>(__pyx_t_1); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 85, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_t_5; + } +</pre><pre class="cython line score-0"> <span class="">086</span>: else:</pre> +<pre class="cython line score-0"> <span class="">087</span>: # strides is None. Compute them explicitely.</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">088</span>: self._t_strides = [0] * self._nd</pre> +<pre class='cython code score-8 '> /*else*/ { + __pyx_t_1 = <span class='py_c_api'>PyList_New</span>(1 * ((__pyx_v_self->_nd<0) ? 0:__pyx_v_self->_nd));<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_self->_nd; __pyx_temp++) { + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_int_0); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_int_0); + <span class='py_macro_api'>PyList_SET_ITEM</span>(__pyx_t_1, __pyx_temp, __pyx_int_0); + } + } + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-21" onclick='toggleDiv(this)'>+<span class="">089</span>: stride = int(self.typestr[2:])</pre> +<pre class='cython code score-21 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_GetSlice</span>(__pyx_t_1, 2, 0, NULL, NULL, &__pyx_slice_, 1, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyNumber_Int</span>(__pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_stride = __pyx_t_4; +/* … */ + __pyx_slice_ = <span class='py_c_api'>PySlice_New</span>(__pyx_int_2, Py_None, Py_None);<span class='error_goto'> if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_slice_); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_slice_); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">090</span>: for i from self._nd > i >= 0:</pre> +<pre class='cython code score-0 '> for (__pyx_v_i = __pyx_v_self->_nd-1; __pyx_v_i >= 0; __pyx_v_i--) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">091</span>: self._strides[i] = stride</pre> +<pre class='cython code score-0 '> (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_v_stride; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">092</span>: self._t_strides[i] = stride</pre> +<pre class='cython code score-5 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_stride);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(__pyx_v_self->_t_strides, __pyx_v_i, __pyx_t_1, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 92, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">093</span>: stride = stride * array_shape[i]</pre> +<pre class='cython code score-19 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_stride);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_array_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_7 = <span class='py_c_api'>PyNumber_Multiply</span>(__pyx_t_1, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_7); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_7); if (unlikely((__pyx_t_4 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_stride = __pyx_t_4; + } +</pre><pre class="cython line score-6" onclick='toggleDiv(this)'>+<span class="">094</span>: self._t_strides = tuple(self._t_strides)</pre> +<pre class='cython code score-6 '> __pyx_t_7 = <span class='py_c_api'>PySequence_Tuple</span>(__pyx_v_self->_t_strides);<span class='error_goto'> if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_7); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_7); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_L5:; +</pre><pre class="cython line score-0"> <span class="">095</span>: # Populate the C array interface</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">096</span>: self.inter = self._get_array_interface()</pre> +<pre class='cython code score-0 '> __pyx_v_self->inter = ((struct __pyx_vtabstruct_6numind_NumInd *)__pyx_v_self->__pyx_vtab)->_get_array_interface(__pyx_v_self); +</pre><pre class="cython line score-0"> <span class="">097</span>: </pre> +<pre class="cython line score-0"> <span class="">098</span>: # Properties. This are visible from Python space.</pre> +<pre class="cython line score-0"> <span class="">099</span>: # Add as many as you want.</pre> +<pre class="cython line score-0"> <span class="">100</span>: </pre> +<pre class="cython line score-0"> <span class="">101</span>: property undarray: # Returns the underlying array</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">102</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8undarray___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8undarray___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">103</span>: return self._undarray</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_undarray); + __pyx_r = __pyx_v_self->_undarray; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">104</span>: </pre> +<pre class="cython line score-0"> <span class="">105</span>: property shape:</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">106</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_5shape___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_5shape___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">107</span>: return self._t_shape</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_t_shape); + __pyx_r = __pyx_v_self->_t_shape; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">108</span>: </pre> +<pre class="cython line score-0"> <span class="">109</span>: property strides:</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">110</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7strides___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7strides___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">111</span>: return self._t_strides</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_t_strides); + __pyx_r = __pyx_v_self->_t_strides; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">112</span>: </pre> +<pre class="cython line score-0"> <span class="">113</span>: property typestr:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">114</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7typestr___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7typestr___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.typestr.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-9" onclick='toggleDiv(this)'>+<span class="">115</span>: return self._undarray.__array_interface__["typestr"]</pre> +<pre class='cython code score-9 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">116</span>: </pre> +<pre class="cython line score-0"> <span class="">117</span>: property typekind:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">118</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8typekind___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8typekind___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.typekind.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-12" onclick='toggleDiv(this)'>+<span class="">119</span>: return chr(self.inter.typekind)</pre> +<pre class='cython code score-12 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">120</span>: </pre> +<pre class="cython line score-0"> <span class="">121</span>: property readonly:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">122</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8readonly___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8readonly___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.readonly.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-12" onclick='toggleDiv(this)'>+<span class="">123</span>: return self._undarray.__array_interface__["data"][1]</pre> +<pre class='cython code score-12 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_data);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">124</span>: </pre> +<pre class="cython line score-0"> <span class="">125</span>: property __array_struct__:</pre> +<pre class="cython line score-0"> <span class="">126</span>: "Allows other numerical packages to obtain a new object."</pre> +<pre class="cython line score-3" onclick='toggleDiv(this)'>+<span class="">127</span>: def __get__(self):</pre> +<pre class='cython code score-3 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_16__array_struct_____get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_16__array_struct_____get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__array_struct__.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">128</span>: if hasattr(self._undarray, "__array_struct__"):</pre> +<pre class='cython code score-4 '> __pyx_t_1 = __pyx_v_self->_undarray; + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_HasAttr</span>(__pyx_t_1, __pyx_n_s_array_struct);<span class='error_goto'> if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 128, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { +/* … */ + } +</pre><pre class="cython line score-3" onclick='toggleDiv(this)'>+<span class="">129</span>: return self._undarray.__array_struct__</pre> +<pre class='cython code score-3 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_struct);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">130</span>: else:</pre> +<pre class="cython line score-0"> <span class="">131</span>: # No an underlying array with __array_struct__</pre> +<pre class="cython line score-0"> <span class="">132</span>: # Deliver an equivalent PyCObject.</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">133</span>: Py_INCREF(self)</pre> +<pre class='cython code score-0 '> /*else*/ { + Py_INCREF(((PyObject *)__pyx_v_self)); +</pre><pre class="cython line score-6" onclick='toggleDiv(this)'>+<span class="">134</span>: return PyCapsule_New(<void*>self.inter,</pre> +<pre class='cython code score-6 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); +/* … */ + __pyx_t_1 = <span class='py_c_api'>PyCapsule_New</span>(((void *)__pyx_v_self->inter), ((char *)"struct array"), ((PyCapsule_Destructor)__pyx_f_6numind_free_array_interface));<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } +</pre><pre class="cython line score-0"> <span class="">135</span>: "struct array",</pre> +<pre class="cython line score-0"> <span class="">136</span>: <PyCapsule_Destructor>free_array_interface)</pre> +<pre class="cython line score-0"> <span class="">137</span>: </pre> +<pre class="cython line score-9" onclick='toggleDiv(this)'>+<span class="">138</span>: cdef PyArrayInterface *_get_array_interface(self):</pre> +<pre class='cython code score-9 '>static __pyx_t_6numind_PyArrayInterface *__pyx_f_6numind_6NumInd__get_array_interface(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + __pyx_t_6numind_PyArrayInterface *__pyx_v_inter; + PyObject *__pyx_v_undarray = 0; + PyObject *__pyx_v_data_address = 0; + PyObject *__pyx_v_typestr = 0; + PyObject *__pyx_v_obj = 0; + __pyx_t_6numind_PyArrayInterface *__pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("_get_array_interface", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); + <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>("numind.NumInd._get_array_interface", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_undarray); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_data_address); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_typestr); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_obj); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">139</span>: "Populates the array interface"</pre> +<pre class="cython line score-0"> <span class="">140</span>: cdef PyArrayInterface *inter</pre> +<pre class="cython line score-0"> <span class="">141</span>: cdef object undarray, data_address, typestr</pre> +<pre class="cython line score-0"> <span class="">142</span>: cdef object obj</pre> +<pre class="cython line score-0"> <span class="">143</span>: </pre> +<pre class="cython line score-1" onclick='toggleDiv(this)'>+<span class="">144</span>: undarray = self._undarray</pre> +<pre class='cython code score-1 '> __pyx_t_1 = __pyx_v_self->_undarray; + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); + __pyx_v_undarray = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">145</span>: typestr = self.typestr</pre> +<pre class='cython code score-2 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_v_typestr = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">146</span>: inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface))</pre> +<pre class='cython code score-0 '> __pyx_v_inter = ((__pyx_t_6numind_PyArrayInterface *)malloc((sizeof(__pyx_t_6numind_PyArrayInterface)))); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">147</span>: if inter is NULL:</pre> +<pre class='cython code score-0 '> __pyx_t_2 = ((__pyx_v_inter == NULL) != 0); + if (__pyx_t_2) { +/* … */ + } +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">148</span>: raise MemoryError()</pre> +<pre class='cython code score-5 '> <span class='py_c_api'>PyErr_NoMemory</span>(); <span class='error_goto'>__PYX_ERR(0, 148, __pyx_L1_error)</span> +</pre><pre class="cython line score-0"> <span class="">149</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">150</span>: inter.version = 2</pre> +<pre class='cython code score-0 '> __pyx_v_inter->version = 2; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">151</span>: inter.nd = self._nd</pre> +<pre class='cython code score-0 '> __pyx_t_3 = __pyx_v_self->_nd; + __pyx_v_inter->nd = __pyx_t_3; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">152</span>: inter.typekind = ord(typestr[1])</pre> +<pre class='cython code score-5 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_Ord</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(__pyx_t_4 == (long)(Py_UCS4)-1)) __PYX_ERR(0, 152, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->typekind = __pyx_t_4; +</pre><pre class="cython line score-18" onclick='toggleDiv(this)'>+<span class="">153</span>: inter.itemsize = int(typestr[2:])</pre> +<pre class='cython code score-18 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetSlice</span>(__pyx_v_typestr, 2, 0, NULL, NULL, &__pyx_slice__2, 1, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyNumber_Int</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->itemsize = __pyx_t_3; +/* … */ + __pyx_slice__2 = <span class='py_c_api'>PySlice_New</span>(__pyx_int_2, Py_None, Py_None);<span class='error_goto'> if (unlikely(!__pyx_slice__2)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_slice__2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_slice__2); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">154</span>: inter.flags = 0 # initialize flags</pre> +<pre class='cython code score-0 '> __pyx_v_inter->flags = 0; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">155</span>: if typestr[0] == '|':</pre> +<pre class='cython code score-5 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_2 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_5, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 155, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_2) { +/* … */ + goto __pyx_L4; + } +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">156</span>: inter.flags = inter.flags | NOTSWAPPED</pre> +<pre class='cython code score-19 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_NOTSWAPPED);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_5, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-26" onclick='toggleDiv(this)'>+<span class="">157</span>: elif byteorder[typestr[0]] == sys.byteorder:</pre> +<pre class='cython code score-26 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_byteorder);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_6, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_sys);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_1, __pyx_n_s_byteorder);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='py_c_api'>PyObject_RichCompare</span>(__pyx_t_5, __pyx_t_6, Py_EQ); <span class='refnanny'>__Pyx_XGOTREF</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { +/* … */ + } + __pyx_L4:; +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">158</span>: inter.flags = inter.flags | NOTSWAPPED</pre> +<pre class='cython code score-19 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_NOTSWAPPED);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_5 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_1, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">159</span>: if not self.readonly:</pre> +<pre class='cython code score-5 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_readonly);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 159, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_7 = ((!__pyx_t_2) != 0); + if (__pyx_t_7) { +/* … */ + } +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">160</span>: inter.flags = inter.flags | WRITEABLE</pre> +<pre class='cython code score-19 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_WRITEABLE);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_1 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_5, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-0"> <span class="">161</span>: # XXX how to determine the ALIGNED flag?</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">162</span>: inter.strides = self._strides</pre> +<pre class='cython code score-0 '> __pyx_t_8 = __pyx_v_self->_strides; + __pyx_v_inter->strides = __pyx_t_8; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">163</span>: inter.shape = self._shape</pre> +<pre class='cython code score-0 '> __pyx_t_8 = __pyx_v_self->_shape; + __pyx_v_inter->shape = __pyx_t_8; +</pre><pre class="cython line score-0"> <span class="">164</span>: # Get the data address</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">165</span>: obj = undarray.__array_interface__["data"]</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_data);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_obj = __pyx_t_6; + __pyx_t_6 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">166</span>: data_address = obj[0]</pre> +<pre class='cython code score-2 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 166, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_v_data_address = __pyx_t_6; + __pyx_t_6 = 0; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">167</span>: inter.data = <void*>PyInt_AsLong(data_address)</pre> +<pre class='cython code score-5 '> __pyx_v_inter->data = ((void *)<span class='py_c_api'>PyInt_AsLong</span>(__pyx_v_data_address)); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">168</span>: return inter</pre> +<pre class='cython code score-0 '> __pyx_r = __pyx_v_inter; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">169</span>: </pre> +<pre class="cython line score-0"> <span class="">170</span>: </pre> +<pre class="cython line score-0"> <span class="">171</span>: # This is just an example on how to modify the data in C space</pre> +<pre class="cython line score-0"> <span class="">172</span>: # (and at C speed! :-)</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">173</span>: def modify(self):</pre> +<pre class='cython code score-5 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_6numind_6NumInd_2modify[] = "Modify the values of the underlying array"; +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("modify (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_2modify(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_2modify(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + long *__pyx_v_ldata; + double *__pyx_v_fdata; + int __pyx_v_i; + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("modify", 0); +/* … */ + /* function exit code */ + __pyx_r = Py_None; <span class='pyx_macro_api'>__Pyx_INCREF</span>(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.modify", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">174</span>: "Modify the values of the underlying array"</pre> +<pre class="cython line score-0"> <span class="">175</span>: cdef long *ldata</pre> +<pre class="cython line score-0"> <span class="">176</span>: cdef double *fdata</pre> +<pre class="cython line score-0"> <span class="">177</span>: cdef int i</pre> +<pre class="cython line score-0"> <span class="">178</span>: </pre> +<pre class="cython line score-0"> <span class="">179</span>: # Modify just the first row</pre> +<pre class="cython line score-14" onclick='toggleDiv(this)'>+<span class="">180</span>: if chr(self.inter.typekind) == 'i':</pre> +<pre class='cython code score-14 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_1, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) <span class='error_goto'>__PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { +/* … */ + goto __pyx_L3; + } +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">181</span>: ldata = <long *>self.inter.data</pre> +<pre class='cython code score-0 '> __pyx_v_ldata = ((long *)__pyx_v_self->inter->data); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">182</span>: for i from 0 <= i < self.inter.shape[self.inter.nd-1]:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">183</span>: ldata[i] = ldata[i] + 1</pre> +<pre class='cython code score-0 '> (__pyx_v_ldata[__pyx_v_i]) = ((__pyx_v_ldata[__pyx_v_i]) + 1); + } +</pre><pre class="cython line score-14" onclick='toggleDiv(this)'>+<span class="">184</span>: elif chr(self.inter.typekind) == 'f':</pre> +<pre class='cython code score-14 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_1, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) <span class='error_goto'>__PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { +/* … */ + } + __pyx_L3:; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">185</span>: fdata = <double *>self.inter.data</pre> +<pre class='cython code score-0 '> __pyx_v_fdata = ((double *)__pyx_v_self->inter->data); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">186</span>: for i from 0 <= i < self.inter.shape[self.inter.nd-1]:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">187</span>: fdata[i] = fdata[i] + 1</pre> +<pre class='cython code score-0 '> (__pyx_v_fdata[__pyx_v_i]) = ((__pyx_v_fdata[__pyx_v_i]) + 1.0); + } +</pre><pre class="cython line score-0"> <span class="">188</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">189</span>: def __dealloc__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self) { + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__dealloc__ (wrapper)", 0); + __pyx_pf_6numind_6NumInd_4__dealloc__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); +} + +static void __pyx_pf_6numind_6NumInd_4__dealloc__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__dealloc__", 0); +/* … */ + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); +} +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">190</span>: free(self._shape)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->_shape); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">191</span>: free(self._strides)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->_strides); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">192</span>: free(self.inter)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->inter); +</pre></div></body></html> diff --git a/pymolfile/molfile/numind-cython/numind.pyx b/pymolfile/molfile/numind-cython/numind.pyx new file mode 100644 index 0000000000000000000000000000000000000000..d959b2b65e14304cb21eb72b71e4d1f004451772 --- /dev/null +++ b/pymolfile/molfile/numind-cython/numind.pyx @@ -0,0 +1,192 @@ +# This Pyrex extension class can take a numpy/numarray/Numeric object +# as a parameter and wrap it so that its information can be accessed +# in a standard way, both in Python space and C space. +# +# Heavily based on an idea of Andrew Straw. See +# http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex +# Very inspiring! :-) +# +# First version: 2006-03-25 +# Last update: 2006-03-25 +# Author: Francesc Altet + +import sys +from cpython.pycapsule cimport * + +cdef extern from "Python.h": + ctypedef int Py_intptr_t + ctypedef object PyObject + long PyInt_AsLong(object) + void Py_INCREF(object) + void Py_DECREF(object) + +cdef extern from "stdlib.h": + ctypedef long size_t + ctypedef long intptr_t + void *malloc(size_t size) + void free(void* ptr) + +cdef extern from "numind.h": + ctypedef struct SignedIntBuf + +# for PyArrayInterface: +CONTIGUOUS=0x01 +FORTRAN=0x02 +ALIGNED=0x100 +NOTSWAPPED=0x200 +WRITEABLE=0x400 + +# byteorder dictionary +byteorder = {'<':'little', '>':'big'} + +ctypedef struct PyArrayInterface: + int version # contains the integer 2 as a sanity check + int nd # number of dimensions + char typekind # kind in array --- character code of typestr + int itemsize # size of each element + int flags # flags indicating how the data should be interpreted + Py_intptr_t *shape # A length-nd array of shape information + Py_intptr_t *strides # A length-nd array of stride information + void *data # A pointer to the first element of the array + +cdef void* free_array_interface(object arr): + Py_DECREF(arr) + + +cdef class NumInd: + cdef void *data + cdef int _nd + cdef Py_intptr_t *_shape + cdef Py_intptr_t *_strides + cdef PyArrayInterface *inter + cdef object _t_shape, _t_strides, _undarray + + def __init__(self, object undarray): + cdef int i, stride + cdef object array_shape, array_strides + + # Keep a reference to the underlying object + self._undarray = undarray + # Get the shape and strides C arrays + array_shape = undarray.__array_interface__["shape"] + self._t_shape = array_shape + # The number of dimensions + self._nd = len(array_shape) + # The shape + self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + for i from 0 <= i < self._nd: + self._shape[i] = self._t_shape[i] + # The strides (compute them if needed) + array_strides = undarray.__array_interface__["strides"] + self._t_strides = array_strides + self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + if array_strides: + for i from 0 <= i < self._nd: + self._strides[i] = array_strides[i] + else: + # strides is None. Compute them explicitely. + self._t_strides = [0] * self._nd + stride = int(self.typestr[2:]) + for i from self._nd > i >= 0: + self._strides[i] = stride + self._t_strides[i] = stride + stride = stride * array_shape[i] + self._t_strides = tuple(self._t_strides) + # Populate the C array interface + self.inter = self._get_array_interface() + + # Properties. This are visible from Python space. + # Add as many as you want. + + property undarray: # Returns the underlying array + def __get__(self): + return self._undarray + + property shape: + def __get__(self): + return self._t_shape + + property strides: + def __get__(self): + return self._t_strides + + property typestr: + def __get__(self): + return self._undarray.__array_interface__["typestr"] + + property typekind: + def __get__(self): + return chr(self.inter.typekind) + + property readonly: + def __get__(self): + return self._undarray.__array_interface__["data"][1] + + property __array_struct__: + "Allows other numerical packages to obtain a new object." + def __get__(self): + if hasattr(self._undarray, "__array_struct__"): + return self._undarray.__array_struct__ + else: + # No an underlying array with __array_struct__ + # Deliver an equivalent PyCObject. + Py_INCREF(self) + return PyCapsule_New(<void*>self.inter, + "struct array", + <PyCapsule_Destructor>free_array_interface) + + cdef PyArrayInterface *_get_array_interface(self): + "Populates the array interface" + cdef PyArrayInterface *inter + cdef object undarray, data_address, typestr + cdef object obj + + undarray = self._undarray + typestr = self.typestr + inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + if inter is NULL: + raise MemoryError() + + inter.version = 2 + inter.nd = self._nd + inter.typekind = ord(typestr[1]) + inter.itemsize = int(typestr[2:]) + inter.flags = 0 # initialize flags + if typestr[0] == '|': + inter.flags = inter.flags | NOTSWAPPED + elif byteorder[typestr[0]] == sys.byteorder: + inter.flags = inter.flags | NOTSWAPPED + if not self.readonly: + inter.flags = inter.flags | WRITEABLE + # XXX how to determine the ALIGNED flag? + inter.strides = self._strides + inter.shape = self._shape + # Get the data address + obj = undarray.__array_interface__["data"] + data_address = obj[0] + inter.data = <void*>PyInt_AsLong(data_address) + return inter + + + # This is just an example on how to modify the data in C space + # (and at C speed! :-) + def modify(self): + "Modify the values of the underlying array" + cdef long *ldata + cdef double *fdata + cdef int i + + # Modify just the first row + if chr(self.inter.typekind) == 'i': + ldata = <long *>self.inter.data + for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + ldata[i] = ldata[i] + 1 + elif chr(self.inter.typekind) == 'f': + fdata = <double *>self.inter.data + for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + fdata[i] = fdata[i] + 1 + + def __dealloc__(self): + free(self._shape) + free(self._strides) + free(self.inter) diff --git a/pymolfile/molfile/numind-cython/numind.so b/pymolfile/molfile/numind-cython/numind.so new file mode 100755 index 0000000000000000000000000000000000000000..f8b762476eb1d362018f305fce67cf22ec134e2f Binary files /dev/null and b/pymolfile/molfile/numind-cython/numind.so differ diff --git a/pymolfile/molfile/numind-cython/test_numpy_swig.py b/pymolfile/molfile/numind-cython/test_numpy_swig.py new file mode 100644 index 0000000000000000000000000000000000000000..d53a1b1d2874a0a7592975989918f36a5e0be95d --- /dev/null +++ b/pymolfile/molfile/numind-cython/test_numpy_swig.py @@ -0,0 +1,42 @@ +import numpy +import ctypes +import numind + +# Create an arbitrary object for each package +np=numpy.arange(12, dtype=numpy.float) +#np=numpy.arange(12) +np.shape = (4,3) + +#ns = _numpy_swig(2,2) +#print(ns) + + +# Wrap the different objects with the NumInd class +# and execute some actions on it +##for obj in [np]: +# ni = _numpy_swig +# print("original object type-->", type(ni.inter)) +# # Print some values +# #print("typestr --> {0}", ni.typestr) +# #print("shape --> {0}", ni.shape) +# #print("strides --> {0}", ni.strides) +# npa = numpy.asarray(ni) +# print("object after a numpy re-wrapping --> " , npa) +# #ni.modify() +# #print("object after modification in C space --> {0}", npa) + +# Wrap the different objects with the NumInd class +# and execute some actions on it +for obj in [np]: + ni = numind.NumInd(obj) + print("original object type-->", type(ni.undarray)) + # Print some values + print("typestr -->", ni.typestr) + print("typekind -->", ni.typekind) + print("shape -->", ni.shape) + print("strides -->", ni.strides) + npa = numpy.asarray(ni) + print("object after a numpy re-wrapping -->", npa) + ni.modify() + print("object after modification in C space -->", npa) + diff --git a/pymolfile/molfile/numpy_swig.h b/pymolfile/molfile/numpy_swig.h new file mode 100644 index 0000000000000000000000000000000000000000..f884368cfc15478b8389f61abe8bbc9cb26da68e --- /dev/null +++ b/pymolfile/molfile/numpy_swig.h @@ -0,0 +1,12 @@ +#ifndef NUMPY_SWIG +#define NUMPY_SWIG + +typedef struct SignedIntBuf +{ + int* data; + int shape[2]; + int strides[2]; +} SignedIntBuf; + +#endif + diff --git a/pymolfile/molfile/numpy_swig.i b/pymolfile/molfile/numpy_swig.i new file mode 100644 index 0000000000000000000000000000000000000000..7adc4f2ccbdc8d09e814778c4c15d74c44e837da --- /dev/null +++ b/pymolfile/molfile/numpy_swig.i @@ -0,0 +1,178 @@ +%{ +#define SWIG_FILE_WITH_INIT +%} +%include "numpy.i" +%init %{ +import_array(); +%} + +%module (docstring="This is a Python SWIG-wrapped module") numpy_swig + +%{ +#include "numpy_swig.h" +#include <numpy/arrayobject.h> + +#if PY_VERSION_HEX >= 0x03000000 +NPY_NO_EXPORT void +gentype_struct_free(PyObject *ptr) +{ + PyArrayInterface *arrif; + PyObject *context; + + arrif = (PyArrayInterface*)PyCapsule_GetPointer(ptr, NULL); + context = (PyObject *)PyCapsule_GetContext(ptr); + Py_DECREF(context); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *)) +{ + PyObject *ret = PyCapsule_New(ptr, NULL, dtor); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *)) +{ + PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor); + if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) { + PyErr_Clear(); + Py_DECREF(ret); + ret = NULL; + } + return ret; +} +#else +NPY_NO_EXPORT void +gentype_struct_free(void *ptr, void *arg) +{ + PyArrayInterface *arrif = (PyArrayInterface *)ptr; + Py_DECREF((PyObject *)arg); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) +{ + return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); +} +#endif + +#ifndef Py_CAPSULE_H +typedef void(*PyCapsule_Destructor)(void *, void *); +#endif + +void delete_SignedIntBuf(SignedIntBuf* buffer) +{ + free(buffer->data); + free(buffer); +} + +void free_array_interface( void* ptr, void *arr ) +{ + PyArrayInterface* inter; + PyObject* arrpy; + + inter = (PyArrayInterface*)ptr; + arrpy = (PyObject*)arr; + Py_DECREF(arrpy); + free(inter); +} +void free_capsule(PyObject* arr) +{ + PyArrayInterface* inter; + inter = (PyArrayInterface*) PyCapsule_GetPointer(arr, "struct SignedIntBuf"); + Py_DECREF(arr); + free(inter); +} +%} + +%inline %{PyObject* get__array_struct__(PyObject* self) +{ + PyArrayInterface *inter; + PyObject *obj; + int nd; + nd = 2; + Py_intptr_t *shape, *strides; + void *data = NULL; + + shape = (Py_intptr_t *)malloc(nd*sizeof(Py_intptr_t)); + strides = (Py_intptr_t *)malloc(nd*sizeof(Py_intptr_t)); + + inter = (PyArrayInterface*)malloc(sizeof(PyArrayInterface)); + if (inter==NULL) + return PyErr_NoMemory(); + + inter->two = 2; + inter->nd = nd; + inter->typekind = 'i'; + inter->itemsize = sizeof(int); + inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE; + inter->strides = strides; + inter->shape = shape; + inter->data = (void*) data; + Py_INCREF(self); + obj = NpyCapsule_FromVoidPtrAndDesc(inter, self, gentype_struct_free); +/* +#ifdef Py_CAPSULE_H + obj = PyCapsule_New((void*)inter, "struct SignedIntBuf", free_capsule); +#else + obj = PyCObject_FromVoidPtrAndDesc((void*)inter, (void*)self, free_array_interface); +#endif +*/ + return obj; +} +%} + +%include numpy_swig.h + +%extend SignedIntBuf{ + %feature("autodoc", "The comment docstring")SignedIntBuf; + SignedIntBuf(int width, int height) + { + SignedIntBuf* buffer = (SignedIntBuf*) malloc(sizeof(SignedIntBuf)); + int shape[2] = { height, width }; + int strides[2] = { width * sizeof(int), sizeof(int) }; + buffer->shape[0] = shape[0]; + buffer->shape[1] = shape[1]; + buffer->strides[0] = strides[0]; + buffer->strides[1] = strides[1]; + buffer->data = (int*) malloc(width*height*sizeof(int)); + return buffer; + } + + ~SignedIntBuf(); + + char *__str__() + { + static char tmp[1024]; + int i, j; + int used = 0; + used += sprintf(tmp, "Array:\n"); + for(i=0; i < $self->shape[0]; i++) + { + for(j=0; j < $self->shape[1]; j++) + used += sprintf(tmp + used, "%d\t", $self->data[j + i*$self->shape[1]]); + used += sprintf(tmp + used, "\n"); + } + return tmp; + } + + %pythoncode + { + def __array_struct__get(self): + return get__array_struct__(self) + + property __array_struct__: + "Allows other numerical packages to obtain a new object." + def __get__(self): + return __array_struct__get(self) + } +}; + + diff --git a/pymolfile/molfile/numpy_swig.py b/pymolfile/molfile/numpy_swig.py new file mode 100644 index 0000000000000000000000000000000000000000..32b6df758c6c317243639454f4e4122bc1841c16 --- /dev/null +++ b/pymolfile/molfile/numpy_swig.py @@ -0,0 +1,150 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 3.0.12 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +"""This is a Python SWIG-wrapped module""" + + +from sys import version_info as _swig_python_version_info +if _swig_python_version_info >= (2, 7, 0): + def swig_import_helper(): + import importlib + pkg = __name__.rpartition('.')[0] + mname = '.'.join((pkg, '_numpy_swig')).lstrip('.') + try: + return importlib.import_module(mname) + except ImportError: + return importlib.import_module('_numpy_swig') + _numpy_swig = swig_import_helper() + del swig_import_helper +elif _swig_python_version_info >= (2, 6, 0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_numpy_swig', [dirname(__file__)]) + except ImportError: + import _numpy_swig + return _numpy_swig + try: + _mod = imp.load_module('_numpy_swig', fp, pathname, description) + finally: + if fp is not None: + fp.close() + return _mod + _numpy_swig = swig_import_helper() + del swig_import_helper +else: + import _numpy_swig +del _swig_python_version_info + +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. + +try: + import builtins as __builtin__ +except ImportError: + import __builtin__ + +def _swig_setattr_nondynamic(self, class_type, name, value, static=1): + if (name == "thisown"): + return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name, None) + if method: + return method(self, value) + if (not static): + if _newclass: + object.__setattr__(self, name, value) + else: + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + + +def _swig_setattr(self, class_type, name, value): + return _swig_setattr_nondynamic(self, class_type, name, value, 0) + + +def _swig_getattr(self, class_type, name): + if (name == "thisown"): + return self.this.own() + method = class_type.__swig_getmethods__.get(name, None) + if method: + return method(self) + raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name)) + + +def _swig_repr(self): + try: + strthis = "proxy of " + self.this.__repr__() + except __builtin__.Exception: + strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except __builtin__.Exception: + class _object: + pass + _newclass = 0 + + +def get__array_struct__(arg1: 'PyObject *') -> "PyObject *": + return _numpy_swig.get__array_struct__(arg1) +get__array_struct__ = _numpy_swig.get__array_struct__ +class SignedIntBuf(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, SignedIntBuf, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, SignedIntBuf, name) + __repr__ = _swig_repr + __swig_setmethods__["data"] = _numpy_swig.SignedIntBuf_data_set + __swig_getmethods__["data"] = _numpy_swig.SignedIntBuf_data_get + if _newclass: + data = _swig_property(_numpy_swig.SignedIntBuf_data_get, _numpy_swig.SignedIntBuf_data_set) + __swig_setmethods__["shape"] = _numpy_swig.SignedIntBuf_shape_set + __swig_getmethods__["shape"] = _numpy_swig.SignedIntBuf_shape_get + if _newclass: + shape = _swig_property(_numpy_swig.SignedIntBuf_shape_get, _numpy_swig.SignedIntBuf_shape_set) + __swig_setmethods__["strides"] = _numpy_swig.SignedIntBuf_strides_set + __swig_getmethods__["strides"] = _numpy_swig.SignedIntBuf_strides_get + if _newclass: + strides = _swig_property(_numpy_swig.SignedIntBuf_strides_get, _numpy_swig.SignedIntBuf_strides_set) + + def __init__(self, width: 'int', height: 'int'): + """The comment docstring""" + this = _numpy_swig.new_SignedIntBuf(width, height) + try: + self.this.append(this) + except __builtin__.Exception: + self.this = this + __swig_destroy__ = _numpy_swig.delete_SignedIntBuf + __del__ = lambda self: None + + def __str__(self) -> "char *": + return _numpy_swig.SignedIntBuf___str__(self) + + def __array_struct__get(self): + return get__array_struct__(self) + + property __array_struct__: + "Allows other numerical packages to obtain a new object." + def __get__(self): + return __array_struct__get(self) + +SignedIntBuf_swigregister = _numpy_swig.SignedIntBuf_swigregister +SignedIntBuf_swigregister(SignedIntBuf) + +# This file is compatible with both classic and new-style classes. + + diff --git a/pymolfile/molfile/numpy_swig_wrap.cxx b/pymolfile/molfile/numpy_swig_wrap.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c2224d3c08a808e30b9fbeb2e894613c4eaadb3a --- /dev/null +++ b/pymolfile/molfile/numpy_swig_wrap.cxx @@ -0,0 +1,4477 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 3.0.12 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + + +#ifndef SWIGPYTHON +#define SWIGPYTHON +#endif + +#define SWIG_PYTHON_DIRECTOR_NO_VTABLE + + +#ifdef __cplusplus +/* SwigValueWrapper is described in swig.swg */ +template<typename T> class SwigValueWrapper { + struct SwigMovePointer { + T *ptr; + SwigMovePointer(T *p) : ptr(p) { } + ~SwigMovePointer() { delete ptr; } + SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } + } pointer; + SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs); + SwigValueWrapper(const SwigValueWrapper<T>& rhs); +public: + SwigValueWrapper() : pointer(0) { } + SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } + operator T&() const { return *pointer.ptr; } + T *operator&() { return pointer.ptr; } +}; + +template <typename T> T SwigValueInit() { + return T(); +} +#endif + +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if defined(__GNUC__) +# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + +/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ +#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) +# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 +#endif + +/* Intel's compiler complains if a variable which was never initialised is + * cast to void, which is a common idiom which we use to indicate that we + * are aware a variable isn't used. So we just silence that warning. + * See: https://github.com/swig/swig/issues/192 for more discussion. + */ +#ifdef __INTEL_COMPILER +# pragma warning disable 592 +#endif + + +#if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) +/* Use debug wrappers with the Python release dll */ +# undef _DEBUG +# include <Python.h> +# define _DEBUG +#else +# include <Python.h> +#endif + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic C API SWIG runtime support for pointer + * type checking. + * ----------------------------------------------------------------------------- */ + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "4" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +# define SWIG_QUOTE_STRING(x) #x +# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +# define SWIG_TYPE_TABLE_NAME +#endif + +/* + You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for + creating a static or dynamic library from the SWIG runtime code. + In 99.9% of the cases, SWIG just needs to declare them as 'static'. + + But only do this if strictly necessary, ie, if you have problems + with your compiler or suchlike. +*/ + +#ifndef SWIGRUNTIME +# define SWIGRUNTIME SWIGINTERN +#endif + +#ifndef SWIGRUNTIMEINLINE +# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE +#endif + +/* Generic buffer size */ +#ifndef SWIG_BUFFER_SIZE +# define SWIG_BUFFER_SIZE 1024 +#endif + +/* Flags for pointer conversions */ +#define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + The SWIG conversion methods, as ConvertPtr, return an integer + that tells if the conversion was successful or not. And if not, + an error code can be returned (see swigerrors.swg for the codes). + + Use the following macros/flags to set or process the returning + states. + + In old versions of SWIG, code such as the following was usually written: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + which is the same really, but now you can also do + + Type *ptr; + int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); + if (SWIG_IsOK(res)) { + // success code + if (SWIG_IsNewObj(res) { + ... + delete *ptr; + } else { + ... + } + } else { + // fail code + } + + I.e., now SWIG_ConvertPtr can return new objects and you can + identify the case and take care of the deallocation. Of course that + also requires SWIG_ConvertPtr to return new result values, such as + + int SWIG_ConvertPtr(obj, ptr,...) { + if (<obj is ok>) { + if (<need new object>) { + *ptr = <ptr to new allocated object>; + return SWIG_NEWOBJ; + } else { + *ptr = <ptr to old object>; + return SWIG_OLDOBJ; + } + } else { + return SWIG_BADOBJ; + } + } + + Of course, returning the plain '0(success)/-1(fail)' still works, but you can be + more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the + SWIG errors code. + + Finally, if the SWIG_CASTRANK_MODE is enabled, the result code + allows to return the 'cast rank', for example, if you have this + + int food(double) + int fooi(int); + + and you call + + food(1) // cast rank '1' (1 -> 1.0) + fooi(1) // cast rank '0' + + just use the SWIG_AddCast()/SWIG_CheckState() +*/ + +#define SWIG_OK (0) +#define SWIG_ERROR (-1) +#define SWIG_IsOK(r) (r >= 0) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* The CastRankLimit says how many bits are used for the cast rank */ +#define SWIG_CASTRANKLIMIT (1 << 8) +/* The NewMask denotes the object was created (using new/malloc) */ +#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) +/* The TmpMask is for in/out typemaps that use temporal objects */ +#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) +/* Simple returning values */ +#define SWIG_BADOBJ (SWIG_ERROR) +#define SWIG_OLDOBJ (SWIG_OK) +#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) +#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) +/* Check, add and del mask methods */ +#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) +#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) +#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) +#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) +#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) +#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) + +/* Cast-Rank Mode */ +#if defined(SWIG_CASTRANK_MODE) +# ifndef SWIG_TypeRank +# define SWIG_TypeRank unsigned long +# endif +# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ +# define SWIG_MAXCASTRANK (2) +# endif +# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) +# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) +SWIGINTERNINLINE int SWIG_AddCast(int r) { + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; +} +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; +} +#else /* no cast-rank mode */ +# define SWIG_AddCast(r) (r) +# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) +#endif + + +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *(*swig_converter_func)(void *, int *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store information on one type */ +typedef struct swig_type_info { + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ +} swig_type_info; + +/* Structure to store a type and conversion function used for casting */ +typedef struct swig_cast_info { + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ +} swig_cast_info; + +/* Structure used to store module information + * Each module generates one structure like this, and the runtime collects + * all of these structures and stores them in a circularly linked list.*/ +typedef struct swig_module_info { + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ +} swig_module_info; + +/* + Compare two type names skipping the space characters, therefore + "char*" == "char *" and "Class<int>" == "Class<int >", etc. + + Return 0 when the two name types are equivalent, as in + strncmp, but skipping ' '. +*/ +SWIGRUNTIME int +SWIG_TypeNameComp(const char *f1, const char *l1, + const char *f2, const char *l2) { + for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); +} + +/* + Check type equivalence in a name list like <name1>|<name2>|... + Return 0 if equal, -1 if nb < tb, 1 if nb > tb +*/ +SWIGRUNTIME int +SWIG_TypeCmp(const char *nb, const char *tb) { + int equiv = 1; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (equiv != 0 && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = SWIG_TypeNameComp(nb, ne, tb, te); + if (*ne) ++ne; + } + return equiv; +} + +/* + Check type equivalence in a name list like <name1>|<name2>|... + Return 0 if not equal, 1 if equal +*/ +SWIGRUNTIME int +SWIG_TypeEquiv(const char *nb, const char *tb) { + return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; +} + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); +} + +/* + Dynamic pointer casting. Down an inheritance hierarchy +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; +} + +/* + Return the name associated with this type +*/ +SWIGRUNTIMEINLINE const char * +SWIG_TypeName(const swig_type_info *ty) { + return ty->name; +} + +/* + Return the pretty name associated with this type, + that is an unmangled type name in a form presentable to the user. +*/ +SWIGRUNTIME const char * +SWIG_TypePrettyName(const swig_type_info *type) { + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s+1; + return last_name; + } + else + return type->name; +} + +/* + Set the clientdata field for a type +*/ +SWIGRUNTIME void +SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; + + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; + } +} +SWIGRUNTIME void +SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; +} + +/* + Search for a swig_type_info structure only by mangled name + Search is a O(log #types) + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + size_t l = 0; + size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; +} + +/* + Search for a swig_type_info structure for either a mangled name or a human readable name. + It first searches the mangled names of the types, which is a O(log #types) + If a type is not found it then searches the human readable names, which is O(#types). + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } + + /* neither found a match */ + return 0; +} + +/* + Pack binary data into a string +*/ +SWIGRUNTIME char * +SWIG_PackData(char *c, void *ptr, size_t sz) { + static const char hex[17] = "0123456789abcdef"; + const unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* + Unpack binary data from a string +*/ +SWIGRUNTIME const char * +SWIG_UnpackData(const char *c, void *ptr, size_t sz) { + unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + char d = *(c++); + unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = (unsigned char)((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = (unsigned char)((d - ('a'-10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (unsigned char)(d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (unsigned char)(d - ('a'-10)); + else + return (char *) 0; + *u = uu; + } + return c; +} + +/* + Pack 'void *' into a string buffer. +*/ +SWIGRUNTIME char * +SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { + char *r = buff; + if ((2*sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,&ptr,sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r,name); + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sizeof(void *)); +} + +SWIGRUNTIME char * +SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2*sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + if (lname) { + strncpy(r,name,lname+1); + } else { + *r = 0; + } + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + memset(ptr,0,sz); + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sz); +} + +#ifdef __cplusplus +} +#endif + +/* Errors in SWIG */ +#define SWIG_UnknownError -1 +#define SWIG_IOError -2 +#define SWIG_RuntimeError -3 +#define SWIG_IndexError -4 +#define SWIG_TypeError -5 +#define SWIG_DivisionByZero -6 +#define SWIG_OverflowError -7 +#define SWIG_SyntaxError -8 +#define SWIG_ValueError -9 +#define SWIG_SystemError -10 +#define SWIG_AttributeError -11 +#define SWIG_MemoryError -12 +#define SWIG_NullReferenceError -13 + + + +/* Compatibility macros for Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + +#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) +#define PyInt_Check(x) PyLong_Check(x) +#define PyInt_AsLong(x) PyLong_AsLong(x) +#define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyInt_FromSize_t(x) PyLong_FromSize_t(x) +#define PyString_Check(name) PyBytes_Check(name) +#define PyString_FromString(x) PyUnicode_FromString(x) +#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) +#define PyString_AsString(str) PyBytes_AsString(str) +#define PyString_Size(str) PyBytes_Size(str) +#define PyString_InternFromString(key) PyUnicode_InternFromString(key) +#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE +#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) +#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) + +#endif + +#ifndef Py_TYPE +# define Py_TYPE(op) ((op)->ob_type) +#endif + +/* SWIG APIs for compatibility of both Python 2 & 3 */ + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_FromFormat PyUnicode_FromFormat +#else +# define SWIG_Python_str_FromFormat PyString_FromFormat +#endif + + +/* Warning: This function will allocate a new string in Python 3, + * so please call SWIG_Python_str_DelForPy3(x) to free the space. + */ +SWIGINTERN char* +SWIG_Python_str_AsChar(PyObject *str) +{ +#if PY_VERSION_HEX >= 0x03000000 + char *cstr; + char *newstr; + Py_ssize_t len; + str = PyUnicode_AsUTF8String(str); + PyBytes_AsStringAndSize(str, &cstr, &len); + newstr = (char *) malloc(len+1); + memcpy(newstr, cstr, len+1); + Py_XDECREF(str); + return newstr; +#else + return PyString_AsString(str); +#endif +} + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) +#else +# define SWIG_Python_str_DelForPy3(x) +#endif + + +SWIGINTERN PyObject* +SWIG_Python_str_FromChar(const char *c) +{ +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_FromString(c); +#else + return PyString_FromString(c); +#endif +} + +/* Add PyOS_snprintf for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +# define PyOS_snprintf _snprintf +# else +# define PyOS_snprintf snprintf +# endif +#endif + +/* A crude PyString_FromFormat implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 + +#ifndef SWIG_PYBUFFER_SIZE +# define SWIG_PYBUFFER_SIZE 1024 +#endif + +static PyObject * +PyString_FromFormat(const char *fmt, ...) { + va_list ap; + char buf[SWIG_PYBUFFER_SIZE * 2]; + int res; + va_start(ap, fmt); + res = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); +} +#endif + +#ifndef PyObject_DEL +# define PyObject_DEL PyObject_Del +#endif + +/* A crude PyExc_StopIteration exception for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# ifndef PyExc_StopIteration +# define PyExc_StopIteration PyExc_RuntimeError +# endif +# ifndef PyObject_GenericGetAttr +# define PyObject_GenericGetAttr 0 +# endif +#endif + +/* Py_NotImplemented is defined in 2.1 and up. */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef Py_NotImplemented +# define Py_NotImplemented PyExc_RuntimeError +# endif +#endif + +/* A crude PyString_AsStringAndSize implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef PyString_AsStringAndSize +# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} +# endif +#endif + +/* PySequence_Size for old Pythons */ +#if PY_VERSION_HEX < 0x02000000 +# ifndef PySequence_Size +# define PySequence_Size PySequence_Length +# endif +#endif + +/* PyBool_FromLong for old Pythons */ +#if PY_VERSION_HEX < 0x02030000 +static +PyObject *PyBool_FromLong(long ok) +{ + PyObject *result = ok ? Py_True : Py_False; + Py_INCREF(result); + return result; +} +#endif + +/* Py_ssize_t for old Pythons */ +/* This code is as recommended by: */ +/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +# define PY_SSIZE_T_MAX INT_MAX +# define PY_SSIZE_T_MIN INT_MIN +typedef inquiry lenfunc; +typedef intargfunc ssizeargfunc; +typedef intintargfunc ssizessizeargfunc; +typedef intobjargproc ssizeobjargproc; +typedef intintobjargproc ssizessizeobjargproc; +typedef getreadbufferproc readbufferproc; +typedef getwritebufferproc writebufferproc; +typedef getsegcountproc segcountproc; +typedef getcharbufferproc charbufferproc; +static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc)) +{ + long result = 0; + PyObject *i = PyNumber_Int(x); + if (i) { + result = PyInt_AsLong(i); + Py_DECREF(i); + } + return result; +} +#endif + +#if PY_VERSION_HEX < 0x02050000 +#define PyInt_FromSize_t(x) PyInt_FromLong((long)x) +#endif + +#if PY_VERSION_HEX < 0x02040000 +#define Py_VISIT(op) \ + do { \ + if (op) { \ + int vret = visit((op), arg); \ + if (vret) \ + return vret; \ + } \ + } while (0) +#endif + +#if PY_VERSION_HEX < 0x02030000 +typedef struct { + PyTypeObject type; + PyNumberMethods as_number; + PyMappingMethods as_mapping; + PySequenceMethods as_sequence; + PyBufferProcs as_buffer; + PyObject *name, *slots; +} PyHeapTypeObject; +#endif + +#if PY_VERSION_HEX < 0x02030000 +typedef destructor freefunc; +#endif + +#if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \ + (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \ + (PY_MAJOR_VERSION > 3)) +# define SWIGPY_USE_CAPSULE +# define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME) +#endif + +#if PY_VERSION_HEX < 0x03020000 +#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) +#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) +#define Py_hash_t long +#endif + +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIME PyObject* +SWIG_Python_ErrorType(int code) { + PyObject* type = 0; + switch(code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; +} + + +SWIGRUNTIME void +SWIG_Python_AddErrorMsg(const char* mesg) +{ + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + + if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); + if (value) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + PyErr_Clear(); + Py_XINCREF(type); + + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_SetString(PyExc_RuntimeError, mesg); + } +} + +#if defined(SWIG_PYTHON_NO_THREADS) +# if defined(SWIG_PYTHON_THREADS) +# undef SWIG_PYTHON_THREADS +# endif +#endif +#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ +# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) +# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ +# define SWIG_PYTHON_USE_GIL +# endif +# endif +# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ +# ifndef SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# endif +# ifdef __cplusplus /* C++ code */ + class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } + }; + class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } + }; +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# else /* C code */ +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() +# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() +# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) +# endif +# else /* Old thread way, not implemented, user must provide it */ +# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) +# define SWIG_PYTHON_INITIALIZE_THREADS +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif +# endif +#else /* No thread support */ +# define SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# define SWIG_PYTHON_THREAD_END_BLOCK +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# define SWIG_PYTHON_THREAD_END_ALLOW +#endif + +/* ----------------------------------------------------------------------------- + * Python API portion that goes into the runtime + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_PY_POINTER 4 +#define SWIG_PY_BINARY 5 + +/* Constant information structure */ +typedef struct swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; +} swig_const_info; + + +/* ----------------------------------------------------------------------------- + * Wrapper of PyInstanceMethod_New() used in Python 3 + * It is exported to the generated module, used for -fastproxy + * ----------------------------------------------------------------------------- */ +#if PY_VERSION_HEX >= 0x03000000 +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) +{ + return PyInstanceMethod_New(func); +} +#else +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(func)) +{ + return NULL; +} +#endif + +#ifdef __cplusplus +} +#endif + + +/* ----------------------------------------------------------------------------- + * pyrun.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * ----------------------------------------------------------------------------- */ + +/* Common SWIG API */ + +/* for raw pointers */ +#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) + +#ifdef SWIGPYTHON_BUILTIN +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags) +#else +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) +#endif + +#define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) + +#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) +#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) +#define swig_owntype int + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) + +/* for C or C++ function pointers */ +#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_Python_GetModule(clientdata) +#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) +#define SWIG_NewClientData(obj) SwigPyClientData_New(obj) + +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Runtime API implementation */ + +/* Error manipulation */ + +SWIGINTERN void +SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +SWIGINTERN void +SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, msg); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) + +/* Set a constant value */ + +#if defined(SWIGPYTHON_BUILTIN) + +SWIGINTERN void +SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { + PyObject *s = PyString_InternFromString(key); + PyList_Append(seq, s); + Py_DECREF(s); +} + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { +#if PY_VERSION_HEX < 0x02030000 + PyDict_SetItemString(d, (char *)name, obj); +#else + PyDict_SetItemString(d, name, obj); +#endif + Py_DECREF(obj); + if (public_interface) + SwigPyBuiltin_AddPublicSymbol(public_interface, name); +} + +#else + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { +#if PY_VERSION_HEX < 0x02030000 + PyDict_SetItemString(d, (char *)name, obj); +#else + PyDict_SetItemString(d, name, obj); +#endif + Py_DECREF(obj); +} + +#endif + +/* Append a value to the result obj */ + +SWIGINTERN PyObject* +SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { +#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyList_Check(result)) { + PyObject *o2 = result; + result = PyList_New(1); + PyList_SetItem(result, 0, o2); + } + PyList_Append(result,obj); + Py_DECREF(obj); + } + return result; +#else + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SET_ITEM(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; +#endif +} + +/* Unpack the argument tuple */ + +SWIGINTERN Py_ssize_t +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) +{ + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } + } + if (!PyTuple_Check(args)) { + if (min <= 1 && max >= 1) { + Py_ssize_t i; + objs[0] = args; + for (i = 1; i < max; ++i) { + objs[i] = 0; + } + return 2; + } + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; + } else { + Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)l); + return 0; + } else { + Py_ssize_t i; + for (i = 0; i < l; ++i) { + objs[i] = PyTuple_GET_ITEM(args, i); + } + for (; l < max; ++l) { + objs[l] = 0; + } + return i + 1; + } + } +} + +/* A functor is a function object with one single object argument */ +#if PY_VERSION_HEX >= 0x02020000 +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); +#else +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); +#endif + +/* + Helper for static pointer initialization for both C and C++ code, for example + static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); +*/ +#ifdef __cplusplus +#define SWIG_STATIC_POINTER(var) var +#else +#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var +#endif + +/* ----------------------------------------------------------------------------- + * Pointer declarations + * ----------------------------------------------------------------------------- */ + +/* Flags for new pointer objects */ +#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) +#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) + +#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) + +#define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2) +#define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN) + +#ifdef __cplusplus +extern "C" { +#endif + +/* How to access Py_None */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_BUILD_NONE +# ifndef SWIG_PYTHON_BUILD_NONE +# define SWIG_PYTHON_BUILD_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_BUILD_NONE +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif +SWIGRUNTIMEINLINE PyObject * +_SWIG_Py_None(void) +{ + PyObject *none = Py_BuildValue((char*)""); + Py_DECREF(none); + return none; +} +SWIGRUNTIME PyObject * +SWIG_Py_None(void) +{ + static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); + return none; +} +#endif + +/* The python void return value */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) +{ + PyObject *none = Py_None; + Py_INCREF(none); + return none; +} + +/* SwigPyClientData */ + +typedef struct { + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; + PyTypeObject *pytype; +} SwigPyClientData; + +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) +{ + SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; + return data ? data->implicitconv : 0; +} + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_ExceptionType(swig_type_info *desc) { + SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); +} + + +SWIGRUNTIME SwigPyClientData * +SwigPyClientData_New(PyObject* obj) +{ + if (!obj) { + return 0; + } else { + SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* the newraw method and newargs arguments used to create a new raw instance */ + if (PyClass_Check(obj)) { + data->newraw = 0; + data->newargs = obj; + Py_INCREF(obj); + } else { +#if (PY_VERSION_HEX < 0x02020000) + data->newraw = 0; +#else + data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); +#endif + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + flags = PyCFunction_GET_FLAGS(data->destroy); +#ifdef METH_O + data->delargs = !(flags & (METH_O)); +#else + data->delargs = 0; +#endif + } else { + data->delargs = 0; + } + data->implicitconv = 0; + data->pytype = 0; + return data; + } +} + +SWIGRUNTIME void +SwigPyClientData_Del(SwigPyClientData *data) { + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); +} + +/* =============== SwigPyObject =====================*/ + +typedef struct { + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; +#ifdef SWIGPYTHON_BUILTIN + PyObject *dict; +#endif +} SwigPyObject; + + +#ifdef SWIGPYTHON_BUILTIN + +SWIGRUNTIME PyObject * +SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) +{ + SwigPyObject *sobj = (SwigPyObject *)v; + + if (!sobj->dict) + sobj->dict = PyDict_New(); + + Py_INCREF(sobj->dict); + return sobj->dict; +} + +#endif + +SWIGRUNTIME PyObject * +SwigPyObject_long(SwigPyObject *v) +{ + return PyLong_FromVoidPtr(v->ptr); +} + +SWIGRUNTIME PyObject * +SwigPyObject_format(const char* fmt, SwigPyObject *v) +{ + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { + PyObject *ofmt = SWIG_Python_str_FromChar(fmt); + if (ofmt) { +#if PY_VERSION_HEX >= 0x03000000 + res = PyUnicode_Format(ofmt,args); +#else + res = PyString_Format(ofmt,args); +#endif + Py_DECREF(ofmt); + } + Py_DECREF(args); + } + } + return res; +} + +SWIGRUNTIME PyObject * +SwigPyObject_oct(SwigPyObject *v) +{ + return SwigPyObject_format("%o",v); +} + +SWIGRUNTIME PyObject * +SwigPyObject_hex(SwigPyObject *v) +{ + return SwigPyObject_format("%x",v); +} + +SWIGRUNTIME PyObject * +#ifdef METH_NOARGS +SwigPyObject_repr(SwigPyObject *v) +#else +SwigPyObject_repr(SwigPyObject *v, PyObject *args) +#endif +{ + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", (name ? name : "unknown"), (void *)v); + if (v->next) { +# ifdef METH_NOARGS + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); +# else + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); +# endif +# if PY_VERSION_HEX >= 0x03000000 + PyObject *joined = PyUnicode_Concat(repr, nrep); + Py_DecRef(repr); + Py_DecRef(nrep); + repr = joined; +# else + PyString_ConcatAndDel(&repr,nrep); +# endif + } + return repr; +} + +SWIGRUNTIME int +SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) +{ + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); +} + +/* Added for Python 3.x, would it also be useful for Python 2.x? */ +SWIGRUNTIME PyObject* +SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) +{ + PyObject* res; + if( op != Py_EQ && op != Py_NE ) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0); + return res; +} + + +SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); + +#ifdef SWIGPYTHON_BUILTIN +static swig_type_info *SwigPyObject_stype = 0; +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + SwigPyClientData *cd; + assert(SwigPyObject_stype); + cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + assert(cd); + assert(cd->pytype); + return cd->pytype; +} +#else +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); + return type; +} +#endif + +SWIGRUNTIMEINLINE int +SwigPyObject_Check(PyObject *op) { +#ifdef SWIGPYTHON_BUILTIN + PyTypeObject *target_tp = SwigPyObject_type(); + if (PyType_IsSubtype(op->ob_type, target_tp)) + return 1; + return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); +#else + return (Py_TYPE(op) == SwigPyObject_type()) + || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); +#endif +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own); + +SWIGRUNTIME void +SwigPyObject_dealloc(PyObject *v) +{ + SwigPyObject *sobj = (SwigPyObject *) v; + PyObject *next = sobj->next; + if (sobj->own == SWIG_POINTER_OWN) { + swig_type_info *ty = sobj->ty; + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + PyObject *destroy = data ? data->destroy : 0; + if (destroy) { + /* destroy is always a VARARGS method */ + PyObject *res; + + /* PyObject_CallFunction() has the potential to silently drop + the active active exception. In cases of unnamed temporary + variable or where we just finished iterating over a generator + StopIteration will be active right now, and this needs to + remain true upon return from SwigPyObject_dealloc. So save + and restore. */ + + PyObject *val = NULL, *type = NULL, *tb = NULL; + PyErr_Fetch(&val, &type, &tb); + + if (data->delargs) { + /* we need to create a temporary object to carry the destroy operation */ + PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + if (!res) + PyErr_WriteUnraisable(destroy); + + PyErr_Restore(val, type, tb); + + Py_XDECREF(res); + } +#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); + } +#endif + } + Py_XDECREF(next); + PyObject_DEL(v); +} + +SWIGRUNTIME PyObject* +SwigPyObject_append(PyObject* v, PyObject* next) +{ + SwigPyObject *sobj = (SwigPyObject *) v; +#ifndef METH_O + PyObject *tmp = 0; + if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; + next = tmp; +#endif + if (!SwigPyObject_Check(next)) { + PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); + return NULL; + } + sobj->next = next; + Py_INCREF(next); + return SWIG_Py_Void(); +} + +SWIGRUNTIME PyObject* +#ifdef METH_NOARGS +SwigPyObject_next(PyObject* v) +#else +SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_disown(PyObject *v) +#else +SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_acquire(PyObject *v) +#else +SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +SwigPyObject_own(PyObject *v, PyObject *args) +{ + PyObject *val = 0; +#if (PY_VERSION_HEX < 0x02020000) + if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) +#elif (PY_VERSION_HEX < 0x02050000) + if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) +#else + if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) +#endif + { + return NULL; + } + else + { + SwigPyObject *sobj = (SwigPyObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { +#ifdef METH_NOARGS + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v); + } else { + SwigPyObject_disown(v); + } +#else + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v,args); + } else { + SwigPyObject_disown(v,args); + } +#endif + } + return obj; + } +} + +#ifdef METH_O +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"acquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#else +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"acquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#endif + +#if PY_VERSION_HEX < 0x02020000 +SWIGINTERN PyObject * +SwigPyObject_getattr(SwigPyObject *sobj,char *name) +{ + return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); +} +#endif + +SWIGRUNTIME PyTypeObject* +SwigPyObject_TypeOnce(void) { + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + + static PyNumberMethods SwigPyObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + /* nb_divide removed in Python 3 */ +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc)0, /*nb_divide*/ +#endif + (binaryfunc)0, /*nb_remainder*/ + (binaryfunc)0, /*nb_divmod*/ + (ternaryfunc)0,/*nb_power*/ + (unaryfunc)0, /*nb_negative*/ + (unaryfunc)0, /*nb_positive*/ + (unaryfunc)0, /*nb_absolute*/ + (inquiry)0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ +#if PY_VERSION_HEX < 0x03000000 + 0, /*nb_coerce*/ +#endif + (unaryfunc)SwigPyObject_long, /*nb_int*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_long, /*nb_long*/ +#else + 0, /*nb_reserved*/ +#endif + (unaryfunc)0, /*nb_float*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_oct, /*nb_oct*/ + (unaryfunc)SwigPyObject_hex, /*nb_hex*/ +#endif +#if PY_VERSION_HEX >= 0x03050000 /* 3.5 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ +#elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ +#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ +#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ +#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ + 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ +#endif + }; + + static PyTypeObject swigpyobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(NULL, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyObject", /* tp_name */ + sizeof(SwigPyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ +#if PY_VERSION_HEX < 0x02020000 + (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ +#else + (getattrfunc)0, /* tp_getattr */ +#endif + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03000000 + 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ +#else + (cmpfunc)SwigPyObject_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyObject_repr, /* tp_repr */ + &SwigPyObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigobject_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + swigobject_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ +#endif + }; + swigpyobject_type = tmp; + type_init = 1; +#if PY_VERSION_HEX < 0x02020000 + swigpyobject_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&swigpyobject_type) < 0) + return NULL; +#endif + } + return &swigpyobject_type; +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own) +{ + SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); + if (sobj) { + sobj->ptr = ptr; + sobj->ty = ty; + sobj->own = own; + sobj->next = 0; + } + return (PyObject *)sobj; +} + +/* ----------------------------------------------------------------------------- + * Implements a simple Swig Packed type, and use it instead of string + * ----------------------------------------------------------------------------- */ + +typedef struct { + PyObject_HEAD + void *pack; + swig_type_info *ty; + size_t size; +} SwigPyPacked; + +SWIGRUNTIME int +SwigPyPacked_print(SwigPyPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char result[SWIG_BUFFER_SIZE]; + fputs("<Swig Packed ", fp); + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + fputs("at ", fp); + fputs(result, fp); + } + fputs(v->ty->name,fp); + fputs(">", fp); + return 0; +} + +SWIGRUNTIME PyObject * +SwigPyPacked_repr(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return SWIG_Python_str_FromFormat("<Swig Packed at %s%s>", result, v->ty->name); + } else { + return SWIG_Python_str_FromFormat("<Swig Packed %s>", v->ty->name); + } +} + +SWIGRUNTIME PyObject * +SwigPyPacked_str(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ + return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); + } else { + return SWIG_Python_str_FromChar(v->ty->name); + } +} + +SWIGRUNTIME int +SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) +{ + size_t i = v->size; + size_t j = w->size; + int s = (i < j) ? -1 : ((i > j) ? 1 : 0); + return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); +} + +SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); + +SWIGRUNTIME PyTypeObject* +SwigPyPacked_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); + return type; +} + +SWIGRUNTIMEINLINE int +SwigPyPacked_Check(PyObject *op) { + return ((op)->ob_type == SwigPyPacked_TypeOnce()) + || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); +} + +SWIGRUNTIME void +SwigPyPacked_dealloc(PyObject *v) +{ + if (SwigPyPacked_Check(v)) { + SwigPyPacked *sobj = (SwigPyPacked *) v; + free(sobj->pack); + } + PyObject_DEL(v); +} + +SWIGRUNTIME PyTypeObject* +SwigPyPacked_TypeOnce(void) { + static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; + static PyTypeObject swigpypacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX>=0x03000000 + PyVarObject_HEAD_INIT(NULL, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyPacked", /* tp_name */ + sizeof(SwigPyPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ + (printfunc)SwigPyPacked_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX>=0x03000000 + 0, /* tp_reserved in 3.0.1 */ +#else + (cmpfunc)SwigPyPacked_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyPacked_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigpacked_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ +#endif + }; + swigpypacked_type = tmp; + type_init = 1; +#if PY_VERSION_HEX < 0x02020000 + swigpypacked_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&swigpypacked_type) < 0) + return NULL; +#endif + } + return &swigpypacked_type; +} + +SWIGRUNTIME PyObject * +SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) +{ + SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); + if (sobj) { + void *pack = malloc(size); + if (pack) { + memcpy(pack, ptr, size); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = size; + } else { + PyObject_DEL((PyObject *) sobj); + sobj = 0; + } + } + return (PyObject *) sobj; +} + +SWIGRUNTIME swig_type_info * +SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) +{ + if (SwigPyPacked_Check(obj)) { + SwigPyPacked *sobj = (SwigPyPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } +} + +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIMEINLINE PyObject * +_SWIG_This(void) +{ + return SWIG_Python_str_FromChar("this"); +} + +static PyObject *swig_this = NULL; + +SWIGRUNTIME PyObject * +SWIG_This(void) +{ + if (swig_this == NULL) + swig_this = _SWIG_This(); + return swig_this; +} + +/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ + +/* TODO: I don't know how to implement the fast getset in Python 3 right now */ +#if PY_VERSION_HEX>=0x03000000 +#define SWIG_PYTHON_SLOW_GETSET_THIS +#endif + +SWIGRUNTIME SwigPyObject * +SWIG_Python_GetSwigThis(PyObject *pyobj) +{ + PyObject *obj; + + if (SwigPyObject_Check(pyobj)) + return (SwigPyObject *) pyobj; + +#ifdef SWIGPYTHON_BUILTIN + (void)obj; +# ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + pyobj = PyWeakref_GET_OBJECT(pyobj); + if (pyobj && SwigPyObject_Check(pyobj)) + return (SwigPyObject*) pyobj; + } +# endif + return NULL; +#else + + obj = 0; + +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); + } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } + } + } +#else + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } +#endif + if (obj && !SwigPyObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + SwigPyObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (SwigPyObject *)obj; +#endif +} + +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Python_AcquirePtr(PyObject *obj, int own) { + if (own == SWIG_POINTER_OWN) { + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + if (sobj) { + int oldown = sobj->own; + sobj->own = own; + return oldown; + } + } + return 0; +} + +/* Convert a pointer value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { + int res; + SwigPyObject *sobj; + int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; + + if (!obj) + return SWIG_ERROR; + if (obj == Py_None && !implicit_conv) { + if (ptr) + *ptr = 0; + return SWIG_OK; + } + + res = SWIG_ERROR; + + sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; + while (sobj) { + void *vptr = sobj->ptr; + if (ty) { + swig_type_info *to = sobj->ty; + if (to == ty) { + /* no type cast needed */ + if (ptr) *ptr = vptr; + break; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) { + sobj = (SwigPyObject *)sobj->next; + } else { + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; + } + res = SWIG_OK; + } else { + if (implicit_conv) { + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + if (data && !data->implicitconv) { + PyObject *klass = data->klass; + if (klass) { + PyObject *impconv; + data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ + impconv = SWIG_Python_CallFunctor(klass, obj); + data->implicitconv = 0; + if (PyErr_Occurred()) { + PyErr_Clear(); + impconv = 0; + } + if (impconv) { + SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(res); + } else { + res = SWIG_AddCast(res); + } + } + } + Py_DECREF(impconv); + } + } + } + } + if (!SWIG_IsOK(res) && obj == Py_None) { + if (ptr) + *ptr = 0; + if (PyErr_Occurred()) + PyErr_Clear(); + res = SWIG_OK; + } + } + return res; +} + +/* Convert a function ptr value */ + +SWIGRUNTIME int +SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { + if (!PyCFunction_Check(obj)) { + return SWIG_ConvertPtr(obj, ptr, ty, 0); + } else { + void *vptr = 0; + + /* here we get the method pointer for callbacks */ + const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); + const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; + if (desc) + desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; + if (!desc) + return SWIG_ERROR; + if (ty) { + swig_cast_info *tc = SWIG_TypeCheck(desc,ty); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } + } else { + *ptr = vptr; + } + return SWIG_OK; + } +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +/* ----------------------------------------------------------------------------- + * Create a new pointer object + * ----------------------------------------------------------------------------- */ + +/* + Create a new instance object, without calling __init__, and set the + 'this' attribute. +*/ + +SWIGRUNTIME PyObject* +SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) +{ +#if (PY_VERSION_HEX >= 0x02020000) + PyObject *inst = 0; + PyObject *newraw = data->newraw; + if (newraw) { + inst = PyObject_Call(newraw, data->newargs, NULL); + if (inst) { +#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + PyDict_SetItem(dict, SWIG_This(), swig_this); + } + } +#else + PyObject *key = SWIG_This(); + PyObject_SetAttr(inst, key, swig_this); +#endif + } + } else { +#if PY_VERSION_HEX >= 0x03000000 + inst = ((PyTypeObject*) data->newargs)->tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); + if (inst) { + PyObject_SetAttr(inst, SWIG_This(), swig_this); + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + } +#else + PyObject *dict = PyDict_New(); + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } +#endif + } + return inst; +#else +#if (PY_VERSION_HEX >= 0x02010000) + PyObject *inst = 0; + PyObject *dict = PyDict_New(); + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } + return (PyObject *) inst; +#else + PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); + if (inst == NULL) { + return NULL; + } + inst->in_class = (PyClassObject *)data->newargs; + Py_INCREF(inst->in_class); + inst->in_dict = PyDict_New(); + if (inst->in_dict == NULL) { + Py_DECREF(inst); + return NULL; + } +#ifdef Py_TPFLAGS_HAVE_WEAKREFS + inst->in_weakreflist = NULL; +#endif +#ifdef Py_TPFLAGS_GC + PyObject_GC_Init(inst); +#endif + PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); + return (PyObject *) inst; +#endif +#endif +} + +SWIGRUNTIME void +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) +{ + PyObject *dict; +#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } +#endif + dict = PyObject_GetAttrString(inst, (char*)"__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} + + +SWIGINTERN PyObject * +SWIG_Python_InitShadowInstance(PyObject *args) { + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { + return NULL; + } else { + SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + SwigPyObject_append((PyObject*) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); + } +} + +/* Create a new pointer object */ + +SWIGRUNTIME PyObject * +SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { + SwigPyClientData *clientdata; + PyObject * robj; + int own; + + if (!ptr) + return SWIG_Py_Void(); + + clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (clientdata && clientdata->pytype) { + SwigPyObject *newobj; + if (flags & SWIG_BUILTIN_TP_INIT) { + newobj = (SwigPyObject*) self; + if (newobj->ptr) { + PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); + while (newobj->next) + newobj = (SwigPyObject *) newobj->next; + newobj->next = next_self; + newobj = (SwigPyObject *)next_self; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif + } + } else { + newobj = PyObject_New(SwigPyObject, clientdata->pytype); +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif + } + if (newobj) { + newobj->ptr = ptr; + newobj->ty = type; + newobj->own = own; + newobj->next = 0; + return (PyObject*) newobj; + } + return SWIG_Py_Void(); + } + + assert(!(flags & SWIG_BUILTIN_TP_INIT)); + + robj = SwigPyObject_New(ptr, type, own); + if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + Py_DECREF(robj); + robj = inst; + } + return robj; +} + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); +} + +/* -----------------------------------------------------------------------------* + * Get type list + * -----------------------------------------------------------------------------*/ + +#ifdef SWIG_LINK_RUNTIME +void *SWIG_ReturnGlobalTypeList(void *); +#endif + +SWIGRUNTIME swig_module_info * +SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { + static void *type_pointer = (void *)0; + /* first check if module already created */ + if (!type_pointer) { +#ifdef SWIG_LINK_RUNTIME + type_pointer = SWIG_ReturnGlobalTypeList((void *)0); +#else +# ifdef SWIGPY_USE_CAPSULE + type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); +# else + type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); +# endif + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; + } +#endif + } + return (swig_module_info *) type_pointer; +} + +#if PY_MAJOR_VERSION < 2 +/* PyModule_AddObject function was introduced in Python 2.0. The following function + is copied out of Python/modsupport.c in python version 2.3.4 */ +SWIGINTERN int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m)) { + PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs module as first arg"); + return SWIG_ERROR; + } + if (!o) { + PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs non-NULL value"); + return SWIG_ERROR; + } + + dict = PyModule_GetDict(m); + if (dict == NULL) { + /* Internal error -- modules must have a dict! */ + PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", + PyModule_GetName(m)); + return SWIG_ERROR; + } + if (PyDict_SetItemString(dict, name, o)) + return SWIG_ERROR; + Py_DECREF(o); + return SWIG_OK; +} +#endif + +SWIGRUNTIME void +#ifdef SWIGPY_USE_CAPSULE +SWIG_Python_DestroyModule(PyObject *obj) +#else +SWIG_Python_DestroyModule(void *vptr) +#endif +{ +#ifdef SWIGPY_USE_CAPSULE + swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); +#else + swig_module_info *swig_module = (swig_module_info *) vptr; +#endif + swig_type_info **types = swig_module->types; + size_t i; + for (i =0; i < swig_module->size; ++i) { + swig_type_info *ty = types[i]; + if (ty->owndata) { + SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; + if (data) SwigPyClientData_Del(data); + } + } + Py_DECREF(SWIG_This()); + swig_this = NULL; +} + +SWIGRUNTIME void +SWIG_Python_SetModule(swig_module_info *swig_module) { +#if PY_VERSION_HEX >= 0x03000000 + /* Add a dummy module object into sys.modules */ + PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); +#else + static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ + PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); +#endif +#ifdef SWIGPY_USE_CAPSULE + PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, (char*)"type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } +#else + PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } +#endif +} + +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + +SWIGRUNTIME swig_type_info * +SWIG_Python_TypeQuery(const char *type) +{ + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = SWIG_Python_str_FromChar(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { +#ifdef SWIGPY_USE_CAPSULE + descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); +#else + descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); +#endif + } else { + swig_module_info *swig_module = SWIG_GetModule(0); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { +#ifdef SWIGPY_USE_CAPSULE + obj = PyCapsule_New((void*) descriptor, NULL, NULL); +#else + obj = PyCObject_FromVoidPtr(descriptor, NULL); +#endif + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } + } + Py_DECREF(key); + return descriptor; +} + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +SWIGRUNTIME int +SWIG_Python_AddErrMesg(const char* mesg, int infront) +{ + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); + } else { + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + } + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + } + return 1; + } else { + return 0; + } +} + +SWIGRUNTIME int +SWIG_Python_ArgFail(int argnum) +{ + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIMEINLINE const char * +SwigPyObject_GetDesc(PyObject *self) +{ + SwigPyObject *v = (SwigPyObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : ""; +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && SwigPyObject_Check(obj)) { + const char *otype = (const char *) SwigPyObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + SWIG_Python_str_DelForPy3(cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* Convert a pointer value, signal an exception on a type mismatch */ +SWIGRUNTIME void * +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); +#if SWIG_POINTER_EXCEPTION + if (flags) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } +#endif + } + return result; +} + +#ifdef SWIGPYTHON_BUILTIN +SWIGRUNTIME int +SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { + PyTypeObject *tp = obj->ob_type; + PyObject *descr; + PyObject *encoded_name; + descrsetfunc f; + int res = -1; + +# ifdef Py_USING_UNICODE + if (PyString_Check(name)) { + name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); + if (!name) + return -1; + } else if (!PyUnicode_Check(name)) +# else + if (!PyString_Check(name)) +# endif + { + PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); + return -1; + } else { + Py_INCREF(name); + } + + if (!tp->tp_dict) { + if (PyType_Ready(tp) < 0) + goto done; + } + + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL) + f = descr->ob_type->tp_descr_set; + if (!f) { + if (PyString_Check(name)) { + encoded_name = name; + Py_INCREF(name); + } else { + encoded_name = PyUnicode_AsUTF8String(name); + } + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); + Py_DECREF(encoded_name); + } else { + res = f(descr, obj, value); + } + + done: + Py_DECREF(name); + return res; +} +#endif + + +#ifdef __cplusplus +} +#endif + + + +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_p_SignedIntBuf swig_types[0] +#define SWIGTYPE_p_char swig_types[1] +#define SWIGTYPE_p_int swig_types[2] +static swig_type_info *swig_types[4]; +static swig_module_info swig_module = {swig_types, 3, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + +#if (PY_VERSION_HEX <= 0x02000000) +# if !defined(SWIG_PYTHON_CLASSIC) +# error "This python version requires swig to be run with the '-classic' option" +# endif +#endif + +/*----------------------------------------------- + @(target):= _numpy_swig.so + ------------------------------------------------*/ +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_init PyInit__numpy_swig + +#else +# define SWIG_init init_numpy_swig + +#endif +#define SWIG_name "_numpy_swig" + +#define SWIGVERSION 0x030012 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) + + +#include <stdexcept> + + +namespace swig { + class SwigPtr_PyObject { + protected: + PyObject *_obj; + + public: + SwigPtr_PyObject() :_obj(0) + { + } + + SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) + { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; + } + + SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) + { + if (initial_ref) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; + } + } + + SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) + { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_XINCREF(item._obj); + Py_XDECREF(_obj); + _obj = item._obj; + SWIG_PYTHON_THREAD_END_BLOCK; + return *this; + } + + ~SwigPtr_PyObject() + { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_XDECREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; + } + + operator PyObject *() const + { + return _obj; + } + + PyObject *operator->() const + { + return _obj; + } + }; +} + + +namespace swig { + struct SwigVar_PyObject : SwigPtr_PyObject { + SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } + + SwigVar_PyObject & operator = (PyObject* obj) + { + Py_XDECREF(_obj); + _obj = obj; + return *this; + } + }; +} + + +#define SWIG_FILE_WITH_INIT + + +#ifndef SWIG_FILE_WITH_INIT +#define NO_IMPORT_ARRAY +#endif +#include "stdio.h" +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + + +#include <complex> + + +#include "numpy_swig.h" +#include <numpy/arrayobject.h> + +#if PY_VERSION_HEX >= 0x03000000 +NPY_NO_EXPORT void +gentype_struct_free(PyObject *ptr) +{ + PyArrayInterface *arrif; + PyObject *context; + + arrif = (PyArrayInterface*)PyCapsule_GetPointer(ptr, NULL); + context = (PyObject *)PyCapsule_GetContext(ptr); + Py_DECREF(context); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *)) +{ + PyObject *ret = PyCapsule_New(ptr, NULL, dtor); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *)) +{ + PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor); + if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) { + PyErr_Clear(); + Py_DECREF(ret); + ret = NULL; + } + return ret; +} +#else +NPY_NO_EXPORT void +gentype_struct_free(void *ptr, void *arg) +{ + PyArrayInterface *arrif = (PyArrayInterface *)ptr; + Py_DECREF((PyObject *)arg); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) +{ + return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); +} +#endif + +#ifndef Py_CAPSULE_H +typedef void(*PyCapsule_Destructor)(void *, void *); +#endif + +void delete_SignedIntBuf(SignedIntBuf* buffer) +{ + free(buffer->data); + free(buffer); +} + +void free_array_interface( void* ptr, void *arr ) +{ + PyArrayInterface* inter; + PyObject* arrpy; + + inter = (PyArrayInterface*)ptr; + arrpy = (PyObject*)arr; + Py_DECREF(arrpy); + free(inter); +} +void free_capsule(PyObject* arr) +{ + PyArrayInterface* inter; + inter = (PyArrayInterface*) PyCapsule_GetPointer(arr, "struct SignedIntBuf"); + Py_DECREF(arr); + free(inter); +} + +PyObject* get__array_struct__(PyObject* self) +{ + PyArrayInterface *inter; + PyObject *obj; + int nd; + nd = 2; + Py_intptr_t *shape, *strides; + void *data = NULL; + + shape = (Py_intptr_t *)malloc(nd*sizeof(Py_intptr_t)); + strides = (Py_intptr_t *)malloc(nd*sizeof(Py_intptr_t)); + + inter = (PyArrayInterface*)malloc(sizeof(PyArrayInterface)); + if (inter==NULL) + return PyErr_NoMemory(); + + inter->two = 2; + inter->nd = nd; + inter->typekind = 'i'; + inter->itemsize = sizeof(int); + inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE; + inter->strides = strides; + inter->shape = shape; + inter->data = (void*) data; + Py_INCREF(self); + obj = NpyCapsule_FromVoidPtrAndDesc(inter, self, gentype_struct_free); +/* +#ifdef Py_CAPSULE_H + obj = PyCapsule_New((void*)inter, "struct SignedIntBuf", free_capsule); +#else + obj = PyCObject_FromVoidPtrAndDesc((void*)inter, (void*)self, free_array_interface); +#endif +*/ + return obj; +} + + +#include <limits.h> +#if !defined(SWIG_NO_LLONG_MAX) +# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) +# define LLONG_MAX __LONG_LONG_MAX__ +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +# endif +#endif + + +SWIGINTERN int +SWIG_AsVal_double (PyObject *obj, double *val) +{ + int res = SWIG_TypeError; + if (PyFloat_Check(obj)) { + if (val) *val = PyFloat_AsDouble(obj); + return SWIG_OK; +#if PY_VERSION_HEX < 0x03000000 + } else if (PyInt_Check(obj)) { + if (val) *val = (double) PyInt_AsLong(obj); + return SWIG_OK; +#endif + } else if (PyLong_Check(obj)) { + double v = PyLong_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + double d = PyFloat_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = d; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); + } else { + PyErr_Clear(); + } + } + } +#endif + return res; +} + + +#include <float.h> + + +#include <math.h> + + +SWIGINTERNINLINE int +SWIG_CanCastAsInteger(double *d, double min, double max) { + double x = *d; + if ((min <= x && x <= max)) { + double fx = floor(x); + double cx = ceil(x); + double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ + if ((errno == EDOM) || (errno == ERANGE)) { + errno = 0; + } else { + double summ, reps, diff; + if (rd < x) { + diff = x - rd; + } else if (rd > x) { + diff = rd - x; + } else { + return 1; + } + summ = rd + x; + reps = diff/summ; + if (reps < 8*DBL_EPSILON) { + *d = rd; + return 1; + } + } + } + return 0; +} + + +SWIGINTERN int +SWIG_AsVal_long (PyObject *obj, long* val) +{ +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else +#endif + if (PyLong_Check(obj)) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + return SWIG_OverflowError; + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + long v = PyInt_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + double d; + int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); + if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { + if (val) *val = (long)(d); + return res; + } + } + } +#endif + return SWIG_TypeError; +} + + +SWIGINTERN int +SWIG_AsVal_int (PyObject * obj, int *val) +{ + long v; + int res = SWIG_AsVal_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v < INT_MIN || v > INT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = static_cast< int >(v); + } + } + return res; +} + +SWIGINTERN SignedIntBuf *new_SignedIntBuf(int width,int height){ + SignedIntBuf* buffer = (SignedIntBuf*) malloc(sizeof(SignedIntBuf)); + int shape[2] = { height, width }; + int strides[2] = { width * sizeof(int), sizeof(int) }; + buffer->shape[0] = shape[0]; + buffer->shape[1] = shape[1]; + buffer->strides[0] = strides[0]; + buffer->strides[1] = strides[1]; + buffer->data = (int*) malloc(width*height*sizeof(int)); + return buffer; + } +SWIGINTERN char *SignedIntBuf___str__(SignedIntBuf *self){ + static char tmp[1024]; + int i, j; + int used = 0; + used += sprintf(tmp, "Array:\n"); + for(i=0; i < self->shape[0]; i++) + { + for(j=0; j < self->shape[1]; j++) + used += sprintf(tmp + used, "%d\t", self->data[j + i*self->shape[1]]); + used += sprintf(tmp + used, "\n"); + } + return tmp; + } + +SWIGINTERN swig_type_info* +SWIG_pchar_descriptor(void) +{ + static int init = 0; + static swig_type_info* info = 0; + if (!init) { + info = SWIG_TypeQuery("_p_char"); + init = 1; + } + return info; +} + + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + if (carray) { + if (size > INT_MAX) { + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + return pchar_descriptor ? + SWIG_InternalNewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : SWIG_Py_Void(); + } else { +#if PY_VERSION_HEX >= 0x03000000 +#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + return PyBytes_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); +#else +#if PY_VERSION_HEX >= 0x03010000 + return PyUnicode_DecodeUTF8(carray, static_cast< Py_ssize_t >(size), "surrogateescape"); +#else + return PyUnicode_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); +#endif +#endif +#else + return PyString_FromStringAndSize(carray, static_cast< Py_ssize_t >(size)); +#endif + } + } else { + return SWIG_Py_Void(); + } +} + + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtr(const char *cptr) +{ + return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); +} + +#ifdef __cplusplus +extern "C" { +#endif +SWIGINTERN PyObject *_wrap_get__array_struct__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + PyObject *arg1 = (PyObject *) 0 ; + PyObject * obj0 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:get__array_struct__",&obj0)) SWIG_fail; + arg1 = obj0; + result = (PyObject *)get__array_struct__(arg1); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_data_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + int *arg2 = (int *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:SignedIntBuf_data_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_data_set" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_int, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "SignedIntBuf_data_set" "', argument " "2"" of type '" "int *""'"); + } + arg2 = reinterpret_cast< int * >(argp2); + if (arg1) (arg1)->data = arg2; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_data_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:SignedIntBuf_data_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_data_get" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + result = (int *) ((arg1)->data); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_shape_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + int *arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:SignedIntBuf_shape_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_shape_set" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_int, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "SignedIntBuf_shape_set" "', argument " "2"" of type '" "int [2]""'"); + } + arg2 = reinterpret_cast< int * >(argp2); + { + if (arg2) { + size_t ii = 0; + for (; ii < (size_t)2; ++ii) *(int *)&arg1->shape[ii] = *((int *)arg2 + ii); + } else { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""shape""' of type '""int [2]""'"); + } + } + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_shape_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:SignedIntBuf_shape_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_shape_get" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + result = (int *)(int *) ((arg1)->shape); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_strides_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + int *arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:SignedIntBuf_strides_set",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_strides_set" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_int, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "SignedIntBuf_strides_set" "', argument " "2"" of type '" "int [2]""'"); + } + arg2 = reinterpret_cast< int * >(argp2); + { + if (arg2) { + size_t ii = 0; + for (; ii < (size_t)2; ++ii) *(int *)&arg1->strides[ii] = *((int *)arg2 + ii); + } else { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""strides""' of type '""int [2]""'"); + } + } + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf_strides_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + int *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:SignedIntBuf_strides_get",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf_strides_get" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + result = (int *)(int *) ((arg1)->strides); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_SignedIntBuf(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + int arg1 ; + int arg2 ; + int val1 ; + int ecode1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + SignedIntBuf *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OO:new_SignedIntBuf",&obj0,&obj1)) SWIG_fail; + ecode1 = SWIG_AsVal_int(obj0, &val1); + if (!SWIG_IsOK(ecode1)) { + SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "new_SignedIntBuf" "', argument " "1"" of type '" "int""'"); + } + arg1 = static_cast< int >(val1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_SignedIntBuf" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + result = (SignedIntBuf *)new_SignedIntBuf(arg1,arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_SignedIntBuf, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_SignedIntBuf(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:delete_SignedIntBuf",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_SignedIntBuf" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + delete_SignedIntBuf(arg1); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SignedIntBuf___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SignedIntBuf *arg1 = (SignedIntBuf *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:SignedIntBuf___str__",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SignedIntBuf, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SignedIntBuf___str__" "', argument " "1"" of type '" "SignedIntBuf *""'"); + } + arg1 = reinterpret_cast< SignedIntBuf * >(argp1); + result = (char *)SignedIntBuf___str__(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *SignedIntBuf_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!PyArg_ParseTuple(args,(char *)"O:swigregister", &obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_SignedIntBuf, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +static PyMethodDef SwigMethods[] = { + { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, + { (char *)"get__array_struct__", _wrap_get__array_struct__, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_data_set", _wrap_SignedIntBuf_data_set, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_data_get", _wrap_SignedIntBuf_data_get, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_shape_set", _wrap_SignedIntBuf_shape_set, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_shape_get", _wrap_SignedIntBuf_shape_get, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_strides_set", _wrap_SignedIntBuf_strides_set, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_strides_get", _wrap_SignedIntBuf_strides_get, METH_VARARGS, NULL}, + { (char *)"new_SignedIntBuf", _wrap_new_SignedIntBuf, METH_VARARGS, (char *)"The comment docstring"}, + { (char *)"delete_SignedIntBuf", _wrap_delete_SignedIntBuf, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf___str__", _wrap_SignedIntBuf___str__, METH_VARARGS, NULL}, + { (char *)"SignedIntBuf_swigregister", SignedIntBuf_swigregister, METH_VARARGS, NULL}, + { NULL, NULL, 0, NULL } +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static swig_type_info _swigt__p_SignedIntBuf = {"_p_SignedIntBuf", "SignedIntBuf *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_int = {"_p_int", "int *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__p_SignedIntBuf, + &_swigt__p_char, + &_swigt__p_int, +}; + +static swig_cast_info _swigc__p_SignedIntBuf[] = { {&_swigt__p_SignedIntBuf, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__p_SignedIntBuf, + _swigc__p_char, + _swigc__p_int, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + +static swig_const_info swig_const_table[] = { +{0, 0, 0, 0.0, 0, 0}}; + +#ifdef __cplusplus +} +#endif +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned statically to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int init; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; + } else { + init = 0; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + iter=module_head; + do { + if (iter==&swig_module) { + /* Our module is already in the list, so there's nothing more to do. */ + return; + } + iter=iter->next; + } while (iter!= module_head); + + /* otherwise we must add our module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpreters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* This function will propagate the clientdata field of type to +* any new swig_type_info structures that have been added into the list +* of equivalent types. It is like calling +* SWIG_TypeClientData(type, clientdata) a second time. +*/ +SWIGRUNTIME void +SWIG_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ + /* c-mode */ +#endif +} +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + /* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + + /* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + + typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; + } swig_globalvar; + + typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; + } swig_varlinkobject; + + SWIGINTERN PyObject * + swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_InternFromString("<Swig global variables>"); +#else + return PyString_FromString("<Swig global variables>"); +#endif + } + + SWIGINTERN PyObject * + swig_varlink_str(swig_varlinkobject *v) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *str = PyUnicode_InternFromString("("); + PyObject *tail; + PyObject *joined; + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + tail = PyUnicode_FromString(var->name); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + if (var->next) { + tail = PyUnicode_InternFromString(", "); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + } + } + tail = PyUnicode_InternFromString(")"); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; +#else + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); +#endif + return str; + } + + SWIGINTERN int + swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { + char *tmp; + PyObject *str = swig_varlink_str(v); + fprintf(fp,"Swig global variables "); + fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(str); + return 0; + } + + SWIGINTERN void + swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } + } + + SWIGINTERN PyObject * + swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + } + return res; + } + + SWIGINTERN int + swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + } + return res; + } + + SWIGINTERN PyTypeObject* + swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(NULL, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"swigvarlink", /* tp_name */ + sizeof(swig_varlinkobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor) swig_varlink_dealloc, /* tp_dealloc */ + (printfunc) swig_varlink_print, /* tp_print */ + (getattrfunc) swig_varlink_getattr, /* tp_getattr */ + (setattrfunc) swig_varlink_setattr, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc) swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ +#endif + }; + varlink_type = tmp; + type_init = 1; +#if PY_VERSION_HEX < 0x02020000 + varlink_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&varlink_type) < 0) + return NULL; +#endif + } + return &varlink_type; + } + + /* Create a variable linking object for use later */ + SWIGINTERN PyObject * + SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); + } + + SWIGINTERN void + SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; + } + + SWIGINTERN PyObject * + SWIG_globals(void) { + static PyObject *_SWIG_globals = 0; + if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); + return _SWIG_globals; + } + + /* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + + /* Install Constants */ + SWIGINTERN void + SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { + PyObject *obj = 0; + size_t i; + for (i = 0; constants[i].type; ++i) { + switch(constants[i].type) { + case SWIG_PY_POINTER: + obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } + } + } + + /* -----------------------------------------------------------------------------*/ + /* Fix SwigMethods to carry the callback ptrs when needed */ + /* -----------------------------------------------------------------------------*/ + + SWIGINTERN void + SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { + size_t i; + for (i = 0; methods[i].ml_name; ++i) { + const char *c = methods[i].ml_doc; + if (!c) continue; + c = strstr(c, "swig_ptr: "); + if (c) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; + char *ndoc = (char*)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } + } + } + } + } + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" +#endif + +SWIGEXPORT +#if PY_VERSION_HEX >= 0x03000000 +PyObject* +#else +void +#endif +SWIG_init(void) { + PyObject *m, *d, *md; +#if PY_VERSION_HEX >= 0x03000000 + static struct PyModuleDef SWIG_module = { +# if PY_VERSION_HEX >= 0x03020000 + PyModuleDef_HEAD_INIT, +# else + { + PyObject_HEAD_INIT(NULL) + NULL, /* m_init */ + 0, /* m_index */ + NULL, /* m_copy */ + }, +# endif + (char *) SWIG_name, + NULL, + -1, + SwigMethods, + NULL, + NULL, + NULL, + NULL + }; +#endif + +#if defined(SWIGPYTHON_BUILTIN) + static SwigPyClientData SwigPyObject_clientdata = { + 0, 0, 0, 0, 0, 0, 0 + }; + static PyGetSetDef this_getset_def = { + (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL + }; + static SwigPyGetSet thisown_getset_closure = { + (PyCFunction) SwigPyObject_own, + (PyCFunction) SwigPyObject_own + }; + static PyGetSetDef thisown_getset_def = { + (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure + }; + PyTypeObject *builtin_pytype; + int builtin_base_count; + swig_type_info *builtin_basetype; + PyObject *tuple; + PyGetSetDescrObject *static_getset; + PyTypeObject *metatype; + PyTypeObject *swigpyobject; + SwigPyClientData *cd; + PyObject *public_interface, *public_symbol; + PyObject *this_descr; + PyObject *thisown_descr; + PyObject *self = 0; + int i; + + (void)builtin_pytype; + (void)builtin_base_count; + (void)builtin_basetype; + (void)tuple; + (void)static_getset; + (void)self; + + /* Metaclass is used to implement static member variables */ + metatype = SwigPyObjectType(); + assert(metatype); +#endif + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + +#if PY_VERSION_HEX >= 0x03000000 + m = PyModule_Create(&SWIG_module); +#else + m = Py_InitModule((char *) SWIG_name, SwigMethods); +#endif + + md = d = PyModule_GetDict(m); + (void)md; + + SWIG_InitializeModule(0); + +#ifdef SWIGPYTHON_BUILTIN + swigpyobject = SwigPyObject_TypeOnce(); + + SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); + assert(SwigPyObject_stype); + cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + if (!cd) { + SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; + SwigPyObject_clientdata.pytype = swigpyobject; + } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { + PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); +# if PY_VERSION_HEX >= 0x03000000 + return NULL; +# else + return; +# endif + } + + /* All objects have a 'this' attribute */ + this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); + (void)this_descr; + + /* All objects have a 'thisown' attribute */ + thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); + (void)thisown_descr; + + public_interface = PyList_New(0); + public_symbol = 0; + (void)public_symbol; + + PyDict_SetItemString(md, "__all__", public_interface); + Py_DECREF(public_interface); + for (i = 0; SwigMethods[i].ml_name != NULL; ++i) + SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); + for (i = 0; swig_const_table[i].name != 0; ++i) + SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); +#endif + + SWIG_InstallConstants(d,swig_const_table); + + + import_array(); + +#if PY_VERSION_HEX >= 0x03000000 + return m; +#else + return; +#endif +} + diff --git a/pymolfile/molfile/pymolfile-backup.c b/pymolfile/molfile/pymolfile-backup.c new file mode 100644 index 0000000000000000000000000000000000000000..9e58ed6b0ddee6cd175455dd65178720aed106a7 --- /dev/null +++ b/pymolfile/molfile/pymolfile-backup.c @@ -0,0 +1,329 @@ +/* Hey emacs this is -*- C -*- and this is my editor vim. + * + * molfile.c : C and Fortran interfaces for molfile_plugins + * Copyright (c) Berk Onat <b.onat@warwick.ac.uk> 2017 + * + * This program is under BSD LICENSE + */ + +/* + * The code is written following the plugin test + * context of f77_molfile.c by Axel Kohlmeyer and + * in molfile_plugin/src/f77 and catdcd.c by + * Justin Gullingsrud of VMD plugins. + */ + +/* Get HAVE_CONFIG_H */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <ctype.h> + +/* get fixed-width types if we are using ANSI C99 */ +#ifdef HAVE_STDINT_H +# include <stdint.h> +#elif (defined HAVE_INTTYPES_H) +# include <inttypes.h> +#endif + +#include "pymolfile.h" + +//for PyArrayInterface: +#define CONTIGUOUS=0x01 +#define FORTRAN=0x02 +#define ALIGNED=0x100 +#define NOTSWAPPED=0x200 +#define WRITEABLE=0x400 + +//byteorder dictionary +char* byteorder = {"<", "little", ">", "big"} + +int numplugins=0; +molfile_plugin_t** plugin_list; + + +typedef struct PyArrayInterface{ + int version; //contains the integer 2 as a sanity check + int nd; //number of dimensions + char typekind; //kind in array --- character code of typestr + int itemsize; //size of each element + int flags; //flags indicating how the data should be interpreted + Py_intptr_t *shape; //A length-nd array of shape information + Py_intptr_t *strides; //A length-nd array of stride information + void *data; //A pointer to the first element of the array +}; + + +/* * * * * * * * * * * * * * * * * * * * * * * + * Helper functions to set and store plugins * + * * * * * * * * * * * * * * * * * * * * * * */ + +void* free_array_interface(PyObject *arr){ + Py_DECREF(arr); +} + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict); + +struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(strcmp(dictitem->key, pluginname) == 0){ + return dictitem; + } + dictitem = dictitem->next; + } + return NULL; +} +#endif + +molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no) +{ + molfile_plugin_t* plugin; + if(plug_no < 0){ + plugin = NULL; + } else { + plugin = plug_list[plug_no]; + } + return plugin; +} + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(!dictitem->id){ + if(plugin_list[dictitem->id]->read_next_timestep){ + dictitem->read = 1; + } + if(plugin_list[dictitem->id]->write_timestep){ + dictitem->write = 1; + } + } + dictitem = dictitem->next; + } +} + +static int has_readsupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->read; + } else { + return 0; + } +} + +static int has_writesupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->write; + } else { + return 0; + } +} + +static int plugin_add(struct DICTHOLDER *dict, const char *key, int id){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + dictitem = dict; + while(1){ + // Find the empty next in the list and add item + if(dictitem == NULL){ + struct DICTHOLDER *item = (struct DICTHOLDER*) malloc(sizeof(struct DICTHOLDER)); + item->key = key; + item->id = id; + item->read = NULL; + item->write = NULL; + dictitem = &item; + return 0; + } else { + dictitem = dictitem->next; + } + } + } else { + return 1; + } +} + +static int plugin_remove(struct DICTHOLDER *dict, const char *key){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + // No key in the list. Nothing to remove. + return 1; + } else { + // Remove key in the list + dictitem = dict; + while(dictitem != NULL){ + if(strcmp(dictitem->next->key, key) == 0){ + struct DICTHOLDER *item = dictitem->next->next; + dictitem->next = item; + return 0; + } + dictitem = dictitem->next; + } + return 1; + } +} +#endif +/* * * * * * * * * * * * * * * * * * * * * * * * * * * + * Interface functions to initialize molfile plugins * + * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* check validity of plugins and register them. */ +static int molfile_register(void*, vmdplugin_t *plugin) { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (numplugins >= MAXPLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + //if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + // return VMDPLUGIN_ERROR; + //} else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + //plugin_add(&plugindict, plugin->name, numplugins); + ++numplugins; + return VMDPLUGIN_SUCCESS; + //} +} + +molfile_plugin_t** molfile_plugin_list(int maxsize) +{ + if(maxsize < MAXPLUGINS){ + maxsize = MAXPLUGINS; + } + plugin_list = (molfile_plugin_t**) malloc(sizeof(molfile_plugin_t*)*maxsize); + return plugin_list; +} + +/* register all available plugins and clear handles. */ +int molfile_init(void) +{ +#if 0 + int molfile_internal_register(void *ptr, vmdplugin_t *plugin) + { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (num_plugins >= MAX_PLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + return VMDPLUGIN_ERROR; + } else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + ++numplugins; + return VMDPLUGIN_SUCCESS; + } + } +#endif + MOLFILE_INIT_ALL; + MOLFILE_REGISTER_ALL(NULL,molfile_register); + return numplugins; +} + +/* unregister all available plugins */ +int molfile_finish(void) +{ + MOLFILE_FINI_ALL; + return 0; +} + +/* * * * * * * * * * * * * * * * * * * * * * * + * Wrappers to directly access molfile plugin* + * functions and settings * + * * * * * * * * * * * * * * * * * * * * * * */ + +/* molfile_plugin_t access */ + +/* Functions in molfile_plugin_t */ + +PyObject * my_read_structure(PyObject* molpack) { + Py_Initialize(); + import_array(); + + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* atoms; + int numatoms, status; + PyArray_Descr *descr; + PyObject p*; + if (PyType_Ready(&MolAtomType) < 0) + return NULL; + PyTypeObject *atype = &MolAtomType; + MolAtom *atom_t; + atom_t = (MolAtom *)atype->tp_alloc(atype, 0); + p = (PyObject*) atom_t; + descr = PyArray_DescrFromObject(p, NULL) + MolObject* plugin_handle = (MolObject*) molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + status = plugin->read_structure(file_handle, &options, atoms); + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + PyArrayObject* oresid; + PyObject* array; + int64_t* cresid; + int nd = 1; + npy_intp dims[1] = { numatoms }; + oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); + Py_DECREF(p); + array = (PyArrayObject*) PyArray_SimpleNewFromDescr(1, dims, descr); + PyObject_Print(array, stdout, 0); + if (!oresid){ + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into numpy array."); + return NULL; + } + npy_intp* n = PyArray_DIMS(oresid); + cresid = (int64_t*) PyArray_DATA(oresid); + +// for (i=0;i<numatoms;i++){ +// cresid[i] = (int64_t) atoms[i].resid; +// } + return (PyObject*) PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0); +} + + diff --git a/pymolfile/molfile/pymolfile-backup2.c b/pymolfile/molfile/pymolfile-backup2.c new file mode 100644 index 0000000000000000000000000000000000000000..3411b394b87105aad96f3903b0311e4acd61899c --- /dev/null +++ b/pymolfile/molfile/pymolfile-backup2.c @@ -0,0 +1,565 @@ +/* Hey emacs this is -*- C -*- and this is my editor vim. + * + * molfile.c : C and Fortran interfaces for molfile_plugins + * Copyright (c) Berk Onat <b.onat@warwick.ac.uk> 2017 + * + * This program is under BSD LICENSE + */ + +/* + * The code is written following the plugin test + * context of f77_molfile.c by Axel Kohlmeyer and + * in molfile_plugin/src/f77 and catdcd.c by + * Justin Gullingsrud of VMD plugins. + */ + +/* Get HAVE_CONFIG_H */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <ctype.h> + +/* get fixed-width types if we are using ANSI C99 */ +#ifdef HAVE_STDINT_H +# include <stdint.h> +#elif (defined HAVE_INTTYPES_H) +# include <inttypes.h> +#endif + +#include "pymolfile.h" + +//for PyArrayInterface: +/* +#define CONTIGUOUS 0x01 +#define FORTRAN 0x02 +#define ALIGNED 0x100 +#define NOTSWAPPED 0x200 +#define WRITEABLE 0x400 +#define ARR_HAS_DESCR 0x800 +*/ +//byteorder dictionary +//char** byteorder = {"<", "little", ">", "big"}; + +int numplugins=0; +molfile_plugin_t** plugin_list; + +/* +typedef struct PyArrayInterface{ + int version; //contains the integer 2 as a sanity check + int nd; //number of dimensions + char typekind; //kind in array --- character code of typestr + int itemsize; //size of each element + int flags; //flags indicating how the data should be interpreted + Py_intptr_t *shape; //A length-nd array of shape information + Py_intptr_t *strides; //A length-nd array of stride information + void *data; //A pointer to the first element of the array +}; +*/ +/* * * * * * * * * * * * * * * * * * * * * * * + * Helper functions to set and store plugins * + * * * * * * * * * * * * * * * * * * * * * * */ + +#if PY_VERSION_HEX >= 0x03000000 +#define PyString_FromString PyBytes_FromString +NPY_NO_EXPORT void +gentype_struct_free(PyObject *ptr) +{ + PyArrayInterface *arrif; + PyObject *context; + + arrif = (PyArrayInterface*)PyCapsule_GetPointer(ptr, NULL); + context = (PyObject *)PyCapsule_GetContext(ptr); + Py_DECREF(context); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *)) +{ + PyObject *ret = PyCapsule_New(ptr, NULL, dtor); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *)) +{ + PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor); + if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) { + PyErr_Clear(); + Py_DECREF(ret); + ret = NULL; + } + return ret; +} +#else +#define PyBytes_FromString PyString_FromString +NPY_NO_EXPORT void +gentype_struct_free(void *ptr, void *arg) +{ + PyArrayInterface *arrif = (PyArrayInterface *)ptr; + Py_DECREF((PyObject *)arg); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) +{ + return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); +} +#endif + + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict); + +struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(strcmp(dictitem->key, pluginname) == 0){ + return dictitem; + } + dictitem = dictitem->next; + } + return NULL; +} +#endif + +molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no) +{ + molfile_plugin_t* plugin; + if(plug_no < 0){ + plugin = NULL; + } else { + plugin = plug_list[plug_no]; + } + return plugin; +} + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(!dictitem->id){ + if(plugin_list[dictitem->id]->read_next_timestep){ + dictitem->read = 1; + } + if(plugin_list[dictitem->id]->write_timestep){ + dictitem->write = 1; + } + } + dictitem = dictitem->next; + } +} + +static int has_readsupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->read; + } else { + return 0; + } +} + +static int has_writesupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->write; + } else { + return 0; + } +} + +static int plugin_add(struct DICTHOLDER *dict, const char *key, int id){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + dictitem = dict; + while(1){ + // Find the empty next in the list and add item + if(dictitem == NULL){ + struct DICTHOLDER *item = (struct DICTHOLDER*) malloc(sizeof(struct DICTHOLDER)); + item->key = key; + item->id = id; + item->read = NULL; + item->write = NULL; + dictitem = &item; + return 0; + } else { + dictitem = dictitem->next; + } + } + } else { + return 1; + } +} + +static int plugin_remove(struct DICTHOLDER *dict, const char *key){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + // No key in the list. Nothing to remove. + return 1; + } else { + // Remove key in the list + dictitem = dict; + while(dictitem != NULL){ + if(strcmp(dictitem->next->key, key) == 0){ + struct DICTHOLDER *item = dictitem->next->next; + dictitem->next = item; + return 0; + } + dictitem = dictitem->next; + } + return 1; + } +} +#endif +/* * * * * * * * * * * * * * * * * * * * * * * * * * * + * Interface functions to initialize molfile plugins * + * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* check validity of plugins and register them. */ +static int molfile_register(void*, vmdplugin_t *plugin) { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (numplugins >= MAXPLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + //if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + // return VMDPLUGIN_ERROR; + //} else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + //plugin_add(&plugindict, plugin->name, numplugins); + ++numplugins; + return VMDPLUGIN_SUCCESS; + //} +} + +molfile_plugin_t** molfile_plugin_list(int maxsize) +{ + if(maxsize < MAXPLUGINS){ + maxsize = MAXPLUGINS; + } + plugin_list = (molfile_plugin_t**) malloc(sizeof(molfile_plugin_t*)*maxsize); + return plugin_list; +} + +/* register all available plugins and clear handles. */ +int molfile_init(void) +{ +#if 0 + int molfile_internal_register(void *ptr, vmdplugin_t *plugin) + { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (num_plugins >= MAX_PLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + return VMDPLUGIN_ERROR; + } else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + ++numplugins; + return VMDPLUGIN_SUCCESS; + } + } +#endif + MOLFILE_INIT_ALL; + MOLFILE_REGISTER_ALL(NULL,molfile_register); + return numplugins; +} + +/* unregister all available plugins */ +int molfile_finish(void) +{ + MOLFILE_FINI_ALL; + return 0; +} + +/* * * * * * * * * * * * * * * * * * * * * * * + * Wrappers to directly access molfile plugin* + * functions and settings * + * * * * * * * * * * * * * * * * * * * * * * */ + +/* molfile_plugin_t access */ + +/* Functions in molfile_plugin_t */ + +PyObject * my_read_structure(PyObject* molpack) { + Py_Initialize(); + import_array(); + + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* atoms; + int numatoms, status; + PyArray_Descr *descr; + PyObject *p = NULL; + //if (PyType_Ready(&MolAtomType) < 0) + // return NULL; + //PyTypeObject *atype = &MolAtomType; + //MolAtom *atom_t; + //atom_t = (MolAtom *)atype->tp_alloc(atype, 0); + //p = (PyObject*) atom_t; + descr = PyArray_DescrFromObject(p, NULL); + MolObject* plugin_handle = (MolObject*) molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + status = plugin->read_structure(file_handle, &options, atoms); + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + PyArrayObject* oresid; + PyObject* array; + int64_t* cresid; + int nd = 1; + npy_intp dims[1] = { numatoms }; + oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); + Py_DECREF(p); + //array = (PyArrayObject*) PyArray_SimpleNewFromDescr(1, dims, descr); + //PyObject_Print(array, stdout, 0); + if (!oresid){ + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into numpy array."); + return NULL; + } + npy_intp* n = PyArray_DIMS(oresid); + cresid = (int64_t*) PyArray_DATA(oresid); + +// for (i=0;i<numatoms;i++){ +// cresid[i] = (int64_t) atoms[i].resid; +// } + return (PyObject*) PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0); +} + + +PyObject* get_structure(PyObject* self) +{ + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* data; + int numatoms, status; + int nd; + PyArrayInterface *inter; + PyArrayObject *ret; + char endian = NPY_NATBYTE; + // Access plugin_handle values + MolObject* plugin_handle = (MolObject*) self; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + // Allocate memory for array of molfile_atom_t struct + data = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + // Get array values in molfile_atom_t + status = plugin->read_structure(file_handle, &options, data); + // Check if the plugin returns the results + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + // Now, we need to allocate a PyArray with PyArrayInterface + // and assign the allocated memory block to the data. + // To do this, we will build a numpy array from scratch. + // First, allocate a PyObject of PyArrayInterface and + // assign relevant information such as typestr, descr for C-side + // struct and second we will assign molfile_atom_t array as a block + // of data. Last, hope this works. + nd = 1; + npy_intp dims[1] = { 1 }; + // We would allocate a numpy array with + // but will not look clever to copy all the data into the new array. + // Instead, we allocate a numpy array with one element and change + // the definition of array. I know I said that it will be from scratch + // but let's accept nobody wants to define everything in numpy again. + //oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT); + // NPY_INT? Don't worry, we will change it. + //Py_intptr_t *shape, *strides; + //void *data = NULL; + + inter = (PyArrayInterface*)malloc(sizeof(PyArrayInterface)); + if (inter==NULL) + return PyErr_NoMemory(); + + // __array_interface__ descr for C side of __array_struct__ + // Could not find a better way to generate the list of tuples for + // Python side. May need to change this later. + PyObject *tuple = PyTuple_New(13); + // One tuple to bind them + PyObject *py_list_name = PyList_New(2); + PyList_SET_ITEM(py_list_name, 0, PyString_FromString("name")); + PyList_SET_ITEM(py_list_name, 0, PyString_FromString("|S16")); + PyTuple_SET_ITEM(tuple, 0, py_list_name); + PyObject *py_list_type = PyList_New(2); + PyList_SET_ITEM(py_list_type, 0, PyString_FromString("type")); + PyList_SET_ITEM(py_list_type, 0, PyString_FromString("|S16")); + PyTuple_SET_ITEM(tuple, 1, py_list_type); + PyObject *py_list_resname = PyList_New(2); + PyList_SET_ITEM(py_list_resname, 0, PyString_FromString("resname")); + PyList_SET_ITEM(py_list_resname, 0, PyString_FromString("|S8")); + PyTuple_SET_ITEM(tuple, 2, py_list_resname); + PyObject *py_list_resid = PyList_New(2); + PyList_SET_ITEM(py_list_resid, 0, PyString_FromString("resid")); + PyList_SET_ITEM(py_list_resid, 0, PyString_FromString("<i4")); + PyTuple_SET_ITEM(tuple, 3, py_list_resid); + PyObject *py_list_segid = PyList_New(2); + PyList_SET_ITEM(py_list_segid, 0, PyString_FromString("segid")); + PyList_SET_ITEM(py_list_segid, 0, PyString_FromString("|S8")); + PyTuple_SET_ITEM(tuple, 4, py_list_segid); + PyObject *py_list_chain = PyList_New(2); + PyList_SET_ITEM(py_list_chain, 0, PyString_FromString("chain")); + PyList_SET_ITEM(py_list_chain, 0, PyString_FromString("|S2")); + PyTuple_SET_ITEM(tuple, 5, py_list_chain); + PyObject *py_list_altloc = PyList_New(2); + PyList_SET_ITEM(py_list_altloc, 0, PyString_FromString("altloc")); + PyList_SET_ITEM(py_list_altloc, 0, PyString_FromString("|S2")); + PyTuple_SET_ITEM(tuple, 6, py_list_altloc); + PyObject *py_list_insertion = PyList_New(2); + PyList_SET_ITEM(py_list_insertion, 0, PyString_FromString("insertion")); + PyList_SET_ITEM(py_list_insertion, 0, PyString_FromString("|S2")); + PyTuple_SET_ITEM(tuple, 7, py_list_insertion); + PyObject *py_list_occupancy = PyList_New(2); + PyList_SET_ITEM(py_list_occupancy, 0, PyString_FromString("occupancy")); + PyList_SET_ITEM(py_list_occupancy, 0, PyString_FromString("|f4")); + PyTuple_SET_ITEM(tuple, 8, py_list_occupancy); + PyObject *py_list_bfactor = PyList_New(2); + PyList_SET_ITEM(py_list_bfactor, 0, PyString_FromString("bfactor")); + PyList_SET_ITEM(py_list_bfactor, 0, PyString_FromString("|f4")); + PyTuple_SET_ITEM(tuple, 9, py_list_bfactor); + PyObject *py_list_mass = PyList_New(2); + PyList_SET_ITEM(py_list_mass, 0, PyString_FromString("mass")); + PyList_SET_ITEM(py_list_mass, 0, PyString_FromString("|f4")); + PyTuple_SET_ITEM(tuple, 10, py_list_mass); + PyObject *py_list_charge = PyList_New(2); + PyList_SET_ITEM(py_list_charge, 0, PyString_FromString("charge")); + PyList_SET_ITEM(py_list_charge, 0, PyString_FromString("|f4")); + PyTuple_SET_ITEM(tuple, 11, py_list_charge); + PyObject *py_list_radius = PyList_New(2); + PyList_SET_ITEM(py_list_radius, 0, PyString_FromString("radius")); + PyList_SET_ITEM(py_list_radius, 0, PyString_FromString("|f4")); + PyTuple_SET_ITEM(tuple, 12, py_list_radius); + PyObject *py_list_atomicnumber = PyList_New(2); + PyList_SET_ITEM(py_list_atomicnumber, 0, PyString_FromString("atomicnumber")); + PyList_SET_ITEM(py_list_atomicnumber, 0, PyString_FromString("|i4")); + PyTuple_SET_ITEM(tuple, 13, py_list_atomicnumber); + //PyArray_Descr *descr = (PyObject*) tuple; + PyArray_Descr *descr = NULL; + // Here we define the size and stride parameters + npy_intp shape[1] = { numatoms }; + npy_intp strides[1] = { 54*sizeof(char) + 8*sizeof(int) + 20*sizeof(float) }; + + inter->two = 2; + inter->nd = nd; + inter->typekind = 'V'; + inter->itemsize = 82*sizeof(char); + inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE | NPY_ARR_HAS_DESCR; + inter->strides = (Py_intptr_t *)strides; + inter->shape = (Py_intptr_t *)shape; + inter->data = (void*) data; + // inter->descr = (PyObject*) tuple; + if ((inter->flags & NPY_ARRAY_NOTSWAPPED) != NPY_ARRAY_NOTSWAPPED) { + endian = NPY_OPPBYTE; + inter->flags &= ~NPY_ARRAY_NOTSWAPPED; + } + // typestr is relatively easy to assign to __array_interface__ + printf("TEST1\n"); + if (inter->flags & NPY_ARR_HAS_DESCR) { + printf("TEST1-1\n"); + if (PyArray_DescrConverter(inter->descr, &descr) == NPY_FAIL) { + descr = NULL; + PyErr_Clear(); + } + } + printf("TEST1-2\n"); + char buf[40]; + PyOS_snprintf(buf, sizeof(buf), + "%c%c%d", endian, + inter->typekind, + inter->itemsize); + printf("TEST2\n"); + PyObject *stringobj = PyString_FromString(buf); + if (stringobj == NULL) { + return NULL; + } + printf("TEST2-2\n"); + if (PyArray_DescrConverter(stringobj, &descr) != NPY_SUCCEED) { + Py_DECREF(stringobj); + return NULL; + } + printf("TEST2-3\n"); + Py_DECREF(stringobj); + + printf("TEST3\n"); + ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, descr, + inter->nd, inter->shape, + inter->strides, inter->data, + inter->flags, NULL); + printf("TEST4\n"); + Py_INCREF(inter); + if (PyArray_SetBaseObject(ret, (PyObject *)inter) < 0) { + Py_DECREF(ret); + return NULL; + } + printf("TEST5\n"); +// Py_DECREF(attr); + PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL); + printf("TEST6\n"); + return (PyObject *)ret; +} +// obj = NpyCapsule_FromVoidPtrAndDesc(inter, self, gentype_struct_free); +/* +#ifdef Py_CAPSULE_H + obj = PyCapsule_New((void*)inter, "struct SignedIntBuf", free_capsule); +#else + obj = PyCObject_FromVoidPtrAndDesc((void*)inter, (void*)self, free_array_interface); +#endif +*/ + // Cross fingers here. +// return obj; + diff --git a/pymolfile/molfile/pymolfile-backup2.h b/pymolfile/molfile/pymolfile-backup2.h new file mode 100644 index 0000000000000000000000000000000000000000..a97de9efecb0b8ab79e791abb2a68a3013957c2b --- /dev/null +++ b/pymolfile/molfile/pymolfile-backup2.h @@ -0,0 +1,354 @@ +/* Hey emacs this is -*- C -*- and this is my editor vim. + * + * molfile.c : C and Fortran interfaces for molfile_plugins + * Copyright (c) Berk Onat <b.onat@warwick.ac.uk> 2017 + * + * This program is under BSD LICENSE + */ + +/* + * The code is written following the plugin test + * context of f77_molfile.c by Axel Kohlmeyer and + * in molfile_plugin/src/f77 and catdcd.c by + * Justin Gullingsrud of VMD plugins. + */ + +#ifndef _MOLFILE_H_ +#define _MOLFILE_H_ + +#ifdef __cplusplus +extern "C" +{ + +#endif + +#include "molfile_plugin.h" +#include "libmolfile_plugin.h" +#include "vmdplugin.h" +#include "Python.h" +#include "structmember.h" +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + +enum { pluginOK, pluginNOINIT, pluginCLOSE, pluginNOMEM, + pluginENDOFFILE, pluginFILENOTFOUND, pluginFORMATERROR }; + +#ifndef MAXPLUGINS +#define MAXPLUGINS 200 +#endif + +struct MolObject { + PyObject_HEAD + molfile_plugin_t* plugin; + void* file_handle; + int natoms; + MolObject(void) {} +}; + +static void MolObject_dealloc(MolObject* self) +{ + Py_XDECREF(self->plugin); + Py_XDECREF(self->file_handle); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject * MolObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + MolObject *self; + + self = (MolObject *)type->tp_alloc(type, 0); + if (self != NULL) { + self->plugin = NULL; + self->file_handle = NULL; + self->natoms = 0; + } + + return (PyObject *)self; +} + +static int MolObject_init(MolObject *self, PyObject *args, PyObject *kwds) +{ + molfile_plugin_t *plugin = NULL; + void *file_handle = NULL; + molfile_plugin_t *tmp1 = NULL; + void *tmp2 = NULL; + + static char *kwlist[] = {"plugin", "file_handle", "natoms", NULL}; + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, + &plugin, &file_handle, + &self->natoms)) + return -1; + + if (plugin) { + tmp1 = self->plugin; + Py_INCREF(plugin); + self->plugin = plugin; + Py_XDECREF(tmp1); + } + + if (file_handle) { + tmp2 = self->file_handle; + Py_INCREF(file_handle); + self->file_handle = file_handle; + Py_XDECREF(tmp2); + } + + return 0; +} + +static molfile_plugin_t* MolObject_plugin(MolObject* self) +{ + return self->plugin; +} + +static void* MolObject_file_handle(MolObject* self) +{ + return self->file_handle; +} + +static PyObject* MolObject_natoms(MolObject* self) +{ + return PyLong_FromLong((long)self->natoms); +} + +static PyMemberDef MolObject_members[] = { + {"plugin", T_OBJECT_EX, offsetof(MolObject, plugin), 0, + "molfile_plugin_t type plugin"}, + {"file_handle", T_OBJECT_EX, offsetof(MolObject, file_handle), 0, + "file handle for plugin"}, + {"natoms", T_INT, offsetof(MolObject, natoms), 0, + "number of atoms"}, + {NULL} /* Sentinel */ +}; + +static PyMethodDef MolObject_methods[] = { + {"get_plugin", (PyCFunction)MolObject_plugin, METH_NOARGS, + "Return the plugin" + }, + {"get_file_handle", (PyCFunction)MolObject_file_handle, METH_NOARGS, + "Return the plugin" + }, + {"get_natoms", (PyCFunction)MolObject_natoms, METH_NOARGS, + "Return the number of atoms" + }, + {NULL} /* Sentinel */ +}; + + +#ifndef PyVarObject_HEAD_INIT + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#endif + +static PyTypeObject MolObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "molobject", /*tp_name*/ + sizeof(MolObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)MolObject_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_reserved*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "molobject objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + MolObject_methods, /* tp_methods */ + MolObject_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)MolObject_init, /* tp_init */ + 0, /* tp_alloc */ + MolObject_new, /* tp_new */ +}; + +#if 0 +struct MolAtom { + PyObject_HEAD + char* name; + char* type; + char* resname; + int* resid; + char* segid; + char* chain; + char* altloc; + char* insertion; + float* occupancy; + float* bfactor; + float* mass; + float* charge; + float* radius; + float* atomicnumber; + float* ctnumber; + MolAtom(void) {} +}; + +static void MolAtom_dealloc(MolAtom* self) +{ + Py_XDECREF(self->name); + Py_XDECREF(self->type); + Py_XDECREF(self->resname); + Py_XDECREF(self->resid); + Py_XDECREF(self->segid); + Py_XDECREF(self->chain); + Py_XDECREF(self->altloc); + Py_XDECREF(self->insertion); + Py_XDECREF(self->occupancy); + Py_XDECREF(self->bfactor); + Py_XDECREF(self->mass); + Py_XDECREF(self->charge); + Py_XDECREF(self->radius); + Py_XDECREF(self->atomicnumber); + Py_XDECREF(self->ctnumber); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject * MolAtom_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + MolAtom *self; + + self = (MolAtom *)type->tp_alloc(type, 0); + if (self != NULL) { + self->name = NULL; + self->type = NULL; + self->resname = NULL; + self->resid = NULL; + self->segid = NULL; + self->chain = NULL; + self->altloc = NULL; + self->insertion = NULL; + self->occupancy = NULL; + self->bfactor = NULL; + self->mass = NULL; + self->charge = NULL; + self->radius = NULL; + self->atomicnumber = NULL; + self->ctnumber = NULL; + } + + return (PyObject *)self; +} + +static PyMemberDef MolAtom_members[] = { + {"name", T_STRING, offsetof(MolAtom, name), 0,""}, + {"type", T_STRING, offsetof(MolAtom, type), 0,""}, + {"resname", T_STRING, offsetof(MolAtom, resname), 0,""}, + {"resid", T_INT, offsetof(MolAtom, resid), 0,""}, + {"segid", T_STRING, offsetof(MolAtom, segid), 0,""}, + {"chain", T_STRING, offsetof(MolAtom, chain), 0,""}, + {"altloc", T_STRING, offsetof(MolAtom, altloc), 0,""}, + {"insertion", T_STRING, offsetof(MolAtom, insertion), 0,""}, + {"occupancy", T_FLOAT, offsetof(MolAtom, occupancy), 0,""}, + {"bfactor", T_FLOAT, offsetof(MolAtom, bfactor), 0,""}, + {"mass", T_FLOAT, offsetof(MolAtom, mass), 0,""}, + {"charge", T_FLOAT, offsetof(MolAtom, charge), 0,""}, + {"radius", T_FLOAT, offsetof(MolAtom, radius), 0,""}, + {"atomicnumber", T_INT, offsetof(MolAtom, atomicnumber), 0,""}, + {"ctnumber", T_INT, offsetof(MolAtom, ctnumber), 0,""}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static PyTypeObject MolAtomType = { + PyVarObject_HEAD_INIT(NULL, 0) + "molobject", /*tp_name*/ + sizeof(MolAtom), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)MolAtom_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_reserved*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "molatom objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + MolAtom_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + MolAtom_new, /* tp_new */ +}; +#endif +PyObject * my_read_structure(PyObject* molpack); +PyObject * get_structure(PyObject* molpack); + +#if 0 +typedef struct DICTHOLDER { + const char *key; // Dictionary key + int id; // Id of the item + int read; // 1 if molfile plugin read the format + int write; // 1 if molfile plugin write in this format + struct DICTHOLDER *next; // Next item in the dictionary +} DICTHOLDER; + +struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname); + +static int plugin_add(struct DICTHOLDER *dict, const char *key, int id); + +static int plugin_remove(struct DICTHOLDER *dict, const char *key); + +static int has_readsupport(const char *pluginname); + +static int has_writesupport(const char *pluginname); + +static molfile_plugin_t *get_plugin(const char *pluginname); + +static int molfile_register(void *ptr, vmdplugin_t *plugin); + +#endif +molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no); + +molfile_plugin_t** molfile_plugin_list(int maxsize); + +int molfile_init(void); + +int molfile_finish(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _MOLFILE_H_ */ + diff --git a/pymolfile/molfile/pymolfile-new.c b/pymolfile/molfile/pymolfile-new.c new file mode 100644 index 0000000000000000000000000000000000000000..21b1c00209ce30e6994149cfa8ee242034c3545e --- /dev/null +++ b/pymolfile/molfile/pymolfile-new.c @@ -0,0 +1,1522 @@ +/* Hey emacs this is -*- C -*- and this is my editor vim. + * + * molfile.c : C and Fortran interfaces for molfile_plugins + * Copyright (c) Berk Onat <b.onat@warwick.ac.uk> 2017 + * + * This program is under BSD LICENSE + */ + +/* + * The code is written following the plugin test + * context of f77_molfile.c by Axel Kohlmeyer and + * in molfile_plugin/src/f77 and catdcd.c by + * Justin Gullingsrud of VMD plugins. + */ + +/* Get HAVE_CONFIG_H */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <ctype.h> + +/* get fixed-width types if we are using ANSI C99 */ +#ifdef HAVE_STDINT_H +# include <stdint.h> +#elif (defined HAVE_INTTYPES_H) +# include <inttypes.h> +#endif + +#include "pymolfile.h" + + +//for PyArrayInterface: +/* +#define CONTIGUOUS 0x01 +#define FORTRAN 0x02 +#define ALIGNED 0x100 +#define NOTSWAPPED 0x200 +#define WRITEABLE 0x400 +#define ARR_HAS_DESCR 0x800 +*/ +//byteorder dictionary +//char** byteorder = {"<", "little", ">", "big"}; + +int numplugins=0; +molfile_plugin_t** plugin_list; + +/* +typedef struct PyArrayInterface{ + int version; //contains the integer 2 as a sanity check + int nd; //number of dimensions + char typekind; //kind in array --- character code of typestr + int itemsize; //size of each element + int flags; //flags indicating how the data should be interpreted + Py_intptr_t *shape; //A length-nd array of shape information + Py_intptr_t *strides; //A length-nd array of stride information + void *data; //A pointer to the first element of the array +}; +*/ +/* * * * * * * * * * * * * * * * * * * * * * * + * Helper functions to set and store plugins * + * * * * * * * * * * * * * * * * * * * * * * */ + +#define PyInt_AsSsize_t PyLong_AsSsize_t +#define PyArray_Check(op) PyObject_TypeCheck(op, &PyArray_Type) + +#if PY_VERSION_HEX >= 0x03000000 +#define PyString_FromString PyBytes_FromString +NPY_NO_EXPORT void +gentype_struct_free(PyObject *ptr) +{ + PyArrayInterface *arrif; + PyObject *context; + + arrif = (PyArrayInterface*)PyCapsule_GetPointer(ptr, NULL); + context = (PyObject *)PyCapsule_GetContext(ptr); + Py_DECREF(context); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +static NPY_INLINE void * +NpyCapsule_AsVoidPtr(PyObject *obj) +{ + void *ret = PyCapsule_GetPointer(obj, NULL); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *)) +{ + PyObject *ret = PyCapsule_New(ptr, NULL, dtor); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *)) +{ + PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor); + if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) { + PyErr_Clear(); + Py_DECREF(ret); + ret = NULL; + } + return ret; +} +#else +#define PyBytes_FromString PyString_FromString +NPY_NO_EXPORT void +gentype_struct_free(void *ptr, void *arg) +{ + PyArrayInterface *arrif = (PyArrayInterface *)ptr; + Py_DECREF((PyObject *)arg); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) +{ + return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); +} +#endif +static PyObject *typeDict = NULL; /* Must be explicitly loaded */ + +#define PyUString_Check PyUnicode_Check +#define PyUString_GET_SIZE PyUnicode_GET_SIZE +#define PyUString_FromFormat PyUnicode_FromFormat +#define PyInt_FromLong PyLong_FromLong +#define PyString_Type PyBytes_Type +#define PyInt_Type PyLong_Type + +#define NPY_NEXT_ALIGNED_OFFSET(offset, alignment) \ + (((offset) + (alignment) - 1) & (-(alignment))) + +static PyArray_Descr * +_convert_from_array_descr(PyObject *obj, int align) +{ + int n, i, totalsize; + int ret; + PyObject *fields, *item, *newobj; + PyObject *name, *tup, *title; + PyObject *nameslist; + PyArray_Descr *newea; + PyArray_Descr *conv; + /* Types with fields need the Python C API for field access */ + char dtypeflags = NPY_NEEDS_PYAPI; + int maxalign = 0; + + printf("Test1\n"); + n = PyList_GET_SIZE(obj); + nameslist = PyTuple_New(n); + if (!nameslist) { + return NULL; + } + totalsize = 0; + fields = PyDict_New(); + for (i = 0; i < n; i++) { + item = PyList_GET_ITEM(obj, i); + if (!PyTuple_Check(item) || (PyTuple_GET_SIZE(item) < 2)) { + goto fail; + } + name = PyTuple_GET_ITEM(item, 0); + if (PyUString_Check(name)) { + title = NULL; + } + else if (PyTuple_Check(name)) { + if (PyTuple_GET_SIZE(name) != 2) { + goto fail; + } + title = PyTuple_GET_ITEM(name, 0); + name = PyTuple_GET_ITEM(name, 1); + if (!PyUString_Check(name)) { + goto fail; + } + } + else { + goto fail; + } + + /* Insert name into nameslist */ + Py_INCREF(name); + + if (PyUString_GET_SIZE(name) == 0) { + Py_DECREF(name); + if (title == NULL) { + name = PyUString_FromFormat("f%d", i); + } +#if PY_VERSION_HEX >= 0x03000000 + /* On Py3, allow only non-empty Unicode strings as field names */ + else if (PyUString_Check(title) && PyUString_GET_SIZE(title) > 0) { + name = title; + Py_INCREF(name); + } + else { + goto fail; + } +#else + else { + name = title; + Py_INCREF(name); + } +#endif + } + PyTuple_SET_ITEM(nameslist, i, name); + + /* Process rest */ + + printf("Test2\n"); + if (PyTuple_GET_SIZE(item) == 2) { + if (align) { + printf("Test3\n"); + ret = PyArray_DescrAlignConverter(PyTuple_GET_ITEM(item, 1), + &conv); + } + else { + printf("Test4\n"); + ret = PyArray_DescrConverter(PyTuple_GET_ITEM(item, 1), &conv); + } + if (ret == NPY_FAIL) { + PyObject_Print(PyTuple_GET_ITEM(item, 1), stderr, 0); + } + } + else if (PyTuple_GET_SIZE(item) == 3) { + newobj = PyTuple_GetSlice(item, 1, 3); + if (align) { + printf("Test5\n"); + ret = PyArray_DescrAlignConverter(newobj, &conv); + } + else { + printf("Test6\n"); + ret = PyArray_DescrConverter(newobj, &conv); + } + Py_DECREF(newobj); + } + else { + goto fail; + } + if (ret == NPY_FAIL) { + goto fail; + } + if ((PyDict_GetItem(fields, name) != NULL) + || (title +#if PY_VERSION_HEX >= 0x03000000 + && PyUString_Check(title) +#else + && (PyUString_Check(title) || PyUnicode_Check(title)) +#endif + && (PyDict_GetItem(fields, title) != NULL))) { +#if PY_VERSION_HEX >= 0x03000000 + name = PyUnicode_AsUTF8String(name); +#endif + PyErr_Format(PyExc_ValueError, + "field '%s' occurs more than once", PyBytes_AsString(name)); +#if PY_VERSION_HEX >= 0x03000000 + Py_DECREF(name); +#endif + goto fail; + } + dtypeflags |= (conv->flags & NPY_FROM_FIELDS); + if (align) { + int _align; + + _align = conv->alignment; + if (_align > 1) { + totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, _align); + } + maxalign = PyArray_MAX(maxalign, _align); + } + tup = PyTuple_New((title == NULL ? 2 : 3)); + PyTuple_SET_ITEM(tup, 0, (PyObject *)conv); + PyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize)); + + /* + * Title can be "meta-data". Only insert it + * into the fields dictionary if it is a string + * and if it is not the same as the name. + */ + if (title != NULL) { + Py_INCREF(title); + PyTuple_SET_ITEM(tup, 2, title); + PyDict_SetItem(fields, name, tup); +#if PY_VERSION_HEX >= 0x03000000 + if (PyUString_Check(title)) { +#else + if (PyUString_Check(title) || PyUnicode_Check(title)) { +#endif + if (PyDict_GetItem(fields, title) != NULL) { + PyErr_SetString(PyExc_ValueError, + "title already used as a name or title."); + Py_DECREF(tup); + goto fail; + } + PyDict_SetItem(fields, title, tup); + } + } + else { + PyDict_SetItem(fields, name, tup); + } + + totalsize += conv->elsize; + Py_DECREF(tup); + } + + if (maxalign > 1) { + totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, maxalign); + } + + newea = PyArray_DescrNewFromType(NPY_VOID); + if (newea == NULL) { + Py_XDECREF(fields); + Py_XDECREF(nameslist); + return NULL; + } + newea->fields = fields; + newea->names = nameslist; + newea->elsize = totalsize; + newea->flags = dtypeflags; + + /* Structured arrays get a sticky aligned bit */ + if (align) { + newea->flags |= NPY_ALIGNED_STRUCT; + newea->alignment = maxalign; + } + return newea; + + fail: + Py_DECREF(fields); + Py_DECREF(nameslist); + return NULL; + +} + +static NPY_INLINE npy_bool +_is_basic_python_type(PyTypeObject *tp) +{ + return ( + /* Basic number types */ + tp == &PyBool_Type || +#if PY_VERSION_HEX >= 0x03000000 + tp == &PyInt_Type || +#endif + tp == &PyLong_Type || + tp == &PyFloat_Type || + tp == &PyComplex_Type || + + /* Basic sequence types */ + tp == &PyList_Type || + tp == &PyTuple_Type || + tp == &PyDict_Type || + tp == &PySet_Type || + tp == &PyFrozenSet_Type || + tp == &PyUnicode_Type || + tp == &PyBytes_Type || +#if PY_VERSION_HEX >= 0x03000000 + tp == &PyString_Type || +#endif + + /* other builtins */ + tp == &PySlice_Type || + tp == Py_TYPE(Py_None) || + tp == Py_TYPE(Py_Ellipsis) || + tp == Py_TYPE(Py_NotImplemented) || + + /* TODO: ndarray, but we can't see PyArray_Type here */ + + /* sentinel to swallow trailing || */ + NPY_FALSE + ); +} + +static NPY_INLINE PyObject * +maybe_get_attr(PyObject *obj, char *name) +{ + PyTypeObject *tp = Py_TYPE(obj); + PyObject *res = (PyObject *)NULL; + + /* Attribute referenced by (char *)name */ + if (tp->tp_getattr != NULL) { + res = (*tp->tp_getattr)(obj, name); + if (res == NULL) { + PyErr_Clear(); + } + } + /* Attribute referenced by (PyObject *)name */ + else if (tp->tp_getattro != NULL) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *w = PyUnicode_InternFromString(name); +#else + PyObject *w = PyString_InternFromString(name); +#endif + if (w == NULL) { + return (PyObject *)NULL; + } + res = (*tp->tp_getattro)(obj, w); + Py_DECREF(w); + if (res == NULL) { + PyErr_Clear(); + } + } + return res; +} + +static int +maybe_set_attr(PyObject *obj, char *name, PyObject *attr) +{ + PyTypeObject *tp = Py_TYPE(obj); + int status; + + /* Attribute referenced by (char *)name */ + if (tp->tp_setattr != NULL) { + status = (*tp->tp_setattr)(obj, name, attr); + if (status < 0) { + PyErr_Clear(); + return -1; + } + } + /* Attribute referenced by (PyObject *)name */ + else if (tp->tp_setattro != NULL) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *w = PyUnicode_InternFromString(name); +#else + PyObject *w = PyString_InternFromString(name); +#endif + if (w == NULL) { + return -1; + } + status = (*tp->tp_setattro)(obj, w, attr); + Py_DECREF(w); + if (status < 0) { + PyErr_Clear(); + return -1; + } + } + return 0; +} + +static int get_array_struct(PyObject* obj, int *maxndim, npy_intp *d_shape, PyArrayInterface* inter) +{ + PyTypeObject *tp = Py_TYPE(obj); + PyObject* ret; + char* str; + int i; + str = "__array_struct__"; + /* We do not need to check for special attributes on trivial types */ + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_struct__ interface */ + ret = maybe_get_attr(obj, str); + if (ret != NULL) { + int nd = -1; + if (PyCapsule_CheckExact(ret)) { + PyArrayInterface *inter; + inter = (PyArrayInterface *)NpyCapsule_AsVoidPtr(ret); + if (inter->two == 2) { + nd = inter->nd; + if (nd >= 0) { + if (nd < *maxndim) { + *maxndim = nd; + } + for (i=0; i<*maxndim; i++) { + d_shape[i] = inter->shape[i]; + } + } + } + } + if(nd >= 0){ + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + +static int my_get_array_attr_interface(PyObject* obj, PyObject* newi){ + newi = obj; +// Py_INCREF(obj); +// Py_DECREF(obj); + return 0; +} + +static int get_array_attr_interface(PyObject* obj, char* str, int *maxndim, npy_intp *d_shape, PyObject* newi){ + PyTypeObject *tp = Py_TYPE(obj); + char* dictstr; + int i; + dictstr = "__array_interface__"; + PyObject* ret; + PyObject* objj; + newi = obj; + return 0; + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_interface__ interface */ + printf("T1\n"); + ret = maybe_get_attr(obj, dictstr); + printf("T2\n"); + if (ret != NULL) { + int nd = -1; + if (PyDict_Check(ret)) { + objj = PyDict_GetItemString(ret, "shape"); + //newi = PyDict_GetItemString(ret, str); + printf("T3\n"); + if (objj && PyTuple_Check(objj)) { + nd = PyTuple_GET_SIZE(objj); + printf("T4\n"); + if (nd >= 0) { + *maxndim = nd; + for (i=0; i<nd; i++) { + d_shape[i] = PyInt_AsSsize_t(PyTuple_GET_ITEM(objj, i)); + if (d_shape[i] < 0) { + PyErr_SetString(PyExc_RuntimeError, + "Invalid shape in __array_interface__"); + return -1; + } + } + } + } + } + if (nd >= 0) { + printf("T5\n"); + //newi = (PyArrayObject*) objj; + PyObject* tuple = PyTuple_New(1); + PyTuple_SET_ITEM(tuple, 0, objj); + newi = (PyObject*) tuple; + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + +static int set_array_attr_interface(PyObject* obj, PyObject* attr, int *nd, npy_intp *d_shape, void* data) +{ + int i, status; +/* obj has the __array_interface__ interface */ + if (obj != NULL || attr !=NULL) { + if (PyDict_Check(attr)) { + PyObject *new_shape = PyTuple_New(*nd); + for (i=0; i<*nd; i++) { + PyTuple_SET_ITEM(new_shape, i, PyInt_FromLong((int)d_shape[i])); + } + status = PyDict_SetItemString(attr, "shape", new_shape); + if (status<0){ + Py_DECREF(new_shape); + PyErr_Clear(); + return -1; + } + PyObject *new_data = PyTuple_New(*nd); + PyTuple_SET_ITEM(new_data, 0, PyLong_FromVoidPtr(data)); + PyTuple_SET_ITEM(new_data, 1, PyInt_FromLong((long)1)); + status = PyDict_SetItemString(attr, "data", new_data); + if (status<0){ + Py_DECREF(new_data); + PyErr_Clear(); + return -1; + } + status = maybe_set_attr(obj, "__array_interface__", attr); + if (status<0){ + Py_DECREF(new_data); + Py_DECREF(new_shape); + PyErr_Clear(); + return -1; + } + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + + + + +#if 0 +NPY_NO_EXPORT int +MyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) +{ + int check_num = NPY_NOTYPE + 10; + PyObject *item; + int elsize = 0; + char endian = '='; + + *at = NULL; + + printf("Test0\n"); + /* default */ + if (obj == Py_None) { + *at = PyArray_DescrFromType(NPY_DEFAULT_TYPE); + return NPY_SUCCEED; + } + + printf("Test1\n"); + if (PyArray_DescrCheck(obj)) { + *at = (PyArray_Descr *)obj; + Py_INCREF(*at); + return NPY_SUCCEED; + } + + printf("Test2\n"); + if (PyType_Check(obj)) { + if (PyType_IsSubtype((PyTypeObject *)obj, &PyGenericArrType_Type)) { + *at = PyArray_DescrFromTypeObject(obj); + return (*at) ? NPY_SUCCEED : NPY_FAIL; + } + check_num = NPY_OBJECT; +#if !defined(NPY_PY3K) + if (obj == (PyObject *)(&PyInt_Type)) { + check_num = NPY_LONG; + } + else if (obj == (PyObject *)(&PyLong_Type)) { + check_num = NPY_LONGLONG; + } +#else + if (obj == (PyObject *)(&PyLong_Type)) { + check_num = NPY_LONG; + } +#endif + else if (obj == (PyObject *)(&PyFloat_Type)) { + check_num = NPY_DOUBLE; + } + else if (obj == (PyObject *)(&PyComplex_Type)) { + check_num = NPY_CDOUBLE; + } + else if (obj == (PyObject *)(&PyBool_Type)) { + check_num = NPY_BOOL; + } + else if (obj == (PyObject *)(&PyBytes_Type)) { + check_num = NPY_STRING; + } + else if (obj == (PyObject *)(&PyUnicode_Type)) { + check_num = NPY_UNICODE; + } +#if defined(NPY_PY3K) + else if (obj == (PyObject *)(&PyMemoryView_Type)) { +#else + else if (obj == (PyObject *)(&PyBuffer_Type)) { +#endif + check_num = NPY_VOID; + } + else { + *at = _arraydescr_fromobj(obj); + if (*at) { + return NPY_SUCCEED; + } + } + goto finish; + } + printf("Test3\n"); + + /* or a typecode string */ + + if (PyUnicode_Check(obj)) { + /* Allow unicode format strings: convert to bytes */ + int retval; + PyObject *obj2; + obj2 = PyUnicode_AsASCIIString(obj); + if (obj2 == NULL) { + return NPY_FAIL; + } + retval = PyArray_DescrConverter(obj2, at); + Py_DECREF(obj2); + return retval; + } + + printf("Test4\n"); + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + + /* Check for a string typecode. */ + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + + /* Empty string is invalid */ + if (len == 0) { + goto fail; + } + + /* check for commas present or first (or second) element a digit */ + if (_check_for_commastring(type, len)) { + *at = _convert_from_commastring(obj, 0); + return (*at) ? NPY_SUCCEED : NPY_FAIL; + } + + /* Process the endian character. '|' is replaced by '='*/ + switch (type[0]) { + case '>': + case '<': + case '=': + endian = type[0]; + ++type; + --len; + break; + + case '|': + endian = '='; + ++type; + --len; + break; + } + + /* Just an endian character is invalid */ + if (len == 0) { + goto fail; + } + + /* Check for datetime format */ + if (is_datetime_typestr(type, len)) { + *at = parse_dtype_from_datetime_typestr(type, len); + if (*at == NULL) { + return NPY_FAIL; + } + /* *at has byte order '=' at this point */ + if (!PyArray_ISNBO(endian)) { + (*at)->byteorder = endian; + } + return NPY_SUCCEED; + } + + /* A typecode like 'd' */ + if (len == 1) { + check_num = type[0]; + } + /* A kind + size like 'f8' */ + else { + char *typeend = NULL; + int kind; + + /* Parse the integer, make sure it's the rest of the string */ + elsize = (int)strtol(type + 1, &typeend, 10); + if (typeend - type == len) { + + kind = type[0]; + switch (kind) { + case NPY_STRINGLTR: + case NPY_STRINGLTR2: + check_num = NPY_STRING; + break; + + /* + * When specifying length of UNICODE + * the number of characters is given to match + * the STRING interface. Each character can be + * more than one byte and itemsize must be + * the number of bytes. + */ + case NPY_UNICODELTR: + check_num = NPY_UNICODE; + elsize <<= 2; + break; + + case NPY_VOIDLTR: + check_num = NPY_VOID; + break; + + default: + if (elsize == 0) { + check_num = NPY_NOTYPE+10; + } + /* Support for generic processing c8, i4, f8, etc...*/ + else { + check_num = PyArray_TypestrConvert(elsize, kind); + if (check_num == NPY_NOTYPE) { + check_num += 10; + } + elsize = 0; + } + } + } + } + } + else if (PyTuple_Check(obj)) { + /* or a tuple */ + *at = _convert_from_tuple(obj); + if (*at == NULL){ + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyList_Check(obj)) { + /* or a list */ + *at = _convert_from_array_descr(obj,0); + if (*at == NULL) { + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyDict_Check(obj) || PyDictProxy_Check(obj)) { + /* or a dictionary */ + *at = _convert_from_dict(obj,0); + if (*at == NULL) { + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyArray_Check(obj)) { + goto fail; + } + else { + *at = _arraydescr_fromobj(obj); + if (*at) { + return NPY_SUCCEED; + } + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + if (PyErr_Occurred()) { + goto fail; + } + +finish: + printf("Test5\n"); + if ((check_num == NPY_NOTYPE + 10) || + (*at = PyArray_DescrFromType(check_num)) == NULL) { + PyErr_Clear(); + /* Now check to see if the object is registered in typeDict */ + if (typeDict != NULL) { + item = PyDict_GetItem(typeDict, obj); +#if defined(NPY_PY3K) + if (!item && PyBytes_Check(obj)) { + PyObject *tmp; + tmp = PyUnicode_FromEncodedObject(obj, "ascii", "strict"); + if (tmp != NULL) { + item = PyDict_GetItem(typeDict, tmp); + Py_DECREF(tmp); + } + } +#endif + if (item) { + /* Check for a deprecated Numeric-style typecode */ + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + char *dep_tps[] = {"Bool", "Complex", "Float", "Int", + "Object0", "String0", "Timedelta64", + "Unicode0", "UInt", "Void0"}; + int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]); + int i; + + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + for (i = 0; i < ndep_tps; ++i) { + char *dep_tp = dep_tps[i]; + + if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) { + if (DEPRECATE("Numeric-style type codes are " + "deprecated and will result in " + "an error in the future.") < 0) { + goto fail; + } + } + } + } + return PyArray_DescrConverter(item, at); + } + } + goto fail; + } + + if (((*at)->elsize == 0) && (elsize != 0)) { + PyArray_DESCR_REPLACE(*at); + (*at)->elsize = elsize; + } + if (endian != '=' && PyArray_ISNBO(endian)) { + endian = '='; + } + if (endian != '=' && (*at)->byteorder != '|' + && (*at)->byteorder != endian) { + PyArray_DESCR_REPLACE(*at); + (*at)->byteorder = endian; + } + return NPY_SUCCEED; + +fail: + if (PyBytes_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "data type \"%s\" not understood", PyBytes_AS_STRING(obj)); + } + else { + PyErr_SetString(PyExc_TypeError, + "data type not understood"); + } + +error: + *at = NULL; + return NPY_FAIL; +} +#endif + + +NPY_NO_EXPORT int +MyPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) +{ + int check_num = NPY_NOTYPE + 10; + PyObject *item; + int elsize = 0; + char endian = '='; + + printf("Test -1\n"); + *at = NULL; + + check_num = NPY_VOID; + printf("Test0\n"); + if (check_num != NPY_VOID) { + PyErr_Clear(); + /* Now check to see if the object is registered in typeDict */ + printf("Test1\n"); + if (typeDict != NULL) { + item = PyDict_GetItem(typeDict, obj); +#if defined(NPY_PY3K) + if (!item && PyBytes_Check(obj)) { + PyObject *tmp; + tmp = PyUnicode_FromEncodedObject(obj, "ascii", "strict"); + if (tmp != NULL) { + item = PyDict_GetItem(typeDict, tmp); + Py_DECREF(tmp); + } + } +#endif + if (item) { + /* Check for a deprecated Numeric-style typecode */ + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + char *dep_tps[] = {"Bool", "Complex", "Float", "Int", + "Object0", "String0", "Timedelta64", + "Unicode0", "UInt", "Void0"}; + int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]); + int i; + + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + for (i = 0; i < ndep_tps; ++i) { + char *dep_tp = dep_tps[i]; + + if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) { + if (DEPRECATE("Numeric-style type codes are " + "deprecated and will result in " + "an error in the future.") < 0) { + goto fail; + } + } + } + } + return PyArray_DescrConverter(item, at); + } + } + printf("Test2\n"); + goto fail; + } + + printf("Test3\n"); + if (((*at)->elsize == 0) && (elsize != 0)) { + PyArray_DESCR_REPLACE(*at); + (*at)->elsize = elsize; + printf("Test4\n"); + } + if (endian != '=' && PyArray_ISNBO(endian)) { + endian = '='; + printf("Test5\n"); + } + if (endian != '=' && (*at)->byteorder != '|' + && (*at)->byteorder != endian) { + PyArray_DESCR_REPLACE(*at); + (*at)->byteorder = endian; + printf("Test6\n"); + } + return NPY_SUCCEED; + +fail: + if (PyBytes_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "data type \"%s\" not understood", PyBytes_AS_STRING(obj)); + } + else { + PyErr_SetString(PyExc_TypeError, + "data type not understood"); + } + +error: + *at = NULL; + return NPY_FAIL; +} + + + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict); + +struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(strcmp(dictitem->key, pluginname) == 0){ + return dictitem; + } + dictitem = dictitem->next; + } + return NULL; +} +#endif + +molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no) +{ + molfile_plugin_t* plugin; + if(plug_no < 0){ + plugin = NULL; + } else { + plugin = plug_list[plug_no]; + } + return plugin; +} + +#if 0 +void init_readwriteaccess(struct DICTHOLDER *dict){ + struct DICTHOLDER *dictitem; + dictitem = dict; + // search in dictionary linked list + while(dictitem != NULL){ + if(!dictitem->id){ + if(plugin_list[dictitem->id]->read_next_timestep){ + dictitem->read = 1; + } + if(plugin_list[dictitem->id]->write_timestep){ + dictitem->write = 1; + } + } + dictitem = dictitem->next; + } +} + +static int has_readsupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->read; + } else { + return 0; + } +} + +static int has_writesupport(const char *pluginname){ + struct DICTHOLDER *item; + item = plugin_find(&plugindict, pluginname); + if (!item){ + return item->write; + } else { + return 0; + } +} + +static int plugin_add(struct DICTHOLDER *dict, const char *key, int id){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + dictitem = dict; + while(1){ + // Find the empty next in the list and add item + if(dictitem == NULL){ + struct DICTHOLDER *item = (struct DICTHOLDER*) malloc(sizeof(struct DICTHOLDER)); + item->key = key; + item->id = id; + item->read = NULL; + item->write = NULL; + dictitem = &item; + return 0; + } else { + dictitem = dictitem->next; + } + } + } else { + return 1; + } +} + +static int plugin_remove(struct DICTHOLDER *dict, const char *key){ + struct DICTHOLDER *dictitem; + // Check list is empty or it already has the key + if (plugin_find(dict, key) == NULL){ + // No key in the list. Nothing to remove. + return 1; + } else { + // Remove key in the list + dictitem = dict; + while(dictitem != NULL){ + if(strcmp(dictitem->next->key, key) == 0){ + struct DICTHOLDER *item = dictitem->next->next; + dictitem->next = item; + return 0; + } + dictitem = dictitem->next; + } + return 1; + } +} +#endif +/* * * * * * * * * * * * * * * * * * * * * * * * * * * + * Interface functions to initialize molfile plugins * + * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* check validity of plugins and register them. */ +static int molfile_register(void*, vmdplugin_t *plugin) { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (numplugins >= MAXPLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + //if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + // return VMDPLUGIN_ERROR; + //} else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + //plugin_add(&plugindict, plugin->name, numplugins); + ++numplugins; + return VMDPLUGIN_SUCCESS; + //} +} + +molfile_plugin_t** molfile_plugin_list(int maxsize) +{ + if(maxsize < MAXPLUGINS){ + maxsize = MAXPLUGINS; + } + plugin_list = (molfile_plugin_t**) malloc(sizeof(molfile_plugin_t*)*maxsize); + return plugin_list; +} + +/* register all available plugins and clear handles. */ +int molfile_init(void) +{ +#if 0 + int molfile_internal_register(void *ptr, vmdplugin_t *plugin) + { + if (!plugin->type || !plugin->name || !plugin->author) { + // skipping plugin with incomplete header + return VMDPLUGIN_ERROR; + } + else if (plugin->abiversion != vmdplugin_ABIVERSION) { + // skipping plugin with incompatible ABI + return VMDPLUGIN_ERROR; + } + else if (0 != strncmp(plugin->type, "mol file", 8)) { + // skipping plugin of incompatible type + return VMDPLUGIN_ERROR; + } + else if (num_plugins >= MAX_PLUGINS) { + // too many plugins: increase MAXPLUGINS + return VMDPLUGIN_ERROR; + } + + if (plugin_find(&plugindict, plugin->name) != NULL) { + // multiple plugins for file type + return VMDPLUGIN_ERROR; + } else { + plugin_list[numplugins] = (molfile_plugin_t *) plugin; + ++numplugins; + return VMDPLUGIN_SUCCESS; + } + } +#endif + MOLFILE_INIT_ALL; + MOLFILE_REGISTER_ALL(NULL,molfile_register); + return numplugins; +} + +/* unregister all available plugins */ +int molfile_finish(void) +{ + MOLFILE_FINI_ALL; + return 0; +} + +/* * * * * * * * * * * * * * * * * * * * * * * + * Wrappers to directly access molfile plugin* + * functions and settings * + * * * * * * * * * * * * * * * * * * * * * * */ + +/* molfile_plugin_t access */ + +/* Functions in molfile_plugin_t */ + +PyObject * my_read_structure(PyObject* molpack) { + Py_Initialize(); + import_array(); + + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* atoms; + int numatoms, status; + PyArray_Descr *descr; + PyObject *p = NULL; + //if (PyType_Ready(&MolAtomType) < 0) + // return NULL; + //PyTypeObject *atype = &MolAtomType; + //MolAtom *atom_t; + //atom_t = (MolAtom *)atype->tp_alloc(atype, 0); + //p = (PyObject*) atom_t; + descr = PyArray_DescrFromObject(p, NULL); + MolObject* plugin_handle = (MolObject*) molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + atoms = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + status = plugin->read_structure(file_handle, &options, atoms); + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + PyArrayObject* oresid; + PyObject* array; + int64_t* cresid; + int nd = 1; + npy_intp dims[1] = { numatoms }; + oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); + Py_DECREF(p); + //array = (PyArrayObject*) PyArray_SimpleNewFromDescr(1, dims, descr); + //PyObject_Print(array, stdout, 0); + if (!oresid){ + PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into numpy array."); + return NULL; + } + npy_intp* n = PyArray_DIMS(oresid); + cresid = (int64_t*) PyArray_DATA(oresid); + +// for (i=0;i<numatoms;i++){ +// cresid[i] = (int64_t) atoms[i].resid; +// } + return (PyObject*) PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0); +} + +PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype) +{ + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* data; + int numatoms, status; + int nd; + PyArrayInterface *inter; + //PyArrayObject *ret; + PyObject *ret; + char endian = NPY_NATBYTE; + nd = 1; + npy_intp dims[1] = { 1 }; + PyArrayObject *obj; + printf("Test1\n"); + obj = (PyArrayObject *)prototype; + if(obj == NULL){ + PyErr_Format(PyExc_IOError, "Error: Given PyObject does not include numpy array."); + return NULL; + } + // Access plugin_handle values + MolObject* plugin_handle = (MolObject*) molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + printf("Test2-1\n"); + // Allocate memory for array of molfile_atom_t struct + data = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + // Get array values in molfile_atom_t + printf("Test2-2\n"); + status = plugin->read_structure(file_handle, &options, data); + printf("Test2-3\n"); + // Check if the plugin returns the results + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + printf("Test3\n"); + int *maxndim; + npy_intp *d_shape; + //status = my_get_array_attr_interface((PyObject*)obj, "descr", maxndim, d_shape, ret); + status = my_get_array_attr_interface(prototype, ret); + printf("Test4 Status:%d nd:%d\n",status,*maxndim); + if (status<0){ + Py_DECREF(obj); + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); + return NULL; + } + printf("Test5\n"); + //return (PyObject*) PyArray_FromArray((PyArrayObject*)ret, PyArray_DESCR((PyArrayObject*)ret), 0); + return (PyObject*) ret; +} + +PyObject* get_structure(PyObject* self) +{ + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* data; + int numatoms, status; + int nd; + PyArrayInterface *inter; + PyArrayObject *ret; + char endian = NPY_NATBYTE; + // Access plugin_handle values + MolObject* plugin_handle = (MolObject*) self; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + // Allocate memory for array of molfile_atom_t struct + data = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + // Get array values in molfile_atom_t + status = plugin->read_structure(file_handle, &options, data); + // Check if the plugin returns the results + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + // Now, we need to allocate a PyArray with PyArrayInterface + // and assign the allocated memory block to the data. + // To do this, we will build a numpy array from scratch. + // First, allocate a PyObject of PyArrayInterface and + // assign relevant information such as typestr, descr for C-side + // struct and second we will assign molfile_atom_t array as a block + // of data. Last, hope this works. + nd = 1; + npy_intp dims[1] = { 1 }; + // We would allocate a numpy array with + // but will not look clever to copy all the data into the new array. + // Instead, we allocate a numpy array with one element and change + // the definition of array. I know I said that it will be from scratch + // but let's accept nobody wants to define everything in numpy again. + //oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT); + // NPY_INT? Don't worry, we will change it. + //Py_intptr_t *shape, *strides; + //void *data = NULL; + + inter = (PyArrayInterface*)malloc(sizeof(PyArrayInterface)); + if (inter==NULL) + return PyErr_NoMemory(); + + // __array_interface__ descr for C side of __array_struct__ + // Could not find a better way to generate the list of tuples for + // Python side. May need to change this later. + PyObject *descrlist = PyList_New(13); + // One tuple to bind them + PyObject *py_tuple_name = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_name, 0, PyUnicode_FromString("name")); + PyTuple_SET_ITEM(py_tuple_name, 1, PyUnicode_FromString("|S16")); + PyList_SET_ITEM(descrlist, 0, py_tuple_name); + PyObject *py_tuple_type = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_type, 0, PyUnicode_FromString("type")); + PyTuple_SET_ITEM(py_tuple_type, 1, PyUnicode_FromString("|S16")); + PyList_SET_ITEM(descrlist, 1, py_tuple_type); + PyObject *py_tuple_resname = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_resname, 0, PyUnicode_FromString("resname")); + PyTuple_SET_ITEM(py_tuple_resname, 1, PyUnicode_FromString("|S8")); + PyList_SET_ITEM(descrlist, 2, py_tuple_resname); + PyObject *py_tuple_resid = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_resid, 0, PyUnicode_FromString("resid")); + PyTuple_SET_ITEM(py_tuple_resid, 1, PyUnicode_FromString("<i4")); + PyList_SET_ITEM(descrlist, 3, py_tuple_resid); + PyObject *py_tuple_segid = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_segid, 0, PyUnicode_FromString("segid")); + PyTuple_SET_ITEM(py_tuple_segid, 1, PyUnicode_FromString("|S8")); + PyList_SET_ITEM(descrlist, 4, py_tuple_segid); + PyObject *py_tuple_chain = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_chain, 0, PyUnicode_FromString("chain")); + PyTuple_SET_ITEM(py_tuple_chain, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 5, py_tuple_chain); + PyObject *py_tuple_altloc = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_altloc, 0, PyUnicode_FromString("altloc")); + PyTuple_SET_ITEM(py_tuple_altloc, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 6, py_tuple_altloc); + PyObject *py_tuple_insertion = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_insertion, 0, PyUnicode_FromString("insertion")); + PyTuple_SET_ITEM(py_tuple_insertion, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 7, py_tuple_insertion); + PyObject *py_tuple_occupancy = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_occupancy, 0, PyUnicode_FromString("occupancy")); + PyTuple_SET_ITEM(py_tuple_occupancy, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 8, py_tuple_occupancy); + PyObject *py_tuple_bfactor = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_bfactor, 0, PyUnicode_FromString("bfactor")); + PyTuple_SET_ITEM(py_tuple_bfactor, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 9, py_tuple_bfactor); + PyObject *py_tuple_mass = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_mass, 0, PyUnicode_FromString("mass")); + PyTuple_SET_ITEM(py_tuple_mass, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 10, py_tuple_mass); + PyObject *py_tuple_charge = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_charge, 0, PyUnicode_FromString("charge")); + PyTuple_SET_ITEM(py_tuple_charge, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 11, py_tuple_charge); + PyObject *py_tuple_radius = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_radius, 0, PyUnicode_FromString("radius")); + PyTuple_SET_ITEM(py_tuple_radius, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 12, py_tuple_radius); + PyObject *py_tuple_atomicnumber = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_atomicnumber, 0, PyUnicode_FromString("atomicnumber")); + PyTuple_SET_ITEM(py_tuple_atomicnumber, 1, PyUnicode_FromString("<i4")); + PyList_SET_ITEM(descrlist, 13, py_tuple_atomicnumber); + //PyArray_Descr *descr = (PyObject*) tuple; + PyArray_Descr *thetype = NULL; + // Here we define the size and stride parameters + npy_intp shape[1] = { numatoms }; + npy_intp strides[1] = { 54*sizeof(char) + 8*sizeof(int) + 20*sizeof(float) }; + + inter->two = 2; + inter->nd = nd; + inter->typekind = 'V'; + inter->itemsize = 82*sizeof(char); + //inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE; + inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE | NPY_ARR_HAS_DESCR; + inter->strides = (Py_intptr_t *)strides; + inter->shape = (Py_intptr_t *)shape; + inter->data = (void*) data; + // inter->descr = (PyObject*) tuple; + if ((inter->flags & NPY_ARRAY_NOTSWAPPED) != NPY_ARRAY_NOTSWAPPED) { + endian = NPY_OPPBYTE; + inter->flags &= ~NPY_ARRAY_NOTSWAPPED; + } + // typestr is relatively easy to assign to __array_interface__ + printf("TEST1\n"); + //thetype = (PyArray_Descr*) tuple; + if (inter->flags & NPY_ARR_HAS_DESCR) { + printf("TEST1-1\n"); + thetype = _convert_from_array_descr(descrlist,0); + //thetype = PyArray_DescrFromTypeObject(descrlist); + printf("TEST1-2\n"); + //if (PyArray_DescrConverter(inter->descr, &thetype) == NPY_FAIL) { + // thetype = NULL; + // PyErr_Clear(); + // } + } + printf("TEST1-3\n"); +#if 0 + char buf[40]; + PyOS_snprintf(buf, sizeof(buf), + "%c%c%d", endian, + inter->typekind, + inter->itemsize); + printf("TEST2 String:%s\n",buf); + PyObject *stringobj = PyUnicode_FromString(buf); + if (stringobj == NULL) { + return NULL; + } + printf("TEST2-2\n"); + if (MyPyArray_DescrConverter(stringobj, &thetype) != NPY_SUCCEED) { + Py_DECREF(stringobj); + return NULL; + } + printf("TEST2-3\n"); + Py_DECREF(stringobj); +#endif + printf("TEST3\n"); + ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, thetype, + inter->nd, inter->shape, + inter->strides, inter->data, + inter->flags, NULL); + printf("TEST4\n"); + Py_INCREF(inter); + if (PyArray_SetBaseObject(ret, (PyObject *)inter) < 0) { + Py_DECREF(ret); + return NULL; + } + printf("TEST5\n"); +// Py_DECREF(attr); + PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL); + printf("TEST6\n"); + return (PyObject *)ret; +} +// obj = NpyCapsule_FromVoidPtrAndDesc(inter, self, gentype_struct_free); +/* +#ifdef Py_CAPSULE_H + obj = PyCapsule_New((void*)inter, "struct SignedIntBuf", free_capsule); +#else + obj = PyCObject_FromVoidPtrAndDesc((void*)inter, (void*)self, free_array_interface); +#endif +*/ + // Cross fingers here. +// return obj; + diff --git a/pymolfile/molfile/pymolfile-new.h b/pymolfile/molfile/pymolfile-new.h new file mode 100644 index 0000000000000000000000000000000000000000..5bf304ee461b11bb8d04b3d03caad856252fb4a6 --- /dev/null +++ b/pymolfile/molfile/pymolfile-new.h @@ -0,0 +1,356 @@ +/* Hey emacs this is -*- C -*- and this is my editor vim. + * + * molfile.c : C and Fortran interfaces for molfile_plugins + * Copyright (c) Berk Onat <b.onat@warwick.ac.uk> 2017 + * + * This program is under BSD LICENSE + */ + +/* + * The code is written following the plugin test + * context of f77_molfile.c by Axel Kohlmeyer and + * in molfile_plugin/src/f77 and catdcd.c by + * Justin Gullingsrud of VMD plugins. + */ + +#ifndef _MOLFILE_H_ +#define _MOLFILE_H_ + +#ifdef __cplusplus +extern "C" +{ + +#endif + +#include "molfile_plugin.h" +#include "libmolfile_plugin.h" +#include "vmdplugin.h" +#include "Python.h" +#include "structmember.h" +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + + +enum { pluginOK, pluginNOINIT, pluginCLOSE, pluginNOMEM, + pluginENDOFFILE, pluginFILENOTFOUND, pluginFORMATERROR }; + +#ifndef MAXPLUGINS +#define MAXPLUGINS 200 +#endif + +struct MolObject { + PyObject_HEAD + molfile_plugin_t* plugin; + void* file_handle; + int natoms; + MolObject(void) {} +}; + +static void MolObject_dealloc(MolObject* self) +{ + Py_XDECREF(self->plugin); + Py_XDECREF(self->file_handle); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject * MolObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + MolObject *self; + + self = (MolObject *)type->tp_alloc(type, 0); + if (self != NULL) { + self->plugin = NULL; + self->file_handle = NULL; + self->natoms = 0; + } + + return (PyObject *)self; +} + +static int MolObject_init(MolObject *self, PyObject *args, PyObject *kwds) +{ + molfile_plugin_t *plugin = NULL; + void *file_handle = NULL; + molfile_plugin_t *tmp1 = NULL; + void *tmp2 = NULL; + + static char *kwlist[] = {"plugin", "file_handle", "natoms", NULL}; + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, + &plugin, &file_handle, + &self->natoms)) + return -1; + + if (plugin) { + tmp1 = self->plugin; + Py_INCREF(plugin); + self->plugin = plugin; + Py_XDECREF(tmp1); + } + + if (file_handle) { + tmp2 = self->file_handle; + Py_INCREF(file_handle); + self->file_handle = file_handle; + Py_XDECREF(tmp2); + } + + return 0; +} + +static molfile_plugin_t* MolObject_plugin(MolObject* self) +{ + return self->plugin; +} + +static void* MolObject_file_handle(MolObject* self) +{ + return self->file_handle; +} + +static PyObject* MolObject_natoms(MolObject* self) +{ + return PyLong_FromLong((long)self->natoms); +} + +static PyMemberDef MolObject_members[] = { + {"plugin", T_OBJECT_EX, offsetof(MolObject, plugin), 0, + "molfile_plugin_t type plugin"}, + {"file_handle", T_OBJECT_EX, offsetof(MolObject, file_handle), 0, + "file handle for plugin"}, + {"natoms", T_INT, offsetof(MolObject, natoms), 0, + "number of atoms"}, + {NULL} /* Sentinel */ +}; + +static PyMethodDef MolObject_methods[] = { + {"get_plugin", (PyCFunction)MolObject_plugin, METH_NOARGS, + "Return the plugin" + }, + {"get_file_handle", (PyCFunction)MolObject_file_handle, METH_NOARGS, + "Return the plugin" + }, + {"get_natoms", (PyCFunction)MolObject_natoms, METH_NOARGS, + "Return the number of atoms" + }, + {NULL} /* Sentinel */ +}; + + +#ifndef PyVarObject_HEAD_INIT + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#endif + +static PyTypeObject MolObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "molobject", /*tp_name*/ + sizeof(MolObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)MolObject_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_reserved*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "molobject objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + MolObject_methods, /* tp_methods */ + MolObject_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)MolObject_init, /* tp_init */ + 0, /* tp_alloc */ + MolObject_new, /* tp_new */ +}; + +#if 0 +struct MolAtom { + PyObject_HEAD + char* name; + char* type; + char* resname; + int* resid; + char* segid; + char* chain; + char* altloc; + char* insertion; + float* occupancy; + float* bfactor; + float* mass; + float* charge; + float* radius; + float* atomicnumber; + float* ctnumber; + MolAtom(void) {} +}; + +static void MolAtom_dealloc(MolAtom* self) +{ + Py_XDECREF(self->name); + Py_XDECREF(self->type); + Py_XDECREF(self->resname); + Py_XDECREF(self->resid); + Py_XDECREF(self->segid); + Py_XDECREF(self->chain); + Py_XDECREF(self->altloc); + Py_XDECREF(self->insertion); + Py_XDECREF(self->occupancy); + Py_XDECREF(self->bfactor); + Py_XDECREF(self->mass); + Py_XDECREF(self->charge); + Py_XDECREF(self->radius); + Py_XDECREF(self->atomicnumber); + Py_XDECREF(self->ctnumber); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject * MolAtom_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + MolAtom *self; + + self = (MolAtom *)type->tp_alloc(type, 0); + if (self != NULL) { + self->name = NULL; + self->type = NULL; + self->resname = NULL; + self->resid = NULL; + self->segid = NULL; + self->chain = NULL; + self->altloc = NULL; + self->insertion = NULL; + self->occupancy = NULL; + self->bfactor = NULL; + self->mass = NULL; + self->charge = NULL; + self->radius = NULL; + self->atomicnumber = NULL; + self->ctnumber = NULL; + } + + return (PyObject *)self; +} + +static PyMemberDef MolAtom_members[] = { + {"name", T_STRING, offsetof(MolAtom, name), 0,""}, + {"type", T_STRING, offsetof(MolAtom, type), 0,""}, + {"resname", T_STRING, offsetof(MolAtom, resname), 0,""}, + {"resid", T_INT, offsetof(MolAtom, resid), 0,""}, + {"segid", T_STRING, offsetof(MolAtom, segid), 0,""}, + {"chain", T_STRING, offsetof(MolAtom, chain), 0,""}, + {"altloc", T_STRING, offsetof(MolAtom, altloc), 0,""}, + {"insertion", T_STRING, offsetof(MolAtom, insertion), 0,""}, + {"occupancy", T_FLOAT, offsetof(MolAtom, occupancy), 0,""}, + {"bfactor", T_FLOAT, offsetof(MolAtom, bfactor), 0,""}, + {"mass", T_FLOAT, offsetof(MolAtom, mass), 0,""}, + {"charge", T_FLOAT, offsetof(MolAtom, charge), 0,""}, + {"radius", T_FLOAT, offsetof(MolAtom, radius), 0,""}, + {"atomicnumber", T_INT, offsetof(MolAtom, atomicnumber), 0,""}, + {"ctnumber", T_INT, offsetof(MolAtom, ctnumber), 0,""}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static PyTypeObject MolAtomType = { + PyVarObject_HEAD_INIT(NULL, 0) + "molobject", /*tp_name*/ + sizeof(MolAtom), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)MolAtom_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_reserved*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "molatom objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + MolAtom_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + MolAtom_new, /* tp_new */ +}; +#endif +PyObject * my_read_structure(PyObject* molpack); +PyObject * read_fill_structure(PyObject* molpack, PyObject* prototype); +PyObject * get_structure(PyObject* molpack); + +#if 0 +typedef struct DICTHOLDER { + const char *key; // Dictionary key + int id; // Id of the item + int read; // 1 if molfile plugin read the format + int write; // 1 if molfile plugin write in this format + struct DICTHOLDER *next; // Next item in the dictionary +} DICTHOLDER; + +struct DICTHOLDER * plugin_find(struct DICTHOLDER *dict, const char *pluginname); + +static int plugin_add(struct DICTHOLDER *dict, const char *key, int id); + +static int plugin_remove(struct DICTHOLDER *dict, const char *key); + +static int has_readsupport(const char *pluginname); + +static int has_writesupport(const char *pluginname); + +static molfile_plugin_t *get_plugin(const char *pluginname); + +static int molfile_register(void *ptr, vmdplugin_t *plugin); + +#endif +molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no); + +molfile_plugin_t** molfile_plugin_list(int maxsize); + +int molfile_init(void); + +int molfile_finish(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _MOLFILE_H_ */ + diff --git a/pymolfile/molfile/pymolfile.c b/pymolfile/molfile/pymolfile.c index b3033e97440a13dc50ef4c006f9ebb4ecdb35fe4..1b813044c1b4d938eec536e5617cc721a1bc22df 100644 --- a/pymolfile/molfile/pymolfile.c +++ b/pymolfile/molfile/pymolfile.c @@ -33,15 +33,1099 @@ #include "pymolfile.h" -int numplugins=0; -molfile_plugin_t** plugin_list; - +//for PyArrayInterface: +/* +#define CONTIGUOUS 0x01 +#define FORTRAN 0x02 +#define ALIGNED 0x100 +#define NOTSWAPPED 0x200 +#define WRITEABLE 0x400 +#define ARR_HAS_DESCR 0x800 +*/ +//byteorder dictionary +//char** byteorder = {"<", "little", ">", "big"}; +int numplugins=0; +molfile_plugin_t** plugin_list; +/* +typedef struct PyArrayInterface{ + int version; //contains the integer 2 as a sanity check + int nd; //number of dimensions + char typekind; //kind in array --- character code of typestr + int itemsize; //size of each element + int flags; //flags indicating how the data should be interpreted + Py_intptr_t *shape; //A length-nd array of shape information + Py_intptr_t *strides; //A length-nd array of stride information + void *data; //A pointer to the first element of the array +}; +*/ /* * * * * * * * * * * * * * * * * * * * * * * * Helper functions to set and store plugins * * * * * * * * * * * * * * * * * * * * * * * */ + + +#if PY_VERSION_HEX >= 0x03000000 +#define PyInt_AsSsize_t PyLong_AsSsize_t +#define PyInt_AsLong PyLong_AsLong +#define PyArray_Check(op) PyObject_TypeCheck(op, &PyArray_Type) +#define PyString_FromString PyBytes_FromString +#define PyUString_Check PyUnicode_Check +#define PyUString_GET_SIZE PyUnicode_GET_SIZE +#define PyUString_FromFormat PyUnicode_FromFormat +#define PyInt_FromLong PyLong_FromLong +#define PyString_Type PyBytes_Type +#define PyInt_Type PyLong_Type + +NPY_NO_EXPORT void +gentype_struct_free(PyObject *ptr) +{ + PyArrayInterface *arrif; + PyObject *context; + + arrif = (PyArrayInterface*)PyCapsule_GetPointer(ptr, NULL); + context = (PyObject *)PyCapsule_GetContext(ptr); + Py_DECREF(context); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +static NPY_INLINE void * +NpyCapsule_AsVoidPtr(PyObject *obj) +{ + void *ret = PyCapsule_GetPointer(obj, NULL); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *)) +{ + PyObject *ret = PyCapsule_New(ptr, NULL, dtor); + if (ret == NULL) { + PyErr_Clear(); + } + return ret; +} +static NPY_INLINE PyObject * +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *)) +{ + PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor); + if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) { + PyErr_Clear(); + Py_DECREF(ret); + ret = NULL; + } + return ret; +} +#else +#define PyBytes_FromString PyString_FromString +NPY_NO_EXPORT void +gentype_struct_free(void *ptr, void *arg) +{ + PyArrayInterface *arrif = (PyArrayInterface *)ptr; + Py_DECREF((PyObject *)arg); + Py_XDECREF(arrif->descr); + PyArray_free(arrif->shape); + PyArray_free(arrif); +} +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) +{ + return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); +} +#endif +static PyObject *typeDict = NULL; /* Must be explicitly loaded */ + + +#define NPY_NEXT_ALIGNED_OFFSET(offset, alignment) \ + (((offset) + (alignment) - 1) & (-(alignment))) + +static PyArray_Descr * +_convert_from_array_descr(PyObject *obj, int align) +{ + int n, i, totalsize; + int ret; + PyObject *fields, *item, *newobj; + PyObject *name, *tup, *title; + PyObject *nameslist; + PyArray_Descr *newea; + PyArray_Descr *conv; + /* Types with fields need the Python C API for field access */ + char dtypeflags = NPY_NEEDS_PYAPI; + int maxalign = 0; + + printf("Test1\n"); + n = PyList_GET_SIZE(obj); + nameslist = PyTuple_New(n); + if (!nameslist) { + return NULL; + } + totalsize = 0; + fields = PyDict_New(); + for (i = 0; i < n; i++) { + item = PyList_GET_ITEM(obj, i); + if (!PyTuple_Check(item) || (PyTuple_GET_SIZE(item) < 2)) { + goto fail; + } + name = PyTuple_GET_ITEM(item, 0); + if (PyUString_Check(name)) { + title = NULL; + } + else if (PyTuple_Check(name)) { + if (PyTuple_GET_SIZE(name) != 2) { + goto fail; + } + title = PyTuple_GET_ITEM(name, 0); + name = PyTuple_GET_ITEM(name, 1); + if (!PyUString_Check(name)) { + goto fail; + } + } + else { + goto fail; + } + + /* Insert name into nameslist */ + Py_INCREF(name); + + if (PyUString_GET_SIZE(name) == 0) { + Py_DECREF(name); + if (title == NULL) { + name = PyUString_FromFormat("f%d", i); + } +#if PY_VERSION_HEX >= 0x03000000 + /* On Py3, allow only non-empty Unicode strings as field names */ + else if (PyUString_Check(title) && PyUString_GET_SIZE(title) > 0) { + name = title; + Py_INCREF(name); + } + else { + goto fail; + } +#else + else { + name = title; + Py_INCREF(name); + } +#endif + } + PyTuple_SET_ITEM(nameslist, i, name); + + /* Process rest */ + + printf("Test2\n"); + if (PyTuple_GET_SIZE(item) == 2) { + if (align) { + printf("Test3\n"); + ret = PyArray_DescrAlignConverter(PyTuple_GET_ITEM(item, 1), + &conv); + } + else { + printf("Test4\n"); + ret = PyArray_DescrConverter(PyTuple_GET_ITEM(item, 1), &conv); + } + if (ret == NPY_FAIL) { + PyObject_Print(PyTuple_GET_ITEM(item, 1), stderr, 0); + } + } + else if (PyTuple_GET_SIZE(item) == 3) { + newobj = PyTuple_GetSlice(item, 1, 3); + if (align) { + printf("Test5\n"); + ret = PyArray_DescrAlignConverter(newobj, &conv); + } + else { + printf("Test6\n"); + ret = PyArray_DescrConverter(newobj, &conv); + } + Py_DECREF(newobj); + } + else { + goto fail; + } + if (ret == NPY_FAIL) { + goto fail; + } + if ((PyDict_GetItem(fields, name) != NULL) + || (title +#if PY_VERSION_HEX >= 0x03000000 + && PyUString_Check(title) +#else + && (PyUString_Check(title) || PyUnicode_Check(title)) +#endif + && (PyDict_GetItem(fields, title) != NULL))) { +#if PY_VERSION_HEX >= 0x03000000 + name = PyUnicode_AsUTF8String(name); +#endif + PyErr_Format(PyExc_ValueError, + "field '%s' occurs more than once", PyBytes_AsString(name)); +#if PY_VERSION_HEX >= 0x03000000 + Py_DECREF(name); +#endif + goto fail; + } + dtypeflags |= (conv->flags & NPY_FROM_FIELDS); + if (align) { + int _align; + + _align = conv->alignment; + if (_align > 1) { + totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, _align); + } + maxalign = PyArray_MAX(maxalign, _align); + } + tup = PyTuple_New((title == NULL ? 2 : 3)); + PyTuple_SET_ITEM(tup, 0, (PyObject *)conv); + PyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize)); + + /* + * Title can be "meta-data". Only insert it + * into the fields dictionary if it is a string + * and if it is not the same as the name. + */ + if (title != NULL) { + Py_INCREF(title); + PyTuple_SET_ITEM(tup, 2, title); + PyDict_SetItem(fields, name, tup); +#if PY_VERSION_HEX >= 0x03000000 + if (PyUString_Check(title)) { +#else + if (PyUString_Check(title) || PyUnicode_Check(title)) { +#endif + if (PyDict_GetItem(fields, title) != NULL) { + PyErr_SetString(PyExc_ValueError, + "title already used as a name or title."); + Py_DECREF(tup); + goto fail; + } + PyDict_SetItem(fields, title, tup); + } + } + else { + PyDict_SetItem(fields, name, tup); + } + + totalsize += conv->elsize; + Py_DECREF(tup); + } + + if (maxalign > 1) { + totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, maxalign); + } + + newea = PyArray_DescrNewFromType(NPY_VOID); + if (newea == NULL) { + Py_XDECREF(fields); + Py_XDECREF(nameslist); + return NULL; + } + newea->fields = fields; + newea->names = nameslist; + newea->elsize = totalsize; + newea->flags = dtypeflags; + + /* Structured arrays get a sticky aligned bit */ + if (align) { + newea->flags |= NPY_ALIGNED_STRUCT; + newea->alignment = maxalign; + } + return newea; + + fail: + Py_DECREF(fields); + Py_DECREF(nameslist); + return NULL; + +} + +static NPY_INLINE npy_bool +_is_basic_python_type(PyTypeObject *tp) +{ + return ( + /* Basic number types */ + tp == &PyBool_Type || +#if PY_VERSION_HEX >= 0x03000000 + tp == &PyInt_Type || +#endif + tp == &PyLong_Type || + tp == &PyFloat_Type || + tp == &PyComplex_Type || + + /* Basic sequence types */ + tp == &PyList_Type || + tp == &PyTuple_Type || + tp == &PyDict_Type || + tp == &PySet_Type || + tp == &PyFrozenSet_Type || + tp == &PyUnicode_Type || + tp == &PyBytes_Type || +#if PY_VERSION_HEX >= 0x03000000 + tp == &PyString_Type || +#endif + + /* other builtins */ + tp == &PySlice_Type || + tp == Py_TYPE(Py_None) || + tp == Py_TYPE(Py_Ellipsis) || + tp == Py_TYPE(Py_NotImplemented) || + + /* TODO: ndarray, but we can't see PyArray_Type here */ + + /* sentinel to swallow trailing || */ + NPY_FALSE + ); +} + +static NPY_INLINE PyObject * +maybe_get_attr(PyObject *obj, char *name) +{ + PyTypeObject *tp = Py_TYPE(obj); + PyObject *res = (PyObject *)NULL; + + /* Attribute referenced by (char *)name */ + if (tp->tp_getattr != NULL) { + res = (*tp->tp_getattr)(obj, name); + if (res == NULL) { + PyErr_Clear(); + } + } + /* Attribute referenced by (PyObject *)name */ + else if (tp->tp_getattro != NULL) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *w = PyUnicode_InternFromString(name); +#else + PyObject *w = PyString_InternFromString(name); +#endif + if (w == NULL) { + return (PyObject *)NULL; + } + res = (*tp->tp_getattro)(obj, w); + Py_DECREF(w); + if (res == NULL) { + PyErr_Clear(); + } + } + return res; +} + +static NPY_INLINE PyObject * +maybe_set_attr(PyObject *obj, char *name, PyObject *attr) +{ + PyTypeObject *tp = Py_TYPE(obj); + int status; + + /* Attribute referenced by (char *)name */ + if (tp->tp_setattr != NULL) { + printf("tp_setattr not null\n"); + status = (*tp->tp_setattr)(obj, name, attr); + if (status < 0) { + printf("No tp_setattr\n"); + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: no __array_interface__ attribute in object."); + return NULL; + } + } + /* Attribute referenced by (PyObject *)name */ + else if (tp->tp_setattro != NULL) { + printf("tp_setattr null but tp_setattro is not null\n"); +#if PY_VERSION_HEX >= 0x03000000 + PyObject *w = PyUnicode_InternFromString(name); + printf("PyUnicode_InternFromString name\n"); +#else + PyObject *w = PyString_InternFromString(name); + printf("PyString_InternFromString name\n"); +#endif + if (w == NULL) { + printf("Name is NULL\n"); + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: no __array_interface__ attribute in object."); + return NULL; + } + //status = (*tp->tp_setattro)(obj, w, attr); + //status = PyObject_GenericSetAttr(obj, w, attr); + status = PyObject_SetAttrString(obj, name, attr); + if (status < 0) { + printf("can not use tp_setattro status:%d\n", status); + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not set interface attribute."); + return NULL; + } + } + return obj; +} + +static int get_array_struct(PyObject* obj, int *maxndim, npy_intp *d_shape, PyArrayInterface* inter) +{ + PyTypeObject *tp = Py_TYPE(obj); + PyObject* ret; + char* str; + int i; + str = "__array_struct__"; + /* We do not need to check for special attributes on trivial types */ + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_struct__ interface */ + ret = maybe_get_attr(obj, str); + if (ret != NULL) { + int nd = -1; + if (PyCapsule_CheckExact(ret)) { + PyArrayInterface *inter; + inter = (PyArrayInterface *)NpyCapsule_AsVoidPtr(ret); + if (inter->two == 2) { + nd = inter->nd; + if (nd >= 0) { + if (nd < *maxndim) { + *maxndim = nd; + } + for (i=0; i<*maxndim; i++) { + d_shape[i] = inter->shape[i]; + } + } + } + } + if(nd >= 0){ + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + +PyObject* my_get_array_attr_interface(PyObject* obj){ + printf("Check-in my_get_array_attr_interface\n"); + printf("Check-out my_get_array_attr_interface\n"); + return obj; +} + +PyObject* get_array_attr_interface(PyObject* obj, char* str, int *maxndim, npy_intp *d_shape){ + PyTypeObject *tp = Py_TYPE(obj); + char* dictstr; + int i, failflag=0; + dictstr = "__array_interface__"; + PyObject* ret; + PyObject* retuni = NULL; + PyObject* newi = NULL; + PyObject* objj = NULL; + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_interface__ interface */ + ret = maybe_get_attr(obj, dictstr); + if (ret != NULL) { + int nd = -1; + if (PyDict_Check(ret)) { + printf("I- %s\n",str); + objj = PyDict_GetItemString(ret, str); + printf("O- %s\n",str); + //newi = PyDict_GetItemString(ret, str); + if (str == "shape"){ + if (objj && PyTuple_Check(objj)) { + nd = PyTuple_GET_SIZE(objj); + if (nd >= 0) { + maxndim = &nd; + printf("nd:%d\n",*maxndim); + for (i=0; i<nd; i++) { + //Py_INCREF(objj); + retuni = PyTuple_GET_ITEM(objj, i); + printf("step:%d\n",i); + //d_shape[i] = (npy_intp) PyInt_AsSsize_t(retuni); + //d_shape[i] = PyInt_AsSsize_t(PyTuple_GET_ITEM(objj, i)); + //Py_DECREF(objj); + printf("T- %d\n",i); + //if (d_shape[i] < 0) { + // PyErr_SetString(PyExc_RuntimeError, + // "Invalid shape in __array_interface__"); + // failflag = 1; + //} + } + } + } + } else { + printf("T5\n"); + PyObject* tuple = PyTuple_New(1); + PyTuple_SET_ITEM(tuple, 0, objj); + printf("T6\n"); + return (PyObject*) tuple; + } + } + if (nd >= 0) { + printf("T5\n"); + //newi = (PyArrayObject*) objj; + PyObject* tuple = PyTuple_New(1); + PyTuple_SET_ITEM(tuple, 0, objj); + printf("T6\n"); + return (PyObject*) tuple; + } else { + failflag = 1; + } + } else { + failflag = 1; + } + if (failflag){ + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); + return NULL; + } +} + +PyObject* get_descr_array_interface(PyObject* obj){ + PyTypeObject *tp = Py_TYPE(obj); + char* dictstr; + char* descrstr; + int i, failflag=0; + dictstr = "__array_interface__"; + descrstr = "descr"; + PyObject* ret; + PyObject* retuni = NULL; + PyObject* newi = NULL; + PyObject* objj = NULL; + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_interface__ interface */ + ret = maybe_get_attr(obj, dictstr); + if (ret != NULL) { + if (PyDict_Check(ret)) { + objj = PyDict_GetItemString(ret, descrstr); + return (PyObject*) objj; + } else { + failflag = 1; + } + } else { + failflag = 1; + } + if (failflag){ + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); + return NULL; + } +} + +PyObject* set_array_attr_interface(PyObject* obj, int nsize, void* data) +{ + PyTypeObject *tp = Py_TYPE(obj); + char* dictstr; + char* shapestr; + char* datastr; + int i, failflag=0; + dictstr = "__array_interface__"; + shapestr= "shape"; + datastr= "data"; + PyObject* ret; + //PyObject* retuni = NULL; + //PyObject* newi = NULL; + PyObject* shapeobj = NULL; + PyObject* dataobj = NULL; + PyObject* new_shape = NULL; + int status; + if (_is_basic_python_type(tp)) { + ret = NULL; + } + /* obj has the __array_interface__ interface */ + ret = maybe_get_attr(obj, dictstr); + printf("AA0\n"); + if (ret != NULL) { + int nd = -1; + if (PyDict_Check(ret)) { + shapeobj = PyDict_GetItemString(ret, shapestr); + printf("AA1\n"); + if (shapeobj && PyTuple_Check(shapeobj)) { + nd = PyTuple_GET_SIZE(shapeobj); + printf("AA1-1\n"); + if (nd >= 0) { + new_shape = PyTuple_New(nd); + for (i=0; i<nd; i++) { + PyTuple_SET_ITEM(new_shape, i, PyInt_FromLong((int)nsize)); + } + status = PyDict_SetItemString(ret, shapestr, new_shape); + if (status<0){ + printf("AA1-2\n"); + Py_DECREF(new_shape); + PyErr_Clear(); + failflag = 1; + } + } else { + printf("AA1-3\n"); + failflag = 1; + } + } + printf("AA2\n"); + if(!failflag){ + dataobj = PyDict_GetItemString(ret, datastr); + printf("AA2-1\n"); + if (dataobj && PyTuple_Check(dataobj)) { + PyTuple_SET_ITEM(dataobj, 0, PyLong_FromVoidPtr(data)); + status = PyDict_SetItemString(ret, datastr, dataobj); + if (status<0){ + printf("AA2-2\n"); + failflag = 1; + } + } + } + printf("AA3\n"); + if(!failflag){ + printf("AA3-1\n"); + obj = maybe_set_attr(obj, dictstr, ret); + if (!obj){ + printf("AA3-2\n"); + failflag = 1; + } + } + printf("AA4\n"); + } else { + printf("AA1-0\n"); + failflag = 1; + } + } else { + printf("AA0-1\n"); + failflag = 1; + } + if (failflag){ + Py_DECREF(new_shape); + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); + printf("AA Fail\n"); + return NULL; + } else { + printf("AA Return\n"); + return obj; + } +} + + +#if 0 +NPY_NO_EXPORT int +MyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) +{ + int check_num = NPY_NOTYPE + 10; + PyObject *item; + int elsize = 0; + char endian = '='; + + *at = NULL; + + printf("Test0\n"); + /* default */ + if (obj == Py_None) { + *at = PyArray_DescrFromType(NPY_DEFAULT_TYPE); + return NPY_SUCCEED; + } + + printf("Test1\n"); + if (PyArray_DescrCheck(obj)) { + *at = (PyArray_Descr *)obj; + Py_INCREF(*at); + return NPY_SUCCEED; + } + + printf("Test2\n"); + if (PyType_Check(obj)) { + if (PyType_IsSubtype((PyTypeObject *)obj, &PyGenericArrType_Type)) { + *at = PyArray_DescrFromTypeObject(obj); + return (*at) ? NPY_SUCCEED : NPY_FAIL; + } + check_num = NPY_OBJECT; +#if !defined(NPY_PY3K) + if (obj == (PyObject *)(&PyInt_Type)) { + check_num = NPY_LONG; + } + else if (obj == (PyObject *)(&PyLong_Type)) { + check_num = NPY_LONGLONG; + } +#else + if (obj == (PyObject *)(&PyLong_Type)) { + check_num = NPY_LONG; + } +#endif + else if (obj == (PyObject *)(&PyFloat_Type)) { + check_num = NPY_DOUBLE; + } + else if (obj == (PyObject *)(&PyComplex_Type)) { + check_num = NPY_CDOUBLE; + } + else if (obj == (PyObject *)(&PyBool_Type)) { + check_num = NPY_BOOL; + } + else if (obj == (PyObject *)(&PyBytes_Type)) { + check_num = NPY_STRING; + } + else if (obj == (PyObject *)(&PyUnicode_Type)) { + check_num = NPY_UNICODE; + } +#if defined(NPY_PY3K) + else if (obj == (PyObject *)(&PyMemoryView_Type)) { +#else + else if (obj == (PyObject *)(&PyBuffer_Type)) { +#endif + check_num = NPY_VOID; + } + else { + *at = _arraydescr_fromobj(obj); + if (*at) { + return NPY_SUCCEED; + } + } + goto finish; + } + printf("Test3\n"); + + /* or a typecode string */ + + if (PyUnicode_Check(obj)) { + /* Allow unicode format strings: convert to bytes */ + int retval; + PyObject *obj2; + obj2 = PyUnicode_AsASCIIString(obj); + if (obj2 == NULL) { + return NPY_FAIL; + } + retval = PyArray_DescrConverter(obj2, at); + Py_DECREF(obj2); + return retval; + } + + printf("Test4\n"); + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + + /* Check for a string typecode. */ + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + + /* Empty string is invalid */ + if (len == 0) { + goto fail; + } + + /* check for commas present or first (or second) element a digit */ + if (_check_for_commastring(type, len)) { + *at = _convert_from_commastring(obj, 0); + return (*at) ? NPY_SUCCEED : NPY_FAIL; + } + + /* Process the endian character. '|' is replaced by '='*/ + switch (type[0]) { + case '>': + case '<': + case '=': + endian = type[0]; + ++type; + --len; + break; + + case '|': + endian = '='; + ++type; + --len; + break; + } + + /* Just an endian character is invalid */ + if (len == 0) { + goto fail; + } + + /* Check for datetime format */ + if (is_datetime_typestr(type, len)) { + *at = parse_dtype_from_datetime_typestr(type, len); + if (*at == NULL) { + return NPY_FAIL; + } + /* *at has byte order '=' at this point */ + if (!PyArray_ISNBO(endian)) { + (*at)->byteorder = endian; + } + return NPY_SUCCEED; + } + + /* A typecode like 'd' */ + if (len == 1) { + check_num = type[0]; + } + /* A kind + size like 'f8' */ + else { + char *typeend = NULL; + int kind; + + /* Parse the integer, make sure it's the rest of the string */ + elsize = (int)strtol(type + 1, &typeend, 10); + if (typeend - type == len) { + + kind = type[0]; + switch (kind) { + case NPY_STRINGLTR: + case NPY_STRINGLTR2: + check_num = NPY_STRING; + break; + + /* + * When specifying length of UNICODE + * the number of characters is given to match + * the STRING interface. Each character can be + * more than one byte and itemsize must be + * the number of bytes. + */ + case NPY_UNICODELTR: + check_num = NPY_UNICODE; + elsize <<= 2; + break; + + case NPY_VOIDLTR: + check_num = NPY_VOID; + break; + + default: + if (elsize == 0) { + check_num = NPY_NOTYPE+10; + } + /* Support for generic processing c8, i4, f8, etc...*/ + else { + check_num = PyArray_TypestrConvert(elsize, kind); + if (check_num == NPY_NOTYPE) { + check_num += 10; + } + elsize = 0; + } + } + } + } + } + else if (PyTuple_Check(obj)) { + /* or a tuple */ + *at = _convert_from_tuple(obj); + if (*at == NULL){ + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyList_Check(obj)) { + /* or a list */ + *at = _convert_from_array_descr(obj,0); + if (*at == NULL) { + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyDict_Check(obj) || PyDictProxy_Check(obj)) { + /* or a dictionary */ + *at = _convert_from_dict(obj,0); + if (*at == NULL) { + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + return NPY_SUCCEED; + } + else if (PyArray_Check(obj)) { + goto fail; + } + else { + *at = _arraydescr_fromobj(obj); + if (*at) { + return NPY_SUCCEED; + } + if (PyErr_Occurred()) { + return NPY_FAIL; + } + goto fail; + } + if (PyErr_Occurred()) { + goto fail; + } + +finish: + printf("Test5\n"); + if ((check_num == NPY_NOTYPE + 10) || + (*at = PyArray_DescrFromType(check_num)) == NULL) { + PyErr_Clear(); + /* Now check to see if the object is registered in typeDict */ + if (typeDict != NULL) { + item = PyDict_GetItem(typeDict, obj); +#if defined(NPY_PY3K) + if (!item && PyBytes_Check(obj)) { + PyObject *tmp; + tmp = PyUnicode_FromEncodedObject(obj, "ascii", "strict"); + if (tmp != NULL) { + item = PyDict_GetItem(typeDict, tmp); + Py_DECREF(tmp); + } + } +#endif + if (item) { + /* Check for a deprecated Numeric-style typecode */ + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + char *dep_tps[] = {"Bool", "Complex", "Float", "Int", + "Object0", "String0", "Timedelta64", + "Unicode0", "UInt", "Void0"}; + int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]); + int i; + + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + for (i = 0; i < ndep_tps; ++i) { + char *dep_tp = dep_tps[i]; + + if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) { + if (DEPRECATE("Numeric-style type codes are " + "deprecated and will result in " + "an error in the future.") < 0) { + goto fail; + } + } + } + } + return PyArray_DescrConverter(item, at); + } + } + goto fail; + } + + if (((*at)->elsize == 0) && (elsize != 0)) { + PyArray_DESCR_REPLACE(*at); + (*at)->elsize = elsize; + } + if (endian != '=' && PyArray_ISNBO(endian)) { + endian = '='; + } + if (endian != '=' && (*at)->byteorder != '|' + && (*at)->byteorder != endian) { + PyArray_DESCR_REPLACE(*at); + (*at)->byteorder = endian; + } + return NPY_SUCCEED; + +fail: + if (PyBytes_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "data type \"%s\" not understood", PyBytes_AS_STRING(obj)); + } + else { + PyErr_SetString(PyExc_TypeError, + "data type not understood"); + } + +error: + *at = NULL; + return NPY_FAIL; +} +#endif + + +NPY_NO_EXPORT int +MyPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) +{ + int check_num = NPY_NOTYPE + 10; + PyObject *item; + int elsize = 0; + char endian = '='; + + printf("Test -1\n"); + *at = NULL; + + check_num = NPY_VOID; + printf("Test0\n"); + if (check_num != NPY_VOID) { + PyErr_Clear(); + /* Now check to see if the object is registered in typeDict */ + printf("Test1\n"); + if (typeDict != NULL) { + item = PyDict_GetItem(typeDict, obj); +#if defined(NPY_PY3K) + if (!item && PyBytes_Check(obj)) { + PyObject *tmp; + tmp = PyUnicode_FromEncodedObject(obj, "ascii", "strict"); + if (tmp != NULL) { + item = PyDict_GetItem(typeDict, tmp); + Py_DECREF(tmp); + } + } +#endif + if (item) { + /* Check for a deprecated Numeric-style typecode */ + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + char *dep_tps[] = {"Bool", "Complex", "Float", "Int", + "Object0", "String0", "Timedelta64", + "Unicode0", "UInt", "Void0"}; + int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]); + int i; + + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + for (i = 0; i < ndep_tps; ++i) { + char *dep_tp = dep_tps[i]; + + if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) { + if (DEPRECATE("Numeric-style type codes are " + "deprecated and will result in " + "an error in the future.") < 0) { + goto fail; + } + } + } + } + return PyArray_DescrConverter(item, at); + } + } + printf("Test2\n"); + goto fail; + } + + printf("Test3\n"); + if (((*at)->elsize == 0) && (elsize != 0)) { + PyArray_DESCR_REPLACE(*at); + (*at)->elsize = elsize; + printf("Test4\n"); + } + if (endian != '=' && PyArray_ISNBO(endian)) { + endian = '='; + printf("Test5\n"); + } + if (endian != '=' && (*at)->byteorder != '|' + && (*at)->byteorder != endian) { + PyArray_DESCR_REPLACE(*at); + (*at)->byteorder = endian; + printf("Test6\n"); + } + return NPY_SUCCEED; + +fail: + if (PyBytes_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "data type \"%s\" not understood", PyBytes_AS_STRING(obj)); + } + else { + PyErr_SetString(PyExc_TypeError, + "data type not understood"); + } + +error: + *at = NULL; + return NPY_FAIL; +} + + + #if 0 void init_readwriteaccess(struct DICTHOLDER *dict); @@ -261,14 +1345,14 @@ PyObject * my_read_structure(PyObject* molpack) { molfile_atom_t* atoms; int numatoms, status; PyArray_Descr *descr; - PyObject p*; - if (PyType_Ready(&MolAtomType) < 0) - return NULL; - PyTypeObject *atype = &MolAtomType; - MolAtom *atom_t; - atom_t = (MolAtom *)atype->tp_alloc(atype, 0); - p = (PyObject*) atom_t; - descr = PyArray_DescrFromObject(p, NULL) + PyObject *p = NULL; + //if (PyType_Ready(&MolAtomType) < 0) + // return NULL; + //PyTypeObject *atype = &MolAtomType; + //MolAtom *atom_t; + //atom_t = (MolAtom *)atype->tp_alloc(atype, 0); + //p = (PyObject*) atom_t; + descr = PyArray_DescrFromObject(p, NULL); MolObject* plugin_handle = (MolObject*) molpack; plugin = plugin_handle->plugin; file_handle = plugin_handle->file_handle; @@ -286,8 +1370,8 @@ PyObject * my_read_structure(PyObject* molpack) { npy_intp dims[1] = { numatoms }; oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT64); Py_DECREF(p); - array = (PyArrayObject*) PyArray_SimpleNewFromDescr(1, dims, descr); - PyObject_Print(array, stdout, 0); + //array = (PyArrayObject*) PyArray_SimpleNewFromDescr(1, dims, descr); + //PyObject_Print(array, stdout, 0); if (!oresid){ PyErr_Format(PyExc_IOError, "Error copying molfile_atom_t into numpy array."); return NULL; @@ -301,4 +1385,296 @@ PyObject * my_read_structure(PyObject* molpack) { return (PyObject*) PyArray_FromArray(oresid, PyArray_DESCR(oresid), 0); } +PyObject* print_array_struct(PyObject* prototype) +{ + Py_Initialize(); + import_array(); + int status = -10; + PyObject *ret = NULL; + int *maxndim = NULL; + npy_intp *d_shape = NULL; + printf("Check-in print_array_struct\n"); + Py_INCREF(prototype); + ret = get_array_attr_interface(prototype, "descr", maxndim, d_shape); + printf("Returned\n"); + //printf("Returned nd:%d\n", *maxndim); + Py_DECREF(prototype); + if (!ret){ + PyErr_Clear(); + PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); + Py_XDECREF(ret); + return NULL; + } + printf("Check-out print_array_struct\n"); + return ret; +} + +PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype) +{ + Py_Initialize(); + import_array(); + int options = 0; +// int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* data; + int numatoms, status; + int nd; + PyArray_Descr *descr; +// PyArrayInterface *inter; + //PyArrayObject *ret = NULL; + PyObject *ret = NULL; + PyObject *descr_obj = NULL; +// char endian = NPY_NATBYTE; +// PyArrayObject *obj; +// printf("Test1\n"); +// obj = (PyArrayObject *)prototype; +// if(obj == NULL){ +// PyErr_Format(PyExc_IOError, "Error: Given PyObject does not include numpy array."); +// return NULL; +// } + // Access plugin_handle values + MolObject* plugin_handle = (MolObject*) molpack; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + printf("Test2-1\n"); + // Allocate memory for array of molfile_atom_t struct + data = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + // Get array values in molfile_atom_t + printf("Test2-2\n"); + status = plugin->read_structure(file_handle, &options, data); + printf("Test2-3\n"); + // Check if the plugin returns the results + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + nd = 1; + npy_intp dims[1] = { numatoms }; + npy_intp strides[1] = { sizeof(molfile_atom_t) }; + printf("Test3\n"); + Py_INCREF(prototype); + //ret = set_array_attr_interface(prototype, numatoms, data); + descr_obj = get_descr_array_interface(prototype); + descr = (PyArray_Descr*) descr_obj; + //ret = set_array_attr_struct(ret, numatoms, data); + printf("Returned 1\n"); + Py_DECREF(prototype); + printf("Set\n"); + Py_INCREF(prototype); + ret = PyArray_NewFromDescr(Py_TYPE(prototype), PyArray_DESCR((PyArrayObject*)prototype), + nd, dims, + strides, data, + PyArray_FLAGS((PyArrayObject*)prototype), prototype); + //PyArray_STRIDES((PyArrayObject*)prototype), data, + Py_DECREF(prototype); + printf("Returned 2\n"); + //status = my_get_array_attr_interface((PyObject*)obj, "descr", maxndim, d_shape, ret); + //status = my_get_array_attr_interface(prototype, ret); + //printf("Test4 Status:%d nd:%d\n",status,*maxndim); + //printf("Test4 Status:%d\n",status); +// if (status<0){ +// Py_DECREF(obj); +// PyErr_Clear(); +// PyErr_Format(PyExc_IOError, "Error: can not get attribute of given numpy array."); +// return NULL; +// } +// printf("Test5\n"); +// Py_INCREF(prototype); +// Py_DECREF(ret); + //return (PyObject*) PyArray_FromArray((PyArrayObject*)ret, PyArray_DESCR((PyArrayObject*)ret), 0); + return (PyObject*) ret; +} + +PyObject* get_structure(PyObject* self) +{ + int options = 0; + int i; + molfile_plugin_t* plugin; + void* file_handle; + molfile_atom_t* data; + int numatoms, status; + int nd; + PyArrayInterface *inter; + PyArrayObject *ret; + char endian = NPY_NATBYTE; + // Access plugin_handle values + MolObject* plugin_handle = (MolObject*) self; + plugin = plugin_handle->plugin; + file_handle = plugin_handle->file_handle; + numatoms = plugin_handle->natoms; + // Allocate memory for array of molfile_atom_t struct + data = (molfile_atom_t *)calloc(numatoms,sizeof(molfile_atom_t)); + // Get array values in molfile_atom_t + status = plugin->read_structure(file_handle, &options, data); + // Check if the plugin returns the results + if (status!=0){ + PyErr_Format(PyExc_IOError, "Error accessing molfile_atom_t in read_structure function of plugin."); + return NULL; + } + // Now, we need to allocate a PyArray with PyArrayInterface + // and assign the allocated memory block to the data. + // To do this, we will build a numpy array from scratch. + // First, allocate a PyObject of PyArrayInterface and + // assign relevant information such as typestr, descr for C-side + // struct and second we will assign molfile_atom_t array as a block + // of data. Last, hope this works. + nd = 1; + npy_intp dims[1] = { 1 }; + // We would allocate a numpy array with + // but will not look clever to copy all the data into the new array. + // Instead, we allocate a numpy array with one element and change + // the definition of array. I know I said that it will be from scratch + // but let's accept nobody wants to define everything in numpy again. + //oresid = (PyArrayObject*) PyArray_SimpleNew(nd, dims, NPY_INT); + // NPY_INT? Don't worry, we will change it. + //Py_intptr_t *shape, *strides; + //void *data = NULL; + + inter = (PyArrayInterface*)malloc(sizeof(PyArrayInterface)); + if (inter==NULL) + return PyErr_NoMemory(); + + // __array_interface__ descr for C side of __array_struct__ + // Could not find a better way to generate the list of tuples for + // Python side. May need to change this later. + PyObject *descrlist = PyList_New(13); + // One tuple to bind them + PyObject *py_tuple_name = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_name, 0, PyUnicode_FromString("name")); + PyTuple_SET_ITEM(py_tuple_name, 1, PyUnicode_FromString("|S16")); + PyList_SET_ITEM(descrlist, 0, py_tuple_name); + PyObject *py_tuple_type = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_type, 0, PyUnicode_FromString("type")); + PyTuple_SET_ITEM(py_tuple_type, 1, PyUnicode_FromString("|S16")); + PyList_SET_ITEM(descrlist, 1, py_tuple_type); + PyObject *py_tuple_resname = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_resname, 0, PyUnicode_FromString("resname")); + PyTuple_SET_ITEM(py_tuple_resname, 1, PyUnicode_FromString("|S8")); + PyList_SET_ITEM(descrlist, 2, py_tuple_resname); + PyObject *py_tuple_resid = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_resid, 0, PyUnicode_FromString("resid")); + PyTuple_SET_ITEM(py_tuple_resid, 1, PyUnicode_FromString("<i4")); + PyList_SET_ITEM(descrlist, 3, py_tuple_resid); + PyObject *py_tuple_segid = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_segid, 0, PyUnicode_FromString("segid")); + PyTuple_SET_ITEM(py_tuple_segid, 1, PyUnicode_FromString("|S8")); + PyList_SET_ITEM(descrlist, 4, py_tuple_segid); + PyObject *py_tuple_chain = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_chain, 0, PyUnicode_FromString("chain")); + PyTuple_SET_ITEM(py_tuple_chain, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 5, py_tuple_chain); + PyObject *py_tuple_altloc = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_altloc, 0, PyUnicode_FromString("altloc")); + PyTuple_SET_ITEM(py_tuple_altloc, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 6, py_tuple_altloc); + PyObject *py_tuple_insertion = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_insertion, 0, PyUnicode_FromString("insertion")); + PyTuple_SET_ITEM(py_tuple_insertion, 1, PyUnicode_FromString("|S2")); + PyList_SET_ITEM(descrlist, 7, py_tuple_insertion); + PyObject *py_tuple_occupancy = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_occupancy, 0, PyUnicode_FromString("occupancy")); + PyTuple_SET_ITEM(py_tuple_occupancy, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 8, py_tuple_occupancy); + PyObject *py_tuple_bfactor = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_bfactor, 0, PyUnicode_FromString("bfactor")); + PyTuple_SET_ITEM(py_tuple_bfactor, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 9, py_tuple_bfactor); + PyObject *py_tuple_mass = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_mass, 0, PyUnicode_FromString("mass")); + PyTuple_SET_ITEM(py_tuple_mass, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 10, py_tuple_mass); + PyObject *py_tuple_charge = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_charge, 0, PyUnicode_FromString("charge")); + PyTuple_SET_ITEM(py_tuple_charge, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 11, py_tuple_charge); + PyObject *py_tuple_radius = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_radius, 0, PyUnicode_FromString("radius")); + PyTuple_SET_ITEM(py_tuple_radius, 1, PyUnicode_FromString("<f4")); + PyList_SET_ITEM(descrlist, 12, py_tuple_radius); + PyObject *py_tuple_atomicnumber = PyTuple_New(2); + PyTuple_SET_ITEM(py_tuple_atomicnumber, 0, PyUnicode_FromString("atomicnumber")); + PyTuple_SET_ITEM(py_tuple_atomicnumber, 1, PyUnicode_FromString("<i4")); + PyList_SET_ITEM(descrlist, 13, py_tuple_atomicnumber); + //PyArray_Descr *descr = (PyObject*) tuple; + PyArray_Descr *thetype = NULL; + // Here we define the size and stride parameters + npy_intp shape[1] = { numatoms }; + npy_intp strides[1] = { 54*sizeof(char) + 8*sizeof(int) + 20*sizeof(float) }; + + inter->two = 2; + inter->nd = nd; + inter->typekind = 'V'; + inter->itemsize = 82*sizeof(char); + //inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE; + inter->flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE | NPY_ARR_HAS_DESCR; + inter->strides = (Py_intptr_t *)strides; + inter->shape = (Py_intptr_t *)shape; + inter->data = (void*) data; + // inter->descr = (PyObject*) tuple; + if ((inter->flags & NPY_ARRAY_NOTSWAPPED) != NPY_ARRAY_NOTSWAPPED) { + endian = NPY_OPPBYTE; + inter->flags &= ~NPY_ARRAY_NOTSWAPPED; + } + // typestr is relatively easy to assign to __array_interface__ + printf("TEST1\n"); + //thetype = (PyArray_Descr*) tuple; + if (inter->flags & NPY_ARR_HAS_DESCR) { + printf("TEST1-1\n"); + thetype = _convert_from_array_descr(descrlist,0); + //thetype = PyArray_DescrFromTypeObject(descrlist); + printf("TEST1-2\n"); + //if (PyArray_DescrConverter(inter->descr, &thetype) == NPY_FAIL) { + // thetype = NULL; + // PyErr_Clear(); + // } + } + printf("TEST1-3\n"); +#if 0 + char buf[40]; + PyOS_snprintf(buf, sizeof(buf), + "%c%c%d", endian, + inter->typekind, + inter->itemsize); + printf("TEST2 String:%s\n",buf); + PyObject *stringobj = PyUnicode_FromString(buf); + if (stringobj == NULL) { + return NULL; + } + printf("TEST2-2\n"); + if (MyPyArray_DescrConverter(stringobj, &thetype) != NPY_SUCCEED) { + Py_DECREF(stringobj); + return NULL; + } + printf("TEST2-3\n"); + Py_DECREF(stringobj); +#endif + printf("TEST3\n"); + ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, thetype, + inter->nd, inter->shape, + inter->strides, inter->data, + inter->flags, NULL); + printf("TEST4\n"); + Py_INCREF(inter); + if (PyArray_SetBaseObject(ret, (PyObject *)inter) < 0) { + Py_DECREF(ret); + return NULL; + } + printf("TEST5\n"); +// Py_DECREF(attr); + PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL); + printf("TEST6\n"); + return (PyObject *)ret; +} +// obj = NpyCapsule_FromVoidPtrAndDesc(inter, self, gentype_struct_free); +/* +#ifdef Py_CAPSULE_H + obj = PyCapsule_New((void*)inter, "struct SignedIntBuf", free_capsule); +#else + obj = PyCObject_FromVoidPtrAndDesc((void*)inter, (void*)self, free_array_interface); +#endif +*/ + // Cross fingers here. +// return obj; diff --git a/pymolfile/molfile/pymolfile.h b/pymolfile/molfile/pymolfile.h index 5d37f5d2dc12ed010c2baa45c4edb26cbe77ae75..6a0c1b5161f6bd1bc19178bcf644e7d0ffc5cb22 100644 --- a/pymolfile/molfile/pymolfile.h +++ b/pymolfile/molfile/pymolfile.h @@ -30,6 +30,7 @@ extern "C" #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include <numpy/arrayobject.h> + enum { pluginOK, pluginNOINIT, pluginCLOSE, pluginNOMEM, pluginENDOFFILE, pluginFILENOTFOUND, pluginFORMATERROR }; @@ -119,7 +120,7 @@ static PyMemberDef MolObject_members[] = { "file handle for plugin"}, {"natoms", T_INT, offsetof(MolObject, natoms), 0, "number of atoms"}, - {NULL, NULL, 0, NULL} /* Sentinel */ + {NULL} /* Sentinel */ }; static PyMethodDef MolObject_methods[] = { @@ -132,7 +133,7 @@ static PyMethodDef MolObject_methods[] = { {"get_natoms", (PyCFunction)MolObject_natoms, METH_NOARGS, "Return the number of atoms" }, - {NULL, NULL, 0, NULL} /* Sentinel */ + {NULL} /* Sentinel */ }; @@ -183,6 +184,7 @@ static PyTypeObject MolObjectType = { MolObject_new, /* tp_new */ }; +#if 0 struct MolAtom { PyObject_HEAD char* name; @@ -257,8 +259,8 @@ static PyMemberDef MolAtom_members[] = { {"segid", T_STRING, offsetof(MolAtom, segid), 0,""}, {"chain", T_STRING, offsetof(MolAtom, chain), 0,""}, {"altloc", T_STRING, offsetof(MolAtom, altloc), 0,""}, - {"insertion", T_STRING, offsetof(MolAtom, occupancy), 0,""}, - {"occupancy", T_FLOAT, offsetof(MolAtom, ), 0,""}, + {"insertion", T_STRING, offsetof(MolAtom, insertion), 0,""}, + {"occupancy", T_FLOAT, offsetof(MolAtom, occupancy), 0,""}, {"bfactor", T_FLOAT, offsetof(MolAtom, bfactor), 0,""}, {"mass", T_FLOAT, offsetof(MolAtom, mass), 0,""}, {"charge", T_FLOAT, offsetof(MolAtom, charge), 0,""}, @@ -309,8 +311,11 @@ static PyTypeObject MolAtomType = { 0, /* tp_alloc */ MolAtom_new, /* tp_new */ }; - +#endif PyObject * my_read_structure(PyObject* molpack); +PyObject * read_fill_structure(PyObject* molpack, PyObject* prototype); +PyObject * get_structure(PyObject* molpack); +PyObject * print_array_struct(PyObject* prototype); #if 0 typedef struct DICTHOLDER { diff --git a/pymolfile/molfile/signedintbuf-cython/compile-numind.sh b/pymolfile/molfile/signedintbuf-cython/compile-numind.sh new file mode 100644 index 0000000000000000000000000000000000000000..680fa4e374146e23eaab3a4e15e25c120176b42a --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/compile-numind.sh @@ -0,0 +1,2 @@ +Cython -a numind.pyx --cplus +g++ -fPIC -Wall -Wextra -Wunused-function -shared -I/labEnv3/lib/python3.6/site-packages/numpy/core/include/ numind.cpp -o numind.so -I/labEnv3/include/python3.6m/ -L/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6 diff --git a/pymolfile/molfile/signedintbuf-cython/numind.cpp b/pymolfile/molfile/signedintbuf-cython/numind.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06f2230dd7ee03c887290f5a40d14c053ceb556d --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/numind.cpp @@ -0,0 +1 @@ +#error Do not use this file, it is the result of a failed Cython compilation. diff --git a/pymolfile/molfile/signedintbuf-cython/numind.h b/pymolfile/molfile/signedintbuf-cython/numind.h new file mode 100644 index 0000000000000000000000000000000000000000..988c2c80604711a3067cf39a3976896c48867526 --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/numind.h @@ -0,0 +1,12 @@ +#ifndef NUMIND_H +#define NUMIND_H + +typedef struct SignedIntBuf +{ + int* data; + int shape[2]; + int strides[2]; +} SignedIntBuf; + +#endif + diff --git a/pymolfile/molfile/signedintbuf-cython/numind.html b/pymolfile/molfile/signedintbuf-cython/numind.html new file mode 100644 index 0000000000000000000000000000000000000000..96768d145b96058d800f53ece01d88f4c34cb278 --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/numind.html @@ -0,0 +1,1243 @@ +<!DOCTYPE html> +<!-- Generated by Cython 0.26.1 --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Cython: numind.pyx</title> + <style type="text/css"> + +body.cython { font-family: courier; font-size: 12; } + +.cython.tag { } +.cython.line { margin: 0em } +.cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; } + +.cython.line .run { background-color: #B0FFB0; } +.cython.line .mis { background-color: #FFB0B0; } +.cython.code.run { border-left: 8px solid #B0FFB0; } +.cython.code.mis { border-left: 8px solid #FFB0B0; } + +.cython.code .py_c_api { color: red; } +.cython.code .py_macro_api { color: #FF7000; } +.cython.code .pyx_c_api { color: #FF3000; } +.cython.code .pyx_macro_api { color: #FF7000; } +.cython.code .refnanny { color: #FFA000; } +.cython.code .trace { color: #FFA000; } +.cython.code .error_goto { color: #FFA000; } + +.cython.code .coerce { color: #008000; border: 1px dotted #008000 } +.cython.code .py_attr { color: #FF0000; font-weight: bold; } +.cython.code .c_attr { color: #0000FF; } +.cython.code .py_call { color: #FF0000; font-weight: bold; } +.cython.code .c_call { color: #0000FF; } + +.cython.score-0 {background-color: #FFFFff;} +.cython.score-1 {background-color: #FFFFe7;} +.cython.score-2 {background-color: #FFFFd4;} +.cython.score-3 {background-color: #FFFFc4;} +.cython.score-4 {background-color: #FFFFb6;} +.cython.score-5 {background-color: #FFFFaa;} +.cython.score-6 {background-color: #FFFF9f;} +.cython.score-7 {background-color: #FFFF96;} +.cython.score-8 {background-color: #FFFF8d;} +.cython.score-9 {background-color: #FFFF86;} +.cython.score-10 {background-color: #FFFF7f;} +.cython.score-11 {background-color: #FFFF79;} +.cython.score-12 {background-color: #FFFF73;} +.cython.score-13 {background-color: #FFFF6e;} +.cython.score-14 {background-color: #FFFF6a;} +.cython.score-15 {background-color: #FFFF66;} +.cython.score-16 {background-color: #FFFF62;} +.cython.score-17 {background-color: #FFFF5e;} +.cython.score-18 {background-color: #FFFF5b;} +.cython.score-19 {background-color: #FFFF57;} +.cython.score-20 {background-color: #FFFF55;} +.cython.score-21 {background-color: #FFFF52;} +.cython.score-22 {background-color: #FFFF4f;} +.cython.score-23 {background-color: #FFFF4d;} +.cython.score-24 {background-color: #FFFF4b;} +.cython.score-25 {background-color: #FFFF48;} +.cython.score-26 {background-color: #FFFF46;} +.cython.score-27 {background-color: #FFFF44;} +.cython.score-28 {background-color: #FFFF43;} +.cython.score-29 {background-color: #FFFF41;} +.cython.score-30 {background-color: #FFFF3f;} +.cython.score-31 {background-color: #FFFF3e;} +.cython.score-32 {background-color: #FFFF3c;} +.cython.score-33 {background-color: #FFFF3b;} +.cython.score-34 {background-color: #FFFF39;} +.cython.score-35 {background-color: #FFFF38;} +.cython.score-36 {background-color: #FFFF37;} +.cython.score-37 {background-color: #FFFF36;} +.cython.score-38 {background-color: #FFFF35;} +.cython.score-39 {background-color: #FFFF34;} +.cython.score-40 {background-color: #FFFF33;} +.cython.score-41 {background-color: #FFFF32;} +.cython.score-42 {background-color: #FFFF31;} +.cython.score-43 {background-color: #FFFF30;} +.cython.score-44 {background-color: #FFFF2f;} +.cython.score-45 {background-color: #FFFF2e;} +.cython.score-46 {background-color: #FFFF2d;} +.cython.score-47 {background-color: #FFFF2c;} +.cython.score-48 {background-color: #FFFF2b;} +.cython.score-49 {background-color: #FFFF2b;} +.cython.score-50 {background-color: #FFFF2a;} +.cython.score-51 {background-color: #FFFF29;} +.cython.score-52 {background-color: #FFFF29;} +.cython.score-53 {background-color: #FFFF28;} +.cython.score-54 {background-color: #FFFF27;} +.cython.score-55 {background-color: #FFFF27;} +.cython.score-56 {background-color: #FFFF26;} +.cython.score-57 {background-color: #FFFF26;} +.cython.score-58 {background-color: #FFFF25;} +.cython.score-59 {background-color: #FFFF24;} +.cython.score-60 {background-color: #FFFF24;} +.cython.score-61 {background-color: #FFFF23;} +.cython.score-62 {background-color: #FFFF23;} +.cython.score-63 {background-color: #FFFF22;} +.cython.score-64 {background-color: #FFFF22;} +.cython.score-65 {background-color: #FFFF22;} +.cython.score-66 {background-color: #FFFF21;} +.cython.score-67 {background-color: #FFFF21;} +.cython.score-68 {background-color: #FFFF20;} +.cython.score-69 {background-color: #FFFF20;} +.cython.score-70 {background-color: #FFFF1f;} +.cython.score-71 {background-color: #FFFF1f;} +.cython.score-72 {background-color: #FFFF1f;} +.cython.score-73 {background-color: #FFFF1e;} +.cython.score-74 {background-color: #FFFF1e;} +.cython.score-75 {background-color: #FFFF1e;} +.cython.score-76 {background-color: #FFFF1d;} +.cython.score-77 {background-color: #FFFF1d;} +.cython.score-78 {background-color: #FFFF1c;} +.cython.score-79 {background-color: #FFFF1c;} +.cython.score-80 {background-color: #FFFF1c;} +.cython.score-81 {background-color: #FFFF1c;} +.cython.score-82 {background-color: #FFFF1b;} +.cython.score-83 {background-color: #FFFF1b;} +.cython.score-84 {background-color: #FFFF1b;} +.cython.score-85 {background-color: #FFFF1a;} +.cython.score-86 {background-color: #FFFF1a;} +.cython.score-87 {background-color: #FFFF1a;} +.cython.score-88 {background-color: #FFFF1a;} +.cython.score-89 {background-color: #FFFF19;} +.cython.score-90 {background-color: #FFFF19;} +.cython.score-91 {background-color: #FFFF19;} +.cython.score-92 {background-color: #FFFF19;} +.cython.score-93 {background-color: #FFFF18;} +.cython.score-94 {background-color: #FFFF18;} +.cython.score-95 {background-color: #FFFF18;} +.cython.score-96 {background-color: #FFFF18;} +.cython.score-97 {background-color: #FFFF17;} +.cython.score-98 {background-color: #FFFF17;} +.cython.score-99 {background-color: #FFFF17;} +.cython.score-100 {background-color: #FFFF17;} +.cython.score-101 {background-color: #FFFF16;} +.cython.score-102 {background-color: #FFFF16;} +.cython.score-103 {background-color: #FFFF16;} +.cython.score-104 {background-color: #FFFF16;} +.cython.score-105 {background-color: #FFFF16;} +.cython.score-106 {background-color: #FFFF15;} +.cython.score-107 {background-color: #FFFF15;} +.cython.score-108 {background-color: #FFFF15;} +.cython.score-109 {background-color: #FFFF15;} +.cython.score-110 {background-color: #FFFF15;} +.cython.score-111 {background-color: #FFFF15;} +.cython.score-112 {background-color: #FFFF14;} +.cython.score-113 {background-color: #FFFF14;} +.cython.score-114 {background-color: #FFFF14;} +.cython.score-115 {background-color: #FFFF14;} +.cython.score-116 {background-color: #FFFF14;} +.cython.score-117 {background-color: #FFFF14;} +.cython.score-118 {background-color: #FFFF13;} +.cython.score-119 {background-color: #FFFF13;} +.cython.score-120 {background-color: #FFFF13;} +.cython.score-121 {background-color: #FFFF13;} +.cython.score-122 {background-color: #FFFF13;} +.cython.score-123 {background-color: #FFFF13;} +.cython.score-124 {background-color: #FFFF13;} +.cython.score-125 {background-color: #FFFF12;} +.cython.score-126 {background-color: #FFFF12;} +.cython.score-127 {background-color: #FFFF12;} +.cython.score-128 {background-color: #FFFF12;} +.cython.score-129 {background-color: #FFFF12;} +.cython.score-130 {background-color: #FFFF12;} +.cython.score-131 {background-color: #FFFF12;} +.cython.score-132 {background-color: #FFFF11;} +.cython.score-133 {background-color: #FFFF11;} +.cython.score-134 {background-color: #FFFF11;} +.cython.score-135 {background-color: #FFFF11;} +.cython.score-136 {background-color: #FFFF11;} +.cython.score-137 {background-color: #FFFF11;} +.cython.score-138 {background-color: #FFFF11;} +.cython.score-139 {background-color: #FFFF11;} +.cython.score-140 {background-color: #FFFF11;} +.cython.score-141 {background-color: #FFFF10;} +.cython.score-142 {background-color: #FFFF10;} +.cython.score-143 {background-color: #FFFF10;} +.cython.score-144 {background-color: #FFFF10;} +.cython.score-145 {background-color: #FFFF10;} +.cython.score-146 {background-color: #FFFF10;} +.cython.score-147 {background-color: #FFFF10;} +.cython.score-148 {background-color: #FFFF10;} +.cython.score-149 {background-color: #FFFF10;} +.cython.score-150 {background-color: #FFFF0f;} +.cython.score-151 {background-color: #FFFF0f;} +.cython.score-152 {background-color: #FFFF0f;} +.cython.score-153 {background-color: #FFFF0f;} +.cython.score-154 {background-color: #FFFF0f;} +.cython.score-155 {background-color: #FFFF0f;} +.cython.score-156 {background-color: #FFFF0f;} +.cython.score-157 {background-color: #FFFF0f;} +.cython.score-158 {background-color: #FFFF0f;} +.cython.score-159 {background-color: #FFFF0f;} +.cython.score-160 {background-color: #FFFF0f;} +.cython.score-161 {background-color: #FFFF0e;} +.cython.score-162 {background-color: #FFFF0e;} +.cython.score-163 {background-color: #FFFF0e;} +.cython.score-164 {background-color: #FFFF0e;} +.cython.score-165 {background-color: #FFFF0e;} +.cython.score-166 {background-color: #FFFF0e;} +.cython.score-167 {background-color: #FFFF0e;} +.cython.score-168 {background-color: #FFFF0e;} +.cython.score-169 {background-color: #FFFF0e;} +.cython.score-170 {background-color: #FFFF0e;} +.cython.score-171 {background-color: #FFFF0e;} +.cython.score-172 {background-color: #FFFF0e;} +.cython.score-173 {background-color: #FFFF0d;} +.cython.score-174 {background-color: #FFFF0d;} +.cython.score-175 {background-color: #FFFF0d;} +.cython.score-176 {background-color: #FFFF0d;} +.cython.score-177 {background-color: #FFFF0d;} +.cython.score-178 {background-color: #FFFF0d;} +.cython.score-179 {background-color: #FFFF0d;} +.cython.score-180 {background-color: #FFFF0d;} +.cython.score-181 {background-color: #FFFF0d;} +.cython.score-182 {background-color: #FFFF0d;} +.cython.score-183 {background-color: #FFFF0d;} +.cython.score-184 {background-color: #FFFF0d;} +.cython.score-185 {background-color: #FFFF0d;} +.cython.score-186 {background-color: #FFFF0d;} +.cython.score-187 {background-color: #FFFF0c;} +.cython.score-188 {background-color: #FFFF0c;} +.cython.score-189 {background-color: #FFFF0c;} +.cython.score-190 {background-color: #FFFF0c;} +.cython.score-191 {background-color: #FFFF0c;} +.cython.score-192 {background-color: #FFFF0c;} +.cython.score-193 {background-color: #FFFF0c;} +.cython.score-194 {background-color: #FFFF0c;} +.cython.score-195 {background-color: #FFFF0c;} +.cython.score-196 {background-color: #FFFF0c;} +.cython.score-197 {background-color: #FFFF0c;} +.cython.score-198 {background-color: #FFFF0c;} +.cython.score-199 {background-color: #FFFF0c;} +.cython.score-200 {background-color: #FFFF0c;} +.cython.score-201 {background-color: #FFFF0c;} +.cython.score-202 {background-color: #FFFF0c;} +.cython.score-203 {background-color: #FFFF0b;} +.cython.score-204 {background-color: #FFFF0b;} +.cython.score-205 {background-color: #FFFF0b;} +.cython.score-206 {background-color: #FFFF0b;} +.cython.score-207 {background-color: #FFFF0b;} +.cython.score-208 {background-color: #FFFF0b;} +.cython.score-209 {background-color: #FFFF0b;} +.cython.score-210 {background-color: #FFFF0b;} +.cython.score-211 {background-color: #FFFF0b;} +.cython.score-212 {background-color: #FFFF0b;} +.cython.score-213 {background-color: #FFFF0b;} +.cython.score-214 {background-color: #FFFF0b;} +.cython.score-215 {background-color: #FFFF0b;} +.cython.score-216 {background-color: #FFFF0b;} +.cython.score-217 {background-color: #FFFF0b;} +.cython.score-218 {background-color: #FFFF0b;} +.cython.score-219 {background-color: #FFFF0b;} +.cython.score-220 {background-color: #FFFF0b;} +.cython.score-221 {background-color: #FFFF0b;} +.cython.score-222 {background-color: #FFFF0a;} +.cython.score-223 {background-color: #FFFF0a;} +.cython.score-224 {background-color: #FFFF0a;} +.cython.score-225 {background-color: #FFFF0a;} +.cython.score-226 {background-color: #FFFF0a;} +.cython.score-227 {background-color: #FFFF0a;} +.cython.score-228 {background-color: #FFFF0a;} +.cython.score-229 {background-color: #FFFF0a;} +.cython.score-230 {background-color: #FFFF0a;} +.cython.score-231 {background-color: #FFFF0a;} +.cython.score-232 {background-color: #FFFF0a;} +.cython.score-233 {background-color: #FFFF0a;} +.cython.score-234 {background-color: #FFFF0a;} +.cython.score-235 {background-color: #FFFF0a;} +.cython.score-236 {background-color: #FFFF0a;} +.cython.score-237 {background-color: #FFFF0a;} +.cython.score-238 {background-color: #FFFF0a;} +.cython.score-239 {background-color: #FFFF0a;} +.cython.score-240 {background-color: #FFFF0a;} +.cython.score-241 {background-color: #FFFF0a;} +.cython.score-242 {background-color: #FFFF0a;} +.cython.score-243 {background-color: #FFFF0a;} +.cython.score-244 {background-color: #FFFF0a;} +.cython.score-245 {background-color: #FFFF0a;} +.cython.score-246 {background-color: #FFFF09;} +.cython.score-247 {background-color: #FFFF09;} +.cython.score-248 {background-color: #FFFF09;} +.cython.score-249 {background-color: #FFFF09;} +.cython.score-250 {background-color: #FFFF09;} +.cython.score-251 {background-color: #FFFF09;} +.cython.score-252 {background-color: #FFFF09;} +.cython.score-253 {background-color: #FFFF09;} +.cython.score-254 {background-color: #FFFF09;} + </style> + <script> + function toggleDiv(id) { + theDiv = id.nextElementSibling + if (theDiv.style.display != 'block') theDiv.style.display = 'block'; + else theDiv.style.display = 'none'; + } + </script> +</head> +<body class="cython"> +<p><span style="border-bottom: solid 1px grey;">Generated by Cython 0.26.1</span></p> +<p> + <span style="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br /> + Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it. +</p> +<p>Raw output: <a href="numind.cpp">numind.cpp</a></p> +<div class="cython"><pre class="cython line score-0"> <span class="">001</span>: # This Pyrex extension class can take a numpy/numarray/Numeric object</pre> +<pre class="cython line score-0"> <span class="">002</span>: # as a parameter and wrap it so that its information can be accessed</pre> +<pre class="cython line score-0"> <span class="">003</span>: # in a standard way, both in Python space and C space.</pre> +<pre class="cython line score-0"> <span class="">004</span>: #</pre> +<pre class="cython line score-0"> <span class="">005</span>: # Heavily based on an idea of Andrew Straw. See</pre> +<pre class="cython line score-0"> <span class="">006</span>: # http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex</pre> +<pre class="cython line score-0"> <span class="">007</span>: # Very inspiring! :-)</pre> +<pre class="cython line score-0"> <span class="">008</span>: #</pre> +<pre class="cython line score-0"> <span class="">009</span>: # First version: 2006-03-25</pre> +<pre class="cython line score-0"> <span class="">010</span>: # Last update: 2006-03-25</pre> +<pre class="cython line score-0"> <span class="">011</span>: # Author: Francesc Altet</pre> +<pre class="cython line score-0"> <span class="">012</span>: </pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">013</span>: import sys</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_Import</span>(__pyx_n_s_sys, 0, -1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 13, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-0"> <span class="">014</span>: from cpython.pycapsule cimport *</pre> +<pre class="cython line score-0"> <span class="">015</span>: </pre> +<pre class="cython line score-0"> <span class="">016</span>: cdef extern from "Python.h":</pre> +<pre class="cython line score-0"> <span class="">017</span>: ctypedef int Py_intptr_t</pre> +<pre class="cython line score-0"> <span class="">018</span>: ctypedef object PyObject</pre> +<pre class="cython line score-0"> <span class="">019</span>: long PyInt_AsLong(object)</pre> +<pre class="cython line score-0"> <span class="">020</span>: void Py_INCREF(object)</pre> +<pre class="cython line score-0"> <span class="">021</span>: void Py_DECREF(object)</pre> +<pre class="cython line score-0"> <span class="">022</span>: </pre> +<pre class="cython line score-0"> <span class="">023</span>: cdef extern from "stdlib.h":</pre> +<pre class="cython line score-0"> <span class="">024</span>: ctypedef long size_t</pre> +<pre class="cython line score-0"> <span class="">025</span>: ctypedef long intptr_t</pre> +<pre class="cython line score-0"> <span class="">026</span>: void *malloc(size_t size)</pre> +<pre class="cython line score-0"> <span class="">027</span>: void free(void* ptr)</pre> +<pre class="cython line score-0"> <span class="">028</span>: </pre> +<pre class="cython line score-0"> <span class="">029</span>: cdef extern from "numind.h":</pre> +<pre class="cython line score-0"> <span class="">030</span>: ctypedef struct SignedIntBuf</pre> +<pre class="cython line score-0"> <span class="">031</span>: </pre> +<pre class="cython line score-0"> <span class="">032</span>: # for PyArrayInterface:</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">033</span>: CONTIGUOUS=0x01</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_CONTIGUOUS, __pyx_int_1) < 0) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">034</span>: FORTRAN=0x02</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_FORTRAN, __pyx_int_2) < 0) <span class='error_goto'>__PYX_ERR(0, 34, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">035</span>: ALIGNED=0x100</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_ALIGNED, __pyx_int_256) < 0) <span class='error_goto'>__PYX_ERR(0, 35, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">036</span>: NOTSWAPPED=0x200</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_NOTSWAPPED, __pyx_int_512) < 0) <span class='error_goto'>__PYX_ERR(0, 36, __pyx_L1_error)</span> +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">037</span>: WRITEABLE=0x400</pre> +<pre class='cython code score-5 '> if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_WRITEABLE, __pyx_int_1024) < 0) <span class='error_goto'>__PYX_ERR(0, 37, __pyx_L1_error)</span> +</pre><pre class="cython line score-0"> <span class="">038</span>: </pre> +<pre class="cython line score-0"> <span class="">039</span>: # byteorder dictionary</pre> +<pre class="cython line score-21" onclick='toggleDiv(this)'>+<span class="">040</span>: byteorder = {'<':'little', '>':'big'}</pre> +<pre class='cython code score-21 '> __pyx_t_1 = <span class='py_c_api'>PyDict_New</span>();<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_t_1, __pyx_kp_s__6, __pyx_n_s_little) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_t_1, __pyx_kp_s__7, __pyx_n_s_big) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_byteorder, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-0"> <span class="">041</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">042</span>: ctypedef struct PyArrayInterface:</pre> +<pre class='cython code score-0 '>struct __pyx_t_6numind_PyArrayInterface { + int version; + int nd; + char typekind; + int itemsize; + int flags; + Py_intptr_t *shape; + Py_intptr_t *strides; + void *data; +}; +</pre><pre class="cython line score-0"> <span class="">043</span>: int version # contains the integer 2 as a sanity check</pre> +<pre class="cython line score-0"> <span class="">044</span>: int nd # number of dimensions</pre> +<pre class="cython line score-0"> <span class="">045</span>: char typekind # kind in array --- character code of typestr</pre> +<pre class="cython line score-0"> <span class="">046</span>: int itemsize # size of each element</pre> +<pre class="cython line score-0"> <span class="">047</span>: int flags # flags indicating how the data should be interpreted</pre> +<pre class="cython line score-0"> <span class="">048</span>: Py_intptr_t *shape # A length-nd array of shape information</pre> +<pre class="cython line score-0"> <span class="">049</span>: Py_intptr_t *strides # A length-nd array of stride information</pre> +<pre class="cython line score-0"> <span class="">050</span>: void *data # A pointer to the first element of the array</pre> +<pre class="cython line score-0"> <span class="">051</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">052</span>: cdef void* free_array_interface(object arr):</pre> +<pre class='cython code score-0 '>static void *__pyx_f_6numind_free_array_interface(PyObject *__pyx_v_arr) { + void *__pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("free_array_interface", 0); +/* … */ + /* function exit code */ + __pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">053</span>: Py_DECREF(arr)</pre> +<pre class='cython code score-0 '> Py_DECREF(__pyx_v_arr); +</pre><pre class="cython line score-0"> <span class="">054</span>: </pre> +<pre class="cython line score-0"> <span class="">055</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">056</span>: cdef class NumInd:</pre> +<pre class='cython code score-0 '>struct __pyx_obj_6numind_NumInd { + PyObject_HEAD + struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtab; + void *data; + int _nd; + Py_intptr_t *_shape; + Py_intptr_t *_strides; + __pyx_t_6numind_PyArrayInterface *inter; + PyObject *_t_shape; + PyObject *_t_strides; + PyObject *_undarray; +}; + + + +struct __pyx_vtabstruct_6numind_NumInd { + __pyx_t_6numind_PyArrayInterface *(*_get_array_interface)(struct __pyx_obj_6numind_NumInd *); +}; +static struct __pyx_vtabstruct_6numind_NumInd *__pyx_vtabptr_6numind_NumInd; +</pre><pre class="cython line score-0"> <span class="">057</span>: cdef void *data</pre> +<pre class="cython line score-0"> <span class="">058</span>: cdef int _nd</pre> +<pre class="cython line score-0"> <span class="">059</span>: cdef Py_intptr_t *_shape</pre> +<pre class="cython line score-0"> <span class="">060</span>: cdef Py_intptr_t *_strides</pre> +<pre class="cython line score-0"> <span class="">061</span>: cdef PyArrayInterface *inter</pre> +<pre class="cython line score-0"> <span class="">062</span>: cdef object _t_shape, _t_strides, _undarray</pre> +<pre class="cython line score-0"> <span class="">063</span>: </pre> +<pre class="cython line score-28" onclick='toggleDiv(this)'>+<span class="">064</span>: def __init__(self, object undarray):</pre> +<pre class='cython code score-28 '>/* Python wrapper */ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_6numind_6NumInd_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_undarray = 0; + int __pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_undarray,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args); + switch (pos_args) { + case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = <span class='py_c_api'>PyDict_GetItem</span>(__pyx_kwds, __pyx_n_s_undarray)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) <span class='error_goto'>__PYX_ERR(0, 64, __pyx_L3_error)</span> + } + } else if (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0); + } + __pyx_v_undarray = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>("__init__", 1, 1, 1, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>__PYX_ERR(0, 64, __pyx_L3_error)</span> + __pyx_L3_error:; + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_6numind_6NumInd___init__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self), __pyx_v_undarray); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static int __pyx_pf_6numind_6NumInd___init__(struct __pyx_obj_6numind_NumInd *__pyx_v_self, PyObject *__pyx_v_undarray) { + int __pyx_v_i; + int __pyx_v_stride; + PyObject *__pyx_v_array_shape = 0; + PyObject *__pyx_v_array_strides = 0; + int __pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__init__", 0); +/* … */ + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_7); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_array_shape); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">065</span>: cdef int i, stride</pre> +<pre class="cython line score-0"> <span class="">066</span>: cdef object array_shape, array_strides</pre> +<pre class="cython line score-0"> <span class="">067</span>: </pre> +<pre class="cython line score-0"> <span class="">068</span>: # Keep a reference to the underlying object</pre> +<pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">069</span>: self._undarray = undarray</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_undarray); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_undarray); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_undarray); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_undarray); + __pyx_v_self->_undarray = __pyx_v_undarray; +</pre><pre class="cython line score-0"> <span class="">070</span>: # Get the shape and strides C arrays</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">071</span>: array_shape = undarray.__array_interface__["shape"]</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_shape);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_array_shape = __pyx_t_2; + __pyx_t_2 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">072</span>: self._t_shape = array_shape</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_array_shape); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_array_shape); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_shape); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_shape); + __pyx_v_self->_t_shape = __pyx_v_array_shape; +</pre><pre class="cython line score-0"> <span class="">073</span>: # The number of dimensions</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">074</span>: self._nd = len(array_shape)</pre> +<pre class='cython code score-5 '> __pyx_t_3 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_array_shape);<span class='error_goto'> if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 74, __pyx_L1_error)</span> + __pyx_v_self->_nd = __pyx_t_3; +</pre><pre class="cython line score-0"> <span class="">075</span>: # The shape</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">076</span>: self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t))</pre> +<pre class='cython code score-0 '> __pyx_v_self->_shape = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">077</span>: for i from 0 <= i < self._nd:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-10" onclick='toggleDiv(this)'>+<span class="">078</span>: self._shape[i] = self._t_shape[i]</pre> +<pre class='cython code score-10 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_self->_t_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_As_Py_intptr_t</span>(__pyx_t_2); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 78, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + (__pyx_v_self->_shape[__pyx_v_i]) = __pyx_t_5; + } +</pre><pre class="cython line score-0"> <span class="">079</span>: # The strides (compute them if needed)</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">080</span>: array_strides = undarray.__array_interface__["strides"]</pre> +<pre class='cython code score-8 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_1 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_2, __pyx_n_s_strides);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_array_strides = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">081</span>: self._t_strides = array_strides</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_array_strides); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_v_array_strides; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">082</span>: self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t))</pre> +<pre class='cython code score-0 '> __pyx_v_self->_strides = ((Py_intptr_t *)malloc((__pyx_v_self->_nd * (sizeof(Py_intptr_t))))); +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">083</span>: if array_strides:</pre> +<pre class='cython code score-2 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_v_array_strides); if (unlikely(__pyx_t_6 < 0)) <span class='error_goto'>__PYX_ERR(0, 83, __pyx_L1_error)</span> + if (__pyx_t_6) { +/* … */ + goto __pyx_L5; + } +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">084</span>: for i from 0 <= i < self._nd:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = __pyx_v_self->_nd; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-10" onclick='toggleDiv(this)'>+<span class="">085</span>: self._strides[i] = array_strides[i]</pre> +<pre class='cython code score-10 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_array_strides, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_As_Py_intptr_t</span>(__pyx_t_1); if (unlikely((__pyx_t_5 == ((Py_intptr_t)-1)) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 85, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_t_5; + } +</pre><pre class="cython line score-0"> <span class="">086</span>: else:</pre> +<pre class="cython line score-0"> <span class="">087</span>: # strides is None. Compute them explicitely.</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">088</span>: self._t_strides = [0] * self._nd</pre> +<pre class='cython code score-8 '> /*else*/ { + __pyx_t_1 = <span class='py_c_api'>PyList_New</span>(1 * ((__pyx_v_self->_nd<0) ? 0:__pyx_v_self->_nd));<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_self->_nd; __pyx_temp++) { + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_int_0); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_int_0); + <span class='py_macro_api'>PyList_SET_ITEM</span>(__pyx_t_1, __pyx_temp, __pyx_int_0); + } + } + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-21" onclick='toggleDiv(this)'>+<span class="">089</span>: stride = int(self.typestr[2:])</pre> +<pre class='cython code score-21 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_GetSlice</span>(__pyx_t_1, 2, 0, NULL, NULL, &__pyx_slice_, 1, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyNumber_Int</span>(__pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_stride = __pyx_t_4; +/* … */ + __pyx_slice_ = <span class='py_c_api'>PySlice_New</span>(__pyx_int_2, Py_None, Py_None);<span class='error_goto'> if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 89, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_slice_); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_slice_); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">090</span>: for i from self._nd > i >= 0:</pre> +<pre class='cython code score-0 '> for (__pyx_v_i = __pyx_v_self->_nd-1; __pyx_v_i >= 0; __pyx_v_i--) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">091</span>: self._strides[i] = stride</pre> +<pre class='cython code score-0 '> (__pyx_v_self->_strides[__pyx_v_i]) = __pyx_v_stride; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">092</span>: self._t_strides[i] = stride</pre> +<pre class='cython code score-5 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_stride);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(__pyx_v_self->_t_strides, __pyx_v_i, __pyx_t_1, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 92, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">093</span>: stride = stride * array_shape[i]</pre> +<pre class='cython code score-19 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_stride);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_array_shape, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + __pyx_t_7 = <span class='py_c_api'>PyNumber_Multiply</span>(__pyx_t_1, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_7); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_7); if (unlikely((__pyx_t_4 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 93, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_stride = __pyx_t_4; + } +</pre><pre class="cython line score-6" onclick='toggleDiv(this)'>+<span class="">094</span>: self._t_strides = tuple(self._t_strides)</pre> +<pre class='cython code score-6 '> __pyx_t_7 = <span class='py_c_api'>PySequence_Tuple</span>(__pyx_v_self->_t_strides);<span class='error_goto'> if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_7); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_7); + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_v_self->_t_strides); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_v_self->_t_strides); + __pyx_v_self->_t_strides = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_L5:; +</pre><pre class="cython line score-0"> <span class="">095</span>: # Populate the C array interface</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">096</span>: self.inter = self._get_array_interface()</pre> +<pre class='cython code score-0 '> __pyx_v_self->inter = ((struct __pyx_vtabstruct_6numind_NumInd *)__pyx_v_self->__pyx_vtab)->_get_array_interface(__pyx_v_self); +</pre><pre class="cython line score-0"> <span class="">097</span>: </pre> +<pre class="cython line score-0"> <span class="">098</span>: # Properties. This are visible from Python space.</pre> +<pre class="cython line score-0"> <span class="">099</span>: # Add as many as you want.</pre> +<pre class="cython line score-0"> <span class="">100</span>: </pre> +<pre class="cython line score-0"> <span class="">101</span>: property undarray: # Returns the underlying array</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">102</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8undarray_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8undarray___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8undarray___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">103</span>: return self._undarray</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_undarray); + __pyx_r = __pyx_v_self->_undarray; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">104</span>: </pre> +<pre class="cython line score-0"> <span class="">105</span>: property shape:</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">106</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_5shape_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_5shape___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_5shape___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">107</span>: return self._t_shape</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_t_shape); + __pyx_r = __pyx_v_self->_t_shape; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">108</span>: </pre> +<pre class="cython line score-0"> <span class="">109</span>: property strides:</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">110</span>: def __get__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7strides_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7strides___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7strides___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">111</span>: return self._t_strides</pre> +<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_self->_t_strides); + __pyx_r = __pyx_v_self->_t_strides; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">112</span>: </pre> +<pre class="cython line score-0"> <span class="">113</span>: property typestr:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">114</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_7typestr_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_7typestr___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_7typestr___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.typestr.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-9" onclick='toggleDiv(this)'>+<span class="">115</span>: return self._undarray.__array_interface__["typestr"]</pre> +<pre class='cython code score-9 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">116</span>: </pre> +<pre class="cython line score-0"> <span class="">117</span>: property typekind:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">118</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8typekind_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8typekind___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8typekind___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.typekind.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-12" onclick='toggleDiv(this)'>+<span class="">119</span>: return chr(self.inter.typekind)</pre> +<pre class='cython code score-12 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">120</span>: </pre> +<pre class="cython line score-0"> <span class="">121</span>: property readonly:</pre> +<pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">122</span>: def __get__(self):</pre> +<pre class='cython code score-4 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_8readonly_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_8readonly___get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_8readonly___get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.readonly.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-12" onclick='toggleDiv(this)'>+<span class="">123</span>: return self._undarray.__array_interface__["data"][1]</pre> +<pre class='cython code score-12 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_data);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">124</span>: </pre> +<pre class="cython line score-0"> <span class="">125</span>: property __array_struct__:</pre> +<pre class="cython line score-0"> <span class="">126</span>: "Allows other numerical packages to obtain a new object."</pre> +<pre class="cython line score-3" onclick='toggleDiv(this)'>+<span class="">127</span>: def __get__(self):</pre> +<pre class='cython code score-3 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_6numind_6NumInd_16__array_struct___1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_16__array_struct_____get__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_16__array_struct_____get__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__get__", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.__array_struct__.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-4" onclick='toggleDiv(this)'>+<span class="">128</span>: if hasattr(self._undarray, "__array_struct__"):</pre> +<pre class='cython code score-4 '> __pyx_t_1 = __pyx_v_self->_undarray; + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_HasAttr</span>(__pyx_t_1, __pyx_n_s_array_struct);<span class='error_goto'> if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 128, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { +/* … */ + } +</pre><pre class="cython line score-3" onclick='toggleDiv(this)'>+<span class="">129</span>: return self._undarray.__array_struct__</pre> +<pre class='cython code score-3 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_self->_undarray, __pyx_n_s_array_struct);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">130</span>: else:</pre> +<pre class="cython line score-0"> <span class="">131</span>: # No an underlying array with __array_struct__</pre> +<pre class="cython line score-0"> <span class="">132</span>: # Deliver an equivalent PyCObject.</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">133</span>: Py_INCREF(self)</pre> +<pre class='cython code score-0 '> /*else*/ { + Py_INCREF(((PyObject *)__pyx_v_self)); +</pre><pre class="cython line score-6" onclick='toggleDiv(this)'>+<span class="">134</span>: return PyCapsule_New(<void*>self.inter,</pre> +<pre class='cython code score-6 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r); +/* … */ + __pyx_t_1 = <span class='py_c_api'>PyCapsule_New</span>(((void *)__pyx_v_self->inter), ((char *)"struct array"), ((PyCapsule_Destructor)__pyx_f_6numind_free_array_interface));<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } +</pre><pre class="cython line score-0"> <span class="">135</span>: "struct array",</pre> +<pre class="cython line score-0"> <span class="">136</span>: <PyCapsule_Destructor>free_array_interface)</pre> +<pre class="cython line score-0"> <span class="">137</span>: </pre> +<pre class="cython line score-9" onclick='toggleDiv(this)'>+<span class="">138</span>: cdef PyArrayInterface *_get_array_interface(self):</pre> +<pre class='cython code score-9 '>static __pyx_t_6numind_PyArrayInterface *__pyx_f_6numind_6NumInd__get_array_interface(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + __pyx_t_6numind_PyArrayInterface *__pyx_v_inter; + PyObject *__pyx_v_undarray = 0; + PyObject *__pyx_v_data_address = 0; + PyObject *__pyx_v_typestr = 0; + PyObject *__pyx_v_obj = 0; + __pyx_t_6numind_PyArrayInterface *__pyx_r; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("_get_array_interface", 0); +/* … */ + /* function exit code */ + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); + <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>("numind.NumInd._get_array_interface", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_undarray); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_data_address); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_typestr); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_obj); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">139</span>: "Populates the array interface"</pre> +<pre class="cython line score-0"> <span class="">140</span>: cdef PyArrayInterface *inter</pre> +<pre class="cython line score-0"> <span class="">141</span>: cdef object undarray, data_address, typestr</pre> +<pre class="cython line score-0"> <span class="">142</span>: cdef object obj</pre> +<pre class="cython line score-0"> <span class="">143</span>: </pre> +<pre class="cython line score-1" onclick='toggleDiv(this)'>+<span class="">144</span>: undarray = self._undarray</pre> +<pre class='cython code score-1 '> __pyx_t_1 = __pyx_v_self->_undarray; + <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); + __pyx_v_undarray = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">145</span>: typestr = self.typestr</pre> +<pre class='cython code score-2 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_typestr);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_v_typestr = __pyx_t_1; + __pyx_t_1 = 0; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">146</span>: inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface))</pre> +<pre class='cython code score-0 '> __pyx_v_inter = ((__pyx_t_6numind_PyArrayInterface *)malloc((sizeof(__pyx_t_6numind_PyArrayInterface)))); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">147</span>: if inter is NULL:</pre> +<pre class='cython code score-0 '> __pyx_t_2 = ((__pyx_v_inter == NULL) != 0); + if (__pyx_t_2) { +/* … */ + } +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">148</span>: raise MemoryError()</pre> +<pre class='cython code score-5 '> <span class='py_c_api'>PyErr_NoMemory</span>(); <span class='error_goto'>__PYX_ERR(0, 148, __pyx_L1_error)</span> +</pre><pre class="cython line score-0"> <span class="">149</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">150</span>: inter.version = 2</pre> +<pre class='cython code score-0 '> __pyx_v_inter->version = 2; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">151</span>: inter.nd = self._nd</pre> +<pre class='cython code score-0 '> __pyx_t_3 = __pyx_v_self->_nd; + __pyx_v_inter->nd = __pyx_t_3; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">152</span>: inter.typekind = ord(typestr[1])</pre> +<pre class='cython code score-5 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_Ord</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(__pyx_t_4 == (long)(Py_UCS4)-1)) __PYX_ERR(0, 152, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->typekind = __pyx_t_4; +</pre><pre class="cython line score-18" onclick='toggleDiv(this)'>+<span class="">153</span>: inter.itemsize = int(typestr[2:])</pre> +<pre class='cython code score-18 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetSlice</span>(__pyx_v_typestr, 2, 0, NULL, NULL, &__pyx_slice__2, 1, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyNumber_Int</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->itemsize = __pyx_t_3; +/* … */ + __pyx_slice__2 = <span class='py_c_api'>PySlice_New</span>(__pyx_int_2, Py_None, Py_None);<span class='error_goto'> if (unlikely(!__pyx_slice__2)) __PYX_ERR(0, 153, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_slice__2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_slice__2); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">154</span>: inter.flags = 0 # initialize flags</pre> +<pre class='cython code score-0 '> __pyx_v_inter->flags = 0; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">155</span>: if typestr[0] == '|':</pre> +<pre class='cython code score-5 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_2 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_5, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 155, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_2) { +/* … */ + goto __pyx_L4; + } +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">156</span>: inter.flags = inter.flags | NOTSWAPPED</pre> +<pre class='cython code score-19 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_NOTSWAPPED);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_5, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_6); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 156, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-26" onclick='toggleDiv(this)'>+<span class="">157</span>: elif byteorder[typestr[0]] == sys.byteorder:</pre> +<pre class='cython code score-26 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_byteorder);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_typestr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_5 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_6, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_sys);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_1, __pyx_n_s_byteorder);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = <span class='py_c_api'>PyObject_RichCompare</span>(__pyx_t_5, __pyx_t_6, Py_EQ); <span class='refnanny'>__Pyx_XGOTREF</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 157, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { +/* … */ + } + __pyx_L4:; +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">158</span>: inter.flags = inter.flags | NOTSWAPPED</pre> +<pre class='cython code score-19 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_NOTSWAPPED);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_5 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_1, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 158, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">159</span>: if not self.readonly:</pre> +<pre class='cython code score-5 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_readonly);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 159, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_7 = ((!__pyx_t_2) != 0); + if (__pyx_t_7) { +/* … */ + } +</pre><pre class="cython line score-19" onclick='toggleDiv(this)'>+<span class="">160</span>: inter.flags = inter.flags | WRITEABLE</pre> +<pre class='cython code score-19 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_inter->flags);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5); + __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_WRITEABLE);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_t_1 = <span class='py_c_api'>PyNumber_Or</span>(__pyx_t_5, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0; + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 160, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inter->flags = __pyx_t_3; +</pre><pre class="cython line score-0"> <span class="">161</span>: # XXX how to determine the ALIGNED flag?</pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">162</span>: inter.strides = self._strides</pre> +<pre class='cython code score-0 '> __pyx_t_8 = __pyx_v_self->_strides; + __pyx_v_inter->strides = __pyx_t_8; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">163</span>: inter.shape = self._shape</pre> +<pre class='cython code score-0 '> __pyx_t_8 = __pyx_v_self->_shape; + __pyx_v_inter->shape = __pyx_t_8; +</pre><pre class="cython line score-0"> <span class="">164</span>: # Get the data address</pre> +<pre class="cython line score-8" onclick='toggleDiv(this)'>+<span class="">165</span>: obj = undarray.__array_interface__["data"]</pre> +<pre class='cython code score-8 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_undarray, __pyx_n_s_array_interface);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_6 = <span class='py_c_api'>PyObject_GetItem</span>(__pyx_t_1, __pyx_n_s_data);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 165, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_obj = __pyx_t_6; + __pyx_t_6 = 0; +</pre><pre class="cython line score-2" onclick='toggleDiv(this)'>+<span class="">166</span>: data_address = obj[0]</pre> +<pre class='cython code score-2 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 166, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6); + __pyx_v_data_address = __pyx_t_6; + __pyx_t_6 = 0; +</pre><pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">167</span>: inter.data = <void*>PyInt_AsLong(data_address)</pre> +<pre class='cython code score-5 '> __pyx_v_inter->data = ((void *)<span class='py_c_api'>PyInt_AsLong</span>(__pyx_v_data_address)); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">168</span>: return inter</pre> +<pre class='cython code score-0 '> __pyx_r = __pyx_v_inter; + goto __pyx_L0; +</pre><pre class="cython line score-0"> <span class="">169</span>: </pre> +<pre class="cython line score-0"> <span class="">170</span>: </pre> +<pre class="cython line score-0"> <span class="">171</span>: # This is just an example on how to modify the data in C space</pre> +<pre class="cython line score-0"> <span class="">172</span>: # (and at C speed! :-)</pre> +<pre class="cython line score-5" onclick='toggleDiv(this)'>+<span class="">173</span>: def modify(self):</pre> +<pre class='cython code score-5 '>/* Python wrapper */ +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_6numind_6NumInd_2modify[] = "Modify the values of the underlying array"; +static PyObject *__pyx_pw_6numind_6NumInd_3modify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("modify (wrapper)", 0); + __pyx_r = __pyx_pf_6numind_6NumInd_2modify(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} + +static PyObject *__pyx_pf_6numind_6NumInd_2modify(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + long *__pyx_v_ldata; + double *__pyx_v_fdata; + int __pyx_v_i; + PyObject *__pyx_r = NULL; + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("modify", 0); +/* … */ + /* function exit code */ + __pyx_r = Py_None; <span class='pyx_macro_api'>__Pyx_INCREF</span>(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); + <span class='pyx_c_api'>__Pyx_AddTraceback</span>("numind.NumInd.modify", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r); + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); + return __pyx_r; +} +</pre><pre class="cython line score-0"> <span class="">174</span>: "Modify the values of the underlying array"</pre> +<pre class="cython line score-0"> <span class="">175</span>: cdef long *ldata</pre> +<pre class="cython line score-0"> <span class="">176</span>: cdef double *fdata</pre> +<pre class="cython line score-0"> <span class="">177</span>: cdef int i</pre> +<pre class="cython line score-0"> <span class="">178</span>: </pre> +<pre class="cython line score-0"> <span class="">179</span>: # Modify just the first row</pre> +<pre class="cython line score-14" onclick='toggleDiv(this)'>+<span class="">180</span>: if chr(self.inter.typekind) == 'i':</pre> +<pre class='cython code score-14 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_1, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) <span class='error_goto'>__PYX_ERR(0, 180, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { +/* … */ + goto __pyx_L3; + } +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">181</span>: ldata = <long *>self.inter.data</pre> +<pre class='cython code score-0 '> __pyx_v_ldata = ((long *)__pyx_v_self->inter->data); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">182</span>: for i from 0 <= i < self.inter.shape[self.inter.nd-1]:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">183</span>: ldata[i] = ldata[i] + 1</pre> +<pre class='cython code score-0 '> (__pyx_v_ldata[__pyx_v_i]) = ((__pyx_v_ldata[__pyx_v_i]) + 1); + } +</pre><pre class="cython line score-14" onclick='toggleDiv(this)'>+<span class="">184</span>: elif chr(self.inter.typekind) == 'f':</pre> +<pre class='cython code score-14 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_char</span>(__pyx_v_self->inter->typekind);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2); + <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); + <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_chr, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1); + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (<span class='pyx_c_api'>__Pyx_PyString_Equals</span>(__pyx_t_1, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) <span class='error_goto'>__PYX_ERR(0, 184, __pyx_L1_error)</span> + <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { +/* … */ + } + __pyx_L3:; +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">185</span>: fdata = <double *>self.inter.data</pre> +<pre class='cython code score-0 '> __pyx_v_fdata = ((double *)__pyx_v_self->inter->data); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">186</span>: for i from 0 <= i < self.inter.shape[self.inter.nd-1]:</pre> +<pre class='cython code score-0 '> __pyx_t_4 = (__pyx_v_self->inter->shape[(__pyx_v_self->inter->nd - 1)]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">187</span>: fdata[i] = fdata[i] + 1</pre> +<pre class='cython code score-0 '> (__pyx_v_fdata[__pyx_v_i]) = ((__pyx_v_fdata[__pyx_v_i]) + 1.0); + } +</pre><pre class="cython line score-0"> <span class="">188</span>: </pre> +<pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">189</span>: def __dealloc__(self):</pre> +<pre class='cython code score-0 '>/* Python wrapper */ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_6numind_6NumInd_5__dealloc__(PyObject *__pyx_v_self) { + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__dealloc__ (wrapper)", 0); + __pyx_pf_6numind_6NumInd_4__dealloc__(((struct __pyx_obj_6numind_NumInd *)__pyx_v_self)); + + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); +} + +static void __pyx_pf_6numind_6NumInd_4__dealloc__(struct __pyx_obj_6numind_NumInd *__pyx_v_self) { + <span class='refnanny'>__Pyx_RefNannyDeclarations</span> + <span class='refnanny'>__Pyx_RefNannySetupContext</span>("__dealloc__", 0); +/* … */ + /* function exit code */ + <span class='refnanny'>__Pyx_RefNannyFinishContext</span>(); +} +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">190</span>: free(self._shape)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->_shape); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">191</span>: free(self._strides)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->_strides); +</pre><pre class="cython line score-0" onclick='toggleDiv(this)'>+<span class="">192</span>: free(self.inter)</pre> +<pre class='cython code score-0 '> free(__pyx_v_self->inter); +</pre></div></body></html> diff --git a/pymolfile/molfile/signedintbuf-cython/numind.pyx b/pymolfile/molfile/signedintbuf-cython/numind.pyx new file mode 100644 index 0000000000000000000000000000000000000000..4e9aa817ab369c7bd8baf27906d9d17a0bd04df8 --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/numind.pyx @@ -0,0 +1,268 @@ +# This Pyrex extension class can take a numpy/numarray/Numeric object +# as a parameter and wrap it so that its information can be accessed +# in a standard way, both in Python space and C space. +# +# Heavily based on an idea of Andrew Straw. See +# http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex +# Very inspiring! :-) +# +# First version: 2006-03-25 +# Last update: 2006-03-25 +# Author: Francesc Altet + +import sys +from cpython.pycapsule cimport * + +cdef extern from "Python.h": + ctypedef int Py_intptr_t + ctypedef object PyObject + long PyInt_AsLong(object) + void Py_INCREF(object) + void Py_DECREF(object) + +cdef extern from "stdlib.h": + ctypedef long size_t + ctypedef long intptr_t + void *malloc(size_t size) + void free(void* ptr) + +cdef extern from "string.h": + int strncmp(const char *str1, const char *str2, size_t n) + +cdef extern from "vmdplugin.h": + ctypedef struct vmdplugin_t + ctypedef int (*vmdplugin_register_cb)(void *, vmdplugin_t *); + +cdef extern from "molfile_plugin.h": + ctypedef struct molfile_atom_t + ctypedef struct molfile_timestep_t + ctypedef struct molfile_plugin_t + +cdef extern from "libmolfile_plugin.h": + MOLFILE_INIT_ALL() + MOLFILE_REGISTER_ALL(void* , vmdplugin_register_cb) + MOLFILE_FINI_ALL() + +# for PyArrayInterface: +CONTIGUOUS=0x01 +FORTRAN=0x02 +ALIGNED=0x100 +NOTSWAPPED=0x200 +WRITEABLE=0x400 + +# for VMDPLUGIN +VMDPLUGIN_SUCCESS=0 +VMDPLUGIN_ERROR=-1 +vmdplugin_ABIVERSION=17 +MAXPLUGINS=200 + +# byteorder dictionary +byteorder = {'<':'little', '>':'big'} + +cdef int numplugins = 0 +cdef (molfile_plugin_t*) plugin_list = NULL + +ctypedef struct PyArrayInterface: + int version # contains the integer 2 as a sanity check + int nd # number of dimensions + char typekind # kind in array --- character code of typestr + int itemsize # size of each element + int flags # flags indicating how the data should be interpreted + Py_intptr_t *shape # A length-nd array of shape information + Py_intptr_t *strides # A length-nd array of stride information + void *data # A pointer to the first element of the array + +ctypedef struct MolObject: + molfile_plugin_t* plugin + void* file_handle + int natoms + +cdef void* free_array_interface(object arr): + Py_DECREF(arr) + +cdef molfile_plugin_t* get_plugin(molfile_plugin_t** plug_list, int plug_no): + cdef molfile_plugin_t* plugin; + if(plug_no < 0): + plugin = NULL + else: + plugin = plug_list[plug_no] + return plugin + +cdef int molfile_register(void* ptr, vmdplugin_t *plugin): + global numplugins, plugin_list + if (plugin.type is NULL or + plugin.name is NULL or + plugin.author is NULL): + return VMDPLUGIN_ERROR + elif plugin.abiversion != vmdplugin_ABIVERSION: + return VMDPLUGIN_ERROR + elif 0 != strncmp(plugin.type, "mol file", 8): + return VMDPLUGIN_ERROR + elif numplugins >= MAXPLUGINS: + return VMDPLUGIN_ERROR + + plugin_list[numplugins] = <molfile_plugin_t *> plugin + numplugins = numplugins + 1 + return VMDPLUGIN_SUCCESS + +cdef molfile_plugin_t** molfile_plugin_list(int maxsize): + global numplugins, plugin_list + if maxsize < MAXPLUGINS: + maxsize = MAXPLUGINS + plugin_list = <molfile_plugin_t**>malloc(sizeof(molfile_plugin_t*)*maxsize) + return plugin_list + +cdef int molfile_init(void): + global numplugins, plugin_list + MOLFILE_INIT_ALL + MOLFILE_REGISTER_ALL(NULL,molfile_register) + return numplugins + +cdef int molfile_finish(void): + MOLFILE_FINI_ALL + return 0 + +cdef class NumCy: + cdef void *data + cdef int _nd + cdef Py_intptr_t *_shape + cdef Py_intptr_t *_strides + cdef PyArrayInterface *inter + cdef MolObject *plugin_handle + cdef object _t_shape, _t_strides, _undarray + + def __init__(self): + cdef int i, stride + cdef object array_shape, array_strides + cdef molfile_plugin_t *plugin; + cdef void *file_handle; + + # Initialize available VMD molfile plugins + + + # Keep a reference to the underlying object + self.plugin_handle = molpack; + self._undarray = undarray + # Get the shape and strides C arrays + array_shape = undarray.__array_interface__["shape"] + self._t_shape = array_shape + # The number of dimensions + self._nd = len(array_shape) + # The shape + self._shape = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + for i from 0 <= i < self._nd: + self._shape[i] = self._t_shape[i] + # The strides (compute them if needed) + array_strides = undarray.__array_interface__["strides"] + self._t_strides = array_strides + self._strides = <Py_intptr_t *>malloc(self._nd*sizeof(Py_intptr_t)) + if array_strides: + for i from 0 <= i < self._nd: + self._strides[i] = array_strides[i] + else: + # strides is None. Compute them explicitely. + self._t_strides = [0] * self._nd + stride = int(self.typestr[2:]) + for i from self._nd > i >= 0: + self._strides[i] = stride + self._t_strides[i] = stride + stride = stride * array_shape[i] + self._t_strides = tuple(self._t_strides) + # Populate the C array interface + self.inter = self._get_array_interface() + + # Properties. This are visible from Python space. + # Add as many as you want. + + property undarray: # Returns the underlying array + def __get__(self): + return self._undarray + + property shape: + def __get__(self): + return self._t_shape + + property strides: + def __get__(self): + return self._t_strides + + property typestr: + def __get__(self): + return self._undarray.__array_interface__["typestr"] + + property typekind: + def __get__(self): + return chr(self.inter.typekind) + + property readonly: + def __get__(self): + return self._undarray.__array_interface__["data"][1] + + property __array_struct__: + "Allows other numerical packages to obtain a new object." + def __get__(self): + if hasattr(self._undarray, "__array_struct__"): + return self._undarray.__array_struct__ + else: + # No an underlying array with __array_struct__ + # Deliver an equivalent PyCObject. + Py_INCREF(self) + return PyCapsule_New(<void*>self.inter, + "struct array", + <PyCapsule_Destructor>free_array_interface) + + cdef PyArrayInterface *_get_array_interface(self): + "Populates the array interface" + cdef PyArrayInterface *inter + cdef object undarray, data_address, typestr + cdef object obj + + undarray = self._undarray + typestr = self.typestr + inter = <PyArrayInterface *>malloc(sizeof(PyArrayInterface)) + if inter is NULL: + raise MemoryError() + + inter.version = 2 + inter.nd = self._nd + inter.typekind = ord(typestr[1]) + inter.itemsize = int(typestr[2:]) + inter.flags = 0 # initialize flags + if typestr[0] == '|': + inter.flags = inter.flags | NOTSWAPPED + elif byteorder[typestr[0]] == sys.byteorder: + inter.flags = inter.flags | NOTSWAPPED + if not self.readonly: + inter.flags = inter.flags | WRITEABLE + # XXX how to determine the ALIGNED flag? + inter.strides = self._strides + inter.shape = self._shape + # Get the data address + obj = undarray.__array_interface__["data"] + data_address = obj[0] + inter.data = <void*>PyInt_AsLong(data_address) + return inter + + + # This is just an example on how to modify the data in C space + # (and at C speed! :-) + def modify(self): + "Modify the values of the underlying array" + cdef long *ldata + cdef double *fdata + cdef int i + + # Modify just the first row + if chr(self.inter.typekind) == 'i': + ldata = <long *>self.inter.data + for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + ldata[i] = ldata[i] + 1 + elif chr(self.inter.typekind) == 'f': + fdata = <double *>self.inter.data + for i from 0 <= i < self.inter.shape[self.inter.nd-1]: + fdata[i] = fdata[i] + 1 + + def __dealloc__(self): + free(self._shape) + free(self._strides) + free(self.inter) diff --git a/pymolfile/molfile/signedintbuf-cython/numind.so b/pymolfile/molfile/signedintbuf-cython/numind.so new file mode 100755 index 0000000000000000000000000000000000000000..f8b762476eb1d362018f305fce67cf22ec134e2f Binary files /dev/null and b/pymolfile/molfile/signedintbuf-cython/numind.so differ diff --git a/pymolfile/molfile/signedintbuf-cython/test_numpy_swig.py b/pymolfile/molfile/signedintbuf-cython/test_numpy_swig.py new file mode 100644 index 0000000000000000000000000000000000000000..d53a1b1d2874a0a7592975989918f36a5e0be95d --- /dev/null +++ b/pymolfile/molfile/signedintbuf-cython/test_numpy_swig.py @@ -0,0 +1,42 @@ +import numpy +import ctypes +import numind + +# Create an arbitrary object for each package +np=numpy.arange(12, dtype=numpy.float) +#np=numpy.arange(12) +np.shape = (4,3) + +#ns = _numpy_swig(2,2) +#print(ns) + + +# Wrap the different objects with the NumInd class +# and execute some actions on it +##for obj in [np]: +# ni = _numpy_swig +# print("original object type-->", type(ni.inter)) +# # Print some values +# #print("typestr --> {0}", ni.typestr) +# #print("shape --> {0}", ni.shape) +# #print("strides --> {0}", ni.strides) +# npa = numpy.asarray(ni) +# print("object after a numpy re-wrapping --> " , npa) +# #ni.modify() +# #print("object after modification in C space --> {0}", npa) + +# Wrap the different objects with the NumInd class +# and execute some actions on it +for obj in [np]: + ni = numind.NumInd(obj) + print("original object type-->", type(ni.undarray)) + # Print some values + print("typestr -->", ni.typestr) + print("typekind -->", ni.typekind) + print("shape -->", ni.shape) + print("strides -->", ni.strides) + npa = numpy.asarray(ni) + print("object after a numpy re-wrapping -->", npa) + ni.modify() + print("object after modification in C space -->", npa) + diff --git a/pymolfile/molfile/test-backup.py b/pymolfile/molfile/test-backup.py new file mode 100644 index 0000000000000000000000000000000000000000..5490a0527f0962ff0c1a8f03b48acdb476bf437c --- /dev/null +++ b/pymolfile/molfile/test-backup.py @@ -0,0 +1,153 @@ +import numpy +import ctypes +import _libpymolfile + +class molatom_t(ctypes.Structure): + _fields_ = [ + ('name', ctypes.c_char * 16), + ('type', ctypes.c_char * 16), + ('resname', ctypes.c_char * 8), + ('resid', ctypes.c_uint8), + ('segid', ctypes.c_char * 8), + ('chain', ctypes.c_char * 2), + ('altloc', ctypes.c_char * 2), + ('insertion', ctypes.c_char *2), + ('occupancy', ctypes.c_float), + ('bfactor', ctypes.c_float), + ('mass', ctypes.c_float), + ('charge', ctypes.c_float), + ('radius', ctypes.c_float), + ('atomicnumber', ctypes.c_uint8), + ('ctnumber', ctypes.c_uint8), + ] + +class molplugin_t(ctypes.Structure): + _fields_ = [ + ('abiversion', ctypes.c_uint8), + ('type', ctypes.c_char_p), + ('name', ctypes.c_char_p), + ('prettyname', ctypes.c_char_p), + ('author', ctypes.c_char_p), + ('majorv', ctypes.c_uint8), + ('minorv', ctypes.c_uint8), + ('is_reentrant', ctypes.c_uint8), + ('filename_extension', ctypes.c_char_p), + ('open_file_read', ctypes.CFUNCTYPE(ctypes.c_char_p, + ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8))), + ('read_structure', ctypes.CFUNCTYPE(ctypes.c_void_p, + ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(molatom_t))), + ('read_bonds', ctypes.CFUNCTYPE(ctypes.c_void_p, + ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), + ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint), + ctypes.c_char_p)), + ('read_next_timestep', ctypes.c_int8), + ('close_file_read', ctypes.c_void_p), + ('open_file_write', ctypes.c_void_p), + ('write_structure', ctypes.c_int8), + ('write_timestep', ctypes.c_int8), + ('close_file_write', ctypes.c_void_p), + ('read_volumetric_metadata', ctypes.c_int8), + ('read_volumetric_data', ctypes.c_int8), + ('read_volumetric_data_ex', ctypes.c_int8), + ('read_rawgraphics', ctypes.c_int8), + ('read_molecule_metadata', ctypes.c_int8), + ('write_bonds', ctypes.c_int8), + ('write_volumetric_data', ctypes.c_int8), + ('write_volumetric_data_ex', ctypes.c_int8), + ('read_angles', ctypes.c_int8), + ('write_angles', ctypes.c_int8), + ('read_qm_metadata', ctypes.c_int8), + ('read_qm_rundata', ctypes.c_int8), + ('read_timestep', ctypes.c_int8), + ('read_timestep_metadata', ctypes.c_int8), + ('read_qm_timestep_metadata', ctypes.c_int8), + ('read_timestep2', ctypes.c_int8), + ('read_times', ctypes.c_ssize_t), + ('cons_fputs', ctypes.c_uint8) + ] + +class moltimestep_t(ctypes.Structure): + _fields_ = [ + ('coords', ctypes.POINTER(ctypes.c_float)), + ('velocities', ctypes.POINTER(ctypes.c_float)), + ('A', ctypes.c_float), + ('B', ctypes.c_float), + ('C', ctypes.c_float), + ('alpha', ctypes.c_float), + ('beta', ctypes.c_float), + ('gamma', ctypes.c_float), + ('physical_time', ctypes.c_double), + ('total_energy', ctypes.c_double), + ('potential_energy', ctypes.c_double), + ('kinetic_energy', ctypes.c_double), + ('extended_energy', ctypes.c_double), + ('force_energy', ctypes.c_double), + ('total_pressure', ctypes.c_double) + ] + +class molhandle_t(ctypes.Structure): + _fields_ = [ + ('plugin', ctypes.POINTER(molplugin_t)), + ('file_handle', ctypes.c_void_p), + ('natoms', ctypes.c_int) + ] + +class molnatoms(ctypes.Structure): + _fields_ = [ + ('natoms', ctypes.c_int) + ] + +#callback_t = ctypes.CFUNCTYPE(None, ctypes.POINTER(molatom_t)) + +def get_open_file_read(output): + ctypes.open_file_read.restype = ctypes.POINTER(molhandle_t) + ctypes.open_file_read.argtypes = [ctypes.POINTER(molplugin_t), ctypes.c_void_p, ctypes.c_uint8] + return ctypes.pythonapi.PyCapsule_GetPointer(output, "plugin") + +def get_capsule(capsule): + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + return ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + +def get_plugincapsule(capsule): + data = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + data = ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + return data + +def get_plugindata(capsule): + data = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.POINTER(molhandle_t) + ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] + data = ctypes.pythonapi.PyCapsule_GetPointer(capsule, b"plugin") + return data + +mylib = _libpymolfile +mylist = mylib.molfile_plugin_list(200) +numlist = mylib.molfile_init() +print(numlist) +for i in range(numlist): + testplugin = mylib.molfile_plugin_info(mylist, i) + print(i, testplugin) + +plugin = mylib.get_plugin(mylist, 81) +print(plugin) +natoms=0 +numatoms=molnatoms(natoms) +fname="../../test/md.gro" +ftype="gro" + +pluginhandle = mylib.open_file_read(plugin, fname, ftype, natoms) +print("This passed") +print(pluginhandle) +print("This passed too") +print(pluginhandle.natoms) +print("Here") +outarray = mylib.get_structure(pluginhandle) +print(outarray) +#print(type(outarray)) +#for i in outarray: +# print(i) + + diff --git a/pymolfile/molfile/test.py b/pymolfile/molfile/test.py index afca74ed4fb9117e100c586e16cbb94e359dd340..65c178d3dce637aede004256e4efa638ba39d4a1 100644 --- a/pymolfile/molfile/test.py +++ b/pymolfile/molfile/test.py @@ -131,12 +131,29 @@ for i in range(numlist): testplugin = mylib.molfile_plugin_info(mylist, i) print(i, testplugin) -plugin = mylib.get_plugin(mylist, 81) +#plugin = mylib.get_plugin(mylist, 99) #pdb +#plugin = mylib.get_plugin(mylist, 83) #trr +#plugin = mylib.get_plugin(mylist, 85) #xtc +plugin = mylib.get_plugin(mylist, 105) #psf +#plugin = mylib.get_plugin(mylist, 81) #gro +#plugin = mylib.get_plugin(mylist, 69) #dcd print(plugin) natoms=0 numatoms=molnatoms(natoms) -fname="../../test/md.gro" -ftype="gro" +#fname="../../test/DPDP.pdb" +#fname="../../test/md.gro" +#fname="../../test/ala3.dcd" +#fname="../../test/ala3.pdb" +fname="../../test/ala3.psf" +#fname="../../test/md.trr" +#fname="../../test/md.xtc" +#fname="../../test/md_1u19.xtc" +#ftype="pdb" +#ftype="trr" +#ftype="xtc" +ftype="psf" +#ftype="gro" +#ftype="dcd" pluginhandle = mylib.open_file_read(plugin, fname, ftype, natoms) print("This passed") @@ -144,8 +161,31 @@ print(pluginhandle) print("This passed too") print(pluginhandle.natoms) print("Here") -outarray = mylib.read_structure(pluginhandle) -print(outarray) + +x = numpy.array([ + ('C1','C','ACE',0,'','','','',1.0,1.0,12.011,6,1.0,6), + ('C2','C','ACE',0,'','','','',1.0,1.0,12.011,6,1.0,6) + ], + dtype=[ + ('name', 'S16'), ('type', 'S16'), ('resname', 'S8'), + ('resid', 'i4'), ('segid', 'S8'), ('chain', 'S2'), + ('altloc', 'S2'), ('insertion', 'S2'), ('occupancy', 'f8'), + ('bfactor', 'f8'), ('mass', 'f8'), ('charge', 'f8'), + ('radius', 'f8'), ('atomicnumber', 'i4') + ] + ) +print(x) +print(x.__array_interface__) +print(x.__array_interface__["descr"]) +print(x.__array_struct__) +y = mylib.read_fill_structure(pluginhandle, x) +#y = mylib.print_array_struct(x) +print(y) +print(len(y)) +print(y.__array_interface__) +print(y.__array_interface__["descr"]) +#outarray = mylib.get_structure(pluginhandle) +#print(outarray) #print(type(outarray)) #for i in outarray: # print(i) diff --git a/pymolfile/molfile/test_numpy_swig.py b/pymolfile/molfile/test_numpy_swig.py new file mode 100644 index 0000000000000000000000000000000000000000..9ea2632148e309ae10dbfdb8f95b862366a106c3 --- /dev/null +++ b/pymolfile/molfile/test_numpy_swig.py @@ -0,0 +1,46 @@ +import numpy +import ctypes +import _numpy_swig +#import numind + +ns = _numpy_swig + +# Create an arbitrary object for each package +np=numpy.arange(12) +np.shape = (4,3) + +newSIB = ns.new_SignedIntBuf(np.shape[0], np.shape[1]) +print(newSIB) +struct = ns.get__array_struct__(np) +print(struct) +ns.delete_SignedIntBuf(newSIB) + + +# Wrap the different objects with the NumInd class +# and execute some actions on it +#for obj in [np]: +# ni = _numpy_swig +# print("original object type-->", ni) +# # Print some values +# #print("typestr --> {0}", ni.typestr) +# #print("shape --> {0}", ni.shape) +# print("strides --> {0}", ni) +# npa = numpy.asarray(ni) +# print("object after a numpy re-wrapping --> " , npa) +# #ni.modify() +# #print("object after modification in C space --> {0}", npa) + +# Wrap the different objects with the NumInd class +# and execute some actions on it +#for obj in [np]: +# ni = numind.NumInd(obj) +# print("original object type-->", type(ni.undarray)) +# # Print some values +# print("typestr -->", ni.typestr) +# print("shape -->", ni.shape) +# print("strides -->", ni.strides) +# npa = numpy.asarray(ni) +# print("object after a numpy re-wrapping -->", npa) +# ni.modify() +# print("object after modification in C space -->", npa) +