AngleAxis and getunit error with Numpy 2.4

Aperta
#177 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
numpy, python
Ambito
backend

Direzione di ricerca

Reproduce the SO3.AngVec(theta=0, v=[0, 0, 1]) failure with NumPy 2.4, then inspect spatialmath/pose3d.py and spatialmath/base/transforms3d.py, including getunit and angvec2r. Done means the call no longer raises a TypeError under NumPy 2.4 and retains the expected identity rotation behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi,

When calling SO3.AxisAngle in Python 3.11 with numpy 2.4, I get the error:

Python 3.11.11 | packaged by conda-forge | (main, Dec  5 2024, 08:47:03) [Clang 18.1.8 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.4.0'
>>> from spatialmath import SO3
>>> SO3.AngVec(theta=0, v=[0, 0, 1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Caskroom/miniconda/base/envs/vp_311/lib/python3.11/site-packages/spatialmath/pose3d.py", line 825, in AngVec
    return cls(smb.angvec2r(theta, v, unit=unit), check=False)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/vp_311/lib/python3.11/site-packages/spatialmath/base/transforms3d.py", line 760, in angvec2r
    R = np.eye(3) + math.sin(θ) * sk + (1.0 - math.cos(θ)) * sk @ sk
                    ^^^^^^^^^^^
TypeError: only 0-dimensional arrays can be converted to Python scalars
>>> 

However, with numpy 2.2, I get the expected behavior:

Python 3.11.11 | packaged by conda-forge | (main, Dec  5 2024, 08:47:03) [Clang 18.1.8 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.2.6'
>>> from spatialmath import SO3
>>> SO3.AngVec(theta=0, v=[0, 0, 1])
SO3(array([[1., 0., 0.],
           [0., 1., 0.],
           [0., 0., 1.]]))

The error seems to stem from getunit, which when given a scalar now returns a 1-dimensional array instead of a 0-dimensional array. That then gets fed to math.cos, not np.cos, in angvec2r and the error occurs.

Thank you for all your work on this library,
JF

Lingua principale
Python
Stelle
641
Fork
102
Merge medio
1g 18h
PR unite (30g)
4

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rai-opensource/spatialmath-python

Tutte le issue di rai-opensource/spatialmath-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.