Author: Antonio Cuni <[email protected]>
Branch: extradoc
Changeset: r5809:e5b2630698e6
Date: 2017-07-10 16:37 +0200
http://bitbucket.org/pypy/extradoc/changeset/e5b2630698e6/
Log: more slides
diff --git a/talk/ep2017/the-joy-of-pypy-jit/talk.rst
b/talk/ep2017/the-joy-of-pypy-jit/talk.rst
--- a/talk/ep2017/the-joy-of-pypy-jit/talk.rst
+++ b/talk/ep2017/the-joy-of-pypy-jit/talk.rst
@@ -168,3 +168,92 @@
...
|end_scriptsize|
+
+
+Version 2
+---------
+
+|scriptsize|
+
+.. sourcecode:: python
+
+ class Image(object):
+
+ def __init__(self, width, height, data=None):
+ self.width = width
+ self.height = height
+ if data is None:
+ self.data = array.array('B', [0]) * (width*height)
+ else:
+ self.data = data
+
+ def __getitem__(self, idx):
+ x, y = idx
+ return self.data[x + y*self.width]
+
+ def __setitem__(self, idx, value):
+ x, y = idx
+ self.data[x + y*self.width] = value
+
+|end_scriptsize|
+
+
+Version 3
+-------------
+
+|scriptsize|
+
+.. sourcecode:: python
+
+ _Point = namedtuple('_Point', ['x', 'y'])
+ class Point(_Point):
+ def __add__(self, other):
+ ox, oy = other
+ x = self.x + ox
+ y = self.y + oy
+ return self.__class__(x, y)
+
+ class ImageIter(object):
+ def __init__(self, x0, x1, y0, y1):
+ self.it = itertools.product(xrange(x0, x1), xrange(y0, y1))
+ def __iter__(self):
+ return self
+ def next(self):
+ x, y = next(self.it)
+ return Point(x, y)
+
+ class Image(v2.Image):
+ def noborder(self):
+ return ImageIter(1, self.width-1, 1, self.height-1)
+
+|end_scriptsize|
+
+Version 3
+-------------
+
+|scriptsize|
+
+.. sourcecode:: python
+
+ def sobel(img):
+ img = Image(*img)
+ out = Image(img.width, img.height)
+ for p in img.noborder():
+ dx = (-1.0 * img[p + (-1,-1)] +
+ 1.0 * img[p + ( 1,-1)] +
+ -2.0 * img[p + (-1, 0)] +
+ 2.0 * img[p + ( 1, 0)] +
+ -1.0 * img[p + (-1, 1)] +
+ 1.0 * img[p + ( 1, 1)])
+
+ dy = (-1.0 * img[p + (-1,-1)] +
+ -2.0 * img[p + ( 0,-1)] +
+ -1.0 * img[p + ( 1,-1)] +
+ 1.0 * img[p + (-1, 1)] +
+ 2.0 * img[p + ( 0, 1)] +
+ 1.0 * img[p + ( 1, 1)])
+
+ value = min(int(sqrt(dx*dx + dy*dy) / 2.0), 255)
+ out[p] = value
+
+|end_scriptsize|
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit