JuliaLang/julia — Issue #436: array recycling/bsxfun-like operator
Author: shabbychef
Created: 2012-02-21 18:00:07+00:00
State: open

Having some kind of array recycling (as _e.g._ in R) for some (all?) binary operators can aid vectorized computation. (Rather, it allows one to write code without thinking too much about vectorization.) I am not sure that R's version of this Does The Right Thing, however:

1. Without fair warning, new users may silently be using this 'feature' without knowing it.
2. Turning it on by default in the core language is an extra complication in the compiler at least, and in the language definition.
3. My preference, at least, is to recycle as Matlab's `bsxfun`, instead of considering a multidimensional array as a single vector and recycling modulo its length. For example, I often deal with multidimensional (5d or higher) arrays; to compute a Z-score 'along' dimension `dim`, in Matlab I can write `x_zscore = bsxfun(@rdivide,bsxfun(@minus,x,mean(x,dim)),std(x,1,dim))`. While this is agnostic to the dimensionality of `x` and the value in `dim`, it is a right PITA to read. It would be preferrable to have, instead, `x_zscore = (x - mean(x,dim)) / std(x,1,dim)`.

Perhaps there should be some way to 'turn on' this kind of recycling in a given scope, which would result in overloading of the binary operators. (And perhaps this mechanism could support other kinds of recycling, _e.g._ R style.)