[C++-sig] fancy indexing

Maik Beckmann beckmann.maik at googlemail.com
Tue Jan 13 18:11:17 CET 2009


Hello,

Question:
Is it possible do implement numpy like fancy indexing with boost.python?


Motivation: 
I'm playing with boost.python (and py++) to generate python bindings for some 
C++ code.  N-dimensional arrays are involved with an api like this
{{{
template<typename float_T, size_t N>
class Array
{
...
public:
Array(tr1::array<size_type,N> const& dims) ...

// arity actually done with BOOST_PP
reference operator()(size_type d0, ..., size_type dN) 
{ ... }
value_type operator()(size_type d0, ..., size_type dN) const
{ ... }
}}}

Now I like to do something like numpy is able to
  dims = (10,20,30)
  a = Array3(dims)
  a[0,0,0] = 1.0
  print a[0,0,0]
  

Observations:
A quick view in 
  numpy/src/core/arrayobject.c 
gives me the impression that they make an ndarray behave like a dict when its 
used like a[0,0...].  This for the tp_as_mapping slot in PyTypeObject seems to 
be set.

However, I'm not an expert at this matters.



Thanks in advance,
 -- Maik  



More information about the Cplusplus-sig mailing list