Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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): |