Skip to content

Instantly share code, notes, and snippets.

@shoyer
shoyer / gist:9d06b7294a8d06981ec7
Last active Aug 29, 2015
numba performance with indexing
View gist:9d06b7294a8d06981ec7
from numba import guvectorize, jit
import numpy as np
import pandas as pd
@guvectorize(['void(float64[:], int64[:], float64[:], float64[:])'],
'(x),(x),(y)->()')
def _grouped_sum_guvec_simple(values, labels, target, out):
for i in range(len(values)):
idx = labels[i]
target[idx] += values[i]
View pandas magic.py
import inspect
import types
def injected(df, thunk):
"""Evaluate a thunk in the context of DataFrame
>>> df = pd.DataFrame({'x': [0, 1, 2]}, index=['a', 'b', 'c'])
>>> injected(df, lambda: x ** 2)
a 0
View xray_nd_groupby.py
import functools
def nd_groupby_apply(ds, dims, func):
if isinstance(dims, str):
dims = [dims]
if len(dims) > 1:
func = functools.partial(nd_groupby_apply, dims=dims[1:], func=func)
return ds.groupby(dims[0]).apply(func)
def nd_group_over_apply(ds, dims, func):
View nbformat3.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shoyer
shoyer / gist:bfdda77549dcead3e996
Created Apr 15, 2015
xray groupby transform profiling
View gist:bfdda77549dcead3e996
4926489 function calls (4835695 primitive calls) in 11.314 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
21928 1.839 0.000 4.441 0.000 slicing.py:202(slice_slices_and_integers)
4 1.521 0.380 1.610 0.402 {sum}
109869 1.494 0.000 1.494 0.000 {method 'update' of 'dict' objects}
131496 1.173 0.000 1.333 0.000 slicing.py:241(_slice_1d)
65748 0.624 0.000 1.551 0.000 slicing.py:544(new_blockdim)
View pipe-demo-seaborn.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View numba-benchmarks.py
@jit(nopython=True)
def g0(x, y):
s = 0
for i in range(len(x)):
s += x[i] * y[i]
return s
@jit(nopython=True)
def g1(x, y):
View resample-laziness.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View rechunk-benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View rechunk-benchmarks (1).ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.