numpy / numpy/numpy

Request: currying `numpy.einsum` for repeated calls with the same subscript string?

Open
#6,631 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: numpy._core
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Hi,

During my experience with the numpy.einsum function, I discovered that I frequently use it in the following pattern: The zeroth argument to einsum(), the string describing the subscripts, is a fixed one, but the array arguments will vary during runtime. That is to say, I apply the same summation rule to many different array arguments repeatedly.

I don't know if einsum() keeps its subscript-parsing results in a cache, but if not, this could be a bit wasteful, because the same subscript description need to be unnecessarily parsed again and again.

So I wonder if it is possible to have a "curriable" version of einsum that, when called with the subscript description string, returns a callable that has already parsed the string. This returned callable is then ready to be applied to the array arguments.

On the other hand, I'm not sure about the performance impact of parsing. Is this kind of optimization worth the effort?

Just my 2c.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the numpy.einsum entry point and investigate whether repeated calls re-parse the subscript string. Measure the performance impact of parsing across repeated calls, then determine whether a callable curried interface is justified and what tests would demonstrate that it works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.