One thing I noticed about the dot syntax is it's obvious that vector or matrix arithmetic is being performed.
If element-wise matrix addition is performed with + as shown below, then it's not entirely obvious if a and b are scalars or matrices. The a + b may be defined somewhere in code that is not near the creation of the matrix variables so just looking at a + b could mean adding two floats, doubles, or integers or it could mean adding two matrices.
let a: Matrix<Double> = [[1, 2, 3], [4, 5, 6]]
let b: Matrix<Double> = [[2, 3, 4], [7, 8, 9]]
let c = a + b
If dot syntax is used such as .+, then it's obvious that a .+ b is adding two vectors or matrices element-by-element. And because .+ does not exist in Swift, then it's not likely to get confused with adding two floats, doubles, or integers.
let a: Matrix<Double> = [[1, 2, 3], [4, 5, 6]]
let b: Matrix<Double> = [[2, 3, 4], [7, 8, 9]]
let c = a .+ b
So I guess the Julia approach is best here. But Julia does support different operators for the same operation, such as + and .+ both perform element-wise matrix addition. I could do the same in Swift:
| Description |
NumPy |
Julia |
MATLAB |
Swift |
| Element-wise addition |
+ |
.+ |
+ |
.+ or + |
| Element-wise subtraction |
- |
.- |
- |
.- or - |
| Element-wise multiplication |
* |
.* |
.* |
.* |
| Matrix multiplication |
@ |
* |
* |
* |
| Element-wise division |
/ |
./ |
./ |
./ |
| Element-wise power |
** |
.^ |
.^ |
.^ |