-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
14 additions
and
196 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
benchpress/benchmarks/convolve_2d/python_numpy/convolve_2d.py
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
benchpress/benchmarks/convolve_3d/python_numpy/convolve_3d.py
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.