NUMPY_API Arange, */
| 2939 | Arange, |
| 2940 | */ |
| 2941 | NPY_NO_EXPORT PyObject * |
| 2942 | PyArray_Arange(double start, double stop, double step, int type_num) |
| 2943 | { |
| 2944 | npy_intp length; |
| 2945 | PyArrayObject *range; |
| 2946 | PyArray_ArrFuncs *funcs; |
| 2947 | PyObject *obj; |
| 2948 | int ret; |
| 2949 | double delta, tmp_len; |
| 2950 | NPY_BEGIN_THREADS_DEF; |
| 2951 | |
| 2952 | delta = stop - start; |
| 2953 | tmp_len = delta/step; |
| 2954 | |
| 2955 | /* Underflow and divide-by-inf check */ |
| 2956 | if (tmp_len == 0.0 && delta != 0.0) { |
| 2957 | if (npy_signbit(tmp_len)) { |
| 2958 | length = 0; |
| 2959 | } |
| 2960 | else { |
| 2961 | length = 1; |
| 2962 | } |
| 2963 | } |
| 2964 | else { |
| 2965 | length = _arange_safe_ceil_to_intp(tmp_len); |
| 2966 | if (error_converting(length)) { |
| 2967 | return NULL; |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | if (length <= 0) { |
| 2972 | length = 0; |
| 2973 | return PyArray_New(&PyArray_Type, 1, &length, type_num, |
| 2974 | NULL, NULL, 0, 0, NULL); |
| 2975 | } |
| 2976 | range = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &length, type_num, |
| 2977 | NULL, NULL, 0, 0, NULL); |
| 2978 | if (range == NULL) { |
| 2979 | return NULL; |
| 2980 | } |
| 2981 | funcs = PyArray_DESCR(range)->f; |
| 2982 | |
| 2983 | /* |
| 2984 | * place start in the buffer and the next value in the second position |
| 2985 | * if length > 2, then call the inner loop, otherwise stop |
| 2986 | */ |
| 2987 | obj = PyFloat_FromDouble(start); |
| 2988 | ret = funcs->setitem(obj, PyArray_DATA(range), range); |
| 2989 | Py_DECREF(obj); |
| 2990 | if (ret < 0) { |
| 2991 | goto fail; |
| 2992 | } |
| 2993 | if (length == 1) { |
| 2994 | return (PyObject *)range; |
| 2995 | } |
| 2996 | obj = PyFloat_FromDouble(start + step); |
| 2997 | ret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), |
| 2998 | range); |
nothing calls this directly
no test coverage detected