Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ repos:
hooks:
- id: autoflake
args: ["--in-place"]
exclude: ^torch_np/tests/numpy_tests/
exclude: '^torch_np/tests/numpy_tests/|^e2e'
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
exclude: ^torch_np/tests/numpy_tests/
exclude: '^torch_np/tests/numpy_tests/|^e2e'
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
exclude: ^torch_np/tests/numpy_tests/
exclude: '^torch_np/tests/numpy_tests/|^e2e'
Binary file added e2e/mandelbrot/mandelbrot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions e2e/mandelbrot/mandelbrot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -----------------------------------------------------------------------------
# From Numpy to Python
# Copyright (2017) Nicolas P. Rougier - BSD license
# More information at https://github.com/rougier/numpy-book
# -----------------------------------------------------------------------------
#import numpy as np
import torch_np as np

# from mandelbrot_numpy_1 import mandelbrot # copy-paste below

def mandelbrot(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0):
# Adapted from https://www.ibm.com/developerworks/community/blogs/jfp/...
# .../entry/How_To_Compute_Mandelbrodt_Set_Quickly?lang=en
X = np.linspace(xmin, xmax, xn, dtype=np.float32)
Y = np.linspace(ymin, ymax, yn, dtype=np.float32)
C = X + Y[:,None]*1j
N = np.zeros(C.shape, dtype=int)
Z = np.zeros(C.shape, np.complex64)
for n in range(maxiter):
I = np.less(abs(Z), horizon)
N[I] = n
Z[I] = Z[I]**2 + C[I]
N[N == maxiter-1] = 0
return Z, N


if __name__ == '__main__':
from matplotlib import colors
import matplotlib.pyplot as plt
## from timeit import timeit

# Benchmark
xmin, xmax, xn = -2.25, +0.75, int(3000/3)
ymin, ymax, yn = -1.25, +1.25, int(2500/3)
maxiter = 200
## timeit("mandelbrot_1(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals())
## timeit("mandelbrot_2(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals())
## timeit("mandelbrot_3(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals())

# Visualization
xmin, xmax, xn = -2.25, +0.75, int(3000/2)
ymin, ymax, yn = -1.25, +1.25, int(2500/2)
maxiter = 200
horizon = 2.0 ** 40
log_horizon = np.log(np.log(horizon))/np.log(2)
Z, N = mandelbrot(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon)

# Normalized recount as explained in:
# http://linas.org/art-gallery/escape/smooth.html
M = np.nan_to_num(N + 1 - np.log(np.log(abs(Z)))/np.log(2) + log_horizon)

dpi = 72
width = 10
height = 10*yn/xn

fig = plt.figure(figsize=(width, height), dpi=dpi)
ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False, aspect=1)

light = colors.LightSource(azdeg=315, altdeg=10)

plt.imshow(light.shade(M.tensor.numpy(), cmap=plt.cm.hot, vert_exag=1.5,
norm = colors.PowerNorm(0.3), blend_mode='hsv'),
extent=[xmin, xmax, ymin, ymax], interpolation="bicubic")
ax.set_xticks([])
ax.set_yticks([])
plt.savefig("mandelbrot.png")
plt.show()

184 changes: 184 additions & 0 deletions e2e/maze/maze.output.np.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
Z = [[ True True True ... True True True]
[ True False False ... True False True]
[ True False True ... True False True]
...
[ True False True ... True False True]
[ True False False ... True False True]
[ True True True ... True True True]]
P = [[79 39]
[79 38]
[79 37]
[79 36]
[79 35]
[78 35]
[77 35]
[76 35]
[75 35]
[75 36]
[75 37]
[74 37]
[73 37]
[72 37]
[71 37]
[71 36]
[71 35]
[70 35]
[69 35]
[69 34]
[69 33]
[68 33]
[67 33]
[67 34]
[67 35]
[67 36]
[67 37]
[66 37]
[65 37]
[64 37]
[63 37]
[62 37]
[61 37]
[61 38]
[61 39]
[60 39]
[59 39]
[58 39]
[57 39]
[56 39]
[55 39]
[54 39]
[53 39]
[52 39]
[51 39]
[50 39]
[49 39]
[48 39]
[47 39]
[46 39]
[45 39]
[45 38]
[45 37]
[45 36]
[45 35]
[44 35]
[43 35]
[43 34]
[43 33]
[43 32]
[43 31]
[44 31]
[45 31]
[45 30]
[45 29]
[46 29]
[47 29]
[47 28]
[47 27]
[48 27]
[49 27]
[50 27]
[51 27]
[51 26]
[51 25]
[51 24]
[51 23]
[50 23]
[49 23]
[48 23]
[47 23]
[46 23]
[45 23]
[44 23]
[43 23]
[43 22]
[43 21]
[42 21]
[41 21]
[40 21]
[39 21]
[38 21]
[37 21]
[36 21]
[35 21]
[34 21]
[33 21]
[32 21]
[31 21]
[31 20]
[31 19]
[32 19]
[33 19]
[33 18]
[33 17]
[33 16]
[33 15]
[33 14]
[33 13]
[32 13]
[31 13]
[30 13]
[29 13]
[29 12]
[29 11]
[28 11]
[27 11]
[26 11]
[25 11]
[24 11]
[23 11]
[22 11]
[21 11]
[20 11]
[19 11]
[19 12]
[19 13]
[19 14]
[19 15]
[19 16]
[19 17]
[19 18]
[19 19]
[18 19]
[17 19]
[16 19]
[15 19]
[15 18]
[15 17]
[14 17]
[13 17]
[12 17]
[11 17]
[11 16]
[11 15]
[11 14]
[11 13]
[11 12]
[11 11]
[11 10]
[11 9]
[10 9]
[ 9 9]
[ 8 9]
[ 7 9]
[ 6 9]
[ 5 9]
[ 4 9]
[ 3 9]
[ 3 10]
[ 3 11]
[ 3 12]
[ 3 13]
[ 2 13]
[ 1 13]
[ 1 12]
[ 1 11]
[ 1 10]
[ 1 9]
[ 1 8]
[ 1 7]
[ 1 6]
[ 1 5]
[ 1 4]
[ 1 3]
[ 1 2]
[ 1 1]]
Loading