On Thu, Jul 15, 2010 at 10:22 AM, Neal Becker <[email protected]> wrote:
> Robert Bradshaw wrote:
>
>> On Thu, Jul 15, 2010 at 7:24 AM, Neal Becker
>> <[email protected]> wrote:
>>> What is the current state of using cython to expose numpy arrays to c++
>>> code?
>>>
>>> I have the (typical) setup of python for high-level code, c++ for
>>> specialized algorithms.  I'm using numpy as the containers.
>>>
>>> My c++ algorithms are usually written to a generic c++
>>> (boost::range-based) interface.
>>>
>>> Currently, the best solution I know of is to use boost::python and
>>> pyublas to interface.
>>>
>>> Are there any cython examples?  Has any of the recent cython work made
>>> cython more attractive for this use?
>>
>> Are you trying to create C++ wrappers for NumPy arrays? In this case
>> Cython is almost certainly the wrong tool. The new C++ features allow
>> you to more easily use C++ libraries,  not write arbitrary C++ code.
>>
>> - Robert
>
> No, I already have lots of algorithms written in c++ for a generic range-
> based interface (templated).  These can be instantiated to use with any
> container types that fit the range concept.
>
> Right now I'm instantiating them using pyublas::numpy_vector as the
> containers, which allows me to use them from python with numpy.
>
> For example, consider this c++ algorithm:
>
> template<typename out_t, typename in_t>
> inline out_t repeat (in_t const& in, int cnt) {
>  out_t out (boost::size (in)*cnt);
>  typename boost::range_const_iterator<in_t>::type i = boost::begin (in);
>  typename boost::range_iterator<out_t>::type o = boost::begin (out);
>
>  for (; i != boost::end (in); ++i, o+=cnt) {
>    std::fill (o, (o+cnt), *i);
>  }
>
>  return out;
> }
>
> This could be used on a numpy vector, instantiated as:
>
> repeat<pyublas::numpy_vector<double>,pyublas::numpy_vector<double> >
>
> Could cython be used to instantiate and call this function, which takes
> a numpy vector<double> as input/output?

Sorry I completely misunderstood your question. Yes, this is something
you could do.

- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to