def cg(A: LinearOperator, rhs: Array, x0=None, P=None, tol=1e-6, max_iters=5000, pbar=False):
    """
    Solves Ax=b or AX=B using conjugate gradients (CG).

    Args:
        A (LinearOperator): A positive definite linear operator of size (n, n).
        rhs (Array): A single right hand side (n,) or multiple right hand sides (n, b).
        x0 (Array, optional): (n,) or (n, b) initial solution guess.
         Defaults to the zero vector.
        P (LinearOperator, optional): Preconditioner. Defaults to the identity.
        tol (float, optional): Stopping criteria.
        max_iters (int, optional): The maximum number of iterations to run.
        pbar (bool, optional): Show a progress bar.

    Returns:
        tuple:
            - soln (Array): solution to the linear system,  either (n,) or (n, b)
            - info (dict): General information about the iterative procedure.
    """
    xnp = A.xnp
    is_vector = len(rhs.shape) == 1
    if x0 is None:
        x0 = xnp.zeros_like(rhs)
    if is_vector:
        rhs = rhs[..., None]
        x0 = x0[..., None]
    if P is None:
        P = I_like(A)
    soln, *_, infodict = run_cg(A, rhs, x0, max_iters, tol, P, pbar=pbar)
    soln = soln.reshape(-1) if is_vector else soln
    return soln, infodict

    Solves Ax=b or AX=B using conjugate gradients (CG).

    Args:
        A (LinearOperator): A positive definite linear operator of size (n, n).
        rhs (Array): A single right hand side (n,) or multiple right hand sides (n, b).
        x0 (Array, optional): (n,) or (n, b) initial solution guess.
         Defaults to the zero vector.
        P (LinearOperator, optional): Preconditioner. Defaults to the identity.
        tol (float, optional): Stopping criteria.
        max_iters (int, optional): The maximum number of iterations to run.
        pbar (bool, optional): Show a progress bar.

    Returns:
        tuple:
            - soln (Array): solution to the linear system,  either (n,) or (n, b)
            - info (dict): General information about the iterative procedure.
    
cola/linalg/inverse/cg.py