(
pairs,
order=2,
ddof=0,
dtype="f8",
sum=np.sum,
axis=None,
computing_meta=False,
**kwargs,
)
| 465 | |
| 466 | |
| 467 | def moment_combine( |
| 468 | pairs, |
| 469 | order=2, |
| 470 | ddof=0, |
| 471 | dtype="f8", |
| 472 | sum=np.sum, |
| 473 | axis=None, |
| 474 | computing_meta=False, |
| 475 | **kwargs, |
| 476 | ): |
| 477 | if not isinstance(pairs, list): |
| 478 | pairs = [pairs] |
| 479 | |
| 480 | kwargs["dtype"] = None |
| 481 | kwargs["keepdims"] = True |
| 482 | |
| 483 | ns = deepmap(lambda pair: pair["n"], pairs) if not computing_meta else pairs |
| 484 | ns = _concatenate2(ns, axes=axis) |
| 485 | n = ns.sum(axis=axis, **kwargs) |
| 486 | |
| 487 | if computing_meta: |
| 488 | return n |
| 489 | |
| 490 | totals = _concatenate2(deepmap(lambda pair: pair["total"], pairs), axes=axis) |
| 491 | Ms = _concatenate2(deepmap(lambda pair: pair["M"], pairs), axes=axis) |
| 492 | |
| 493 | total = totals.sum(axis=axis, **kwargs) |
| 494 | |
| 495 | with np.errstate(divide="ignore", invalid="ignore"): |
| 496 | if np.issubdtype(total.dtype, np.complexfloating): |
| 497 | mu = divide(total, n) |
| 498 | inner_term = np.abs(divide(totals, ns) - mu) |
| 499 | else: |
| 500 | mu = divide(total, n, dtype=dtype) |
| 501 | inner_term = divide(totals, ns, dtype=dtype) - mu |
| 502 | |
| 503 | xs = [ |
| 504 | _moment_helper(Ms, ns, inner_term, o, sum, axis, kwargs) |
| 505 | for o in range(2, order + 1) |
| 506 | ] |
| 507 | M = np.stack(xs, axis=-1) |
| 508 | return {"total": total, "n": n, "M": M} |
| 509 | |
| 510 | |
| 511 | def moment_agg( |
no test coverage detected
searching dependent graphs…