| 319 | } |
| 320 | |
| 321 | NPY_NO_EXPORT PyObject * |
| 322 | __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, |
| 323 | int variance, int num) |
| 324 | { |
| 325 | PyObject *obj1 = NULL, *obj2 = NULL, *obj3 = NULL; |
| 326 | PyArrayObject *arr1 = NULL, *arr2 = NULL, *arrnew = NULL; |
| 327 | PyObject *ret = NULL, *newshape = NULL; |
| 328 | int i, n; |
| 329 | npy_intp val; |
| 330 | |
| 331 | arrnew = (PyArrayObject *)PyArray_CheckAxis(self, &axis, 0); |
| 332 | if (arrnew == NULL) { |
| 333 | return NULL; |
| 334 | } |
| 335 | /* Compute and reshape mean */ |
| 336 | arr1 = (PyArrayObject *)PyArray_EnsureAnyArray( |
| 337 | PyArray_Mean(arrnew, axis, rtype, NULL)); |
| 338 | if (arr1 == NULL) { |
| 339 | Py_DECREF(arrnew); |
| 340 | return NULL; |
| 341 | } |
| 342 | n = PyArray_NDIM(arrnew); |
| 343 | newshape = PyTuple_New(n); |
| 344 | if (newshape == NULL) { |
| 345 | Py_DECREF(arr1); |
| 346 | Py_DECREF(arrnew); |
| 347 | return NULL; |
| 348 | } |
| 349 | for (i = 0; i < n; i++) { |
| 350 | if (i == axis) { |
| 351 | val = 1; |
| 352 | } |
| 353 | else { |
| 354 | val = PyArray_DIM(arrnew,i); |
| 355 | } |
| 356 | PyTuple_SET_ITEM(newshape, i, PyLong_FromSsize_t(val)); |
| 357 | } |
| 358 | arr2 = (PyArrayObject *)PyArray_Reshape(arr1, newshape); |
| 359 | Py_DECREF(arr1); |
| 360 | Py_DECREF(newshape); |
| 361 | if (arr2 == NULL) { |
| 362 | Py_DECREF(arrnew); |
| 363 | return NULL; |
| 364 | } |
| 365 | |
| 366 | /* Compute x = x - mx */ |
| 367 | arr1 = (PyArrayObject *)PyArray_EnsureAnyArray( |
| 368 | PyNumber_Subtract((PyObject *)arrnew, (PyObject *)arr2)); |
| 369 | Py_DECREF(arr2); |
| 370 | if (arr1 == NULL) { |
| 371 | Py_DECREF(arrnew); |
| 372 | return NULL; |
| 373 | } |
| 374 | /* Compute x * x */ |
| 375 | if (PyArray_ISCOMPLEX(arr1)) { |
| 376 | obj3 = PyArray_Conjugate(arr1, NULL); |
| 377 | } |
| 378 | else { |
no test coverage detected