Skip to content

Use built in method numpy.set_printoptions in addObject/addChild methods to enable numpy 2 - #518

Merged
hugtalbot merged 4 commits into
sofa-framework:masterfrom
bakpaul:25_07_fix_compat_with_numpy2_using_strings
Jul 16, 2025
Merged

Use built in method numpy.set_printoptions in addObject/addChild methods to enable numpy 2 #518
hugtalbot merged 4 commits into
sofa-framework:masterfrom
bakpaul:25_07_fix_compat_with_numpy2_using_strings

Conversation

@bakpaul

Copy link
Copy Markdown
Contributor

Use set_printoptions(legacy=True) in node binding to force usage of legacy repr for numpy objects. This is compatible with numpy 1

This still uses string representation of all arguments when calling addObject or addChild, which reduces the possibles bugs.

…egacy repr for numpy objects. This is ocmpatible with numpy 1

@hugtalbothugtalbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if some refactoring could have been done (use a function to avoid repeated code snippets), it would require multiple load of numpy which I doubt we also desire

@hugtalbothugtalbot added the topic for next dev-meeting Worth discussion at dev meeting label Jul 15, 2025
Comment threadbindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp Outdated
Comment threadbindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp Outdated
Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
@hugtalbot
hugtalbot merged commit c5b0fb1 into sofa-framework:masterJul 16, 2025
4 checks passed
hugtalbot added a commit that referenced this pull request Jul 16, 2025
…ods to enable numpy 2 (#518)
* Use set_printoptions(legacy=True) in node binfing to force usage of legacy repr for numpy objects. This is ocmpatible with numpy 1
* Patch addChild
* Add RAII mechanism to make sure numpy is put back its initial state
* Add [[maybe_unused]]
Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
---------
Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
Sign up for freeto 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.

3 participants

@bakpaul@fredroy@hugtalbot