[Pyrex] using numpy arrays and random number generators in Pyrex

Robert Kern robert.kern at gmail.com
Wed Jan 31 18:00:32 UTC 2007


Mark P. Miller wrote:
> This is likely a naive question on my part, but how do I use numpy's and 
> python's random number generators within a pyrex module?  Please note 
> that I have little experience with C, so any detailed descriptions would 
> be greatly appreciated.

Unfortunately, the C API for the random number generators is not exposed to
other modules. We are happy to accept contributions for this, and can give hints
to those who want to work on it, but we have not had time to do this ourselves.

> Same thing goes for numpy arrays.  Is there a correct way to pass a 
> numpy array to a pyrex function?

Yes! You can look at the source of numpy/random/mtrand.pyx for examples. Get the
latest from SVN as I've recently committed fixes for Pyrex 0.9.5. There is also
an example in numpy/doc/pyrex/ that uses a slightly different approach (a .pxd
instead of a .pxi to expose the numpy API).

Come join us on numpy-discussion if you have more numpy-specific questions.

  http://www.scipy.org/Mailing_Lists

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Pyrex mailing list