Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: typesafe einsum #2

Open
tscholak opened this issue Sep 21, 2018 · 5 comments
Open

idea: typesafe einsum #2

tscholak opened this issue Sep 21, 2018 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@tscholak
Copy link

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

@leptonyu
Copy link
Owner

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

@leptonyu leptonyu self-assigned this Sep 21, 2018
@leptonyu leptonyu added the enhancement New feature or request label Sep 21, 2018
@bgavran
Copy link

bgavran commented Oct 20, 2018

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)

@leptonyu
Copy link
Owner

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

@leptonyu
Copy link
Owner

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.

@tscholak
Copy link
Author

@leptonyu cool, this looks promising!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants