Hacker News new | past | comments | ask | show | jobs | submit login

It does not appear to be the case.

On the other hand, optimal speed and JavaScript are often different ball parks.

I threw together this thing for when I need some matrix stuff in a little script. Not fast, but flexible.

    var vop = op=>( (a,b)=>( a.map((v,i)=>op(v,b[i])) ) );
    var vdiff = vop((a,b)=>a-b);
    var vadd = vop((a,b)=>a+b);
    var vdot= (a,b)=>a.reduce( (ac,av,i)=>ac+=av*b[i],0);
    var vlength = a=>Math.sqrt(vdot(a,a));
    var vscale = (a,b)=>a.map(v=>v*b);
    var vdistance = (a,b)=>vlength(vdiff(a,b));
    var vnormalised = (a,b=1)=>vscale(a,b/vlength(a));
    var project = (point, matrix) => matrix.map( p=>vdot(p,[...point,1]));
    var transpose = matrix=> ( matrix.reduce(($, row) => row.map((_, i) => [...($[i] || []), row[i]]), []) );
    var multiply = (a,b,...rest)=>(!b)?a:multiply(a.map( (p=>transpose(b).map(q=>vdot(p,q)))),...rest);

  
I look forward to the day when the sufficiently-smart JIT implements the optimal Matrix Multiplication from that. :-)



Thanks! I find it weird that performance-focused javascript projects don't have live benchmarks up so you can judge for yourself. Personally I've found that a semi-clever matrix multiplier in c++ compiled with emscripten can give about 1.5 gflops (singlethreaded on a 2.5GHz i7 macbook pro), and existing js libs like sushi are a lot slower.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: