octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic bsxfun almost everywhere


From: Ben Abbott
Subject: Re: Automatic bsxfun almost everywhere
Date: Thu, 25 Aug 2011 08:27:36 -0400

On Aug 25, 2011, at 5:24 AM, Jordi GutiƩrrez Hermoso wrote:

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/61be447052c3

I 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.

I think bsxfun is behaving in inconsistently. ML handles such things in a consistent manner.

>> class ([uint8(rand(2)), rand(2)])

ans = uint8

Take a look at the bug report below.

https://savannah.gnu.org/bugs/?33966

Thus I think your choice is correct.

Ben

reply via email to

[Prev in Thread] Current Thread [Next in Thread]