[Scilab-users] circshift() : Scilab Enhancement Proposal

classic Classic list List threaded Threaded
7 messages Options
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] circshift() : Scilab Enhancement Proposal

Dear co-scilabers,

After the wish reported at http://bugzilla.scilab.org/7293 in 2010,
some cshift() function was proposed on the FileExchange at
http://fileexchange.scilab.org/toolboxes/161000 to provide a way
to circularly shift the rows or columns of a matrix or an hypermatrix.

In order to include this basic but non-trivial feature in Scilab 6.1,
a Scilab Enhancement Proposal is posted on review at
https://codereview.scilab.org/#/c/19625/

Proposed features are described in the help page in PDF format in
attachment.

Every comment is welcome.

Best regards
Samuel Gougeon


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

circshift.pdf (64K) Download Attachment
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

Hi Samuel,


Thanks a lot for this nice SEP.
I have a couple of comments:

1) I think I should be good to also show some multidimensional examples using "shifts" and using both "shifts" and "dims". Sometimes in the scilab documentation, the user is served with examples only covering the most basic usage and not the advanced one with N optional arguments.

2) For multidimentional cshift, the order of the shifts (for example shift  by N along the lines than shift by M along the columns or the other way round) is key, right? Inverting the order would give a different result, right? Should this be specified in the SEP:

circshift(A, shifts) first circularly shifts indices of A rows by shifts(1), then the indices of A columns by shifts(2), then indices of A layers by shifts(3), etc.

Cheers,

Antoine

(& Happy New Year to all!)

Le 23/12/2017 à 19:06, Samuel Gougeon a écrit :
Dear co-scilabers,

After the wish reported at http://bugzilla.scilab.org/7293 in 2010,
some cshift() function was proposed on the FileExchange at
http://fileexchange.scilab.org/toolboxes/161000 to provide a way
to circularly shift the rows or columns of a matrix or an hypermatrix.

In order to include this basic but non-trivial feature in Scilab 6.1,
a Scilab Enhancement Proposal is posted on review at
https://codereview.scilab.org/#/c/19625/

Proposed features are described in the help page in PDF format in attachment.

Every comment is welcome.

Best regards
Samuel Gougeon



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

Hello Antoine,

Thanks for your time to have read this proposal and comment it.

I am afraid i don't catch your first point. As far as i understand your suggestion, the last existing example with an hypermatrix of texts already fulfills it.
For my part, in examples, i think it is better to show results as often as possible, not only the code. Since there is presently no way to display examples by default in a fold way (at least in the native Scilab help browser/viewer, with a "+/-" clickable switch), this makes quite long pages that requires to be scrolled a lot. By the way, as soon as hypermatrices are involved, displayed results are still more lengthy. So, in my opinion, there is a compromise.

About the order of multiple crossed or parallel or mixed shifts: no, the order does not matter. One gets the same result whatever the order is.

Happy new year 2018 to you and to every scilaber.
Have nice projects and involvements with Scilab and others.

Best wishes
Samuel

Le 03/01/2018 à 09:09, antoine monmayrant a écrit :

Hi Samuel,


Thanks a lot for this nice SEP.
I have a couple of comments:

1) I think I should be good to also show some multidimensional examples using "shifts" and using both "shifts" and "dims". Sometimes in the scilab documentation, the user is served with examples only covering the most basic usage and not the advanced one with N optional arguments.

2) For multidimentional cshift, the order of the shifts (for example shift  by N along the lines than shift by M along the columns or the other way round) is key, right? Inverting the order would give a different result, right? Should this be specified in the SEP:

circshift(A, shifts) first circularly shifts indices of A rows by shifts(1), then the indices of A columns by shifts(2), then indices of A layers by shifts(3), etc.

Cheers,

Antoine

(& Happy New Year to all!)

Le 23/12/2017 à 19:06, Samuel Gougeon a écrit :
Dear co-scilabers,

After the wish reported at http://bugzilla.scilab.org/7293 in 2010,
some cshift() function was proposed on the FileExchange at
http://fileexchange.scilab.org/toolboxes/161000 to provide a way
to circularly shift the rows or columns of a matrix or an hypermatrix.

