bugGNU Octave - Bugs: bug #49019, some function fail when DIM>=3...

 
 

bug #49019: some function fail when DIM>=3 and size(X,DIM)==1

Submitter:  None
Submitted:  Wed 07 Sep 2016 08:55:53 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.3
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 04 Nov 2016 02:32:14 AM UTC, comment #3: 

It looks like some of this has been resolved in the source (I'm running 4.0.0) with the closing of #33523. However the "fft" function still seems to be incompatible with the MATLAB version.

Joakim Andén <janden>
Thu 03 Nov 2016 10:44:46 PM UTC, comment #2: 

Looking at the MATLAB behavior for these functions


>> A

A =

   3.578396939725760  -1.349886940156521
   2.769437029884877   3.034923466331855

>> fft(A, [], 3)

ans =

   3.578396939725760  -1.349886940156521
   2.769437029884877   3.034923466331855

>> mean(A, 3)

ans =

   3.578396939725760  -1.349886940156521
   2.769437029884877   3.034923466331855

>> diff(A, 1, 3)

ans =

   Empty array: 2-by-2-by-0


so identity for "fft" and "mean", while empty matrix for "diff". However, Octave gives errors for each of those calls. Similar discrepancies are there for "mode", "median", and others. For the sake of compatibility, it would be good to copy this behavior. I would be willing to make the necessary changes if there is interest in changing this.

Joakim Andén <janden>
Wed 07 Sep 2016 03:00:36 PM UTC, comment #1: 

If a function accepts a dimension greater than ndims, then it is probably done for Matlab compatibility.

Indeed, for example, Matlab's help for the max function states

> max returns A if dim is greater than ndims(A).


This is not the case for most functions and cannot really be solved in a general way. Since all arrays have ndims >= 2, 1 and 2 will always work, but dim >= 3 will only work if the array actually has ndims >= dim.

Mike Miller <mtmiller>
Group Member
Wed 07 Sep 2016 08:55:53 AM UTC, original submission:  

When DIM>=3 and size(X,DIM)==1, some functions work, such as "max", "min", "sum", "prod",

>>  max(1:3, [], 3)
ans =

   1   2   3

>>  sum(1:3, 3)
ans =

   1   2   3


but some functions fail, such as "fft", "mean", "diff",

>>  fft(1:3, 256, 3)
error: fft: DIM must be a valid dimension along which to perform FFT
>>  fft(1:3, [], 3)
error: fft: DIM must be a valid dimension along which to perform FFT
>>  diff(1:3, [], 3)
error: DIM must be a valid dimension
>>  mean(1:3, 3)
error: mean: DIM must be an integer and a valid dimension
error: called from
    mean at line 110 column 7


I'm not sure whether this is a bug or a feature,

although sometimes this is inconvenient and we have to make a workaround by "resize" or "postpad" X to make sure size(X,DIM)>=2 before calling these functions.

Anonymous

 

(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 janden (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  •  

    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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-09-07 mtmiller StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code