Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

To do that you first need to have a way of extending JavaScript with C and/or Fortran. No way numpy can be implemented in pure js or python without being excruciatingly slow.


sort by: page size:

This was posted multiple times on HN over the past 5 years.

And every time I see it, I cry that JavaScript doesn't have something like numpy.

numpy is just so damn logical and fast (and comprehensive!) that i don't consider myself a python programmer, i'm a numpy user.

EDIT: (removed complaint). That said: this looks like a good foundation for someone to use for implementing a fully featured numpy in JS.


I think Numpy is written in C, so in principle they could use the same approach for JS (and invoke SIMD functions from C). The problem, however, is that there is no operator overloading in JS. So you can't write things like a[:,:,3] *= 2.

Ah ok, by "numpy wouldn't work in JS" you meant something like it wouldn't be popular or as loved. Makes more sense now.

Is there a Numpy equivalent for JS yet? How easy is it to use (considering that JS doesn't have operator overloading)?

So rather than spend 10-20 minutes reading about numpy, the author wrote 3 other implementations...?

The fact that they ran the C code without the optimisation flags and compared it that way makes me think Javascript was what they actually wanted to write this one in anyway.


In particular, does this mean Javascript has access to Numpy? Sounds unbelievable, but would be extremely cool.

The core of numpy is written in C, with some unfortunate dependencies on the C Python API. It should be possible to extract the C core of numpy (with some additional work) and wrap it in Javascript or Lua.

It doesn't sound like OP is working on something that needs NumPy, and if he did, I don't see why he couldn't write a small script in Python to be called by the existing codebase.

But javascript does not have something like numpy. You can easily get one to two orders of magnitude faster using numpy when applicable, and a MP3 decode certainly falls in that category.

Hmm, numpy isn't pure python, is it? If I read correctly this only works with pure python.

NumPy has lots of C calls, and the functionality has to be implemented entirely with the language features. What you are suggesting is outside the scope of the paper.

This is an interesting idea.

However, their timelines are too short. It makes me feel like they don't really understand what it's going to take.

A good start would be the C++ library libdynd which was designed to potentially be used from Javascript.

NumPy has much more than vectors and matrices. Does Javascript have operator overloading?


There’s probably a way to get at the numpy objects without having to go through the python runtime and do all the computation in pure C.

I assume, haven’t really messed with numpy for anything but I can’t imagine it wouldn’t work that way.


You can do it with the nodejs FFI. It makes me cringe a bit to say that, but you could do it in roughly the same way as how NumPy does it.

Thank you! So this looks interesting but it seems like there's no easy way to share numpy arrays?

The main use case for a language other than python is a more robust codebase but also performance. We need to be able to efficiently ship lots of large arrays between the languages and the Rust-Python interop supports zero copy arrays for example.


Interesting. Numpy within python does give near native speeds for number crunching though does it not? Copying around arrays does feel like an area where python suffers, however.

I wish NumPy had it built in.

Numpy is Fortran btw.

numpy doesn’t get sent to the client if you use it on the server.

> JavaScript frontends are becoming unnecessarily bloated

next

Legal | privacy