Rewrite Dask Array's `pad` to add only new chunks (#4152)
Rewrite Dask Array's `pad` to add only new chunks (#4152)

* Create `get_pad_shapes_chunks` helper function

Adds a helper function for getting the shapes and chunks for the arrays
to be padded on either end of the result. Useful in conjunction with
broadcasting operations like those in `pad_edge` or `pad_stats`.

* Create `linear_ramp_chunk` helper function

Adds a helper function to be used for chunks in the Dask graph in the
`linear_ramp` case of `pad` to build border chunks.

* Rewrite Dask Array's `pad` to add only new chunks

In nearly all cases Dask Array's `pad` would handle the intended padding
in new chunks concatenated around the input array. This is nice as it
ensure the original array is passed through unaltered with padding
chunks being generated (possibly using the original arrays data) as
needed by downstream computations.

However this was not the case for the `constant`, `edge`, and
`linear_ramp` modes where NumPy's `pad` was called on the edge chunks
instead. This could be bad for a few reasons. First the edge chunks
would increase in size based on the padding width in these specific
cases. Second NumPy's `pad` appears to have performance penalties (due
to temporaries and copying) if these array chunks are quite large. Third
inconsistent handling of chunking in modes causes unnecessary confusion.

To fix these issues, this rewrites Dask Array's `pad` in these cases to
not make use of NumPy's `pad`. Instead it performs the padding
operations itself by building up the chunks for each dimension on either
end and concatenating them with the original array. Thus the original
array is simply passed through while padded chunks are generated around
the edges.

* Drop `np_pad` wrapper

As we no longer use the `np_pad` wrapper function in, `pad_edge` or any
of the other padding functions, go ahead and drop it.

jcrist/dask,jakirkham/dask,blaze/dask,jakirkham/dask,mrocklin/dask,ContinuumIO/dask,jcrist/dask,mrocklin/dask,blaze/dask,dask/dask,dask/dask,ContinuumIO/dask