Hi,

With recent version of NumPy, when we compile c code, by default it
raise a deprecation warning. To remore it, we must of only the new
NumPy C API and define a macro. The new API only exist for NumPy 1.6
and later, so if we want to support older NumPy we need to do more
work.

As Theano compile many c code that include NumPy, it generate too many
warning to the user. So I spend about 2 weeks to update Theano. Here
is what I did in hope that this help people.

In particular, I think cython can do the same. Currently they use only
the old interface as they want to support old NumPy version.

1) Define this macro when compiled again numpy:
NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

2) Replace the use of old macro to the new one and define new macro
that map the new one to the old one when compiling with old NumPy
version:

New macro = old macro

NPY_ARRAY_ENSURECOPY=NPY_ENSURECOPY
NPY_ARRAY_ALIGNED=NPY_ALIGNED
NPY_ARRAY_WRITEABLE=NPY_WRITEABLE
NPY_ARRAY_UPDATE_ALL=NPY_UPDATE_ALL
NPY_ARRAY_C_CONTIGUOUS=NPY_C_CONTIGUOUS
NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS

2) Do not access members of PyArrayObject directly, but use the old
macro(that are inline fct in newer NumPy) For example change
a_object->dimensions to PyArray_DIMS(a_object).

3) Another change is that the new API do not allow asignation to the
BASE attribute of an ndarray. To do this, you must call a function. So
we use this code that will work for all version of NumPy:

#if NPY_API_VERSION < 0x00000007
PyArray_BASE(xview) = py_%(x)s;
#else
PyArray_SetBaseObject(xview, py_%(x)s);
#endif


4) The new interface have no way to modify the data ptr of an ndarray.
The work around that we needed is to change our code such that we
create the ndarray directly with the good data ptr. In the past, we
created it with a temporary value, compute the one we want, and update
it. Now we create the ndarray directly with the good data ptr. This
was done in our subtensor code (a_ndarray[slice[,...]]) code.

5) Lastly, we have one c code file that is generated from cython code.
We modified manually this code to be compatible with the new NumPy API
to don't generate error, as we disable the old NumPy interface.

Here is the PR to Theano for this:
https://github.com/scikit-learn/scikit-learn/issues/2573

Hoping that this will help someone.

Frédéric
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to