numpy-cython

508 views
Skip to first unread message

pauld11718

unread,
May 8, 2015, 5:13:10 PM5/8/15
to cython...@googlegroups.com
Unable to compile :

import numpy as np
cimport numpy as np
import math as m

DTYPE = np.float
ctypedef np.float_t DTYPE_t

def visc1(float t, float dcal):
    cdef float h, tr, trinv, rhor
    cdef float eta0, sumi, i, sumj, im1, jm1, eta
   
    cdef np.ndarray vb = np.array([1.00000, 0.940695, 0.578377, -0.202044], dtype = DTYPE)
   
    cdef np.ndarray[DTYPE_t, ndim=2] va = np.array([[.4864192, .3509007, -.2847572, .07013759,.0164122, -.01163815,.0],
        [-.2448372,1.315436, -1.037026, .4660127, -.02884911,-.008239587,.0],
        [-.8702035, 1.297752, -1.287846, .2292075, .0,  .0, .0],
        [.8716056, 1.353448,  .0,  -.4857462, .1607171,.0,    -.003886659],
        [-1.051126, .0,   .0,   .0,   .0,      .0,   .0],
        [.3458395, .0,  -.02148229, .0, -.009603846, .004559914,.0]], dtype=DTYPE, ndim = 2)
   

    h=55.2651e-06;
    tr = t/643.89;
    trinv=643.89/t;
    rhor=dcal/0.358;

    eta0 = h*(m.pow(tr,0.5))/(vb[0] + vb[1]/tr + vb[2]/(tr*tr) + vb[3]/(tr**3));
    sumi=0.0
    for i in range(6):
        sumj=va[i,0]
        for j in range(2,7):
            jm1=j-1;
            sumj=sumj+va[i,j]*((rhor-1.0)**jm1);
           
        im1 = i-1
        sumi = sumi+sumj*((trinv-1.0)**im1);
       
    eta = eta0*m.exp(rhor*sumi)
    return eta

Error :
Compiling visco.pyx because it changed.
Cythonizing visco.pyx
running build_ext
building 'visco' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/deepraj/miniconda3/envs/venv1/include/python3.4m -c visco.c -o build/temp.linux-x86_64-3.4/visco.o
In file included from /usr/include/numpy/ndarraytypes.h:1761:0,
                 from /usr/include/numpy/ndarrayobject.h:17,
                 from /usr/include/numpy/arrayobject.h:4,
                 from visco.c:258:
/usr/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
gcc -pthread -shared build/temp.linux-x86_64-3.4/visco.o -L/home/abcd/miniconda3/envs/venv1/lib -lpython3.4m -o /media/abcd/Man_UTD/pythoncode/venv1/visco.cpython-34m.so

pauld11718

unread,
May 11, 2015, 1:56:14 AM5/11/15
to cython...@googlegroups.com
I guess it is with

cimport numpy as np

Some other simple cython code which has nothing to do with numpy array, if there is just the above declaration, similar error comes in.....
Any suggestion?

pauld11718

unread,
May 11, 2015, 1:56:18 AM5/11/15
to cython...@googlegroups.com
The setup.py is :

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np

setup(
    ext_modules=cythonize("visco.pyx"),
)

Daπid

unread,
May 11, 2015, 2:02:43 AM5/11/15
to cython...@googlegroups.com

On 9 May 2015 at 08:55, pauld11718 <pauld...@gmail.com> wrote:

setup(
    ext_modules=cythonize("visco.pyx"),
)

You need to pass numpy's headers. Here is how:

http://docs.cython.org/src/reference/compilation.html

I think there should be a note in the page on Cython for Numpy users. I will try to remember to put a PR together.

/David.

Giuseppe Attardi

unread,
May 13, 2015, 3:47:37 AM5/13/15
to cython...@googlegroups.com
I have always had the problem of deprecated NumPy API warning:

/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

I tried all possible suggested solution but none worked.
In my setup,py I have:

    Extension('deepnl/words',
              sources=["deepnl/words.pyx", "deepnl/WordsTrainer.cpp"],
              include_dirs=[np.get_include(),
                            "/usr/include/eigen3"],
              language="c++",
              extra_compile_args=["-fopenmp"]),

but still I get the warning. Notice that the documentation in the link suggested below, mentions
            include_path
instead of include_dirs, which is not what Python expects:

I can provide further details if needed, but I would like to see this issue solved.

Chris Barker - NOAA Federal

unread,
May 13, 2015, 11:15:16 AM5/13/15
to cython...@googlegroups.com

I have always had the problem of deprecated NumPy API warning:

