[SciPy-dev] def __array__

Robert Kern robert.kern@gmail....
Tue Aug 18 10:48:41 CDT 2009

On Tue, Aug 18, 2009 at 08:43, David Goldsmith<d_l_goldsmith@yahoo.com> wrote:
> Is this in the compiled C code also?
> Someone (I think it was Pierre) recently asked me if I checked the code to see how something worked.  I "took the fifth," but I feel I needn't have: the real reason I haven't made a habit of it recently is (and maybe this is just due to the late stage we're at in the doc game), more often than not, the explanation I seek is buried in the compiled C code, and thus unfindable by me, at least with the technology I have at my disposal, and thus I'm at the "mercy" of the list for various explanations.
> To wit: trying to flesh out the details of how chararray.argsort works - I go examine the code and all it does is call self.__array__.  chararray doesn't appear to have an __array__ method, and I can't find one in ndarray either, so after checking all other leads, I finally remember that the main def of ndarray is in the compiled C code.  What's an innocent to do?

[~]$ cd ~/svn/numpy/numpy/core/src
[src]$ grep -r __array__ .
# AHA!
./multiarray/methods.c:    {"__array__", (PyCFunction)array_getarray,
[src]$ grep -n array_getarray multiarray/methods.c
793:array_getarray(PyArrayObject *self, PyObject *args)
2032:    {"__array__", (PyCFunction)array_getarray,

And there you can see that ndarray.__array__ implementation is on line
793 of multiarray/methods.c .

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 Scipy-dev mailing list