Skip to content

Commit 8ffd4bf

Browse files
committed
Update README.md
1 parent 5ddc28f commit 8ffd4bf

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Einops.jl is a Julia implementation of the [einops](https://einops.rocks) Python package, providing an elegant and intuitive notation for tensor operations. Einops offers a unified way to perform Julia's `reshape` and `permutedims`, with plans for also implementing `reduce` and `repeat`.
99

10-
The Python implementation uses strings to specify the operation, but in Julia, that would be tricky to compile, so for parity a string macro `@einops_str` is exported, e.g. `einops"a 1 b c -> (c b) a"`, which expands to the form `(:a, 1, :b, :c,) --> ((:c, :b), :a)` where `-->` is an operator that creates an `Einops.Pattern{(:a, 1, :b, :c), ((:c, :b), :a)}`, allowing for compile-time awareness of dimensionalities and permutations—this is not yet taken advantage of, since the tuple types are sufficient for at least ensuring type stability (see [Roadmap](#Roadmap)).
10+
The Python implementation uses strings to specify the operation, but that would be tricky to compile in Julia, so a string macro `@einops_str` is exported for parity, e.g. `einops"a 1 b c -> (c b) a"`, which expands to the form `(:a, 1, :b, :c,) --> ((:c, :b), :a)` where `-->` is an operator that creates an `Einops.Pattern{(:a, 1, :b, :c), ((:c, :b), :a)}`, allowing for compile-time awareness of dimensionalities and permutations—this is not yet taken advantage of, since the tuple types are sufficient for at least ensuring type stability (see [Roadmap](#Roadmap)).
1111

1212
## Operations
1313

@@ -17,22 +17,16 @@ The `rearrange` combines reshaping and permutation operations into a single, exp
1717

1818
```julia
1919
# Example from Python API
20-
# no-op:
21-
images = randn(32, 30, 40, 3) # batch, height, width, channel
22-
rearranged_images = rearrange(images, (:b, :h, :w, :c) --> (:b, :h, :w, :c))
23-
@assert size(rearranged_images) == (32, 30, 40, 3)
20+
images = randn(32, 30, 40, 3); # batch, height, width, channel
2421

2522
# reorder axes to "b c h w" format:
26-
rearranged_images = rearrange(images, (:b, :h, :w, :c) --> (:b, :c, :h, :w))
27-
@assert size(rearranged_images) == (32, 3, 30, 40)
23+
rearrange(images, (:b, :h, :w, :c) --> (:b, :c, :h, :w)) # (32, 3, 30, 40)
2824

2925
# flatten each image into a vector
30-
flattened_images = rearrange(images, (:b, :h, :w, :c) --> (:b, (:c, :h, :w)))
31-
@assert size(flattened_images) == (32, 30*40*3)
26+
rearrange(images, (:b, :h, :w, :c) --> (:b, (:h, :w, :c))) # (32, 30*40*3)
3227

3328
# split each image into 4 smaller (top-left, top-right, bottom-left, bottom-right), 128 = 32 * 2 * 2
34-
four_smaller_images = rearrange(images, (:b, (:h1, :h), (:w1, :w), :c) --> ((:b, :h1, :w1), :h, :w, :c), h1=2, w1=2)
35-
@assert size(four_smaller_images) (128, 15, 20, 3)
29+
rearrange(images, (:b, (:h1, :h), (:w1, :w), :c) --> ((:b, :h1, :w1), :h, :w, :c), h1=2, w1=2) # (128, 15, 20, 3)
3630
```
3731

3832
### `reduce` (Planned)
@@ -42,7 +36,7 @@ The `reduce` function will allow for applying reduction operations (like `sum`,
4236
```julia
4337
# Example (conceptual):
4438
x = randn(100, 32, 64)
45-
y = reduce(maximum, x, (:t, :b, :c) --> (:b, :c)) # Max-reduction on the first axis
39+
y = reduce(maximum, x, (:t, :b, :c) --> (:b, :c)) # max-reduction on the first axis
4640
```
4741

4842
### `repeat` (Planned)

0 commit comments

Comments
 (0)