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

Function __New_PyArray_Std

numpy/core/src/multiarray/calculation.c:321–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321NPY_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 {

Callers 1

PyArray_StdFunction · 0.85

Calls 13

PyArray_CheckAxisFunction · 0.85
PyArray_EnsureAnyArrayFunction · 0.85
PyArray_MeanFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMFunction · 0.85
PyArray_ReshapeFunction · 0.85
PyArray_ConjugateFunction · 0.85
PyArray_EnsureArrayFunction · 0.85
PyArray_ViewFunction · 0.85

Tested by

no test coverage detected