How to pass a tuple of slice objects to C via the python-C api -


I have 2D matrix class in C that I am using in Python. I want to be able to call a matrix class by passing a tulip of slice object, e.g. A [1: 2,1: 2]. So far what do I have to do is look like the relevant code for the following __getitem __ method

  int __getitem __ (PyObject * slice) {// piece of objects Receive Tupal PyObject * slice1; // Announce the first slice object PyObject * slice2; // Announce the second slice object slice1 = PyTuple_GetItem (slices, 0); // Get the piece before the Tuol Slice 2 = PyTuple_GetItem (Slice, 1); // Get second piece from Tuol / start and stop the first slice (currently the following three lines do not work) Py_ssize_t start, stop, move, length; PySlice_GetIndicesEx (slice1, length, & amp; begin, & amp; stop, & amp; step); Return PESliciceHack (Slice 2); }   

This code checks whether slice2 is actually a piece object using the PySlice_Check method. If I comment on PySlice_GetIndicesEx (slice 1, length, and start, end stop, and phase), I get 1 as expected, however, if I get this line I get an error:

  with 'PyObject * {aka _object *}', for argument '1', 'int PySlice_GetIndicesEx (' .. 'for' emigrating object '. .   

Which means that I can not pass slice 1 or slice 2 into PySlice_GetIndicesEx because the PySliceObject object for it Required. How do I resolve the slice object properly, so I can pass it in PySlice_GetIndicesEx. In this function PySliceObject What's that which is slice1 and slice2, even if PySlice_Check (slice1) and PySlice_Check (slice2) both return a and a PyObject 1.

Here's the solution to the solution:

  int __getitem __ (PyObject * slice) {PyObject * slice1; PyObject * slice2; slice1 = PyTuple_GetItem (slices, 0); Slice 2 = PETplay_get item (slice, 1); Foot_scid_t lane = 0, seat1 = 0, stop1 = 0, step1 = 0, sicceland1 = 0; T2 = 0, stop2 = 0, step 2 = 0, sublimeth2 = 0; Len = (* self) .ize () // Or you get the length of Slapse Paisalis_Get Indexx ((pyasloius object *) slice 1, lane, and start1, end stop 1, and stap1, and skyland 1) ; PySlice_GetIndicesEx ((PySliceObject *) slice2, lane, & amp; start2, & amp; stop2, & amp; phase 2, & amp; slicelength2); Return 0;   

Here the key is to pass the (Peslice object *) slice 1, which passes the slice object as PySliceObject .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -