AngleAxis and getunit error with Numpy 2.4

Abierto
#177 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
50/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
numpy, python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
641
Forks
102
Merge medio
1 d 18 h
PR fusionados (30 d)
4

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rai-opensource/spatialmath-python

Todos los issues de rai-opensource/spatialmath-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.