tensors
tensors copied to clipboard
idea: typesafe einsum
https://rockt.github.io/2018/04/30/einsum
Good idea! Let me check how to do first. thanks.
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 Thanks. It's not easy to provide type safe einsum.
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 cool, this looks promising!