| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
from dask.utils import Dispatch |
| 4 |
|
| 5 |
|
| 6 |
def get_type(array): |
| 7 |
"""Return type of arrays contained within the dask array chunks.""" |
| 8 |
try: |
| 9 |
datatype = type(array._meta) # Check chunk type backing dask array |
| 10 |
except AttributeError: |
| 11 |
datatype = type(array) # For all non-dask arrays |
| 12 |
return datatype |
| 13 |
|
| 14 |
|
| 15 |
class Dispatcher(Dispatch): |
| 16 |
"""Simple single dispatch for different dask array types.""" |
| 17 |
|
| 18 |
def __call__(self, arg, *args, **kwargs): |
| 19 |
""" |
| 20 |
Call the corresponding method based on type of dask array. |
| 21 |
""" |
| 22 |
datatype = get_type(arg) |
| 23 |
meth = self.dispatch(datatype) |
| 24 |
return meth(arg, *args, **kwargs) |