/* -*- mode: c++; c-basic-offset: 4 -*- */ #ifndef MPL_NUMPY_CPP_H #define MPL_NUMPY_CPP_H #define PY_SSIZE_T_CLEAN /*************************************************************************** * This file is based on original work by Mark Wiebe, available at: * * http://github.com/mwiebe/numpy-cpp * * However, the needs of matplotlib wrappers, such as treating an * empty array as having the correct dimensions, have made this rather * matplotlib-specific, so it's no longer compatible with the * original. */ #ifdef _POSIX_C_SOURCE # undef _POSIX_C_SOURCE #endif #ifndef _AIX #ifdef _XOPEN_SOURCE # undef _XOPEN_SOURCE #endif #endif // Prevent multiple conflicting definitions of swab from stdlib.h and unistd.h #if defined(__sun) || defined(sun) #if defined(_XPG4) #undef _XPG4 #endif #if defined(_XPG3) #undef _XPG3 #endif #endif #include #include #include "py_exceptions.h" #include namespace numpy { // Type traits for the NumPy types template struct type_num_of; /* Be careful with bool arrays as python has sizeof(npy_bool) == 1, but it is * not always the case that sizeof(bool) == 1. Using the array_view_accessors * is always fine regardless of sizeof(bool), so do this rather than using * array.data() and pointer arithmetic which will not work correctly if * sizeof(bool) != 1. */ template struct type_num_of { enum { value = NPY_BOOL }; }; template struct type_num_of { enum { value = NPY_BYTE }; }; template struct type_num_of { enum { value = NPY_UBYTE }; }; template struct type_num_of { enum { value = NPY_SHORT }; }; template struct type_num_of { enum { value = NPY_USHORT }; }; template struct type_num_of { enum { value = NPY_INT }; }; template struct type_num_of { enum { value = NPY_UINT }; }; template struct type_num_of { enum { value = NPY_LONG }; }; template struct type_num_of { enum { value = NPY_ULONG }; }; template struct type_num_of { enum { value = NPY_LONGLONG }; }; template struct type_num_of { enum { value = NPY_ULONGLONG }; }; template struct type_num_of { enum { value = NPY_FLOAT }; }; template struct type_num_of { enum { value = NPY_DOUBLE }; }; #if NPY_LONGDOUBLE != NPY_DOUBLE template struct type_num_of { enum { value = NPY_LONGDOUBLE }; }; #endif template struct type_num_of { enum { value = NPY_CFLOAT }; }; template struct type_num_of<:complex> > { enum { value = NPY_CFLOAT }; }; template struct type_num_of { enum { value = NPY_CDOUBLE }; }; template struct type_num_of<:complex> > { enum { value = NPY_CDOUBLE }; }; #if NPY_CLONGDOUBLE != NPY_CDOUBLE template struct type_num_of { enum { value = NPY_CLONGDOUBLE }; }; template struct type_num_of<:complex> > { enum { value = NPY_CLONGDOUBLE }; }; #endif template struct type_num_of { enum { value = NPY_OBJECT }; }; template struct type_num_of { enum { value = type_num_of::value }; }; template struct type_num_of { enum { value = type_num_of::value }; }; template struct is_const { enum { value = false }; }; template struct is_const { enum { value = true }; }; namespace detail { template