discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] vectors of vectors in python


From: Michael Dickens
Subject: Re: [Discuss-gnuradio] vectors of vectors in python
Date: Wed, 7 Feb 2007 10:31:05 -0500

On Feb 1, 2007, at 11:47 PM, Achilleas Anastasopoulos wrote:
private:
  std::vector< std::vector<int> > d_PS;
public:
  const std::vector< std::vector<int> > & PS () const { return d_PS; }

Here's a quick, partial answer. According to the SWIG docs & tutorials, what one needs to do is something like (these could be in struct's of class'es instead):

typedef std::vector<int> VecInt;
typedef std::vector<VecInt> VecInt2;

Then in Python (after compilation via SWIG -> C++), something like:

>>> import VecStuff
>>> a = VecInt ([1 2 3])
>>> b = VecInt ([4 5 6])
>>> c = VecInt2 (a, b)

Please note that 'a' and 'b' above do -not- need to be the same length, not for C++ nor SWIG nor Python, since this is not a "matrix" but just a vector of vectors.

The exact details remain to be figured out. The basic idea is that, in order for SWIG (and thus Python) to know what type of structure is being dealt with, one has to name all of the relevant parts of the structure. Thus

std::vector< std::vector<int> > V2Int;

won't work because SWIG can't name the internal "std::vector<int>" data. SWIG takes the approach of "separate and conquer". Hope this helps! - MLD




reply via email to

[Prev in Thread] Current Thread [Next in Thread]