After discussions with Pierre-Antoine, here is a more precise highlight of a difference between nested function handles in Octave 6.1.0 and Matlab.
The following code works as expected both in Matlab and in Octave 6.1.0:
% Define this in main_610.m
function f = main_610(x)
f = @fun;
function y = fun()
y = x;
end
end
% Run this:
f = main_610(5); f() % both systems display 5, as intended.
However, the following succeeds in Matlab and fails in Octave 6.1.0 (error: "z undefined")
% Define this in main_610.m
function f = main_610(x)
z = 2*x;
f = @fun;
function y = fun()
y = z; % fails in Octave 6.1.0 because the subfunction doesn't 'see' z; it sees x though.
end
end
% Run this:
f = main_610(5); f() % Matlab displays 10; Octave 6.1.0 throws an error.
Based on this, here is a possible conclusion regarding Octave 6.1.0: nested subfunctions can see the inputs of the mother function, but they cannot see other variables created within the mother function.
For productmanifold and powermanifold, this suggests that a possible way out is to copy/past the definitions of elems and nelems in all subfunctions... Not exactly an elegant solution (and we may need to do this in very many other places), but it wouldn't be too hard.
Perhaps Octave offers other ways to handle this (for example, a way to "tell" Octave that elems and nelems are "static"; or perhaps automatic detection of the static nature of such variables is on the feature list for futur releases). If anyone knows, please post here.
Best,
Nicolas