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

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

[Octave-bug-tracker] [bug #35481] [var{:}] does not collapse empty eleme


From: Garrett
Subject: [Octave-bug-tracker] [bug #35481] [var{:}] does not collapse empty elements when some elements are cell
Date: Wed, 08 Feb 2012 15:10:51 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0

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

                 Summary: [var{:}] does not collapse empty elements when some
elements are cell
                 Project: GNU Octave
            Submitted by: g2e
            Submitted on: Wed 08 Feb 2012 03:10:50 PM GMT
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.6.0
        Operating System: GNU/Linux

    _______________________________________________________

Details:

A simple example:


octave:1> a{4}={1};
octave:2> [a{:}]
ans = 
{
  [1,1] = [](0x0)
  [1,2] = [](0x0)
  [1,3] = [](0x0)
  [1,4] =  1
}


I expected the empty elements to be collapsed upon concatenation by the "[ ]"
operator leaving just a 1x1 cell array.  Instead the empty elements were
re-celled.  This shown behavior is inconsistent with empty element collapsing
when only numeric or char entries are present:


octave:3> a{4}=1;
octave:4> [a{:}]
ans =  1


and


octave:5> a{4}=['ab';'cd'];
octave:6> [a{:}]
ans =

ab
cd



The behavior also occurs for mixed cell/numeric/char cases which leads to the
numeric/char elements being re-celled:


octave:7> a{4}={1};
octave:8> a{2}=1;
octave:9> [a{:}]
ans = 
{
  [1,1] = [](0x0)
  [1,2] =  1
  [1,3] = [](0x0)
  [1,4] =  1
}


I expected an error in that example.  The behavior is the same if the cell
array (here 'a') is 2-dimensional:

octave:10> clear a;
octave:11> a{2,3}={1};
octave:12> a{1,2}=1;
octave:13> [a{:}]
ans = 
{
  [1,1] = [](0x0)
  [1,2] = [](0x0)
  [1,3] =  1
  [1,4] = [](0x0)
  [1,5] = [](0x0)
  [1,6] =  1
}


The lack of collapsing empty elements when cell elements are present is
inconsistent with Matlab behavior (7.10.0):


>> a{4}={1};
>> [a{:}]

ans = 

    [1]

>> a{4}=1;
>> [a{:}]

ans =

     1

>> a{4}=['ab';'cd'];
>> [a{:}]

ans =

ab
cd

>> a{4}={1};
>> a{2}=1;
>> [a{:}]

ans = 

    [1]    [1]

>> clear a;
>> a{2,3}={1};
>> a{1,2}=1;
>> [a{:}]

ans = 

    [1]    [1]

>> 



The Octave and Matlab are the same except for the collapsing of empty
elements.  It is interesting to note that the unexpected re-celling of
non-empty elements (which I thought would throw an error) is consistent with
Matlab.  So it seems Octave just needs to know not to re-cell empty elements
to be compatible and consistent.

Oh and I tested the behavior for mixed numeric/char elements:


octave:14> clear a;
octave:15> a{1,2}=1;
octave:16> a{2,3}='a';
octave:17> [a{:}]
ans = a
octave:18> double(ans)
ans =

    1   97


which IS consistent with Matlab.  So it looks like there is a type
relationship of cell>char>numeric.





    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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