MCPcopy Create free account
hub / github.com/dask/dask / arg_chunk

Function arg_chunk

dask/array/reductions.py:781–811  ·  view source on GitHub ↗
(func, argfunc, x, axis, offset_info)

Source from the content-addressed store, hash-verified

779
780
781def arg_chunk(func, argfunc, x, axis, offset_info):
782 arg_axis = None if len(axis) == x.ndim or x.ndim == 1 else axis[0]
783 vals = func(x, axis=arg_axis, keepdims=True)
784 arg = argfunc(x, axis=arg_axis, keepdims=True)
785 if x.ndim > 0:
786 if arg_axis is None:
787 offset, total_shape = offset_info
788 ind = np.unravel_index(arg.ravel()[0], x.shape)
789 total_ind = tuple(o + i for (o, i) in zip(offset, ind))
790 arg[:] = np.ravel_multi_index(total_ind, total_shape)
791 else:
792 arg += offset_info
793
794 if isinstance(vals, np.ma.masked_array):
795 if "min" in argfunc.__name__:
796 fill_value = np.ma.minimum_fill_value(vals)
797 else:
798 fill_value = np.ma.maximum_fill_value(vals)
799 vals = np.ma.filled(vals, fill_value)
800
801 try:
802 result = np.empty_like(
803 vals, shape=vals.shape, dtype=[("vals", vals.dtype), ("arg", arg.dtype)]
804 )
805 except TypeError:
806 # Array type doesn't support structured arrays (e.g., CuPy)
807 result = dict()
808
809 result["vals"] = vals
810 result["arg"] = arg
811 return result
812
813
814def arg_combine(argfunc, data, axis=None, **kwargs):

Callers

nothing calls this directly

Calls 2

funcFunction · 0.70
ravelMethod · 0.45

Tested by

no test coverage detected