Skip to content

Commit

Permalink
Updated the convolve benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Jun 23, 2017
1 parent f791dee commit 8d7ad06
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 196 deletions.
3 changes: 0 additions & 3 deletions benchpress/benchmarks/convolve/python_numpy/bohrium.rst

This file was deleted.

59 changes: 14 additions & 45 deletions benchpress/benchmarks/convolve/python_numpy/convolve.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,28 @@
from __future__ import print_function
from PIL import Image
from benchpress import util
import numpy as np
from bohrium.stdviews import cartesian

def apply_filter(size, weight):
"""TODO: And what does this one do?"""

kernel = np.zeros((size, size))
totalsum = 0
kernelrad = size/2
distance = 0
caleuler = 1.0 /(2.0 * np.pi * weight**2)

for filterY in range(-kernelrad, kernelrad+1, 1):
for filterX in range(-kernelrad, kernelrad+1, 1):
distance = ((filterX * filterX)+(filterY*filterY))/(2 * (weight * weight))
kernel[filterY + kernelrad,filterX + kernelrad] = caleuler * np.exp(-distance)
totalsum += kernel[filterY + kernelrad, filterX + kernelrad]
kernel *= (1.0/totalsum)

return kernel

def convolve_init(fsize, photo='/tmp/Hell.jpg'):
"""TODO: Describe the data loaded/generated by this function."""

img = Image.open(photo)
rgb = np.array(img)
tones = np.array((0.3, 0.6, 0.11))
rgb = np.add.reduce((rgb*tones[np.newaxis, np.newaxis, :]), axis=2)
kernel = apply_filter(fsize, 13.0)

return (rgb, kernel)

def convolve(image, image_filter):
"""TODO: Describe the benchmark."""

views = cartesian(image, len(image_filter))
result = sum(d[0]*d[1] for d in zip(views, image_filter.flatten()))

return result

def main():
"""
Example parameter: --size=25.
This will execute on a something related to 25....
Example parameter : --size=10000000*10*10
"""
B = util.Benchmark()
(N,) = B.size
image, image_filter = convolve_init(N)

(image_size, filter_size, I) = B.size

image = B.random_array((image_size,))
image_filter = B.random_array((filter_size,))

B.start()
result = convolve(image, image_filter)
for _ in range(I):
R = np.convolve(image, image_filter)
B.flush()
B.stop()
B.pprint()
if B.outputfn:
B.tofile(B.outputfn, {'res': R})

if B.verbose:
print (R)

if __name__ == "__main__":
main()
Empty file.
9 changes: 0 additions & 9 deletions benchpress/benchmarks/convolve/python_numpy/issues.rst

This file was deleted.

3 changes: 0 additions & 3 deletions benchpress/benchmarks/convolve_2d/python_numpy/bohrium.rst

This file was deleted.

58 changes: 0 additions & 58 deletions benchpress/benchmarks/convolve_2d/python_numpy/convolve_2d.py

This file was deleted.

Empty file.
9 changes: 0 additions & 9 deletions benchpress/benchmarks/convolve_2d/python_numpy/issues.rst

This file was deleted.

3 changes: 0 additions & 3 deletions benchpress/benchmarks/convolve_3d/python_numpy/bohrium.rst

This file was deleted.

56 changes: 0 additions & 56 deletions benchpress/benchmarks/convolve_3d/python_numpy/convolve_3d.py

This file was deleted.

Empty file.
10 changes: 0 additions & 10 deletions benchpress/benchmarks/convolve_3d/python_numpy/issues.rst

This file was deleted.

0 comments on commit 8d7ad06

Please sign in to comment.