bugGNU Octave - Bugs: bug #38164, inline doesn't understand x(:) ...

 
 

bug #38164: inline doesn't understand x(:) (and other indexing of x)

Submitted by:  Mikhail Kostousov <mikhako>
Submitted on:  Thu 24 Jan 2013 05:21:54 PM UTC  
 
Category: InterpreterSeverity: 2 - Minor
Priority: 1 - LaterItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 3.6.2Operating System: Microsoft Windows

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 24 Jan 2013 10:17:05 PM UTC, comment #4:

So I just couldn't step away from this. It turns out that Matlab's behaviour here is to never create inline functions with no input arguments and "x" is always the default input argument if none is found. This is an easy patch on Octave:

http://hg.savannah.gnu.org/hgweb/octave/rev/6535f92350ec

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Thu 24 Jan 2013 06:02:01 PM UTC, comment #3:

So this is where the problem is:

http://hg.savannah.gnu.org/hgweb/octave/file/bbce6de5c0a5/libinterp/octave-value/ov-fcn-inline.cc#l704

The inline parser assumes that "foo(bar)" whatever is always a function call, regardless of what foo and bar may be. This is actually documented: " All arguments followed by a parenthesis are considered to be functions."

I don't know how to fix this. A reasonable thing would be to check the symbol table for the existence of a function with this name, but exclude some functions such as i and j.

I'm lowering the priority for this, since there are a couple of easy work-arounds and inline functions should be deprecated in favour of anonymous functions.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Thu 24 Jan 2013 05:36:10 PM UTC, comment #2:

As another workaround, you can pass "x" as the second argument to inline.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Thu 24 Jan 2013 05:31:51 PM UTC, comment #1:

feval is unrelated. The problem is inline. It doesn't recognise variables if you index into them.

You can work around this by explicitly using an anonymous function instead of making inline attempt to parse the string as a function:

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Thu 24 Jan 2013 05:21:54 PM UTC, original submission:

octave-3.6.2.exe:2> feval(inline('sum(x(:))'),[1,2;3,4])
error: `x' undefined near line 2 column 9
error: evaluating argument list element number 1
error: called from:
error: at line -1, column -1

If you change x(:) to x, feval will work. There is workaround to reshape matrix x to an array (like reshape(x,prod(size(x)),1) ), but in case you need to get something by index, it will not work.

Mikhail Kostousov <mikhako>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by mikhako (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 24 Jan 2013 10:17:05 PM UTCjordighStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Thu 24 Jan 2013 06:02:01 PM UTCjordighSeverity3 - Normal=>2 - Minor
      Priority5 - Normal=>1 - Later
    Thu 24 Jan 2013 05:31:51 PM UTCjordighStatusNone=>Confirmed
      Summaryfeval doesn\'t understand x(:) (and other indexing of x)=>inline doesn't understand x(:) (and other indexing of x)

    Back to the top


    Powered by Savane 3.1-cleanup1