# Buggy code
def inv(a):
    """
    Compute the (multiplicative) inverse of a matrix.
    Given a square matrix `a`, return the matrix `ainv` satisfying
    ``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``.
    Parameters
    ----------
    a : (..., M, M) array_like
        Matrix to be inverted.
    Returns
    -------
    ainv : (..., M, M) ndarray or matrix
        (Multiplicative) inverse of the matrix `a`.
    Raises
    ------
    LinAlgError
        If `a` is not square or inversion fails.
    Notes
    -----
    .. versionadded:: 1.8.0
    Broadcasting rules apply, see the `numpy.linalg` documentation for
    details.
    Examples
    --------
    >>> import mars.tensor as mt

    >>> a = np.array([[1., 2.], [3., 4.]])
    >>> ainv = mt.linalg.inv(a)
    >>> mt.allclose(mt.dot(a, ainv), mt.eye(2)).execute()
    True
    >>> mt.allclose(mt.dot(ainv, a), mt.eye(2)).execute()
    True
    >>> ainv.execute()
    array([[ -2. ,  1. ],
           [ 1.5, -0.5]])
    """
    # TODO: using some parallel algorithm for matrix inversion.
    from ..datasource import eye

    a = astensor(a)
    return solve(a, eye(a.shape[0], chunk_size=a.params.raw_chunk_size))


# Traceback (KeyError)
In [1]: import mars.tensor as mt

In [2]: a = mt.random.randint(1, 10, (6, 6), chunk_size=3)

In [3]: b = a.dot(a)

In [4]: r = mt.linalg.inv(b)

Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 65, in __getattr__
return self[item]
KeyError: 'raw_chunk_size'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-7-7491bd48bc7b>", line 1, in <module>
mt.linalg.inv(a.dot(a)).execute()
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/linalg/inv.py", line 61, in inv
return solve(a, eye(a.shape[0], chunk_size=a.params.raw_chunk_size))
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 68, in __getattr__
"'AttributeDict' object has no attribute {0}".format(item))
AttributeError: 'AttributeDict' object has no attribute raw_chunk_size

# Fixed code
def inv(a):
    """
    Compute the (multiplicative) inverse of a matrix.
    Given a square matrix `a`, return the matrix `ainv` satisfying
    ``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``.
    Parameters
    ----------
    a : (..., M, M) array_like
        Matrix to be inverted.
    Returns
    -------
    ainv : (..., M, M) ndarray or matrix
        (Multiplicative) inverse of the matrix `a`.
    Raises
    ------
    LinAlgError
        If `a` is not square or inversion fails.
    Examples
    --------
    >>> import mars.tensor as mt

    >>> a = np.array([[1., 2.], [3., 4.]])
    >>> ainv = mt.linalg.inv(a)
    >>> mt.allclose(mt.dot(a, ainv), mt.eye(2)).execute()
    True
    >>> mt.allclose(mt.dot(ainv, a), mt.eye(2)).execute()
    True
    >>> ainv.execute()
    array([[ -2. ,  1. ],
           [ 1.5, -0.5]])
    """

    # TODO: using some parallel algorithm for matrix inversion.
    a = astensor(a)
    if a.ndim != 2:
        raise LinAlgError(
            "{0}-dimensional array given. Tensor must be two-dimensional".format(a.ndim)
        )
    if a.shape[0] != a.shape[1]:
        raise LinAlgError("Input must be square")

    tiny_inv = np.linalg.inv(np.array([[1, 2], [2, 5]], dtype=a.dtype))
    op = TensorInv(dtype=tiny_inv.dtype, sparse=a.is_sparse())
    return op(a)