numpy-like package for node

前端 未结 9 2252
误落风尘
误落风尘 2021-01-31 01:30

During my years on Python development, I\'ve always been amazed at how much much much faster things become if you manage to rewrite that code that loops though your ndarray and

9条回答
  •  爱一瞬间的悲伤
    2021-01-31 02:20

    I've not tried this, but I found node-lapack. Since Numpy gets most of it's speed from using blas/lapack to do everything, this should help. From the readme it looks like it has an array object too, which is essential to not convert between JS and lapack on every operation.

    Here's a part of their demo:

    var lapack = require('lapack');
    
    var result = lapack.sgeqrf([
        [1, 2, 3],
        [3, 4, 5],
        [5, 6, 7]
    ]);
    
    console.log(result.R);
    console.log(result.tau);
    
    result = sgesvd('A', 'A', [
        [1, 2, 3],
        [3, 4, 5],
        [5, 6, 7]
    ]);
    
    console.log(result.U);
    console.log(result.S);
    console.log(result.VT);
    
    result = lapack.sgetrf([
        [1, 2, 3],
        [3, 4, 5],
        [5, 6, 7]
    ]);
    
    // see the readme for more
    

    It seems to be a pretty direct interface to lapack using the same names, so in that regard it's not as convenient as Numpy, but at least it takes care of array dimensions and stuff and should be about as fast (since most of the work is being done by Lapack in either case).

    However, this won't work in a browser, which means everywhere where this is available, Python is probably also available. Personally I'd stick with Python, which is much more dominant for numerical stuff, unless there's some specific Node functionality Python is missing...

提交回复
热议问题