MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_Arange

Function PyArray_Arange

numpy/core/src/multiarray/ctors.c:2941–3023  ·  view source on GitHub ↗

NUMPY_API Arange, */

Source from the content-addressed store, hash-verified

2939 Arange,
2940*/
2941NPY_NO_EXPORT PyObject *
2942PyArray_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);

Callers

nothing calls this directly

Calls 6

PyArray_NewFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_BYTESFunction · 0.85
PyArray_ITEMSIZEFunction · 0.85

Tested by

no test coverage detected