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? #27

Open
Rudxain opened this issue Apr 29, 2022 · 0 comments
Open

Dot product? #27

Rudxain opened this issue Apr 29, 2022 · 0 comments

Comments

@Rudxain
Copy link

Rudxain commented Apr 29, 2022

I don't see any reason to add this because:

  • Math methods don't expect arrays, the only thing similar to that is making use of rest params or the local arguments object.
  • It's not a commonly used operation, although more frequently used than matrix multiplication.
  • It's easy to implement in userland (see polyfill at the footer).

However some reasons to add it may be:

  • Users/devs don't need to think about how to handle arrays with different lengths, because it would be standardized.
  • Less rounding errors, because implementations could use Kahan Summation or Pairwise Sum internally (related: Issue Math.sum? #4 ).

I think this shouldn't be added because, as said before, it would break the consistency of Math.*. This is better suited for the Array namespace or a new namespace, which are both out of scope of this proposal. I opened this Issue just in case someone has valid (and solid) arguments for adding it.

Polyfill:

Math.dotProd = function(arr0, arr1) {
  return arr0.map((_, i) => arr0[i] * arr1[i]).reduce((x, y) => x + y);
}

Wikipedia article

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

1 participant