Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:59:27+00:00 2026-06-13T08:59:27+00:00

I’m attempting to optimise a simple cython routine I’ve written that accepts a 1D

  • 0

I’m attempting to optimise a simple cython routine I’ve written that accepts a 1D numpy array as input and returns a 1D numpy array as output.

I have a naive version working, and am now attempting to do some standard optimisations to the numpy parts of the cython code.

However, as soon as I add cimport numpy to my cython source file, I am unable to run the extension module (though it compiles okay), throwing a ValueError: numpy.dtype does not appear to be the correct type object.

My numpy version is 1.6.0 and python version 2.6.5 (default, Ubuntu 10.04 apt-get installations)

Minimal example causing the problem:


test_ext.pyx

import numpy as np
cimport numpy as np #Commenting this line un-breaks the extension

def test_ext(refls, str mode, int nguard, int nblock):

    cdef int i
    cdef int _len = refls.shape[0]
    _out = np.zeros([_len])

    for i in range(_len):
        _out[i] = refls[i] + 1
    return _out

setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("test_ext", ["test_ext.pyx"])]

setup(
    name = 'test',
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)

run_ext.py

import numpy
from test_ext import test_ext

a = np.array([x for x in range(260)])
_res = test_ext.test_ext(a, 'avg', 2, 3)

build with:

python setup.py build_ext --inplace

My build output:

running build_ext
cythoning my_ext.pyx to my_ext.c
building 'my_ext' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c my_ext.c -o build/temp.linux-x86_64-2.6/my_ext.o
/usr/include/python2.6/numpy/__multiarray_api.h:968: warning: ‘_import_array’ defined but not used
my_ext.c:732: warning: ‘__pyx_k_3’ defined but not used
my_ext.c:733: warning: ‘__pyx_k_4’ defined but not used
my_ext.c:753: warning: ‘__pyx_k_24’ defined but not used
my_ext.c:759: warning: ‘__pyx_k_26’ defined but not used
my_ext.c:760: warning: ‘__pyx_k_27’ defined but not used
my_ext.c:1118: warning: ‘__pyx_pf_5numpy_7ndarray___getbuffer__’ defined but not used
my_ext.c:1876: warning: ‘__pyx_pf_5numpy_7ndarray___releasebuffer__’ defined but not used
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6/my_ext.o -o /home/path/to/my_ext.so

and run then run_ext.py.

With the cimport line uncommented, I get the error:

Traceback (most recent call last):
  File "run_ext.py", line 2, in <module>
    from test_ext import test_ext
  File "numpy.pxd", line 43, in test_ext (test_ext.c:2788)
ValueError: numpy.dtype does not appear to be the correct type object

What causes this and how can I fix it to continue optimising my extension? I have attempted to continue with the optimisations as per the link above, but however far along I get, nothing un-breaks this issue for me.

I’ve seen some other people with this problem that had version problems with python/numpy, but I don’t think that’s the case for me (though I’m open to suggestion there). Any suggestions appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:59:28+00:00Added an answer on June 13, 2026 at 8:59 am

    Looks like my build file just needed to include the numpy include files. Changing setup.py to what is below fixed everything:

    setup.py

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    import numpy   # << New line
    
    ext_modules = [Extension("test_ext", ["test_ext.pyx"])]
    
    setup(
        name = 'test',
        cmdclass = {'build_ext': build_ext},
        include_dirs = [numpy.get_include()], # << New line
        ext_modules = ext_modules
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.