bugGNU Octave - Bugs: bug #52668, Anonymous function locks in an...

 
 

bug #52668: Anonymous function locks in an unexpected type for the arguments in its closure

Submitter:  Joseph Young <josyoun>
Submitted:  Thu 14 Dec 2017 10:24:26 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  josyoun Open/Closed:  * Closed
Release:  * 4.2.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 15 Dec 2017 02:38:27 AM UTC, comment #2: 

Perfect.  Thanks Rik!

Joseph Young <josyoun>
Thu 14 Dec 2017 11:05:46 PM UTC, comment #1: 

You're quite right that this problem exists with the current stable version of Octave.  The good news is that this has already been fixed in the development version of Octave.  This will be released as 4.4.0, but there is no release date set.  You can also access the fix by building the development version from Mercurial sources.  Instructions for that are on the web page.

Rik <rik5>
Group administrator
Thu 14 Dec 2017 10:24:26 PM UTC, original submission:  

It appears as though an anonymous function is locking in an unexpected type for one of its arguments.  Consider the following code:


octave:1> I=eye(5);
octave:2> ei=@(i)I(:,i);
octave:3> ei(3)
error: can't perform indexing operations for diagonal matrix type
octave:3> I(:,3)
ans =

   0
   0
   1
   0
   0


Basically, the closure appears to be locking in I as a diagonal matrix whereas if we access it directly the interpreter allows it to change types.  This also appears unique to Octave.  From MATLAB:


>> I=eye(5);
>> ei=@(i)I(:,i);
>> ei(3)

ans =

     0
     0
     1
     0
     0


That said, we can force the correct type by:


octave:1> I=full(eye(5));
octave:2> ei=@(i)I(:,i);
octave:3> ei(3)
ans =

   0
   0
   1
   0
   0


Anyway, I'm not sure if Octave is supposed to be dynamically changing the type in the closure or not.  It would appear that it should, but it's not.

Joseph Young <josyoun>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by josyoun (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-12-14 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code