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...
DumPy: NumPy except it's OK if you're dum
21–30 of 62 posts
Re: DumPy: NumPy except it's OK if you're dum
#22Dupe. 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
Re: DumPy: NumPy except it's OK if you're dum
#23> 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
#24Earlier 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)
Re: DumPy: NumPy except it's OK if you're dum
#25Re: DumPy: NumPy except it's OK if you're dum
#26Pretty 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...
Re: DumPy: NumPy except it's OK if you're dum
#27Earlier 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…
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
#28Re: DumPy: NumPy except it's OK if you're dum
#29I’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…
Re: DumPy: NumPy except it's OK if you're dum
#30I 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!