| 101 | int dtype::get_itemsize() const { return reinterpret_cast<PyArray_Descr*>(ptr())->elsize;} |
| 102 | |
| 103 | bool equivalent(dtype const & a, dtype const & b) { |
| 104 | // On Windows x64, the behaviour described on |
| 105 | // http://docs.scipy.org/doc/numpy/reference/c-api.array.html for |
| 106 | // PyArray_EquivTypes unfortunately does not extend as expected: |
| 107 | // "For example, on 32-bit platforms, NPY_LONG and NPY_INT are equivalent". |
| 108 | // This should also hold for 64-bit platforms (and does on Linux), but not |
| 109 | // on Windows. Implement an alternative: |
| 110 | #ifdef _MSC_VER |
| 111 | if (sizeof(long) == sizeof(int) && |
| 112 | // Manually take care of the type equivalence. |
| 113 | ((a == dtype::get_builtin<long>() || a == dtype::get_builtin<int>()) && |
| 114 | (b == dtype::get_builtin<long>() || b == dtype::get_builtin<int>()) || |
| 115 | (a == dtype::get_builtin<unsigned int>() || a == dtype::get_builtin<unsigned long>()) && |
| 116 | (b == dtype::get_builtin<unsigned int>() || b == dtype::get_builtin<unsigned long>()))) { |
| 117 | return true; |
| 118 | } else { |
| 119 | return PyArray_EquivTypes( |
| 120 | reinterpret_cast<PyArray_Descr*>(a.ptr()), |
| 121 | reinterpret_cast<PyArray_Descr*>(b.ptr()) |
| 122 | ); |
| 123 | } |
| 124 | #else |
| 125 | return PyArray_EquivTypes( |
| 126 | reinterpret_cast<PyArray_Descr*>(a.ptr()), |
| 127 | reinterpret_cast<PyArray_Descr*>(b.ptr()) |
| 128 | ); |
| 129 | #endif |
| 130 | } |
| 131 | |
| 132 | namespace |
| 133 | { |