I have pushed the following three experimental changesets that enable
bsxfun automatically for almost all binary operations except for those
on sparse matrices. This includes things like rem, min, and hypot
(basically, anything that calls binmap is also covered), along with
basic arithmetic and logical operators:
http://hg.savannah.gnu.org/hgweb/octave/rev/d9d65c3017c3 http://hg.savannah.gnu.org/hgweb/octave/rev/4061106b1c4b http://hg.savannah.gnu.org/hgweb/octave/rev/61be447052c3I didn't attempt to refactor the code to get rid of some macros. That
seemed like it required deeper surgery than I wanted to do.
I noticed that in some cases my implementations disagree a little with
what bsxfun does. For example,
bsxfun(@power, uint8(rand(2)), rand(2,1))
casts everything to double whereas
uint8(rand(2)) .^ rand(2,1)
casts to uint8. I'm not sure which one is more correct, but I think it
makes more sense to keep the one with smaller precision. I understand
Matlab just refuses to do bsxfun arithmetic (or arithmetic in
general?) with mixed types.
I noticed that bsxfun seems to just cast sparse matrices into full
matrices. I didn't implement anything at all for sparse matrices. If
there's interest, I could keep going.
HTH,
- Jordi G. H.