Skip to content

Commit

Permalink
wording
Browse files Browse the repository at this point in the history
  • Loading branch information
arogozhnikov committed Nov 8, 2018
1 parent 9bd739e commit d23ebe9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ Plain and simple:
pip install einops
```

`einops` has no mandatory dependencies. To obtain the latest github version
`einops` has no mandatory dependencies (code examples also require jupyter, pillow + backends).
To obtain the latest github version

```bash
pip install https://github.com/arogozhnikov/einops/archive/master.zip
```

## API

`einops` API is very minimalistic and powerful.
`einops` has minimalistic and powerful API.

Two operations provided (see [einops tutorial](https://github.com/arogozhnikov/einops/blob/master/docs/) for examples)
```python
from einops import rearrange, reduce
# rearrange elements according to pattern
output_tensor = rearrange(input_tensor, pattern, **axes_lengths)
# rearrange elements according to the pattern
output_tensor = rearrange(input_tensor, 't b c -> b c t')
# combine rearrangement and reduction
output_tensor = reduce(input_tensor, pattern, reduction, **axes_lengths)
output_tensor = reduce(input_tensor, 'b c (h h2) (w w2) -> b h w c', 'mean', h2=2, w2=2)
```
And two corresponding layers (`einops` keeps separate version for each framework) with the same API.

Expand All @@ -79,7 +80,7 @@ Layers are behaving in the same way as operations and have same parameters
layer = Rearrange(pattern, **axes_lengths)
layer = Reduce(pattern, reduction, **axes_lengths)

# later apply to a tensor / variable
# apply created layer to a tensor / variable
x = layer(x)
```

Expand All @@ -93,7 +94,8 @@ model = Sequential(
Conv2d(3, 6, kernel_size=5),
MaxPool2d(kernel_size=2),
Conv2d(6, 16, kernel_size=5),
Reduce('b c (h h2) (w w2) -> b (c h w)', 'max', h2=2, w2=2), # combined pooling and flattening
# combined pooling and flattening
Reduce('b c (h h2) (w w2) -> b (c h w)', 'max', h2=2, w2=2),
Linear(16*5*5, 120),
ReLU(),
Linear(120, 10),
Expand All @@ -105,8 +107,8 @@ Additionally two auxiliary functions provided
from einops import asnumpy, parse_shape
# einops.asnumpy converts tensors of imperative frameworks to numpy
numpy_tensor = asnumpy(input_tensor)
# einops.parse_shape returns a shape in the form of a dictionary, axis name mapped to its length
parse_shape(input_tensor, pattern)
# einops.parse_shape gives a shape of axes of interest
parse_shape(input_tensor, 'batch _ h w') # e.g {'batch': 64, 'h': 128, 'w': 160}
```

## Naming and terminology
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3 ',
],
keywords='deep learning, neural networks, tensor manipulation, scientific computations',

keywords='deep learning, neural networks, tensor manipulation, machine learning, '
'scientific computations, einops',
install_requires=[
# no run-time or installation-time dependencies
],
Expand Down
3 changes: 1 addition & 2 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def create_model(use_reduce=False):
Conv2d(3, 6, kernel_size=5),
Reduce('b c (h h2) (w w2) -> b c h w', 'max', h2=2, w2=2) if use_reduce else MaxPool2d(kernel_size=2),
Conv2d(6, 16, kernel_size=5),
Reduce('b c (h h2) (w w2) -> b c h w', 'max', h2=2, w2=2) if use_reduce else MaxPool2d(kernel_size=2),
Rearrange('b c h w -> b (c h w)'),
Reduce('b c (h h2) (w w2) -> b (c h w)', 'max', h2=2, w2=2),
Linear(16 * 5 * 5, 120),
ReLU(),
Linear(120, 84),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_doctests_examples():
def test_backends_installed():
"""
This test will fail if some of backends are not installed or can't be imported
Other tests will just work
Other tests will just work and only test installed backends.
"""
from . import skip_cupy
errors = []
Expand Down

0 comments on commit d23ebe9

Please sign in to comment.