'Test np.linalg.inv'

@tag('important')
@needs_lapack
def test_linalg_inv(self):

    n = 10
    cfunc = jit(nopython=True)(invert_matrix)
    def check(a, **kwargs):
        expected = invert_matrix(a)
        got = cfunc(a)
        self.assert_contig_sanity(got, 'F')
        use_reconstruction = False
        try:
            np.testing.assert_array_almost_equal_nulp(got, expected, nulp=10)
        except AssertionError:
            use_reconstruction = True
        if use_reconstruction:
            rec = np.dot(got, a)
            self.assert_is_identity_matrix(rec)
        with self.assertNoNRTLeak():
            cfunc(a)
    for (dtype, order) in product(self.dtypes, 'CF'):
        a = self.specific_sample_matrix((n, n), dtype, order)
        check(a)
    self.assert_non_square(cfunc, (np.ones((2, 3)),))
    self.assert_wrong_dtype('inv', cfunc, (np.ones((2, 2), dtype=np.int32),))
    self.assert_wrong_dimensions('inv', cfunc, (np.ones(10),))
    self.assert_raise_on_singular(cfunc, (np.zeros((2, 2)),))
