# Path: pyamg/util/params.py
# def set_tol(dtype):
#     """Set a tolerance based on a numpy dtype char.
# 
#     Parameters
#     ----------
#     dtype : np.dtype
#         numpy dtype
# 
#     Returns
#     -------
#     tol : float
#         A smallish value based on precision
# 
#     Notes
#     -----
#     Handles both real and complex (through the .lower() case)
# 
#     See Also
#     --------
#     numpy.typecodes, numpy.sctypes
#     """
#     if dtype.char.lower() == 'f':
#         tol = 1e3 * np.finfo(np.single).eps
#     elif dtype.char.lower() == 'd':
#         tol = 1e6 * np.finfo(np.double).eps
#     elif dtype.char.lower() == 'g':
#         tol = 1e6 * np.finfo(np.longdouble).eps
#     else:
#         raise ValueError('Attempting to set a tolerance for an unsupported precision.')
# 
#     return tol


from warnings import warn
from scipy import sparse
from scipy.sparse.linalg import aslinearoperator
from scipy.linalg import lapack, get_blas_funcs, eig, svd
from .params import set_tol
import numpy as np
    >>> a = np.array([[[1.,2.],[1.,1.]], [[1.,1.],[3.,3.]]])
    >>> ac = a.copy()
    >>> # each block of a is inverted in-place
    >>> pinv_array(a)

    """
    n = a.shape[0]
    m = a.shape[1]

    if m == 1:
        # Pseudo-inverse of 1 x 1 matrices is trivial
        zero_entries = (a == 0.0).nonzero()[0]
        a[zero_entries] = 1.0
        a[:] = 1.0/a
        a[zero_entries] = 0.0
        del zero_entries

    else:
        # The block size is greater than 1

        # Create necessary arrays and function pointers for calculating pinv
        gelss, gelss_lwork = lapack.get_lapack_funcs(('gelss', 'gelss_lwork'),
                                                     (np.ones((1,), dtype=a.dtype)))
        RHS = np.eye(m, dtype=a.dtype)
        # pylint: disable=protected-access
        lwork = lapack._compute_lwork(gelss_lwork, m, m, m)
        # pylint: enable=protected-access

        # Choose tolerance for which singular values are zero in *gelss below
        if tol is None:

# Path: pyamg/util/params.py
# def set_tol(dtype):
#     """Set a tolerance based on a numpy dtype char.
# 
#     Parameters
#     ----------
#     dtype : np.dtype
#         numpy dtype
# 
#     Returns
#     -------
#     tol : float
#         A smallish value based on precision
# 
#     Notes
#     -----
#     Handles both real and complex (through the .lower() case)
# 
#     See Also
#     --------
#     numpy.typecodes, numpy.sctypes
#     """
#     if dtype.char.lower() == 'f':
#         tol = 1e3 * np.finfo(np.single).eps
#     elif dtype.char.lower() == 'd':
#         tol = 1e6 * np.finfo(np.double).eps
#     elif dtype.char.lower() == 'g':
#         tol = 1e6 * np.finfo(np.longdouble).eps
#     else:
#         raise ValueError('Attempting to set a tolerance for an unsupported precision.')
# 
#     return tol


# Path: pyamg/util/linalg.py
from warnings import warn
from scipy import sparse
from scipy.sparse.linalg import aslinearoperator
from scipy.linalg import lapack, get_blas_funcs, eig, svd
from .params import set_tol
import numpy as np

    >>> a = np.array([[[1.,2.],[1.,1.]], [[1.,1.],[3.,3.]]])
    >>> ac = a.copy()
    >>> # each block of a is inverted in-place
    >>> pinv_array(a)

    """
    n = a.shape[0]
    m = a.shape[1]

    if m == 1:
        # Pseudo-inverse of 1 x 1 matrices is trivial
        zero_entries = (a == 0.0).nonzero()[0]
        a[zero_entries] = 1.0
        a[:] = 1.0/a
        a[zero_entries] = 0.0
        del zero_entries

    else:
        # The block size is greater than 1

        # Create necessary arrays and function pointers for calculating pinv
        gelss, gelss_lwork = lapack.get_lapack_funcs(('gelss', 'gelss_lwork'),
                                                     (np.ones((1,), dtype=a.dtype)))
        RHS = np.eye(m, dtype=a.dtype)
        # pylint: disable=protected-access
        lwork = lapack._compute_lwork(gelss_lwork, m, m, m)
        # pylint: enable=protected-access

        # Choose tolerance for which singular values are zero in *gelss below
        if tol is None:

            tol = set_tol(a.dtype)