Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lesquoyb
Copy link
Contributor

@lesquoyb lesquoyb commented Sep 5, 2025

What has been done so far:

  • adds simple slice/submatrix operators to handle matrices and fields
  • adds a base unit test model to make sure all case will be handled
  • fixes some documentation
  • adds a new alias "slice" for "copy_between"
  • adds a new definition of "copy_between" with a parameter to handle steps
  • beginning of handling negative index to represent counting from the end
  • Fixes [gaml] collect operator on field returns a matrix #754

What's left:

  • proper handling of negative indices in lists and matrices
  • finish the unit test model
  • proper handling of negative steps (reverse is not working in lists and not implemented in matrices)

- adds simple slice/submatrix operators to handle matrices and fields
- adds a base unit test model to make sure all case will be handled
- fixes some documentation
- adds a new alias "slice" for "copy_between"
- adds a new definition of "copy_between" with a parameter to handle steps
- beginning of handling negative index to represent counting from the end
- Fixes #754
- remove the slice alias from copy_between. Now slice will be a completely different operator that includes both bounds for better functionalities
- adds a sublist operator that returns a list composed of the values at the indices given as parameter
- slice is now inclusive of the upper bound making reverse-like manipulation possible
- makes implicit step work both ways
- adding more cases to the unit test file
- better documentation and method renaming for better understanding
@lesquoyb lesquoyb marked this pull request as ready for review September 10, 2025 02:38
@lesquoyb lesquoyb changed the title [WIP][GAML] rework of slicing for lists and matrices [GAML] rework of slicing for lists and matrices Sep 10, 2025
@lesquoyb
Copy link
Contributor Author

lesquoyb commented Sep 10, 2025

I'm pretty much done, finally I've went for a separation between the copy_between and a new operator called slice. It also has two aliases sublist and submatrix depending on what container it is applied to.
I've also added as_list operator for matrices that just reuse the listValue and removed an unused field: epsilon that was in GamaField + fixed #754
For slicing there are now three ways to do it using the new operators:

  • directly giving a list (or two for matrices) of indices that we want to use to create the new container
  • giving a pair (or two for matrices) of from/to values that will be used to generate a range of indices. Managing forward and backward traversing
  • giving a pair (or two) for indices bounds as previously + an int value (or two) used to step in that range
    Those operator all support negative indices to represent counting from the end.

To make this possible I had to specify that the "end" of the range of value is inclusive, that's why I had to part away from copy_between but I think that it actually makes sense as the definitions overlap only partially.

I think the implementation for matrices is currently not optimal but it avoids code repetition, so this part is still improvable but it's working. As for test cases I'll gladly take new ideas if you have any.

Waiting for your feedbacks/improvements before closing

…e cases

also creates a matrixLike method for internal use: it creates a matrix or field of the same type as the one given in parameters but with other dimensions and using the default value
@lesquoyb lesquoyb merged commit eea94d7 into main Sep 17, 2025
5 of 6 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in GAMA current Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[gaml] collect operator on field returns a matrix

2 participants