Skip to content

Instantly share code, notes, and snippets.

@shoyer
shoyer / jax-gradient-benchmark.ipynb
Created January 8, 2020 04:57
jax gradient benchmark.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / numpy-duck-array-ecosystem-graph.ipynb
Created August 28, 2019 16:20
NumPY duck array ecosystem graph
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / gufunc-numba-axis-examples.ipynb
Created September 19, 2018 18:52
gufunc-numba-axis-examples.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / dask-task-class-benchmark.ipynb
Last active August 17, 2018 19:20
Dask Task class benchmark.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / resize-non-integer-local-mean.ipynb
Created July 19, 2018 18:41
resize non-integer local mean.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / notebook.ipynb
Last active July 24, 2018 17:04
nep-18-example-implementation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / scipy-vs-numba-interp1d.ipynb
Last active September 18, 2019 08:05
scipy vs numba interp1d.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

I'll mention one other option that I've been contemplating recently, a bit of a hybrid of solutions 1 and 2:

  • We could build a new library with dispatchable functions inside NumPy itself, e.g., "numpy.api."

Functions in numpy.api work just like those in numpy, with two critical differences:

  1. They support overloading, via some to be determined mechanism.
  2. They don't coerce unknown types to np.array() using __array__().

This approach has a number of advantages over adjusting existing NumPy functions:

  • Backwards compatibility. For any particular numpy function without overloads, there is assuredly existing code that relies on it always coercing to numpy arrays. Every time we add a new overload in NumPy (e.g., np.any() recently), we've seen things break in downstream libraries like pandas. Even if we require downstream libraries to opt-in (e.g., by implementing __array_ufunc__) that just pushes the breakage downstream.
  • Predictability. We can remove any uncertainty over whether a NumPy function s
# Copyright 2017 Google LLC.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
TypeError Traceback (most recent call last)
~/conda/envs/xarray-py36/lib/python3.6/site-packages/distributed/protocol/pickle.py in dumps(x)
37 try:
---> 38 result = pickle.dumps(x, protocol=pickle.HIGHEST_PROTOCOL)
39 if len(result) < 1000:
TypeError: can't pickle netCDF4._netCDF4.Variable objects
During handling of the above exception, another exception occurred: