Exemple #1
0

class Kernel(StencilKernel):
    def kernel(self, in_img, out_img):
        for x in out_img.interior_points():
            out_img[x] = in_img[x]
            for y in in_img.neighbors(x, 0):
                out_img[x] += 0.125 * in_img[y]
            for z in in_img.neighbors(x, 1):
                out_img[x] -= 0.125 * 2.0 * in_img[z]


kernel = Kernel()
kernel.should_unroll = False
out_grid = StencilGrid([time_steps, width, height])
out_grid.ghost_depth = 1
in_grid = StencilGrid([time_steps, width, height])
in_grid.ghost_depth = 1

base = 1024
r = random.seed()
for i in range(width):
    for j in range(height):
        in_grid.data[(0, i, j)] = random.randrange(1024) * 1.0

in_grid.neighbor_definition[0] = [(-1, 1, 0), (-1, -1, 0), (-1, 0, 1),
                                  (-1, 0, -1)]
in_grid.neighbor_definition[1] = [(-1, 0, 0), (-1, 0, 0)]


class Timer:
Exemple #2
0
    return result


def distance(x, y):
    return math.sqrt(sum([(x[i] - y[i])**2 for i in range(0, len(x))]))


pixels = map(ord,
             list(image_in.read(width * height)))  # Read in grayscale values
# pixels = image_in.read(width * height)    # Read in grayscale values
# intensity = float(sum(pixels))/len(pixels)

kernel = Kernel()
kernel.should_unroll = False
out_grid = StencilGrid([width, height])
out_grid.ghost_depth = radius
in_grid = StencilGrid([width, height])
in_grid.ghost_depth = radius
for x in range(-radius, radius + 1):
    for y in range(-radius, radius + 1):
        in_grid.neighbor_definition[1].append((x, y))

for x in range(0, width):
    for y in range(0, height):
        in_grid.data[(x, y)] = pixels[y * width + x]

gaussian1 = gaussian(stdev_d, radius * 2)
gaussian2 = gaussian(stdev_s, 256)


class Timer:
Exemple #3
0
time_steps = 500


class Kernel(StencilKernel):
    def kernel(self, in_img, out_img):
        for x in out_img.interior_points():
            out_img[x] = in_img[x]
            for y in in_img.neighbors(x, 0):
                out_img[x] += 0.125 * in_img[y]
            for z in in_img.neighbors(x, 1):
                out_img[x] -= 0.125 * 2.0 * in_img[z]

kernel = Kernel()
kernel.should_unroll = False
out_grid = StencilGrid([time_steps, width, height])
out_grid.ghost_depth = 1
in_grid = StencilGrid([time_steps, width, height])
in_grid.ghost_depth = 1

base = 1024
r = random.seed()
for i in range(width):
    for j in range(height):
        in_grid.data[(0, i, j)] = random.randrange(1024) * 1.0

in_grid.neighbor_definition[0] = [(-1, 1, 0), (-1, -1, 0),
                                  (-1, 0, 1), (-1, 0, -1)]
in_grid.neighbor_definition[1] = [(-1, 0, 0), (-1, 0, 0)]


class Timer:
Exemple #4
0
    for x in range(length):
        result[x] = scale * math.exp(float(x) * float(x) * divisor)
    return result


def distance(x, y):
    return math.sqrt(sum([(x[i]-y[i])**2 for i in range(0, len(x))]))

pixels = map(ord, list(image_in.read(width * height))) # Read in grayscale values
# pixels = image_in.read(width * height)    # Read in grayscale values
# intensity = float(sum(pixels))/len(pixels)

kernel = Kernel()
kernel.should_unroll = False
out_grid = StencilGrid([width, height])
out_grid.ghost_depth = radius
in_grid = StencilGrid([width, height])
in_grid.ghost_depth = radius
for x in range(-radius, radius+1):
    for y in range(-radius, radius+1):
        in_grid.neighbor_definition[1].append((x, y))

for x in range(0, width):
    for y in range(0, height):
        in_grid.data[(x, y)] = pixels[y * width + x]

gaussian1 = gaussian(stdev_d, radius*2)
gaussian2 = gaussian(stdev_s, 256)


kernel.kernel(in_grid, gaussian1, gaussian2, out_grid)