In order to include this basic but non-trivial feature in Scilab 6.1,
a Scilab Enhancement Proposal is posted on review at
https://codereview.scilab.org/#/c/19625/

Proposed features are described in the help page in PDF format in attachment.

Every comment is welcome.

Best regards
Samuel Gougeon



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

In reply to this post by Antoine Monmayrant

Samuel,

 

As requested, some further feedback on circshift:

 

  • The proposed syntax seems to be compatible with Matlab’s circshift while adding extra functionality, which is very positive

 

  • To add to the wish list: if the input matrix represents a regularly sampled function, it would be useful to have in Scilab a generalization of circshift allowing non-integer shifts, also to have option for non-circular shifts and for padding with zeros

 

Best Wishes for 2018!

 

Rafael

 

 

Le 23/12/2017 à 19:06, Samuel Gougeon a écrit :

Dear co-scilabers,

After the wish reported at
http://bugzilla.scilab.org/7293
in 2010,
some cshift() function was proposed on the FileExchange at
http://fileexchange.scilab.org/toolboxes/161000 to provide a way
to circularly shift the rows or columns of a matrix or an hypermatrix.

In order to include this basic but non-trivial feature in Scilab 6.1,
a Scilab Enhancement Proposal is posted on review at
https://codereview.scilab.org/#/c/19625/

Proposed features are described in the help page in PDF format in attachment.

Every comment is welcome.

Best regards
Samuel Gougeon




_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

Thanks for your comments, Rafael.
I am answering in the body:

Le 03/01/2018 à 16:00, Rafael Guerra a écrit :

Samuel,

 

As requested, some further feedback on circshift:

 

  • The proposed syntax seems to be compatible with Matlab’s circshift while adding extra functionality, which is very positive

 

  • To add to the wish list: if the input matrix represents a regularly sampled function, it would be useful to have in Scilab a generalization of circshift allowing non-integer shifts,

As far as i understand, you are addressing here an interpolation feature rather than an indices-shifting one.
IMO, this is a job much closer to existing interp#() functions than to circshift(). Interpolations modes usually propose options to process edges, and other ones to chose an interpolation mode (linear, splines ,etc).
This is far beyond and out of the purpose of circshift(), that does not change values, just indices.

  • also to have option for non-circular shifts and for padding with zeros

Something like circshift(), without circ ;)
Padding is presently proposed throught resize_matrix(). But indeed, it does not propose left or top padded insertions.
This will become easy with circshift() as it is presently proposed. Example:

--> m = grand(3,4,"uin",0,9)
 m  =
   2.   5.   9.   3.
   2.   4.   5.   5.
   4.   1.   8.   5.

--> circshift(resize_matrix(m, [5,7]),[1,2])
 ans  =
   0.   0.   0.   0.   0.   0.   0.
   0.   0.   2.   5.   9.   3.   0.
   0.   0.   2.   4.   5.   5.   0.
   0.   0.   4.   1.   8.   5.   0.
   0.   0.   0.   0.   0.   0.   0.

The main resize_matrix() syntax is

resMat = resize_matrix(mat, nbRows, nbCols)

Specifying a vector of 2 components instead of a scalar for either nbrows or nbcols or both would enable specifying margins on both sides for each direction, instead of the new required sizes.
IMO, this would be an improvement for resize_matrix() rather than a circshift() extension.
Don't you think so?

Best regards
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

In reply to this post by Rafael Guerra
Hello Rafael,

Le 03/01/2018 à 16:00, Rafael Guerra a écrit :

Samuel,

 

As requested, some further feedback on circshift:

 .../...

  • To add to the wish list: if the input matrix represents a regularly sampled function, it would be useful to have in Scilab a generalization of circshift allowing non-integer shifts, also to have option for non-circular shifts and for padding with zeros

To go on about resize_matrix() , padding, and shifting without wrapping:
Specifying a (N>1 x 2) matrix of positive (pad) or negative (trim) margins resizing
would be simple.
Padding with other default elements for non-numerical arrays, or with a chosen
value, is already enabled.
Possible new syntaxes and examples of usages:

