bugGNU Octave - Bugs: bug #53178, Circshift incompatibility with...

 
 

bug #53178: Circshift incompatibility with MATLAB

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Sat 17 Feb 2018 03:00:22 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 01 Dec 2018 10:35:15 AM UTC, comment #5: 

I checked in a cset for this here (https://hg.savannah.gnu.org/hgweb/octave/rev/8be616a0b9aa).

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Sun 18 Mar 2018 01:57:01 PM UTC, comment #4: 

Sorry that logic was busted, trying to be clever. This is a simpler fix for scalar "n" arguments.

diff circshift.m circshift_new.m

< function y = circshift (x, n, dim)
---

> function y = circshift_new (x, n, dim)

75a76,81

>   if (isscalar (n))
>     ## Find the first non-singleton dimension.
>     (dim = find (sz > 1, 1)) || (dim = 1);
>     n = [zeros(1, dim-1), n];
>   end
>  


Ceral Paquet <octavebugs>
Thu 15 Mar 2018 10:14:36 PM UTC, comment #3: 

The diff was kind of terse! ;) In context:


  nd = ndims (x);
  sz = size (x);

  if (nargin == 3 || isscalar(n))
    if (! isscalar (n))
      error ("circshift: N must be a scalar when DIM is also specified");
    else
        ## Find the first non-singleton dimension.
        (dim = find (sz > 1, 1)) || (dim = 1);
    endif
    n = [zeros(1, dim-1), n];
  endif


Ceral Paquet <octavebugs>
Thu 15 Mar 2018 10:11:27 PM UTC, comment #2: 

This change to circshift.m allows a scalar "n" argument that acts along the first non-singleton dimension.


66c66,69
<   if (nargin == 3)
---
>   nd = ndims (x);
>   sz = size (x);
>
>   if (nargin == 3 || isscalar(n))
68a72,74
>     else
>         ## Find the first non-singleton dimension.
>         (dim = find (sz > 1, 1)) || (dim = 1);
72,74d77
<
<   nd = ndims (x);
<   sz = size (x);


Ceral Paquet <octavebugs>
Sat 17 Feb 2018 03:23:28 PM UTC, comment #1: 

Aha, now I see why this never bit us before!


Note

The default behavior of circshift(A,K) where K is a scalar changed in R2016b. To preserve the behavior of R2016a and previous releases, use circshift(A,K,1). This syntax specifies 1 as the dimension to operate along.


https://www.mathworks.com/help/matlab/ref/circshift.html

Ceral Paquet <octavebugs>
Sat 17 Feb 2018 03:00:22 PM UTC, original submission:  

With a vector input and singleton shift argument, MATLAB always shifts whereas Octave respects the dimension.

MATLAB 2017a

>> x=1:4

x =

     1     2     3     4

>> circshift(x,1)

ans =

     4     1     2     3

>> circshift(x',1)

ans =

     4
     1
     2
     3



Octave 4.2.1

>> x=1:4
x =

   1   2   3   4

>> circshift(x,1)
ans =

   1   2   3   4

>> circshift(x',1)
ans =

   4
   1
   2
   3


Ceral Paquet <octavebugs>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by octavebugs (Submitted the item)
  •  

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

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-01 rik5 Open/ClosedOpen Closed
    2018-12-01 rik5 StatusNone Fixed
        Release4.2.1 dev
    2018-03-20 mtmiller CategoryNone Octave Function
        Item GroupWTF, Matlab?!? Matlab Compatibility

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code