tensors icon indicating copy to clipboard operation
tensors copied to clipboard

idea: typesafe einsum

Open tscholak opened this issue 6 years ago • 5 comments

https://rockt.github.io/2018/04/30/einsum

tscholak avatar Sep 21 '18 12:09 tscholak

Good idea! Let me check how to do first. thanks.

leptonyu avatar Sep 21 '18 13:09 leptonyu

This is something I'm interested in as well! What might be useful to know: There's a hTensor package which provides contractions of tensors of arbitrary rank using named indices, but it's not type safe (tutorial)

bgavran avatar Oct 20 '18 12:10 bgavran

@bgavran Thanks. It's not easy to provide type safe einsum.

leptonyu avatar Oct 22 '18 05:10 leptonyu

Hi @tscholak, I found a way to do Symbol manipulation in type-level, then this idea may be practical.

By defining following type class, I can implement by type-level programming.

class (KnownSymbol s, Num n) => Einsum s r n where
  einsum :: r

in ghci

λ> :t einsum @"ijk,kl->ijl"
einsum @"ijk,kl->ijl"
  :: Num n =>
     Tensor '[0, 1, 2] n -> Tensor '[2, 3] n -> Tensor '[0, 1, 3] n
λ> :t einsum @"ij->ji"
einsum @"ij->ji" :: Num n => Tensor '[0, 1] n -> Tensor '[1, 0] n

But I still need sometimes to finish it.

leptonyu avatar Jun 23 '19 12:06 leptonyu

@leptonyu cool, this looks promising!

tscholak avatar Jun 23 '19 13:06 tscholak