To be clear -- it's a warning -- but your code still compiles and runs fine?

I agree that it's unfortunate that Cython is using a deprecated API, but I think what needs to happen is for Cython to be updated to use the newer APIs

I don't know if there is a technical reason for not doing that, or if it's just that no one has gotten around to it yet.

I suspect that at some point, we specifically wanted to support older numpy versions, but that may be no longer relevant.

But it's just a warning -- it will probably be a long time before numpy will actually remove that API.

Chris


--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Bradshaw

unread,
May 14, 2015, 12:23:29 AM5/14/15
to cython...@googlegroups.com
On Wed, May 13, 2015 at 8:15 AM, Chris Barker - NOAA Federal
<chris....@noaa.gov> wrote:
>
> I have always had the problem of deprecated NumPy API warning:
>
>
> To be clear -- it's a warning -- but your code still compiles and runs fine?
>
> I agree that it's unfortunate that Cython is using a deprecated API, but I
> think what needs to happen is for Cython to be updated to use the newer APIs
>
> I don't know if there is a technical reason for not doing that, or if it's
> just that no one has gotten around to it yet.
>
> I suspect that at some point, we specifically wanted to support older numpy
> versions, but that may be no longer relevant.

Yep, that's my understanding as well.

> But it's just a warning -- it will probably be a long time before numpy will
> actually remove that API.

It'd be nice not to have the warning though.

Giuseppe Attardi

unread,
May 14, 2015, 4:08:49 AM5/14/15
to cython...@googlegroups.com
Yes, it is a warning, but it is very annoying, since there are plenty of them filling pages on the screen and when I distribute the code, people get worried that something is incorrect.

Giuseppe Attardi

unread,
May 14, 2015, 4:09:01 AM5/14/15
to cython...@googlegroups.com
Besides, and I am sorry to say this: why don't you mention the issue in the documentation instead of providing wrong hints to a solution?
I spend hours of my time trying to find a fix: two lines in the documentation would have spared me such a waste of time.


On Wednesday, May 13, 2015 at 5:15:16 PM UTC+2, Chris Barker - NOAA Federal wrote:

Robert Bradshaw

unread,
May 14, 2015, 11:54:53 AM5/14/15
to cython...@googlegroups.com
On Thu, May 14, 2015 at 1:05 AM, Giuseppe Attardi <att...@gmail.com> wrote:
> Besides, and I am sorry to say this: why don't you mention the issue in the
> documentation instead of providing wrong hints to a solution?
> I spend hours of my time trying to find a fix: two lines in the
> documentation would have spared me such a waste of time.

We'd welcome a pull request to fix the documentation.

Chris Barker

unread,
May 14, 2015, 4:24:51 PM5/14/15
to cython-users
On Thu, May 14, 2015 at 1:05 AM, Giuseppe Attardi <att...@gmail.com> wrote:
Besides, and I am sorry to say this: why don't you mention the issue in the documentation instead of providing wrong hints to a solution?
I spend hours of my time trying to find a fix: two lines in the documentation would have spared me such a waste of time.

Last I looked into this, it looked like there might we a way to disable that warning, but gave up trying....

So not sure what should be in the docs, there may be a way to disable it. but a note that it's a pain at best, and not to worry about it wold be good.

Robert (or anyone else...) -- Is there any reason other than the fact that someone has to do it to not update Cyton to use the non-deprecated APIs?

-CHB




--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov

Robert Bradshaw

unread,
May 14, 2015, 11:39:38 PM5/14/15
to cython...@googlegroups.com
On Thu, May 14, 2015 at 1:24 PM, Chris Barker <chris....@noaa.gov> wrote:
On Thu, May 14, 2015 at 1:05 AM, Giuseppe Attardi <att...@gmail.com> wrote:
Besides, and I am sorry to say this: why don't you mention the issue in the documentation instead of providing wrong hints to a solution?
I spend hours of my time trying to find a fix: two lines in the documentation would have spared me such a waste of time.

Last I looked into this, it looked like there might we a way to disable that warning, but gave up trying....

So not sure what should be in the docs, there may be a way to disable it. but a note that it's a pain at best, and not to worry about it wold be good.

Robert (or anyone else...) -- Is there any reason other than the fact that someone has to do it to not update Cyton to use the non-deprecated APIs?

It's like you said--at the beginning we didn't want to require the newer NumPy and now that that's way behind us no one has updated Cython to use the new API.

Giuseppe Attardi

unread,
May 15, 2015, 1:47:28 AM5/15/15
to cython...@googlegroups.com
Fair enough. Did so.
Reply all
Reply to author
Forward
0 new messages