Live data from Hacker News

DumPy: NumPy except it's OK if you're dum

dynomight.net

21–30 of 62 posts

Re: DumPy: NumPy except it's OK if you're dum

#21

Pretty sure Numpy’s einsum[1] function allows all of this reasoning in vanilla numpy (albeit with a different interface that I assume this author likes less than theirs). Quite sure that first example of how annoying numpy can be could be written much simpler with einsum. [1]: https://numpy.org/doc/stable/reference/generated/numpy.einsu...

Sure, but einsum needs a syntax and concepts of its own, and more importantly does not work if you need to do something else than a limited set of matrix operations.

Re: DumPy: NumPy except it's OK if you're dum

#22
post #16

Dupe. Posted a number of times the past day and a half: https://news.ycombinator.com/item?id=44072775 https://news.ycombinator.com/item?id=44063553 https://news.ycombinator.com/item?id=44078019 https://news.ycombinator.com/item?id=44063490

but only https://news.ycombinator.com/item?id=44063490 has 'some' comments. so this current discussion is better

There is an "older" discussion with a different title: https://news.ycombinator.com/item?id=43996431 (488 points | 9 days ago | 212 comments)

Re: DumPy: NumPy except it's OK if you're dum

#23
Lots to like here but I'm not so sure about this:

> In DumPy, every time you index an array or assign to a dp.Slot, it checks that all indices have been included.

Not having to specify all indices makes for more generic implementations. Sure, the broadcasting rules could be simpler and more consistent, but in the meantime (implicit) broadcasting is what makes NumPy so powerful and flexible.

Also I think straight up vmap would be cleaner IF Python did not intentionally make lambdas/FP so restricted and cumbersome apparently due to some emotional reasons.

Re: DumPy: NumPy except it's OK if you're dum

#24
post #16

Earlier quoted context omitted.

but only https://news.ycombinator.com/item?id=44063490 has 'some' comments. so this current discussion is better

There is an "older" discussion with a different title: https://news.ycombinator.com/item?id=43996431 (488 points | 9 days ago | 212 comments)

That's a different post.

Re: DumPy: NumPy except it's OK if you're dum

#25
I think this sort of DSL construction is a perfect fit for languages with macros: Lisp, Nim, etc. I spend a lot of time on both so I might explore the possibilities. What should a higher-dimensional array indexing, looping, and broadcasting syntax even look like, if until now it's just been cludges? Is it just APL but with actual words?

Re: DumPy: NumPy except it's OK if you're dum

#26

Pretty sure Numpy’s einsum[1] function allows all of this reasoning in vanilla numpy (albeit with a different interface that I assume this author likes less than theirs). Quite sure that first example of how annoying numpy can be could be written much simpler with einsum. [1]: https://numpy.org/doc/stable/reference/generated/numpy.einsu...

The author posted a previous article about why they don't like numpy and his problems with einsum:

https://dynomight.net/numpy/

Re: DumPy: NumPy except it's OK if you're dum

#27
post #11
post #5

Earlier quoted context omitted.

What’s a better syntax then?

The real question—to which I have absolutely no answer—is not about syntax, it's about concepts: what is a better way to think about higher-dimensional arrays rather than loops and indices? I'm convinced that something better exists and, if it existed, encoding it in a sufficiently expressive (ie probably not-Python) language would give us the corresponding syntax, but trying to come up with a better syntax without a…

Numpy seems somewhat constrained here… it grew out of the matrix ecosystem, and matrices map naturally to two-dimensional arrays (sidenote: it’s super annoying that we have n-dimensional matrices and n-dimensional arrays, but the matrix dimension maps to the width of the array).

Anyway, the general problem of having an n-dimensional array and wanting to dynamically… I dunno, it is a little tricky. But, sometimes when I see the examples people pop up with, I wonder how much pressure could be relieved if we just had a nice way of expressing operations on block or partitioned matrices. Like the canonical annoying example of wanting to apply solve using a series of small-ish matrices on a series of vectors, that’s just a block diagonal matrix…

Re: DumPy: NumPy except it's OK if you're dum

#28
Always wanted to experiment with a syntax like this myself, thanks to author! I completely agree with you reasoning re complexity of mental model for indexing vs broadcasting. Moreover, it appears to me that such a representation should allow for finding more optimal low level impls (something like deeper "out of order" op fusing, idk)? I've seen a paper from either nvidia or meta around five years ago doing exactly that - translating an index-based meta-language built on top of python into cuda kernels (usually several variants and picking the best), can't find the reference unfortunately.

Re: DumPy: NumPy except it's OK if you're dum

#29
post #14
post #3

I’ve known some people who didn’t want to learn the syntax of numpy and did it all in loops, and the code was not easy to read. It was harder to read. The fundamental issue is that operations on high dimensional arrays are very difficult to reason about. Numpy can probably be improved, but I don’t think loops are the answer.

The point here is not that it’s loops per se, the point is that the indexing is explicit. It seems like a big win to me. The article’s ~10 non-trivial examples all make the code easier to read, and more importantly, to understand exactly what the code is doing. It is true that some operations are difficult to reason about, that’s where explicit indexing really helps. The article resonates with me because I do want to…

I involuntarily whispered "reshape" to myself near the top of your comment. Numpy is a very different way for me to think and I have similar feelings to what you're describing.

Re: DumPy: NumPy except it's OK if you're dum

#30
It seems like a neat idea. If it can just be layered on top of Jax pretty easily… I dunno, seems so simple it might actually get traction?

I wish I could peek at the alternative universe where Numpy just didn’t include broadcasting. Broadcasting is a sort of ridiculous idea. Trying to multiply a NxM matrix by a 1x1 matrix… should return an error, not perform some other operation totally unrelated to matrix multiplication!

Post reply on HN