How to get python slicing to work with my c++ array class using SWIG -


I have an Array class defined in Array1D, c ++ which essentially wraps the STL vector class. I have expanded this class so that I can display different elements of the array vector. Here is the relevant code in my SWIG interface file:

  Namespace CSS {% Template (DBLector) vector & lt; Double> }% Array1D extension {double __getitem __ (int index) {return (* self) [index]; }}   

This allows me to access individual elements of the array in Python:

  & gt; & Gt; & Gt; A = array 1D (10) # creates a C ++ vector length of zero with zero-gt; & Gt; & Gt; A [0]> gt; & Gt; & Gt; 0   

I want to be able to call a [1: 3] , for example, though, I get a TypeError while trying it :

  typeError: In the method 'Array1D___getitem__', logic2 type 'int'    

The problem is that the dragon passes through a slice object when the slice type of getitem calls and your function definition is expecting an int you get getitem a variant of Which PyObject * takes as a parameter, then you must implement Skiising vector.

I'm not writing it without actually being tested to test it, so take it with a grain of salt. But I have to do something like the following

 % Extend Array1D {Array1D * __getitem __ (PyObject * param) {If (PySlice_Check (Ultimate)) {/ * Py_ssize_t may be required Instead ints * / int len ​​= 0, start = 0, stop = 0, step = 0, siceland = 0; LAN = THIS- & gt; Shape (); / * Or you get the shape of a vector * / pieslosi_gate indexx (Peslice object *), ultimate lane, and start, end stop, and action, and skylland; / * Here, do the stuff to return an Array1D which is the correct slice given starting / stop / step defined above / / / / * unexpected parameter, possibly an exception here * /}}  < / pre>  

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -