Today in the LinearAlgebra module we write matrix-matrix multiplication with e.g. A.dot(B) or dot(A,B).
However, it would be more math-like if we had an infix operator for this.
It's my understanding that Python uses @ for this and Julia uses * for mat-mat and .* for element-wise.
Should we add an operator for matrix multiplication? If so, what should it be?
Related to #14282 is the idea that we could use a UTF-8 symbol such as •
Ignoring whether or not it's a good idea, is it possible for the language syntax & parser to support . as a matrix-multiplication operator?
var C = A . B;
I doubt it, because there would be an ambiguity between matrix multiplication and method call.
Eg
var C = some kind of matrix thing;
var isdiagonal = some kind of matrix thing;
C . isdiagonal // does this call an isdiagonal paren-less method? Or multiply with the local variable?
Related to #14282 is the idea that we could use a UTF-8 symbol such as •
Even though people seem to like unicode operators in Julia, I downvoted this as I need someone to train me how that would be a good idea while typing code. I definitely don't want to type latex in my code :) I wonder what some of the (potential) LinearAlgebra users think about this.
How common is element-wise multiplication in linear algebra? My thinking is that not as common as matrix multiplication, so maybe we need * to do matrix multiplication and handle element-wise via a method on matrices. This would make * behave differently between 2D arrays and matrices, however.
FWIW I brought up this question because I was thinking about how a Matrix type was a motivating example for user-defined implicit conversions. One of the things we might get from a Matrix type (separate from 2D arrays) would be for * to mean matrix-matrix multiplications but this issue brings up an alternative strategy to that. (I currently do not think it makes sense to have implicit conversions between any new Matrix type and 2D arrays - such implicit conversions are particularly problematic for matrix types like DiagonalMatrix or TriangularMatrix).
My preference here would be to distinguish matrices from 2D arrays and use * for matrix multiplication rather than introducing a new operator and conflating matrices and 2D arrays (in saying that, I realize they're fairly conflated today).
(I'm also generally open to the more concept we've discussed at times of permitting users to define any operators they want using identifiers that are sequences of certain symbolic characters, where doing so would permit supporting a new operator as matrix multiplication. But not to the extent that it suggests conflating 2D arrays and matrices; I'd only do this if, for some reason, we didn't want * on a matrix type to mean multiplication).
Not a big fan of UTF-8 operators because it is too easy to confuse with a similar looking symbol depending on your font. When I looked at @mppf 's first comment about UTF-8, it still looked like a dot to me. When I now look at it on a nice big 27inch screen, it looks more like a tiny bullet symbol. No, I do not need glasses.
The words used above. "This would make * behave differently between 2D arrays and matrices, however" should ring alarm bells. Allowing the same symbol to behave differently on a type which is nominally a superset of another is a recipe for disaster. On a totally different type, not an issue (in general).
I have never understood why we do not label what we commonly call matrix multiplication a "Binet product" after the French guy who first described it (although he is remembered in the Cauchy-Binet formula). But that has nothing to do with Chapel! I would like to ensure that '*' (ASCII 0x2a) always means element-by-element (or Hadamard or Schur) multiplication wherever it is used.