Live data from Hacker News

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

dynomight.net

11–20 of 62 posts

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

#11
post #5
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.

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 better conceptual model won't get us very far.

Then again, maybe even that is wrong! "Notation as a tool for thought" and all that. Maybe "dimension-munging" in APL really is the best way to do these things, once you really understand it.

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

#12
In the way that `ggplot2` tries to abstract those common "high dimensional" graphing components into an intuitive grammar, such that you may in many places be able to guess the sequence of commands correctly, I would love to see an equivalent ergonomic notation. This gets part way there by acknowledging the problem.

Mathematical operations aren't obliged to respect the Zen of Python, but I like the thought that we could make it so that most have an obvious expression.

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

#13
post #5
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.

What’s a better syntax then?

English. "Write me a Python function or program that does X, Y, and Z on U and V using W." That will be the inevitable outcome of current trends, where relatively-primitive AI tools are used to write slightly more sophisticated code than would otherwise be written, which in turn is used to create slightly less-primitive AI tools.

For example, I just cut-and-pasted the author's own cri de coeur into Claude: https://claude.ai/share/1d750315-bffa-434b-a7e8-fb4d739ac89a Presumably at least one of the vectorized versions it replied with will work, although none is identical to the author's version.

When this cycle ends, high-level programs and functions will be as incomprehensible to most mainstream developers as assembly is today. Today's specs are tomorrow's programs.

Not a bad thing, really. And overdue, as the article makes all too clear. But the transition will be a dizzying one, with plenty of collateral disruption along the way.

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

#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 learn numpy syntax, I’ve written hundreds of programs with nympy, spent countless hours doing battle with it, and I feel like I’m no better off now than someone who’s brand new to it. The indexing is constantly confounding, nothing ever just works. Anytime you see “None” and “axis=“ inside an operation, it’s a tell: bound to be difficult to comprehend. I’m always having to guess how to use some combination of reshape, dstack, hstack, transpose, and five other shape changers I’m forgetting, just to get something to work and it’s difficult to read and understand later. It feels like there is no debugging, only rewriting. I keep reading the manual for einsum over again and I’ve used it, but I can’t explain how, why, or when to use it, it seems like this thing you have to resort to because no other indexing seems to work. The ability to do straightforward explicit non-clever indexing as if you were writing loops seems like a pretty big step forward.

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

#15
That is amazing. My main doubt would be how future proof this is. Does it wrap numpy? Or something equivalent? Does it require continuous development to keep up?

Also I both understand the need for declaring the matrices up front and think it's a bit of a shame that it is not seamless.

Here are some (ill-advised?) alternatives:

    X, Y, Z = dp.Slots()
    
    with dp.Slot() as X:
        ...
    
    import dp.Slot as new
    X = new['i','j'] = ...

    X = dp['i','j'] = ...

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

#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

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

#17

That is amazing. My main doubt would be how future proof this is. Does it wrap numpy? Or something equivalent? Does it require continuous development to keep up? Also I both understand the need for declaring the matrices up front and think it's a bit of a shame that it is not seamless. Here are some (ill-advised?) alternatives: X, Y, Z = dp.Slots() with dp.Slot() as X: ... import dp.Slot as new X = new['i','j'] = ...…

Need transpilation rather than relying on this library being present. I like the idea alot though

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

#18

That is amazing. My main doubt would be how future proof this is. Does it wrap numpy? Or something equivalent? Does it require continuous development to keep up? Also I both understand the need for declaring the matrices up front and think it's a bit of a shame that it is not seamless. Here are some (ill-advised?) alternatives: X, Y, Z = dp.Slots() with dp.Slot() as X: ... import dp.Slot as new X = new['i','j'] = ...…

(author here) This wraps JAX and JAX's version of NumPy. It would surely require some development to keep up, although it's quite short and simple (only 700 lines), so I don't think it would be a big burden. That said, I should be clear that my goal here is just to show that this is possible/easy, and possibly inspire existing array packages to consider adding this kind of syntax.

I like your alternatives! I agree that having to write

  X = dp.Slot()
before assigning to X is unfortunate. I settled on the current syntax mostly just because I thought it was the choice that made it most "obvious" what was happening under the hood. If you really want to, you could use the walrus operator and write

  (X := dp.Slot())['i','j'] = ...
but this cure seems worse than the disease...

Actually, doing something like

  X = new['i','j'] = ...
could simplify the implementation. Currently, a Slot has to act both like an Array and a Slot, which is slightly awkward. If new is a special object, it could just return an Array, which would be a bit nicer.

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

#19
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...

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

#20
The kind of person with the background to need these operations, and who is working on the kinds of problems where this stuff comes up, is more than capable of learning numpys syntax. Its not that bad.

Avoiding the special purpose tools designed by and used by the people who work on these problems every day is the instinct of someone who has just started needing them and wants to solve new kinds of problems with the tools they already know. But the people with experience don't do it that way (for a reason), you need to learn what the current best solution is before you can transcend it.

Guys, every few months some well meaning person posts their great new library here that "fixes" something to remove all that pesky complexity. Invariably its made by some beginner with whatever it is who doesn't understand why the complexity exists, and we never hear of them or the library again. This is absolutely one of those times.

Post reply on HN