def check_symmetric(array, tol=<NUM_LIT>, raise_warning=True,<EOL>raise_exception=False):
if (array.ndim != <NUM_LIT:2>) or (array.shape[<NUM_LIT:0>] != array.shape[<NUM_LIT:1>]):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(array.shape))<EOL><DEDENT>if sp.issparse(array):<EOL><INDENT>diff = array - array.T<EOL>if diff.format not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>diff = diff.tocsr()<EOL><DEDENT>symmetric = np.all(abs(diff.data) < tol)<EOL><DEDENT>else:<EOL><INDENT>symmetric = np.allclose(array, array.T, atol=tol)<EOL><DEDENT>if not symmetric:<EOL><INDENT>if raise_exception:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if raise_warning:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if sp.issparse(array):<EOL><INDENT>conversion = '<STR_LIT:to>' + array.format<EOL>array = getattr(<NUM_LIT:0.5> * (array + array.T), conversion)()<EOL><DEDENT>else:<EOL><INDENT>array = <NUM_LIT:0.5> * (array + array.T)<EOL><DEDENT><DEDENT>return array<EOL>
Make sure that array is 2D, square and symmetric.
    If the array is not symmetric, then a symmetrized version is returned.
    Optionally, a warning or exception is raised if the matrix is not
    symmetric.
    Parameters
    ----------
    array : nd-array or sparse matrix
        Input object to check / convert. Must be two-dimensional and square,
        otherwise a ValueError will be raised.
    tol : float
        Absolute tolerance for equivalence of arrays. Default = 1E-10.
    raise_warning : boolean (default=True)
        If True then raise a warning if conversion is required.
    raise_exception : boolean (default=False)
        If True then raise an exception if array is not symmetric.
    Returns
    -------
    array_sym : ndarray or sparse matrix
        Symmetrized version of the input array, i.e. the average of array
        and array.transpose(). If sparse, then duplicate entries are first
        summed and zeros are eliminated.