Skip to content

Instantly share code, notes, and snippets.

Stephan Hoyer shoyer

Block or report user

Report or block shoyer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View canonicalize_gufunc_axis.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gist:92f8beb8bf9b0a66da69
def transform_state_vector(rho, U):
N = len(U)
if rho.shape[-1] == N:
# rho is in Hilbert space
pass
elif rho.shape[-1] == N ** 2:
# rho is in Liouville space
U = np.kron(U, U)
else:
raise ValueError('basis transformation incompatible with '
View simpler_stride_ticks.py
import numpy as np
from numpy.lib.stride_tricks import as_strided
def broadcast_to(array, shape):
"""Expand a numpy.ndarray to a new shape according to broadcasting rules
"""
array = np.asarray(array)
# will raise ValueError if shapes incompatible
np.nditer((array,), itershape=shape)
@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):
You can’t perform that action at this time.