def gen_map(a, b):
    if len(a.shape) == len(b.shape):
        for i in range(len(a.shape)):
            if a.shape[i] != b.shape[i]: return [a, b]
        return [expr.add(a, b)]

    return [a, b]
def shortestPath(ctx, dim, numIters):
	dist = eager(
			expr.shuffle(
				expr.ndarray(
					(dim, 1),
					dtype = np.int64,
					tile_hint = (dim / ctx.num_workers, 1)
				),
			make_dist,
			)
		)

	linkMatrix = eager(
				expr.shuffle(
					expr.ndarray(
						(dim, dim),
						dtype = np.int64,
						tile_hint = (dim, dim / ctx.num_workers)),
				make_matrix,
				))

	startCompute = time.time()
	for it in range(numIters):
		first = expr.add(dist, linkMatrix)
		second = first.min(axis = 0)
		dist = second.reshape(dim, 1)
	dist.evaluate()
	endCompute = time.time()
	return endCompute - startCompute
def gen_map(a, b):
  if len(a.shape) == len(b.shape):
    for i in range(len(a.shape)):
      if a.shape[i] != b.shape[i]: return [a, b]
    return [expr.add(a, b)]

  return [a, b]
Esempio n. 4
0
    def test_broadcast(self):
        a = expr.ones((100, 1, 100, 100)).force()
        b = expr.ones((10, 100, 1)).force()
        a, b = broadcast.broadcast((a, b))
        c = expr.add(a, b).force()
        d = expr.sub(a, b).force()

        n = np.ones((100, 10, 100, 100))
        n1 = n + n
        n2 = n - n
        Assert.all_eq(n1, c.glom())
        Assert.all_eq(n2, d.glom())
Esempio n. 5
0
  def test_broadcast(self):
    a = expr.ones((100, 1, 100, 100)).force()
    b = expr.ones((10, 100, 1)).force()
    a, b = broadcast.broadcast((a, b))
    c = expr.add(a, b).force()
    d = expr.sub(a, b).force()

    n = np.ones((100, 10, 100, 100))
    n1 = n + n
    n2 = n - n
    Assert.all_eq(n1, c.glom())
    Assert.all_eq(n2, d.glom())
Esempio n. 6
0
 def test_sparse_operators(self):
   x = expr.sparse_diagonal(ARRAY_SIZE)
   #print x.glom().todense()
   
   y = x
   print 'test add'
   #z = expr.add(x, y)
   z = expr.add(x, y)
   print z.glom().todense()
   
   print 'test minus'   
   z = expr.sub(x, y)
   print z.glom().todense()
   
   print 'test multiply'
   z = expr.dot(x, x)
   print z.glom().todense()
Esempio n. 7
0
 def test_sparse_operators(self):
   x = expr.sparse_diagonal(ARRAY_SIZE)
   #print x.glom().todense()
   
   y = x
   print 'test add'
   #z = expr.add(x, y)
   z = expr.add(x, y)
   print z.glom().todense()
   
   print 'test minus'   
   z = expr.sub(x, y)
   print z.glom().todense()
   
   print 'test multiply'
   z = expr.dot(x, x)
   print z.glom().todense()
Esempio n. 8
0
  def test_trace(self):
    devnull = open(os.devnull, 'w')
    with RedirectStdStreams(stdout = devnull, stderr = devnull):
      t1 = expr.randn(100, 100)
      t2 = expr.randn(200, 100)
      t3 = expr.add(t1, t2)
      t4 = expr.randn(300, 100)
      t5 = expr.add(t3, t4)
      t6 = expr.randn(400, 100)
      t7 = expr.add(t6, t5)
      t8 = t7.optimized()
      try:
        t8.force()
      except Exception as e:
        pass

      t1 = expr.randn(100, 100)
      t2 = expr.randn(100, 100)
      t3 = expr.dot(t1, t2)
      t4 = expr.randn(200, 100)
      t5 = expr.add(t3, t4)
      t6 = t5.optimized()
      try:
        t6.force()
      except Exception as e:
        pass

      t1 = expr.randn(100, 100)
      t2 = expr.randn(100, 100)
      t3 = expr.add(t1, t2)
      t4 = expr.randn(200, 100)
      t5 = expr.add(t3, t4)
      t6 = expr.randn(100, 100)
      t7 = expr.add(t6, t5)
      t8 = expr.count_zero(t7)
      t9 = t8.optimized()
      try:
        t9.force()
      except Exception as e:
        pass
Esempio n. 9
0
    def test_trace(self):
        devnull = open(os.devnull, 'w')
        with RedirectStdStreams(stdout=devnull, stderr=devnull):
            t1 = expr.randn(100, 100)
            t2 = expr.randn(200, 100)
            t3 = expr.add(t1, t2)
            t4 = expr.randn(300, 100)
            t5 = expr.add(t3, t4)
            t6 = expr.randn(400, 100)
            t7 = expr.add(t6, t5)
            t8 = t7.optimized()
            try:
                t8.force()
            except Exception as e:
                pass

            t1 = expr.randn(100, 100)
            t2 = expr.randn(100, 100)
            t3 = expr.dot(t1, t2)
            t4 = expr.randn(200, 100)
            t5 = expr.add(t3, t4)
            t6 = t5.optimized()
            try:
                t6.force()
            except Exception as e:
                pass

            t1 = expr.randn(100, 100)
            t2 = expr.randn(100, 100)
            t3 = expr.add(t1, t2)
            t4 = expr.randn(200, 100)
            t5 = expr.add(t3, t4)
            t6 = expr.randn(100, 100)
            t7 = expr.add(t6, t5)
            t8 = expr.count_zero(t7)
            t9 = t8.optimized()
            try:
                t9.force()
            except Exception as e:
                pass