numere-org / NumeRe

Framework for numerical computations, data analysis and visualisation
https://www.numere.org
GNU General Public License v3.0
18 stars 6 forks source link

circShift, hShift and vShift command for tables #39

Closed raphael-sys closed 10 months ago

raphael-sys commented 1 year ago

DESCRIPTION

What does your feature request improve on? Please describe. When having to rearrange table data the commands circShift, hShift and vShift can be helpful. The same thing can be achieved with some lines of code, but that solution would be cleaner and might be faster.

Describe the solution you'd like test() = {{1,2,3},{4,5,6},{7,8,9}} circShift -> shift the table entries, there needs to be an option to shift row and col wise. Example: circShift by 1 (row wise) -> {{9,7,8},{1,2,3},{4,5,6}} circShift by 1 (col wise) -> {{9,1,2},{3,4,5},{6,7,8}} hShift -> hShift by 1 -> {{3,1,2},{6,4,5},{9,7,8}} vShift -> vShift by 1 -> {{4,5,6},{7,8,9},{1,2,3}}

Additional context It is possible to shift by an positive or negative integer.

(Do not write below this line)


DEVS' SECTION

ANALYSIS

Create two new matop functions vectshift(MAT, n, m) -> MAT (for rows and columns) and circshift(MAT, n, m) -> MAT (for circular shifts) to implement the required behaviors. All three functions are to be implemented by creating a new matrix with the elements reorganized, because the arguments of this functions are always passed as const ref. Both functions provide two dimensions to indicate the number of elements to be shifted row-wise and col-wise (in this order).

Consider also to creation of the necessary entries in the language files.

IMPLEMENTATION STEPS

(see also our Wiki for implementation guidelines)

DOCUMENTATION STEPS

(see also our Wiki for further information)

PULL REQUEST

numeredev commented 1 year ago

Is it intended that this is a matop function or shall that be a table method like TAB().circshift()?

raphael-sys commented 1 year ago

I would be open to both. At first glance it seems more convenient to me to have a table method, but on the other hand this would always override.. So both versions have their pros and cons, if nobody objects I would vote for the table method.

numeredev commented 1 year ago

@raphael-sys: I do not understand the second circshift option. How is that intended to work? Or is there a typo within the example?

raphael-sys commented 1 year ago

Maybe the names for the commands are not clear yet. While hshift and vshift should shift entire rows or cols, the circshift should "push" each element by on position (row- or col-wise). So the examples show the "1" being shifted to the right in the first example and down in the second example. An element that is pushed outside the matrix moves to the next row/col. Does that clarify it?

raphael-sys commented 1 year ago

Okay. The confusion was caused by the matrix format. I changed the ticket to reflect the default NumeRe Matrix format, that is {{Col1},{Col2},...}.

numeredev commented 1 year ago

@raphael-sys After some thought, it seems that this is only really relevant in numerical context, therefore, it will be implemented as matop functions.