NUMPY_API * ScalarKind * * Returns the scalar kind of a type number, with an * optional tweak based on the scalar value itself. * If no scalar is provided, it returns INTPOS_SCALAR * for both signed and unsigned integers, otherwise * it checks the sign of any signed integer to choose * INTNEG_SCALAR when appropriate. */
| 810 | * INTNEG_SCALAR when appropriate. |
| 811 | */ |
| 812 | NPY_NO_EXPORT NPY_SCALARKIND |
| 813 | PyArray_ScalarKind(int typenum, PyArrayObject **arr) |
| 814 | { |
| 815 | NPY_SCALARKIND ret = NPY_NOSCALAR; |
| 816 | |
| 817 | if ((unsigned int)typenum < NPY_NTYPES) { |
| 818 | ret = _npy_scalar_kinds_table[typenum]; |
| 819 | /* Signed integer types are INTNEG in the table */ |
| 820 | if (ret == NPY_INTNEG_SCALAR) { |
| 821 | if (!arr || !_signbit_set(*arr)) { |
| 822 | ret = NPY_INTPOS_SCALAR; |
| 823 | } |
| 824 | } |
| 825 | } else if (PyTypeNum_ISUSERDEF(typenum)) { |
| 826 | PyArray_Descr* descr = PyArray_DescrFromType(typenum); |
| 827 | |
| 828 | if (descr->f->scalarkind) { |
| 829 | ret = descr->f->scalarkind((arr ? *arr : NULL)); |
| 830 | } |
| 831 | Py_DECREF(descr); |
| 832 | } |
| 833 | |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | /*NUMPY_API |
| 838 | * |
no test coverage detected