@@ -16,17 +16,19 @@ The Python implementation uses strings to specify the operation, but that would
16
16
The ` rearrange ` combines reshaping and permutation operations into a single, expressive command:
17
17
18
18
``` julia
19
- # Example from Python API
20
- images = randn (32 , 30 , 40 , 3 ); # batch, height, width, channel
19
+ julia> images = randn (32 , 30 , 40 , 3 ); # batch, height, width, channel
21
20
22
21
# reorder axes to "b c h w" format:
23
- rearrange (images, (:b , :h , :w , :c ) --> (:b , :c , :h , :w )) # (32, 3, 30, 40)
22
+ julia> rearrange (images, (:b , :h , :w , :c ) --> (:b , :c , :h , :w )) |> size
23
+ (32 , 3 , 30 , 40 )
24
24
25
25
# flatten each image into a vector
26
- rearrange (images, (:b , :h , :w , :c ) --> (:b , (:h , :w , :c ))) # (32, 30*40*3)
26
+ julia> rearrange (images, (:b , :h , :w , :c ) --> (:b , (:h , :w , :c ))) |> size
27
+ (32 , 3600 )
27
28
28
29
# split each image into 4 smaller (top-left, top-right, bottom-left, bottom-right), 128 = 32 * 2 * 2
29
- rearrange (images, (:b , (:h1 , :h ), (:w1 , :w ), :c ) --> ((:b , :h1 , :w1 ), :h , :w , :c ), h1= 2 , w1= 2 ) # (128, 15, 20, 3)
30
+ julia> rearrange (images, (:b , (:h1 , :h ), (:w1 , :w ), :c ) --> ((:b , :h1 , :w1 ), :h , :w , :c ), h1= 2 , w1= 2 ) |> size
31
+ (128 , 15 , 20 , 3 )
30
32
```
31
33
32
34
### ` reduce ` (Planned)
0 commit comments