[C++-sig] more examples of automatic type conversion
Neal Becker
ndbecker2 at gmail.com
Thu May 3 01:51:31 CEST 2007
Eric Jonas wrote:
>> I'm very interested in interfacing various c++ array containers to numpy.
>> Do you have any small examples?
>>
>
> I think we all are, and the existing numpy/numeric interface is getting
> a bit crufty, and the new numpy type module is somewhat complex :) one
> thing I'm struggling with is my poor understanding of python's internal
> memory management and the like. I'll hopefully have the automatic type
> conversion working in a day or two, and I'll be sure to post my results
> to the list. I'm not trying to do anything fancy like the
> numeric/numarray stuff currently in boost; I just want functions that
> take in const boost::multi_array<T, n> & to handle the conversion for
> me. I want to mostly use my python as a scripting interface on top of
> some number-crunching C++ monte-carlo code.
>
> Interesting questions include: What sort of containers do we use?
> Boost::array? Boost::multiarray? The ublas containers? all of them? Just
> std::vector< std::vector (...) How do we handle the static typing
> problems?
>
I've used:
ublas::{vector,matrix}
boost::multi_array
blitz::array
Recently, I've been playing with blitz/python and I am starting to really
like it. OTOH, it doesn't seem to be a very active project and my
questions have gone largely unanswered. OTOH, the code is far easier to
comprehend (for me, at least) than the first 2 above, so I can pretty much
answer my own questions.
I like that blitz::array handles more than just 1/2 dimensions, and I am
starting to _really_ like that it does ref counting. That means I can do:
u = array1_int ((1,2,3,4))
u2 = u[::2]
and now u2 is a proxy for u. This behavior is (I believe) like numpy. Or:
u = array1_complex ((1,2,3,4))
u2 = real (u)
u2[:] = 7
Again, this will write to the real part of u. And, I haven't needed to even
think about ownership.
More information about the Cplusplus-sig
mailing list