Skip to content

Einsum gets slow with multiple arguments #5366

@perimosocordiae

Description

@perimosocordiae

With multiple arguments, einsum blows up fast:

In [1]: import numpy as np

In [2]: a = np.random.random((5,5))

In [3]: %timeit a.dot(a).dot(a).dot(a)
100000 loops, best of 3: 3.3 µs per loop

In [4]: %timeit np.linalg.multi_dot((a,a,a,a))
10000 loops, best of 3: 30.8 µs per loop

In [5]: %timeit np.einsum('ij,kl,mn,op->ip', a,a,a,a)
100 loops, best of 3: 7.2 ms per loop

In [6]: a = np.random.random((50,50))

In [7]: %timeit a.dot(a).dot(a).dot(a)
10000 loops, best of 3: 82.1 µs per loop

In [8]: %timeit np.linalg.multi_dot((a,a,a,a))
10000 loops, best of 3: 150 µs per loop

In [9]: %timeit np.einsum('ij,kl,mn,op->ip', a,a,a,a)
# takes so long I had to kill IPython.

Is there some fundamental limitation involved, or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions