X Tutup
/* -*- mode: c++; c-basic-offset: 4 -*- */ #ifndef _NUMPY_CPP_H_ #define _NUMPY_CPP_H_ /*************************************************************************** * 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. */ #include "py_exceptions.h" #include #ifdef _POSIX_C_SOURCE # undef _POSIX_C_SOURCE #endif #ifdef _XOPEN_SOURCE # undef _XOPEN_SOURCE #endif #include #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 > { enum { value = NPY_CFLOAT }; }; template <> struct type_num_of { enum { value = NPY_CDOUBLE }; }; template <> struct type_num_of > { enum { value = NPY_CDOUBLE }; }; #if NPY_CLONGDOUBLE != NPY_CDOUBLE template <> struct type_num_of { enum { value = NPY_CLONGDOUBLE }; }; template <> struct type_num_of > { 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
X Tutup