Einops
This is a rust port of the incredible einops library. Almost all the operations specified in its tutorial should be available, if you find any inconsistencies please raise a github issue.
Unlike its python counterpart, caching the parsed expression has not been implemented yet. So
when applying the same pattern multiple times, prefer Rearrange::new(...)
or Rearrange::with_lengths(...)
api, over the methods available through RearrangeFn
like traits.
Flexible and powerful tensor operations for readable and reliable code. Currently only supports tch.
Getting started
Add the following to your Cargo.toml
file,
[dependencies]
einops = "*"
Examples
Einops provies three operations, they cover stacking, reshape, transposition, squeeze/unsqueeze, repeat, tile, concatenate and numerous reductions.
For usage within a deep learning model look at the examples folder.
// Tch specific imports
use ;
// Structs that provide constructor like api
use ;
// Traits required to call functions directly on the tensors
use ;
// We create a random tensor as input
let input = randn;
// ------------------------------------------------------------------------
// Rearrange operation
let output = new?.apply?;
assert_eq!;
// Apply rearrange operation directly on the tensor using `RearrangeFn` trait
let output = input.rearrange?
assert_eq!;
// ------------------------------------------------------------------------
// Perform reduction on first axis
let output = new?.apply?;
assert_eq!;
// Same reduction done directly on the tensor using `ReduceFn` trait
let output = input.reduce?;
assert_eq!;
// ------------------------------------------------------------------------
// We repeat the third axis
let output = with_lengths?.apply;
assert_eq!;
// Same as above using `RepeatFn` trait and directly specifying the `repeat` size
// in the pattern
let output = input.repeat;
assert_eq!;