octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #31287] Certain assignments of empty arrays gi


From: anonymous
Subject: [Octave-bug-tracker] [bug #31287] Certain assignments of empty arrays give errors (Matlab incompatibility)
Date: Sat, 09 Oct 2010 22:04:09 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10

URL:
  <http://savannah.gnu.org/bugs/?31287>

                 Summary: Certain assignments of empty arrays give errors
(Matlab incompatibility)
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sat Oct  9 22:04:08 2010
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Iain Murray
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.2.2
        Operating System: GNU/Linux

    _______________________________________________________

Details:

The following minimal example gives "error: A(I,J,...) = X: dimensions
mismatch" in Octave, while Matlab leaves Y unchanged without complaint:

Y = 1;
Y(1, zeros(1,0)) = zeros(0,0);

You might reasonably think that the above code is silly, so let me give a
motivating example for altering Octave's behavior. Below is some code to
replace NaNs with some default values. It works in Octave and Matlab:

A = [  1   2   3   4   5;
     1.4 2.3 4.5 2.3 3.2];
defaults = [2.1 3.1 4.1 5.1 6.1];
mask = isnan(A(2,:));
A(2,mask) = defaults(mask);

If a function has code like the above and is sometimes given arrays with one
column, it breaks in Octave (but not in Matlab):

A = [  1;
     2.1];
defaults = [1.4];
mask = isnan(A(2,:));
A(2,mask) = defaults(mask);

The problem is that now size(defaults(mask)) is [0,0], so it looks like the
minimal example and Octave says "error: A(I,J,...) = X: dimensions mismatch".

One could argue that the code should have used:
    A(2,mask) = defaults(1,mask);
Which does work in Matlab and Octave regardless of the number of columns in
A. But making
    A(2,logical(0)) = zeros(0,0)
work would make more Matlab code work in Octave out-of-the-box. Matlab coders
wouldn't usually put in the "1," when indexing a vector, and even Octave
coders might not notice that an edge case is broken.


More examples:

% GROUP 1: for reference, these all work (do nothing) in both Matlab and
Octave:
a = 1;
a(1, []) = zeros(1,0)
a(1, zeros(1,0)) = zeros(1,0)
a(1, logical(0)) = zeros(1,0)

% GROUP 2: These work (do nothing) in Matlab but currently give
% "error: A(I,J,...) = X: dimensions mismatch" in Octave
% Making Octave accept these would be good for compatibility.
a = 1;
a(1, []) = zeros(0,0)
a(1, zeros(1,0)) = zeros(0,0)
a(1, logical(0)) = zeros(0,0)

% GROUP 3: Like Group 2 these work in Matlab but not in Octave.
% The error message is different:
% "error: A null assignment can only have one non-colon index."
% which makes sense because assigning '[]' has special meaning.
% Although Matlab accepts all of the following, I can't think of a
convincing
% use case. Maybe there is no point in "fixing" Octave for group 3(?).
a = 1;
a(1, []) = []
a(1, zeros(1,0)) = []
a(1, logical(0)) = []

The above experience was on:
GNU Octave, version 3.2.2
As shipped by Ubuntu 9.10 "karmic", Linx 2.6.31-22-generic i686
(I also briefly tried the Mercurial dev version)

I could probably be encouraged to try to come up with a patch. I thought I'd
see if there was interest in changing Octave before spending too much time
looking at the source. Also maybe one of the developers will know how to tweak
this much faster than I would be able to.




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?31287>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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