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
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
def fn3(): a = expr.ones((10,)) g = expr.diag(a) g += expr.ones((10,10)) g = expr.diagonal(g) print g.optimized()
def fn3(): a = expr.ones((10,)) g = expr.diag(a) g += expr.ones((10, 10)) g = expr.diagonal(g) print g.optimized()