コード例 #1
0
ファイル: jacobi.py プロジェクト: GabrielWen/spartan
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
コード例 #2
0
ファイル: jacobi.py プロジェクト: muddimedia/spartan-1
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
コード例 #3
0
ファイル: test_autotiling.py プロジェクト: MaggieQi/spartan
def fn3():
  a = expr.ones((10,))
  g = expr.diag(a)
  g += expr.ones((10,10))
  g = expr.diagonal(g)
  print g.optimized()
コード例 #4
0
def fn3():
  a = expr.ones((10,))
  g = expr.diag(a)
  g += expr.ones((10, 10))
  g = expr.diagonal(g)
  print g.optimized()