Repository: numpy/numpy
File: numpy/_core/tests/test_einsum.py (Python)

Code before:
        c = np.ones((4, 3), order='C')
        for opt in [True, False]:
            tmp = np.einsum('...ft,mf->...mt', a, c, order='a', optimize=opt)
            assert_(tmp.flags.c_contiguous)

        d = np.ones((2, 3, 5), order='C')
        for opt in [True, False]:
            tmp = np.einsum('...ft,mf->...mt', d, c, order='a', optimize=opt)
            assert_(tmp.flags.c_contiguous)

    def test_singleton_broadcasting(self):
        eq = "ijp,ipq,ikq->ijk"
        shapes = (3, 1, 1), (3, 1, 3), (1, 3, 3)
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "jhcabhijaci,dfijejgh->fgje"
        shapes = (
            (1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1),
            (3, 1, 3, 1, 1, 1, 1, 2),
        )
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "baegffahgc,hdggeff->dhg"
        shapes = ((2, 1, 4, 1, 1, 1, 1, 2, 1, 1), (1, 1, 1, 1, 4, 1, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "cehgbaifff,fhhdegih->cdghbi"
        shapes = ((1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 1, 1, 2, 4, 1, 1, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "gah,cdbcghefg->ef"
        shapes = ((2, 3, 1), (1, 3, 1, 1, 1, 2, 1, 4, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "cacc,bcb->"
        shapes = ((1, 1, 1, 1), (1, 4, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)


class TestEinsumPath:
    def build_operands(self, string, size_dict=global_size_dict):

        # Builds views based off initial operands
        operands = [string]
        terms = string.split('->')[0].split(',')

Review comment (suggestion):
for consistency with line 1124

```suggestion
        shapes = (2, 1, 4, 1, 1, 1, 1, 2, 1, 1), (1, 1, 1, 1, 4, 1, 1)
```

and same story for the 4 similar cases below

or alternatively you could add some parentheses to 1124 (I have no preference)

Code after:
        c = np.ones((4, 3), order='C')
        for opt in [True, False]:
            tmp = np.einsum('...ft,mf->...mt', a, c, order='a', optimize=opt)
            assert_(tmp.flags.c_contiguous)

        d = np.ones((2, 3, 5), order='C')
        for opt in [True, False]:
            tmp = np.einsum('...ft,mf->...mt', d, c, order='a', optimize=opt)
            assert_(tmp.flags.c_contiguous)

    def test_singleton_broadcasting(self):
        eq = "ijp,ipq,ikq->ijk"
        shapes = ((3, 1, 1), (3, 1, 3), (1, 3, 3))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "jhcabhijaci,dfijejgh->fgje"
        shapes = (
            (1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1),
            (3, 1, 3, 1, 1, 1, 1, 2),
        )
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "baegffahgc,hdggeff->dhg"
        shapes = ((2, 1, 4, 1, 1, 1, 1, 2, 1, 1), (1, 1, 1, 1, 4, 1, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "cehgbaifff,fhhdegih->cdghbi"
        shapes = ((1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 1, 1, 2, 4, 1, 1, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "gah,cdbcghefg->ef"
        shapes = ((2, 3, 1), (1, 3, 1, 1, 1, 2, 1, 4, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)

        eq = "cacc,bcb->"
        shapes = ((1, 1, 1, 1), (1, 4, 1))
        arrays = [np.random.rand(*shape) for shape in shapes]
        self.optimize_compare(eq, operands=arrays)


class TestEinsumPath:
    def build_operands(self, string, size_dict=global_size_dict):

        # Builds views based off initial operands
        operands = [string]
        terms = string.split('->')[0].split(',')