Skip to content

Use real copy instead of converting to string for when calling addObject or addChild #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

bakpaul
Copy link
Contributor

@bakpaul bakpaul commented Jul 7, 2025

This supersede PR #45

This takes the work in #45 , update it with master, remove unrelated changes to PrefabLinks, fix it compilation and execution.

This will solve the issue of incompatibility with numpy 2. But at the cost of being way more strict on data structures of lists. Until now, because each input value passed to addObject was processed by the method toSofaParsableString we didn't have to make sure the list was correctly formated.

Indeed, the method toSofaParsableString used a recursive pattern for list object, removing any sort of shape of the list, such as what it is expected in xml: one contiguous chunk of stringed values that will be reshaped in a row major fashion. This allowed to pass position=[0, 0, 0] for vector, or even worst [0, 0, 0, [0, 1, 0], [0, 2, 0]]. Now only list of list of three elems (or numpy arrays) will be accepted. So even if only one point is in the mstate we need to put position=[[0,0,0]].

This, of course brakes a lot of scenes in a lot of repository. We need to decide what to do. I suggest to make a huge refactoring, by testing this PR on the SOFA CI with a ci-depend-on and only merge everything when all scenes are passing.

--> 🦸 To make it less breaking, I've added a compat' layer that translate data to string when an error is thrown.

To complete the explanations:
The main difficulty here comes from the factory that takes a structure of type BaseObjectDescription as input of creation of the object. The method that actually creates the object does multiple checks on this description to know if the object can be created regarding the context and tries to fix wrong parametrization as much as possible + it will set the data that are already inside the struc. The issue is that this description object can only store string representation the the datas, which is breaking with numpy 2 because its string representation contains numpy type names which makes no sens in C++.

To solve this, the idea of this work is to, before creating the object, sort the input kwargs to 'createObject' to transform the list into vectors of real data in C++ instead of transforming them to string. But because they are not string anymore, they need to be passed to the object after its creation, so they cannot be used for the factory check and parsing. This is ok for most of the data, but for some such as template, linkslist of link (for multimapping), src and more, this is breaking. Plus there are also some data field that are not real data but only parsed by the object itself. That is the reason of the apparent complexity of the fix.

damienmarchal and others added 7 commits August 31, 2020 21:54
…h invalid argument.

(this was the previous behavior)
The PR is breaking existing code. But the previously working code was,
despite being conveniant was not valid and it was using a "flat" array as
a multi-dimensionnal structure. It was not noticed before because the lists were
converted into a 1D array then into a big string.

Two options were possibles:
a) not allowing this kind of code (using a 1D array to fill a 2D structure)
b) implement kind of de-flattening a python lists into the corresponding multidimmensional matrix

For the simplicity I choose option (a), so I updated the tests to use the 'right' syntax.
… factory itself (e.g. src, template, input...)
@damienmarchal
Copy link
Contributor

Hello Paul,

Thank you so much to rewarming this old fire.

For the transition one option could simply be to add a new addComponent/addNode replacing the add addObject
Or as this was suggested, and agreed on, simply mkes the the generic add() (to replace addObject/addChild) to only work with the non-string code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants