TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A basic introduction to NumPy's einsum

141 pointsby s1291about 3 years ago

9 comments

teddykokerabout 3 years ago
Also see Einops: <a href="https:&#x2F;&#x2F;github.com&#x2F;arogozhnikov&#x2F;einops" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;arogozhnikov&#x2F;einops</a>, which uses a einsum-like notation for various tensor operations used in deep learning.<p><a href="https:&#x2F;&#x2F;einops.rocks&#x2F;pytorch-examples.html" rel="nofollow">https:&#x2F;&#x2F;einops.rocks&#x2F;pytorch-examples.html</a> shows how it can be used to implement various neural network architectures in a more simplified manor.
评论 #30975710 未加载
评论 #30975053 未加载
评论 #30974665 未加载
moelfabout 3 years ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;mcabbott&#x2F;Tullio.jl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mcabbott&#x2F;Tullio.jl</a>:<p><pre><code> - better syntax (because Julia has proper macro&#x2F;metaprogramming) - faster - automatically works with GPU arrays.</code></pre>
dsharletabout 3 years ago
If you are looking for something like this in C++, here&#x27;s my attempt at implementing it: <a href="https:&#x2F;&#x2F;github.com&#x2F;dsharlet&#x2F;array#einstein-reductions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dsharlet&#x2F;array#einstein-reductions</a><p>It doesn&#x27;t do any automatic optimization of the loops like some of the projects linked in this thread, but, it provides all the tools needed for humans to express the code in a way that a good compiler can turn it into really good code.
评论 #30975147 未加载
cschmidabout 3 years ago
I&#x27;d really like to use einsum more often, because it allows me to code my expressions the same way I derive them on pen and paper. Unfortunately, as mentioned in the article, it&#x27;s slow, because it converts your formula to a for loop.<p>So usually, I rewrite my formulas into messy combinations of broadcasts, transposes and array multiplications. Is there a package or an algorithm that does this conversion automatically? It seems to be a pretty straightforward problem, at least for most expressions I use.
评论 #30973696 未加载
评论 #30973067 未加载
评论 #30973053 未加载
评论 #30972754 未加载
评论 #30973048 未加载
评论 #30973348 未加载
imranqabout 3 years ago
I&#x27;ve found einsum to be amazing at consolidating my code into something more readable, particularly for implementing architectures from scratch.<p>Here&#x27;s a good video that explains why its so good: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=pkVwUVEHmfI" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=pkVwUVEHmfI</a><p>Also check out Lucid Rains Github, who uses it extensively to build transformer architectures from scratch: <a href="https:&#x2F;&#x2F;github.com&#x2F;lucidrains" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lucidrains</a> \<p>* Example: <a href="https:&#x2F;&#x2F;github.com&#x2F;lucidrains&#x2F;alphafold2&#x2F;blob&#x2F;d59cb1ea536bc5d2e0eee81056d786cb1011ac57&#x2F;alphafold2_pytorch&#x2F;alphafold2.py#L150" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lucidrains&#x2F;alphafold2&#x2F;blob&#x2F;d59cb1ea536bc5...</a>
评论 #30973877 未加载
thetwentyoneabout 3 years ago
Also see: <a href="https:&#x2F;&#x2F;github.com&#x2F;ahwillia&#x2F;Einsum.jl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ahwillia&#x2F;Einsum.jl</a>
immmmmmabout 3 years ago
If you&#x27;re into tensor algebra i can only recommend the beautiful piece of Software Cadabra is:<p><a href="https:&#x2F;&#x2F;cadabra.science&#x2F;" rel="nofollow">https:&#x2F;&#x2F;cadabra.science&#x2F;</a><p>We wrote an article with it once, 40th order in the Lagrangian, perhaps 50k pages of calculations when all printed. Amazing tool! Thanks Kasper!
physicsguyabout 3 years ago
Oh god why did I not know about this when I did my theoretical physics PhD
评论 #30976834 未加载
aquafoxabout 3 years ago
There&#x27;s also an implementation in R: <a href="https:&#x2F;&#x2F;github.com&#x2F;const-ae&#x2F;einsum" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;const-ae&#x2F;einsum</a>