当前位置: 首页>>代码示例>>Python>>正文


Python expr.dot函数代码示例

本文整理汇总了Python中spartan.expr.dot函数的典型用法代码示例。如果您正苦于以下问题:Python dot函数的具体用法?Python dot怎么用?Python dot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_2d_2d

  def test_2d_2d(self):
    #Not dot with vector exactly,
    #just to make sure new feature hasn't break anything

    # Test with row > col
    av = expr.arange((132, 100))
    bv = expr.arange((100, 77))
    na = np.arange(13200).reshape(132, 100)
    nb = np.arange(7700).reshape(100, 77)

    Assert.all_eq(expr.dot(av, bv).glom(),
                  np.dot(na, nb))

    # Test with row < col
    av = expr.arange((67, 100))
    bv = expr.arange((100, 77))
    na = np.arange(6700).reshape(67, 100)
    nb = np.arange(7700).reshape(100, 77)

    Assert.all_eq(expr.dot(av, bv).glom(),
                  np.dot(na, nb))

    #Dot with numpy obj
    cv = expr.arange((77, 100))
    dv = np.arange(8800).reshape(100, 88)
    nc = np.arange(7700).reshape(77, 100)
    nd = np.arange(8800).reshape(100, 88)

    Assert.all_eq(expr.dot(cv, dv).glom(),
                  np.dot(nc, nd))
开发者ID:GabrielWen,项目名称:spartan,代码行数:30,代码来源:test_dot.py

示例2: test_reshape_dot

  def test_reshape_dot(self):
    npa1 = np.random.random((357, 93))
    npa2 = np.random.random((31, 357))
    result = np.dot(np.reshape(npa1, (1071, 31)), npa2)

    t1 = expr.from_numpy(npa1)
    t2 = expr.from_numpy(npa2)
    t3 = expr.dot(expr.reshape(t1, (1071, 31)), t2)
    Assert.all_eq(result, t3.glom(), 10e-9)

    npa1 = np.random.random((357, 718))
    npa2 = np.random.random((718, ))
    result = np.dot(npa1, np.reshape(npa2, (718, 1)))

    t1 = expr.from_numpy(npa1)
    t2 = expr.from_numpy(npa2)
    t3 = expr.dot(t1, expr.reshape(t2, (718, 1)))
    Assert.all_eq(result, t3.glom(), 10e-9)

    npa1 = np.random.random((718, ))
    npa2 = np.random.random((1, 357))
    result = np.dot(np.reshape(npa1, (718, 1)), npa2)

    t1 = expr.from_numpy(npa1)
    t2 = expr.from_numpy(npa2)
    t3 = expr.dot(expr.reshape(t1, (718, 1)), t2)
    Assert.all_eq(result, t3.glom(), 10e-9)
开发者ID:MaggieQi,项目名称:spartan,代码行数:27,代码来源:test_reshape.py

示例3: fn2

def fn2():
  a = expr.ones((N, N))
  b = expr.ones((N, N/2))
  g = expr.dot(a, b) + expr.dot(expr.sum(a, axis=1).reshape((1, N)), b)
  t1 = time.time()
  g_opt = g.optimized()
  #g_opt.force()
  t2 = time.time()
  print t2 - t1
  print g_opt
开发者ID:MaggieQi,项目名称:spartan,代码行数:10,代码来源:test_autotiling.py

示例4: update

 def update(self):
     """
 gradient_update = 2xTxw - 2xTy + 2* lambda * w
 Correct this if the update function is wrong.
 """
     xT = expr.transpose(self.x)
     g1 = expr.dot(expr.dot(xT, self.x), self.w)
     g2 = expr.dot(xT, self.y)
     g3 = self.ridge_lambda * self.w
     g4 = g1 + g2 + g3
     return expr.reshape(g4, (1, self.N_DIM))
开发者ID:EasonLiao,项目名称:spartan,代码行数:11,代码来源:ridge_regression.py

示例5: bfs

def bfs(ctx, dim):
	util.log_info("start to computing......")

	sGenerate = time.time()
	current = eager(
			expr.shuffle(
				expr.ndarray(
					(dim, 1),
					dtype = np.int64,
					tile_hint = (dim / ctx.num_workers, 1)),
				make_current,
			))
	
	linkMatrix = eager(
				expr.shuffle(
					expr.ndarray(
					 (dim, dim),
					 dtype = np.int64,
					 tile_hint = (dim, dim / ctx.num_workers)),
				make_matrix,
				))
	eGenerate = time.time()

	startCompute = time.time()
	while(True):
		next = expr.dot(linkMatrix, current)
		formerNum = expr.count_nonzero(current)
		laterNum = expr.count_nonzero(next)
		hasNew = expr.equal(formerNum, laterNum).glom()
		current = next
		if (hasNew):
			break
	current.evaluate()
	endCompute = time.time()
	return (eGenerate - sGenerate, endCompute - startCompute) 
开发者ID:GatsbyNewton,项目名称:graph-computation-benchmark,代码行数:35,代码来源:backup-bfs.py

示例6: _test_optimization_ordered

  def _test_optimization_ordered(self):
    na = np.random.rand(1000, 1000)
    nb = np.random.rand(1000, 1000)
    a = expr.from_numpy(na)
    b = expr.from_numpy(nb)

    c = a - b
    d = a + c
    f = c[200:900, 200:900]
    g = d[200:900, 200:900]
    h = f - g
    i = f + h
    j = h[100:500, 100:500]
    k = i[100:500, 100:500]
    l = expr.dot(j, k)
    m = j + k
    n = k - l
    o = n - m
    q = o[100:200, 100:200]

    nc = na - nb
    nd = na + nc
    nf = nc[200:900, 200:900]
    ng = nd[200:900, 200:900]
    nh = nf - ng
    ni = nf + nh
    nj = nh[100:500, 100:500]
    nk = ni[100:500, 100:500]
    nl = np.dot(nj, nk)
    nm = nj + nk
    nn = nk - nl
    no = nn - nm
    nq = no[100:200, 100:200]

    Assert.all_eq(nq, q.optimized().glom(), tolerance = 1e-10)
开发者ID:MaggieQi,项目名称:spartan,代码行数:35,代码来源:test_optimization.py

示例7: update

 def update(self):
   '''
   gradient_update = (h(w) - y) * x
   h(w) = x * w
   '''
   yp = expr.dot(self.x, self.w)
   return self.x * (yp - self.y)
开发者ID:EasonLiao,项目名称:spartan,代码行数:7,代码来源:linear_regression.py

示例8: jacobi_method

def jacobi_method(A, b, _iter=100):
    """
  Iterative algorithm for approximating the solutions of a diagonally dominant system of linear equations. 

  Parameters
  ----------
  A : ndarray or Expr - 2d
      Input matrix
  b : ndarray or Expr - vector
      RHS vector
  _iter : int
      Times of iteration needed, default to be 100

 Returns
  -------
  result : Expr - vector
      Approximated solution.
  """
    util.Assert.eq(A.shape[0], b.shape[0])

    x = expr.zeros((A.shape[0],))

    D = expr.diag(A)
    R = A - expr.diagflat(D)

    for i in xrange(_iter):
        x = (b - expr.dot(R, x)) / D

    return x
开发者ID:GabrielWen,项目名称:spartan,代码行数:29,代码来源:jacobi.py

示例9: fn2

def fn2():
  a = expr.ones((N, N))
  b = expr.ones((N, N))
  x = expr.dot(a, b)
  g = a + b + x

  return g
开发者ID:GabrielWen,项目名称:spartan,代码行数:7,代码来源:test_random_autotiling.py

示例10: cgit

