bugGNU Octave - Bugs: bug #51728, del2 fails on 1-D input with a...


bug #51728: del2 fails on 1-D input with a vector as spacing

Submitted by:  None
Submitted on:  Fri 11 Aug 2017 11:04:56 AM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  Fixed Assigned to:  None
Originator Name:  Roger Jeurissen Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.0.0
Operating System:  GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

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


( Jump to the original submission)

Fri 25 Aug 2017 11:29:33 PM UTC, comment #8:

I fixed this on the development branch. See cset http://hg.savannah.gnu.org/hgweb/octave/rev/c7b801f36be4. Since this is just an m-file, the original reporter (OP) can grab the file del2.m from the Octave Mercurial repository to get the fix.

The OP also mentioned a problem with circshift. Please file a new bug report about that with an example of the problem.

Rik <rik5>
Project Administrator
Fri 25 Aug 2017 06:11:51 AM UTC, comment #7:

Never mind. I found a bug in the code. I don't need the test in comment #6 to be run.

Rik <rik5>
Project Administrator
Fri 25 Aug 2017 05:31:31 AM UTC, comment #6:

I've re-coded the input validation, but I need another test run. What does Matlab do for this code

Rik <rik5>
Project Administrator
Thu 24 Aug 2017 09:23:31 AM UTC, comment #5:

On Matlab R2017a:

Guillaume <gyom>
Thu 17 Aug 2017 12:22:54 PM UTC, comment #4:

The code snippet that I gave didn't come out as I expected. Here's a new attempt:

Roger Jeurissen <rogerjeurissen>
Thu 17 Aug 2017 12:19:39 PM UTC, comment #3:

The Matlab documentation for del2 is indeed incorrect here. I said that the example code that I gave works in Matlab, because it came directly from the example on the Mathworks website. I assume that they checked their examples. I don't have access to Matlab right now.

Your suggestion of supplying a spacing for the y-direction is actually much simpler than what I proposed. I assumed that that wouldn't work because the doc says:

At least 3 data points are needed for each dimension.

This solution relies on what happens when there are fewer than 3 data points; that dimension is ignored, so it works. This could be implemented by adding this right after line 80 ( which is h = varargin{1}; )

I just noticed that circshift has the same issue.

Roger Jeurissen <rogerjeurissen>
Fri 11 Aug 2017 05:08:23 PM UTC, comment #2:

Probably easiest to start a session and execute 'diary on'. At the end of the session upload the diary file to the bug report?

Sample Code #1:

Does this produce an error because the spacing is neither a scalar nor a vector?

Sample Code #2:

Documentation says the first spacing applies to the first dimension. However, the first dimension is rows, not columns, which is different than specifying the x-separation which people think of as the first argument.

Sample Code #3:

Just making sure they don't something special for the 1-D vectors in Code #2.

Rik <rik5>
Project Administrator
Fri 11 Aug 2017 04:22:47 PM UTC, comment #1:

Certainly Octave should be able to calculate this.

I think the issue is that Matlab defaults unspecified dimensions to a spacing of 1, despite the fact that the documentation says

For reference, see http://www.mathworks.com/help/matlab/ref/del2.html.

In Octave, the simple way to get this to work is to specify all dimensions. In the Matlab language everything has a minimum of two dimensions. 1-D objects, vectors, are really just Nx1 or 1XN matrices. I can get your code to work simply by supplying a spacing for the Y dimension.


The m-file del2 hasn't been reviewed for a long time and probably needs an overhaul. Given that you have access to Matlab, can you run a few sample pieces of code through Matlab and report the result?

Rik <rik5>
Project Administrator
Fri 11 Aug 2017 11:04:56 AM UTC, original submission:

According to the documentation, the discrete Laplacian of a 1-D array can be calculated with del2, with non-uniform spacing. When I tried to use this, octave threw an error:

error: del2: dimensionality mismatch in 1-th spacing vector

The following code reproduces the error:

In Matlab, this does return a value without errors.

I suspect that this originates from line 73 of del2. There, ndims is used to obtain the number of dimensions of the input array, and this value is stored in the variable nd. However, ndims returns 2 for a 1-D array. What is needed is the number of non-singleton dimensions:

However, this would break the functionality later on, because the for loops run over the dimensions. To fix that, we can add the following lines after line 73:

We should also add this line at the end:

As far as I can see right now, this should work. I tested this fix to check that it solves the issue that i encountered, and it does.



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

Attach Files:

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 gyom (Posted a comment)
  • -email is unavailable- added by rogerjeurissen (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)

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

    Only project members can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-25 rik5 StatusNeed Info => Fixed
        Open/ClosedOpen => Closed
    2017-08-15 rik5 StatusConfirmed => Need Info
    2017-08-11 rik5 StatusNone => Confirmed

    Back to the top

    Powered by Savane 3.3