[Numpy-discussion] Best way to insert C code in numpy code

René Dudfield renesd@gmail....
Tue Sep 22 10:24:15 CDT 2009

On Tue, Sep 22, 2009 at 3:45 PM, Sturla Molden <sturla@molden.no> wrote:
> Xavier Gnata skrev:
>> I have a large 2D numpy array as input and a 1D array as output.
>> In between, I would like to use C code.
>> C is requirement because it has to be fast and because the algorithm
>> cannot be written in a numpy oriented way :( (no way...really).
> There are certain algorithms that cannot be vectorized, particularly
> those that are recursive/iterative.


one thing you can do is guess(predict) what the previous answer is and
continue on a path from that guess.  Say you have 1000 processing
units, you could get the other 999 working on guesses for the answers
and go from there.  If one of your guess paths is right, you might be
able to skip a bunch of steps.  That's what cpus do with their
'speculative execution and branch prediction'.  even more OT, you can
take advantage of this sometimes by getting the cpu to work out
multiple things for you at once by putting in well placed if/elses,
but that's fairly cpu specific.  It's also used with servers... you
ask say 5 servers to give you a result, and wait for the first one to
give you the answer.

That cython pure module looks cool, thanks for pointing it out.

I wonder if anyone has tried using that with traces?  So common paths
in your code record the types, and then can be used by the cython pure
module to try and generate the types for you?  It could generate a
file containing a {callable : @cython.locals} mapping to be used on
compilation.  Similar to how psyco works, but with a separate run
program/compilation step.


More information about the NumPy-Discussion mailing list