Hacker News new | ask | show | jobs
by shiandow 434 days ago
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'] = ...
2 comments

(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.
Need transpilation rather than relying on this library being present. I like the idea alot though