[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #59989] Wrong scope of nested function in anon
From: |
Markus Mützel |
Subject: |
[Octave-bug-tracker] [bug #59989] Wrong scope of nested function in anonymous function handle |
Date: |
Tue, 2 Feb 2021 02:55:09 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.56 |
URL:
<https://savannah.gnu.org/bugs/?59989>
Summary: Wrong scope of nested function in anonymous function
handle
Project: GNU Octave
Submitted by: mmuetzel
Submitted on: Tue 02 Feb 2021 08:55:07 AM CET
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Regression
Status: Confirmed
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: 6.1.0
Discussion Lock: Any
Operating System: Any
_______________________________________________________
Details:
Like reported on the discourse forum [1], calling the following function fails
in Octave 6.1.0:
function topLevelFunction()
% Helper anonymous function - used to pack/unpack design variables in actual
code.
unpacker = @(x) sum( x );
% Optimisation objective function - required soem other data passed through
% using anonymous function in call to solver.
function [ x ] = objFcn( x , a )
x = a + unpacker( x );
end % function nf
% Dummy solver - actually using leasqr.
function [ y ] = solver( funcHandle )
% Solver determine design values.
x = [ 2 , 3 ];
% Call objective function to get value.
y = funcHandle( x );
end % function
% Fixed data needed by objective function. Actually a heap of stuff
requiring
% complex calculation.
a = 1;
% Call optmiser.
% Octave 5.2.0, as shipped on Ubuntu 20.04 - OK.
% Octave 6.1.0, self compiled - FAIL:
% error: 'unpacker' undefined near line 10, column 10
% error: called from
% topLevelFunction>objFcn at line 10 column 7
% topLevelFunction>@<anonymous> at line 38 column 20
% topLevelFunction>solver at line 21 column 7
% topLevelFunction at line 38 column 5
y = solver( @(x) objFcn( x , a ) )
end % function topLevelFunction
The same function executes without error in Octave 5.2 and with Matlab
R2020b.
The expected output is:
>> topLevelFunction2
y = 6
In Octave 6.1.0, the function fails with the following error:
>> topLevelFunction
error: 'unpacker' undefined near line 10, column 10
error: called from
>objFcn at line 10 column 7
>@<anonymous> at line 38 column 20
>solver at line 21 column 7
topLevelFunction at line 38 column 5
[1]:
https://octave.discourse.group/t/anonymous-function-scope-change-from-5-2-0-to-6-1-0/701
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Tue 02 Feb 2021 08:55:07 AM CET Name: topLevelFunction.m Size: 1KiB
By: mmuetzel
<http://savannah.gnu.org/bugs/download.php?file_id=50821>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?59989>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #59989] Wrong scope of nested function in anonymous function handle,
Markus Mützel <=