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

PMVector/PMMatrix >> #dot: does not compute a dot product. #29

Closed
emdonahue opened this issue May 14, 2017 · 8 comments
Closed

PMVector/PMMatrix >> #dot: does not compute a dot product. #29

emdonahue opened this issue May 14, 2017 · 8 comments

Comments

@emdonahue
Copy link

emdonahue commented May 14, 2017

Currently, #* computes the dot product:
#(1 2) asPMVector * #(2 1) asPMVector. "4"

and #dot: computes elementwise multiplication:
#(1 2) asPMVector dot: #(2 1) asPMVector. "a PMVector(2 2)"

#dot: should probably be renamed to something like #elementwiseMultiply: or maybe a shorter binary message.

@olekscode
Copy link
Member

I think I could swap them.
But wouldn't it silently break all the code that has ever used this multiplication?

@emdonahue
Copy link
Author

emdonahue commented May 18, 2017

Yes, for that reason I think swap is a bad idea. Moreover, #* is a natural message for dot product because that is what we would expect, from the mathematical notation, to be polymorphic with scalars. Still, having #dot: not compute the dot product is probably not ideal under any circumstances. My thought would be to leave the default multiplication #* as the dot product, make #dot: just delegate to #*, and add a new method for elementwise multiplication.

@SergeStinckwich
Copy link
Member

We can try to swap because I don't silent breaks ;-) we have also a lot of tests to cover these kind of changes. Before that we can have a look to dot: implementors if they are any others.

@emdonahue
Copy link
Author

I don't think we should swap. I didn't fully think it through before I made that suggestion. Dot product IS the default multiplication for matrices and vectors, so it makes sense to leave #* as the dot product. I think all we need to do is rename #dot: to something like #elementwiseMultiply: or maybe some shorter binary message.

@nicolas-cellier-aka-nice
Copy link
Contributor

nicolas-cellier-aka-nice commented Aug 2, 2017

Indeed, dot: is misleading and should be renamed...
But I never saw * used for dot product elsewhere. Usually it can be array product (element-wise), or matrix product (matrix*vector), or external product in a space vector (scalar*vector).
If * is both dot product and scalar product, then (u*v)*w ~= u*(v*w)

@hemalvarambhia
Copy link
Contributor

I had a quick look at wikipedia and this binary operation is referred to as the Hadamard product (or Schur product/entrywise product) and the symbol used to refer to it is a circle with a dot inside it. Could we call the message circleDot instead of dot?

@SergeStinckwich
Copy link
Member

yes better to be more precise. Maybe hadamardProduct ?

@hemalvarambhia
Copy link
Contributor

I think we can introduce hadamardProduct as you say and deprecate the dot message, after your mentioning your concern about silent breaks.

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

No branches or pull requests

5 participants