octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #55984] movfun dangerous test for function out


From: Juan Pablo Carbajal
Subject: [Octave-bug-tracker] [bug #55984] movfun dangerous test for function output dimension
Date: Sun, 4 Oct 2020 11:43:14 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0

Follow-up Comment #2, bug #55984 (project octave):

The issue is that the code assumes that all zeros is a valid input for the
function.

The following example shows the failure


function y = bad_func (x)
  if all (x != 0)
    y = sum (x);
  endif
endfunction

movfun(@bad_func,rand(1,100),3)
error: 'y' undefined near line 1, column 1
error: called from
    bad_func at line 5 column 1
    movfun at line 259 column 11


The function is not defined for the input that we are using to recover the
output dimension.
A better check is to use the input that the user provided. If there is a
failure then is an user error and not due to an assumption in the code.

Here are the changes to be done on movfun.m from default branch (491433ba8612)
to implement the safer "check"


259c259
<   tmp     = fcn (zeros (length (win), 1));  # output for window
---
>   tmp     = fcn (x(1:length(win)));  # output for window


After this changes the previous examples runs, and the error is recovered when
the user input is invalid


movfun(@bad_func,zeros(1,100),3)
error: 'y' undefined near line 1, column 1
error: called from
    bad_func at line 5 column 1
    movfun at line 259 column 11


I cannot think of a test to provide a better error message in that case. I
guess it is up to the programmer of bad_func.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55984>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]