Ejemplo n.º 1
0
def parakeet_dists(W, E = None):
  C = init(W,E)
  m,n = C.shape
  assert m == n
  vertices = np.arange(n)
  def min_row(c_row, a_row):
    return map(min, c_row, a_row)
  
  for k in vertices:
    from_k = C[:, k]
    to_k = C[k, :]
    A = parakeet.allpairs(parakeet.add, from_k, to_k)
    C = parakeet.each(min_row, C, A)
  return C
Ejemplo n.º 2
0
def allpairs_elt_diff(x,y):
    return parakeet.allpairs(lambda xi,yi: xi - yi, x, y)
Ejemplo n.º 3
0
def adverb_matmult(X,Y):
  return parakeet.allpairs(dot, X, Y)
Ejemplo n.º 4
0
def allpairs_dist_adverb(X,Y):
  return parakeet.allpairs(sqr_dist, X, Y)
Ejemplo n.º 5
0
 def matmult(X,Y):
   return parakeet.allpairs(dot, X, Y)
Ejemplo n.º 6
0
def matmult_allpairs(X,Y):
  return allpairs(dot, X, Y, axis = (0,1))
Ejemplo n.º 7
0
def matmult_allpairs(X, Y):
    return allpairs(dot, X, Y, axis=(0, 1))
Ejemplo n.º 8
0
def allpairs_left2d(X, Y):
  return parakeet.allpairs(allpairs_left_helper, X, Y, axis=0)
Ejemplo n.º 9
0
def mm(X,Y):
  return par.allpairs(par.dot, X, Y.T, axis=0)
Ejemplo n.º 10
0
def adverb_matmult(X,Y):
  return allpairs(dot, X, Y)
Ejemplo n.º 11
0
def allpairs_dist_adverb(X, Y):
    return parakeet.allpairs(sqr_dist, X, Y)
Ejemplo n.º 12
0
def par_blur():
  return allpairs(gaussian_conv, iidxs, jidxs)
Ejemplo n.º 13
0
def adverb_outer_prod(x, y):
    return allpairs(multiply, x, y)
Ejemplo n.º 14
0
def parakeet_update_assignments(X, centroids):
  dists = allpairs(sqr_dist, X, centroids)

  return np.argmin(dists, 1)
Ejemplo n.º 15
0
def adverb_outer_prod(x,y):
  return allpairs(multiply, x, y)
Ejemplo n.º 16
0
def apd(X,Y):
  return parakeet.allpairs(sqr_dist, X, Y)
Ejemplo n.º 17
0
def isolated_iter(n_rows, n_cols, kernel_size, n_repeats = 3):
    print "Generating random image of size %d x %d"% (n_rows, n_cols)
    image = np.random.random((n_rows, n_cols))
    kernel = gaussian_kernel(kernel_size)
    kw, kh = kernel.shape
    print "Kernel size: %d x %d" % (kw, kh)
    row_indices = np.arange(n_rows)[kernel_size:-kernel_size]
    col_indices = np.arange(n_cols)[kernel_size:-kernel_size]

    def conv_pixel(i,j):
      window = image[i-kernel_size:i+kernel_size+1, 
                     j-kernel_size:j+kernel_size+1]
      result = 0.0
      for it in range(kw):
        for jt in range(kh):
          result = result + window[it,jt] * kernel[it,jt]
      return result 
    print "Warming up JIT (without tiling)"
    # warm up parakeet with a first run 
    parakeet.config.opt_tile = False
    _ = parakeet.allpairs(conv_pixel, row_indices, col_indices)
    print "Warming up JIT (with tiling)"
    parakeet.config.opt_tile = True
    _ = parakeet.allpairs(conv_pixel, row_indices, col_indices)
    
    times = np.array([0.0]*4)

    for _ in xrange(n_repeats):      
      # generate the data transposed and then transpose it
      # again since Parakeet is currently cobbled by an 
      # inability to use any axis other than 0

      start = time.time()
      np_result = scipy.ndimage.convolve(image, kernel)
      # scipy.signal.convolve2d(image, kernel, 'valid')
      times[0] += time.time() - start
      # trim the image to make the convolutions comparable  
      np_result = np_result[kernel_size:-kernel_size, 
                            kernel_size:-kernel_size]
      
      parakeet.config.opt_tile = False
      start = time.time()
      parakeet_result = parakeet.allpairs(conv_pixel, row_indices, col_indices) 
      times[1] += time.time() - start 
      print "...par_runtime without tiling: %f" % adverb_api.par_runtime
        
      # print "...running with tiling & search..."  
      parakeet.config.opt_tile = True
      parakeet.config.use_cached_tile_sizes = False
      start = time.time()
      parakeet_tile_result = parakeet.allpairs(conv_pixel, row_indices, col_indices) 
      times[2] += time.time() - start
      print "...par_runtime with tiling & search: %f" % adverb_api.par_runtime
       
      # print "...running with tiling & cached tile sizes..."  
      parakeet.config.opt_tile = True
      parakeet.config.use_cached_tile_sizes = True
      start = time.time()
      _ = parakeet.allpairs(conv_pixel, row_indices, col_indices) 
      times[3] += time.time() - start
      print "...par_runtime for cached tile sizes: %f" % adverb_api.par_runtime
        
        
      rmse = np.sqrt(np.mean( (parakeet_result - np_result) ** 2))
      rmse_tile = np.sqrt(np.mean( (parakeet_tile_result - np_result) ** 2))
      # print "(RMSE) without tiling: %s, with tiling: %s " %(rmse, rmse_tile)
      assert rmse < 0.0001
      assert rmse_tile < 0.0001
    return repr(times / n_repeats)
Ejemplo n.º 18
0
def allpairs_add(x):
  return parakeet.allpairs(np.add, x, x)
Ejemplo n.º 19
0
def parakeet_update_assignments(X, centroids):
  dists = allpairs(sqr_dist, X, centroids)

  return np.argmin(dists, 1)