def _solve_cg_mg(lap_sparse, B, tol, return_full_prob=False):
 X = []
 ml = ruge_stuben_solver(lap_sparse)
 M = ml.aspreconditioner(cycle='V')
 for i in range(len(B)):
  x0 = cg(lap_sparse, (- B[i].todense()), tol=tol, M=M, maxiter=30)[0]
  X.append(x0)
 if (not return_full_prob):
  X = np.array(X)
  X = np.argmax(X, axis=0)
 return X

def _solve_cg_mg ( lap_sparse , B , tol , return_full_prob = False ) : X = [ ] ml = ruge_stuben_solver ( lap_sparse ) M = ml . aspreconditioner ( cycle = 'V' ) for i in range ( len ( B ) ) : x0 = cg ( lap_sparse , ( - B [ i ] . todense ( ) ) , tol = tol , M = M , maxiter = 30 ) [ 0 ] X . append ( x0 ) if ( not return_full_prob ) : X = np . array ( X ) X = np . argmax ( X , axis = 0 ) return X
solves lap_sparse x_i = b_i for each phase i .