home / github / pull_requests

Menu
  • GraphQL API
  • Search all tables

pull_requests: 137274781

This data as json

id node_id number state locked title user body created_at updated_at closed_at merged_at merge_commit_sha assignee milestone draft head base author_association auto_merge repo url merged_by
137274781 MDExOlB1bGxSZXF1ZXN0MTM3Mjc0Nzgx 1517 closed 0 Automatic parallelization for dask arrays in apply_ufunc 1217238 This lets you parallelize a function designed for numpy inputs just by adding a few keyword arguments to `apply_ufunc`. Example usage, to calculate rank correlation between two variables (this will probably turn into an example for the docs): ```python import numpy as np import xarray as xr import bottleneck def covariance_gufunc(x, y): return ((x - x.mean(axis=-1, keepdims=True)) * (y - y.mean(axis=-1, keepdims=True))).mean(axis=-1) def correlation_gufunc(x, y): return covariance_gufunc(x, y) / (x.std(axis=-1) * y.std(axis=-1)) def spearman_correlation_gufunc(x, y): x_ranks = bottleneck.rankdata(x, axis=-1) y_ranks = bottleneck.rankdata(y, axis=-1) return correlation_gufunc(x_ranks, y_ranks) def spearman_correlation(x, y, dim): return xr.core.compuation.apply_ufunc( spearman_correlation_gufunc, x, y, input_core_dims=[[dim], [dim]], dask='parallelized', output_dtypes=[float]) ``` We get a nice 5x speedup for this compute bound task: ``` In [56]: rs = np.random.RandomState(0) In [57]: array1 = xr.DataArray(rs.randn(1000, 100000), dims=['place', 'time']) # 800MB In [58]: array2 = array1 + 0.5 * rs.randn(1000, 100000) # using one core, on numpy arrays In [61]: %time _ = spearman_correlation(array1, array2, 'time') CPU times: user 21.6 s, sys: 2.84 s, total: 24.5 s Wall time: 24.9 s # using all my laptop's cores, with dask In [63]: r = spearman_correlation(array1.chunk({'place': 10}), array2.chunk({'place': 10}), 'time') In [64]: %time _ = r.compute() CPU times: user 30.9 s, sys: 1.74 s, total: 32.6 s Wall time: 4.59 s ``` Still needs examples in the documentation. The next step is finally expose `apply_ufunc` as public API :). - [x] Closes #585 - [x] Tests added / passed - [x] Passes ``git diff upstream/master | flake8 --diff`` - [x] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API cc @mrocklin 2017-08-23T17:27:36Z 2017-10-09T23:28:52Z 2017-10-09T23:26:06Z 2017-10-09T23:26:06Z b46fcd656391d786b8d25b0615f6d4bd30b524b7     0 bdeb875ac7160f4e17c6821413fbb684edd5d483 3fb5cbbeabef9d1df538ffa11cb01e6c09ea17a4 MEMBER   13221727 https://github.com/pydata/xarray/pull/1517  

Links from other tables

  • 3 rows from pull_requests_id in labels_pull_requests
Powered by Datasette · Queries took 0.666ms