-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Florian Jetter <fjetter@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import numpy as np | ||
import numpy_groupies as npg | ||
|
||
|
||
def tdigest_chunk(group_idx, array, *, axis=-1, size=None, fill_value=None, dtype=None, **kwargs): | ||
from crick import TDigest | ||
|
||
def _(arr): | ||
digest = TDigest() | ||
# we receive object arrays from numpy_groupies | ||
digest.update(arr.astype(array.dtype, copy=False)) | ||
return digest | ||
|
||
result = npg.aggregate_numpy.aggregate(group_idx, array, func=_, axis=axis, dtype=object) | ||
return result | ||
|
||
|
||
def tdigest_combine(digests, axis=-1, keepdims=True): | ||
from crick import TDigest | ||
|
||
def _(arr): | ||
t = TDigest() | ||
t.merge(*arr) | ||
return np.array([t], dtype=object) | ||
|
||
(axis,) = axis | ||
result = np.apply_along_axis(_, axis, digests) | ||
|
||
return result | ||
|
||
|
||
def tdigest_aggregate(digests, q, axis=-1, keepdims=True): | ||
for idx in np.ndindex(digests.shape): | ||
digests[idx] = digests[idx].quantile(q) | ||
return digests |