def cgit(A, x):
  '''
  CGIT Conjugate Gradient iteration
  z = cgit(A, x) generates approximate solution to A*z = x.
  
  Args:
  A(Expr): matrix to be processed.
  x(Expr): the input vector.
  '''
  z = expr.zeros(x.shape, tile_hint=(A.tile_shape()[1], 1))
  r = x
  rho = expr.sum(r * r).glom()
  #util.log_warn('rho:%s', rho)
  p = r
  
  for i in xrange(15):
    q = expr.dot(A, p, tile_hint=(A.tile_shape()[1], 1))
    alpha = rho / expr.sum(p * q).glom()
    #util.log_warn('alpha:%s', alpha)
    z = z + p * alpha
    rho0 = rho
    r = r - q * alpha
    rho = expr.sum(r * r).glom()
    beta = rho / rho0
    #util.log_warn('beta:%s', beta)
    p = r + p * beta
  
  return z
开发者ID:EasonLiao,项目名称:spartan,代码行数:28,代码来源:conj_gradient.py

示例11: connectedConponents

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

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

	eye = expr.eye(dim, tile_hint = (dim / ctx.num_workers,dim))
	startCompute = time.time()
	result = expr.logical_or(eye, linkMatrix).optimized().glom()
	for i in range(numIters):
		power = expr.dot(power, linkMatrix).optimized().glom()
		result = expr.logical_or(result, power)
	result.optimized().glom()
	final = expr.logical_and(result, expr.transpose(result.optimized())).optimized().evaluate()
	endCompute = time.time()
	return endCompute - startCompute
开发者ID:GatsbyNewton,项目名称:graph-computation-benchmark,代码行数:29,代码来源:concomp.py

示例12: test_numpy_vec_2d

  def test_numpy_vec_2d(self):
    av = expr.arange(stop = 100)
    bv = np.arange(7700).reshape(100, 77)
    na = np.arange(100)
    nb = np.arange(7700).reshape(100, 77)

    Assert.all_eq(expr.dot(av, bv).glom(),
                  np.dot(na, nb))
开发者ID:xuanhan863,项目名称:spartan,代码行数:8,代码来源:test_dot.py

示例13: gen_dot

def gen_dot(a, b):
  if not hasattr(a, 'shape') or not hasattr(b, 'shape') or len(a.shape) * len(b.shape) == 0: return [a * b]

  if a.shape[0] == b.shape[0]:
    if len(a.shape) > 1: return [expr.dot(expr.transpose(a), b)]
    elif len(b.shape) == 1: return [expr.dot(a, b)]

  if len(a.shape) > 1 and a.shape[1] == b.shape[0]:
      return [expr.dot(a, b)]

  if len(b.shape) > 1 and a.shape[0] == b.shape[1]:
      return [expr.dot(b, a)]

  if len(a.shape) > 1 and len(b.shape) > 1 and a.shape[1] == b.shape[1]:
      return [expr.dot(a, expr.transpose(b))]

  return [a, b]
开发者ID:GabrielWen,项目名称:spartan,代码行数:17,代码来源:test_random_autotiling.py

示例14: update

 def update(self):
   '''
   gradient_update = (h(w) - y) * x
   h(w) = 1 / (1 + e^(-(x*w)))
   '''
   g = expr.exp(expr.dot(self.x, self.w))
   yp = g / (g + 1)
   return self.x * (yp - self.y)
开发者ID:GabrielWen,项目名称:spartan,代码行数:8,代码来源:logistic_regression.py

示例15: test_numpy_2d_vec

  def test_numpy_2d_vec(self):
    av = expr.arange((77, 100))
    bv = np.arange(100)
    na = np.arange(7700).reshape(77, 100)
    nb = np.arange(100)

    Assert.all_eq(expr.dot(av, bv).glom(),
                  np.dot(na, nb))
开发者ID:GabrielWen,项目名称:spartan,代码行数:8,代码来源:test_dot.py


注:本文中的spartan.expr.dot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。