Skip to content

Commit f6dc911

Browse files
committed
Use cases section: add einops use case
1 parent c647cff commit f6dc911

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec/use_cases.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,37 @@ and have `freq`, `Pxx` be arrays of the same type and on the same device as `x`.
109109
This type of use case applies to many other libraries, from scikit-learn
110110
and scikit-image to domain-specific libraries like AstroPy and
111111
scikit-bio, to code written for a single purpose or user.
112+
113+
114+
### Use case 2: simplify einops by removing the backend system
115+
116+
[einops](https://github.com/arogozhnikov/einops) is a library that provides flexible tensor operations and supports many array libraries (NumPy, TensorFlow, PyTorch, CuPy, MXNet, JAX).
117+
Most of the code in `einops` is:
118+
119+
- [einops.py](https://github.com/arogozhnikov/einops/blob/master/einops/einops.py)
120+
contains the functions it offers as public API (`rearrange`, `reduce`, `repeat`).
121+
- [_backends.py](https://github.com/arogozhnikov/einops/blob/master/einops/_backends.py)
122+
contains the glue code needed to support that many array libraries.
123+
124+
The amount of code in each of those two files is almost the same (~550 LoC each).
125+
The typical pattern in `einops.py` is:
126+
```
127+
def some_func(x):
128+
...
129+
backend = get_backend(x)
130+
shape = backend.shape(x)
131+
result = backend.reduce(x)
132+
...
133+
```
134+
With a standard array API, the `_backends.py` glue layer could almost completely disappear,
135+
because the purpose it serves (providing a unified interface to array operations from each
136+
of the supported backends) is already addressed by the array API standard.
137+
Hence the complete `einops` code base could be close to 50% smaller, and easier to maintain or add to.
138+
139+
.. note::
140+
141+
Other libraries that have a similar backend system to support many array libraries
142+
include [TensorLy](https://github.com/tensorly/tensorly),
143+
[Unumpy](https://github.com/Quansight-Labs/unumpy) and
144+
[EagerPy](https://github.com/jonasrauber/eagerpy). Many end users and organizations will also have such glue code - it tends to be needed whenever one tries to support multiple
145+
array types in a single API.

0 commit comments

Comments
 (0)