def test_nd(self): sign = lambda v: -1 if v < 0 else 1 if v > 0 else 0 for n in range(2, 6): with self.subTest(n=n): desired = numpy.empty((n,)*n, int) for I in itertools.product(*[range(n)]*n): desired[I] = util.product(sign(b-a) for a, b in itertools.combinations(I, 2)) self.assertAllEqual(numeric.levicivita(n, int), desired)
def test_2d(self): self.assertAllEqual(numeric.levicivita(2, int), numpy.array([[0, 1], [-1, 0]]))
def test_1d(self): with self.assertRaisesRegex( ValueError, '^The Levi-Civita symbol is undefined for dimensions lower than 2.' ): numeric.levicivita(1)