AngleAxis and getunit error with Numpy 2.4

オープン
#177 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
numpy, python
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
641
フォーク
102
平均マージ
1日 18時間
マージ済み PR(30日)
4

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rai-opensource/spatialmath-python のほかの issue

rai-opensource/spatialmath-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。