Do any browsers currently support or plan to support fast array math operations, similar to what NumPy provides for Python? Here is an example to dem开发者_如何学运维onstrate what I mean:
var a = new NumericArray('uint32', [1, 2, 3, 4]);
var b = new NumericArray('uint32', [2, 2, 2, 2]);
var c = a.add(b); // c == [3, 4, 5, 6]
In that example, add
is not meant to represent a function implemented in JavaScript. That would be trivial to write. It is meant to represent a function that is written in C (or whatever language the JavaScript implementation is written in) and is optimized specifically for math operations over the array.
I don't think so, but Google are certainly interested in pushing the limits of what is possible in Javascript. If you are interested in safely running native code in the browser you might want to take a look at NaCl.
I'm the original poster, but I figured I'd share something I ran across. WebGL (implementations are already in progress by Mozilla and WebKit, see Lesson 0 at learningwebgl.com) introduces something called "Typed Arrays", which is sort of what I was looking for. The specification is available at https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html.
You can use use the built-in JavaScript array.map method
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3], numbers is still [1, 4, 9]
精彩评论