resMat = resize_matrix(mat, frameWidth)
resMat = resize_matrix(mat, frameWidth, ..)

m = [
  6 -7 -1 -2
 -6  0 -2 -5
 -5  4 -1  8
  ];

// shift without extension nor wrapping:
resize_matrix(m, [0 0 ; -1 1])
ans =
  -7 -1 -2  0
   0 -2 -5  0
   4 -1  8  0

// Another case without extensions nor wrapping:
resize_matrix(m, [1 -1 ; 2 -2])
ans = 
0  0  0  0 
0  0  6 -7 
0  0 -6  0 

// More general
resize_matrix(m, [2 1 ; 1 -1])
ans = 
0  0  0  0 
0  0  0  0 
0  6 -7 -1 
0 -6  0 -2 
0 -5  4 -1 
0  0  0  0 


Is it the kind of features you were thinking about?

IMO, there is no need to implement this in another specific function, because these features are just particular cases or resizing, with a simple syntax allowing to crop borders as well.

Best regards
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: circshift() : Scilab Enhancement Proposal

Hi Samuel,

 

The functionality is very nice but the syntax proposed is maybe a bit complicated?

It would be easier to combine ‘newSizes’ with a new ‘shift’ argument (but with no wrapping as proposed in circshift).

For example:

 

 m  =
   2.   5.   9.   3.
   2.   4.   5.   5.
   4.   1.   8.   5.

 

resize_matrix(m, newSizes=[5 7], shift=[1 2])

 ans  =
   0.   0.   0.   0.   0.   0.   0.
   0.   0.   2.   5.   9.   3.   0.
   0.   0.   2.   4.   5.   5.   0.
   0.   0.   4.   1.   8.   5.   0.
   0.   0.   0.   0.   0.   0.   0.

 

resize_matrix(m, newSizes=[-1 -1], shift=[-1 -2])

 ans  =

   5.   5.   0.   0.
   8.   5.   0.   0.
   0.   0.   0.   0. 

 

 

Regarding extending circshift() to non-integers I had in mind n-dimensional matrices and the discrete Fourier transform.

These matrices could represent regularly sampled 1D time signals, or 2D/3D spatial functions, etc.

In this context the shift theorem gives a specific meaning to the circular shifts of the input signals (corresponding to linear phase shifts in their spectrum).

 

Regards,

Rafael

 

From: users [mailto:[hidden email]] On Behalf Of Samuel Gougeon
Sent: Tuesday, January 09, 2018 8:26 PM
To: Users mailing list for Scilab <[hidden email]>
Subject: Re: [Scilab-users] circshift() : Scilab Enhancement Proposal

 

Hello Rafael,

To go on about resize_matrix() , padding, and shifting without wrapping:
Specifying a (N>1 x 2) matrix of positive (pad) or negative (trim) margins resizing
would be simple.
Padding with other default elements for non-numerical arrays, or with a chosen
value, is already enabled.
Possible new syntaxes and examples of usages:

 
resMat = resize_matrix(mat, frameWidth)
resMat = resize_matrix(mat, frameWidth, ..)
 
m = [
  6 -7 -1 -2
 -6  0 -2 -5
 -5  4 -1  8
  ];
 
// shift without extension nor wrapping:
resize_matrix(m, [0 0 ; -1 1])
ans =
  -7 -1 -2  0
   0 -2 -5  0
   4 -1  8  0
 
// Another case without extensions nor wrapping:
resize_matrix(m, [1 -1 ; 2 -2])
ans = 
0  0  0  0 
0  0  6 -7 
0  0 -6  0 
 
// More general
resize_matrix(m, [2 1 ; 1 -1])
ans = 
0  0  0  0 
0  0  0  0 
0  6 -7 -1 
0 -6  0 -2 
0 -5  4 -1 
0  0  0  0 
 
 

Is it the kind of features you were thinking about?

IMO, there is no need to implement this in another specific function, because these features are just particular cases or resizing, with a simple syntax allowing to crop borders as well.

Best regards
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users