Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/awkward/operations/ak_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,33 @@ def _impl(x, y, weight, axis, keepdims, mask_identity, highlevel, behavior, attr
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
y = ctx.wrap(y_layout)
y = ak.operations.ak_values_astype._impl(
y,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

with np.errstate(invalid="ignore", divide="ignore"):
xmean = ak.operations.ak_mean._impl(
Expand Down
25 changes: 25 additions & 0 deletions src/awkward/operations/ak_covar.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,33 @@ def _impl(x, y, weight, axis, keepdims, mask_identity, highlevel, behavior, attr
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
y = ctx.wrap(y_layout)
y = ak.operations.ak_values_astype._impl(
y,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

with np.errstate(invalid="ignore", divide="ignore"):
xmean = ak.operations.ak_mean._impl(
Expand Down
25 changes: 25 additions & 0 deletions src/awkward/operations/ak_linear_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,33 @@ def _impl(x, y, weight, axis, keepdims, mask_identity, highlevel, behavior, attr
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
y = ctx.wrap(y_layout)
y = ak.operations.ak_values_astype._impl(
y,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

with np.errstate(invalid="ignore", divide="ignore"):
if weight is None:
Expand Down
17 changes: 17 additions & 0 deletions src/awkward/operations/ak_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,24 @@ def _impl(x, weight, axis, keepdims, mask_identity, highlevel, behavior, attrs):
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

# Handle named axis
named_axis = _get_named_axis(ctx)
Expand Down
17 changes: 17 additions & 0 deletions src/awkward/operations/ak_moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,24 @@ def _impl(
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

with np.errstate(invalid="ignore", divide="ignore"):
if weight is None:
Expand Down
17 changes: 17 additions & 0 deletions src/awkward/operations/ak_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,24 @@ def _impl(x, weight, ddof, axis, keepdims, mask_identity, highlevel, behavior, a
)

x = ctx.wrap(x_layout)
x = ak.operations.ak_values_astype._impl(
x,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)
weight = ctx.wrap(weight_layout, allow_other=True)
if weight is not None:
weight = ak.operations.ak_values_astype._impl(
weight,
np.float64,
including_unknown=False,
highlevel=True,
behavior=ctx.behavior,
attrs=ctx.attrs,
)

# Handle named axis
named_axis = _get_named_axis(ctx)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_3527_descriptive_statistics_float64_casting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import numpy as np

import awkward as ak


def test_int32_overflow():
np.random.seed(42)
x = np.random.randint(2**21, 2**22, size=1000, dtype=np.int32)
y = np.random.randint(2**21, 2**22, size=1000, dtype=np.int32)

np.testing.assert_allclose(np.sum(x), ak.sum(x))
np.testing.assert_allclose(np.mean(x), ak.mean(x))
np.testing.assert_allclose(np.var(x), ak.var(x))
np.testing.assert_allclose(np.std(x), ak.std(x))
np.testing.assert_allclose(np.cov(x, y, ddof=0)[0][1], ak.covar(x, y))
np.testing.assert_allclose(np.corrcoef(x, y)[0][1], ak.corr(x, y))


def test_int64_overflow():
np.random.seed(42)
x = np.random.randint(2**61, 2**62, size=1000, dtype=np.int64)
y = np.random.randint(2**61, 2**62, size=1000, dtype=np.int64)

np.testing.assert_allclose(np.sum(x), ak.sum(x))
np.testing.assert_allclose(np.mean(x), ak.mean(x))
np.testing.assert_allclose(np.var(x), ak.var(x))
np.testing.assert_allclose(np.std(x), ak.std(x))
np.testing.assert_allclose(np.cov(x, y, ddof=0)[0][1], ak.covar(x, y))
np.testing.assert_allclose(np.corrcoef(x, y)[0][1], ak.corr(x, y))
Loading