We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
dask.array test failures on OS X
Got this on an OS X machine where I ran the test suite out of curiosity (with Python 3.6):
```
____________________________________________________________________________ test_coarsen ____________________________________________________________________________
Traceback (most recent call last):
  File "/Users/buildbot/antoine/dask/dask/array/tests/test_array_core.py", line 628, in test_coarsen
    assert_eq(chunk.coarsen(np.sum, x, {0: 2, 1: 4}),
  File "/Users/buildbot/antoine/dask/dask/array/chunk.py", line 148, in coarsen
    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))
TypeError: 'float' object cannot be interpreted as an integer
______________________________________________________________________ test_coarsen_with_excess ______________________________________________________________________
Traceback (most recent call last):
  File "/Users/buildbot/antoine/dask/dask/array/tests/test_array_core.py", line 637, in test_coarsen_with_excess
    np.array([0, 5]))
  File "/Users/buildbot/antoine/dask/dask/array/utils.py", line 51, in assert_eq
    a = a.compute(get=get_sync)
  File "/Users/buildbot/antoine/dask/dask/base.py", line 94, in compute
    (result,) = compute(self, traverse=False, **kwargs)
  File "/Users/buildbot/antoine/dask/dask/base.py", line 201, in compute
    results = get(dsk, keys, **kwargs)
  File "/Users/buildbot/antoine/dask/dask/async.py", line 544, in get_sync
    raise_on_exception=True, **kwargs)
  File "/Users/buildbot/antoine/dask/dask/async.py", line 487, in get_async
    fire_task()
  File "/Users/buildbot/antoine/dask/dask/async.py", line 483, in fire_task
    callback=queue.put)
  File "/Users/buildbot/antoine/dask/dask/async.py", line 532, in apply_sync
    res = func(*args, **kwds)
  File "/Users/buildbot/antoine/dask/dask/async.py", line 266, in execute_task
    result = _execute_task(task, data)
  File "/Users/buildbot/antoine/dask/dask/async.py", line 247, in _execute_task
    return func(*args2)
  File "/Users/buildbot/antoine/dask/dask/array/chunk.py", line 148, in coarsen
    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))
TypeError: 'float' object cannot be interpreted as an integer
____________________________________________________________________________ test_coarsen ____________________________________________________________________________
Traceback (most recent call last):
  File "/Users/buildbot/antoine/dask/dask/array/tests/test_chunk.py", line 98, in test_coarsen
    y = coarsen(np.sum, x, {0: 2, 1: 4})
  File "/Users/buildbot/antoine/dask/dask/array/chunk.py", line 148, in coarsen
    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))
TypeError: 'float' object cannot be interpreted as an integer
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dask/array/chunk.py`
Content:
```
1 """ A set of NumPy functions to apply per chunk """
2 from __future__ import absolute_import, division, print_function
3 
4 from collections import Container, Iterable, Sequence
5 from functools import wraps
6 
7 from toolz import concat
8 import numpy as np
9 from . import numpy_compat as npcompat
10 
11 from ..compatibility import getargspec
12 from ..utils import ignoring
13 
14 
15 def keepdims_wrapper(a_callable):
16     """
17     A wrapper for functions that don't provide keepdims to ensure that they do.
18     """
19 
20     if "keepdims" in getargspec(a_callable).args:
21         return a_callable
22 
23     @wraps(a_callable)
24     def keepdims_wrapped_callable(x, axis=None, keepdims=None, *args, **kwargs):
25         r = a_callable(x, axis=axis, *args, **kwargs)
26 
27         if not keepdims:
28             return r
29 
30         axes = axis
31 
32         if axes is None:
33             axes = range(x.ndim)
34 
35         if not isinstance(axes, (Container, Iterable, Sequence)):
36             axes = [axes]
37 
38         r_slice = tuple()
39         for each_axis in range(x.ndim):
40             if each_axis in axes:
41                 r_slice += (None,)
42             else:
43                 r_slice += (slice(None),)
44 
45         r = r[r_slice]
46 
47         return r
48 
49     return keepdims_wrapped_callable
50 
51 
52 # Wrap NumPy functions to ensure they provide keepdims.
53 sum = keepdims_wrapper(np.sum)
54 prod = keepdims_wrapper(np.prod)
55 min = keepdims_wrapper(np.min)
56 max = keepdims_wrapper(np.max)
57 argmin = keepdims_wrapper(np.argmin)
58 nanargmin = keepdims_wrapper(np.nanargmin)
59 argmax = keepdims_wrapper(np.argmax)
60 nanargmax = keepdims_wrapper(np.nanargmax)
61 any = keepdims_wrapper(np.any)
62 all = keepdims_wrapper(np.all)
63 nansum = keepdims_wrapper(np.nansum)
64 
65 try:
66     from numpy import nanprod, nancumprod, nancumsum
67 except ImportError:  # pragma: no cover
68     nanprod = npcompat.nanprod
69     nancumprod = npcompat.nancumprod
70     nancumsum = npcompat.nancumsum
71 
72 nanprod = keepdims_wrapper(nanprod)
73 nancumprod = keepdims_wrapper(nancumprod)
74 nancumsum = keepdims_wrapper(nancumsum)
75 
76 nanmin = keepdims_wrapper(np.nanmin)
77 nanmax = keepdims_wrapper(np.nanmax)
78 mean = keepdims_wrapper(np.mean)
79 
80 with ignoring(AttributeError):
81     nanmean = keepdims_wrapper(np.nanmean)
82 
83 var = keepdims_wrapper(np.var)
84 
85 with ignoring(AttributeError):
86     nanvar = keepdims_wrapper(np.nanvar)
87 
88 std = keepdims_wrapper(np.std)
89 
90 with ignoring(AttributeError):
91     nanstd = keepdims_wrapper(np.nanstd)
92 
93 
94 def coarsen(reduction, x, axes, trim_excess=False):
95     """ Coarsen array by applying reduction to fixed size neighborhoods
96 
97     Parameters
98     ----------
99     reduction: function
100         Function like np.sum, np.mean, etc...
101     x: np.ndarray
102         Array to be coarsened
103     axes: dict
104         Mapping of axis to coarsening factor
105 
106     Examples
107     --------
108     >>> x = np.array([1, 2, 3, 4, 5, 6])
109     >>> coarsen(np.sum, x, {0: 2})
110     array([ 3,  7, 11])
111     >>> coarsen(np.max, x, {0: 3})
112     array([3, 6])
113 
114     Provide dictionary of scale per dimension
115 
116     >>> x = np.arange(24).reshape((4, 6))
117     >>> x
118     array([[ 0,  1,  2,  3,  4,  5],
119            [ 6,  7,  8,  9, 10, 11],
120            [12, 13, 14, 15, 16, 17],
121            [18, 19, 20, 21, 22, 23]])
122 
123     >>> coarsen(np.min, x, {0: 2, 1: 3})
124     array([[ 0,  3],
125            [12, 15]])
126 
127     You must avoid excess elements explicitly
128 
129     >>> x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
130     >>> coarsen(np.min, x, {0: 3}, trim_excess=True)
131     array([1, 4])
132     """
133     # Insert singleton dimensions if they don't exist already
134     for i in range(x.ndim):
135         if i not in axes:
136             axes[i] = 1
137 
138     if trim_excess:
139         ind = tuple(slice(0, -(d % axes[i]))
140                     if d % axes[i] else
141                     slice(None, None) for i, d in enumerate(x.shape))
142         x = x[ind]
143 
144     # (10, 10) -> (5, 2, 5, 2)
145     newshape = tuple(concat([(x.shape[i] / axes[i], axes[i])
146                              for i in range(x.ndim)]))
147 
148     return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))
149 
150 
151 def trim(x, axes=None):
152     """ Trim boundaries off of array
153 
154     >>> x = np.arange(24).reshape((4, 6))
155     >>> trim(x, axes={0: 0, 1: 1})
156     array([[ 1,  2,  3,  4],
157            [ 7,  8,  9, 10],
158            [13, 14, 15, 16],
159            [19, 20, 21, 22]])
160 
161     >>> trim(x, axes={0: 1, 1: 1})
162     array([[ 7,  8,  9, 10],
163            [13, 14, 15, 16]])
164     """
165     if isinstance(axes, int):
166         axes = [axes] * x.ndim
167     if isinstance(axes, dict):
168         axes = [axes.get(i, 0) for i in range(x.ndim)]
169 
170     return x[tuple(slice(ax, -ax if ax else None) for ax in axes)]
171 
172 
173 try:
174     from numpy import broadcast_to
175 except ImportError:  # pragma: no cover
176     broadcast_to = npcompat.broadcast_to
177 
178 
179 def topk(k, x):
180     """ Top k elements of an array
181 
182     >>> topk(2, np.array([5, 1, 3, 6]))
183     array([6, 5])
184     """
185     # http://stackoverflow.com/a/23734295/616616 by larsmans
186     k = np.minimum(k, len(x))
187     ind = np.argpartition(x, -k)[-k:]
188     return np.sort(x[ind])[::-1]
189 
190 
191 def arange(start, stop, step, length, dtype):
192     res = np.arange(start, stop, step, dtype)
193     return res[:-1] if len(res) > length else res
194
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dask/array/chunk.py b/dask/array/chunk.py
--- a/dask/array/chunk.py
+++ b/dask/array/chunk.py
@@ -142,7 +142,7 @@
         x = x[ind]
 
     # (10, 10) -> (5, 2, 5, 2)
-    newshape = tuple(concat([(x.shape[i] / axes[i], axes[i])
+    newshape = tuple(concat([(x.shape[i] // axes[i], axes[i])
                              for i in range(x.ndim)]))
 
     return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))

{"golden_diff": "diff --git a/dask/array/chunk.py b/dask/array/chunk.py\n--- a/dask/array/chunk.py\n+++ b/dask/array/chunk.py\n@@ -142,7 +142,7 @@\n         x = x[ind]\n \n     # (10, 10) -> (5, 2, 5, 2)\n-    newshape = tuple(concat([(x.shape[i] / axes[i], axes[i])\n+    newshape = tuple(concat([(x.shape[i] // axes[i], axes[i])\n                              for i in range(x.ndim)]))\n \n     return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\n", "issue": "dask.array test failures on OS X\nGot this on an OS X machine where I ran the test suite out of curiosity (with Python 3.6):\r\n```\r\n____________________________________________________________________________ test_coarsen ____________________________________________________________________________\r\nTraceback (most recent call last):\r\n  File \"/Users/buildbot/antoine/dask/dask/array/tests/test_array_core.py\", line 628, in test_coarsen\r\n    assert_eq(chunk.coarsen(np.sum, x, {0: 2, 1: 4}),\r\n  File \"/Users/buildbot/antoine/dask/dask/array/chunk.py\", line 148, in coarsen\r\n    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\r\nTypeError: 'float' object cannot be interpreted as an integer\r\n______________________________________________________________________ test_coarsen_with_excess ______________________________________________________________________\r\nTraceback (most recent call last):\r\n  File \"/Users/buildbot/antoine/dask/dask/array/tests/test_array_core.py\", line 637, in test_coarsen_with_excess\r\n    np.array([0, 5]))\r\n  File \"/Users/buildbot/antoine/dask/dask/array/utils.py\", line 51, in assert_eq\r\n    a = a.compute(get=get_sync)\r\n  File \"/Users/buildbot/antoine/dask/dask/base.py\", line 94, in compute\r\n    (result,) = compute(self, traverse=False, **kwargs)\r\n  File \"/Users/buildbot/antoine/dask/dask/base.py\", line 201, in compute\r\n    results = get(dsk, keys, **kwargs)\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 544, in get_sync\r\n    raise_on_exception=True, **kwargs)\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 487, in get_async\r\n    fire_task()\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 483, in fire_task\r\n    callback=queue.put)\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 532, in apply_sync\r\n    res = func(*args, **kwds)\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 266, in execute_task\r\n    result = _execute_task(task, data)\r\n  File \"/Users/buildbot/antoine/dask/dask/async.py\", line 247, in _execute_task\r\n    return func(*args2)\r\n  File \"/Users/buildbot/antoine/dask/dask/array/chunk.py\", line 148, in coarsen\r\n    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\r\nTypeError: 'float' object cannot be interpreted as an integer\r\n____________________________________________________________________________ test_coarsen ____________________________________________________________________________\r\nTraceback (most recent call last):\r\n  File \"/Users/buildbot/antoine/dask/dask/array/tests/test_chunk.py\", line 98, in test_coarsen\r\n    y = coarsen(np.sum, x, {0: 2, 1: 4})\r\n  File \"/Users/buildbot/antoine/dask/dask/array/chunk.py\", line 148, in coarsen\r\n    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\r\nTypeError: 'float' object cannot be interpreted as an integer\r\n```\r\n\n", "before_files": [{"content": "\"\"\" A set of NumPy functions to apply per chunk \"\"\"\nfrom __future__ import absolute_import, division, print_function\n\nfrom collections import Container, Iterable, Sequence\nfrom functools import wraps\n\nfrom toolz import concat\nimport numpy as np\nfrom . import numpy_compat as npcompat\n\nfrom ..compatibility import getargspec\nfrom ..utils import ignoring\n\n\ndef keepdims_wrapper(a_callable):\n    \"\"\"\n    A wrapper for functions that don't provide keepdims to ensure that they do.\n    \"\"\"\n\n    if \"keepdims\" in getargspec(a_callable).args:\n        return a_callable\n\n    @wraps(a_callable)\n    def keepdims_wrapped_callable(x, axis=None, keepdims=None, *args, **kwargs):\n        r = a_callable(x, axis=axis, *args, **kwargs)\n\n        if not keepdims:\n            return r\n\n        axes = axis\n\n        if axes is None:\n            axes = range(x.ndim)\n\n        if not isinstance(axes, (Container, Iterable, Sequence)):\n            axes = [axes]\n\n        r_slice = tuple()\n        for each_axis in range(x.ndim):\n            if each_axis in axes:\n                r_slice += (None,)\n            else:\n                r_slice += (slice(None),)\n\n        r = r[r_slice]\n\n        return r\n\n    return keepdims_wrapped_callable\n\n\n# Wrap NumPy functions to ensure they provide keepdims.\nsum = keepdims_wrapper(np.sum)\nprod = keepdims_wrapper(np.prod)\nmin = keepdims_wrapper(np.min)\nmax = keepdims_wrapper(np.max)\nargmin = keepdims_wrapper(np.argmin)\nnanargmin = keepdims_wrapper(np.nanargmin)\nargmax = keepdims_wrapper(np.argmax)\nnanargmax = keepdims_wrapper(np.nanargmax)\nany = keepdims_wrapper(np.any)\nall = keepdims_wrapper(np.all)\nnansum = keepdims_wrapper(np.nansum)\n\ntry:\n    from numpy import nanprod, nancumprod, nancumsum\nexcept ImportError:  # pragma: no cover\n    nanprod = npcompat.nanprod\n    nancumprod = npcompat.nancumprod\n    nancumsum = npcompat.nancumsum\n\nnanprod = keepdims_wrapper(nanprod)\nnancumprod = keepdims_wrapper(nancumprod)\nnancumsum = keepdims_wrapper(nancumsum)\n\nnanmin = keepdims_wrapper(np.nanmin)\nnanmax = keepdims_wrapper(np.nanmax)\nmean = keepdims_wrapper(np.mean)\n\nwith ignoring(AttributeError):\n    nanmean = keepdims_wrapper(np.nanmean)\n\nvar = keepdims_wrapper(np.var)\n\nwith ignoring(AttributeError):\n    nanvar = keepdims_wrapper(np.nanvar)\n\nstd = keepdims_wrapper(np.std)\n\nwith ignoring(AttributeError):\n    nanstd = keepdims_wrapper(np.nanstd)\n\n\ndef coarsen(reduction, x, axes, trim_excess=False):\n    \"\"\" Coarsen array by applying reduction to fixed size neighborhoods\n\n    Parameters\n    ----------\n    reduction: function\n        Function like np.sum, np.mean, etc...\n    x: np.ndarray\n        Array to be coarsened\n    axes: dict\n        Mapping of axis to coarsening factor\n\n    Examples\n    --------\n    >>> x = np.array([1, 2, 3, 4, 5, 6])\n    >>> coarsen(np.sum, x, {0: 2})\n    array([ 3,  7, 11])\n    >>> coarsen(np.max, x, {0: 3})\n    array([3, 6])\n\n    Provide dictionary of scale per dimension\n\n    >>> x = np.arange(24).reshape((4, 6))\n    >>> x\n    array([[ 0,  1,  2,  3,  4,  5],\n           [ 6,  7,  8,  9, 10, 11],\n           [12, 13, 14, 15, 16, 17],\n           [18, 19, 20, 21, 22, 23]])\n\n    >>> coarsen(np.min, x, {0: 2, 1: 3})\n    array([[ 0,  3],\n           [12, 15]])\n\n    You must avoid excess elements explicitly\n\n    >>> x = np.array([1, 2, 3, 4, 5, 6, 7, 8])\n    >>> coarsen(np.min, x, {0: 3}, trim_excess=True)\n    array([1, 4])\n    \"\"\"\n    # Insert singleton dimensions if they don't exist already\n    for i in range(x.ndim):\n        if i not in axes:\n            axes[i] = 1\n\n    if trim_excess:\n        ind = tuple(slice(0, -(d % axes[i]))\n                    if d % axes[i] else\n                    slice(None, None) for i, d in enumerate(x.shape))\n        x = x[ind]\n\n    # (10, 10) -> (5, 2, 5, 2)\n    newshape = tuple(concat([(x.shape[i] / axes[i], axes[i])\n                             for i in range(x.ndim)]))\n\n    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\n\n\ndef trim(x, axes=None):\n    \"\"\" Trim boundaries off of array\n\n    >>> x = np.arange(24).reshape((4, 6))\n    >>> trim(x, axes={0: 0, 1: 1})\n    array([[ 1,  2,  3,  4],\n           [ 7,  8,  9, 10],\n           [13, 14, 15, 16],\n           [19, 20, 21, 22]])\n\n    >>> trim(x, axes={0: 1, 1: 1})\n    array([[ 7,  8,  9, 10],\n           [13, 14, 15, 16]])\n    \"\"\"\n    if isinstance(axes, int):\n        axes = [axes] * x.ndim\n    if isinstance(axes, dict):\n        axes = [axes.get(i, 0) for i in range(x.ndim)]\n\n    return x[tuple(slice(ax, -ax if ax else None) for ax in axes)]\n\n\ntry:\n    from numpy import broadcast_to\nexcept ImportError:  # pragma: no cover\n    broadcast_to = npcompat.broadcast_to\n\n\ndef topk(k, x):\n    \"\"\" Top k elements of an array\n\n    >>> topk(2, np.array([5, 1, 3, 6]))\n    array([6, 5])\n    \"\"\"\n    # http://stackoverflow.com/a/23734295/616616 by larsmans\n    k = np.minimum(k, len(x))\n    ind = np.argpartition(x, -k)[-k:]\n    return np.sort(x[ind])[::-1]\n\n\ndef arange(start, stop, step, length, dtype):\n    res = np.arange(start, stop, step, dtype)\n    return res[:-1] if len(res) > length else res\n", "path": "dask/array/chunk.py"}], "after_files": [{"content": "\"\"\" A set of NumPy functions to apply per chunk \"\"\"\nfrom __future__ import absolute_import, division, print_function\n\nfrom collections import Container, Iterable, Sequence\nfrom functools import wraps\n\nfrom toolz import concat\nimport numpy as np\nfrom . import numpy_compat as npcompat\n\nfrom ..compatibility import getargspec\nfrom ..utils import ignoring\n\n\ndef keepdims_wrapper(a_callable):\n    \"\"\"\n    A wrapper for functions that don't provide keepdims to ensure that they do.\n    \"\"\"\n\n    if \"keepdims\" in getargspec(a_callable).args:\n        return a_callable\n\n    @wraps(a_callable)\n    def keepdims_wrapped_callable(x, axis=None, keepdims=None, *args, **kwargs):\n        r = a_callable(x, axis=axis, *args, **kwargs)\n\n        if not keepdims:\n            return r\n\n        axes = axis\n\n        if axes is None:\n            axes = range(x.ndim)\n\n        if not isinstance(axes, (Container, Iterable, Sequence)):\n            axes = [axes]\n\n        r_slice = tuple()\n        for each_axis in range(x.ndim):\n            if each_axis in axes:\n                r_slice += (None,)\n            else:\n                r_slice += (slice(None),)\n\n        r = r[r_slice]\n\n        return r\n\n    return keepdims_wrapped_callable\n\n\n# Wrap NumPy functions to ensure they provide keepdims.\nsum = keepdims_wrapper(np.sum)\nprod = keepdims_wrapper(np.prod)\nmin = keepdims_wrapper(np.min)\nmax = keepdims_wrapper(np.max)\nargmin = keepdims_wrapper(np.argmin)\nnanargmin = keepdims_wrapper(np.nanargmin)\nargmax = keepdims_wrapper(np.argmax)\nnanargmax = keepdims_wrapper(np.nanargmax)\nany = keepdims_wrapper(np.any)\nall = keepdims_wrapper(np.all)\nnansum = keepdims_wrapper(np.nansum)\n\ntry:\n    from numpy import nanprod, nancumprod, nancumsum\nexcept ImportError:  # pragma: no cover\n    nanprod = npcompat.nanprod\n    nancumprod = npcompat.nancumprod\n    nancumsum = npcompat.nancumsum\n\nnanprod = keepdims_wrapper(nanprod)\nnancumprod = keepdims_wrapper(nancumprod)\nnancumsum = keepdims_wrapper(nancumsum)\n\nnanmin = keepdims_wrapper(np.nanmin)\nnanmax = keepdims_wrapper(np.nanmax)\nmean = keepdims_wrapper(np.mean)\n\nwith ignoring(AttributeError):\n    nanmean = keepdims_wrapper(np.nanmean)\n\nvar = keepdims_wrapper(np.var)\n\nwith ignoring(AttributeError):\n    nanvar = keepdims_wrapper(np.nanvar)\n\nstd = keepdims_wrapper(np.std)\n\nwith ignoring(AttributeError):\n    nanstd = keepdims_wrapper(np.nanstd)\n\n\ndef coarsen(reduction, x, axes, trim_excess=False):\n    \"\"\" Coarsen array by applying reduction to fixed size neighborhoods\n\n    Parameters\n    ----------\n    reduction: function\n        Function like np.sum, np.mean, etc...\n    x: np.ndarray\n        Array to be coarsened\n    axes: dict\n        Mapping of axis to coarsening factor\n\n    Examples\n    --------\n    >>> x = np.array([1, 2, 3, 4, 5, 6])\n    >>> coarsen(np.sum, x, {0: 2})\n    array([ 3,  7, 11])\n    >>> coarsen(np.max, x, {0: 3})\n    array([3, 6])\n\n    Provide dictionary of scale per dimension\n\n    >>> x = np.arange(24).reshape((4, 6))\n    >>> x\n    array([[ 0,  1,  2,  3,  4,  5],\n           [ 6,  7,  8,  9, 10, 11],\n           [12, 13, 14, 15, 16, 17],\n           [18, 19, 20, 21, 22, 23]])\n\n    >>> coarsen(np.min, x, {0: 2, 1: 3})\n    array([[ 0,  3],\n           [12, 15]])\n\n    You must avoid excess elements explicitly\n\n    >>> x = np.array([1, 2, 3, 4, 5, 6, 7, 8])\n    >>> coarsen(np.min, x, {0: 3}, trim_excess=True)\n    array([1, 4])\n    \"\"\"\n    # Insert singleton dimensions if they don't exist already\n    for i in range(x.ndim):\n        if i not in axes:\n            axes[i] = 1\n\n    if trim_excess:\n        ind = tuple(slice(0, -(d % axes[i]))\n                    if d % axes[i] else\n                    slice(None, None) for i, d in enumerate(x.shape))\n        x = x[ind]\n\n    # (10, 10) -> (5, 2, 5, 2)\n    newshape = tuple(concat([(x.shape[i] // axes[i], axes[i])\n                             for i in range(x.ndim)]))\n\n    return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)))\n\n\ndef trim(x, axes=None):\n    \"\"\" Trim boundaries off of array\n\n    >>> x = np.arange(24).reshape((4, 6))\n    >>> trim(x, axes={0: 0, 1: 1})\n    array([[ 1,  2,  3,  4],\n           [ 7,  8,  9, 10],\n           [13, 14, 15, 16],\n           [19, 20, 21, 22]])\n\n    >>> trim(x, axes={0: 1, 1: 1})\n    array([[ 7,  8,  9, 10],\n           [13, 14, 15, 16]])\n    \"\"\"\n    if isinstance(axes, int):\n        axes = [axes] * x.ndim\n    if isinstance(axes, dict):\n        axes = [axes.get(i, 0) for i in range(x.ndim)]\n\n    return x[tuple(slice(ax, -ax if ax else None) for ax in axes)]\n\n\ntry:\n    from numpy import broadcast_to\nexcept ImportError:  # pragma: no cover\n    broadcast_to = npcompat.broadcast_to\n\n\ndef topk(k, x):\n    \"\"\" Top k elements of an array\n\n    >>> topk(2, np.array([5, 1, 3, 6]))\n    array([6, 5])\n    \"\"\"\n    # http://stackoverflow.com/a/23734295/616616 by larsmans\n    k = np.minimum(k, len(x))\n    ind = np.argpartition(x, -k)[-k:]\n    return np.sort(x[ind])[::-1]\n\n\ndef arange(start, stop, step, length, dtype):\n    res = np.arange(start, stop, step, dtype)\n    return res[:-1] if len(res) > length else res\n", "path": "dask/array/chunk.py"}]}