I'm having trouble passing in this memoryview of integers into this (rather trivial) function. Python is giving me this error:
ValueError: Buffer dtype mismatch, expected 'int' but got 'long'
Can someone help me understand what's going on? Searching around stackoverflow, it seems that it has to do with how python interprets types, and how C interprets types.
%%cython
def myfunction(int [:] y):
pass
# Python code
import numpy as np
y = np.array([0, 0, 1, 1])
myfunction(y)
This produces the ValueError
from above.
EDIT: Here are some other things I've discovered.
To clarify, this error persists if I declare y
the following ways:
y = np.array([0, 0, 1, 1], dtype='int')
y = np.array([0, 0, 1, 1], dtype=np.int)
y = np.array([0, 0, 1, 1], dtype=np.int64)
However, it works if I declare y
with
y = np.array([0, 0, 1, 1], dtype=np.int32)
Does anyone want to give a suggestion why this is the case? Would throwing in np.int32
work on different computers? (I use a macbook pro retina, 2013.)