Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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 game(word, max_guesses=10): | |
'''Given a word and a guess limit, returns a | |
coroutine for playing hangman. Guess letters | |
by sending messages to the coroutine. Returns | |
True if you win, False otherwise. | |
Example | |
>>> g = game('jazz', 10) | |
>>> next(g) # prime the coroutine | |
>>> g.send('e') # guess 'e' |
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 predict_over_time(x, y, z, overlay=False): | |
"Predicts a quantity at times = 0, 1, ... 14" | |
out = np.zeros((x.shape[0], 15)) | |
for t in range(15): | |
out[:, t] = t * x ** 2 + y - 2 * z - 2 * t | |
adj = 1.5 if overlay else 1.0 | |
return adj * out |
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 jit | |
@jit | |
def jitted_func(x, y, z, overlay=False): | |
"Predicts a quantity at times = 0, 1, ... 14" | |
out = np.zeros((x.shape[0], 15)) | |
for t in range(15): | |
out[:, t] = t * x ** 2 + y - 2 * z - 2 * t | |
adj = 1.5 if overlay else 1.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
from numba import guvectorize | |
@guvectorize('i8, f8, f8, b1, f8[:], f8[:]', | |
'(), (), (), (), (s) -> (s)') | |
def fast_predict_over_time(x, y, z, overlay, _, out): | |
adj = 1.5 if overlay else 1.0 | |
for t in range(len(out)): | |
out[t] = adj * (t * x ** 2 + y - 2 * z - 2 * t) |
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
res = np.zeros((n, 15)) | |
%%timeit -n 100 | |
_ = fast_predict_over_time(x, y, z, False, res) # 100 loops, best of 3: 575 µs per loop |
OlderNewer