hello,
I think you'll want to use the C macro PyArray_IsIntegerScalar, e.g.
in pandas I have the following function exposed to my Cython code:
PANDAS_INLINE int
is_integer_object(PyObject* obj) {
return PyArray_IsIntegerScalar(obj);
}
last time I checked that macro detects Python int, long, and all of
the NumPy integer hierarchy (int8, 16, 32, 64). If you ONLY want to
check for int64 I am not 100% sure the best way.
- Wes
_______________________________________________
NumPy-Discussion mailing list
NumPy-Di...@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
No. All of the PyTypeObject objects for the NumPy array scalars are
explicitly part of the NumPy C API so you have no choice but to depend
on that (to get the best performance). If you want to ONLY check for
int64 at the C API level, I did a bit of digging and the relevant type
definitions are in
https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/npy_common.h
so you'll want to do:
int is_int64(PyObject* obj){
return PyObject_TypeCheck(obj, &PyInt64ArrType_Type);
}
and that will *only* detect np.int64
- Wes
Not sure off-hand. You'll have to look at the NumPy scalar API in the C code
No. All of the PyTypeObject objects for the NumPy array scalars areexplicitly part of the NumPy C API so you have no choice but to dependon that (to get the best performance). If you want to ONLY check forint64 at the C API level, I did a bit of digging and the relevant typedefinitions are inhttps://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/npy_common.hso you'll want to do:int is_int64(PyObject* obj){return PyObject_TypeCheck(obj, &PyInt64ArrType_Type);}and that will *only* detect np.int64- WesOk many thanks !One last thing, do you happen to know how to actually convert an np int64 toa C int ?
- x.
Not sure off-hand. You'll have to look at the NumPy scalar API in the C code