NUMPY_API * * ArangeObj, * * this doesn't change the references */
| 3136 | * this doesn't change the references |
| 3137 | */ |
| 3138 | NPY_NO_EXPORT PyObject * |
| 3139 | PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) |
| 3140 | { |
| 3141 | PyArrayObject *range = NULL; |
| 3142 | PyArray_ArrFuncs *funcs; |
| 3143 | PyObject *next = NULL; |
| 3144 | PyArray_Descr *native = NULL; |
| 3145 | npy_intp length; |
| 3146 | int swap; |
| 3147 | NPY_BEGIN_THREADS_DEF; |
| 3148 | |
| 3149 | /* Datetime arange is handled specially */ |
| 3150 | if ((dtype != NULL && (dtype->type_num == NPY_DATETIME || |
| 3151 | dtype->type_num == NPY_TIMEDELTA)) || |
| 3152 | (dtype == NULL && (is_any_numpy_datetime_or_timedelta(start) || |
| 3153 | is_any_numpy_datetime_or_timedelta(stop) || |
| 3154 | is_any_numpy_datetime_or_timedelta(step)))) { |
| 3155 | return (PyObject *)datetime_arange(start, stop, step, dtype); |
| 3156 | } |
| 3157 | |
| 3158 | /* We need to replace many of these, so hold on for easier cleanup */ |
| 3159 | Py_XINCREF(start); |
| 3160 | Py_XINCREF(stop); |
| 3161 | Py_XINCREF(step); |
| 3162 | Py_XINCREF(dtype); |
| 3163 | |
| 3164 | if (!dtype) { |
| 3165 | /* intentionally made to be at least NPY_LONG */ |
| 3166 | dtype = PyArray_DescrFromType(NPY_LONG); |
| 3167 | Py_SETREF(dtype, PyArray_DescrFromObject(start, dtype)); |
| 3168 | if (dtype == NULL) { |
| 3169 | goto fail; |
| 3170 | } |
| 3171 | if (stop && stop != Py_None) { |
| 3172 | Py_SETREF(dtype, PyArray_DescrFromObject(stop, dtype)); |
| 3173 | if (dtype == NULL) { |
| 3174 | goto fail; |
| 3175 | } |
| 3176 | } |
| 3177 | if (step && step != Py_None) { |
| 3178 | Py_SETREF(dtype, PyArray_DescrFromObject(step, dtype)); |
| 3179 | if (dtype == NULL) { |
| 3180 | goto fail; |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /* |
| 3186 | * If dtype is not in native byte-order then get native-byte |
| 3187 | * order version. And then swap on the way out. |
| 3188 | */ |
| 3189 | if (!PyArray_ISNBO(dtype->byteorder)) { |
| 3190 | native = PyArray_DescrNewByteorder(dtype, NPY_NATBYTE); |
| 3191 | if (native == NULL) { |
| 3192 | goto fail; |
| 3193 | } |
| 3194 | swap = 1; |
| 3195 | } |
no test coverage detected