* Converts an axis parameter into an ndim-length C-array of * boolean flags, True for each axis specified. * * If obj is None or NULL, everything is set to True. If obj is a tuple, * each axis within the tuple is set to True. If obj is an integer, * just that axis is set to True. */
| 354 | * just that axis is set to True. |
| 355 | */ |
| 356 | NPY_NO_EXPORT int |
| 357 | PyArray_ConvertMultiAxis(PyObject *axis_in, int ndim, npy_bool *out_axis_flags) |
| 358 | { |
| 359 | /* None means all of the axes */ |
| 360 | if (axis_in == Py_None || axis_in == NULL) { |
| 361 | memset(out_axis_flags, 1, ndim); |
| 362 | return NPY_SUCCEED; |
| 363 | } |
| 364 | /* A tuple of which axes */ |
| 365 | else if (PyTuple_Check(axis_in)) { |
| 366 | int i, naxes; |
| 367 | |
| 368 | memset(out_axis_flags, 0, ndim); |
| 369 | |
| 370 | naxes = PyTuple_Size(axis_in); |
| 371 | if (naxes < 0) { |
| 372 | return NPY_FAIL; |
| 373 | } |
| 374 | for (i = 0; i < naxes; ++i) { |
| 375 | PyObject *tmp = PyTuple_GET_ITEM(axis_in, i); |
| 376 | int axis = PyArray_PyIntAsInt_ErrMsg(tmp, |
| 377 | "integers are required for the axis tuple elements"); |
| 378 | if (error_converting(axis)) { |
| 379 | return NPY_FAIL; |
| 380 | } |
| 381 | if (check_and_adjust_axis(&axis, ndim) < 0) { |
| 382 | return NPY_FAIL; |
| 383 | } |
| 384 | if (out_axis_flags[axis]) { |
| 385 | PyErr_SetString(PyExc_ValueError, |
| 386 | "duplicate value in 'axis'"); |
| 387 | return NPY_FAIL; |
| 388 | } |
| 389 | out_axis_flags[axis] = 1; |
| 390 | } |
| 391 | |
| 392 | return NPY_SUCCEED; |
| 393 | } |
| 394 | /* Try to interpret axis as an integer */ |
| 395 | else { |
| 396 | int axis; |
| 397 | |
| 398 | memset(out_axis_flags, 0, ndim); |
| 399 | |
| 400 | axis = PyArray_PyIntAsInt_ErrMsg(axis_in, |
| 401 | "an integer is required for the axis"); |
| 402 | |
| 403 | if (error_converting(axis)) { |
| 404 | return NPY_FAIL; |
| 405 | } |
| 406 | /* |
| 407 | * Special case letting axis={-1,0} slip through for scalars, |
| 408 | * for backwards compatibility reasons. |
| 409 | */ |
| 410 | if (ndim == 0 && (axis == 0 || axis == -1)) { |
| 411 | return NPY_SUCCEED; |
| 412 | } |
| 413 |
no test coverage detected