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

 
 

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

Submitter:  Mikhail Kostousov <mikhako>
Submitted:  Thu 24 Jan 2013 05:21:54 PM UTC
   
 
Category:  Interpreter Severity:  2 - Minor
Priority:  1 - Later Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.6.2 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group Member
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>
Group Member
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>
Group Member
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:


feval(@(x) sum(x(:)), [1 2; 3 4])


Jordi Gutiérrez Hermoso <jordigh>
Group Member
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 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 jordigh (Posted a comment)
  • -email is unavailable- added by mikhako (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-01-24 jordigh StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2013-01-24 jordigh Severity3 - Normal 2 - Minor
        Priority5 - Normal 1 - Later
    2013-01-24 jordigh StatusNone 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.13-caa5.
    Corresponding source code