So the natrual question would be what should be done in a case like (A is nxm 2-D array, v is a 1-D m element vector) A.+v? Should that do an implicit "bsxfun", or should doing that require a different operator?
The way I think about it, * and / work on matrices, i e linearoperators. The natural definition of + that goes with this is the one
that makes * distribute over +
A*x + B*x = (A + B)*x # A, B linear operators, operating on
column vector x
i e + adds linear operators. It just happens that you do that by
adding the corresponding matrix elements (but it doesn't make sense to
broadcast).
Now .* and ./ are elementwise. Suppose that they do broadcast.
To have .* distribute over .+, we need e g that
R.*C .+ A.*C = (R .+ A).*C # R = row array, C = column array, A
= 2d array
i e since .* broadcasts, .+ must do so too. It is pointwise plus
+(A::Matrix, x::Number) = A+x*one(A)
(A+1)*B == A*B+1*B
This would be a big win for generic programming — e.g. polynomial expressions would apply trivially to matrices without needing any special care. The cost, of course, is a bit of incompatibility with Matlab: most usages of Matlab's + operator should be changed to .+ instead. That's a really easy search-and-replace, however.
The broadcast is simple: you broadcast any singleton dimension along the corresponding singleton dimension, considering absent trailing dimensions as singletons. Suppose A is an mxn matrix and v is an m-length vector. Then A.+v is equivalent to but more efficient than A+v*ones(1,n). Likewise, A'.+v' is equivalent to but more efficient than A'+ones(n,1)*v'.
Having A+v be different than v+A would be insane.
I'm a long-time Matlab user whose code contains, I'd guess, something like at
least one call to bsxfun every 50 or so lines (across all types of projects,
and a much higher density on some). Replacing it with broadcasting on '.'
operators seems likely to be an improvement to me, and quite intuitive given
what .* already means.
I would have more reservations about broadcasting simple '+', but that is not
what is being proposed here. So I guess I'd say I am entirely in favor.
Best,
--Tim