Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot product #26

Closed
nicolaspanel opened this issue Dec 11, 2015 · 3 comments
Closed

Dot product #26

nicolaspanel opened this issue Dec 11, 2015 · 3 comments

Comments

@nicolaspanel
Copy link

Hi,

Is there a way/module to perform dot product of 2 ndarrays?

Best regards

@nicolaspanel
Copy link
Author

ndgemm package handles matrix multiplication

@fasiha
Copy link

fasiha commented Aug 18, 2016

Consider adding .dot() as a user-friendly wrapper over ndgemm?

@fasiha
Copy link

fasiha commented Aug 18, 2016

This is about what I could manage:

function dot(...args) {
  return args.reduce((sofar, curr) => {
    const result = zeros([ sofar.shape[0], curr.shape[1] ]);
    gemm(result, sofar, curr);
    return result;
  });
}

Test code:

var zeros = require('zeros');
var ops = require('ndarray-ops');
var gemm = require('ndarray-gemm');

var a = ops.random(zeros([ 2, 3 ]));
var b = ops.random(zeros([ 3, 4 ]));
var c = ops.random(zeros([ 4, 2 ]));

var tmp = zeros([ 2, 4 ]);
var res1 = zeros([ 2, 2 ]);
gemm(tmp, a, b);
gemm(res1, tmp, c);

var res2 = dot(a, b, c);

assert(ops.equals(res1, res2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants